ccg-workflow 1.5.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +182 -351
- package/bin/codeagent-wrapper-linux-arm64 +0 -0
- package/bin/codeagent-wrapper-windows-arm64.exe +0 -0
- package/dist/cli.mjs +13 -4
- package/dist/index.d.mts +3 -10
- package/dist/index.d.ts +3 -10
- package/dist/index.mjs +2 -2
- package/dist/shared/{ccg-workflow.DSwxPZjT.mjs → ccg-workflow.BtBr1Jpn.mjs} +955 -838
- package/package.json +1 -1
- package/templates/commands/agents/planner.md +2 -2
- package/templates/commands/agents/ui-ux-designer.md +2 -2
- package/templates/commands/analyze.md +112 -57
- package/templates/commands/backend.md +110 -51
- package/templates/commands/clean-branches.md +81 -66
- package/templates/commands/commit.md +81 -117
- package/templates/commands/debug.md +88 -86
- package/templates/commands/feat.md +62 -283
- package/templates/commands/frontend.md +110 -50
- package/templates/commands/init.md +100 -36
- package/templates/commands/optimize.md +109 -68
- package/templates/commands/review.md +106 -63
- package/templates/commands/rollback.md +86 -60
- package/templates/commands/test.md +115 -52
- package/templates/commands/workflow.md +198 -0
- package/templates/commands/worktree.md +78 -226
- package/templates/commands/bugfix.md +0 -116
- package/templates/commands/code.md +0 -257
- package/templates/commands/dev.md +0 -174
- package/templates/commands/enhance.md +0 -52
- package/templates/commands/think.md +0 -104
- package/templates/config/shared-config.md +0 -87
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: planner
|
|
3
3
|
description: 📋 任务规划师 - 使用 WBS 方法论分解功能需求为可执行任务
|
|
4
|
-
tools: Read, Write,
|
|
4
|
+
tools: Read, Write, mcp__ace-tool__search_context
|
|
5
5
|
color: blue
|
|
6
6
|
---
|
|
7
7
|
|
|
@@ -29,7 +29,7 @@ color: blue
|
|
|
29
29
|
如果需要了解现有实现,使用 ace-tool 检索:
|
|
30
30
|
|
|
31
31
|
```
|
|
32
|
-
|
|
32
|
+
mcp__ace-tool__search_context {
|
|
33
33
|
"project_root_path": "{{项目路径}}",
|
|
34
34
|
"query": "{{相关功能关键词}}"
|
|
35
35
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: ui-ux-designer
|
|
3
3
|
description: 🎨 UI/UX 设计师 - 为前端功能生成页面结构、组件拆分和交互流程设计
|
|
4
|
-
tools: Read, Write,
|
|
4
|
+
tools: Read, Write, mcp__ace-tool__search_context
|
|
5
5
|
color: magenta
|
|
6
6
|
---
|
|
7
7
|
|
|
@@ -30,7 +30,7 @@ color: magenta
|
|
|
30
30
|
如果项目已有组件库,使用 ace-tool 检索:
|
|
31
31
|
|
|
32
32
|
```
|
|
33
|
-
|
|
33
|
+
mcp__ace-tool__search_context {
|
|
34
34
|
"project_root_path": "{{项目路径}}",
|
|
35
35
|
"query": "可复用的 UI 组件、按钮、表单、卡片、布局组件"
|
|
36
36
|
}
|
|
@@ -1,79 +1,134 @@
|
|
|
1
1
|
---
|
|
2
|
-
description:
|
|
2
|
+
description: '多模型技术分析(并行执行):Codex 后端视角 + Gemini 前端视角,交叉验证后综合见解'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
# Analyze - 多模型技术分析
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
`/analyze <QUESTION_OR_TASK>`
|
|
7
|
+
使用双模型并行分析,交叉验证得出综合技术见解。**仅分析,不修改代码。**
|
|
9
8
|
|
|
10
|
-
##
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
## 使用方法
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
/analyze <分析问题或任务>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 多模型调用语法
|
|
16
|
+
|
|
17
|
+
**必须使用 heredoc 语法调用外部模型**:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
codeagent-wrapper --backend <codex|gemini> - $PWD <<'EOF'
|
|
21
|
+
ROLE_FILE: ~/.claude/.ccg/prompts/<model>/<role>.md
|
|
22
|
+
<TASK>
|
|
23
|
+
任务描述
|
|
24
|
+
</TASK>
|
|
25
|
+
OUTPUT: 期望输出格式
|
|
26
|
+
EOF
|
|
27
|
+
```
|
|
14
28
|
|
|
15
29
|
## 你的角色
|
|
16
|
-
You are the **Analysis Coordinator** orchestrating multi-model research. You direct:
|
|
17
|
-
1. **ace-tool** – for codebase context retrieval
|
|
18
|
-
2. **Configured Models** – for comprehensive multi-perspective analysis
|
|
19
|
-
3. **Claude (Self)** – for synthesizing insights
|
|
20
30
|
|
|
21
|
-
|
|
31
|
+
你是**分析协调者**,编排多模型分析流程:
|
|
32
|
+
- **ace-tool** – 代码上下文检索
|
|
33
|
+
- **Codex** – 后端/系统视角(**后端权威**)
|
|
34
|
+
- **Gemini** – 前端/用户视角(**前端权威**)
|
|
35
|
+
- **Claude (自己)** – 综合见解
|
|
22
36
|
|
|
23
|
-
|
|
37
|
+
---
|
|
24
38
|
|
|
25
|
-
|
|
26
|
-
- `project_root_path`: Project root directory absolute path
|
|
27
|
-
- `query`: Natural language description of what to analyze
|
|
28
|
-
5. Identify key files, patterns, and architecture
|
|
39
|
+
## 执行工作流
|
|
29
40
|
|
|
30
|
-
|
|
41
|
+
**分析任务**:$ARGUMENTS
|
|
31
42
|
|
|
32
|
-
|
|
43
|
+
### 🔍 阶段 1:上下文检索
|
|
33
44
|
|
|
34
|
-
|
|
45
|
+
`[模式:研究]`
|
|
35
46
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
47
|
+
1. 调用 `mcp__ace-tool__search_context` 检索相关代码
|
|
48
|
+
2. 识别分析范围和关键组件
|
|
49
|
+
3. 列出已知约束和假设
|
|
50
|
+
|
|
51
|
+
### 💡 阶段 2:并行分析
|
|
52
|
+
|
|
53
|
+
`[模式:分析]`
|
|
41
54
|
|
|
42
|
-
|
|
43
|
-
for model in $ALL_MODELS; do
|
|
44
|
-
codeagent-wrapper --backend $model - $PROJECT_DIR <<'EOF' &
|
|
45
|
-
ROLE_FILE: ~/.claude/.ccg/prompts/$model/analyzer.md
|
|
55
|
+
**并行调用两个模型**:
|
|
46
56
|
|
|
57
|
+
**执行步骤**:
|
|
58
|
+
1. 在**同一个 Bash 调用**中启动两个后台进程(不加 wait,立即返回):
|
|
59
|
+
```bash
|
|
60
|
+
codeagent-wrapper --backend codex - $PWD <<'EOF' &
|
|
61
|
+
ROLE_FILE: ~/.claude/.ccg/prompts/codex/analyzer.md
|
|
47
62
|
<TASK>
|
|
48
|
-
|
|
49
|
-
Context:
|
|
63
|
+
分析需求: $ARGUMENTS
|
|
64
|
+
Context: <阶段1检索到的上下文>
|
|
50
65
|
</TASK>
|
|
66
|
+
OUTPUT: 技术可行性、架构影响、性能考量
|
|
67
|
+
EOF
|
|
51
68
|
|
|
52
|
-
|
|
69
|
+
codeagent-wrapper --backend gemini - $PWD <<'EOF' &
|
|
70
|
+
ROLE_FILE: ~/.claude/.ccg/prompts/gemini/analyzer.md
|
|
71
|
+
<TASK>
|
|
72
|
+
分析需求: $ARGUMENTS
|
|
73
|
+
Context: <阶段1检索到的上下文>
|
|
74
|
+
</TASK>
|
|
75
|
+
OUTPUT: UI/UX 影响、用户体验、视觉设计考量
|
|
53
76
|
EOF
|
|
54
|
-
done
|
|
55
|
-
wait # 等待所有后台任务完成
|
|
56
77
|
```
|
|
78
|
+
2. 使用 `TaskOutput` 监控并获取 2 个模型的分析结果。
|
|
79
|
+
|
|
80
|
+
**⚠️ 强制规则:必须等待 TaskOutput 返回两个模型的完整结果后才能进入下一阶段,禁止跳过或提前继续!**
|
|
81
|
+
|
|
82
|
+
### 🔀 阶段 3:交叉验证
|
|
83
|
+
|
|
84
|
+
`[模式:验证]`
|
|
85
|
+
|
|
86
|
+
1. 对比双方分析结果
|
|
87
|
+
2. 识别:
|
|
88
|
+
- **一致观点**(强信号)
|
|
89
|
+
- **分歧点**(需权衡)
|
|
90
|
+
- **互补见解**(各自领域洞察)
|
|
91
|
+
3. 按信任规则权衡:后端以 Codex 为准,前端以 Gemini 为准
|
|
92
|
+
|
|
93
|
+
### 📊 阶段 4:综合输出
|
|
94
|
+
|
|
95
|
+
`[模式:总结]`
|
|
96
|
+
|
|
97
|
+
```markdown
|
|
98
|
+
## 🔬 技术分析:<主题>
|
|
99
|
+
|
|
100
|
+
### 一致观点(强信号)
|
|
101
|
+
1. <双方都认同的点>
|
|
102
|
+
|
|
103
|
+
### 分歧点(需权衡)
|
|
104
|
+
| 议题 | Codex 观点 | Gemini 观点 | 建议 |
|
|
105
|
+
|------|------------|-------------|------|
|
|
106
|
+
|
|
107
|
+
### 核心结论
|
|
108
|
+
<1-2 句话总结>
|
|
109
|
+
|
|
110
|
+
### 推荐方案
|
|
111
|
+
**首选**:<方案>
|
|
112
|
+
- 理由 / 风险 / 缓解措施
|
|
113
|
+
|
|
114
|
+
### 后续行动
|
|
115
|
+
1. [ ] <具体步骤>
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## 适用场景
|
|
121
|
+
|
|
122
|
+
| 场景 | 示例 |
|
|
123
|
+
|------|------|
|
|
124
|
+
| 技术选型 | "比较 Redux vs Zustand" |
|
|
125
|
+
| 架构评估 | "评估微服务拆分方案" |
|
|
126
|
+
| 性能分析 | "分析 API 响应慢的原因" |
|
|
127
|
+
| 安全审计 | "评估认证模块安全性" |
|
|
128
|
+
|
|
129
|
+
## 关键规则
|
|
57
130
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
3. Evaluate trade-offs objectively
|
|
63
|
-
4. Weight opinions based on model strengths
|
|
64
|
-
|
|
65
|
-
### Step 4: 综合输出
|
|
66
|
-
Present unified analysis combining all perspectives.
|
|
67
|
-
|
|
68
|
-
## 输出格式
|
|
69
|
-
1. **Configuration** – models used for analysis
|
|
70
|
-
2. **Context Overview** – relevant codebase elements
|
|
71
|
-
3. **Model Perspectives** – analysis from each configured model
|
|
72
|
-
4. **Synthesis** – combined insights and trade-offs
|
|
73
|
-
5. **Recommendations** – actionable next steps
|
|
74
|
-
|
|
75
|
-
## 注意事项
|
|
76
|
-
- This command is for analysis only, no code changes
|
|
77
|
-
- **Use `run_in_background: true` for parallel execution** to avoid blocking
|
|
78
|
-
- 多模型结果交叉验证,取长补短
|
|
79
|
-
- Use HEREDOC syntax (`<<'EOF'`) to avoid shell escaping issues
|
|
131
|
+
1. **仅分析不修改** – 本命令不执行任何代码变更
|
|
132
|
+
2. **使用后台进程 `&` + `TaskOutput` 获取结果**
|
|
133
|
+
3. **必须等待所有模型返回完整结果后才能进入下一阶段**,禁止跳过或提前继续
|
|
134
|
+
4. **信任规则** – 后端以 Codex 为准,前端以 Gemini 为准
|
|
@@ -1,70 +1,129 @@
|
|
|
1
1
|
---
|
|
2
|
-
description:
|
|
2
|
+
description: '后端专项工作流(研究→构思→计划→执行→优化→评审),Codex主导'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
# Backend - 后端专项开发
|
|
6
6
|
|
|
7
|
-
##
|
|
8
|
-
|
|
7
|
+
## 使用方法
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
/backend <后端任务描述>
|
|
11
|
+
```
|
|
9
12
|
|
|
10
13
|
## 上下文
|
|
11
|
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
+
|
|
15
|
+
- 后端任务:$ARGUMENTS
|
|
16
|
+
- Codex 主导,Gemini 辅助参考
|
|
17
|
+
- 适用:API设计、算法实现、数据库优化、业务逻辑
|
|
14
18
|
|
|
15
19
|
## 你的角色
|
|
16
|
-
You are the **Backend Orchestrator** specializing in server-side logic. You coordinate:
|
|
17
|
-
1. **ace-tool** – for retrieving existing backend code and architecture
|
|
18
|
-
2. **Configured Backend Models** – for generating logic, algorithms, and API implementations
|
|
19
|
-
3. **Claude (Self)** – for refactoring prototypes into production code
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
你是**后端编排者**,协调多模型完成服务端任务(研究 → 构思 → 计划 → 执行 → 优化 → 评审),用中文协助用户。
|
|
22
|
+
|
|
23
|
+
**协作模型**:
|
|
24
|
+
- **Codex** – 后端逻辑、算法(**后端权威,可信赖**)
|
|
25
|
+
- **Gemini** – 前端视角(**后端意见仅供参考**)
|
|
26
|
+
- **Claude (自己)** – 编排、计划、执行、交付
|
|
27
|
+
|
|
28
|
+
[沟通守则]
|
|
29
|
+
|
|
30
|
+
1. 响应以模式标签 `[模式:X]` 开始,初始为 `[模式:研究]`
|
|
31
|
+
2. 严格按 `研究 → 构思 → 计划 → 执行 → 优化 → 评审` 顺序流转
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## 多模型调用语法
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# Codex 调用(后端主力)
|
|
39
|
+
~/.claude/bin/codeagent-wrapper --backend codex - "$PWD" <<'EOF'
|
|
40
|
+
[角色提示词内容]
|
|
41
|
+
|
|
42
|
+
[任务内容]
|
|
43
|
+
EOF
|
|
44
|
+
|
|
45
|
+
# Gemini 调用(前端参考)
|
|
46
|
+
~/.claude/bin/codeagent-wrapper --backend gemini - "$PWD" <<'EOF'
|
|
47
|
+
[任务内容]
|
|
48
|
+
EOF
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 核心工作流
|
|
54
|
+
|
|
55
|
+
### 🔍 阶段 1:研究
|
|
56
|
+
|
|
57
|
+
`[模式:研究]` - 理解需求并收集上下文
|
|
22
58
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
- `project_root_path`: Project root directory absolute path
|
|
26
|
-
- `query`: Natural language description of the backend task
|
|
27
|
-
2. Identify API patterns, data models, services, and dependencies
|
|
59
|
+
1. 检索现有 API、数据模型、服务架构
|
|
60
|
+
2. 需求完整性评分(0-10 分):≥7 继续,<7 停止补充
|
|
28
61
|
|
|
29
|
-
###
|
|
62
|
+
### 💡 阶段 2:构思
|
|
30
63
|
|
|
31
|
-
|
|
64
|
+
`[模式:构思]` - Codex 主导分析
|
|
65
|
+
|
|
66
|
+
**调用示例**:
|
|
32
67
|
|
|
33
68
|
```bash
|
|
34
|
-
codeagent-wrapper --backend
|
|
35
|
-
|
|
69
|
+
~/.claude/bin/codeagent-wrapper --backend codex - "$PWD" <<'EOF'
|
|
70
|
+
你是后端分析专家,擅长 API 设计、算法、数据库优化。
|
|
36
71
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
72
|
+
任务:分析以下后端需求,提供设计方案
|
|
73
|
+
- API 接口设计
|
|
74
|
+
- 数据模型结构
|
|
75
|
+
- 性能与安全考虑
|
|
76
|
+
- 错误处理策略
|
|
41
77
|
|
|
42
|
-
|
|
78
|
+
需求:[具体任务描述]
|
|
43
79
|
EOF
|
|
44
80
|
```
|
|
45
81
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
2
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
82
|
+
**⚠️ 等待 Codex 返回后继续**
|
|
83
|
+
|
|
84
|
+
输出方案(至少 2 个),等待用户选择。
|
|
85
|
+
|
|
86
|
+
### 📋 阶段 3:计划
|
|
87
|
+
|
|
88
|
+
`[模式:计划]` - Codex 主导规划
|
|
89
|
+
|
|
90
|
+
调用 Codex(`architect.md`)→ 文件结构、函数/类设计、依赖
|
|
91
|
+
|
|
92
|
+
**⚠️ 等待 Codex 返回后继续**
|
|
93
|
+
|
|
94
|
+
Claude 综合规划,请求用户批准后存入 `.claude/plan/任务名.md`
|
|
95
|
+
|
|
96
|
+
### ⚡ 阶段 4:执行
|
|
97
|
+
|
|
98
|
+
`[模式:执行]` - 代码开发
|
|
99
|
+
|
|
100
|
+
- 严格按批准的计划实施
|
|
101
|
+
- 遵循项目现有代码规范
|
|
102
|
+
- 确保错误处理、安全性、性能优化
|
|
103
|
+
|
|
104
|
+
### 🚀 阶段 5:优化
|
|
105
|
+
|
|
106
|
+
`[模式:优化]` - Codex 主导审查
|
|
107
|
+
|
|
108
|
+
调用 Codex(`reviewer.md`)→ 安全性、性能、错误处理、API规范
|
|
109
|
+
|
|
110
|
+
**⚠️ 等待 Codex 返回后继续**
|
|
111
|
+
|
|
112
|
+
整合审查意见,用户确认后执行优化。
|
|
113
|
+
|
|
114
|
+
### ✅ 阶段 6:评审
|
|
115
|
+
|
|
116
|
+
`[模式:评审]` - 最终评估
|
|
117
|
+
|
|
118
|
+
- 对照计划检查完成情况
|
|
119
|
+
- 运行测试验证功能
|
|
120
|
+
- 报告问题与建议
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## 关键规则
|
|
125
|
+
|
|
126
|
+
1. **Codex 后端意见可信赖**
|
|
127
|
+
2. **Gemini 后端意见仅供参考**
|
|
128
|
+
3. 外部模型对文件系统**零写入权限**
|
|
129
|
+
4. Claude 负责所有代码写入和文件操作
|
|
@@ -1,102 +1,117 @@
|
|
|
1
1
|
---
|
|
2
|
-
description:
|
|
3
|
-
allowed-tools: Read(**), Exec(git fetch, git config, git branch, git remote, git push, git for-each-ref, git log), Write()
|
|
4
|
-
argument-hint: [--base <branch>] [--stale <days>] [--remote] [--force] [--dry-run] [--yes]
|
|
5
|
-
# examples:
|
|
6
|
-
# - /git-cleanBranches --dry-run
|
|
7
|
-
# - /git-cleanBranches --base release/v2.1 --stale 90
|
|
8
|
-
# - /git-cleanBranches --remote --yes
|
|
2
|
+
description: '清理 Git 分支:安全清理已合并或过期分支,默认 dry-run 模式'
|
|
9
3
|
---
|
|
10
4
|
|
|
11
|
-
#
|
|
5
|
+
# Clean-Branches - 清理 Git 分支
|
|
12
6
|
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
安全识别并清理已合并或长期未更新的分支。
|
|
8
|
+
|
|
9
|
+
## 使用方法
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
/clean-branches [options]
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 选项
|
|
16
|
+
|
|
17
|
+
| 选项 | 说明 |
|
|
18
|
+
|------|------|
|
|
19
|
+
| `--base <branch>` | 基准分支(默认 main/master) |
|
|
20
|
+
| `--stale <days>` | 清理超过 N 天未更新的分支 |
|
|
21
|
+
| `--remote` | 同时清理远程分支 |
|
|
22
|
+
| `--dry-run` | 只预览,不执行(**默认**) |
|
|
23
|
+
| `--yes` | 跳过确认直接删除 |
|
|
24
|
+
| `--force` | 强制删除未合并分支 |
|
|
15
25
|
|
|
16
26
|
---
|
|
17
27
|
|
|
18
|
-
##
|
|
28
|
+
## 执行工作流
|
|
19
29
|
|
|
20
|
-
|
|
21
|
-
# [最安全] 预览将要清理的分支,不执行任何删除
|
|
22
|
-
/git-cleanBranches --dry-run
|
|
30
|
+
### 🔍 阶段 1:预检
|
|
23
31
|
|
|
24
|
-
|
|
25
|
-
/git-cleanBranches --stale 90
|
|
32
|
+
`[模式:准备]`
|
|
26
33
|
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
1. 同步远端:`git fetch --all --prune`
|
|
35
|
+
2. 读取保护分支配置
|
|
36
|
+
3. 确定基准分支
|
|
29
37
|
|
|
30
|
-
|
|
31
|
-
/git-cleanBranches --force outdated-feature
|
|
32
|
-
```
|
|
38
|
+
### 📋 阶段 2:分析识别
|
|
33
39
|
|
|
34
|
-
|
|
40
|
+
`[模式:分析]`
|
|
35
41
|
|
|
36
|
-
|
|
37
|
-
- `--
|
|
38
|
-
- `--remote`:同时清理远程已合并/过期的分支。
|
|
39
|
-
- `--dry-run`:**默认行为**。仅列出将要删除的分支,不执行任何操作。
|
|
40
|
-
- `--yes`:跳过逐一确认的步骤,直接删除所有已识别的分支(适合 CI/CD)。
|
|
41
|
-
- `--force`:使用 `-D` 强制删除本地分支(即使未合并)。
|
|
42
|
+
**已合并分支**:
|
|
43
|
+
- 已完全合并到 `--base` 的分支
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
**过期分支**(如指定 `--stale`):
|
|
46
|
+
- 最后提交在 N 天前的分支
|
|
44
47
|
|
|
45
|
-
|
|
48
|
+
**排除**:
|
|
49
|
+
- 从待清理列表中移除保护分支
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
- **更新信息**:自动执行 `git fetch --all --prune`,确保分支状态最新。
|
|
49
|
-
- **读取保护分支**:从 Git 配置读取不应被清理的分支列表(见下文“Configuration”)。
|
|
50
|
-
- **确定基准**:使用 `--base` 参数或自动识别的 `main`/`master` 作为比较基准。
|
|
51
|
+
### 📊 阶段 3:报告预览
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
- **已合并分支**:找出已完全合并到 `--base` 的本地(及远程,如加 `--remote`)分支。
|
|
54
|
-
- **过期分支**:如指定 `--stale <days>`,找出最后一次提交在 N 天前的分支。
|
|
55
|
-
- **排除保护分支**:从待清理列表中移除所有已配置的保护分支。
|
|
53
|
+
`[模式:报告]`
|
|
56
54
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
- 若无 `--yes` 参数,**命令到此结束**,等待用户确认后再次执行(不带 `--dry-run`)。
|
|
55
|
+
```markdown
|
|
56
|
+
## 将要删除的分支
|
|
60
57
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
- 本地用 `git branch -d <branch>`;远程用 `git push origin --delete <branch>`。
|
|
65
|
-
- 若指定 `--force`,本地删除会改用 `git branch -D <branch>`。
|
|
58
|
+
### 已合并分支
|
|
59
|
+
- feature/old-feature (合并于 3 天前)
|
|
60
|
+
- bugfix/fixed-issue (合并于 7 天前)
|
|
66
61
|
|
|
67
|
-
|
|
62
|
+
### 过期分支
|
|
63
|
+
- experiment/old-test (最后更新 90 天前)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### ✅ 阶段 4:执行清理
|
|
68
67
|
|
|
69
|
-
|
|
68
|
+
`[模式:执行]`
|
|
70
69
|
|
|
71
|
-
|
|
70
|
+
仅在不带 `--dry-run` 且确认后执行:
|
|
72
71
|
|
|
73
72
|
```bash
|
|
74
|
-
#
|
|
75
|
-
git
|
|
73
|
+
# 本地分支
|
|
74
|
+
git branch -d <branch>
|
|
76
75
|
|
|
77
|
-
#
|
|
76
|
+
# 远程分支(如果 --remote)
|
|
77
|
+
git push origin --delete <branch>
|
|
78
|
+
|
|
79
|
+
# 强制删除(如果 --force)
|
|
80
|
+
git branch -D <branch>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 保护分支配置
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# 添加保护分支
|
|
89
|
+
git config --add branch.cleanup.protected develop
|
|
78
90
|
git config --add branch.cleanup.protected 'release/*'
|
|
79
91
|
|
|
80
|
-
#
|
|
92
|
+
# 查看保护分支
|
|
81
93
|
git config --get-all branch.cleanup.protected
|
|
82
94
|
```
|
|
83
95
|
|
|
84
96
|
---
|
|
85
97
|
|
|
86
|
-
##
|
|
98
|
+
## 示例
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# 预览将清理的分支
|
|
102
|
+
/clean-branches --dry-run
|
|
87
103
|
|
|
88
|
-
|
|
89
|
-
-
|
|
90
|
-
- **谨慎 `--force`**:除非你百分百确定某个未合并分支是无用功,否则不要强制删除。
|
|
91
|
-
- **团队协作**:在清理共享的远程分支前,先在团队频道通知一声。
|
|
92
|
-
- **定期运行**:每月或每季度运行一次,保持仓库清爽。
|
|
104
|
+
# 清理已合并且超过 90 天未动的分支
|
|
105
|
+
/clean-branches --stale 90
|
|
93
106
|
|
|
94
|
-
|
|
107
|
+
# 清理已合并到 release/v2.1 的分支
|
|
108
|
+
/clean-branches --base release/v2.1 --remote --yes
|
|
109
|
+
```
|
|
95
110
|
|
|
96
|
-
##
|
|
111
|
+
## 最佳实践
|
|
97
112
|
|
|
98
|
-
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
113
|
+
1. **优先 dry-run** – 先预览再执行
|
|
114
|
+
2. **活用 --base** – 适配 release 工作流
|
|
115
|
+
3. **谨慎 --force** – 除非确定无用
|
|
116
|
+
4. **团队协作** – 清理远程分支前先通知
|
|
117
|
+
5. **定期运行** – 每月/季度一次保持清爽
|