用于 HarmonyOS NEXT 和 ArkTS 开发,特别是处理 .ets 文件、实现 @ComponentV2 组件或调试错误时使用。基于官方标准提供开发指导,并维护分类错误日志以实现高效故障排查。
为 HarmonyOS NEXT 应用开发提供全面支持,使用 ArkTS 和 @ComponentV2 架构。本 skill 结合了:
本 skill 在以下场景自动触发:
.ets 文件(HarmonyOS ArkTS 源文件)时实现 HarmonyOS 功能或组件时:
步骤 1:查阅开发指南
加载并参考 references/development-guide.md 以获取:
步骤 2:遵循架构原则
遵守指南中的核心原则:
$r('app.xxx') 引用资源,使用 ThemeSizeTokens 常量定义尺寸步骤 3:应用命名规范
遵循命名标准:
ProductListPage.ets)Props 结尾步骤 4:代码审查
完成前,根据代码审查清单验证(development-guide.md 第 15 节)。
主动运行编译指令发现错误:参考 development-guide.md 中的完整编译命令章节 遇到错误或调试问题时:
步骤 1:优先搜索错误日志
尝试解决错误之前:
// 使用 Grep 工具在 error-log.md 中搜索类似错误模式
Grep(pattern="[错误关键词]", path="references/error-log.md", output_mode="content")
搜索内容:
步骤 2:应用已有解决方案
如果在日志中找到匹配的错误:
步骤 3:调查新错误
如果日志中不存在匹配的错误:
步骤 4:记录新解决方案
成功解决新错误后:
确定错误类别:
添加错误条目到 references/error-log.md:
使用 Edit 工具在适当类别下追加新的错误记录:
### 错误:[简短描述]
**错误信息**:
[完整的错误信息或关键代码片段]
**原因**:
[错误产生的根本原因]
**解决方案**:
[具体的解决步骤和代码示例]
**相关规范**:
[引用 development-guide.md 中的相关章节]
**记录时间**:YYYY-MM-DD
开发指南(references/development-guide.md):
错误日志(references/error-log.md):
any随着项目发展:
场景 1:创建新页面
用户:"帮我创建一个产品列表页面"
助手:
1. 加载 development-guide.md 第 2 节(项目结构)和第 4 节(MVVM)
2. 按照标准结构创建页面:
- pages/product/list/ProductListPage.ets
- pages/product/list/viewmodel/ProductListViewModel.ets
- pages/product/list/components/ProductCard.ets
3. 遵循第 3 节使用 @ComponentV2、@Param、@Local 实现
4. 参考第 10 节设置路由
场景 2:调试编译错误
用户:"编译报错:Cannot use @State with @ComponentV2"
助手:
1. 在 error-log.md 中 Grep 搜索 "Mixing V1 and V2 decorators"
2. 找到已记录的解决方案
3. 应用修复:将 @State 替换为 @Local
4. 解释 V1/V2 装饰器分离原则
场景 3:解决新错误
用户:"Navigation 跳转时报错:[NEW_ERROR_MESSAGE]"
助手:
1. Grep 搜索 error-log.md 但未找到匹配
2. 分析错误并查阅 development-guide.md 第 10 节(Navigation)
3. 识别根本原因并应用修复
4. 将新错误记录到 error-log.md 的"运行时错误"类别下
5. 通知用户:"已将此错误和解决方案记录到错误日志中"
| 任务 | 参考文件 | 章节 |
|---|---|---|
| 项目结构 | development-guide.md | 1-2 |
| @ComponentV2 使用 | development-guide.md | 3 |
| MVVM 架构 | development-guide.md | 4 |
| Navigation 路由 | development-guide.md | 10 |
| 状态管理 | development-guide.md | 11 |
| 性能优化 | development-guide.md | 12 |
| 已知错误 | error-log.md | 全部 |
记住:本 skill 在将 development-guide.md 中的结构化知识与 error-log.md 中的实践经验积累相结合时最为有效。始终先搜索后解决,始终记录新方案。