@harmonyos-arkts/d2h 0.1.28 → 0.1.32
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/.claude-plugin/plugin.json +1 -1
- package/README.md +13 -1
- package/agents/d2h.md +23 -14
- package/dist/bin/install-opencode.js +20 -5
- package/dist/src/install-opencode.js +6 -4
- package/dist/src/install-tui-extension.js +1 -1
- package/dist/src/metrics-plugin.js +4 -3
- package/dist/src/poc.js +53 -0
- package/dist/src/select-agent.js +207 -0
- package/docs/architecture-plan-guide.zh-CN.md +30 -46
- package/docs/poc-rule-evaluation.md +38 -0
- package/package.json +3 -2
- package/schemas/code-stats.schema.json +245 -0
- package/skills/android2hmos_resources_convert/SKILL.md +1 -9
- package/skills/d2h-app-solution/SKILL.md +3 -3
- package/skills/d2h-app-solution/references/inventory-schema.md +2 -2
- package/skills/d2h-architecture-plan/SKILL.md +23 -22
- package/skills/d2h-architecture-plan/references/architecture-plan.example.json +650 -76
- package/skills/d2h-architecture-plan/references/directory-creation.md +7 -7
- package/skills/d2h-architecture-plan/references/hybrid-design.md +63 -63
- package/skills/d2h-architecture-plan/references/json-contract.md +42 -27
- package/skills/d2h-architecture-plan/references/layout-reference.md +25 -72
- package/skills/d2h-architecture-plan/references/plan-contract.md +24 -34
- package/skills/d2h-architecture-plan/references/source-review.md +10 -7
- package/skills/d2h-architecture-plan/scripts/architecture_plan.py +50 -16
- package/skills/d2h-code-audit/SKILL.md +68 -0
- package/skills/d2h-code-audit/references/code-stats-schema.md +260 -0
- package/skills/d2h-code-audit/references/metrics.md +94 -0
- package/skills/d2h-code-audit/scripts/code_stats.py +600 -0
- package/skills/d2h-code-audit/scripts/validate_code_stats.py +446 -0
- package/skills/d2h-dashboard/SKILL.md +59 -33
- package/skills/d2h-dashboard/app/assets/Analysis-9GrmuIjp.css +1 -0
- package/skills/d2h-dashboard/app/assets/Analysis-Dj-4QEJi.js +1 -0
- package/skills/d2h-dashboard/app/assets/CodeAudit-Ctt3XEec.css +1 -0
- package/skills/d2h-dashboard/app/assets/CodeAudit-TcIcLwQL.js +1 -0
- package/skills/d2h-dashboard/app/assets/FeaturesList-C5yGUbRo.js +1 -0
- package/skills/d2h-dashboard/app/assets/FeaturesList-CZ40orVY.css +1 -0
- package/skills/d2h-dashboard/app/assets/Overview-CNkA3J9F.js +1 -0
- package/skills/d2h-dashboard/app/assets/Overview-Cmz8yjX-.css +1 -0
- package/skills/d2h-dashboard/app/assets/PageHeading-B5I3tpO8.js +1 -0
- package/skills/d2h-dashboard/app/assets/PageHeading-BIDu_a9G.css +1 -0
- package/skills/d2h-dashboard/app/assets/Project-BC9Tz1WY.js +1 -0
- package/skills/d2h-dashboard/app/assets/Project-BRyXCzsB.css +1 -0
- package/skills/d2h-dashboard/app/assets/Review-BfWvqlU9.js +1 -0
- package/skills/d2h-dashboard/app/assets/SpecDetail-BHB6smtT.css +1 -0
- package/skills/d2h-dashboard/app/assets/SpecDetail-DguVmqAE.js +1 -0
- package/skills/d2h-dashboard/app/assets/SpecItemDetail-7s7SaF3O.js +69 -0
- package/skills/d2h-dashboard/app/assets/SpecItemDetail-Bf4pGDEN.css +1 -0
- package/skills/d2h-dashboard/app/assets/_plugin-vue_export-helper-B9l48Cov.js +1 -0
- package/skills/d2h-dashboard/app/assets/batchReport-B3IzPnHF.js +1 -0
- package/skills/d2h-dashboard/app/assets/datetime-CHrzCsjX.js +1 -0
- package/skills/d2h-dashboard/app/assets/index-B3nfIPBm.js +3 -0
- package/skills/d2h-dashboard/app/assets/index-CnjP19Vs.css +1 -0
- package/skills/d2h-dashboard/app/assets/navigation-d1Uf6TR4.js +1 -0
- package/skills/d2h-dashboard/app/dataApi.mjs +387 -0
- package/skills/d2h-dashboard/app/index.html +14 -0
- package/skills/d2h-dashboard/app/package.json +12 -0
- package/skills/d2h-dashboard/app/serve.mjs +310 -0
- package/skills/d2h-hypium-forge/SKILL.md +6 -1
- package/skills/d2h-spec-develop/SKILL.md +24 -25
- package/skills/d2h-spec-develop/scripts/__pycache__/check_acceptance.cpython-313.pyc +0 -0
- package/skills/d2h-spec-develop/scripts/check_acceptance.py +66 -0
- package/skills/d2h-spec-generate/SKILL.md +2 -0
- package/skills/d2h-spec-plan/SKILL.md +6 -0
- package/skills/{cpp → language/cpp}/d2h-native-library-verify/scripts/__pycache__/native_common.cpython-313.pyc +0 -0
- package/skills/d2h-architecture-plan/scripts/test_architecture_plan.py +0 -241
- package/skills/d2h-spec-generate/assets/spec-template.md +0 -109
- package/skills/d2h-spec-generate/references/from-plan.md +0 -27
- package/skills/d2h-spec-generate/references/spec-content.md +0 -32
- package/skills/maintaining-migration-report/SKILL.md +0 -144
- package/skills/maintaining-migration-report/references/final-acceptance.md +0 -48
- package/skills/maintaining-migration-report/references/source-provenance.md +0 -66
- /package/skills/{cpp → language/cpp}/d2h-native-library-analyse/SKILL.md +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-analyse/scripts/analyse-android-so.py +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-build/SKILL.md +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-build/references/build-config-mapping.md +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-build/references/jni-to-napi-mapping.md +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-build/scripts/check-android-so.py +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/SKILL.md +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-build-sign-run.md +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-project-template/AppScope/app.json5 +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-project-template/AppScope/resources/base/element/string.json +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-project-template/README.md +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-project-template/build-profile.json5 +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-project-template/entry/build-profile.json5 +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-project-template/entry/hvigorfile.ts +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-project-template/entry/oh-package.json5 +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-project-template/entry/src/main/ets/entryability/EntryAbility.ets +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-project-template/entry/src/main/ets/pages/Index.ets +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-project-template/entry/src/main/ets/pages/NativeVerifyDemo.ets +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-project-template/entry/src/main/module.json5 +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-project-template/entry/src/main/resources/base/element/color.json +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-project-template/entry/src/main/resources/base/element/string.json +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-project-template/entry/src/main/resources/base/profile/main_pages.json +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-project-template/entry/src/ohosTest/ets/test/FFmpegVerify.test.ets +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-project-template/entry/src/ohosTest/ets/test/List.test.ets +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-project-template/entry/src/ohosTest/module.json5 +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-project-template/hvigor/hvigor-config.json5 +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-project-template/hvigorfile.ts +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-project-template/oh-package.json5 +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/demo-template.md +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/references/hypium-test-template.md +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/scripts/device-verify.py +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/scripts/native_common.py +0 -0
- /package/skills/{cpp → language/cpp}/d2h-native-library-verify/scripts/verify-ohos-native.py +0 -0
package/README.md
CHANGED
|
@@ -20,7 +20,15 @@
|
|
|
20
20
|
|
|
21
21
|
## 安装
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
不传 `--agent` 时,在终端用上下键选择安装目标,回车确认,也可输入序号或名称;前两项固定为 OpenCode、VS Code,不显示命令名或路径。检测到工具命令或配置目录时显示“可配置”,否则显示“未检测到”;VS Code 以发现鸿蒙插件为准。检测结果不代替安装校验。未检测到的工具仍可手动选择。
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npx --yes @harmonyos-arkts/d2h@latest install
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`install`、`upgrade` 默认执行 `--force` 行为,覆盖冲突的定义并更新受管理的工具链,无需额外传参。CI、管道等非交互环境必须显式传入 `--agent`。`upgrade` 同样支持交互选择,`doctor` 保留默认检查 OpenCode 的行为。
|
|
30
|
+
|
|
31
|
+
直接安装到 OpenCode:
|
|
24
32
|
|
|
25
33
|
```bash
|
|
26
34
|
npx --yes @harmonyos-arkts/d2h@latest install --agent opencode --force
|
|
@@ -143,3 +151,7 @@ Claude Code、DSH 分别遵循 `CLAUDE_CONFIG_DIR`、`DSH_HOME`;`--config-dir`
|
|
|
143
151
|
- `contracts/`、`schemas/`、`workflow/`:流程契约、数据格式与运行支持。
|
|
144
152
|
|
|
145
153
|
在仓库根目录运行 `npm run check` 和 `npm test`;编译产物仍输出到 `dist/`,CLI 入口保持不变。
|
|
154
|
+
|
|
155
|
+
## 内部规则评估
|
|
156
|
+
|
|
157
|
+
使用包含本次 skill 改动的 `d2h@beta install --remote --poc`,可在独立配置目录启用当前正式 Full 包 的规则采集与上传;Session View 使用正式版 0.3.3。普通安装默认关闭规则评估,详见 [安装说明](docs/poc-rule-evaluation.md)。
|
package/agents/d2h.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: d2h
|
|
3
|
-
description: Android 应用到 HarmonyOS 的 AI 驱动迁移主 Agent;按迁移场景加载专项 Skill
|
|
3
|
+
description: Android 应用到 HarmonyOS 的 AI 驱动迁移主 Agent;按迁移场景加载专项 Skill,完成页面规划、逐页开发、必要验证和最终交付。
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Android to HarmonyOS Migration Agent
|
|
@@ -17,7 +17,7 @@ description: Android 应用到 HarmonyOS 的 AI 驱动迁移主 Agent;按迁
|
|
|
17
17
|
|
|
18
18
|
- `.migration/progress.json` 汇总七个阶段的进度。工作区就绪后执行 `droid2hmos progress init <ANDROID_PROJECT>`,恢复时保留已有记录;用 `progress update <ANDROID_PROJECT> --stage <STAGE_ID> --status <in_progress|completed|blocked>` 更新状态,阻塞原因用 `--blocker` 记录。
|
|
19
19
|
按 CLI 的语义 ID 更新:架构规划为 `harmony-architecture`,Android 分析为 `android-analysis`。仅在实际交付条件满足后标记完成,返工时同步受影响阶段;不手改 JSON。
|
|
20
|
-
- `.migration/architecture-plan/architecture-plan.md`
|
|
20
|
+
- `.migration/architecture-plan/architecture-plan.json` 在提问前保存项目简介、迁移注意点、两套目录,供看板按契约展示;`architecture-plan.md` 保存源证据、目录归属、主要依赖、共享所有者和真实回答/授权。实际创建/复用基础工程与目录时才附 `shell-receipt.json`;规划或目录壳子不能作为目标能力已实现的证据。
|
|
21
21
|
- `.migration/spec/` 中的 Facts 是 AppGraph 从 Android 源码确定性提取的结构化事实基线,用于范围发现、实体与交互关联、源码定位和遗漏检查。Facts 可能包含 unresolved 项或存在抽取遗漏,不能替代对 Android 源码及必要运行行为的阅读核验。
|
|
22
22
|
- `.migration/utg/page.json` 是页面、到达路径和导航计划的输入,也是页面 Spec 使用的运行路径依据。
|
|
23
23
|
- `.migration/page-specs/pages.json` 保存 AI 作出的页面范围、顺序、评分和证据决策。
|
|
@@ -34,21 +34,22 @@ description: Android 应用到 HarmonyOS 的 AI 驱动迁移主 Agent;按迁
|
|
|
34
34
|
| 开始或恢复迁移,定位工程、准备工具链、读取状态、执行 Preflight、检查设备 | `preparing-migration-workspace` |
|
|
35
35
|
| 迁移实时看板(progress.json 就绪后自动启动;阶段进度、功能清单、Spec 执行、耗时/token 总览) | `d2h-dashboard` |
|
|
36
36
|
| 从源码生成可审计功能清单、MVP/core/full 阶段、逐功能技术栈/三方 SDK/SO/权限与跨仓实现状态 | `d2h-app-solution` |
|
|
37
|
+
| 双端代码静态审计:超大文件(默认 2000 行)、模块数、三方依赖、SO 依赖统计与对比 | `d2h-code-audit` |
|
|
37
38
|
| 从 Android 源码生成或刷新 Facts、UTG、点击路径和 `.migration/utg/page.json` | `d2h-utg-static-generate` |
|
|
38
39
|
| 需要 AI 修复源码派生 UTG,或在 Android 设备上按已有计划采集运行时证据 | `d2h-utg-ai-generate` |
|
|
39
40
|
| 根据 Facts、源码和 UTG 生成页面计划、完整 `spec.md` 及初始账本 | `d2h-spec-generate` |
|
|
40
41
|
| 根据已确认功能范围与已有页面任务规划里程碑和波次 | `d2h-spec-plan` |
|
|
41
42
|
| 按固定 Spec 范围串行实施、构建、检查并返回提交与证据 | `d2h-spec-develop` |
|
|
42
|
-
| 根据 Android
|
|
43
|
+
| 根据 Android 源码设计原结构对照/融合优化两套目录,先写 JSON 并提供只读看板链接辅助提问;确认且有创建要求后落地目录壳子 | `d2h-architecture-plan` |
|
|
43
44
|
| 落实模块内 MVVM 分层、状态管理及 ArkTS 编码规范 | `arkts-mvvm-architecture` |
|
|
44
|
-
|
|
|
45
|
+
| 用户明确要求生成或执行 Python Hypium 端到端功能测试 | `d2h-hypium-forge` |
|
|
45
46
|
| 迁移应用名称、图标、版本号、包名等身份信息 | `arkts-app-identity` |
|
|
46
47
|
| 迁移用户可见文案与多语言资源,或清理硬编码文案 | `arkts-i18n` |
|
|
47
48
|
| 转换 Android 图片、XML drawable 和自适应图标 | `android2hmos_resources_convert` |
|
|
48
49
|
| 修复 HarmonyOS 图片或图标尺寸、比例失真 | `arkts-icon-sizing` |
|
|
49
50
|
| 迁移 C/C++ 原生库(源码重编、带 patch 重放、三方预编译 .so/JNI 改写 NAPI),或判断现有 .so/.a 能否直接用于鸿蒙 | `d2h-native-library-build`(情况③查替代时配合 `native-library-substitution`) |
|
|
50
51
|
| 诊断 ArkTS 构建、运行时、UI 自动化或迁移验证故障 | `harmonyos-migration-playbook` |
|
|
51
|
-
|
|
|
52
|
+
| 云侧鸿蒙知识库 | `d2h-cloud-knowledge` |
|
|
52
53
|
| 迁移完整结束或本次运行明确中止后复盘流程 | `reviewing-migration-process` |
|
|
53
54
|
| 首次安装、工具缺失、版本/能力不符或主动升级 | `managing-d2h-toolchain` |
|
|
54
55
|
|
|
@@ -69,8 +70,8 @@ description: Android 应用到 HarmonyOS 的 AI 驱动迁移主 Agent;按迁
|
|
|
69
70
|
### 三、HarmonyOS 工程架构设计
|
|
70
71
|
|
|
71
72
|
1. 加载 `d2h-architecture-plan`,输入 Android 工程目录、已确认功能范围和第二阶段已有功能分析作为定位线索。遵循该 Skill 的默认 Android 阅读范围、鸿蒙工程结合选择及目录级分析深度,不另做全量扫描或完整业务链审计。
|
|
72
|
-
2. 按该 Skill
|
|
73
|
-
3. 确认当前方案且已要求创建后,按该 Skill
|
|
73
|
+
2. 按该 Skill 比较原结构对照 android-mirror 与融合优化 hybrid 两套目录,先写 `.migration/architecture-plan/architecture-plan.json`(项目简介、迁移注意点、两套嵌套目录与决定,不含推荐/选择状态)和 `architecture-plan.md`(分析证据及回答/授权记录)。向看板调用方交接 JSON,并在 question 或对话提问的同时提供已绑定当前工作区的实际看板链接;用户通过宿主工具/对话选择,不推荐某套;回答后只在 Markdown 保存所选方案 ID 和实际授权,JSON 始终保留两套目录且不显示已选状态。已有当前有效选择时沿用,不重复询问。优化方案以根级 entry/feature/common 为参考,优先按相对独立的 Tab 组织业务模块并保留健康源结构;候选页面族不是最终页面/Spec 清单。
|
|
74
|
+
3. 确认当前方案且已要求创建后,按该 Skill 的目录落地流程先读取 Markdown 的实际确认和所选 ID,再按 ID 读取 JSON 中对应的方案分支,创建或复用基础工程、补齐所选目录并保存 `shell-receipt.json`。完整迁移已有创建要求,或已有“采用方案 B 并创建”等明确授权时,不追加确认;预检已有壳则复用,不把目录壳子当成注册完成的模块或业务实现。
|
|
74
75
|
4. 创建/复用后核对 `.migration/config.json` 的 `harmonyProject` 与实际目标根一致;路径变化时通过现有 CLI 配置入口同步。向后续阶段交接当前规划路径、选定方案、目标根、模块/目录归属、共享所有者与必要前置,实际落地时再附 receipt 及未完成项。完整迁移的架构阶段须完成选型,以及本次要求的创建/复用后才能标记完成;仅请求规划则按 Skill 的规划交付条件结束。
|
|
75
76
|
5. 目标工程和目录落地后,按场景完成资源迁移,再生成 Spec;仅请求架构规划时不执行资源迁移。
|
|
76
77
|
|
|
@@ -96,11 +97,13 @@ description: Android 应用到 HarmonyOS 的 AI 驱动迁移主 Agent;按迁
|
|
|
96
97
|
2. 加载 `d2h-spec-develop`,主 Agent 按有效计划初始化或恢复 `batch_report.json`,按里程碑、波次和任务排序严格串行推进。任意时刻只运行一个独立 page-worker;可将同一波次内排序相邻、共享页面或模块上下文的 2~3 个 Spec 交给同一 worker,具体分组和逐项交接按该技能执行:
|
|
97
98
|
|
|
98
99
|
a. 主 Agent 按账本中的有效规划,只从纳入的任务中,根据实际前置证据选择当前波次内按任务排序最早未完成且前置满足的任务,固定本次任务 ID、版本和允许路径;未纳入任务不得因规格已生成而派发。进入相关波次前核对外部条件,区分实现与验收所需条件;仅阻塞实际依赖项,主 Agent 按依赖调整后继续其他可执行任务,不能用固定登录成功或伪造结果绕过验收。
|
|
99
|
-
b. 向 page-worker 交接固定的有序任务 ID、当前 Spec、源码与目标工程、Git 基线、真实共享接口和检查要求。worker 加载 `d2h-spec-develop`,只实施当前获授权的 Spec
|
|
100
|
-
c. 主 Agent
|
|
100
|
+
b. 向 page-worker 交接固定的有序任务 ID、当前 Spec、源码与目标工程、Git 基线、真实共享接口和检查要求。worker 加载 `d2h-spec-develop`,只实施当前获授权的 Spec;worker 在开发中完成必要的快速验证,主 Agent 复核,各 Spec 独立记录结果。
|
|
101
|
+
c. 主 Agent 复核本次构建与必要验证结果,不另设逐页测试流程;仅用户明确要求时加载 `d2h-hypium-forge` 或执行专项测试。未执行、缺失或过期的结果不能标记通过。
|
|
101
102
|
d. 主 Agent 复核作用域提交和工作区,核对 `batch_report.json` 中记录的真实实现文件、来源、本次构建与测试证据、差异及阻塞,原位更新并保留历史。
|
|
102
103
|
e. 当前任务闭环后,重新核对前置并评估上下文与宿主续会话能力,适合时复用同一 worker 继续组内下一项,否则明确调整分组并重新派发剩余任务;本组完成后再按计划派发下一组。受阻时继续修复当前任务或记录外部阻塞,不自动跳过或扩组。里程碑与波次组织交付顺序,不拆分页面闭环或改变验收要求。
|
|
103
104
|
|
|
105
|
+
3. 本次确认范围的开发任务全部完成、进入完成条件核对前,加载 `d2h-code-audit` 对 Android 与 HarmonyOS 工程执行双端静态审计终检:超大文件(默认 2000 行)、模块数、三方依赖与 SO 依赖统计及对比,产物写入 `.migration/code-audit/code-stats.json`。HarmonyOS 侧超大文件如实记录,不静默省略,也不阻塞本次范围交付。
|
|
106
|
+
|
|
104
107
|
若当前环境不支持独立 page-worker,必须明确报告该开发模式无法执行,不能静默改成主 Agent 批量开发。
|
|
105
108
|
|
|
106
109
|
## 持续执行与人工介入
|
|
@@ -110,12 +113,15 @@ e. 当前任务闭环后,重新核对前置并评估上下文与宿主续会
|
|
|
110
113
|
- 禁止依据模型自行估算的“剩余 token”“上下文百分比”“本轮剩余容量”等决定停止、收尾、汇报后等待或要求用户开启新会话。此类估算不可信。
|
|
111
114
|
- 用户主动中断、修改需求或发出新指令。
|
|
112
115
|
- 首次范围尚未确认或用户正在调整功能清单;收到明确回答后从对应环节继续,已有有效选择不重复询问。
|
|
113
|
-
- 架构选型或重要修订需要用户决定时,只等待依赖该选择的目标目录落地/Spec 分配;独立的 Android
|
|
116
|
+
- 架构选型或重要修订需要用户决定时,只等待依赖该选择的目标目录落地/Spec 分配;独立的 Android 分析可继续。仅请求架构规划则交付即可,不强求立即选型;已有指定方案并创建的明确授权时记录后继续,不重复询问。
|
|
114
117
|
- 真机签名、开发者账号、权限或凭据必须由用户完成,且没有可用替代方案。
|
|
115
118
|
- 设备、CLI、构建环境或外部服务持续不可用,完成自诊和有限重试后仍确认是外部问题。
|
|
116
119
|
- 完成目标需要超出原迁移范围的产品决策或新的授权。
|
|
117
120
|
|
|
118
|
-
|
|
121
|
+
实现缺陷、编译错误、测试失败、布局错误、平台方案选择和可由源码裁决的歧义都不属于暂停理由。
|
|
122
|
+
所有构建、安装和测试必须非交互并有明确超时,且工具调用超时须大于 CLI 自身 `--timeout-ms`。
|
|
123
|
+
Windows 下设备类命令(build/test/sign 等)调用 `droid2hmos.cmd` 并在命令末尾追加 `; $rc=$LASTEXITCODE; hdc kill; exit $rc`,hdc 常驻服务持有会话输出管道,会让 CLI 已完成而工具调用空等超时,杀掉即返回;
|
|
124
|
+
hdc 不在 PATH 或仍悬挂时改用 `cmd /c "… > log 2>&1"` 文件重定向兜底(PowerShell 原生 `>` 重定向无效)。工具超时不等于失败:先核对 CLI 落盘报告/产物再决定是否重跑。
|
|
119
125
|
|
|
120
126
|
## 禁止的伪完成
|
|
121
127
|
|
|
@@ -140,13 +146,16 @@ e. 当前任务闭环后,重新核对前置并评估上下文与宿主续会
|
|
|
140
146
|
- Preflight、Facts、UTG、页面 Spec、`batch_report.json` 和证据对应当前源码。
|
|
141
147
|
- `pages.json` 覆盖全部已知页面或明确记录排除原因。
|
|
142
148
|
- 每个已知页面、Dialog、Sheet 和关键模式都有唯一 `spec.md`,页面包中没有额外产物。
|
|
143
|
-
- `batch_report.json` 覆盖当前确认范围内的全部 Spec
|
|
149
|
+
- `batch_report.json` 覆盖当前确认范围内的全部 Spec,逐项开发复核、波次目标和页面约定范围均已满足,没有未解决的开发阻塞;未执行的专项测试如实记录,不冒充通过;以当前账本契约与实际证据核验,不以旧页面状态字段替代逐项验收。
|
|
144
150
|
- 所有 Spec 功能项都有真实、可达的 HarmonyOS 实现。
|
|
145
|
-
- HarmonyOS
|
|
146
|
-
- `batch_report.json`
|
|
151
|
+
- HarmonyOS 工程构建、安装、启动成功,开发阶段必要验证通过;仅在用户明确要求专项测试时核对其实际结果。
|
|
152
|
+
- `batch_report.json` 已记录最终开发复核、必要验证结果、未验证项及实际证据路径,队列、页面明细和汇总一致。
|
|
153
|
+
- 已按 `d2h-code-audit` 完成双端静态审计终检,`.migration/code-audit/code-stats.json` 已生成;HarmonyOS 侧超大文件已如实记录并标注。
|
|
147
154
|
- 所有页面、可见控件、状态、导航、Dialog、业务功能、数据效果和错误路径均真实实现。
|
|
148
155
|
- Facts 或 UTG 遗漏、但经源码或运行时发现的行为也已实现并验证。
|
|
149
156
|
- 无法等价的差异已经明确呈现,没有被静默标记为完成。
|
|
150
157
|
- 每个页面实现都有可恢复提交,用户已有和无关改动未被覆盖。
|
|
151
158
|
|
|
152
159
|
账本状态、编译成功或测试汇总都不能替代对真实用户可观察结果的 AI 审查。
|
|
160
|
+
|
|
161
|
+
宣布本次确认范围完成后,按 d2h-dashboard skill 的自动停止规则关闭看板并执行 `clear` 清空 TUI 横幅(root 归属校验、失败仅记录,不影响完成宣布);用户后续要求查看时按该 skill 重新启动。
|
|
@@ -14,10 +14,12 @@ import { inspectInstallation, installOpenCode } from '../src/install-opencode.js
|
|
|
14
14
|
import { findMetricsPluginCacheDirs, metricsPluginCacheRoots } from '../src/metrics-plugin.js';
|
|
15
15
|
import { inspectToolchain, installToolchain, loadToolchain } from '../src/toolchain.js';
|
|
16
16
|
import fs from 'node:fs';
|
|
17
|
+
import { preparePoc } from '../src/poc.js';
|
|
17
18
|
import { inspectVSCodeInstallation, installVSCode } from '../src/install-vscode.js';
|
|
18
19
|
import { isSkillHost, skillHosts, skillHostConfigRoot, inspectSkillHostInstallation, installSkillHost } from '../src/install-skills.js';
|
|
19
20
|
import { installTuiExtension, inspectTuiExtension } from '../src/install-tui-extension.js';
|
|
20
21
|
import { runWorkflow } from '../src/workflow.js';
|
|
22
|
+
import { selectAgent } from '../src/select-agent.js';
|
|
21
23
|
const help = `Install this package's skills and agents into supported AI coding tools.
|
|
22
24
|
|
|
23
25
|
Usage: d2h [options]
|
|
@@ -34,8 +36,9 @@ Usage: d2h [options]
|
|
|
34
36
|
Use d2h --check-env --help for check options
|
|
35
37
|
|
|
36
38
|
--source-dir <path> Source root (defaults to this package)
|
|
37
|
-
--agent <name> opencode
|
|
39
|
+
--agent <name> opencode, vscode, deveco, codex, qoder, trae,
|
|
38
40
|
trae-cn, claude, dsh, zcode, codebuddy or workbuddy
|
|
41
|
+
Omit for interactive selection with local detection hints
|
|
39
42
|
--extension-dir <path> VS Code HarmonyOS Dev Assistant extension root
|
|
40
43
|
--config-dir <path> Override the selected agent's config root
|
|
41
44
|
OPENCODE_CONFIG_DIR / DEVECO_CONFIG_DIR, or
|
|
@@ -44,7 +47,9 @@ Usage: d2h [options]
|
|
|
44
47
|
Skills under skills/; trae-cn uses ~/.trae-cn
|
|
45
48
|
Claude/DSH also honor CLAUDE_CONFIG_DIR/DSH_HOME
|
|
46
49
|
--link Create absolute symbolic links (development only)
|
|
47
|
-
--force Replace conflicting definitions and managed CLI npm links
|
|
50
|
+
--force Replace conflicting definitions and managed CLI npm links (default)
|
|
51
|
+
--poc Enable local rule/event collection in an isolated config
|
|
52
|
+
Combine --remote for Full POC collection and cloud upload
|
|
48
53
|
--remote Use opencode-metrics-plugin instead of the default lite plugin
|
|
49
54
|
--dry-run Print operations without writing files
|
|
50
55
|
--skip-tools Install definitions only (local development)
|
|
@@ -120,7 +125,7 @@ try {
|
|
|
120
125
|
let remote = false;
|
|
121
126
|
const options = {
|
|
122
127
|
sourceDir: packageRoot,
|
|
123
|
-
|
|
128
|
+
force: true,
|
|
124
129
|
};
|
|
125
130
|
for (let index = 0; index < installArgs.length; index++) {
|
|
126
131
|
const arg = installArgs[index];
|
|
@@ -143,6 +148,9 @@ try {
|
|
|
143
148
|
const key = { '--link': 'link', '--force': 'force', '--dry-run': 'dryRun' }[arg];
|
|
144
149
|
options[key] = true;
|
|
145
150
|
}
|
|
151
|
+
else if (arg === '--poc') {
|
|
152
|
+
options.poc = true;
|
|
153
|
+
}
|
|
146
154
|
else if (arg === '--remote') {
|
|
147
155
|
remote = true;
|
|
148
156
|
}
|
|
@@ -153,6 +161,11 @@ try {
|
|
|
153
161
|
throw new Error(`unknown option: ${arg}`);
|
|
154
162
|
}
|
|
155
163
|
}
|
|
164
|
+
options.agent ??= options.poc ? 'opencode' : await selectAgent(extensionDir);
|
|
165
|
+
if (options.poc && !['opencode', 'deveco'].includes(options.agent))
|
|
166
|
+
throw new Error('--poc currently supports opencode and deveco; use a separate config root');
|
|
167
|
+
if (options.poc && !options.configDir)
|
|
168
|
+
options.configDir = path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config'), `${options.agent}-poc`);
|
|
156
169
|
if (!options.agent || (!['opencode', 'deveco', 'vscode'].includes(options.agent) && !isSkillHost(options.agent))) {
|
|
157
170
|
throw new Error(`unsupported agent: ${options.agent}; choose opencode, deveco, vscode or ${Object.keys(skillHosts).join(', ')}`);
|
|
158
171
|
}
|
|
@@ -171,11 +184,13 @@ try {
|
|
|
171
184
|
const pluginCache = isSkillHost(options.agent) ? [] : findMetricsPluginCacheDirs(metricsPluginCacheRoots(options.agent));
|
|
172
185
|
console.log(`plugin cache: ${pluginCache.length ? `${pluginCache.join(', ')}; cleared by d2h install/upgrade` : 'none'}`);
|
|
173
186
|
}
|
|
174
|
-
else if (!skipTools)
|
|
187
|
+
else if (!skipTools && !options.poc)
|
|
175
188
|
installToolchain(packageRoot, { dryRun: options.dryRun, force: options.force });
|
|
176
189
|
else if (!explicitSource && !options.dryRun)
|
|
177
190
|
console.log(`Skipped managed CLI installation (${Object.keys(loadToolchain(packageRoot).tools).join(', ')}).`);
|
|
178
191
|
if (!checkOnly) {
|
|
192
|
+
if (options.poc)
|
|
193
|
+
preparePoc(options.sourceDir, options.configDir, { dryRun: options.dryRun, installViewer: !skipTools });
|
|
179
194
|
let vscodeExtensionRoot;
|
|
180
195
|
if (options.agent === 'vscode') {
|
|
181
196
|
vscodeExtensionRoot = installVSCode({ sourceDir: options.sourceDir, extensionDir, remote, dryRun: options.dryRun }).extensionRoot;
|
|
@@ -184,7 +199,7 @@ try {
|
|
|
184
199
|
installSkillHost(options.agent, { ...options, remote });
|
|
185
200
|
else
|
|
186
201
|
installOpenCode({ ...options, remote });
|
|
187
|
-
if ((options.agent === 'opencode' || options.agent === 'vscode') && !skipTools)
|
|
202
|
+
if (!options.poc && (options.agent === 'opencode' || options.agent === 'vscode') && !skipTools)
|
|
188
203
|
installTuiExtension({ dryRun: options.dryRun, force: options.force, extensionRoot: vscodeExtensionRoot });
|
|
189
204
|
if (!options.dryRun) {
|
|
190
205
|
const target = options.agent === 'vscode' ? 'VS Code HarmonyOS Dev Assistant' :
|
|
@@ -82,8 +82,8 @@ function parseJsonConfig(source) {
|
|
|
82
82
|
function configFileFor(root, agent) {
|
|
83
83
|
return path.join(root, agent === 'deveco' ? 'deveco.jsonc' : 'opencode.json');
|
|
84
84
|
}
|
|
85
|
-
function updateAgentConfig(config, remote) {
|
|
86
|
-
updateMetricsPlugin(config, remote);
|
|
85
|
+
function updateAgentConfig(config, remote, pocRoot) {
|
|
86
|
+
updateMetricsPlugin(config, remote, pocRoot);
|
|
87
87
|
config.agent ??= {};
|
|
88
88
|
for (const name of ['general', 'explore']) {
|
|
89
89
|
config.agent[name] = { ...config.agent[name], permission: { '*': 'allow' } };
|
|
@@ -136,9 +136,11 @@ export function resolvedLocation(directory) {
|
|
|
136
136
|
const parent = path.dirname(directory);
|
|
137
137
|
return parent === directory ? directory : path.join(resolvedLocation(parent), path.basename(directory));
|
|
138
138
|
}
|
|
139
|
-
export function installOpenCode({ sourceDir, configDir, agent = 'opencode', link = false, force = false, dryRun = false, remote = false, pluginCacheRoots, log = console.log }) {
|
|
139
|
+
export function installOpenCode({ sourceDir, configDir, agent = 'opencode', link = false, force = false, dryRun = false, remote = false, poc = false, pluginCacheRoots, log = console.log }) {
|
|
140
140
|
if (!['opencode', 'deveco'].includes(agent))
|
|
141
141
|
throw new Error(`unsupported agent: ${agent}`);
|
|
142
|
+
if (poc)
|
|
143
|
+
pluginCacheRoots = [];
|
|
142
144
|
const application = agent === 'deveco' ? 'DevEco Code' : 'OpenCode';
|
|
143
145
|
if (!configDir || ['.', '..'].includes(configDir))
|
|
144
146
|
throw new Error(`refusing unsafe OpenCode config directory: ${configDir}`);
|
|
@@ -153,7 +155,7 @@ export function installOpenCode({ sourceDir, configDir, agent = 'opencode', link
|
|
|
153
155
|
if (existingConfig?.isSymbolicLink())
|
|
154
156
|
throw new Error(`refusing linked OpenCode config file: ${configFile}`);
|
|
155
157
|
const config = existingConfig ? parseJsonConfig(fs.readFileSync(configFile, 'utf8')) : {};
|
|
156
|
-
updateAgentConfig(config, remote);
|
|
158
|
+
updateAgentConfig(config, remote, poc ? configRoot : undefined);
|
|
157
159
|
const configText = JSON.stringify(config, null, 2) + '\n';
|
|
158
160
|
const entries = [];
|
|
159
161
|
for (const kind of ['skills', 'agents']) {
|
|
@@ -3,7 +3,7 @@ import os from 'node:os';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { run } from './toolchain.js';
|
|
5
5
|
import { locateVSCodeExtension } from './install-vscode.js';
|
|
6
|
-
export const tuiExtension = { name: 'opencode-tui-extension', version: '
|
|
6
|
+
export const tuiExtension = { name: 'opencode-tui-extension', version: 'latest' };
|
|
7
7
|
function bundledOpenCodeBinary(extensionRoot) {
|
|
8
8
|
const executable = process.platform === 'win32' ? 'opencode.exe' : 'opencode';
|
|
9
9
|
return path.join(extensionRoot, 'resources', 'opencode', 'bin', process.platform, process.arch, executable);
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
+
import { pocPluginOptions } from './poc.js';
|
|
2
3
|
import os from 'node:os';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
export const liteMetricsPlugin = 'opencode-metrics-plugin-lite';
|
|
5
6
|
export const remoteMetricsPlugin = 'opencode-metrics-plugin';
|
|
6
7
|
const metricsPluginCachePrefix = 'opencode-metrics-plugin';
|
|
7
|
-
export function updateMetricsPlugin(config, remote = false) {
|
|
8
|
+
export function updateMetricsPlugin(config, remote = false, pocRoot) {
|
|
8
9
|
const plugins = config.plugin ?? [];
|
|
9
10
|
if (!Array.isArray(plugins))
|
|
10
11
|
throw new Error('opencode plugin list must be an array');
|
|
11
12
|
const selected = remote ? remoteMetricsPlugin : liteMetricsPlugin;
|
|
12
13
|
const isMetrics = (entry) => {
|
|
13
14
|
const name = Array.isArray(entry) ? entry[0] : entry;
|
|
14
|
-
return name === liteMetricsPlugin
|
|
15
|
+
return typeof name === 'string' && [liteMetricsPlugin, remoteMetricsPlugin].some(base => name === base || name.startsWith(`${base}@`));
|
|
15
16
|
};
|
|
16
17
|
const existing = plugins.findIndex(isMetrics);
|
|
17
18
|
const filtered = plugins.filter((entry, index) => !isMetrics(entry) || index === existing);
|
|
18
|
-
const selectedEntry = [selected, { agents: remote ? ['d2h'] : ['*'] }];
|
|
19
|
+
const selectedEntry = [selected, { agents: remote ? ['d2h'] : ['*'], ...(pocRoot ? pocPluginOptions(pocRoot, remote) : {}) }];
|
|
19
20
|
if (existing < 0)
|
|
20
21
|
filtered.push(selectedEntry);
|
|
21
22
|
else
|
package/dist/src/poc.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { run } from './toolchain.js';
|
|
5
|
+
export const pocViewerVersion = '0.3.3';
|
|
6
|
+
export function pocPluginOptions(root, remote = false) {
|
|
7
|
+
const data = path.join(root, 'd2h-poc');
|
|
8
|
+
return { enabled: true, eventLogging: true, ...(remote ? { upload: { enabled: true } } : {}), dirs: { ...(remote ? { uploadStagingDir: path.join(data, 'upload-staging') } : {}), metricsDir: path.join(data, 'metrics'), eventsDir: path.join(data, 'events'), logFile: path.join(data, 'plugin.log') },
|
|
9
|
+
ruleEvaluation: { enabled: true, catalogPath: path.join(data, 'catalog.json'), outputDir: path.join(data, 'reports') } };
|
|
10
|
+
}
|
|
11
|
+
export function preparePoc(source, configRoot, { dryRun = false, installViewer = true, runner = run, log = console.log } = {}) {
|
|
12
|
+
const data = path.join(configRoot, 'd2h-poc'), runtime = path.join(data, 'runtime');
|
|
13
|
+
if (dryRun) {
|
|
14
|
+
log(`would prepare isolated POC data at ${data}; viewer session-viewer-plugin@${pocViewerVersion}${installViewer ? '' : ' (runtime install skipped)'}`);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const entries = [
|
|
18
|
+
['toolchain.check', 'managing-d2h-toolchain', '首先检查工具链', 'skills/managing-d2h-toolchain/SKILL.md', '首先运行 `check`', { tool: 'bash', input: { command: ['manage-toolchain.mjs', 'check'] } }],
|
|
19
|
+
['develop.managed-build', 'd2h-spec-develop', '使用托管入口构建', 'skills/d2h-spec-develop/SKILL.md', 'Use `droid2hmos` managed build', { tool: 'bash', input: { command: 'droid2hmos build' } }],
|
|
20
|
+
['workspace.preflight', 'preparing-migration-workspace', '执行 Preflight', 'skills/preparing-migration-workspace/SKILL.md', '只调用 `droid2hmos`', { tool: 'bash', input: { command: 'droid2hmos preflight' } }],
|
|
21
|
+
['forge.preinject-ids', 'd2h-hypium-forge', '预置控件 ID', 'skills/d2h-hypium-forge/SKILL.md', '必须先预置控件 ID', { tool: 'bash', input: { command: 'preinject_ids.py' } }],
|
|
22
|
+
];
|
|
23
|
+
const rules = [], missing = [];
|
|
24
|
+
for (const [id, skill, title, file, needle, action] of entries) {
|
|
25
|
+
let lines;
|
|
26
|
+
try {
|
|
27
|
+
lines = fs.readFileSync(path.join(source, file), 'utf8').split(/\r?\n/);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
missing.push(id);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const index = lines.findIndex(line => line.includes(needle));
|
|
34
|
+
if (index < 0) {
|
|
35
|
+
missing.push(id);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const text = lines[index];
|
|
39
|
+
rules.push({ id, skill, title, source: { file, text, startLine: index + 1, endLine: index + 1, sha256: createHash('sha256').update(text).digest('hex') }, action, verify: 'manual', matchCoverage: 'partial' });
|
|
40
|
+
}
|
|
41
|
+
fs.mkdirSync(data, { recursive: true });
|
|
42
|
+
fs.writeFileSync(path.join(data, 'catalog.json'), JSON.stringify({ schema: 'd2h-rule-catalog/v1', revision: `d2h-${JSON.parse(fs.readFileSync(path.join(source, 'package.json'), 'utf8')).version}`, coverage: 'partial', rules, notes: ['POC tool matching only; no omissions inferred from incomplete traces.', `Unavailable anchors: ${missing.join(', ') || 'none'}`] }, null, 2) + '\n');
|
|
43
|
+
if (installViewer) {
|
|
44
|
+
const result = runner('npm', ['install', '--prefix', runtime, '--no-audit', '--no-fund', '--ignore-scripts', `session-viewer-plugin@${pocViewerVersion}`]);
|
|
45
|
+
if (result.status !== 0)
|
|
46
|
+
throw new Error(`POC viewer installation failed: ${result.stderr || result.error?.message}`);
|
|
47
|
+
}
|
|
48
|
+
// No global executable replacement, no default config or port changes.
|
|
49
|
+
const launcher = `import { spawn } from 'node:child_process';\nconst child=spawn(process.execPath,[${JSON.stringify(path.join(runtime, 'node_modules/session-viewer-plugin/server/dist/cli.js'))},'--poc','--data-dir',${JSON.stringify(data)},'--port','3301'],{stdio:'inherit'});\nchild.on('error',e=>{console.error(e.message);process.exitCode=1});child.on('exit',code=>{process.exitCode=code??1});\n`;
|
|
50
|
+
fs.writeFileSync(path.join(data, 'start-session-view.mjs'), launcher);
|
|
51
|
+
log(`POC viewer: node ${JSON.stringify(path.join(data, 'start-session-view.mjs'))}`);
|
|
52
|
+
log(`Launch host with ${'OPENCODE_CONFIG_DIR / DEVECO_CONFIG_DIR'}=${configRoot}; normal host configuration is unchanged.`);
|
|
53
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createInterface } from 'node:readline/promises';
|
|
5
|
+
import { emitKeypressEvents, moveCursor, cursorTo, clearScreenDown } from 'node:readline';
|
|
6
|
+
import { skillHosts } from './install-skills.js';
|
|
7
|
+
import { locateVSCodeExtension } from './install-vscode.js';
|
|
8
|
+
function executable(name, env, platform) {
|
|
9
|
+
const extensions = platform === 'win32' ? (env.PATHEXT || '.EXE;.CMD;.BAT').split(';') : [''];
|
|
10
|
+
for (const directory of (env.PATH || '').split(platform === 'win32' ? ';' : ':').filter(Boolean)) {
|
|
11
|
+
for (const extension of extensions) {
|
|
12
|
+
const file = path.join(directory, name + extension);
|
|
13
|
+
try {
|
|
14
|
+
if (!fs.statSync(file).isFile())
|
|
15
|
+
continue;
|
|
16
|
+
fs.accessSync(file, platform === 'win32' ? fs.constants.F_OK : fs.constants.X_OK);
|
|
17
|
+
return file;
|
|
18
|
+
}
|
|
19
|
+
catch { /* Missing or inaccessible commands are not detection evidence. */ }
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
export function detectAgents({ home = os.homedir(), env = process.env, platform = process.platform, extensionDir } = {}) {
|
|
25
|
+
const configHome = env.XDG_CONFIG_HOME || path.join(home, '.config');
|
|
26
|
+
const hosts = [
|
|
27
|
+
{ agent: 'opencode', label: 'OpenCode', root: env.OPENCODE_CONFIG_DIR || path.join(configHome, 'opencode'), commands: ['opencode'] },
|
|
28
|
+
{ agent: 'vscode', label: 'VS Code (HarmonyOS Dev Assistant)', root: path.join(home, '.vscode'), commands: ['code'] },
|
|
29
|
+
{ agent: 'deveco', label: 'DevEco Code', root: env.DEVECO_CONFIG_DIR || path.join(configHome, 'deveco'), commands: ['deveco'] },
|
|
30
|
+
...Object.entries(skillHosts).map(([agent, host]) => ({
|
|
31
|
+
agent, label: host.label,
|
|
32
|
+
root: ('environment' in host && env[host.environment]) || path.join(home, host.directory),
|
|
33
|
+
commands: agent === 'qoder' ? ['qodercli', 'qoder'] : agent === 'trae-cn' ? ['trae-cn'] : [agent]
|
|
34
|
+
}))
|
|
35
|
+
];
|
|
36
|
+
return hosts.map(host => {
|
|
37
|
+
const detected = [];
|
|
38
|
+
for (const command of host.commands) {
|
|
39
|
+
const file = executable(command, env, platform);
|
|
40
|
+
if (file) {
|
|
41
|
+
detected.push(`命令 ${file}`);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
if (fs.statSync(host.root).isDirectory())
|
|
47
|
+
detected.push(`配置目录 ${host.root}`);
|
|
48
|
+
}
|
|
49
|
+
catch { /* Not present. */ }
|
|
50
|
+
if (host.agent === 'vscode') {
|
|
51
|
+
try {
|
|
52
|
+
const extension = locateVSCodeExtension(extensionDir, home);
|
|
53
|
+
const metadata = JSON.parse(fs.readFileSync(path.join(extension, 'package.json'), 'utf8'));
|
|
54
|
+
if (String(metadata.name).toLowerCase() === 'harmonyosdevassistantforvscode' &&
|
|
55
|
+
String(metadata.publisher).toLowerCase() === 'huaweideveloperserviceplatform') {
|
|
56
|
+
detected.push(`鸿蒙插件 ${extension}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch { /* VS Code without the required extension remains selectable. */ }
|
|
60
|
+
}
|
|
61
|
+
return { agent: host.agent, label: host.label, detected };
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
export function formatAgentChoice(choice) {
|
|
65
|
+
const detected = choice.agent === 'vscode'
|
|
66
|
+
? choice.detected.some(item => item.startsWith('鸿蒙插件 '))
|
|
67
|
+
: choice.detected.length > 0;
|
|
68
|
+
const status = detected ? '可配置' : '未检测到';
|
|
69
|
+
const label = ['opencode', 'vscode'].includes(choice.agent) ? choice.label : `${choice.label} (${choice.agent})`;
|
|
70
|
+
return `${label} — ${status}`;
|
|
71
|
+
}
|
|
72
|
+
export async function chooseAgent(choices, ask, write) {
|
|
73
|
+
write('选择安装目标 / Select agent(检测结果仅供参考):\n');
|
|
74
|
+
choices.forEach((choice, index) => write(` ${index + 1}. ${formatAgentChoice(choice)}\n`));
|
|
75
|
+
for (;;) {
|
|
76
|
+
const answer = (await ask('输入序号或 agent 名称,q 取消:')).trim().toLowerCase();
|
|
77
|
+
if (['q', 'quit', 'exit'].includes(answer))
|
|
78
|
+
throw new Error('Installation cancelled before making changes');
|
|
79
|
+
const choice = /^\d+$/.test(answer) ? choices[Number(answer) - 1] : choices.find(item => item.agent === answer);
|
|
80
|
+
if (choice)
|
|
81
|
+
return choice.agent;
|
|
82
|
+
write('请选择列表中的序号或 agent 名称。\n');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export function chooseAgentWithKeys(choices, input = process.stdin, output = process.stderr) {
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
let selected = 0;
|
|
88
|
+
let renderedLines = 0;
|
|
89
|
+
let answer = '';
|
|
90
|
+
const colorDepth = process.env.NO_COLOR === undefined ? (output.getColorDepth?.() || 1) : 1;
|
|
91
|
+
const wasRaw = Boolean(input.isRaw);
|
|
92
|
+
const wasFlowing = input.readableFlowing === true;
|
|
93
|
+
const rows = Math.max(1, Math.min(choices.length, (output.rows || 24) - 4));
|
|
94
|
+
function render() {
|
|
95
|
+
if (renderedLines) {
|
|
96
|
+
moveCursor(output, 0, -renderedLines);
|
|
97
|
+
cursorTo(output, 0);
|
|
98
|
+
clearScreenDown(output);
|
|
99
|
+
}
|
|
100
|
+
const start = Math.max(0, Math.min(selected - rows + 1, choices.length - rows));
|
|
101
|
+
const lines = ['选择安装目标 / Select agent(检测结果仅供参考)'];
|
|
102
|
+
for (let i = start; i < start + rows; i++) {
|
|
103
|
+
lines.push(`${i === selected ? '>' : ' '} ${i + 1}. ${formatAgentChoice(choices[i])}`);
|
|
104
|
+
}
|
|
105
|
+
lines.push(`↑↓ 选择,回车确认;也可输入序号或名称,q 取消:${answer}`);
|
|
106
|
+
// Keep every row within the terminal width so cursor movement stays aligned.
|
|
107
|
+
const width = Math.max(1, (output.columns || 80) - 1);
|
|
108
|
+
const clipped = lines.map(line => {
|
|
109
|
+
let cells = 0;
|
|
110
|
+
let result = '';
|
|
111
|
+
for (const char of line) {
|
|
112
|
+
const size = char.codePointAt(0) >= 0x1100 ? 2 : 1;
|
|
113
|
+
if (cells + size > width)
|
|
114
|
+
break;
|
|
115
|
+
result += char;
|
|
116
|
+
cells += size;
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
});
|
|
120
|
+
const highlighted = clipped.map((line, index) => {
|
|
121
|
+
if (index !== selected - start + 1 || colorDepth < 4)
|
|
122
|
+
return line;
|
|
123
|
+
// HarmonyOS-style blue (#0A59F7), with an ANSI blue fallback.
|
|
124
|
+
const color = colorDepth >= 24 ? '\x1b[1;38;2;255;255;255;48;2;10;89;247m' : '\x1b[1;97;44m';
|
|
125
|
+
return color + line + '\x1b[0m';
|
|
126
|
+
});
|
|
127
|
+
output.write(highlighted.join('\n') + '\n');
|
|
128
|
+
renderedLines = clipped.length;
|
|
129
|
+
}
|
|
130
|
+
function finish(agent) {
|
|
131
|
+
input.removeListener('keypress', onKey);
|
|
132
|
+
input.removeListener('end', onEnd);
|
|
133
|
+
input.removeListener('error', onError);
|
|
134
|
+
input.setRawMode(wasRaw);
|
|
135
|
+
if (!wasFlowing)
|
|
136
|
+
input.pause();
|
|
137
|
+
if (agent) {
|
|
138
|
+
output.write(`已选择:${choices.find(item => item.agent === agent).label}\n`);
|
|
139
|
+
resolve(agent);
|
|
140
|
+
}
|
|
141
|
+
else
|
|
142
|
+
reject(new Error('Installation cancelled before making changes'));
|
|
143
|
+
}
|
|
144
|
+
function onEnd() { finish(); }
|
|
145
|
+
function onError(error) { finish(); }
|
|
146
|
+
function onKey(text, key = {}) {
|
|
147
|
+
if ((key.ctrl && ['c', 'd'].includes(key.name || '')) || key.name === 'escape') {
|
|
148
|
+
finish();
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (key.name === 'up' || key.name === 'down') {
|
|
152
|
+
selected = (selected + (key.name === 'up' ? -1 : 1) + choices.length) % choices.length;
|
|
153
|
+
answer = '';
|
|
154
|
+
}
|
|
155
|
+
else if (key.name === 'return' || key.name === 'enter') {
|
|
156
|
+
const value = answer.trim().toLowerCase();
|
|
157
|
+
if (['q', 'quit', 'exit'].includes(value)) {
|
|
158
|
+
finish();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const choice = !value ? choices[selected] : /^\d+$/.test(value) ? choices[Number(value) - 1] : choices.find(item => item.agent === value);
|
|
162
|
+
if (choice) {
|
|
163
|
+
finish(choice.agent);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
answer = '';
|
|
167
|
+
}
|
|
168
|
+
else if (key.name === 'backspace')
|
|
169
|
+
answer = answer.slice(0, -1);
|
|
170
|
+
else if (text && !key.ctrl && !key.meta && /^[a-zA-Z0-9-]+$/.test(text))
|
|
171
|
+
answer = (answer + text).slice(0, 30);
|
|
172
|
+
else
|
|
173
|
+
return;
|
|
174
|
+
render();
|
|
175
|
+
}
|
|
176
|
+
emitKeypressEvents(input);
|
|
177
|
+
input.setRawMode(true);
|
|
178
|
+
input.on('keypress', onKey);
|
|
179
|
+
input.once('end', onEnd);
|
|
180
|
+
input.once('error', onError);
|
|
181
|
+
input.resume();
|
|
182
|
+
render();
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
export async function selectAgent(extensionDir) {
|
|
186
|
+
if (!process.stdin.isTTY || !process.stderr.isTTY) {
|
|
187
|
+
throw new Error('Agent selection requires an interactive terminal; pass --agent <name> (for example --agent opencode)');
|
|
188
|
+
}
|
|
189
|
+
const choices = detectAgents({ extensionDir });
|
|
190
|
+
if (process.env.TERM !== 'dumb')
|
|
191
|
+
return chooseAgentWithKeys(choices);
|
|
192
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
193
|
+
const controller = new AbortController();
|
|
194
|
+
rl.once('SIGINT', () => controller.abort());
|
|
195
|
+
rl.once('close', () => controller.abort());
|
|
196
|
+
try {
|
|
197
|
+
return await chooseAgent(choices, prompt => rl.question(prompt, { signal: controller.signal }), text => process.stderr.write(text));
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
if (controller.signal.aborted)
|
|
201
|
+
throw new Error('Installation cancelled before making changes');
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
finally {
|
|
205
|
+
rl.close();
|
|
206
|
+
}
|
|
207
|
+
}
|