HarmonyOS device bridge: hdc screenshot/install/log/crash/UI automation loop with read_image, official-first versioned API knowledge (SDK .d.ts + offline bundled docs), and a DevEco CLI build/sign/lint lane.
Install
# from npm (prebuilt)
dsh plugin --profile web add dsh-hdc-bridge
# from GitHub (first run asks for allowBuilds approval — follow the hint, retry)
dsh plugin --profile web add github:1na-ko/dsh-hdc-bridge
GitHub-sourced plugins run build scripts on your machine at install time. Only install sources you trust, and pin a commit (github:owner/repo#sha).
README
DSH 原生鸿蒙开发助手:
hdc设备闭环调试(看设备 → 截图 → 看图 → 改码 → 装包 → 验证)+ 官方优先版本化知识层(离线 Tier-1 随包 + SDK 机读 + 官方文档检索)+ 可选官方 DevEco CLI 构建/签名通道。 A DSH-native HarmonyOS dev assistant: the hdc device loop (inspect → screenshot → view → fix → install → verify), an official-first version-classified knowledge layer (offline Tier-1 bundled + SDK-accurate reads + official docs search), and an optional official DevEco CLI build/sign backend.
定位
hdc_mcp 等 MCP 服务器已覆盖 hdc 能力层。本插件不重写 hdc 协议,直接复用本机 hdc 二进制(3.x),价值在 DSH 原生层:
- 会话内工具卡片与
read_image原生闭环 - 按调用会话解析沙箱策略(与
pwsh工具同款路线),截图写入<workspace>/.dsh-hdc/screenshots/ - 结构化的失败上报(hdc 传输层退出码不可靠,插件用输出标记 + 落盘校验兜底)
工具
| 工具 | 说明 |
|---|---|
hdc_list_targets |
列出已连接设备/模拟器(空列表 + 连接指引) |
hdc_connect |
hdc tconn(严格 host:port 校验) |
hdc_shell |
设备 shell(param get / ps / uitest dumpLayout…) |
hdc_screenshot |
截图 → 拉取 JPEG → 落盘校验(API 10+ 的 snapshot_display 仅支持 .jpeg) |
hdc_install |
安装 .hap(默认 -r;输出标记级失败检测) |
hdc_hilog |
hilog 尾部 N 行(可选域名 -T 过滤,如 PARAM) |
hdc_ui_dump |
文本化 UI 快照:uitest 布局树 → 可见文本节点(纯文本模型的「文字截图」) |
hdc_ui_find |
按文本/hint 找控件:返回 bounds 与中心坐标,配合 tap 免手算坐标 |
hdc_ui |
UI 操作:tap / doubleTap / longPress / swipe / input / key(Back/Home/Power/keyID),配合 dump 形成「观察 → 操作 → 验证」闭环 |
hdc_app |
应用管理:query / start / stop / clear-data / uninstall(破坏性动作已标注) |
hdc_crash |
崩溃抓取:faultlogger 目录里最近的 jscrash / cppcrash / appfreeze,可按包名过滤,并解析结构化摘要(错误名/信息/错误码/源码帧/已知错误码提示) |
hdc_diag |
诊断:shell 口味 / hdc 路径 / 策略解析 / 探测日志 |
| 错误码提示 | install / app 失败时按错误码附中文修复建议(如 9568332 → 登记设备 UDID) |
hms_setup |
环境体检:hdc / DevEco Studio / SDK(API 版本) / devecocli / 设备五项 + 目标 API 版本三源解析(项目→设备→SDK)与不一致告警 |
hms_build |
官方构建/签名/运行通道:status / build / run / sign / clean;devecocli 缺失时自动回退本机 hvigorw + hdc_install + hdc_app 闭环 |
hms_api |
官方优先的版本化 API 知识:读本机 SDK .d.ts(@since/@deprecated/@syscap 精确到 API 版本),按目标版本分类"可用/已废弃/不可用" |
hms_knowledge |
离线随包官方知识层(Tier-1):OpenHarmony 官方文档(CC-BY-4.0)逐字节选 20 个高频 API 模块与应用模型/ArkTS 指南,无需 SDK/CLI/网络。catalog / read(先目录后按小节读)/ search |
hms_docs |
官方本地文档检索:devecocli docs search / read / catalog(Tier-2:全量文档,需 devecocli) |
hms_api_change |
官方跨版本破坏性变更扫描:devecocli check compat(versions / diff)——回答"知识在哪一版变了" |
hms_lint |
官方 lint:rules(本机 57+ 条 codelinter 规则索引)/ read-rule / check(devecocli check lint) |
| 运行时技能 | hdc-bridge(设备闭环用法)、deveco-cli(官方 SKILL.md 改写,MIT 声明保留)、harmonyos-knowledge(知识层纪律:官方优先、版本化、许可合规),模型按需加载 |
| 设备面板 | v0.6:web 宿主右上角浮动面板——已连接设备(型号/API 版本)、一键截图缩略、hilog 尾部、连接指引;数据走 /api2/hdc-bridge/* 只读 REST(8s 轮询 + 手动刷新),headless 宿主自动跳过 |
| 可选知识搭配 | Tier-2 社区包 harmony-next.skills(无 LICENSE,不随包,用户自行 npx skills add linhay/harmony-next.skills) |
安装 / Installation
# npm 安装 / install from npm
dsh plugin --profile <name> add dsh-hdc-bridge
# 或直接从 GitHub 安装(纯 JS、无构建步骤,无需授权 prepare)/ or install straight from GitHub (plain JS, no build step, no prepare grant needed)
dsh plugin --profile <name> add github:1na-ko/dsh-hdc-bridge
# 验证组合层,然后启动 / verify the composed layer, then boot
dsh --profile <name> --dump-config # 确认出现 dsh-hdc-bridge 层 / confirms the dsh-hdc-bridge layer
dsh --profile <name>
环境要求
- HarmonyOS 设备/模拟器;真机需开发者模式 + USB 调试
- hdc 二进制自动探测:DevEco Studio 常见 SDK 路径(
<DevEco>\sdk\<apiVer>\openharmony\toolchains\hdc.exe,apiVer 覆盖 default/10…18)→ PATH(where.exe/Get-Command/which) - 截图查看需图像输入模型;纯文本模型可用
hdc_ui_dump做文本化 UI 检查 - 可选后端
@deveco/deveco-cli(MIT)随插件作为 optionalDependency 自动安装(pnpm 失败容忍);构建/签名/lint 的--format json能力需本机 DevEco Studio ≥ 6.1.0(macOS/Windows,Node ≥ 18)。签名前需一次人工devecocli auth login(浏览器 OAuth) hms_api/hms_lint rules直接读本机 DevEco Studio/SDK 安装(零再分发);未装 Studio 时这两项降级并给出指引hms_knowledge的 Tier-1 官方知识节选随包内置(约 1.2MB,CC-BY-4.0 逐字节选并附署名),离线可用,无需任何本机安装hms_api_change(check compat)需要更高版本的 DevEco Studio(实测 6.1.0.830 报"min required 26.0.0.810");不满足时工具返回官方错误原文 + 升级指引,并提示先用hms_api的@since/@deprecated版本知识
依赖与许可合规
- 所有运行时依赖显式声明;本包代码保持零第三方 npm 依赖(解析器全部手写)
- 引用资源严格分四类并记录于 THIRD_PARTY_NOTICES.md(机器源
notices.json):① 随装依赖(devecocli,MIT);② 随包内容(knowledge/官方文档逐字节选,CC-BY-4.0 署名 + 逐文件溯源);③ 改写内容(deveco-cli技能改编自官方 SKILL.md,MIT 版权声明保留);④ 仅引用不分发(SDK .d.ts、codelinter 规则、harmony-next.skills 等——本机读取或链接指路) - 发布前跑
npm run license-check门禁:白名单校验(MIT/Apache-2.0/CC-BY-4.0/ISC/BSD/0BSD)、依赖声明与 notices 一致性、改写内容版权行存在性
权限与沙箱
- 工具按调用会话解析沙箱策略(会话 cwd 为工作区边界)
- 截图默认写入
<workspace>/.dsh-hdc/screenshots/,建议加入项目.gitignore - 若部署沙箱 runner 不可用(
SandboxUnavailableError),按 DSH 规范对单条命令以更宽模式升级重试;hvigor 构建因其用户级缓存(~/.hvigor、npm 缓存)在工作区外,通常需要该升级 - devecocli 内部会派生管道 stdio 子进程(签名校验、hvigor fork):在受限沙箱会话中会报 EPERM/误报"未签名",工具透传官方错误原文并给出沙箱外执行指引(build/run/sign 官方本就标注 [Outside sandbox])
实测矩阵
| 环境 | 结果 |
|---|---|
| Windows + hdc 3.2.0c + 真机(API 24) | 全部工具 ✓ |
| Windows + hdc 3.2.0c + 模拟器(API 23) | 全部工具 ✓(含 -t 多目标覆盖) |
| 双目标(USB + TCP 模拟器) | 列表/覆盖/默认目标选择 ✓ |
| 无设备 | 结构化降级 + 连接指引 ✓ |
| 装包(签名已绑定 UDID) | 双目标安装成功 + 应用启动 + UI 文本验证 ✓ |
| 装包签名未绑定 UDID | 结构化上报 9568332 + 修复提示 ✓ |
| v0.2 UI 操作闭环 | tap 聚焦 → input 输入 → dump 验证文本回显 ✓(模拟器实测) |
| v0.2 应用生命周期 | stop → clear-data → uninstall → install → start 全链路 ✓(模拟器实测) |
| v0.2 崩溃抓取 | jscrash 按包名过滤返回源码级堆栈 ✓(模拟器);无崩溃时优雅返回 ✓(真机) |
| v0.2 实机登录流程 | 拉起 → dump 定位 → 分段输入 → 校验 → 点登录、请求发出 ✓(真机实测) |
已知限制 / Known limitations
snapshot_display仅支持.jpeg(API 10+ 实测;API 24 真机 2800×1840 已验证)- 真机安装需签名 profile 绑定设备 UDID,否则报
9568332 install sign info inconsistent(应用签名问题,非插件问题) - hdc 客户端对远端失败可能仍返回退出码 0,插件以输出标记 + 落盘校验兜底
- UI 输入实战经验(真机实测):
- 混合字符串(数字→字母→数字)注入时,IME 模式切换会稳定吞掉紧跟字母后的第一个字符;规避:分段输入 +
hdc_ui_dump校验 + 缺失字符单独补发 - 软键盘会改变页面布局:每次点击/输入前使用最新 dump 的坐标,否则可能点到键盘区
- 键盘可能遮住按钮:先
hdc_ui action=key key=Back收起键盘,再按新坐标点击
- 混合字符串(数字→字母→数字)注入时,IME 模式切换会稳定吞掉紧跟字母后的第一个字符;规避:分段输入 +
路线图
- 会话头部设备面板(v0.6:web 宿主浮动面板 + 挂载 toast,/api2 REST 数据通道;Typert Remote 推送升级留待后续)
- DevEco CLI(devecocli)构建/签名封装(v0.4:可选后端 + hvigorw 降级)
- 官方优先版本化知识层(v0.4:SDK .d.ts + 官方文档检索 + 跨版本变更扫描 + 官方 lint 规则)
- macOS 实机验证
- 按 API 版本整理的官方知识节选随包内置(v0.5:
hms_knowledge,20 个高频主题逐字节选,CC-BY-4.0 合规)
License
MIT
Links
More in this category
liustack/modlens★ 1199
Vision bridge for text-only models: paste an image, get structured JSON evidence (OCR, layout, semantics).
Anionex/dsh-vision-toolkit★ 308
Vision tasks for text-only models: intent-aware image Q&A, long-screenshot OCR, UI reproduction, grounding, and pixel diff.
zhaoolee/notes★ 138
Export DSH conversations as Smartisan Notes-style PNGs, or create and update Markdown notes in a configured account-scoped workspace.
liustack/modsearch★ 85
Web search bridge for text-only agents: ask the web or X, get structured JSON evidence (search, fetch, citations).
Lum1104/dsh-browser★ 80
Chrome sidebar extension that lets DSH operate your browser directly, no vision capabilities required.
taxueseek/argo★ 69
Search built for agents: multilingual coverage across web, academic, code, shopping, finance, news, and encyclopedias.