moai-workflow-worktree
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMoAI Worktree Management
MoAI Worktree 管理
Git worktree management system for parallel SPEC development with isolated workspaces, automatic registration, and seamless MoAI-ADK integration.
Core Philosophy: Each SPEC deserves its own isolated workspace to enable true parallel development without context switching overhead.
用于并行SPEC开发的Git worktree管理系统,提供独立工作区、自动注册以及与MoAI-ADK的无缝集成。
核心理念:每个SPEC都应拥有独立的工作区,实现真正的并行开发,消除上下文切换的开销。
Quick Reference (30 seconds)
快速参考(30秒)
What is MoAI Worktree Management?
A specialized Git worktree system that creates isolated development environments for each SPEC, enabling parallel development without conflicts.
Key Features:
- Isolated Workspaces: Each SPEC gets its own worktree with independent Git state
- Automatic Registration: Worktree registry tracks all active workspaces
- Parallel Development: Multiple SPECs can be developed simultaneously
- Seamless Integration: Works with /moai:1-plan, /moai:2-run, /moai:3-sync workflow
- Smart Synchronization: Automatic sync with base branch when needed
- Cleanup Automation: Automatic cleanup of merged worktrees
Quick Access:
- CLI commands: Refer to Worktree Commands Module at modules/worktree-commands.md
- Management patterns: Refer to Worktree Management Module at modules/worktree-management.md
- Parallel workflow: Refer to Parallel Development Module at modules/parallel-development.md
- Integration guide: Refer to Integration Patterns Module at modules/integration-patterns.md
- Troubleshooting: Refer to Troubleshooting Module at modules/troubleshooting.md
Use Cases:
- Multiple SPECs development in parallel
- Isolated testing environments
- Feature branch isolation
- Code review workflows
- Experimental feature development
什么是MoAI Worktree管理?
这是一个专用的Git worktree系统,可为每个SPEC创建独立的开发环境,实现无冲突的并行开发。
核心功能:
- 独立工作区:每个SPEC拥有独立Git状态的专属worktree
- 自动注册:Worktree注册表跟踪所有活跃工作区
- 并行开发:可同时开发多个SPEC
- 无缝集成:与/moai:1-plan、/moai:2-run、/moai:3-sync工作流兼容
- 智能同步:必要时自动与基础分支同步
- 自动清理:自动清理已合并的worktree
快速访问:
- CLI命令:参考modules/worktree-commands.md中的Worktree命令模块
- 管理模式:参考modules/worktree-management.md中的Worktree管理模块
- 并行工作流:参考modules/parallel-development.md中的并行开发模块
- 集成指南:参考modules/integration-patterns.md中的集成模式模块
- 故障排除:参考modules/troubleshooting.md中的故障排除模块
适用场景:
- 多个SPEC并行开发
- 独立测试环境
- 功能分支隔离
- 代码评审工作流
- 实验性功能开发
Implementation Guide (5 minutes)
实施指南(5分钟)
1. Core Architecture - Worktree Management System
1. 核心架构 - Worktree管理系统
Purpose: Create isolated Git worktrees for parallel SPEC development.
Key Components:
- Worktree Registry - Central registry tracking all worktrees
- Manager Layer - Core worktree operations including create, switch, remove, and sync
- CLI Interface - User-friendly command interface
- Models - Data structures for worktree metadata
- Integration Layer - MoAI-ADK workflow integration
Registry Structure:
The registry file stores worktree metadata in JSON format. Each worktree entry contains an identifier, file path, branch name, creation timestamp, last sync time, status (active or merged), and base branch reference. The config section defines the worktree root directory, auto-sync preference, and cleanup behavior for merged branches.
File Structure:
The worktree system creates a dedicated directory structure inside the project's .moai directory. At the worktree root ({repo}/.moai/worktrees/{ProjectName}/), you will find the central registry JSON file and individual directories for each SPEC. Each SPEC directory contains a .git file for worktree metadata and a complete copy of all project files.
Detailed Reference: Refer to Worktree Management Module at modules/worktree-management.md
目的:为并行SPEC开发创建独立的Git worktree。
核心组件:
- Worktree注册表 - 跟踪所有worktree的中央注册表
- 管理层 - 负责worktree的核心操作,包括创建、切换、删除和同步
- CLI界面 - 友好的命令行交互界面
- 模型 - 存储worktree元数据的数据结构
- 集成层 - 与MoAI-ADK工作流的集成模块
注册表结构:
注册表文件以JSON格式存储worktree元数据。每个worktree条目包含标识符、文件路径、分支名称、创建时间戳、最后同步时间、状态(活跃或已合并)以及基础分支引用。配置部分定义了worktree根目录、自动同步偏好和已合并分支的清理行为。
文件结构:
Worktree系统会在项目的.moai目录内创建专用的目录结构。在worktree根目录({repo}/.moai/worktrees/{ProjectName}/)中,你会找到中央注册表JSON文件以及每个SPEC对应的独立目录。每个SPEC目录包含用于存储worktree元数据的.git文件和项目文件的完整副本。
详细参考:参考modules/worktree-management.md中的Worktree管理模块
2. CLI Commands - Complete Command Interface
2. CLI命令 - 完整命令界面
Purpose: Provide intuitive CLI commands for worktree management.
Core Commands:
To create a new worktree for a SPEC, use the new command followed by the SPEC ID and description. To list all worktrees, use the list command. To switch to a specific worktree, use the switch command with the SPEC ID. To get the worktree path for shell integration, use the go command with eval. To sync a worktree with its base branch, use the sync command. To remove a worktree, use the remove command. To clean up merged worktrees, use the clean command. To show worktree status, use the status command. For configuration management, use the config command with get or set subcommands.
Command Categories:
- Creation: The new command creates an isolated worktree
- Navigation: The list, switch, and go commands enable browsing and navigating
- Management: The sync, remove, and clean commands maintain worktrees
- Status: The status command checks worktree state
- Configuration: The config command manages settings
Shell Integration:
For switching to a worktree directory, two approaches work well. The switch command directly changes to the worktree directory. The go command outputs a cd command that can be evaluated by the shell, which is the recommended pattern for shell scripts and automation.
Detailed Reference: Refer to Worktree Commands Module at modules/worktree-commands.md
目的:提供直观的CLI命令用于Worktree管理。
核心命令:
要为SPEC创建新的worktree,使用new命令并跟上SPEC ID和描述。要列出所有worktree,使用list命令。要切换到特定worktree,使用switch命令并指定SPEC ID。要获取worktree路径用于Shell集成,使用go命令并配合eval执行。要将worktree与基础分支同步,使用sync命令。要删除worktree,使用remove命令。要清理已合并的worktree,使用clean命令。要查看worktree状态,使用status命令。要管理配置,使用config命令并配合get或set子命令。
命令分类:
- 创建类:new命令用于创建独立worktree
- 导航类:list、switch和go命令用于浏览和切换worktree
- 管理类:sync、remove和clean命令用于维护worktree
- 状态类:status命令用于检查worktree状态
- 配置类:config命令用于管理设置
Shell集成:
切换到worktree目录有两种常用方式。switch命令可直接切换到worktree目录。go命令会输出cd命令,可由Shell执行,这是Shell脚本和自动化场景中的推荐方式。
详细参考:参考modules/worktree-commands.md中的Worktree命令模块
3. Parallel Development Workflow - Isolated SPEC Development
3. 并行开发工作流 - 独立SPEC开发
Purpose: Enable true parallel development without context switching.
Workflow Integration:
During the Plan Phase using /moai:1-plan, the SPEC is created and the worktree new command sets up automatic worktree isolation.
During the Development Phase, the isolated worktree environment provides independent Git state with zero context switching overhead.
During the Sync Phase using /moai:3-sync, the worktree sync command ensures clean integration with conflict resolution support.
During the Cleanup Phase, the worktree clean command provides automatic cleanup with registry maintenance.
Parallel Development Benefits:
- Context Isolation: Each SPEC has its own Git state, files, and environment
- Zero Switching Cost: Instant switching between worktrees
- Independent Development: Work on multiple SPECs simultaneously
- Safe Experimentation: Isolated environment for experimental features
- Clean Integration: Automatic sync and conflict resolution
Example Workflow:
First, create a worktree for SPEC-001 with a description like "User Authentication" and switch to that directory. Then run /moai:2-run SPEC-001 to develop in isolation. Next, navigate back to the main repository and create another worktree for SPEC-002 with description "Payment Integration". Switch to that worktree and run /moai:2-run SPEC-002 for parallel development. When needed, switch between worktrees and continue development. Finally, sync both worktrees when ready for integration.
Detailed Reference: Refer to Parallel Development Module at modules/parallel-development.md
目的:实现真正的并行开发,消除上下文切换。
工作流集成:
在使用/moai:1-plan的规划阶段,SPEC创建完成后,worktree new命令会自动设置独立worktree。
在开发阶段,独立worktree环境提供独立的Git状态,完全消除上下文切换的开销。
在使用/moai:3-sync的同步阶段,worktree sync命令可确保干净的集成,并支持冲突解决。
在清理阶段,worktree clean命令可自动清理并维护注册表。
并行开发优势:
- 上下文隔离:每个SPEC拥有独立的Git状态、文件和环境
- 零切换成本:在worktree之间即时切换
- 独立开发:可同时开发多个SPEC
- 安全实验:为实验性功能提供独立环境
- 干净集成:自动同步和冲突解决
示例工作流:
首先,为SPEC-001创建一个描述为"用户认证"的worktree并切换到该目录。然后运行/moai:2-run SPEC-001进行独立开发。接着回到主仓库,为SPEC-002创建一个描述为"支付集成"的worktree。切换到该worktree并运行/moai:2-run SPEC-002进行并行开发。需要时可在worktree之间切换并继续开发。最后,在准备集成时同步所有worktree。
详细参考:参考modules/parallel-development.md中的并行开发模块
4. Integration Patterns - MoAI-ADK Workflow Integration
4. 集成模式 - 与MoAI-ADK工作流集成
Purpose: Seamless integration with MoAI-ADK Plan-Run-Sync workflow.
Integration Points:
During Plan Phase Integration with /moai:1-plan, after SPEC creation, create the worktree using the new command with the SPEC ID. The output provides guidance for switching to the worktree using either the switch command or the shell eval pattern with the go command.
During Development Phase with /moai:2-run, worktree isolation provides a clean development environment with independent Git state preventing conflicts and automatic registry tracking.
During Sync Phase with /moai:3-sync, before PR creation run the sync command for the SPEC. After PR merge, run the clean command with the merged-only flag to remove completed worktrees.
Auto-Detection Patterns:
The system detects worktree environments by checking for the registry file in the parent directory. When detected, the SPEC ID is extracted from the current directory name. The status command with sync-check option automatically identifies worktrees that need synchronization.
Configuration Integration:
The MoAI configuration supports worktree settings including auto_create for automatic worktree creation, auto_sync for automatic synchronization, cleanup_merged for automatic cleanup of merged branches, and worktree_root for specifying the worktree directory location with project name substitution.
Detailed Reference: Refer to Integration Patterns Module at modules/integration-patterns.md
目的:与MoAI-ADK的Plan-Run-Sync工作流无缝集成。
集成点:
在与/moai:1-plan集成的规划阶段,SPEC创建完成后,使用new命令并指定SPEC ID来创建worktree。输出内容会指导你使用switch命令或配合Shell eval的go命令来切换到worktree。
在使用/moai:2-run的开发阶段,worktree隔离提供了干净的开发环境,独立的Git状态可防止冲突,并自动跟踪注册表。
在使用/moai:3-sync的同步阶段,创建PR前运行对应SPEC的sync命令。PR合并后,使用clean命令并加上merged-only标志来移除已完成的worktree。
自动检测模式:
系统会通过检查父目录中的注册表文件来检测worktree环境。检测到后,会从当前目录名称中提取SPEC ID。使用status命令并加上sync-check选项可自动识别需要同步的worktree。
配置集成:
MoAI配置支持worktree相关设置,包括auto_create(自动创建worktree)、auto_sync(自动同步)、cleanup_merged(自动清理已合并分支)和worktree_root(指定worktree目录位置,支持项目名称替换)。
详细参考:参考modules/integration-patterns.md中的集成模式模块
Advanced Implementation (10+ minutes)
高级实施(10分钟以上)
Multi-Developer Worktree Coordination
多开发者Worktree协作
Shared Worktree Registry:
Configure team worktree settings by setting the registry type to team mode and specifying a shared registry path accessible to all team members. For developer-specific worktrees within the shared environment, use the developer flag when creating worktrees to prefix entries with the developer name. The list command with all-developers flag shows worktrees from all team members, and the status command with team-overview provides a consolidated team view.
共享Worktree注册表:
通过将注册表类型设置为团队模式并指定所有团队成员均可访问的共享注册表路径,来配置团队worktree设置。在共享环境中创建开发者专属worktree时,使用developer标志为条目添加开发者名称前缀。使用list命令并加上all-developers标志可查看所有团队成员的worktree,使用status命令并加上team-overview选项可查看整合后的团队视图。
Advanced Synchronization Strategies
高级同步策略
Selective Sync Patterns:
The sync command supports selective synchronization with include and exclude patterns to sync only specific directories or files. For conflict resolution, choose between auto-resolve for simple conflicts, interactive resolution for manual conflict handling, or abort to cancel the sync operation.
选择性同步模式:
sync命令支持通过include和exclude模式进行选择性同步,仅同步特定目录或文件。对于冲突解决,可选择auto-resolve(自动解决简单冲突)、交互式解决(手动处理冲突)或abort(取消同步操作)。
Worktree Templates and Presets
Worktree模板和预设
Custom Worktree Templates:
Create worktrees with specific setups using the template flag. A frontend template might include npm install and eslint setup with pre-commit hooks. A backend template might include virtual environment creation, activation, and dependency installation. Configure custom templates through the config command by setting template-specific setup commands.
自定义Worktree模板:
使用template标志创建带有特定配置的worktree。前端模板可能包含npm install、eslint配置和提交前钩子。后端模板可能包含虚拟环境创建、激活和依赖安装。可通过config命令设置模板专属的初始化命令来配置自定义模板。
Performance Optimization
性能优化
Optimized Worktree Operations:
For faster worktree creation, use the shallow flag with a depth value for shallow clones. The background flag enables background synchronization. The parallel flag with all option enables parallel operations across all worktrees. Enable caching through configuration with cache enable and cache TTL settings for faster repeated operations.
优化后的Worktree操作:
为了加快worktree创建速度,使用shallow标志并指定深度值进行浅克隆。background标志支持后台同步。parallel标志配合all选项可在所有worktree上执行并行操作。通过配置启用缓存(cache enable)并设置缓存TTL,可加快重复操作的速度。
Works Well With
搭配使用
Commands:
- moai:1-plan - SPEC creation with automatic worktree setup
- moai:2-run - Development in isolated worktree environment
- moai:3-sync - Integration with automatic worktree sync
- moai:9-feedback - Worktree workflow improvements
Skills:
- moai-foundation-core - Parallel development patterns
- moai-workflow-project - Project management integration
- moai-workflow-spec - SPEC-driven development
- moai-git-strategy - Git workflow optimization
Tools:
- Git worktree - Native Git worktree functionality
- Rich CLI - Formatted terminal output
- Click framework - Command-line interface framework
命令:
- moai:1-plan - 创建SPEC并自动设置worktree
- moai:2-run - 在独立worktree环境中开发
- moai:3-sync - 集成时自动同步worktree
- moai:9-feedback - 改进Worktree工作流
技能:
- moai-foundation-core - 并行开发模式
- moai-workflow-project - 项目管理集成
- moai-workflow-spec - 基于SPEC的开发
- moai-git-strategy - Git工作流优化
工具:
- Git worktree - 原生Git worktree功能
- Rich CLI - 格式化终端输出
- Click framework - 命令行界面框架
Quick Decision Guide
快速决策指南
For new SPEC development, use the worktree isolation pattern with auto-setup. The primary approach is worktree isolation and the supporting pattern is integration with /moai:1-plan.
For parallel development across multiple SPECs, use multiple worktrees with shell integration. The primary approach is maintaining multiple worktrees and the supporting pattern is fast switching between them.
For team coordination in shared environments, use shared registry with developer prefixes. The primary approach is the shared registry pattern and the supporting pattern is conflict resolution.
For code review workflows, use isolated review worktrees. The primary approach is worktree isolation for reviews and the supporting pattern is clean sync after review completion.
For experimental features, use temporary worktrees with auto-cleanup. The primary approach is creating temporary worktrees and the supporting pattern is safe experimentation with automatic removal.
Module Deep Dives:
- Worktree Commands: Refer to modules/worktree-commands.md for complete CLI reference
- Worktree Management: Refer to modules/worktree-management.md for core architecture
- Parallel Development: Refer to modules/parallel-development.md for workflow patterns
- Integration Patterns: Refer to modules/integration-patterns.md for MoAI-ADK integration
- Troubleshooting: Refer to modules/troubleshooting.md for problem resolution
Full Examples: Refer to examples.md
External Resources: Refer to reference.md
对于新的SPEC开发,使用带自动设置的worktree隔离模式。主要方法是worktree隔离,配套模式是与/moai:1-plan集成。
对于跨多个SPEC的并行开发,使用多个worktree并配合Shell集成。主要方法是维护多个worktree,配套模式是快速切换。
对于共享环境中的团队协作,使用带开发者前缀的共享注册表。主要方法是共享注册表模式,配套模式是冲突解决。
对于代码评审工作流,使用独立的评审worktree。主要方法是用于评审的worktree隔离,配套模式是评审完成后的干净同步。
对于实验性功能,使用带自动清理的临时worktree。主要方法是创建临时worktree,配套模式是安全实验并自动移除。
模块深入学习:
- Worktree命令:参考modules/worktree-commands.md获取完整CLI参考
- Worktree管理:参考modules/worktree-management.md了解核心架构
- 并行开发:参考modules/parallel-development.md学习工作流模式
- 集成模式:参考modules/integration-patterns.md了解与MoAI-ADK的集成
- 故障排除:参考modules/troubleshooting.md解决问题
完整示例:参考examples.md
外部资源:参考reference.md