harmonyos-device-automation by web-infra-dev/midscene-skills
npx skills add https://github.com/web-infra-dev/midscene-skills --skill harmonyos-device-automation关键规则 — 违反将导致工作流中断:
- 切勿在后台运行 midscene 命令。 每个命令必须同步运行,以便您(AI 代理)在决定下一步操作之前能够读取其输出(尤其是截图)。后台执行会破坏截图-分析-操作的循环。
- 一次只运行一个 midscene 命令。 等待上一个命令完成,读取截图,然后决定下一个操作。切勿将多个命令链接在一起运行。
- 为每个命令留出足够的完成时间。 Midscene 命令涉及 AI 推理和屏幕交互,可能比典型的 shell 命令耗时更长。一个典型命令大约需要 1 分钟;复杂的
act命令可能需要更长时间。
使用 npx @midscene/harmony@1 自动化 HarmonyOS NEXT 设备。每个 CLI 命令都直接对应一个 MCP 工具 — 您(AI 代理)作为大脑,根据截图决定采取哪些操作。
act 能做什么在 HarmonyOS 上,单个 act 调用中,Midscene 可以从当前可见屏幕出发,执行点击、双击、长按、输入、清除文本、滚动、拖拽项目、按键以及使用系统导航(如返回、主页或最近应用)等操作。双指缩放不可用,因为底层的 HarmonyOS 自动化层未暴露多点触控输入。
Midscene 需要具备强大视觉理解能力的模型。必须配置以下环境变量 — 可以作为系统环境变量,也可以在当前工作目录的 .env 文件中配置(Midscene 会自动加载 .env):
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
MIDSCENE_MODEL_API_KEY="your-api-key"
MIDSCENE_MODEL_NAME="model-name"
MIDSCENE_MODEL_BASE_URL="https://..."
MIDSCENE_MODEL_FAMILY="family-identifier"
示例:Gemini (Gemini-3-Flash)
MIDSCENE_MODEL_API_KEY="your-google-api-key"
MIDSCENE_MODEL_NAME="gemini-3-flash"
MIDSCENE_MODEL_BASE_URL="https://generativelanguage.googleapis.com/v1beta/openai/"
MIDSCENE_MODEL_FAMILY="gemini"
示例:Qwen 3.5
MIDSCENE_MODEL_API_KEY="your-aliyun-api-key"
MIDSCENE_MODEL_NAME="qwen3.5-plus"
MIDSCENE_MODEL_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"
MIDSCENE_MODEL_FAMILY="qwen3.5"
MIDSCENE_MODEL_REASONING_ENABLED="false"
# 如果使用 OpenRouter,请设置:
# MIDSCENE_MODEL_API_KEY="your-openrouter-api-key"
# MIDSCENE_MODEL_NAME="qwen/qwen3.5-plus"
# MIDSCENE_MODEL_BASE_URL="https://openrouter.ai/api/v1"
示例:Doubao Seed 2.0 Lite
MIDSCENE_MODEL_API_KEY="your-doubao-api-key"
MIDSCENE_MODEL_NAME="doubao-seed-2-0-lite"
MIDSCENE_MODEL_BASE_URL="https://ark.cn-beijing.volces.com/api/v3"
MIDSCENE_MODEL_FAMILY="doubao-seed"
常用模型:Doubao Seed 2.0 Lite、Qwen 3.5、Zhipu GLM-4.6V、Gemini-3-Pro、Gemini-3-Flash。
如果模型未配置,请要求用户进行设置。支持的提供商请参阅模型配置。
必须安装并可使用 HDC(HarmonyOS Device Connector)。常见设置:
HDC_HOME 环境变量指向 HDC 目录验证 HDC 是否正常工作:
hdc version
hdc list targets
npx @midscene/harmony@1 connect
npx @midscene/harmony@1 connect --deviceId 0123456789ABCDEF
当您希望在任务开始前有一个确定的起点时,请使用专用的启动步骤:
npx @midscene/harmony@1 launch --uri com.huawei.hmos.settings
npx @midscene/harmony@1 launch --uri com.huawei.hmos.camera
npx @midscene/harmony@1 launch --uri https://www.example.com
当任务需要底层的设备控制,而这些控制不适合表达为可见的 UI 交互时,请使用此命令:
npx @midscene/harmony@1 runhdcshell --command "hidumper -s RenderService -a screen"
此命令会转发到已连接设备的 hdc shell。实际上,底层命令是 hdc -t <deviceId> shell hidumper -s RenderService -a screen。
npx @midscene/harmony@1 take_screenshot
截图后,读取保存的图像文件以了解当前屏幕状态,然后再决定下一步操作。
使用 act 与设备交互并获取结果。它会在内部自主处理所有 UI 交互 — 点击、输入、滚动、滑动、等待和导航 — 因此您应该将复杂的高级任务作为一个整体交给它,而不是将其分解为小步骤。用自然语言描述您想做什么以及期望的效果:
# 具体指令
npx @midscene/harmony@1 act --prompt "type hello world in the search field and press Enter"
npx @midscene/harmony@1 act --prompt "long press the message bubble and tap Delete in the popup menu"
# 或目标驱动的指令
npx @midscene/harmony@1 act --prompt "open Settings and navigate to Wi-Fi settings, tell me the connected network name"
npx @midscene/harmony@1 disconnect
由于 CLI 命令在调用之间是无状态的,请遵循以下模式:
act 执行操作以执行期望的操作或目标驱动的指令。hdc shell aa start -a EntryAbility -b <bundleName>)。然后截图以确认应用确实在前台。只有在视觉确认后,才应继续使用此技能进行 UI 自动化。HDC 命令比使用 midscene 导航和打开应用要快得多。"the Wi-Fi toggle switch on the right side",而不是 "the toggle"。"the search icon at the top right"、"the third item in the list")。act 命令中:当在同一应用内执行连续操作时,将它们合并到一个 act 提示中,而不是拆分成多个命令。例如,"open Settings, tap Wi-Fi, and toggle it on" 应该是一个 act 调用,而不是三个。这减少了往返次数,避免了不必要的截图-分析循环,并且速度显著更快。示例 — 应用启动和交互:
hdc shell aa start -a EntryAbility -b com.huawei.hmos.settings
npx @midscene/harmony@1 connect
npx @midscene/harmony@1 take_screenshot
npx @midscene/harmony@1 act --prompt "scroll down the settings list and tap About device"
npx @midscene/harmony@1 take_screenshot
npx @midscene/harmony@1 disconnect
示例 — 表单交互:
npx @midscene/harmony@1 act --prompt "fill in the username field with 'testuser' and the password field with 'pass123', then tap the Login button"
npx @midscene/harmony@1 take_screenshot
| 应用 | 包名 |
|---|---|
| 设置 | com.huawei.hmos.settings |
| 相机 | com.huawei.hmos.camera |
| 图库 | com.huawei.hmos.photos |
| 日历 | com.huawei.hmos.calendar |
| 时钟 | com.huawei.hmos.clock |
| 计算器 | com.huawei.hmos.calculator |
| 浏览器 | com.huawei.hmos.browser |
| 天气 | com.huawei.hmos.weather |
| 问题 | 解决方案 |
|---|---|
| 未找到 HDC | 通过 DevEco Studio 安装或设置 HDC_HOME 环境变量。 |
| 设备未列出 | 检查 USB 连接,确保开发者选项中已启用 USB 调试,并运行 hdc list targets。 |
| 命令超时 | 设备屏幕可能已关闭或锁定。唤醒设备并解锁。 |
| API 密钥错误 | 检查 .env 文件是否包含 MIDSCENE_MODEL_API_KEY=<your-key>。请参阅模型配置。 |
| 目标设备错误 | 如果连接了多个设备,请在 connect 命令中使用 --deviceId <id> 标志。 |
每周安装量
392
仓库
GitHub Stars
141
首次出现
2026年3月6日
安全审计
安装于
openclaw248
codex178
cursor176
opencode176
cline174
kimi-cli173
CRITICAL RULES — VIOLATIONS WILL BREAK THE WORKFLOW:
- Never run midscene commands in the background. Each command must run synchronously so you can read its output (especially screenshots) before deciding the next action. Background execution breaks the screenshot-analyze-act loop.
- Run only one midscene command at a time. Wait for the previous command to finish, read the screenshot, then decide the next action. Never chain multiple commands together.
- Allow enough time for each command to complete. Midscene commands involve AI inference and screen interaction, which can take longer than typical shell commands. A typical command needs about 1 minute; complex
actcommands may need even longer.
Automate HarmonyOS NEXT devices using npx @midscene/harmony@1. Each CLI command maps directly to an MCP tool — you (the AI agent) act as the brain, deciding which actions to take based on screenshots.
act Can DoInside a single act call on HarmonyOS, Midscene can tap, double-tap, long-press, type, clear text, scroll, drag items, press keys, and use system navigation such as Back, Home, or recent apps while working from the current visible screen. Two-finger zoom is not available because the underlying HarmonyOS automation layer does not expose multi-touch input.
Midscene requires models with strong visual grounding capabilities. The following environment variables must be configured — either as system environment variables or in a .env file in the current working directory (Midscene loads .env automatically):
MIDSCENE_MODEL_API_KEY="your-api-key"
MIDSCENE_MODEL_NAME="model-name"
MIDSCENE_MODEL_BASE_URL="https://..."
MIDSCENE_MODEL_FAMILY="family-identifier"
Example: Gemini (Gemini-3-Flash)
MIDSCENE_MODEL_API_KEY="your-google-api-key"
MIDSCENE_MODEL_NAME="gemini-3-flash"
MIDSCENE_MODEL_BASE_URL="https://generativelanguage.googleapis.com/v1beta/openai/"
MIDSCENE_MODEL_FAMILY="gemini"
Example: Qwen 3.5
MIDSCENE_MODEL_API_KEY="your-aliyun-api-key"
MIDSCENE_MODEL_NAME="qwen3.5-plus"
MIDSCENE_MODEL_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"
MIDSCENE_MODEL_FAMILY="qwen3.5"
MIDSCENE_MODEL_REASONING_ENABLED="false"
# If using OpenRouter, set:
# MIDSCENE_MODEL_API_KEY="your-openrouter-api-key"
# MIDSCENE_MODEL_NAME="qwen/qwen3.5-plus"
# MIDSCENE_MODEL_BASE_URL="https://openrouter.ai/api/v1"
Example: Doubao Seed 2.0 Lite
MIDSCENE_MODEL_API_KEY="your-doubao-api-key"
MIDSCENE_MODEL_NAME="doubao-seed-2-0-lite"
MIDSCENE_MODEL_BASE_URL="https://ark.cn-beijing.volces.com/api/v3"
MIDSCENE_MODEL_FAMILY="doubao-seed"
Commonly used models: Doubao Seed 2.0 Lite, Qwen 3.5, Zhipu GLM-4.6V, Gemini-3-Pro, Gemini-3-Flash.
If the model is not configured, ask the user to set it up. See Model Configuration for supported providers.
HDC (HarmonyOS Device Connector) must be installed and accessible. Common setup:
HDC_HOME environment variable to point to the HDC directoryVerify HDC is working:
hdc version
hdc list targets
npx @midscene/harmony@1 connect
npx @midscene/harmony@1 connect --deviceId 0123456789ABCDEF
Use the dedicated launch step when you want a deterministic starting point before the rest of the task:
npx @midscene/harmony@1 launch --uri com.huawei.hmos.settings
npx @midscene/harmony@1 launch --uri com.huawei.hmos.camera
npx @midscene/harmony@1 launch --uri https://www.example.com
Use this when the task needs lower-level device control that is not best expressed as a visible UI interaction:
npx @midscene/harmony@1 runhdcshell --command "hidumper -s RenderService -a screen"
This is forwarded to hdc shell on the connected device. In practice, the underlying command is hdc -t <deviceId> shell hidumper -s RenderService -a screen.
npx @midscene/harmony@1 take_screenshot
After taking a screenshot, read the saved image file to understand the current screen state before deciding the next action.
Use act to interact with the device and get the result. It autonomously handles all UI interactions internally — tapping, typing, scrolling, swiping, waiting, and navigating — so you should give it complex, high-level tasks as a whole rather than breaking them into small steps. Describe what you want to do and the desired effect in natural language:
# specific instructions
npx @midscene/harmony@1 act --prompt "type hello world in the search field and press Enter"
npx @midscene/harmony@1 act --prompt "long press the message bubble and tap Delete in the popup menu"
# or target-driven instructions
npx @midscene/harmony@1 act --prompt "open Settings and navigate to Wi-Fi settings, tell me the connected network name"
npx @midscene/harmony@1 disconnect
Since CLI commands are stateless between invocations, follow this pattern:
act to perform the desired action or target-driven instructions.hdc shell aa start -a EntryAbility -b <bundleName>) before invoking any midscene commands. Then take a screenshot to confirm the app is actually in the foreground. Only after visual confirmation should you proceed with UI automation using this skill. HDC commands are significantly faster than using midscene to navigate to and open apps."the Wi-Fi toggle switch on the right side" instead of "the toggle"."the search icon at the top right", "the third item in the list").act command: When performing consecutive operations within the same app, combine them into one prompt instead of splitting them into separate commands. For example, "open Settings, tap Wi-Fi, and toggle it on" should be a single call, not three. This reduces round-trips, avoids unnecessary screenshot-analyze cycles, and is significantly faster.Example — App launch and interaction:
hdc shell aa start -a EntryAbility -b com.huawei.hmos.settings
npx @midscene/harmony@1 connect
npx @midscene/harmony@1 take_screenshot
npx @midscene/harmony@1 act --prompt "scroll down the settings list and tap About device"
npx @midscene/harmony@1 take_screenshot
npx @midscene/harmony@1 disconnect
Example — Form interaction:
npx @midscene/harmony@1 act --prompt "fill in the username field with 'testuser' and the password field with 'pass123', then tap the Login button"
npx @midscene/harmony@1 take_screenshot
| App | Bundle Name |
|---|---|
| Settings | com.huawei.hmos.settings |
| Camera | com.huawei.hmos.camera |
| Gallery | com.huawei.hmos.photos |
| Calendar | com.huawei.hmos.calendar |
| Clock | com.huawei.hmos.clock |
| Calculator | com.huawei.hmos.calculator |
| Browser | com.huawei.hmos.browser |
| Weather | com.huawei.hmos.weather |
| Problem | Solution |
|---|---|
| HDC not found | Install via DevEco Studio or set HDC_HOME environment variable. |
| Device not listed | Check USB connection, ensure USB debugging is enabled in Developer Options, and run hdc list targets. |
| Command timeout | The device screen may be off or locked. Wake the device and unlock it. |
| API key error | Check .env file contains MIDSCENE_MODEL_API_KEY=<your-key>. See Model Configuration. |
| Wrong device targeted | If multiple devices are connected, use flag with the command. |
Weekly Installs
392
Repository
GitHub Stars
141
First Seen
Mar 6, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
openclaw248
codex178
cursor176
opencode176
cline174
kimi-cli173
Skills CLI 使用指南:AI Agent 技能包管理器安装与管理教程
19,000 周安装
可预测收入框架:B2B销售系统构建与陌生电话拜访2.0外拓策略指南
303 周安装
社交媒体内容策略指南:LinkedIn、Twitter、Instagram、TikTok、Facebook平台优化与内容创作模板
303 周安装
data-extractor 数据提取技能:从PDF、Word、Excel等文档自动提取结构化数据
304 周安装
架构决策框架:需求驱动架构设计,ADR记录决策,权衡分析指南
304 周安装
使用reveal.js创建HTML幻灯片 | 交互式演示文稿制作工具 | 代码高亮与动画效果
304 周安装
移动应用发布策略指南:从ASO优化到推广渠道的完整发布计划
304 周安装
actact--deviceId <id>connect