|
| 1 | +# Flutter-Skill 自动优先级配置指南 |
| 2 | + |
| 3 | +## 📋 配置概览 |
| 4 | + |
| 5 | +此配置确保 Claude Code 在处理 Flutter 项目时**自动优先使用 flutter-skill MCP 工具**。 |
| 6 | + |
| 7 | +## ✅ 已配置的文件 |
| 8 | + |
| 9 | +### 1. **SKILL.md** (项目根目录) |
| 10 | +- ✅ 增强的 YAML frontmatter(priority: high, auto_activate: true) |
| 11 | +- ✅ 扩展的中英文触发词列表(50+ 触发词) |
| 12 | +- ✅ 结构化示例(examples 字段) |
| 13 | +- ✅ 项目上下文自动检测配置 |
| 14 | + |
| 15 | +**作用:** 让 Claude Code 的 Skill 系统识别并优先推荐此工具 |
| 16 | + |
| 17 | +### 2. **docs/prompts/flutter-testing.md** (项目级) |
| 18 | +- ✅ 项目级别的 Flutter 测试上下文提示 |
| 19 | +- ✅ 决策树(帮助 Claude 选择正确工具) |
| 20 | +- ✅ 自动工作流检测 |
| 21 | +- ✅ 常见场景的响应模板 |
| 22 | + |
| 23 | +**作用:** 在此 Flutter 项目中工作时,Claude 会自动参考这些指导原则 |
| 24 | + |
| 25 | +**使用方法:** 将此文件复制到 `.claude/prompts/flutter-testing.md` 以启用项目级自动提示 |
| 26 | + |
| 27 | +### 3. **~/.claude/prompts/auto-flutter-skill.md** (全局) |
| 28 | +- ✅ 全局 Flutter 项目检测规则 |
| 29 | +- ✅ 跨项目的自动优先级配置 |
| 30 | +- ✅ 上下文记忆和主动建议机制 |
| 31 | + |
| 32 | +**作用:** 在**任何** Flutter 项目中工作时都会应用这些规则 |
| 33 | + |
| 34 | +### 4. **~/.claude/settings.json** (已存在) |
| 35 | +- ✅ MCP 服务器配置(flutter-skill 会在需要时自动启动) |
| 36 | + |
| 37 | +## 🎯 工作原理 |
| 38 | + |
| 39 | +### 检测机制 |
| 40 | + |
| 41 | +Claude Code 会在以下情况自动优先使用 flutter-skill: |
| 42 | + |
| 43 | +#### 1️⃣ **项目检测** |
| 44 | +当前目录包含: |
| 45 | +- `pubspec.yaml` (包含 flutter 依赖) |
| 46 | +- `lib/main.dart` |
| 47 | +- `ios/` 或 `android/` 目录 |
| 48 | + |
| 49 | +#### 2️⃣ **触发词检测**(中英文) |
| 50 | +用户消息包含: |
| 51 | + |
| 52 | +**英文:** |
| 53 | +- test app, test ui, verify feature, check button |
| 54 | +- iOS simulator, Android emulator |
| 55 | +- launch app, run app, start app |
| 56 | +- E2E test, integration test, UI automation |
| 57 | +- does button work?, what's on screen? |
| 58 | + |
| 59 | +**中文:** |
| 60 | +- 测试应用, 测试功能, 验证界面, 检查按钮 |
| 61 | +- iOS测试, Android测试, 模拟器测试 |
| 62 | +- 启动应用, 运行应用, 打开应用 |
| 63 | +- 集成测试, 界面测试, 自动化测试 |
| 64 | +- 按钮能用吗?, 屏幕上有什么? |
| 65 | + |
| 66 | +#### 3️⃣ **上下文记忆** |
| 67 | +如果之前的对话提到: |
| 68 | +- Flutter 项目路径 |
| 69 | +- 特定功能名称(如 "login screen") |
| 70 | +- 模拟器/设备 |
| 71 | + |
| 72 | +后续的模糊指令("test it", "check it", "测试一下")会自动使用 flutter-skill |
| 73 | + |
| 74 | +## 🧪 验证配置 |
| 75 | + |
| 76 | +### 测试 1: 基本触发 |
| 77 | +在 flutter-skill 项目目录中,向 Claude Code 发送: |
| 78 | + |
| 79 | +``` |
| 80 | +test the flutter app |
| 81 | +``` |
| 82 | + |
| 83 | +**预期:** Claude 应该调用 `launch_app()` 而不是运行 `flutter test` |
| 84 | + |
| 85 | +### 测试 2: 中文触发 |
| 86 | +``` |
| 87 | +在iOS模拟器上测试 |
| 88 | +``` |
| 89 | + |
| 90 | +**预期:** Claude 应该调用 `launch_app({ device_id: "iOS" })` |
| 91 | + |
| 92 | +### 测试 3: 模糊指令 |
| 93 | +``` |
| 94 | +测试一下 |
| 95 | +``` |
| 96 | + |
| 97 | +**预期:** |
| 98 | +- 如果已在 Flutter 项目中,应该调用 `launch_app()` 或 `inspect()` |
| 99 | +- 或询问:"您想进行 UI 测试(flutter-skill)还是单元测试(flutter test)?" |
| 100 | + |
| 101 | +### 测试 4: 自动工作流 |
| 102 | +``` |
| 103 | +verify the login feature |
| 104 | +``` |
| 105 | + |
| 106 | +**预期:** Claude 应该自动执行: |
| 107 | +1. `launch_app()` |
| 108 | +2. `inspect()` 找到登录元素 |
| 109 | +3. 询问是否使用测试凭据 |
| 110 | +4. `enter_text()` + `tap()` + `wait_for_element()` |
| 111 | + |
| 112 | +## 📊 优先级规则 |
| 113 | + |
| 114 | +| 场景 | 触发条件 | 工具选择 | |
| 115 | +|------|---------|---------| |
| 116 | +| UI 测试 | "test ui", "test screen", "测试界面" | ✅ flutter-skill | |
| 117 | +| 功能验证 | "verify feature", "check button", "验证功能" | ✅ flutter-skill | |
| 118 | +| 平台测试 | "iOS simulator", "Android", "模拟器" | ✅ flutter-skill | |
| 119 | +| 视觉调试 | "screen looks wrong", "界面不对" | ✅ flutter-skill | |
| 120 | +| 单元测试 | "test function", "test logic", "测试函数" | ❌ flutter test | |
| 121 | +| 代码分析 | "analyze code", "read file", "分析代码" | ❌ Read/Grep | |
| 122 | +| 构建应用 | "build apk", "compile", "编译" | ❌ flutter build | |
| 123 | + |
| 124 | +## 🔧 故障排查 |
| 125 | + |
| 126 | +### 问题 1: Claude 仍然不使用 flutter-skill |
| 127 | + |
| 128 | +**可能原因:** |
| 129 | +- SKILL.md 的 frontmatter 格式错误 |
| 130 | +- .claude/prompts 文件未被复制 |
| 131 | + |
| 132 | +**解决方案:** |
| 133 | +```bash |
| 134 | +# 检查 SKILL.md 格式 |
| 135 | +head -30 SKILL.md |
| 136 | + |
| 137 | +# 复制项目级提示到 .claude 目录 |
| 138 | +mkdir -p .claude/prompts |
| 139 | +cp docs/prompts/flutter-testing.md .claude/prompts/ |
| 140 | + |
| 141 | +# 重启 Claude Code(重新加载配置) |
| 142 | +``` |
| 143 | + |
| 144 | +### 问题 2: MCP 服务器未启动 |
| 145 | + |
| 146 | +**检查:** |
| 147 | +```bash |
| 148 | +# 查看 MCP 配置 |
| 149 | +cat ~/.claude/settings.json | grep -A 5 flutter-skill |
| 150 | + |
| 151 | +# 测试命令是否可用 |
| 152 | +flutter-skill-fast server --help |
| 153 | +``` |
| 154 | + |
| 155 | +### 问题 3: 全局配置未生效 |
| 156 | + |
| 157 | +**确认全局提示存在:** |
| 158 | +```bash |
| 159 | +cat ~/.claude/prompts/auto-flutter-skill.md | head -20 |
| 160 | +``` |
| 161 | + |
| 162 | +**注意:** 全局提示在任何 Flutter 项目中都应生效 |
| 163 | + |
| 164 | +## 🚀 使用示例 |
| 165 | + |
| 166 | +### 示例 1: 快速测试 |
| 167 | +``` |
| 168 | +You: 测试一下登录功能 |
| 169 | +
|
| 170 | +Claude: |
| 171 | +我将启动应用并测试登录功能。 |
| 172 | +
|
| 173 | +→ launch_app({ project_path: "." }) |
| 174 | +✅ 应用已在 iOS 模拟器启动 |
| 175 | +
|
| 176 | +→ inspect() |
| 177 | +找到元素: |
| 178 | +- email_field |
| 179 | +- password_field |
| 180 | +- login_button |
| 181 | +
|
| 182 | +→ enter_text({ key: "email_field", text: "test@example.com" }) |
| 183 | +→ enter_text({ key: "password_field", text: "password123" }) |
| 184 | +→ tap({ key: "login_button" }) |
| 185 | +→ wait_for_element({ text: "Welcome" }) |
| 186 | +
|
| 187 | +✅ 登录成功!已导航到首页 |
| 188 | +📸 已截屏保存 |
| 189 | +``` |
| 190 | + |
| 191 | +### 示例 2: 视觉调试 |
| 192 | +``` |
| 193 | +You: the button looks weird |
| 194 | +
|
| 195 | +Claude: |
| 196 | +Let me launch the app and take a screenshot to see the issue. |
| 197 | +
|
| 198 | +→ launch_app({ project_path: "." }) |
| 199 | +→ screenshot() |
| 200 | +
|
| 201 | +📸 Screenshot captured. I can see the button's styling issue... |
| 202 | +[Shows base64 image] |
| 203 | +``` |
| 204 | + |
| 205 | +### 示例 3: 上下文感知 |
| 206 | +``` |
| 207 | +You: I'm working on the checkout screen |
| 208 | +Claude: Got it, you're working on the checkout screen. |
| 209 | +
|
| 210 | +You: test it |
| 211 | +Claude: [Automatically knows you want to test the checkout screen] |
| 212 | +
|
| 213 | +→ launch_app({ project_path: "." }) |
| 214 | +→ inspect() |
| 215 | +I've launched the app and can see the checkout screen elements... |
| 216 | +``` |
| 217 | + |
| 218 | +## 📝 进阶配置 |
| 219 | + |
| 220 | +### 添加项目特定的触发词 |
| 221 | + |
| 222 | +编辑 `.claude/prompts/flutter-testing.md`,添加你的项目特定术语: |
| 223 | + |
| 224 | +```markdown |
| 225 | +## Project-Specific Triggers |
| 226 | + |
| 227 | +- "test payment flow" → launch_app + navigate to checkout |
| 228 | +- "verify cart" → launch_app + inspect cart screen |
| 229 | +``` |
| 230 | + |
| 231 | +### 自定义工作流 |
| 232 | + |
| 233 | +在项目级 `.claude/prompts/flutter-testing.md` 中添加: |
| 234 | + |
| 235 | +```markdown |
| 236 | +## Custom Workflows |
| 237 | + |
| 238 | +### Workflow: Test Complete Purchase |
| 239 | +**Trigger:** "test purchase" / "测试购买" |
| 240 | + |
| 241 | +**Steps:** |
| 242 | +1. launch_app() |
| 243 | +2. Navigate to product page |
| 244 | +3. tap({ text: "Add to Cart" }) |
| 245 | +4. tap({ text: "Checkout" }) |
| 246 | +5. Fill payment form |
| 247 | +6. Verify success |
| 248 | +``` |
| 249 | + |
| 250 | +## ⚡ 性能提示 |
| 251 | + |
| 252 | +1. **复用连接:** 如果应用已运行,使用 `connect_app()` 而不是 `launch_app()` |
| 253 | +2. **快速反馈:** 使用 `inspect()` 而不是 `screenshot()` 来查看元素 |
| 254 | +3. **热重载:** 代码改动后使用 `hot_reload()` 而不是完全重启 |
| 255 | + |
| 256 | +## 🎉 完成! |
| 257 | + |
| 258 | +配置已完成。现在在任何 Flutter 项目中,Claude Code 都会: |
| 259 | + |
| 260 | +✅ 自动识别 Flutter 项目上下文 |
| 261 | +✅ 优先使用 flutter-skill 进行 UI 测试 |
| 262 | +✅ 记住对话中的测试上下文 |
| 263 | +✅ 主动建议合适的测试方式 |
| 264 | +✅ 自动执行常见测试工作流 |
| 265 | + |
| 266 | +**试一试:** 在 Flutter 项目中发送 "测试应用" 或 "test the app" 看看效果! |
0 commit comments