Skip to content

Commit 354826e

Browse files
authored
Merge pull request #16 from hu-qi/skill-modernization-clean
Modernize HarmonyOS agent skill packaging
2 parents f9dd03e + 5e95b4b commit 354826e

20 files changed

Lines changed: 695 additions & 22 deletions

.github/workflows/build-dist.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Build dist
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'harmonyos-development/**'
7+
- 'scripts/build-dist.sh'
8+
- 'scripts/validate-skill.sh'
9+
- 'scripts/check-frontmatter.py'
10+
- '.github/workflows/build-dist.yml'
11+
push:
12+
branches:
13+
- main
14+
paths:
15+
- 'harmonyos-development/**'
16+
- 'scripts/build-dist.sh'
17+
- 'scripts/validate-skill.sh'
18+
- 'scripts/check-frontmatter.py'
19+
- '.github/workflows/build-dist.yml'
20+
- '!dist/**'
21+
workflow_dispatch:
22+
23+
permissions:
24+
contents: write
25+
26+
concurrency:
27+
group: build-dist-${{ github.ref }}
28+
cancel-in-progress: true
29+
30+
jobs:
31+
build-dist:
32+
runs-on: ubuntu-latest
33+
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v4
37+
with:
38+
persist-credentials: true
39+
40+
- name: Validate skill
41+
run: bash scripts/validate-skill.sh
42+
43+
- name: Build dist
44+
run: bash scripts/build-dist.sh
45+
46+
- name: Commit generated dist
47+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
48+
run: |
49+
if git diff --quiet -- dist; then
50+
echo "dist is already up to date."
51+
exit 0
52+
fi
53+
54+
git config user.name "github-actions[bot]"
55+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
56+
git add dist
57+
git commit -m "chore: build dist [skip ci]"
58+
git push
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
cases:
2+
- id: objectlink-vs-state
3+
prompt: "解释 ArkUI 中 ObjectLink 是什么,什么时候用它代替 State?"
4+
must_include:
5+
- "Observed"
6+
- "ObjectLink"
7+
- "父子组件"
8+
- "对象属性"
9+
must_not_include:
10+
- "useState"
11+
- "React Hook"
12+
13+
- id: api24-production-default
14+
prompt: "帮我写一个生产可用的鸿蒙相机功能方案。"
15+
must_include:
16+
- "API 24"
17+
- "生产"
18+
- "module.json5"
19+
must_not_include:
20+
- "默认使用 API 26"
21+
- "HarmonyOS 7 Beta 默认"
22+
23+
- id: api26-preview-boundary
24+
prompt: "HarmonyOS 7 / API 26 适配要注意什么?"
25+
must_include:
26+
- "预览"
27+
- "Beta"
28+
- "API 26"
29+
- "适配"
30+
must_not_include:
31+
- "API 24 默认使用 API 26"
32+
33+
- id: stage-model-new-app
34+
prompt: "新建鸿蒙应用应该用 FA 模型还是 Stage 模型?"
35+
must_include:
36+
- "Stage"
37+
- "FA"
38+
- "legacy"
39+
must_not_include:
40+
- "新项目优先 FA"
41+
42+
- id: permission-camera
43+
prompt: "ArkTS 里申请相机权限怎么写?"
44+
must_include:
45+
- "module.json5"
46+
- "ohos.permission.CAMERA"
47+
- "requestPermissionsFromUser"
48+
must_not_include:
49+
- "AndroidManifest.xml"
50+
51+
- id: lazyforeach-performance
52+
prompt: "鸿蒙大列表卡顿怎么优化?"
53+
must_include:
54+
- "LazyForEach"
55+
- "稳定 key"
56+
- "渲染"
57+
must_not_include:
58+
- "RecyclerView"
59+
60+
- id: arkts-strict-review
61+
prompt: "帮我 review 一段 ArkTS 代码,看看有没有类型问题。"
62+
must_include:
63+
- "strict"
64+
- "类型"
65+
- "ArkTS"
66+
must_not_include:
67+
- "any 随便用"
68+
69+
- id: build-error-routing
70+
prompt: "DevEco Studio 编译报错,我应该先提供哪些信息?"
71+
must_include:
72+
- "DevEco Studio"
73+
- "compileSdkVersion"
74+
- "module.json5"
75+
- "oh-package.json5"
76+
must_not_include:
77+
- "只重启电脑"
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
@Observed
2+
export class TodoItem {
3+
id: string;
4+
title: string;
5+
done: boolean;
6+
7+
constructor(id: string, title: string, done: boolean = false) {
8+
this.id = id;
9+
this.title = title;
10+
this.done = done;
11+
}
12+
}
13+
14+
@Component
15+
struct TodoRow {
16+
@ObjectLink item: TodoItem;
17+
18+
build() {
19+
Row() {
20+
Checkbox()
21+
.select(this.item.done)
22+
.onChange((checked: boolean) => {
23+
this.item.done = checked;
24+
})
25+
Text(this.item.title)
26+
.fontSize(16)
27+
.margin({ left: 8 })
28+
}
29+
.width('100%')
30+
}
31+
}
32+
33+
@Entry
34+
@Component
35+
struct TodoListPage {
36+
@State items: TodoItem[] = [
37+
new TodoItem('1', 'Review ArkTS strict typing'),
38+
new TodoItem('2', 'Use stable keys')
39+
];
40+
41+
build() {
42+
List() {
43+
LazyForEach(this.items, (item: TodoItem) => {
44+
ListItem() {
45+
TodoRow({ item })
46+
}
47+
}, (item: TodoItem) => item.id)
48+
}
49+
.width('100%')
50+
.height('100%')
51+
}
52+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { abilityAccessCtrl, common, Permissions } from '@kit.AbilityKit';
2+
3+
const PERMISSION: Permissions = 'ohos.permission.CAMERA';
4+
5+
export async function requestCameraPermission(context: common.UIAbilityContext): Promise<boolean> {
6+
const atManager = abilityAccessCtrl.createAtManager();
7+
const result = await atManager.requestPermissionsFromUser(context, [PERMISSION]);
8+
return result.authResults.length > 0 && result.authResults[0] === 0;
9+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Recipe: Debug HarmonyOS Build Errors
2+
3+
Use this recipe when the user shares a DevEco Studio, Hvigor, ohpm, ArkTS, signing, or packaging error.
4+
5+
## Steps
6+
7+
1. Identify the error type:
8+
- ArkTS compile error
9+
- Hvigor build error
10+
- ohpm dependency error
11+
- SDK version mismatch
12+
- module or app configuration error
13+
- signing or certificate error
14+
- native / NAPI error
15+
2. Confirm project baseline:
16+
- DevEco Studio version
17+
- compile SDK
18+
- target SDK
19+
- compatible SDK
20+
- Node.js version if relevant
21+
3. Check whether the answer must use API 24 production rules or API 26 preview rules.
22+
4. Provide one minimal fix first.
23+
5. Provide a verification command or IDE action.
24+
25+
## Response format
26+
27+
- Problem type
28+
- Likely cause
29+
- Minimal fix
30+
- Why it works
31+
- Verification steps
32+
- Follow-up data needed if still failing
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Recipe: Review ArkTS / ArkUI Code
2+
3+
Use this recipe when the user asks for code review, refactoring, migration review, or bug analysis.
4+
5+
## Review order
6+
7+
1. Target SDK and production/preview boundary.
8+
2. ArkTS strict typing and null safety.
9+
3. ArkUI state decorator correctness.
10+
4. Lifecycle side effects and async work.
11+
5. Permission and module configuration requirements.
12+
6. UI rendering and list performance.
13+
7. Build, signing, and package implications.
14+
15+
## Output format
16+
17+
- Summary judgment
18+
- Critical issues
19+
- Recommended patch direction
20+
- HarmonyOS-specific risks
21+
- Verification checklist
22+
23+
## Avoid
24+
25+
- Generic React or Android advice.
26+
- Rewriting the whole file when a targeted fix is enough.
27+
- API 26-only recommendations for API 24 production code.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# HarmonyOS Skill Reference Loading Guide
2+
3+
This directory contains supporting reference files for the `harmonyos-development` skill.
4+
5+
The root `SKILL.md` remains the discovery entry. These files are loaded only when the user request needs deeper guidance.
6+
7+
## Intent routing
8+
9+
| User intent | Read first | Then read |
10+
|---|---|---|
11+
| Version, SDK, DevEco Studio, API baseline | `platform-baseline.md` | `api26-preview.md` only for preview requests |
12+
| ArkTS syntax or TypeScript migration | `arkts-rules.md` | `../examples/*.ets` |
13+
| ArkUI layout, components, rendering | `arkui-components.md` | `state-management.md` |
14+
| Stage model lifecycle | `stage-model.md` | `../recipes/debug-build-error.md` |
15+
| Navigation and page stack | `navigation.md` | `state-management.md` |
16+
| State decorators and data flow | `state-management.md` | `arkts-rules.md` |
17+
| Permissions and privacy prompts | `permissions.md` | `../examples/permission-request.ets` |
18+
| Build, signing, packaging, release | `build-sign-release.md` | `platform-baseline.md` |
19+
| Performance and large lists | `performance.md` | `../examples/lazyforeach-list.ets` |
20+
21+
## Production default
22+
23+
Use API 24 Release as the production default unless the user explicitly targets HarmonyOS 7 / API 26 preview.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# API 26 Preview Boundary
2+
3+
This reference is for preview adaptation only.
4+
5+
Use it only when the user explicitly targets HarmonyOS 7, API 26, DevEco Studio 26 Beta, preview adaptation, or Beta SDK compatibility.
6+
7+
## Rule
8+
9+
Do not use API 26-only APIs, SDK versions, behavior changes, or DevEco 26-only tooling in API 24 production answers.
10+
11+
## How to answer preview questions
12+
13+
1. State that the capability is preview or Beta unless it has been promoted to Release.
14+
2. Separate migration risks from implementation steps.
15+
3. Call out SDK, toolchain, permission, and UX behavior changes.
16+
4. If an API signature is uncertain, mark the code as conceptual and ask the user to verify against the installed SDK docs.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# ArkTS Rules
2+
3+
Use this file for ArkTS syntax, TypeScript-to-ArkTS migration, and code review.
4+
5+
## Defaults
6+
7+
- Prefer `.ets` examples for HarmonyOS UI and ability code.
8+
- Prefer explicit types over dynamic object shapes.
9+
- Avoid generic TypeScript, DOM, React, Android, or Web-only advice unless the user explicitly asks for comparison.
10+
- Include imports from `@kit.*` where possible.
11+
12+
## Review checklist
13+
14+
- Strict typing is respected.
15+
- State is not mutated through unsupported dynamic patterns.
16+
- Async work is not placed in unsafe lifecycle positions.
17+
- Classes used with `@ObjectLink` are marked with `@Observed`.
18+
- Nullability and optional values are handled explicitly.
19+
- API version assumptions are stated.
20+
21+
## Common output pattern
22+
23+
When generating implementation code, include:
24+
25+
1. File path suggestion.
26+
2. ArkTS code.
27+
3. Required config changes.
28+
4. Integration notes.
29+
5. API baseline notes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# ArkUI Components Reference
2+
3+
Use this reference when the user asks about ArkUI layout, components, rendering, interaction, or page implementation.
4+
5+
## Defaults
6+
7+
- Prefer declarative ArkUI component examples in `.ets` files.
8+
- Use HarmonyOS-native components and APIs instead of React, DOM, Android View, or Jetpack Compose patterns.
9+
- State the target SDK assumption when behavior depends on SDK version.
10+
11+
## Component guidance
12+
13+
| Need | Prefer |
14+
|---|---|
15+
| Vertical layout | `Column` |
16+
| Horizontal layout | `Row` |
17+
| Overlay / layered layout | `Stack` |
18+
| Flexible wrapping layout | `Flex` |
19+
| Large lists | `List` + `LazyForEach` |
20+
| Grid content | `Grid` / `GridItem` |
21+
| Paged tabs | `Tabs` / `TabContent` |
22+
| Swipe carousel | `Swiper` |
23+
| Navigation shell | `Navigation` / `NavDestination` |
24+
25+
## Review checklist
26+
27+
- Keep layout nesting reasonable.
28+
- Avoid heavy computation inside `build()`.
29+
- Use stable keys for dynamic list rendering.
30+
- Keep component state ownership clear.
31+
- Include permission, routing, or module configuration when the component depends on it.

0 commit comments

Comments
 (0)