@buaa_smat/hometrans 0.1.13 → 0.1.14

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.
Files changed (86) hide show
  1. package/README.md +164 -112
  2. package/agents/build-fixer.md +384 -394
  3. package/agents/code-reviewer.md +240 -240
  4. package/agents/logic-coder.md +199 -199
  5. package/agents/logic-context-builder.md +194 -194
  6. package/agents/review-fixer.md +405 -405
  7. package/agents/self-test-fixer.md +296 -296
  8. package/agents/self-tester.md +393 -392
  9. package/agents/spec-generator.md +540 -540
  10. package/dist/cli/config-store.js +84 -8
  11. package/dist/cli/config.js +3 -3
  12. package/dist/cli/env-vars.js +129 -0
  13. package/dist/cli/init.js +272 -272
  14. package/dist/cli/uninstall.js +152 -17
  15. package/dist/context/index.js +10 -197
  16. package/env-requirements.json +3 -3
  17. package/package.json +1 -1
  18. package/resource/choose_editor.png +0 -0
  19. package/resource/common_config.png +0 -0
  20. package/resource/integration_test_config.png +0 -0
  21. package/resource/set_env.png +0 -0
  22. package/resource/ui_align_config.png +0 -0
  23. package/skills/hmos-batch-ui-align/SKILL.md +108 -98
  24. package/skills/hmos-batch-ui-align/references/conversion-procedure.md +180 -180
  25. package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +2533 -2533
  26. package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +555 -555
  27. package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +117 -117
  28. package/skills/hmos-batch-ui-align/references/mvvm/@Link/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/217/214/345/220/221/345/220/214/346/255/245.md +648 -648
  29. package/skills/hmos-batch-ui-align/references/mvvm/@Observed/350/243/205/351/245/260/345/231/250/345/222/214@ObjectLink/350/243/205/351/245/260/345/231/250/357/274/232/345/265/214/345/245/227/347/261/273/345/257/271/350/261/241/345/261/236/346/200/247/345/217/230/345/214/226.md +2088 -2088
  30. package/skills/hmos-batch-ui-align/references/mvvm/@Prop/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/215/225/345/220/221/345/220/214/346/255/245.md +1033 -1033
  31. package/skills/hmos-batch-ui-align/references/mvvm/@Provide/350/243/205/351/245/260/345/231/250/345/222/214@Consume/350/243/205/351/245/260/345/231/250/357/274/232/344/270/216/345/220/216/344/273/243/347/273/204/344/273/266/345/217/214/345/220/221/345/220/214/346/255/245.md +1183 -1183
  32. package/skills/hmos-batch-ui-align/references/mvvm/@State/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/347/212/266/346/200/201.md +576 -576
  33. package/skills/hmos-batch-ui-align/references/mvvm/@Track/350/243/205/351/245/260/345/231/250/357/274/232class/345/257/271/350/261/241/345/261/236/346/200/247/347/272/247/346/233/264/346/226/260.md +297 -297
  34. package/skills/hmos-batch-ui-align/references/mvvm/@Watch/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/346/233/264/346/224/271/351/200/232/347/237/245.md +395 -395
  35. package/skills/hmos-batch-ui-align/references/mvvm/AppStorage/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200/347/232/204UI/347/212/266/346/200/201/345/255/230/345/202/250.md +902 -902
  36. package/skills/hmos-batch-ui-align/references/mvvm/Environment/357/274/232/350/256/276/345/244/207/347/216/257/345/242/203/346/237/245/350/257/242.md +106 -106
  37. package/skills/hmos-batch-ui-align/references/mvvm/LocalStorage/357/274/232/351/241/265/351/235/242/347/272/247UI/347/212/266/346/200/201/345/255/230/345/202/250.md +1178 -1178
  38. package/skills/hmos-batch-ui-align/references/mvvm/MVVM/346/250/241/345/274/217/357/274/210V1/357/274/211.md +911 -911
  39. package/skills/hmos-batch-ui-align/references/mvvm/PersistentStorage/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +354 -354
  40. package/skills/hmos-batch-ui-align/references/mvvm//347/256/241/347/220/206/345/272/224/347/224/250/346/213/245/346/234/211/347/232/204/347/212/266/346/200/201/346/246/202/350/277/260.md +11 -11
  41. package/skills/hmos-convert-pipeline/SKILL.md +429 -415
  42. package/skills/hmos-fix-build-errors/SKILL.md +272 -273
  43. package/skills/hmos-fix-build-errors/references/arkts-strict-patterns.md +219 -219
  44. package/skills/hmos-fix-build-errors/references/known-patterns.md +157 -157
  45. package/skills/hmos-fix-build-errors/references/rdb-entity-pattern.md +131 -131
  46. package/skills/hmos-incremental-ui-align/SKILL.md +219 -200
  47. package/skills/hmos-incremental-ui-align/diff_analysis.md +52 -52
  48. package/skills/hmos-incremental-ui-align/page_align.md +62 -62
  49. package/skills/hmos-incremental-ui-align/readme.md +237 -230
  50. package/skills/hmos-incremental-ui-align/references/Comparison_Template.md +2 -2
  51. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Link/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/217/214/345/220/221/345/220/214/346/255/245.md +648 -648
  52. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Observed/350/243/205/351/245/260/345/231/250/345/222/214@ObjectLink/350/243/205/351/245/260/345/231/250/357/274/232/345/265/214/345/245/227/347/261/273/345/257/271/350/261/241/345/261/236/346/200/247/345/217/230/345/214/226.md +2088 -2088
  53. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Prop/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/215/225/345/220/221/345/220/214/346/255/245.md +1033 -1033
  54. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Provide/350/243/205/351/245/260/345/231/250/345/222/214@Consume/350/243/205/351/245/260/345/231/250/357/274/232/344/270/216/345/220/216/344/273/243/347/273/204/344/273/266/345/217/214/345/220/221/345/220/214/346/255/245.md +1183 -1183
  55. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@State/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/347/212/266/346/200/201.md +576 -576
  56. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Track/350/243/205/351/245/260/345/231/250/357/274/232class/345/257/271/350/261/241/345/261/236/346/200/247/347/272/247/346/233/264/346/226/260.md +297 -297
  57. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Watch/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/346/233/264/346/224/271/351/200/232/347/237/245.md +395 -395
  58. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/AppStorage/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200/347/232/204UI/347/212/266/346/200/201/345/255/230/345/202/250.md +902 -902
  59. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/Environment/357/274/232/350/256/276/345/244/207/347/216/257/345/242/203/346/237/245/350/257/242.md +106 -106
  60. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/LocalStorage/357/274/232/351/241/265/351/235/242/347/272/247UI/347/212/266/346/200/201/345/255/230/345/202/250.md +1178 -1178
  61. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/MVVM/346/250/241/345/274/217V1.md +911 -911
  62. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/PersistentStorage/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +354 -354
  63. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243//347/256/241/347/220/206/345/272/224/347/224/250/346/213/245/346/234/211/347/232/204/347/212/266/346/200/201/346/246/202/350/277/260.md +11 -11
  64. package/skills/hmos-incremental-ui-align/references/UI_Analysis_Template.md +3 -3
  65. package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +2533 -2533
  66. package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-interaction-mapping-reference.md +555 -555
  67. package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-layout-mapping-reference.md +117 -117
  68. package/skills/hmos-incremental-ui-align/scripts/navigation-capure.md +37 -37
  69. package/skills/hmos-integration-test/SKILL.md +380 -369
  70. package/skills/hmos-integration-test/readme.md +309 -309
  71. package/skills/hmos-resources-convert/SKILL.md +623 -623
  72. package/skills/hmos-resources-convert/references/conversion-rules.md +663 -663
  73. package/skills/hmos-resources-convert/references/dependency-analysis-rules.md +388 -388
  74. package/skills/hmos-resources-convert/references/resource-mapping-rules.md +457 -457
  75. package/skills/hmos-resources-convert/references/xml-drawable-to-svg-rules.md +513 -513
  76. package/skills/hmos-spec-generate/SKILL.md +331 -331
  77. package/skills/hmos-spec-generate/references/android-platform-tokens.md +105 -105
  78. package/skills/hmos-spec-generate/references/spec-sample-1.md +78 -78
  79. package/skills/hmos-spec-generate/references/spec-sample-2.md +58 -58
  80. package/skills/hmos-spec-generate/references/spec-sample-3.md +116 -116
  81. package/skills/hmos-spec-generate/references/step4-report-template.md +33 -33
  82. package/tools/test-tools/autotest/README.md +33 -17
  83. package/tools/test-tools/autotest/self_test_runner.py +109 -15
  84. package/resource/hometrans_config.png +0 -0
  85. package/skills/hmos-incremental-ui-align/config-example.json +0 -11
  86. package/tools/test-tools/autotest/config.yaml.example +0 -58
@@ -1,273 +1,272 @@
1
- ---
2
- name: hmos-fix-build-errors
3
- description: Build a HarmonyOS project via CLI and automatically fix compile errors in a loop until the build succeeds. Default unsigned HAP; pass --signed to build a signed HAP (signing config must already exist in the project's build-profile.json5).
4
- argument-hint: <harmonyos-project-path> [deveco-studio-path] [--signed]
5
- allowed-tools: Agent, Read, Write, Edit, Glob, Grep, Bash
6
- type: tool
7
- domain: engineering
8
- ---
9
-
10
- # HarmonyOS Auto Build & Fix
11
-
12
- Automatically build a HarmonyOS NEXT project from the command line, parse compile errors, fix them, and retry — repeating until the build succeeds.
13
-
14
- - **HarmonyOS Project**: `$ARGUMENTS[0]` (the HarmonyOS project root, e.g. `D:/MyHmosApp`)
15
- - **DevEco Studio Path** (optional): `$ARGUMENTS[1]` (DevEco Studio installation root, e.g. `D:/DevEco Studio`) — when omitted, resolved automatically (see Step 0.2)
16
- - **--signed** (optional): if any argument equals `--signed`, the build produces a **signed HAP**. If omitted, the build produces an **unsigned HAP** (default).
17
-
18
- ---
19
-
20
- ## Step 0: Validate Inputs & Setup Environment
21
-
22
- 1. **Verify project exists** — Check that `$ARGUMENTS[0]` contains a valid HarmonyOS project (look for `build-profile.json5`, `entry/src` directory, `oh-package.json5`).
23
-
24
- 2. **Resolve `<deveco-path>`** — stop at the first source that yields a valid path:
25
- 1. `$ARGUMENTS[1]` if provided (and not `--signed`).
26
- 2. `~/.hometrans/config.json` (on Windows `%USERPROFILE%\.hometrans\config.json`): `env.DEVECO_PATH`; else parent dir of `env.DEVECO_SDK_HOME`; else strip the trailing `/sdk/default/openharmony/ets` from `env.OHOS_SDK_PATH` (legacy).
27
- 3. Environment variables, same precedence: `DEVECO_PATH` parent of `DEVECO_SDK_HOME` strip suffix from `OHOS_SDK_PATH`.
28
- 4. **Ask the user** for the DevEco Studio install path (suggest running `ht init` to persist it).
29
-
30
- **Verify the resolved `<deveco-path>`** contains:
31
- - `tools/node/node.exe`
32
- - `tools/hvigor/bin/hvigorw.js`
33
- - `tools/ohpm/bin/ohpm`
34
- - `sdk/` directory
35
-
36
- If verification fails for a config/env-sourced path, treat that source as invalid and continue down the list; if it fails for a user-supplied path, report what is missing and ask again.
37
-
38
- 3. **Set up `local.properties`** — Ensure the project root has `local.properties` with:
39
- ```properties
40
- hwsdk.dir=<deveco-path>/sdk
41
- ```
42
- Create it if missing. Use forward slashes in the path.
43
-
44
- 4. **Run `ohpm install`** — Install dependencies before first build:
45
- ```bash
46
- cd "<project-dir>"
47
- export PATH="<deveco-path>/tools/ohpm/bin:$PATH"
48
- "<deveco-path>/tools/ohpm/bin/ohpm" install
49
- ```
50
-
51
- 5. **Determine Build Mode** Check if any argument equals `--signed` (it may be `$ARGUMENTS[1]` when the DevEco path is omitted, or `$ARGUMENTS[2]` when it is provided):
52
- - **If NOT `--signed`** → **Unsigned build mode**. Ensure `build-profile.json5` does NOT have `signingConfigs` or `signingConfig` references in products (remove them if present). Go to Step 1.
53
- - **If `--signed`** → **Signed build mode**. Proceed to Step 0.5 to validate signing config.
54
-
55
- ---
56
-
57
- ## Step 0.5: Validate Signing Config (Only for --signed Builds)
58
-
59
- This step is ONLY executed when `--signed` is specified.
60
-
61
- Signing information is read directly from the project's own `build-profile.json5`. The user must have already configured signing in DevEco Studio before running this skill.
62
-
63
- ### Steps:
64
-
65
- 1. **Read `build-profile.json5`** in the project root.
66
-
67
- 2. **Check for `signingConfigs`** Look for `app.signingConfigs` array in the file.
68
- - If `signingConfigs` exists and has at least one entry with valid `material` fields (`certpath`, `storeFile`, `profile`), proceed to step 3.
69
- - If `signingConfigs` is missing or empty, **STOP and report to the user**:
70
- > Signing configuration not found in `build-profile.json5`.
71
- > Please open the project in DevEco Studio, go to **File → Project Structure → Signing Configs**, enable **Automatically generate signature**, then re-run this skill with `--signed`.
72
-
73
- 3. **Validate signing material files exist** For the first entry in `signingConfigs`, check that the files referenced by `material.certpath`, `material.storeFile`, and `material.profile` actually exist on disk.
74
- - If any file is missing, **STOP and report** which files are missing. Suggest the user re-open DevEco Studio and re-generate the signing config.
75
-
76
- 4. **Ensure product references signing** — Check that the product entry in `products` array has `"signingConfig": "default"` (or matching the signing config name). Add it if missing.
77
-
78
- 5. Proceed to Step 1.
79
-
80
- ---
81
-
82
- ## Step 1: Build-Fix Loop
83
-
84
- Execute the following loop. **Maximum 20 iterations** to prevent infinite loops.
85
-
86
- ### 1.1 Run CLI Build
87
-
88
- **IMPORTANT (Windows)**: On Windows, bash `export PATH` does NOT propagate to Windows native child processes. You **must** use a temporary `.bat` file to set `PATH` and `JAVA_HOME`.
89
-
90
- 1. **Write a temporary batch file** (e.g. `<project-dir>/build_temp.bat`):
91
-
92
- **For unsigned builds** (no `--signed`):
93
- ```bat
94
- @echo off
95
- set "DEVECO_SDK_HOME=<deveco-path>\sdk"
96
- cd /d "<project-dir>"
97
- "<deveco-path>\tools\node\node.exe" "<deveco-path>\tools\hvigor\bin\hvigorw.js" assembleHap --mode module -p module=entry --no-daemon
98
- ```
99
-
100
- **For signed builds** (`--signed`):
101
- ```bat
102
- @echo off
103
- set "PATH=<deveco-path>\jbr\bin;%PATH%"
104
- set "JAVA_HOME=<deveco-path>\jbr"
105
- set "DEVECO_SDK_HOME=<deveco-path>\sdk"
106
- cd /d "<project-dir>"
107
- "<deveco-path>\tools\node\node.exe" "<deveco-path>\tools\hvigor\bin\hvigorw.js" assembleHap --mode module -p module=entry --no-daemon
108
- ```
109
- Note: Signed builds need `JAVA_HOME` and `jbr\bin` in PATH because the `SignHap` step spawns `java` as a child process.
110
-
111
- Use backslashes (`\`) in paths inside the `.bat` file (Windows convention).
112
-
113
- 2. **Run the batch file** via `cmd.exe`:
114
- ```bash
115
- cmd.exe //c "<project-dir>/build_temp.bat" 2>&1
116
- ```
117
-
118
- 3. **Delete the batch file** after the build completes (success or failure).
119
-
120
- - Capture the **full output** into a variable.
121
- - The build command may take 1-3 minutes. Use a timeout of 300000ms (5 minutes).
122
-
123
- ### 1.2 Check Build Result
124
-
125
- - If output contains `BUILD SUCCESSFUL` → **Build succeeded!** Exit the loop, go to Step 2.
126
- - If output contains `ERROR` or `BUILD FAILED` → Parse errors and continue to 1.3.
127
-
128
- ### 1.3 Parse Errors
129
-
130
- Extract error information from the build output. Errors typically appear in these formats:
131
-
132
- ```
133
- ERROR: <file-path>:<line>:<col> - <error-code>: <message>
134
- ```
135
-
136
- or
137
-
138
- ```
139
- ArkTS:ERROR File: <file-path>:<line>:<col>
140
- <error message>
141
- ```
142
-
143
- Group errors by file. Focus on **actual errors**, not warnings.
144
-
145
- ### 1.4 Fix Errors
146
-
147
- Read each file that has errors and apply fixes. Use the error reference table below to identify and fix common issues:
148
-
149
- | Error Code / Pattern | Message | Fix |
150
- |---|---|---|
151
- | `arkts-limited-throw` | "throw statements cannot accept values of arbitrary types" | Change `throw err` to `throw (err instanceof Error) ? err : new Error(String(err))` |
152
- | `arkts-no-obj-literals-as-types` | "Object literals cannot be used as type declarations" | Define a named `interface` instead of inline `{ key: Type }` |
153
- | `arkts-no-untyped-obj-literals` | "Object literal must correspond to some explicitly declared class or interface" | Assign to typed variable: `const r: MyInterface = {...}; return r;` |
154
- | `arkts-no-any-type` / `any` type usage | "Use explicit types instead of any" | Replace `any` with the correct concrete type or `object` |
155
- | `arkts-no-var` | "Use 'let' or 'const' instead of 'var'" | Replace `var` with `let` or `const` |
156
- | `10903329` | "Unknown resource name 'xxx'" | Verify resource exists in `resources/base/media/` or `element/*.json`. Use `layered_image` as fallback for missing images. **Special case**: `$r('sys.media.ohos_ic_public_xxx')` references system icons by SDK-specific names that may not exist in the build SDK — replace with `$r('app.media.ic_public_xxx')` and add the icon file to `resources/base/media/` |
157
- | `10505001` | "Resource[] is not assignable to ResourceColor" | Remove array brackets: `.fontColor($r('app.color.x'))` not `.fontColor([$r('app.color.x')])` |
158
- | `00303221` | "permission must be a value that is predefined within the SDK" | Remove invalid permission from `module.json5`. See valid permissions list below |
159
- | Missing import | "Cannot find name 'xxx'" | Add the correct import (see import reference below) |
160
- | Missing `async` | "await expression requires async function" | Add `async` to the enclosing function |
161
- | Missing `build()` | "@Component must have build() method" | Add a `build() {}` method to the @Component struct |
162
- | Type mismatch | Various type errors | Fix the type annotation or cast appropriately |
163
- | Duplicate identifier | "Duplicate identifier 'xxx'" | Remove or rename the duplicate declaration |
164
-
165
- **For errors NOT in the table above**: Read the error message carefully, read the relevant source file, understand the context, and apply an appropriate fix. Use your knowledge of ArkTS/HarmonyOS to determine the correct solution.
166
-
167
- ### 1.5 Log Progress
168
-
169
- After each fix iteration, briefly report:
170
- - Iteration number
171
- - Number of errors found
172
- - Summary of fixes applied
173
- - Whether re-building
174
-
175
- Then go back to **1.1** and rebuild.
176
-
177
- ---
178
-
179
- ## Step 2: Build Success Report
180
-
181
- When the build succeeds, present a summary:
182
-
183
- 1. **Build Status**: SUCCESS
184
- 2. **Build Type**: Signed HAP or Unsigned HAP
185
- 3. **Signing** (if signed): Confirm signing config from `build-profile.json5` was used
186
- 4. **Iterations**: How many build-fix cycles were needed
187
- 5. **Total Errors Fixed**: Count of errors fixed across all iterations
188
- 6. **Summary of Changes**: List of files modified and what was fixed in each
189
- 7. **Output HAP Path**:
190
- - Signed: `<project>/entry/build/default/outputs/default/entry-default-signed.hap`
191
- - Unsigned: `<project>/entry/build/default/outputs/default/entry-default-unsigned.hap`
192
-
193
- ---
194
-
195
- ## Reference: Common HarmonyOS Imports
196
-
197
- ```typescript
198
- // Network
199
- import { http } from '@kit.NetworkKit';
200
-
201
- // Data persistence
202
- import { preferences } from '@kit.ArkData';
203
- import { relationalStore } from '@kit.ArkData';
204
-
205
- // UI utilities
206
- import { router } from '@kit.ArkUI';
207
- import { promptAction } from '@kit.ArkUI';
208
-
209
- // Ability & Context
210
- import { UIAbility, AbilityConstant, Want } from '@kit.AbilityKit';
211
- import { common } from '@kit.AbilityKit';
212
-
213
- // File I/O
214
- import { fileIo } from '@kit.CoreFileKit';
215
-
216
- // Logging
217
- import { hilog } from '@kit.PerformanceAnalysisKit';
218
-
219
- // JSON parsing — built-in, no import needed
220
- // ArkUI built-in components (Text, Column, Row, List, Button, Image, etc.) — NO import needed
221
- ```
222
-
223
- ## Reference: Valid Permission Names
224
-
225
- Commonly used SDK-validated permissions for `module.json5`:
226
-
227
- - `ohos.permission.INTERNET`
228
- - `ohos.permission.GET_NETWORK_INFO`
229
- - `ohos.permission.GET_WIFI_INFO`
230
- - `ohos.permission.KEEP_BACKGROUND_RUNNING`
231
- - `ohos.permission.PUBLISH_AGENT_REMINDER`
232
- - `ohos.permission.CAMERA`
233
- - `ohos.permission.MICROPHONE`
234
- - `ohos.permission.APPROXIMATELY_LOCATION`
235
- - `ohos.permission.LOCATION`
236
- - `ohos.permission.READ_MEDIA`
237
- - `ohos.permission.WRITE_MEDIA`
238
- - `ohos.permission.USE_BLUETOOTH`
239
- - `ohos.permission.VIBRATE`
240
-
241
- **Note**: `ohos.permission.NOTIFICATION` does NOT exist. When in doubt, omit the permission.
242
-
243
- ## Reference: ArkTS Strict Mode Rules
244
-
245
- All code must comply with ArkTS strict mode:
246
-
247
- 1. **No `any` type** Use explicit types or `object`
248
- 2. **No `var`**Only `let` and `const`
249
- 3. **No dynamic property access** — Use typed interfaces instead of `obj['key']` on typed objects
250
- 4. **`throw` must throw Error instances** — Never `throw 'string'` or `throw unknownVar`
251
- 5. **All object literals must match declared interfaces** — No anonymous `{ key: val }` returns without a matching interface
252
- 6. **No inline object literal types** `function(): { a: string }` is forbidden; define a named `interface`
253
- 7. **All `@Component` structs must have `build()`** Missing build method is a compile error
254
- 8. **`$r()` resource references validated at compile time** All referenced resources must exist
255
- 9. **`fontColor()` expects `ResourceColor`**, not `Resource[]`Don't wrap in array brackets (exception: `SymbolGlyph`)
256
- 10. **Permission names in `module.json5`** — Must be SDK-predefined values
257
-
258
- ## Important Notes
259
-
260
- - **Timeout**: Individual build commands may take up to 5 minutes. Use a 300000ms timeout.
261
- - **Max iterations**: Stop after 20 iterations to prevent infinite loops. If build still fails after 20 attempts, report the remaining errors to the user.
262
- - **Don't over-fix**: Only fix errors reported by the compiler. Don't proactively refactor unrelated code.
263
- - **Read before edit**: Always read a file before modifying it. Understand the surrounding context.
264
- - **One error can cause many**: A single root-cause fix (like adding a missing interface) may resolve multiple reported errors. After fixing root causes, rebuild to see remaining issues.
265
- - **ohpm errors**: If the build fails because of missing packages, run `ohpm install` again.
266
-
267
- ---
268
-
269
- ## References
270
-
271
- - `references/arkts-strict-patterns.md` — ArkTS 严格模式编译错误的确定性修复 Pattern(throw/any/var/interface 等)
272
- - `references/known-patterns.md` — 已知常见编译错误 Pattern 及修复方案
273
- - `references/rdb-entity-pattern.md` — RDB 实体类编译错误 Pattern(数据库实体相关)
1
+ ---
2
+ name: hmos-fix-build-errors
3
+ description: Build a HarmonyOS project via CLI and automatically fix compile errors in a loop until the build succeeds. Default unsigned HAP; pass --signed to build a signed HAP (signing config must already exist in the project's build-profile.json5).
4
+ argument-hint: <harmony_project_dir> [deveco-studio-path] [--signed]
5
+ allowed-tools: Agent, Read, Write, Edit, Glob, Grep, Bash
6
+ type: tool
7
+ domain: engineering
8
+ ---
9
+
10
+ # HarmonyOS Auto Build & Fix
11
+
12
+ Automatically build a HarmonyOS NEXT project from the command line, parse compile errors, fix them, and retry — repeating until the build succeeds.
13
+
14
+ - **HarmonyOS Project**: `$ARGUMENTS[0]` (the HarmonyOS project root, e.g. `D:/MyHmosApp`)
15
+ - **DevEco Studio Path** (optional): `$ARGUMENTS[1]` (DevEco Studio installation root, e.g. `D:/DevEco Studio`) — when omitted, resolved automatically (see Step 0.2)
16
+ - **--signed** (optional): if any argument equals `--signed`, the build produces a **signed HAP**. If omitted, the build produces an **unsigned HAP** (default).
17
+
18
+ ---
19
+
20
+ ## Step 0: Validate Inputs & Setup Environment
21
+
22
+ 1. **Verify project exists** — Check that `$ARGUMENTS[0]` contains a valid HarmonyOS project (look for `build-profile.json5`, `entry/src` directory, `oh-package.json5`).
23
+
24
+ 2. **Resolve `<deveco-path>`** — read **directly from the OS environment**; stop at the first source that yields a valid path:
25
+ 1. `$ARGUMENTS[1]` if provided (and not `--signed`).
26
+ 2. Environment variables (`echo "$VAR"` on macOS/Linux; `$env:VAR` in PowerShell on Windows): `DEVECO_HOME` parent of `DEVECO_SDK_HOME` strip the trailing `/sdk/default/openharmony/ets` from `OHOS_SDK_PATH` (legacy).
27
+ 3. **Ask the user** for the DevEco Studio install path (suggest running `ht init` to persist it as an environment variable).
28
+
29
+ **Verify the resolved `<deveco-path>`** contains:
30
+ - `tools/node/node.exe`
31
+ - `tools/hvigor/bin/hvigorw.js`
32
+ - `tools/ohpm/bin/ohpm`
33
+ - `sdk/` directory
34
+
35
+ If verification fails for an env-sourced path, treat that source as invalid and continue down the list; if it fails for a user-supplied path, report what is missing and ask again.
36
+
37
+ 3. **Set up `local.properties`** — Ensure the project root has `local.properties` with:
38
+ ```properties
39
+ hwsdk.dir=<deveco-path>/sdk
40
+ ```
41
+ Create it if missing. Use forward slashes in the path.
42
+
43
+ 4. **Run `ohpm install`** — Install dependencies before first build:
44
+ ```bash
45
+ cd "<project-dir>"
46
+ export PATH="<deveco-path>/tools/ohpm/bin:$PATH"
47
+ "<deveco-path>/tools/ohpm/bin/ohpm" install
48
+ ```
49
+
50
+ 5. **Determine Build Mode** — Check if any argument equals `--signed` (it may be `$ARGUMENTS[1]` when the DevEco path is omitted, or `$ARGUMENTS[2]` when it is provided):
51
+ - **If NOT `--signed`** **Unsigned build mode**. Ensure `build-profile.json5` does NOT have `signingConfigs` or `signingConfig` references in products (remove them if present). Go to Step 1.
52
+ - **If `--signed`** → **Signed build mode**. Proceed to Step 0.5 to validate signing config.
53
+
54
+ ---
55
+
56
+ ## Step 0.5: Validate Signing Config (Only for --signed Builds)
57
+
58
+ This step is ONLY executed when `--signed` is specified.
59
+
60
+ Signing information is read directly from the project's own `build-profile.json5`. The user must have already configured signing in DevEco Studio before running this skill.
61
+
62
+ ### Steps:
63
+
64
+ 1. **Read `build-profile.json5`** in the project root.
65
+
66
+ 2. **Check for `signingConfigs`** — Look for `app.signingConfigs` array in the file.
67
+ - If `signingConfigs` exists and has at least one entry with valid `material` fields (`certpath`, `storeFile`, `profile`), proceed to step 3.
68
+ - If `signingConfigs` is missing or empty, **STOP and report to the user**:
69
+ > Signing configuration not found in `build-profile.json5`.
70
+ > Please open the project in DevEco Studio, go to **File → Project Structure → Signing Configs**, enable **Automatically generate signature**, then re-run this skill with `--signed`.
71
+
72
+ 3. **Validate signing material files exist** — For the first entry in `signingConfigs`, check that the files referenced by `material.certpath`, `material.storeFile`, and `material.profile` actually exist on disk.
73
+ - If any file is missing, **STOP and report** which files are missing. Suggest the user re-open DevEco Studio and re-generate the signing config.
74
+
75
+ 4. **Ensure product references signing** — Check that the product entry in `products` array has `"signingConfig": "default"` (or matching the signing config name). Add it if missing.
76
+
77
+ 5. Proceed to Step 1.
78
+
79
+ ---
80
+
81
+ ## Step 1: Build-Fix Loop
82
+
83
+ Execute the following loop. **Maximum 20 iterations** to prevent infinite loops.
84
+
85
+ ### 1.1 Run CLI Build
86
+
87
+ **IMPORTANT (Windows)**: On Windows, bash `export PATH` does NOT propagate to Windows native child processes. You **must** use a temporary `.bat` file to set `PATH` and `JAVA_HOME`.
88
+
89
+ 1. **Write a temporary batch file** (e.g. `<project-dir>/build_temp.bat`):
90
+
91
+ **For unsigned builds** (no `--signed`):
92
+ ```bat
93
+ @echo off
94
+ set "DEVECO_SDK_HOME=<deveco-path>\sdk"
95
+ cd /d "<project-dir>"
96
+ "<deveco-path>\tools\node\node.exe" "<deveco-path>\tools\hvigor\bin\hvigorw.js" assembleHap --mode module -p module=entry --no-daemon
97
+ ```
98
+
99
+ **For signed builds** (`--signed`):
100
+ ```bat
101
+ @echo off
102
+ set "PATH=<deveco-path>\jbr\bin;%PATH%"
103
+ set "JAVA_HOME=<deveco-path>\jbr"
104
+ set "DEVECO_SDK_HOME=<deveco-path>\sdk"
105
+ cd /d "<project-dir>"
106
+ "<deveco-path>\tools\node\node.exe" "<deveco-path>\tools\hvigor\bin\hvigorw.js" assembleHap --mode module -p module=entry --no-daemon
107
+ ```
108
+ Note: Signed builds need `JAVA_HOME` and `jbr\bin` in PATH because the `SignHap` step spawns `java` as a child process.
109
+
110
+ Use backslashes (`\`) in paths inside the `.bat` file (Windows convention).
111
+
112
+ 2. **Run the batch file** via `cmd.exe`:
113
+ ```bash
114
+ cmd.exe //c "<project-dir>/build_temp.bat" 2>&1
115
+ ```
116
+
117
+ 3. **Delete the batch file** after the build completes (success or failure).
118
+
119
+ - Capture the **full output** into a variable.
120
+ - The build command may take 1-3 minutes. Use a timeout of 300000ms (5 minutes).
121
+
122
+ ### 1.2 Check Build Result
123
+
124
+ - If output contains `BUILD SUCCESSFUL` → **Build succeeded!** Exit the loop, go to Step 2.
125
+ - If output contains `ERROR` or `BUILD FAILED` → Parse errors and continue to 1.3.
126
+
127
+ ### 1.3 Parse Errors
128
+
129
+ Extract error information from the build output. Errors typically appear in these formats:
130
+
131
+ ```
132
+ ERROR: <file-path>:<line>:<col> - <error-code>: <message>
133
+ ```
134
+
135
+ or
136
+
137
+ ```
138
+ ArkTS:ERROR File: <file-path>:<line>:<col>
139
+ <error message>
140
+ ```
141
+
142
+ Group errors by file. Focus on **actual errors**, not warnings.
143
+
144
+ ### 1.4 Fix Errors
145
+
146
+ Read each file that has errors and apply fixes. Use the error reference table below to identify and fix common issues:
147
+
148
+ | Error Code / Pattern | Message | Fix |
149
+ |---|---|---|
150
+ | `arkts-limited-throw` | "throw statements cannot accept values of arbitrary types" | Change `throw err` to `throw (err instanceof Error) ? err : new Error(String(err))` |
151
+ | `arkts-no-obj-literals-as-types` | "Object literals cannot be used as type declarations" | Define a named `interface` instead of inline `{ key: Type }` |
152
+ | `arkts-no-untyped-obj-literals` | "Object literal must correspond to some explicitly declared class or interface" | Assign to typed variable: `const r: MyInterface = {...}; return r;` |
153
+ | `arkts-no-any-type` / `any` type usage | "Use explicit types instead of any" | Replace `any` with the correct concrete type or `object` |
154
+ | `arkts-no-var` | "Use 'let' or 'const' instead of 'var'" | Replace `var` with `let` or `const` |
155
+ | `10903329` | "Unknown resource name 'xxx'" | Verify resource exists in `resources/base/media/` or `element/*.json`. Use `layered_image` as fallback for missing images. **Special case**: `$r('sys.media.ohos_ic_public_xxx')` references system icons by SDK-specific names that may not exist in the build SDK — replace with `$r('app.media.ic_public_xxx')` and add the icon file to `resources/base/media/` |
156
+ | `10505001` | "Resource[] is not assignable to ResourceColor" | Remove array brackets: `.fontColor($r('app.color.x'))` not `.fontColor([$r('app.color.x')])` |
157
+ | `00303221` | "permission must be a value that is predefined within the SDK" | Remove invalid permission from `module.json5`. See valid permissions list below |
158
+ | Missing import | "Cannot find name 'xxx'" | Add the correct import (see import reference below) |
159
+ | Missing `async` | "await expression requires async function" | Add `async` to the enclosing function |
160
+ | Missing `build()` | "@Component must have build() method" | Add a `build() {}` method to the @Component struct |
161
+ | Type mismatch | Various type errors | Fix the type annotation or cast appropriately |
162
+ | Duplicate identifier | "Duplicate identifier 'xxx'" | Remove or rename the duplicate declaration |
163
+
164
+ **For errors NOT in the table above**: Read the error message carefully, read the relevant source file, understand the context, and apply an appropriate fix. Use your knowledge of ArkTS/HarmonyOS to determine the correct solution.
165
+
166
+ ### 1.5 Log Progress
167
+
168
+ After each fix iteration, briefly report:
169
+ - Iteration number
170
+ - Number of errors found
171
+ - Summary of fixes applied
172
+ - Whether re-building
173
+
174
+ Then go back to **1.1** and rebuild.
175
+
176
+ ---
177
+
178
+ ## Step 2: Build Success Report
179
+
180
+ When the build succeeds, present a summary:
181
+
182
+ 1. **Build Status**: SUCCESS
183
+ 2. **Build Type**: Signed HAP or Unsigned HAP
184
+ 3. **Signing** (if signed): Confirm signing config from `build-profile.json5` was used
185
+ 4. **Iterations**: How many build-fix cycles were needed
186
+ 5. **Total Errors Fixed**: Count of errors fixed across all iterations
187
+ 6. **Summary of Changes**: List of files modified and what was fixed in each
188
+ 7. **Output HAP Path**:
189
+ - Signed: `<project>/entry/build/default/outputs/default/entry-default-signed.hap`
190
+ - Unsigned: `<project>/entry/build/default/outputs/default/entry-default-unsigned.hap`
191
+
192
+ ---
193
+
194
+ ## Reference: Common HarmonyOS Imports
195
+
196
+ ```typescript
197
+ // Network
198
+ import { http } from '@kit.NetworkKit';
199
+
200
+ // Data persistence
201
+ import { preferences } from '@kit.ArkData';
202
+ import { relationalStore } from '@kit.ArkData';
203
+
204
+ // UI utilities
205
+ import { router } from '@kit.ArkUI';
206
+ import { promptAction } from '@kit.ArkUI';
207
+
208
+ // Ability & Context
209
+ import { UIAbility, AbilityConstant, Want } from '@kit.AbilityKit';
210
+ import { common } from '@kit.AbilityKit';
211
+
212
+ // File I/O
213
+ import { fileIo } from '@kit.CoreFileKit';
214
+
215
+ // Logging
216
+ import { hilog } from '@kit.PerformanceAnalysisKit';
217
+
218
+ // JSON parsing — built-in, no import needed
219
+ // ArkUI built-in components (Text, Column, Row, List, Button, Image, etc.) — NO import needed
220
+ ```
221
+
222
+ ## Reference: Valid Permission Names
223
+
224
+ Commonly used SDK-validated permissions for `module.json5`:
225
+
226
+ - `ohos.permission.INTERNET`
227
+ - `ohos.permission.GET_NETWORK_INFO`
228
+ - `ohos.permission.GET_WIFI_INFO`
229
+ - `ohos.permission.KEEP_BACKGROUND_RUNNING`
230
+ - `ohos.permission.PUBLISH_AGENT_REMINDER`
231
+ - `ohos.permission.CAMERA`
232
+ - `ohos.permission.MICROPHONE`
233
+ - `ohos.permission.APPROXIMATELY_LOCATION`
234
+ - `ohos.permission.LOCATION`
235
+ - `ohos.permission.READ_MEDIA`
236
+ - `ohos.permission.WRITE_MEDIA`
237
+ - `ohos.permission.USE_BLUETOOTH`
238
+ - `ohos.permission.VIBRATE`
239
+
240
+ **Note**: `ohos.permission.NOTIFICATION` does NOT exist. When in doubt, omit the permission.
241
+
242
+ ## Reference: ArkTS Strict Mode Rules
243
+
244
+ All code must comply with ArkTS strict mode:
245
+
246
+ 1. **No `any` type** — Use explicit types or `object`
247
+ 2. **No `var`**Only `let` and `const`
248
+ 3. **No dynamic property access** Use typed interfaces instead of `obj['key']` on typed objects
249
+ 4. **`throw` must throw Error instances** — Never `throw 'string'` or `throw unknownVar`
250
+ 5. **All object literals must match declared interfaces** — No anonymous `{ key: val }` returns without a matching interface
251
+ 6. **No inline object literal types** — `function(): { a: string }` is forbidden; define a named `interface`
252
+ 7. **All `@Component` structs must have `build()`** Missing build method is a compile error
253
+ 8. **`$r()` resource references validated at compile time** All referenced resources must exist
254
+ 9. **`fontColor()` expects `ResourceColor`**, not `Resource[]` Don't wrap in array brackets (exception: `SymbolGlyph`)
255
+ 10. **Permission names in `module.json5`**Must be SDK-predefined values
256
+
257
+ ## Important Notes
258
+
259
+ - **Timeout**: Individual build commands may take up to 5 minutes. Use a 300000ms timeout.
260
+ - **Max iterations**: Stop after 20 iterations to prevent infinite loops. If build still fails after 20 attempts, report the remaining errors to the user.
261
+ - **Don't over-fix**: Only fix errors reported by the compiler. Don't proactively refactor unrelated code.
262
+ - **Read before edit**: Always read a file before modifying it. Understand the surrounding context.
263
+ - **One error can cause many**: A single root-cause fix (like adding a missing interface) may resolve multiple reported errors. After fixing root causes, rebuild to see remaining issues.
264
+ - **ohpm errors**: If the build fails because of missing packages, run `ohpm install` again.
265
+
266
+ ---
267
+
268
+ ## References
269
+
270
+ - `references/arkts-strict-patterns.md` — ArkTS 严格模式编译错误的确定性修复 Pattern(throw/any/var/interface 等)
271
+ - `references/known-patterns.md` — 已知常见编译错误 Pattern 及修复方案
272
+ - `references/rdb-entity-pattern.md` — RDB 实体类编译错误 Pattern(数据库实体相关)