name: gemini-plan description: 使用Gemini的推理生成Claude可执行的实现计划 argument-hint: <任务描述> [–context <文件>] [–output <路径>] allowed-tools: Read, Bash, Glob
Gemini 计划命令
生成结构化的实现计划,使用Gemini CLI。计划格式化为供Claude执行,具有清晰的任务分解、文件修改和序列排序。
用法
/google-ecosystem:gemini-plan <task-description> [options]
参数
$ARGUMENTS(必需): 描述您想要实现的内容--context <glob>(可选): 包含上下文的文件模式 (例如src/**/*.ts)--output <path>(可选): 计划输出路径 (默认:docs/ai-artifacts/plans/)--pro(可选): 使用Gemini Pro进行复杂规划 (默认: Flash)
示例
/google-ecosystem:gemini-plan "Add user authentication with JWT"/google-ecosystem:gemini-plan "Refactor database layer to use repository pattern" --context "src/db/**"/google-ecosystem:gemini-plan "Implement dark mode toggle" --output ./plans//google-ecosystem:gemini-plan "Migrate from REST to GraphQL" --pro
何时使用
当您需要时使用此命令:
- 规划复杂的多文件更改
- 希望获得“第二大脑”对实现方法的视角
- 需要将大型功能分解为可操作的步骤
- 验证自己的实现计划
- 获取替代方法以考虑
理念:“Claude协调,Gemini规划”
Gemini的不同推理方法通常提供:
- 替代的架构视角
- Claude可能错过的边缘情况
- 实现步骤的不同排序
- 对潜在问题的新鲜视角
执行
步骤 1: 解析参数
task_description="$ARGUMENTS"
context_pattern=""
output_dir="docs/ai-artifacts/plans"
model="gemini-2.5-flash"
# 解析可选标志
while [[ $# -gt 0 ]]; do
case $1 in
--context)
context_pattern="$2"
shift 2
;;
--output)
output_dir="$2"
shift 2
;;
--pro)
model="gemini-2.5-pro"
shift
;;
*)
shift
;;
esac
done
步骤 2: 收集上下文
# 读取CLAUDE.md以获取项目约定
claude_context=""
if [ -f "CLAUDE.md" ]; then
claude_context=$(cat CLAUDE.md)
fi
# 收集指定的上下文文件
file_context=""
if [ -n "$context_pattern" ]; then
file_context=$(find . -path "$context_pattern" -type f | xargs cat 2>/dev/null | head -c 500000)
fi
步骤 3: 构建规划提示
prompt="PLANNING MODE: Generate an implementation plan for Claude Code to execute.
## Task
$task_description
## Project Context (from CLAUDE.md)
$claude_context
## Relevant Code Context
$file_context
## Instructions
Generate a detailed implementation plan with the following structure:
### 1. Summary
Brief description of the approach (2-3 sentences)
### 2. Prerequisites
- Dependencies to install
- Configuration changes needed
- Files to read/understand first
### 3. Implementation Tasks
Numbered list of specific, actionable tasks:
1. [FILE: path/to/file.ts] Description of change
2. [FILE: path/to/another.ts] Description of change
...
### 4. File Modifications
Table format:
| File | Action | Description |
| --- | --- | --- |
| path/to/file.ts | CREATE/MODIFY/DELETE | What changes |
### 5. Sequence Order
Which tasks depend on others, what order to execute
### 6. Testing Strategy
How to verify the implementation works
### 7. Potential Risks
- Risk 1: Mitigation
- Risk 2: Mitigation
### 8. Recommendations for Claude
Specific guidance for Claude when executing this plan
Format the output as structured markdown that another AI agent can parse and execute."
步骤 4: 执行规划
result=$(echo "$prompt" | gemini "$(cat)" --output-format json -m "$model")
步骤 5: 解析结果
response=$(echo "$result" | jq -r '.response // "Planning failed"')
total_tokens=$(echo "$result" | jq '.stats.models | to_entries | map(.value.tokens.total) | add // 0')
model_used=$(echo "$result" | jq -r '.stats.models | keys[0] // "unknown"')
步骤 6: 生成计划文档
创建结构化的markdown计划:
---
generated-by: gemini-cli
model: {model_used}
timestamp: {ISO8601}
tokens: {total_tokens}
task: "{task_description}"
---
# 实现计划
## 机器可读摘要
```json
{
"type": "plan",
"task": "{task_description}",
"tokens_used": {total_tokens},
"model": "{model_used}",
"files_to_modify": [
"path/to/file1.ts",
"path/to/file2.ts"
],
"estimated_complexity": "low|medium|high"
}
```
{response}
---
*由Gemini CLI通过`/gemini-plan`命令生成*
*执行前请审查和验证*
步骤 7: 保存计划
mkdir -p "$output_dir"
timestamp=$(date -u +"%Y-%m-%dT%H-%M-%SZ")
# 从任务描述创建slug
slug=$(echo "$task_description" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | head -c 50)
output_file="$output_dir/plan-${slug}-${timestamp}.md"
echo "$plan" > "$output_file"
echo "Plan saved to: $output_file"
输出格式
计划包括用于机器解析的YAML前标题:
- generated-by: 总是 “gemini-cli”
- model: 使用的Gemini模型
- timestamp: ISO 8601格式
- tokens: 总消耗的token
- task: 原始任务描述
与Claude集成
生成计划后:
- 审查: Claude从
docs/ai-artifacts/plans/读取计划 - 验证: Claude根据项目约定检查计划
- 执行: Claude按序列实现任务
- 验证: Claude运行测试按照测试策略
计划质量检查清单
好的计划应具备:
- [ ] 清晰、原子的任务描述
- [ ] 特定的文件路径 (而非 “组件文件”)
- [ ] 逻辑序列并注明依赖关系
- [ ] 用于验证的测试策略
- [ ] 风险评估及缓解措施
笔记
- 默认使用Flash模型 (Pro用于
--pro标志) - 自动包含CLAUDE.md上下文
- 计划保存到
docs/ai-artifacts/plans/(git追踪) - 执行前请审查计划
- 计划是建议 - Claude应根据项目约定验证