@deveco-test/hmos-deveco-cli 0.1.0-TD.4 → 0.1.0-TD.4.1

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/README.md CHANGED
@@ -2,31 +2,35 @@
2
2
  <h1>DevEco CLI</h1>
3
3
  <p>一个面向 HarmonyOS 应用开发的统一命令行入口。</p>
4
4
  <p>
5
- <a href="https://www.npmjs.com/package/@deveco/deveco-cli"><img src="https://img.shields.io/npm/v/@deveco/deveco-cli.svg" alt="NPM Version" /></a>
6
- <a href="https://www.npmjs.com/package/@deveco/deveco-cli"><img src="https://img.shields.io/npm/dm/@deveco/deveco-cli.svg" alt="NPM Downloads" /></a>
5
+ <a href="https://www.npmjs.com/package/@deveco-test/hmos-deveco-cli"><img src="https://img.shields.io/npm/v/@deveco/deveco-cli.svg" alt="NPM Version" /></a>
6
+ <a href="https://www.npmjs.com/package/@deveco-test/hmos-deveco-cli"><img src="https://img.shields.io/npm/dm/@deveco-test/hmos-deveco-cli.svg" alt="NPM Downloads" /></a>
7
7
  <a href="https://nodejs.org/"><img src="https://img.shields.io/badge/Node.js-%3E%3D18-green.svg" alt="Node.js" /></a>
8
- <img src="https://img.shields.io/badge/platform-macOS%20%7C%20Windows-blue.svg" alt="Platform" />
9
- <a href="https://developer.huawei.com/consumer/cn/download/"><img src="https://img.shields.io/badge/DevEco%20Studio-%3E%3D6.1.0-orange.svg" alt="DevEco Studio" /></a>
8
+ <img src="https://img.shields.io/badge/platform-HarmonyOS-blue.svg" alt="Platform" />
9
+ </a>
10
10
  <a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License" /></a>
11
11
  </p>
12
12
  </div>
13
13
 
14
- `DevEco CLI` 将 `DevEco Studio` 工具链统一封装为一个 `CLI`,内置 `ohpm`、`hvigor`、`hdc`、`emulator`、`hilog`,同时集成 HarmonyOS 技能安装、项目脚手架、本地 HarmonyOS 文档检索和 `MCP` 服务。
14
+ `DevEco CLI` 将 `DevEco Studio` 工具链统一封装为一个 `CLI`,内置 `ohpm`、`hvigor`、`hdc`、`hilog`,同时集成 HarmonyOS 技能安装、项目脚手架、本地 HarmonyOS 文档检索和 `MCP` 服务。
15
15
 
16
16
 
17
17
  ## 快速开始
18
18
 
19
19
  ### 前置要求
20
20
 
21
- - 操作系统为 `macOS` 或 `Windows`
22
- - Node.js >= 18,推荐使用22及以上版本
23
- - [DevEco Studio](https://developer.huawei.com/consumer/cn/download/) >= 6.1.0
24
- - **macOS**:必须安装在 `~/Applications` 或 `/Applications` 目录下。
21
+ - 操作系统为 `HarmonyOS`
22
+ - 安装 Command Line Tool 工具
23
+ - 配置环境变量:
24
+ ```bash
25
+ export COMMAND_LINE_TOOL_PATH=path/to/deveco_tools
26
+ export PATH=$PATH:path/to/deveco_tools/node/bin
27
+ ```
28
+
25
29
 
26
30
  ### 安装
27
31
 
28
32
  ```bash
29
- npm install -g @deveco/deveco-cli@latest
33
+ npm install -g @deveco-test/hmos-deveco-cli
30
34
  ```
31
35
 
32
36
  安装后可以通过以下命令更新到最新版本:
@@ -72,12 +76,12 @@ opencode
72
76
  如果 `Agent` 不在 `--agent` 参数取值范围内,可使用 `--path` 参数进行添加,参考如下命令:
73
77
 
74
78
  ```bash
75
- devecocli init --path D:\work\ARKTS\NewData
79
+ devecocli init --path .\work\ARKTS\NewData
76
80
  ```
77
81
 
78
82
  进入 `Agent` 后可以直接描述任务,例如:
79
83
 
80
- - `Build this project in release mode and run it on my emulator`
84
+ - `Build this project in release mode and run it on my device`
81
85
  - `Tail the last error logs from this app`
82
86
  - `Check for syntax errors in src/main/ets/pages/Index.ets`
83
87
 
@@ -89,7 +93,6 @@ devecocli init --path D:\work\ARKTS\NewData
89
93
  | `devecocli build` | 构建项目并产出 `.hap` / `.hsp` / `.har` / `.app` |
90
94
  | `devecocli run` | 安装并运行应用 |
91
95
  | `devecocli device list` | 查看当前连接设备 |
92
- | `devecocli emulator list` | 查看本地模拟器实例 |
93
96
  | `devecocli log` | 查看 `hilog` 或崩溃日志 |
94
97
  | `devecocli docs search` | 搜索本地 HarmonyOS 文档 |
95
98
  | `devecocli init` | 安装内置技能或配置 `MCP` |
@@ -122,7 +125,6 @@ Commands:
122
125
  run [options] Build and run the project on a connected device
123
126
  update Update deveco-cli to the latest version
124
127
  device Manage connected devices
125
- emulator Manage emulator instances
126
128
  skills Manage HarmonyOS skills
127
129
  log [options] Obtain device application logs
128
130
  create [options] Scaffold a new HarmonyOS application project
@@ -160,12 +162,12 @@ devecocli init --agent <agents> --project <path> --path <path> --skill --mcp --f
160
162
  devecocli init -f # 安装或更新deveco-cli Skill
161
163
  devecocli init --skill
162
164
  devecocli init --agent agentname # agentname需替换为实际的智能体名称
163
- devecocli init --path D:\work\ARKTS\NewData -f
165
+ devecocli init --path /path/to/project -f
164
166
 
165
167
  # 配置MCP
166
168
  devecocli init --mcp
167
169
  devecocli init --mcp --agent agentname # agentname需替换为实际的智能体名称
168
- devecocli init --mcp --project D:\work\ARKTS\NewData -f
170
+ devecocli init --mcp --project /path/to/project -f
169
171
  ```
170
172
 
171
173
  ### `docs search`
@@ -310,214 +312,9 @@ devecocli build --product oversea --modules entry --build-mode release
310
312
  devecocli build clean
311
313
  ```
312
314
 
313
- ### `emulator list`
314
-
315
- 查看模拟器实例
316
-
317
- **命令格式:**
318
-
319
- ```bash
320
- devecocli emulator list
321
- ```
322
-
323
- ### `emulator start`
324
-
325
- 启动模拟器。首次使用时,需要签署 HarmonyOS 软件许可与服务协议,具体请参考 `emulator license accept`
326
-
327
- **命令格式:**
328
-
329
- ```bash
330
- devecocli emulator start [names...]
331
- ```
332
-
333
- **参数:**
334
-
335
- | 参数名 | 说明 |
336
- | ----------- | ----------------------------------------- |
337
- | \[names...] | 必选,模拟器实例名称,多个名称用空格隔开。若名称中带有空格,则名称需要添加英文引号 |
338
-
339
- **示例:**
340
-
341
- ```bash
342
- devecocli emulator start Phone
343
- devecocli emulator start Phone1 Phone2
344
- ```
345
-
346
- **说明:**
347
-
348
- - `emulator start` 命令仅支持启动 `release` 版本的模拟器
349
-
350
- ### `emulator stop`
351
-
352
- 关闭模拟器
353
-
354
- **命令格式:**
355
-
356
- ```bash
357
- devecocli emulator stop [names...]
358
- ```
359
-
360
- **参数:**
361
-
362
- | 参数名 | 说明 |
363
- | ----------- | ----------------------------------------- |
364
- | \[names...] | 必选,模拟器实例名称,多个名称用空格隔开。若名称中带有空格,则名称需要添加英文引号 |
365
-
366
- **示例:**
367
-
368
- ```bash
369
- devecocli emulator stop Phone
370
- devecocli emulator stop 127.0.0.1:5555
371
- ```
372
-
373
- ### `emulator create`
374
-
375
- 创建模拟器
376
-
377
- **命令格式:**
378
-
379
- ```bash
380
- devecocli emulator create <name> --device-type <type> --os-version <version> --force
381
- ```
382
-
383
- **参数:**
384
-
385
- | 参数名 | 说明 |
386
- | ------------- | ------------------------------------------------------------------------------------------------------------------------------- |
387
- | name | 必选,模拟器名称 |
388
- | --device-type | 必选,模拟器设备类型,支持 `phone` , `foldable` , `widefold` , `triplefold` , `tablet` , `2in1` , `2in1 foldable` , `tv` , `wearable` ,全小写 |
389
- | --os-version | 必选,模拟器镜像版本 |
390
- | --force | 可选,覆盖已有同名的模拟器 |
391
-
392
- **示例:**
393
-
394
- ```bash
395
- devecocli emulator create MyPhone --device-type phone --os-version "HarmonyOS 6.0.1(21)"
396
- ```
397
-
398
- ### `emulator delete`
399
-
400
- 创建模拟器
401
-
402
- **命令格式:**
403
-
404
- ```bash
405
- devecocli emulator delete <name>
406
- ```
407
-
408
- **参数:**
409
-
410
- | 参数名 | 说明 |
411
- | ---- | -------------- |
412
- | name | 必选,模拟器实例名称或序列号 |
413
-
414
- **示例:**
415
-
416
- ```bash
417
- devecocli emulator delete MyPhone
418
- ```
419
-
420
- ### `emulator image list`
421
-
422
- 查询模拟器镜像列表
423
-
424
- **命令格式:**
425
-
426
- ```bash
427
- devecocli emulator image list --device-type <type> --all --format <format>
428
- ```
429
-
430
- **参数:**
431
-
432
- | 参数名 | 说明 |
433
- | ------------- | -------------------------------------------------------------------------------------------------------------------------- |
434
- | --device-type | 可选,模拟器设备类型,支持 `phone` , `foldable` , `widefold` , `triplefold` , `tablet` , `2in1` , `2in1 foldable` , `tv` , `wearable` |
435
- | --all | 可选,查询已下载和未下载的所有镜像 |
436
- | --format | 可选,控制输出格式,取值为 `table` 或 `json` ,默认为 `table` |
437
-
438
- **示例:**
439
-
440
- ```bash
441
- devecocli emulator image list
442
- devecocli emulator image list --all
443
- devecocli emulator image list --device-type phone
444
- devecocli emulator image list --format json
445
- ```
446
-
447
- ### `emulator image download`
448
-
449
- 下载模拟器镜像。首次使用时,需要签署 HarmonyOS `SDK` 许可协议,具体请参考 `emulator license accept`
450
-
451
- **命令格式:**
452
-
453
- ```bash
454
- devecocli emulator image download --device-type <type> --os-version <version> --force
455
- ```
456
-
457
- **参数:**
458
-
459
- | 参数名 | 说明 |
460
- | ------------- | ------------------------------------------------------------------------------------------------------------------------------- |
461
- | --device-type | 必选,模拟器设备类型,支持 `phone` , `foldable` , `widefold` , `triplefold` , `tablet` , `2in1` , `2in1 foldable` , `tv` , `wearable` ,全小写 |
462
- | --os-version | 必选,模拟器镜像版本 |
463
- | --force | 可选,覆盖已有的模拟器镜像 |
464
-
465
- **示例:**
466
-
467
- ```bash
468
- devecocli emulator image download --device-type phone --os-version "HarmonyOS 6.0.1(21)" --force
469
- ```
470
-
471
- **说明:**
472
-
473
- - `emulator image download` 命令仅支持下载 `release` 版本的模拟器镜像
474
-
475
- ### `emulator image remove`
476
-
477
- 删除模拟器镜像
478
-
479
- **命令格式:**
480
-
481
- ```bash
482
- devecocli emulator image remove --device-type <type> --os-version <version>
483
- ```
484
-
485
- **参数:**
486
-
487
- | 参数名 | 说明 |
488
- | ------------- | ------------------------------ |
489
- | --device-type | 必选,模拟器设备类型,与下载镜像的device-type一致 |
490
- | --os-version | 必选,模拟器镜像版本,与下载镜像的os-version一致 |
491
-
492
- **示例:**
493
-
494
- ```bash
495
- devecocli emulator image remove --device-type phone --os-version "HarmonyOS 6.0.1(21)"
496
- ```
497
-
498
- ### `emulator license view`
499
-
500
- 查看协议文本(只读)
501
-
502
- **命令格式:**
503
-
504
- ```bash
505
- devecocli emulator license view
506
- ```
507
-
508
- ### `emulator license accept`
509
-
510
- 查看并接受协议。使用模拟器需要同意 HarmonyOS 软件许可与服务协议,下载镜像需要同意 HarmonyOS `SDK` 许可协议
511
-
512
- **命令格式:**
513
-
514
- ```bash
515
- devecocli emulator license accept
516
- ```
517
-
518
315
  ### `device list`
519
316
 
520
- 查询所有已连接的设备,包括真机设备和运行中的模拟器
317
+ 查询所有已连接的设备
521
318
 
522
319
  **命令格式:**
523
320
 
@@ -551,7 +348,7 @@ devecocli device view -t "My Device Name"
551
348
 
552
349
  ### `run`
553
350
 
554
- 构建应用后,将应用安装到真机设备或模拟器上,并启动执行
351
+ 构建应用后,将应用安装到设备上,并启动执行
555
352
 
556
353
  **命令格式:**
557
354
 
@@ -733,9 +530,8 @@ devecocli skills remove --skill skillname --agent agentname # skillname需替
733
530
  "mcp"
734
531
  ],
735
532
  "environment":{
736
- "PROJECT_PATH": "D:\\code\\sample_project", // 工程路径
533
+ "PROJECT_PATH": "/path/to/project", // 工程路径
737
534
  "NODE_MAX_OLD_SPACE_SIZE": "8192", // 可选,设置内部node进程最大的老生代内存大小,默认为8192
738
- "DEVECO_PATH": "D:\\Application\\DevEco Studio" // 可选,Deveco Studio的路径
739
535
  },
740
536
  "enbale": true
741
537
  }
@@ -745,7 +541,32 @@ devecocli skills remove --skill skillname --agent agentname # skillname需替
745
541
 
746
542
  ## 常见问题
747
543
 
748
- [FAQ](https://gitcode.com/openharmony-sig/deveco-cli/wiki/FAQ.md)
544
+ ### 如何本地推包运行
545
+
546
+ 当没有真机设备连接时,可以通过无线调试实现自连,在本地推包运行应用:
547
+
548
+ **步骤 1:开启无线调试**
549
+
550
+ 在设备上进入:系统 → 开发者选项 → 无线调试,开启无线调试功能。
551
+
552
+ **步骤 2:配置 hdc 命令路径**
553
+
554
+ 将 hdc 工具路径添加到环境变量:
555
+
556
+ ```bash
557
+ export PATH=$PATH:path/to/deveco_tools/sdk/default/openharmony/toolchains
558
+ ```
559
+
560
+ **步骤 3:通过 hdc 命令自连**
561
+
562
+ 使用 hdc 命令连接设备的 IP 和端口:
563
+
564
+ ```bash
565
+ hdc tconn IP:端口
566
+ ```
567
+
568
+ 连接成功后,即可使用 `devecocli run` 命令推包运行应用。
569
+
749
570
 
750
571
  ## 开发
751
572
 
package/SKILL.md CHANGED
@@ -1,13 +1,18 @@
1
- ---
1
+ ---
2
2
  name: deveco-cli
3
3
  description: >-
4
- **MUST** use 'devecocli' for HarmonyOS apps (scaffold, build, run, debug, devices, emulators, logs, docs, 鸿蒙开发文档, skills). **REQUIRED** and **MANDATORY** if workspace has build-profile.json5 or oh-package.json5, or user mentions HarmonyOS, 鸿蒙, DevEco, ArkTS, ArkUI, docs, 鸿蒙文档, 知识, 搜索, or skills.
4
+ **MUST** use 'devecocli' for HarmonyOS apps (scaffold, build, run, debug, devices, emulators, logs, docs, 鸿蒙开发文档, skills, multi-preview). **REQUIRED** and **MANDATORY** if workspace has build-profile.json5 or oh-package.json5, or user mentions HarmonyOS, 鸿蒙, DevEco, ArkTS, ArkUI, docs, 鸿蒙文档, 知识, 搜索, skills, or preview/预览/预览器/多预览器/多设备预览器.
5
5
  ---
6
6
 
7
7
  # DevEco CLI
8
8
 
9
9
  `devecocli` wraps DevEco Studio's `hvigor`, `ohpm`, `hdc`, emulator toolchain, and HarmonyOS-skills installer. **Prefer `devecocli` over invoking underlying tools directly.**
10
10
 
11
+ **Do NOT use these legacy commands** — use the `devecocli` equivalent instead:
12
+ - ❌ `deveco preview` / `hvigorw preview` → ✅ `devecocli run --preview` (launches DevEco Studio previewer)
13
+ - ❌ `hvigorw` directly → ✅ `devecocli build`
14
+ - ❌ `hdc` directly (when a `devecocli` wrapper exists) → ✅ `devecocli device` / `devecocli log` / `devecocli run`
15
+
11
16
  Available commands: `build`, `run`, `update`, `device`, `emulator`, `skills`, `log`, `create`, `init`, `serve`, `docs`.
12
17
 
13
18
  **Sandbox Rule**: Commands tagged `[Outside sandbox]` must be run outside the sandbox.
@@ -60,6 +65,12 @@ Build, install, and launch.
60
65
  - `--ability <ability>`: Default from `module.json5`.
61
66
  - `--uninstall`: Uninstall existing app first (Fixes signing key issues).
62
67
  - `--skip-build`: Deploy existing artifacts.
68
+ - `--preview`: Launch the DevEco Studio **previewer** instead of installing/running the app. Ensures the DevEco Studio desktop process is running first (throws immediately if not — does NOT auto-start Studio on any platform), then `hdc shell aa start -a DevEcoViewerAbility -b com.huawei.devecostudio -m DevEcoViewer --pi instanceId <pid> --ps paramJson <JSON with double-quotes escaped>` with project info (`bundleName` / `abilityName` / `moduleName` / `productName` / `productType` / `subProductType` / `instanceId` / `launchDeviceIndex` / `launchFlag` / `isCustom` / `nativeDebuggable` / `appDebuggable`). `instanceId` = CLI process.pid (identifies which IDE launched); `launchDeviceIndex` = -1 for single previewer, 0-based for multi. Skips build/install. **Cross-platform**:
69
+ - **Windows/macOS**: uses DevEco Studio's bundled hdc, auto-detects Studio install path via ToolProvider.
70
+ - **HarmonyOS native (2in1 PC)**: hdc does NOT auto-discover the local device — self-connect required. Resolution chain for the target port: `--device 127.0.0.1:<port>` (or bare port) → `DEVECO_HDC_PORT` env var → existing `hdc list targets` → interactive prompt → error. DevEco Studio is a system app there (no launcher script, `hap` under `/data/app/el1/bundle/public/com.huawei.devecostudio/`); local `pgrep` cannot see Studio's process due to UID isolation (currentUser 20020102 vs Studio 20020176), so the CLI detects Studio via `hdc shell ps -ef | grep com.huawei.devecostudio` (hdcd runs as root, can see all UIDs) — this requires the hdc self-connect to be established first, so on HarmonyOS the device selection step runs before IDE detection. The CLI does NOT auto-start Studio on any platform — if Studio is not detected, `--preview` throws immediately and the user must start DevEco Studio manually.
71
+ - `--count <n>` (Previewer only, mutually exclusive with `--devices`): Launch N previewer windows by list order (multi-previewer mode). Each device type at most one window.
72
+ - `--devices <names>` (Previewer only, mutually exclusive with `--count`): Launch specified device types, comma-separated (e.g. `"Pura 90 Pro,MatePad 11.5'S"`). Supported: `Pura 90 Pro`, `MatePad 11.5'S`, `Mate X7`, `Pura X`, `Mate XT`. Single name → single previewer of that type. **Smart matching**: case/whitespace/punctuation insensitive; accepts aliases (`phone`, `tablet`/`pad`, `fold`/`foldable`, `widefold`/`wide`, `triplefold`/`triple`) and short forms (`pura90`, `matepad`, `matex7`, `purax`, `matext`); substring match and Levenshtein distance ≤ 2 auto-correction are applied as fallback. Ambiguous matches report candidates.
73
+ - **Agent hint**: After a successful single-preview launch where the user did NOT specify device type or count (i.e. bare `devecocli run --preview`), briefly inform the user in natural language that they can try specifying a device type to preview, and that they can also try launching multiple different device previewers at once. Do NOT mention specific CLI flags (like `--devices` or `--count`) or print command examples — keep it conversational. Do NOT print this hint if the user already specified device type or count.
63
74
 
64
75
  ### `devecocli log`
65
76
  Fetch hilog or crash logs. Req `--device <name|serial>` on multi-device hosts.
@@ -98,6 +109,13 @@ Manage HarmonyOS skills in AI agents/projects.
98
109
 
99
110
  - **Fresh checkout to emulator**:
100
111
  `devecocli build` -> `devecocli emulator list` -> `devecocli emulator start "Name"` -> `devecocli run`
112
+ - **Launch previewer for current project** (instead of `deveco preview`):
113
+ - Single previewer (default first device in list): `devecocli run --preview`
114
+ - Single previewer, specific device type: `devecocli run --preview --devices "MatePad 11.5'S"`
115
+ - Multi-preview by count: `devecocli run --preview --count 2`
116
+ - Multi-preview by device types: `devecocli run --preview --devices "Pura 90 Pro,Mate XT"`
117
+ - On HarmonyOS native PC: ensure wireless debugging is on, then `devecocli run --preview` will self-connect (or pass `--device 127.0.0.1:<port>`)
118
+ - `--count` and `--devices` are mutually exclusive
101
119
  - **Diagnose crash**:
102
120
  `devecocli log --crash --bundle-name <bundle>`
103
121
  - **Release build**:
@@ -114,3 +132,5 @@ Manage HarmonyOS skills in AI agents/projects.
114
132
  - **`image download` failure / timeout**: Do NOT auto-retry. Give the command to the user to run manually in their terminal.
115
133
  - **`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.
116
134
  - **`image list` duplicate OS rows**: `phone`/`foldable`/`widefold`/`triplefold` share the same image. Download/remove ONCE per OS version.
135
+ - **HarmonyOS native (2in1 PC) — `hdc list targets` shows `[Empty]`**: hdc on HarmonyOS does NOT auto-discover the local device. Open "Settings → System → Developer options → Wireless debugging", note the port, then `hdc tconn 127.0.0.1:<port>`. Or pass `--device 127.0.0.1:<port>` / set `DEVECO_HDC_PORT` to let `run --preview` self-connect.
136
+ - **`run --preview` — "DevEco Studio is not running"**: The previewer's rendering depends on the DevEco Studio desktop process. If the CLI returns this error, do NOT retry. Use natural language to tell the user: "预览器需要 DevEco Studio 处于运行状态,请先手动启动 DevEco Studio,启动后再重试此命令。" On HarmonyOS PC, also remind the user that process detection may be limited by UID isolation (currentUser cannot see Studio's process), but if the CLI reports this error it means detection genuinely failed.