@deveco-test/deveco-code 1.0.2 → 1.0.4
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.
- package/CHANGELOG.md +13 -0
- package/package.json +6 -5
- package/resources/deveco/skills/customize-deveco/.deveco-builtin +1 -0
- package/resources/deveco/skills/customize-deveco/SKILL.md +469 -0
- package/resources/deveco/skills/deveco-cli/.deveco-builtin +1 -0
- package/resources/deveco/skills/deveco-cli/SKILL.md +240 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/.deveco-builtin +1 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/SKILL.md +83 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/01-layout.md +629 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/02-basic-components.md +645 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/03-data-display.md +81 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/04-selectors.md +76 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/05-media.md +60 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/06-advanced.md +32 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/07-security.md +30 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/08-state-decorators.md +79 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/09-animation.md +111 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/10-gesture.md +59 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/11-dialog-menu.md +92 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/12-navigation.md +81 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/13-rendering.md +22 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/14-extension.md +22 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/15-theme-style.md +10 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/16-enums.md +87 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/17-resources.md +1379 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/18-error-code.md +24 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-apis/_index.md +75 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/00-arkts-syntax.md +229 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/01-import.md +116 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/02-uicontext.md +56 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/03-component.md +105 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/04-build.md +41 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/05-state.md +300 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/06-rendering.md +67 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/07-attribute-params.md +219 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/08-navigation.md +102 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/09-dialog.md +72 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/10-style.md +90 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/11-extension.md +54 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/12-layout.md +69 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/13-performance.md +27 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/14-deprecated.md +28 -0
- package/resources/deveco/skills/hmos-arkui-develop-skill/references/quick-rules/_index.md +79 -0
- package/resources/deveco/skills/hmos-runtime-fix-skill/.deveco-builtin +1 -0
- package/resources/deveco/skills/hmos-runtime-fix-skill/SKILL.md +187 -0
- package/resources/deveco/skills/hmos-runtime-fix-skill/SKILL_CN.md +160 -0
- package/resources/deveco/skills/hmos-runtime-fix-skill/evals/evals.json +17 -0
- package/resources/deveco/skills/hmos-runtime-fix-skill/reference/businesserror_patterns.md +17 -0
- package/resources/deveco/skills/hmos-runtime-fix-skill/reference/error_patterns.md +31 -0
- package/resources/deveco/skills/hmos-runtime-fix-skill/reference/fault-mode-library.md +57 -0
- package/resources/deveco/skills/hmos-runtime-fix-skill/reference/outofmemoryerror_patterns.md +19 -0
- package/resources/deveco/skills/hmos-runtime-fix-skill/reference/rangeerror_patterns.md +15 -0
- package/resources/deveco/skills/hmos-runtime-fix-skill/reference/referenceerror_patterns.md +23 -0
- package/resources/deveco/skills/hmos-runtime-fix-skill/reference/syntaxerror_patterns.md +14 -0
- package/resources/deveco/skills/hmos-runtime-fix-skill/reference/typeerror_patterns.md +19 -0
- package/resources/deveco/skills/hmos-runtime-fix-skill/reference/urierror_patterns.md +17 -0
- package/resources/deveco/skills/hmos-runtime-fix-skill/scripts/collect-hilog.mjs +120 -0
- package/resources/deveco/skills/hmos-runtime-fix-skill/scripts/jscrash-report.mjs +138 -0
- package/resources/deveco/skills/hmos-runtime-fix-skill/scripts/parse-jscrash-log.mjs +126 -0
- package/resources/deveco/skills/hmos-runtime-fix-skill/scripts/shared/deveco-cli.mjs +79 -0
- package/resources/deveco/skills/hmos-runtime-fix-skill/scripts/shared/jscrash-parse.mjs +389 -0
- package/resources/deveco/skills/hmos-runtime-fix-skill/scripts/shared/utils.mjs +27 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: deveco-cli
|
|
3
|
+
description: >-
|
|
4
|
+
Use 'devecocli' for HarmonyOS apps (scaffold, build, run, debug, devices, emulators, logs, docs, UI inspection, 鸿蒙开发文档, skills). Use it if workspace has build-profile.json5 or oh-package.json5, or user mentions HarmonyOS, 鸿蒙, DevEco, ArkTS, ArkUI, docs, 鸿蒙文档, 知识, 搜索, skills, UI, UI测试, 组件调试. If user explicitly specifies another tool, skill, or workflow, follow that choice; otherwise use 'devecocli'.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# DevEco CLI
|
|
8
|
+
|
|
9
|
+
`devecocli` wraps DevEco Studio's `hvigor`, `ohpm`, `hdc`, emulator toolchain, and bundled skills installer.
|
|
10
|
+
|
|
11
|
+
This is DevEco Code's Router-aware skill, synchronized with `@deveco/deveco-cli@1.3.4`. DevEco Code invokes its bundled CLI through a proxy; the create, build, docs, run, and log behavior below includes local adaptations. Maintain this repository copy when upgrading the CLI; do not replace it with the npm package's unmodified skill.
|
|
12
|
+
|
|
13
|
+
Available commands: `build`, `check`, `run`, `update`, `device`, `emulator`, `ui`, `skills`, `log`, `create`, `init`, `serve`, `docs`, `signature`, `auth`.
|
|
14
|
+
|
|
15
|
+
**Sandbox Rule**: Commands tagged `[Outside sandbox]` must be run outside the sandbox.
|
|
16
|
+
|
|
17
|
+
## 1. Code → Build → Deploy → Run → Debug
|
|
18
|
+
|
|
19
|
+
### `devecocli create`
|
|
20
|
+
Scaffold a new HarmonyOS project.
|
|
21
|
+
- `--app-name <name>` (Req): 1–200 chars, `^[a-zA-Z][a-zA-Z0-9_]*$`
|
|
22
|
+
- `--project-path <path>`: Final project root. Auto-created if omitted (`./<app-name>`) or missing, and populated if empty. A non-empty target returns `PROJECT_EXISTS` unless `--merge` is supplied.
|
|
23
|
+
- `--bundle-name <bundle>`: Default `com.example.<appname-lowercase>`. 7–128 chars, ≥3 segments.
|
|
24
|
+
- `--api-level <level>`: int ≥17 (default: auto or 23).
|
|
25
|
+
- `--merge` allows a non-empty target while preserving existing content. Generated paths are checked before the target changes, and no existing file is overwritten.
|
|
26
|
+
- `PROJECT_EXISTS` (exit 2): use `--merge` only if the existing directory is intended to become the project root. Otherwise ask whether to overwrite, rename, or cancel. Never clear the reported `details.targetRoot` without explicit confirmation.
|
|
27
|
+
- `PROJECT_FILE_CONFLICT` (exit 2): report `details.conflicts` and ask the user to rename those paths, choose another root, or cancel. No existing files were changed; never overwrite the conflicts automatically.
|
|
28
|
+
- In a DevEco Code session, successful creation reports `Project root:` for the session's workspace switch. In a standalone shell, change directory to that root before building.
|
|
29
|
+
*Ex*: `devecocli create --app-name MyApp --project-path ./CustomDir --api-level 23`
|
|
30
|
+
|
|
31
|
+
### `devecocli build` `[Outside sandbox]`
|
|
32
|
+
Compile and package project/modules. (Defaults: `--product default`, `--build-mode debug`)
|
|
33
|
+
| Goal | Command |
|
|
34
|
+
|---|---|
|
|
35
|
+
| Single-module / single-`entry` | `devecocli build` |
|
|
36
|
+
| Specific modules | `devecocli build --modules <m1> <m2>@<target>` |
|
|
37
|
+
| Whole product bundle (.app) | `devecocli build --product <name>` |
|
|
38
|
+
| Clean build outputs | `devecocli build clean` |
|
|
39
|
+
|
|
40
|
+
If build output is truncated, the complete log is saved at the path shown after `Full output saved to:`.
|
|
41
|
+
|
|
42
|
+
### `devecocli check lint`
|
|
43
|
+
Run DevEco Code Linter checks for TS/ArkTS code.
|
|
44
|
+
- **Studio requirement**: Default lint checks and `--fix`, `--incremental`, `--product`, `--config-path`, and `--limit` support DevEco Studio `>= 6.0.0`; explicitly using `--format` or `--output-path` requires DevEco Studio `>= 6.1.0`. Command Line Tools mode follows the CLT `>= 26.0.0` baseline.
|
|
45
|
+
- `[path]`: File or directory to lint. Defaults to the project root from `build-profile.json5`, otherwise the current directory.
|
|
46
|
+
- Options: `--config-path <file>`, `--fix`, `--incremental`, `--product <name>`, `--format <default|json>`, `--output-path <path>`, `--limit <number>`.
|
|
47
|
+
- Set `DEVECO_CLI_CLT_PATH` to the Command Line Tools root when DevEco Studio is not installed; CLT is not discovered automatically from PATH or default installation directories.
|
|
48
|
+
|
|
49
|
+
### `devecocli emulator`
|
|
50
|
+
Manage local emulator instances and system images.
|
|
51
|
+
- **Studio requirement**: DevEco Studio `>= 6.1.0`.
|
|
52
|
+
- `list`: Show instances (status, serial, device type). Opt: `--format <table|json>` (default: `table`).
|
|
53
|
+
- `start <names...>`: Start instances. Quote names with spaces. (See Troubleshooting if blocked).
|
|
54
|
+
- `stop <names...>`: Stop by name or serial (`127.0.0.1:<port>`).
|
|
55
|
+
- Scene control commands require Emulator 7.0 or later. Use `DEVECO_CLI_DEBUG=1` to inspect the underlying `Emulator` command mapping.
|
|
56
|
+
- `shake` / `power` / `rotate <left|right>` / `volume <up|down>` (Req: `--target <nameOrSerial>`): Basic emulator controls.
|
|
57
|
+
- `fold <state>` (Req: `--target <nameOrSerial>`): Set foldable display state, matched against the target emulator's reported `deviceType`. `foldable` uses `open|half-open|close`; `2in1_foldable` uses `open|vertical-open|half-open|close`; `triplefold` uses `single|double|triple` or one of its six left/right folded-state combinations. Other device types and cross-device states are rejected before execution.
|
|
58
|
+
- `battery` (Req: `--target`; one of `--level <0-100>` or `--status <charging|discharging>`): Set battery state. `--level` checks the current emulator charging state automatically (`0-100` while charging, `1-100` otherwise).
|
|
59
|
+
- `geolocation` (Req: `--target`; one of `--longitude`, `--latitude`, `--altitude`, `--direction`): Inject GPS data.
|
|
60
|
+
- `scene <outdoorRunning|outdoorCycling|drivingNavigation>` (Req: `--target`): Start motion simulation.
|
|
61
|
+
- `sensor` (Req: `--target`; one of `--light-intensity`, `--humidity`, `--temperature`, `--steps`, `--heartrate`): Inject sensor data.
|
|
62
|
+
- `create <name>` (Req: `--device-type`, `--os-version`): Create instance. Optional: `--force`.
|
|
63
|
+
- `delete <name>`: Delete instance.
|
|
64
|
+
- `image list`: List downloaded images. Opts: `--device-type <type>`, `--all`, `--format <table|json>`.
|
|
65
|
+
- `image download` / `image remove` (Req: `--device-type`, `--os-version`): Download/remove image. (Takes 30+ min, set long timeout).
|
|
66
|
+
*Device types*: `phone`, `foldable`, `widefold`, `triplefold`, `tablet`, `2in1`, `2in1 foldable`, `wearable`, `tv`.
|
|
67
|
+
|
|
68
|
+
### `devecocli ui`
|
|
69
|
+
Inspect UI on a connected physical device or running emulator.
|
|
70
|
+
- `screenshot`: Capture a screenshot from a physical device or running emulator. `--device <name|serial>` is optional when exactly one device is connected, and required when multiple devices are connected.
|
|
71
|
+
- Optional: `--display <displayId>`. Required: `--path <path>` (existing directory or PNG file path, including paths relative to the current directory; writable destination; no overwrite).
|
|
72
|
+
- Implementation uses `hdc shell snapshot_display` and `hdc file recv`; set `DEVECO_CLI_DEBUG=1` to inspect the actual `hdc` commands.
|
|
73
|
+
*Ex*: `devecocli ui screenshot --device Phone --path ./screenshots/phone.png`
|
|
74
|
+
|
|
75
|
+
### `devecocli docs`
|
|
76
|
+
Search/read local HarmonyOS docs.
|
|
77
|
+
- `search <keywords...>`: Match any keyword. Opts: `--catalog <name>`, `--format <default|json>`, `--limit <n>`.
|
|
78
|
+
- `read <documentId>`: Read a document by ID (e.g. `devecocli docs read 开发指南/冷启动_Launch分析/Launch模板基本操作/ide-insight-session-launch`).
|
|
79
|
+
- `catalog`: List available catalogs.
|
|
80
|
+
- `search` and `read` responses default to a 5,000-character preview. When truncated, the complete result is saved at the path shown after `Full output saved to:`.
|
|
81
|
+
- This also applies to `--format json`: a truncated preview is not valid JSON. Read the saved file for the complete result instead of parsing the preview.
|
|
82
|
+
|
|
83
|
+
### `devecocli device`
|
|
84
|
+
- `list`: Show active real devices and running emulators. Opt: `--format <table|json>` (default: `table`).
|
|
85
|
+
- `view`: Detailed info. Req `-t <name|serial>` on multi-device hosts. Opt: `--format <table|json>` (default: `table`).
|
|
86
|
+
|
|
87
|
+
### `devecocli run` `[Outside sandbox]`
|
|
88
|
+
Build, install, and launch.
|
|
89
|
+
- `--module <module>`: Target module (auto-selected if only one runnable).
|
|
90
|
+
- `--device <name|serial>`: Target device. For a standard build-and-run deployment, omitting it auto-selects the only available physical device or emulator and starts a stopped emulator before deployment. Multiple targets return `DEVICE_SELECTION_REQUIRED`; no available target returns `NO_DEVICE_AVAILABLE`.
|
|
91
|
+
- On `DEVICE_SELECTION_REQUIRED`, ask the user to choose from the returned targets, then retry with `--device`. An explicitly selected stopped emulator is also started automatically. Special modes (`--apply`, `--hotreload`, `--hotreload-apply`), help, and unknown run options bypass Router device selection/startup; ensure a running device and pass `--device` when needed. Discovery failures fall back to the native CLI.
|
|
92
|
+
- `--product <product>` / `--build-mode <mode>`: Defaults: `default` / `debug`.
|
|
93
|
+
- `--ability <ability>`: Default from `module.json5`.
|
|
94
|
+
- `--uninstall`: Uninstall existing app first (Fixes signing key issues).
|
|
95
|
+
- `--skip-build`: Deploy existing artifacts.
|
|
96
|
+
- `--apply <fileName>`: **Fast incremental deploy** — rebuilds only changed files into a signed hqf, installs via `bm quickfix -a -f -o`, then restarts the app. Much faster than a full `devecocli run` for iterating on code changes. Modules are auto-detected from the file paths in `<fileName>` (no `--module` needed).
|
|
97
|
+
- `<fileName>`: a plain file name (no path separators) under the project's `.hvigor/` directory; the caller writes the changed-file list there. File name is sanitized to prevent path traversal. Content: list of **source file paths changed this round** (one per line, relative to project root or absolute; `#` comments and blank lines ignored; typically `.ets`/`.ts`/`.cpp`/resource files). The changeFileList is **incrementally merged** — only list files changed since the last apply; previously listed files are retained automatically.
|
|
98
|
+
- **Prereq**: DevEco Studio ≥6.1.1 (hvigor `assembleDevHqf` support; below is rejected with an upgrade hint); run `devecocli run` once first (full build + deploy + generates the `buildConfig.json` cache that `--apply` reuses).
|
|
99
|
+
- **If changes don't take effect**: check `<module>/build/config/buildConfig.json` has content — empty/missing means `devecocli run` wasn't run; on any apply failure, fall back to a full `devecocli run`.
|
|
100
|
+
*Ex*: `devecocli run` → edit code → write `.hvigor/changes.txt` → `devecocli run --apply changes.txt`
|
|
101
|
+
- `--hotreload [action]`: **Hot-reload watch session** — must be started as a **background process** (the process holds a persistent socket to the hvigor daemon). It builds the hap in hot-reload mode (`hotReload=true debuggable=true`), deploys+launches the app, then the process itself connects a socket to the daemon and sends `CommonBuild assembleHap --hot-reload-build --watch`, **staying connected** so the daemon's watch worker (rollup watch) stays alive for `--hotreload-apply` to reuse. The process stays alive (onBuildOutput streams to its stdout). **Must be stopped (kill the background process) when the hot-reload debug session ends** — otherwise the watch worker/daemon leaks. `--hotreload stop` additionally stops the hvigor daemon.
|
|
102
|
+
- **Usage through DevEco Code**: the proxy buffers child stdout/stderr until the CLI exits, so do not wait for "watch session active" on proxy stdout. Use a managed background job, inspect `<module>/build/<product>/.hotreload-mode` and `.hvigor/hotreload-watch.log` for readiness/errors, then run `devecocli run --module <m> --hotreload-apply <file>`. A marker left by an earlier session alone does not prove readiness. When done, stop the job's CLI child process as well as the proxy, then run `devecocli run --hotreload stop`; killing only the proxy may leave the child alive.
|
|
103
|
+
- `--hotreload-apply <fileName>`: **Hot reload without app restart** — reads the changed-file list from `.hvigor/<fileName>` (same format/merge rules as `--apply`), opens a **short socket** to the daemon (kept alive by the background `--hotreload` process) and sends `CommonBuild assembleDevHqf --hot-compile` → the watch worker incrementally hot-compiles changed `.ets`/`.ts` into abc (HotReloadArkTS; output/errors streamed live via WatchLog), then **manually** packs + signs a hqf from that abc (`app_packing_tool.jar` + `hap-sign-tool.jar`, DevEco material password decrypted via `DecipherUtil`), and installs it via `bm quickfix -a -f -o`. The app is **not restarted** — changes take effect immediately.
|
|
104
|
+
- **Prereq**: the background `devecocli run --hotreload` process must be running (holds the watch session). If `--hotreload-apply` times out, the watch session isn't alive — (re)start the background `--hotreload`.
|
|
105
|
+
- **Scope (important)**: hot reload targets a **single module** (`--module` required; the target can be entry/hsp/feature; `har` deps are folded in and fine). **`har` dependency changes are auto-routed** to the dependent main module's (entry/feature/hsp) `hotReload/changedFileList.json` — so editing a har's `.ets` and listing it hot-reloads via the target module. Changes in **`feature`/`hsp` dependency modules** (not the target) are NOT hot-reloadable — they're detected and warned (run a full `devecocli run` to redeploy those). `@State`/state-decorator changes are **not** hot-reloadable (state isn't re-initialized); hot-reloadable changes are non-state code: UI property values (`.fontColor`/`.fontSize`), `Text`/`Button` literal labels, method bodies, expressions. Resources/native changes need a full run.
|
|
106
|
+
- **Compile errors**: ArkTS compile errors from the hot compile are routed (via WatchLog) to the **background `--hotreload` process**, which writes them to **`.hvigor/hotreload-watch.log`** (and its stdout). On failure, `--hotreload-apply` reads that file and prints the errors inline (fast-fail, ~15s timeout if the watch session is dead).
|
|
107
|
+
- **Artifacts under `.hvigor/`** (shared with `--apply`): `.hvigor/<fileName>` = the changed-file list you write; `.hvigor/hotreload-watch.log` = the watch session's onBuildOutput/compile-errors (written by the background `--hotreload` process; safe to read/delete). The hot-reload marker is `<module>/build/<product>/.hotreload-mode`.
|
|
108
|
+
*Ex*: background `devecocli run --module entry --hotreload` → (ready) → edit `.fontColor` in `entry/src/main/ets/pages/Index.ets` → write path to `.hvigor/changes.txt` → `devecocli run --module entry --hotreload-apply changes.txt` (UI updates without restart). When done: kill the background process + `devecocli run --hotreload stop`.
|
|
109
|
+
|
|
110
|
+
### `devecocli signature generate` `[Outside sandbox]`
|
|
111
|
+
Auto-generate HarmonyOS signing materials (local p12/csr + cloud cert + test profile) and write signing config to `build-profile.json5`.
|
|
112
|
+
- **Prereq**: `devecocli auth login` first; run from a project directory (with `build-profile.json5`); a connected device or emulator is required for device registration.
|
|
113
|
+
- `--product <name>`: Product name for local p12/csr file naming (default: `default`).
|
|
114
|
+
- `--team-id <id>`: Specify the team-id (default: current user's id).
|
|
115
|
+
- `--force`: Force regenerate even if existing materials are valid.
|
|
116
|
+
- Generates under `~/.ohos/config/`: `.p12` keystore, `.csr`, downloaded `.cer` certificate, `.p7b` profile.
|
|
117
|
+
- Writes `signingConfigs` + `products` entries to `build-profile.json5` with encrypted key/store passwords (AES-128-GCM).
|
|
118
|
+
- Cloud cert name: `auto_debug_<teamId>.cer`. Local files: `<product>_<project>_<hash>=.{p12,csr,cer,p7b}`.
|
|
119
|
+
- Error handling (aligned with DevEco Studio JAR): 401→re-login, 403→no AGC permission, `205389872`→cert limit, `205389904`→not Harmony user, `205389938`→provision limit, invalid `.cer`→retry.
|
|
120
|
+
*Ex*: `devecocli signature generate --product default`
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
### `devecocli log`
|
|
124
|
+
Fetch hilog or crash logs. Req `--device <name|serial>` on multi-device hosts.
|
|
125
|
+
- `--crash`: Dump crash logs.
|
|
126
|
+
- `--level D|I|W|E|F`: Filter by level.
|
|
127
|
+
- `--bundle-name` / `--keyword`: Filter output.
|
|
128
|
+
- `--from <start>` / `--to <end>`: Relative offsets (`30s`, `5m`).
|
|
129
|
+
- `--tail <num>`: Return the latest N matching log lines; must be a positive integer. Defaults to 2000 only when none of `--tail`, `--from`, `--to`, `--follow`, or `--crash` is present.
|
|
130
|
+
- `--follow`: The native CLI follows logs until stopped, but the DevEco Code proxy buffers output until the child exits; it is not a live log stream in the tool response. Prefer bounded `--from` / `--tail` queries for interactive diagnosis. Cannot be combined with `--to`.
|
|
131
|
+
- `clear [--device <name|serial>]`: Clear hilog before reproducing an issue. Without a selector, exactly one connected device is required. Names must resolve uniquely; prefer a serial when names repeat.
|
|
132
|
+
- Invalid clear selectors, device discovery failures, missing HDC, and HDC failure output return an error without reporting successful cleanup.
|
|
133
|
+
*Ex*: `devecocli log --crash --bundle-name com.example.app`, `devecocli log --level E --from 5m --tail 200`
|
|
134
|
+
|
|
135
|
+
### `devecocli ui`
|
|
136
|
+
Inspect UI on a connected device. All subcommands accept `--device <name|serial>` (Req on multi-device hosts).
|
|
137
|
+
|
|
138
|
+
| Subcommand | Description | Key Options |
|
|
139
|
+
|---|---|---|
|
|
140
|
+
| `layout` | Dump ArkUI accessibility layout tree — **visible area only** (on-screen nodes) | `--id <id>`, `--window <windowId>`, `--all-windows`, `--depth <n>` (0=unlimited, 1=root only, 2=root+children), `--format default\|json`, `--mode full\|simplified` |
|
|
141
|
+
| `window list` | List active windows | `--format default\|json`, `--all` (include system windows) |
|
|
142
|
+
| `screenshot` | Capture a screenshot of the device screen | `--display <displayId>`, required `--path <path>` (existing directory or PNG file path; relative paths supported; writable destination; no overwrite) |
|
|
143
|
+
| `click [x] [y]` | Tap at the specified coordinates or node | `--id <id>` (auto-resolves to center), `--window <windowId>` (used with `--id`) |
|
|
144
|
+
| `doubleclick [x] [y]` | Double-tap at the specified coordinates or node | `--id <id>`, `--window <windowId>` |
|
|
145
|
+
| `longclick [x] [y]` | Long-press at the specified coordinates or node | `--id <id>`, `--window <windowId>` |
|
|
146
|
+
| `swipe <x1> <y1> <x2> <y2>` | Swipe from one point to another (precise coordinates, custom speed) | `--speed <n>` (200–40000, px/s) |
|
|
147
|
+
| `fling <x1> <y1> <x2> <y2>` | Fling from one point to another | `--speed <n>` (200–40000, px/s) |
|
|
148
|
+
| `drag <x1> <y1> <x2> <y2>` | Drag from one point to another | `--speed <n>` (200–40000, px/s) |
|
|
149
|
+
| `dircfling <direction>` | Quick directional fling (system default speed, ideal for scrolling) | `direction`: `up`, `down`, `left`, `right` |
|
|
150
|
+
| `text <text> [x] [y]` | Input text at a target location or the currently focused field | `--id <id>` (auto-resolves to center), `--window <windowId>` (used with `--id`) |
|
|
151
|
+
|
|
152
|
+
- **Coordinates vs `--id`**: Mutually exclusive. Provide either `x y` or `--id <id>`. For `text`, if neither is given, text goes to the currently focused field.
|
|
153
|
+
- **`--window`**: May only be used together with `--id`. Default is focused window. Secondary display operations via `--id` + `--window` are not supported.
|
|
154
|
+
- **`swipe` vs `dircfling`**: `swipe` requires exact start/end coordinates and supports `--speed`; `dircfling` only needs a direction (`up/down/left/right`) and uses system default speed (ideal for page/list scrolling).
|
|
155
|
+
- **Text encoding**: Special characters in `text` are Base64-encoded internally to safely pass through device shell.
|
|
156
|
+
- `--format json` pairs well with `jq`.
|
|
157
|
+
- `--mode full`: full layout tree, no filtering.
|
|
158
|
+
- `--mode simplified` (default): folds meaningless wrapper containers (non-root, no `id`, no text, not interactive) by lifting their surviving children up. `--depth` truncates after folding.
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
## 2. Setup
|
|
162
|
+
|
|
163
|
+
### `devecocli init`
|
|
164
|
+
MUTUALLY EXCLUSIVE modes for setup:
|
|
165
|
+
1. `--skill` (Default): Install `deveco-cli` skill to AI agents.
|
|
166
|
+
2. `--mcp`: Configure `deveco-mcp` server (ArkTS/C++ syntax checking).
|
|
167
|
+
*Options*:
|
|
168
|
+
- `--agent <agents>`: Comma-separated (e.g. `opencode,cursor`). Omitting targets all.
|
|
169
|
+
- `--project <path>`: Project-level config (Abs path for MCP).
|
|
170
|
+
- `--path <path>`: Direct skill install path.
|
|
171
|
+
- `-f, --force`: Overwrite existing config.
|
|
172
|
+
*MCP Rules*: Global MCP (no `--project`) only supports `opencode` and `cursor`. Others require `--project`.
|
|
173
|
+
|
|
174
|
+
DevEco Code already ships this Router-aware skill. Do not use `init --skill` to overwrite it with the native CLI skill; use that installer only for separately requested agent/project setup.
|
|
175
|
+
|
|
176
|
+
### `devecocli auth login`
|
|
177
|
+
Sign in to your Huawei Developer account. Opens a browser for OAuth authentication. Required before `signature generate`.
|
|
178
|
+
*Ex*: `devecocli auth login`
|
|
179
|
+
|
|
180
|
+
### `devecocli auth logout`
|
|
181
|
+
Sign out and clear locally stored credentials.
|
|
182
|
+
|
|
183
|
+
### `devecocli auth status`
|
|
184
|
+
Show the current logged-in user.
|
|
185
|
+
|
|
186
|
+
### `devecocli auth team list`
|
|
187
|
+
List team accounts the current user has joined.
|
|
188
|
+
|
|
189
|
+
### `devecocli skills`
|
|
190
|
+
Manage HarmonyOS skills in AI agents/projects.
|
|
191
|
+
- `list [-l|--long]` / `find <keyword>`: List or search skills.
|
|
192
|
+
- `add (--all | --skill <name>) [--agent <a,b…>] [--project <path>] [--path <path>] [-f]`: Install.
|
|
193
|
+
- `remove --skill <name> [...]`: Uninstall.
|
|
194
|
+
|
|
195
|
+
### `devecocli check compat` `[Outside sandbox]`
|
|
196
|
+
Scan source code for breaking API changes between two SDK versions. Built on top of DevEco Studio's `arkanalyzer-apiscan` plugin.
|
|
197
|
+
- `versions`: List available target SDK versions. Opts: `--format <default|json>` (default: `default`).
|
|
198
|
+
- Default (no args): project-level scan.
|
|
199
|
+
- `--modules <m1> [m2...]`: Module-level scan.
|
|
200
|
+
- `<file1> [file2...]`: File-level scan (`.ets`/`.c`/`.cpp` only).
|
|
201
|
+
- `--source-version <v>` (Req) / `--target-version <v>` (Req): SDK version pair. Run `devecocli check compat versions` first; on zsh, **quote the value** (e.g. `"<source_version>"`, `"<target_version>"`).
|
|
202
|
+
- `--format <default|csv|json>` (default: `default`): Console output accepts `default` (text) or `json`; file output (via `--output-path`) accepts `default` (csv), `csv`, or `json`. `csv` requires `--output-path`.
|
|
203
|
+
- `--output-path <path>`: Directory (writes `apiChange-*.csv`/`apiChange-*.json`) or explicit file (extension must match `--format`).
|
|
204
|
+
- `--limit <n>` (default `100`): Max records shown on console when no `--output-path`.
|
|
205
|
+
|
|
206
|
+
Validation order: `files` + `--modules` mutually exclusive → `--source-version`/`--target-version` required → `csv` requires `--output-path` → project dir valid → modules exist → files exist + extension valid → versions in catalog + `target > source` → format/extension match → output target writable.
|
|
207
|
+
|
|
208
|
+
*Ex*: `devecocli check compat --source-version "<source_version>" --target-version "<target_version>" --output-path ./report`
|
|
209
|
+
|
|
210
|
+
## 3. Maintenance
|
|
211
|
+
|
|
212
|
+
- **`devecocli update`** `[Outside sandbox]`: Native standalone CLI updater. DevEco Code pins its bundled CLI; do not use this command or a global npm install to upgrade the bundle. Upgrade DevEco Code itself, or update its pinned dependency, lockfile, and this skill together during repository development.
|
|
213
|
+
- **`devecocli serve mcp`**: Host stdio MCP server (`check` tool for `.ets`/C/C++). Used via `init --mcp`. (Env: `PROJECT_PATH`, `DEVECO_PATH`, `NODE_MAX_OLD_SPACE_SIZE`, `DEBUG=1`).
|
|
214
|
+
|
|
215
|
+
## Recipes
|
|
216
|
+
|
|
217
|
+
- **Fresh checkout to emulator**:
|
|
218
|
+
`devecocli run` (builds and deploys; Router selects/starts the sole target). If there are multiple targets, choose one and retry with `--device "Name"`. After a separate successful build, use `devecocli run --skip-build`.
|
|
219
|
+
- **Diagnose crash**:
|
|
220
|
+
`devecocli log --crash --bundle-name <bundle>`
|
|
221
|
+
- **Release build**:
|
|
222
|
+
`devecocli build --product oversea --build-mode release`
|
|
223
|
+
- **First-time signing setup**:
|
|
224
|
+
`devecocli auth login` -> `devecocli signature generate --product default` -> `devecocli build` -> `devecocli run`
|
|
225
|
+
|
|
226
|
+
## Troubleshooting
|
|
227
|
+
|
|
228
|
+
- **"Product / Build mode `<x>` not found"**: Check `build-profile.json5`.
|
|
229
|
+
- **"Multiple entry modules" / "No entry module"**: Pass `--modules` (build) or `--module` (run).
|
|
230
|
+
- **"No active devices" / "Multiple devices connected"**: Connect/start emulator. Pass `-t <serial>` (device view) or `--device <name|serial>` (run/log).
|
|
231
|
+
- **`error:install sign info inconsistent`**: Signing key changed. Run `devecocli run --uninstall` or `devecocli signature generate --force`.
|
|
232
|
+
- **`Not logged in. Run devecocli auth login first`**: Run `devecocli auth login` to authenticate.
|
|
233
|
+
- **`Provision number exceeds limit`**: Test provision quota is full. Delete old test provisions in DevEco Studio (Signing Configs) or AGC console, then retry `devecocli signature generate`.
|
|
234
|
+
- **`Invalid AccessToken. Sign in and try again`**: Token expired. Run `devecocli auth login` again.
|
|
235
|
+
- **`skills add` agent not found**: Valid: `atomcode`, `codebuddy`, `cursor`, `opencode`, `qoder`, `trae-cn`.
|
|
236
|
+
- **`emulator start` / `image download` blocked on agreement**: User MUST accept agreements. Interactive: `devecocli emulator license` (requires TTY). Non-interactive (CI/scripts): `devecocli emulator license accept`. Ask the user to review and accept; run the non-interactive acceptance only if explicitly authorized. Do not retry until accepted.
|
|
237
|
+
- **`image download` failure / timeout**: Do NOT auto-retry. Give the command to the user to run manually in their terminal.
|
|
238
|
+
- **`emulator create` timeout**: Treat as user-action step. Ask user to open DevEco Studio -> Device Manager. Check `emulator list` after user confirms. Do NOT auto-retry or edit SDK files.
|
|
239
|
+
- **`image list` duplicate OS rows**: `phone`/`foldable`/`widefold`/`triplefold` share the same image. Download/remove ONCE per OS version.
|
|
240
|
+
- **`ui layout` missing expected node**: `layout` only returns on-screen nodes. Scroll the target into view with `ui dircfling` / `ui swipe` when appropriate for the requested UI task, or ask the user to scroll, then retry `ui layout`.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hmos-arkui-develop-skill
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: hmos-arkui-develop-skill
|
|
3
|
+
description: REQUIRED before writing the first .ets file of a session. Fatal gotchas list + API quick-reference for HarmonyOS ArkTS/ArkUI development. Load this skill when writing or modifying .ets files, porting TypeScript to ArkTS, or building any ArkUI page, component, layout, navigation, dialog, state-driven UI, or animation. Covers ArkTS linter rules, forbidden syntax, null safety, struct/@Component constraints, V1/V2 state management, rendering control, API parameter correctness, and UI quality. Triggers — .ets, ArkTS, ArkUI, HarmonyOS, struct, @Component, TS-to-ArkTS migration, ArkUI build error, runtime crash.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# ArkTS/ArkUI 编码约束
|
|
7
|
+
|
|
8
|
+
为 agent 写 ArkTS/ArkUI 代码提供致命陷阱清单和准确的 API 参考入口。
|
|
9
|
+
|
|
10
|
+
## API 和约束查表优先
|
|
11
|
+
|
|
12
|
+
1. **写任何组件前,必须同时查两类文件**:
|
|
13
|
+
- **API 签名**:在 `references/quick-apis/_index.md` 定位组件所在文件,用 Grep 取卡片(勿整读大文件)。签名必须照搬,不得凭记忆改写、增减参数或改变参数类型
|
|
14
|
+
- **约束规则**:在 `references/quick-rules/_index.md` 按任务特征查对应规则文件,提前预防错误
|
|
15
|
+
2. **组件→规则文件交叉索引**(写某组件时,必查对应的规则文件):
|
|
16
|
+
|
|
17
|
+
| 写这些组件/功能时 | 必查 API 文件 | 必查规则文件 |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| List / Grid / WaterFlow / Tabs / Scroll | 01-layout | 12-layout(子组件约束)+ 06-rendering(ForEach/LazyForEach/Repeat) |
|
|
20
|
+
| Navigation / NavDestination | 12-navigation | 08-navigation(路由栈、pushPath param) |
|
|
21
|
+
| @State/@Link/@Prop/@Local/@Param 等 | 08-state-decorators | 05-state(V1/V2 混用、@Builder 传参、@ObjectLink 限制) |
|
|
22
|
+
| Button / Text / Image / TextInput | 02-basic-components | 07-attribute-params(臆造 API 清单) |
|
|
23
|
+
| DatePicker / TimePicker / TextPicker | 04-selectors | 07-attribute-params(构造参数字段名高发错) |
|
|
24
|
+
| AlertDialog / ActionSheet / bindSheet | 11-dialog-menu | 09-dialog(堆叠规则) |
|
|
25
|
+
| animateTo / transition | 09-animation | 07-attribute-params(curve 必须枚举等) |
|
|
26
|
+
| 手势 / 拖拽 | 10-gesture | 11-extension(手势绑定、拖拽冲突) |
|
|
27
|
+
| import / router / promptAction | — | 01-import(kit 路径)+ 02-uicontext(全局接口替换) |
|
|
28
|
+
|
|
29
|
+
## 高频错误及约束
|
|
30
|
+
|
|
31
|
+
### ArkTS 语法
|
|
32
|
+
|
|
33
|
+
1. 不使用 any/unknown 类型、以及...解构赋值
|
|
34
|
+
2. 从回调 / Map.get / Array.find / 可选属性取值时做空安全处理(`??` 默认值或判空)
|
|
35
|
+
3. 函数与箭头函数参数必须显式标注类型;泛型函数调用必须显式指定类型参数——`arr.map(x => x.id)` ❌、`arr.map((x: Item): string => x.id)` ✅;`new Map()` ❌、`new Map<string, number>()` ✅;`arr.find(x => x.id === 1)` ❌、`arr.find((x: Item): boolean => x.id === 1)` ✅(依赖推断会报 `arkts-no-any-unknown` 或 `arkts-no-inferred-generic-params`)
|
|
36
|
+
|
|
37
|
+
### 命名与作用域
|
|
38
|
+
|
|
39
|
+
4. ArkTS 不支持声明合并(arkts-no-decl-merging),同一项目中不同文件的顶层 interface/class/struct 名不能重复,也不能与系统组件/全局类型重名——自定义名称一律加业务前缀
|
|
40
|
+
- WRONG: 文件A声明 `interface Item`,文件B也声明 `interface Item`
|
|
41
|
+
- RIGHT: 文件A用 `interface CartItem`,文件B用 `interface OrderItem`,按业务语义区分命名
|
|
42
|
+
5. 变量名/参数名/方法名避开框架保留字(如 `builder`/`create`/`value`),否则报 `arkts-unique-names` 或 `10505001`——见 `references/quick-rules/03-component.md` 保留字全表
|
|
43
|
+
6. **@State/@Prop/@Local 等成员名禁止与链式方法重名**——`value`/`width`/`height`/`margin`/`padding`/`offset`/`position`/`border`/`backgroundColor`/`opacity`/`visibility`/`scale`/`rotate`/`size`/`direction`/`enabled`/`zIndex`/`layoutWeight`/`alignItems`/`justifyContent`/`alignContent` 等通用属性名均为禁区 → **10505001**。用业务前缀消歧义:`currentValue` 而非 `value`
|
|
44
|
+
|
|
45
|
+
### build() 与组件结构
|
|
46
|
+
|
|
47
|
+
7. @Entry 根节点必须是单个容器组件(Column/Row/Stack 等);@Component 根节点可为非容器,但必须是唯一节点,但 **`ForEach` 仍不可作为根节点**
|
|
48
|
+
|
|
49
|
+
8. build() 中不声明本地变量、不用 console,详细可以参考`references/quick-rule/build.md`
|
|
50
|
+
|
|
51
|
+
9. ForEach / LazyForEach / Repeat 必须显式提供 key(用业务 ID 不用索引);省略时 ForEach 默认 `JSON.stringify`(bigint/循环引用会 jscrash),Repeat 生成随机值(每次更新全量重建)
|
|
52
|
+
|
|
53
|
+
10. `@Entry` 不能用 `@ObjectLink`,必须抽子组件
|
|
54
|
+
|
|
55
|
+
11. **Button('label') 与子组件互斥**——`Button('OK') { Text('x') }` ❌ → **10905202**;`Button('OK')` ✅ 或 `Button() { Text('x') }` ✅
|
|
56
|
+
|
|
57
|
+
12. **@Builder 返回 void,调用处不可链式**——`myBuilder().onClick(...)` ❌
|
|
58
|
+
|
|
59
|
+
13. **嵌套 ForEach 参数名必须不同**——外层 `row` 内层 `cell`,不用 `item`/`item`
|
|
60
|
+
|
|
61
|
+
### 状态管理
|
|
62
|
+
|
|
63
|
+
14. V1/V2 状态管理不混用——@Component 内只能用 @State/@Prop/@Link/@Provide/@Consume/@Watch/@ObjectLink/@Observed;@ComponentV2 内只能用 @Local/@Param/@Provider/@Consumer/@Monitor/@Computed/@ObservedV2/@Trace;AppStorageV2/PersistenceV2 只能在@ComponentV2 内使用;@Link/@ObjectLink 不本地初始化(值从父组件传入)
|
|
64
|
+
15. `@State` 只代理第一层;嵌套属性变化不刷新,需 `@Observed` 类 + 子组件 `@ObjectLink` 逐层代理
|
|
65
|
+
16. `@Builder` 按引用传递:形参用 `$$: InterfaceType` 接收,调用时传单参数对象字面量 `myBuilder({ key: this.val })`;多参数不刷新;@Builder 方法定义在 build() 之前;参数类型必须用显式声明的 interface/class,禁止内联对象字面量类型 → **10605040**
|
|
66
|
+
17. **@Param 只读**——`this.x = ...` 在 @ComponentV2 内报 `Cannot assign to 'x' because it is a read-only property`;@Local 只能内部初始化,调用处传值不生效
|
|
67
|
+
18. **@ObjectLink 禁止整体赋值**——`this.objLink = new Info()` ❌,只能改属性
|
|
68
|
+
|
|
69
|
+
### 布局与渲染
|
|
70
|
+
|
|
71
|
+
19. 部分容器组件内部只允许放对应的子组件,如`List与ListItem、Grid与GridItem`等
|
|
72
|
+
20. `ForEach`/`LazyForEach`/`Repeat` **不是真实组件**,返回的 `ForEachAttribute` 等不支持 `.layoutWeight()`/`.width()` 等通用布局属性
|
|
73
|
+
21. Repeat (V2)设置了virtualScroll懒加载情况下仅 `@ComponentV2` 内可用
|
|
74
|
+
22. **Repeat 的 cachedCount 放滚动容器上**——`Repeat(arr).cachedCount(3)` ❌ → **10505001**;`List() { Repeat(arr) }.cachedCount(3)` ✅
|
|
75
|
+
23. **LazyForEach 的 dataSource 不可重新赋值**,修改数据后必须通过 DataChangeListener 通知更新
|
|
76
|
+
|
|
77
|
+
### API 参数(编译必挂高频)
|
|
78
|
+
|
|
79
|
+
24. 传给组件构造/API 的对象字面量,字段名与 Options 类型逐字一致
|
|
80
|
+
25. 回调参数类型用编译器声明的联合类型,不自行收窄(如 `onChange(index: number)` → 实际签名是 `onChange(index: number | string)`)
|
|
81
|
+
26. **构造参数字段名不能凭记忆编造**——实测高发:`TimePicker({ useMilitaryTime: true })` ❌(useMilitaryTime 是 TimePickerDialog 的字段);`Tabs(this.tabsController)` ❌(构造参数是 `{ controller: ... }`);`MenuItem({ value: '复制', icon: $r(...) })` ❌(正确字段是 content + startIcon);`Shape({ viewPort: {...} })` ❌(viewPort 是链式方法);`PersistentStorage.persistProps([{ key: 'k', default: 'v' }])` ❌(正确字段是 defaultValue)
|
|
82
|
+
|
|
83
|
+
详细规则文件索引见 `references/quick-rules/_index.md`。
|