AgentSkillsCN

ohhdc

OpenHarmony HDC工具专为设备HAP管理而设计。当用户需要列出已安装的应用、卸载HAP(bm uninstall -n <bundleName>)、安装HAP(hdc install <path>)、替换安装HAP(hdc -r install <path>)、查看前台或运行中的应用(aa dump -a / aa dump -r)、强制停止应用(aa force-stop <bundleName>)、启动应用(aa start -a <abilityName> -b <bundleName>),或运行测试(aa test -b <bundleName> -m <moduleName> -s unittest OpenHarmonyTestRunner -s class <suiteName>[#<caseName>] -s timeout <timeout>)时,均可使用此工具。其结果将以Markdown格式呈现。

SKILL.md
--- frontmatter
name: ohhdc
description: "OpenHarmony HDC tool for device HAP management. Use when users need to list installed apps, uninstall a HAP (bm uninstall -n <bundleName>), install a HAP (hdc install <path>), replace-install a HAP (hdc -r install <path>), view foreground/running apps (aa dump -a / aa dump -r), force-stop an app (aa force-stop <bundleName>), start an app (aa start -a <abilityName> -b <bundleName>), or run tests (aa test -b <bundleName> -m <moduleName> -s unittest OpenHarmonyTestRunner -s class <suiteName>[#<caseName>] -s timeout <timeout>). Presents results in Markdown format."
author: "Created by user"
created: "2026-01-28"
version: "1.0.0"

OpenHarmony HDC Skill

This skill provides capabilities for OpenHarmony/HarmonyOS devices via HDC (HarmonyOS Device Connector): list installed HAP apps, uninstall HAP, install HAP, replace-install HAP, view foreground/running applications, force-stop applications, start applications, and run tests.

Query Installed Apps

Feature Description

List device-installed HAP applications. The skill runs hdc shell "bm dump -a" to get all installed bundle names (HAP apps) from the connected device, then formats the output as Markdown for easy reading.

When to Use

  • User asks: "查看设备上安装的 HAP" / "查看设备安装的 app" / "设备上装了多少 hap"
  • User asks: "List installed apps on device" / "Show device HAP apps" / "How many apps are installed"
  • User needs to inspect or count installed applications on an OpenHarmony/HarmonyOS device

How It Works

  1. Execute: bash -c "source ~/.bashrc && hdc shell 'bm dump -a'" (so hdc is in PATH from bashrc)
  2. Parse output: skip ID: lines, strip leading tabs/spaces, extract bundle names (lines containing . or starting with ohos.)
  3. Deduplicate and format as Markdown: table + bullet list

Usage in Conversation

Natural language examples:

  • "查看设备上安装的 HAP"
  • "查看设备安装的 app"
  • "设备上装了多少 hap"
  • "List installed apps on the device"
  • "Show me the installed HAP apps"

The assistant uses this skill to run the script and show the result in Markdown.

Quick Start – Using the Script

bash
# From project root; ensure hdc is available (e.g. source ~/.bashrc in your shell first)

# List installed apps, Markdown format (default)
python3 .claude/skills/ohhdc/ohhdc.py apps

# Same, explicit format
python3 .claude/skills/ohhdc/ohhdc.py list-apps --format markdown

# Plain text list
python3 .claude/skills/ohhdc/ohhdc.py apps --format plain

Available commands:

  • apps / list-apps – List installed HAP apps (bundle names).
  • --format markdown or --format md – Output as Markdown (default).
  • --format plain or --format list – Output as plain text list.

Uninstall HAP

Feature Description

Uninstall a HAP from the device by bundle name. Uses:
hdc shell "bm uninstall -n <bundleName>".

When to Use

  • User says: "卸载设备上的 xxx 应用" / "卸载 com.example.p7zipTest" / "uninstall HAP com.xxx.xxx"
  • User needs to remove a specific app by its bundle name.

How It Works

  1. Execute: bash -c "source ~/.bashrc && hdc shell \"bm uninstall -n <bundleName>\""
  2. Print success or error.

Usage in Conversation

  • "卸载 com.example.p7zipTest"
  • "Uninstall the app com.example.p7zipTest from the device"

Quick Start – Script

bash
# Uninstall by bundle name (required)
python3 .claude/skills/ohhdc/ohhdc.py uninstall com.example.p7zipTest

Parameter: target = bundle name (e.g. com.example.p7zipTest).


Install HAP

Feature Description

Install a HAP file onto the device. Uses:
hdc install <hap_path>.

When to Use

  • User says: "安装这个 HAP 到设备" / "把 xxx.hap 装到设备" / "install HAP /path/to/app.hap"
  • User provides a HAP file path and wants to install it.

How It Works

  1. Execute: bash -c "source ~/.bashrc && hdc install <hap_path>"
  2. Path is quoted so spaces are safe.
  3. Print success or error.

Usage in Conversation

  • "安装 /root/workspace/napi_generator/src/skills/ohhap/NativeProj46R/autosign/app1-signed.hap"
  • "Install the HAP at .../app1-signed.hap to the device"

Quick Start – Script

bash
# Install HAP (target = full path to .hap file)
python3 .claude/skills/ohhdc/ohhdc.py install /root/workspace/napi_generator/src/skills/ohhap/NativeProj46R/autosign/app1-signed.hap

Parameter: target = absolute or relative path to the .hap file.


Replace Install HAP

Feature Description

Replace-install a HAP (overwrite existing app with same bundle name). Uses:
hdc -r install <hap_path>.

When to Use

  • User says: "替换安装这个 HAP" / "覆盖安装 xxx.hap" / "replace install /path/to/app.hap"
  • User wants to update an already installed app by reinstalling the HAP.

How It Works

  1. Execute: bash -c "source ~/.bashrc && hdc -r install <hap_path>"
  2. Path is quoted so spaces are safe.
  3. Print success or error.

Usage in Conversation

  • "替换安装 /root/workspace/napi_generator/src/skills/ohhap/NativeProj46R/autosign/app1-signed.hap"
  • "Replace-install the HAP at .../app1-signed.hap"

Quick Start – Script

bash
# Replace-install HAP (target = full path to .hap file)
python3 .claude/skills/ohhdc/ohhdc.py replace-install /root/workspace/napi_generator/src/skills/ohhap/NativeProj46R/autosign/app1-signed.hap

Parameter: target = absolute or relative path to the .hap file.


View Foreground/Running Apps

Feature Description

View foreground applications and running app processes on the device. Uses:

  • hdc shell "aa dump -a" - View all abilities (foreground and background)
  • hdc shell "aa dump -r" - View running abilities (app processes)

Extracts key information: bundle name, ability name, ability type, app state (FOREGROUND/BACKGROUND), start time, AbilityRecord ID, and running app processes (process name, PID, UID, state).

When to Use

  • User says: "查看前台应用" / "查看正在运行的应用" / "查看设备上的前台应用"
  • User says: "Show foreground apps" / "View running applications" / "What apps are running"
  • User needs to inspect which apps are currently active on the device

How It Works

  1. Execute: bash -c "source ~/.bashrc && hdc shell \"aa dump -a\"" (or aa dump -r for running only)
  2. Parse output: extract AbilityRecord info (bundle name, ability type, app state, etc.) and AppRunningRecords (process info)
  3. Format as Markdown: show foreground apps table and running app processes table

Usage in Conversation

  • "查看前台应用"
  • "查看正在运行的应用"
  • "设备上哪些应用在前台"
  • "Show foreground apps on the device"
  • "View running applications"

Quick Start – Script

bash
# View foreground apps (default: shows foreground + running processes)
python3 .claude/skills/ohhdc/ohhdc.py foreground

# Same, short form
python3 .claude/skills/ohhdc/ohhdc.py fg

# View all abilities (including background)
python3 .claude/skills/ohhdc/ohhdc.py dump-all

# View running abilities only
python3 .claude/skills/ohhdc/ohhdc.py running
python3 .claude/skills/ohhdc/ohhdc.py dump-running

Available commands:

  • foreground / fg – View foreground apps and running processes (default view)
  • dump-all – View all abilities including background ones
  • running / dump-running – View running abilities/app processes only

Output includes:

  • Foreground Apps Table: Bundle Name, Ability Name, Type, State, AbilityRecord ID, Start Time
  • Running App Processes Table: Process Name, PID, UID, State

Force Stop Application

Feature Description

Force-stop an application by bundle name. Uses:
hdc shell "aa force-stop <bundleName>".

When to Use

  • User says: "强制关闭 xxx 应用" / "关闭 com.ohos.settings" / "force stop app com.xxx.xxx"
  • User needs to forcefully terminate a running application on the device.

How It Works

  1. Execute: bash -c "source ~/.bashrc && hdc shell \"aa force-stop <bundleName>\""
  2. Print success or error.

Usage in Conversation

  • "强制关闭 com.ohos.settings"
  • "关闭设置应用"
  • "Force stop the app com.ohos.settings"

Quick Start – Script

bash
# Force-stop by bundle name (required)
python3 .claude/skills/ohhdc/ohhdc.py force-stop com.ohos.settings

# Same, short form
python3 .claude/skills/ohhdc/ohhdc.py stop com.ohos.settings

Parameter: target = bundle name (e.g. com.ohos.settings).


Start Application

Feature Description

Start an application by bundle name and ability name. Uses:
hdc shell "aa start -a <abilityName> -b <bundleName>".

When to Use

  • User says: "启动 xxx 应用" / "打开 com.ohos.settings" / "start app com.xxx.xxx"
  • User needs to launch an application on the device.

How It Works

  1. Execute: bash -c "source ~/.bashrc && hdc shell \"aa start -a <abilityName> -b <bundleName>\""
  2. Print success or error.

Usage in Conversation

  • "启动 com.ohos.settings 应用"
  • "打开设置应用,使用 EntryAbility"
  • "Start the app com.ohos.settings with EntryAbility"

Quick Start – Script

bash
# Start app (requires bundleName and ability name)
python3 .claude/skills/ohhdc/ohhdc.py start com.ohos.settings --ability EntryAbility

# Same, using short form
python3 .claude/skills/ohhdc/ohhdc.py start com.ohos.settings -a EntryAbility

Parameters:

  • target = bundle name (e.g. com.ohos.settings)
  • --ability / -a = ability name (e.g. EntryAbility)

Note: Common ability names include:

  • EntryAbility - Main entry ability
  • com.ohos.settings.MainAbility - Settings main ability
  • Check installed apps or use aa dump -a to find ability names

Run Tests

Feature Description

Run test cases for an application. Uses:
hdc shell "aa test -b <bundleName> -m <moduleName> -s unittest OpenHarmonyTestRunner -s class <suiteName>[#<caseName>] -s timeout <timeout>".

Supports:

  • Run specific test case: Provide suite name and case name (e.g., ActsAbilityTest#assertContain)
  • Run full test suite: Provide only suite name (e.g., ActsAbilityTest)

When to Use

  • User says: "运行测试" / "执行测试用例" / "运行 ohos.test.nativeproj46r 的测试"
  • User says: "Run tests for app" / "Execute test case" / "Run ActsAbilityTest#assertContain"
  • User needs to run unit tests or specific test cases on the device.

How It Works

  1. Execute: bash -c "source ~/.bashrc && hdc shell \"aa test -b <bundleName> -m <moduleName> -s unittest OpenHarmonyTestRunner -s class <suiteName>[#<caseName>] -s timeout <timeout>\""
  2. If caseName is provided, runs specific test case: suiteName#caseName
  3. If caseName is not provided, runs full test suite: suiteName
  4. Print test execution results.

Usage in Conversation

  • "运行 ohos.test.nativeproj46r 的测试"
  • "执行 ActsAbilityTest#assertContain 测试用例"
  • "运行 entry_test 模块的全量测试"
  • "Run tests for ohos.test.nativeproj46r"
  • "Execute test case ActsAbilityTest#assertContain"

Quick Start – Script

bash
# Run specific test case
python3 .claude/skills/ohhdc/ohhdc.py test ohos.test.nativeproj46r \
  --module entry_test \
  --suite ActsAbilityTest \
  --case assertContain \
  --timeout 15000

# Run full test suite (omit --case)
python3 .claude/skills/ohhdc/ohhdc.py test ohos.test.nativeproj46r \
  --module entry_test \
  --suite ActsAbilityTest \
  --timeout 15000

# Using short form
python3 .claude/skills/ohhdc/ohhdc.py test ohos.test.nativeproj46r \
  -m entry_test \
  -s ActsAbilityTest \
  -c assertContain \
  -t 15000

Parameters:

  • target = bundle name (e.g. ohos.test.nativeproj46r) - required
  • --module / -m = module name (e.g. entry_test) - required
  • --suite / -s = test suite name (e.g. ActsAbilityTest) - required
  • --case / -c = test case name (e.g. assertContain) - optional, if provided runs specific case, otherwise runs full suite
  • --timeout / -t = timeout in milliseconds (default: 15000) - optional

Examples:

bash
# Run specific test case
python3 .claude/skills/ohhdc/ohhdc.py test ohos.test.nativeproj46r \
  -m entry_test -s ActsAbilityTest -c assertContain

# Run full test suite
python3 .claude/skills/ohhdc/ohhdc.py test ohos.test.nativeproj46r \
  -m entry_test -s ActsAbilityTest

# With custom timeout (30 seconds)
python3 .claude/skills/ohhdc/ohhdc.py test ohos.test.nativeproj46r \
  -m entry_test -s ActsAbilityTest -t 30000

环境与通用说明

Environment Requirements(适用于所有操作)

  • hdc: OpenHarmony/HarmonyOS HDC 需在 PATH 中。若通过 source ~/.bashrc 配置,脚本会执行 bash -c "source ~/.bashrc && hdc ..." 以保证能找到 hdc
  • Device: 设备或模拟器需已连接并被 hdc 识别。

Example Output(仅“查看已安装应用”)

markdown
## 已安装应用

共找到 **48** 个已安装应用:

| 序号 | Bundle Name |
|------|-------------|
| 1 | `com.OpenHarmony.app.test` |
| 2 | `com.example.kikakeyboard` |
...

### 应用列表(纯文本)

- `com.OpenHarmony.app.test`
- `com.example.kikakeyboard`
...

Script Location

  • Skill: .claude/skills/ohhdc/SKILL.md
  • Script: .claude/skills/ohhdc/ohhdc.py

Summary

Trigger (conversation)Action
查看设备上的已安装应用/HAPRun ohhdc.py apps,展示 Markdown 结果
设备上装了多少 hapRun ohhdc.py apps,展示数量与列表
卸载 xxx 应用 / uninstallRun ohhdc.py uninstall <bundleName>,如 uninstall com.example.p7zipTest
安装 HAP / installRun ohhdc.py install <HAP 路径>,如 install /path/to/app-signed.hap
替换安装 HAP / replace-installRun ohhdc.py replace-install <HAP 路径>,如 replace-install /path/to/app-signed.hap
查看前台应用 / foregroundRun ohhdc.py foregroundohhdc.py fg,展示前台应用和运行进程
查看正在运行的应用 / runningRun ohhdc.py running,展示运行中的应用进程
查看所有 ability / dump-allRun ohhdc.py dump-all,展示所有 ability(包括后台)
强制关闭应用 / force-stopRun ohhdc.py force-stop <bundleName>ohhdc.py stop <bundleName>,如 force-stop com.ohos.settings
启动应用 / startRun ohhdc.py start <bundleName> --ability <abilityName>,如 start com.ohos.settings --ability EntryAbility
运行测试 / testRun ohhdc.py test <bundleName> --module <moduleName> --suite <suiteName> [--case <caseName>],如 test ohos.test.nativeproj46r -m entry_test -s ActsAbilityTest -c assertContain