@harmonyos-arkts/d2h 0.1.22 → 0.1.27
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 +3 -1
- package/agents/d2h.md +25 -45
- package/dist/bin/install-opencode.js +16 -2
- package/dist/src/install-opencode.js +12 -2
- package/dist/src/install-tui-extension.js +133 -0
- package/dist/src/install-vscode.js +7 -2
- package/dist/src/metrics-plugin.js +54 -0
- package/dist/src/toolchain.js +2 -2
- package/package.json +1 -1
- package/skills/d2h-app-solution/SKILL.md +2 -0
- package/skills/d2h-architecture-plan/SKILL.md +21 -11
- package/skills/d2h-architecture-plan/references/architecture-plan.example.json +357 -0
- package/skills/d2h-architecture-plan/references/directory-creation.md +24 -14
- package/skills/d2h-architecture-plan/references/json-contract.md +111 -0
- package/skills/d2h-architecture-plan/references/plan-contract.md +18 -15
- package/skills/d2h-architecture-plan/references/selection-flow.md +71 -0
- package/skills/d2h-architecture-plan/references/source-review.md +14 -0
- package/skills/d2h-architecture-plan/scripts/architecture_plan.py +281 -0
- package/skills/d2h-architecture-plan/scripts/test_architecture_plan.py +378 -0
- package/skills/d2h-cloud-knowledge/SKILL.md +1 -1
- package/skills/d2h-dashboard/SKILL.md +35 -21
- package/skills/d2h-spec-develop/SKILL.md +135 -41
- package/skills/d2h-spec-generate/SKILL.md +22 -70
- package/skills/d2h-spec-generate/assets/spec-template.md +1 -1
- package/skills/d2h-spec-generate/references/from-plan.md +13 -5
- package/skills/d2h-spec-generate/references/spec-content.md +4 -6
- package/skills/d2h-spec-plan/SKILL.md +22 -23
- package/skills/d2h-spec-plan/agents/openai.yaml +3 -3
- package/skills/d2h-spec-plan/references/plan-contract.md +32 -7
- package/skills/d2h-spec-plan/references/planning-method.md +13 -37
- package/skills/d2h-spec-plan/references/planning-review.md +23 -0
- package/skills/d2h-spec-plan/references/round-scope-assessment.md +12 -39
- package/skills/d2h-spec-plan/references/work-packets.md +7 -55
- package/skills/managing-d2h-toolchain/environment-requirements.json +1 -1
- package/skills/managing-d2h-toolchain/toolchain.json +1 -1
- package/skills/d2h-spec-develop/agents/openai.yaml +0 -7
- package/skills/d2h-spec-develop/references/worker-workflow.md +0 -26
- package/skills/d2h-spec-plan/references/architecture-handoff.md +0 -9
package/README.md
CHANGED
|
@@ -46,6 +46,8 @@ npx --yes @harmonyos-arkts/d2h@latest install --agent vscode --force
|
|
|
46
46
|
npx --yes @harmonyos-arkts/d2h@latest install --agent vscode --force --remote
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
+
安装或升级时会自动清除指标插件缓存(`~/.cache/opencode/{packages,node_modules}`,macOS/Linux/Windows 路径一致;VS Code 场景为 `~/.harmonybot/opencode/vscode/cache/opencode/{packages,node_modules}`)中 `opencode-metrics-plugin*` 目录,OpenCode 会在下次启动时重新拉取最新版插件;`--dry-run` 只预览不删除。
|
|
50
|
+
|
|
49
51
|
安装器会安装清单中验证过的 AppGraph 和 droid2hmos 版本,并安装迁移 Skill 和 `d2h` Agent。安装完成后请完全退出并重新启动对应应用。
|
|
50
52
|
|
|
51
53
|
## 检查与升级
|
|
@@ -108,4 +110,4 @@ npx --yes @harmonyos-arkts/d2h@latest doctor --agent codex
|
|
|
108
110
|
|
|
109
111
|
`d2h workflow --help` 查看能力,`d2h workflow contract artifacts` 查看产物所有权。运行时与契约随 D2H 包分发,不再位于规划 Skill 内;只复制或删除某个 Skill 不影响公共工具。Python 解释器可用 `D2H_PYTHON` 显式指定。详见 [工作流解耦说明](docs/workflow-decoupling.md)。
|
|
110
112
|
|
|
111
|
-
增量流程可先用 `d2h-spec-plan` 输出可评审波次计划,再由原 `d2h-spec-generate` 的 `from-plan` 模式展开所选成员,旧独立生成模式保留。新计划以 `spec_generation_policy=required-v1` 对未生成或失效正文阻止派发;评审用 `d2h workflow validate --planning-only`,生成交接见 `d2h workflow contract generation`。主入口 `d2h.md` 由人工适配。
|
|
113
|
+
增量流程可先用 `d2h-spec-plan` 输出可评审波次计划,再由原 `d2h-spec-generate` 的 `from-plan` 模式展开所选成员,旧独立生成模式保留。新计划以 `spec_generation_policy=required-v1` 对未生成或失效正文阻止派发;评审用 `d2h workflow validate --planning-only`,生成交接见 `d2h workflow contract generation`。主入口 `d2h.md` 由人工适配。
|
package/agents/d2h.md
CHANGED
|
@@ -11,17 +11,18 @@ description: Android 应用到 HarmonyOS 的 AI 驱动迁移主 Agent;按迁
|
|
|
11
11
|
|
|
12
12
|
必须覆盖所有页面、可见控件和状态、导航与 Dialog 流程、业务功能,以及影响行为的资源和配置。Android 源码与真实运行行为决定“做什么”,HarmonyOS 原生机制决定“怎么做”。无法等价的差异必须明确记录,不能静默省略或伪装成完成。
|
|
13
13
|
|
|
14
|
-
迁移由 AI 读取 Facts、`.migration/utg/page.json`、页面 Spec、`batch_report.json`、Android 源码、HarmonyOS
|
|
14
|
+
迁移由 AI 读取 Facts、`.migration/utg/page.json`、页面 Spec、`batch_report.json`、Android 源码、HarmonyOS 代码和实际测试结果后作出决策。
|
|
15
15
|
|
|
16
16
|
## 产物边界
|
|
17
17
|
|
|
18
|
-
- `.migration/progress.json` 汇总七个阶段的进度。工作区就绪后执行 `droid2hmos progress init <ANDROID_PROJECT>`,恢复时保留已有记录;用 `progress update <ANDROID_PROJECT> --stage <STAGE_ID> --status <in_progress|completed|blocked>` 更新状态,阻塞原因用 `--blocker`
|
|
18
|
+
- `.migration/progress.json` 汇总七个阶段的进度。工作区就绪后执行 `droid2hmos progress init <ANDROID_PROJECT>`,恢复时保留已有记录;用 `progress update <ANDROID_PROJECT> --stage <STAGE_ID> --status <in_progress|completed|blocked>` 更新状态,阻塞原因用 `--blocker` 记录。
|
|
19
|
+
按 CLI 的语义 ID 更新:架构规划为 `harmony-architecture`,Android 分析为 `android-analysis`。仅在实际交付条件满足后标记完成,返工时同步受影响阶段;不手改 JSON。
|
|
19
20
|
- `.migration/architecture-plan/architecture-plan.md` 保存架构选项、推荐/选定方案、源到目标目录归属、主要依赖、共享所有者及风险。实际创建/复用基础工程与目录时才附 `shell-receipt.json`;规划或目录壳子不能作为目标能力已实现的证据。
|
|
20
21
|
- `.migration/spec/` 中的 Facts 是 AppGraph 从 Android 源码确定性提取的结构化事实基线,用于范围发现、实体与交互关联、源码定位和遗漏检查。Facts 可能包含 unresolved 项或存在抽取遗漏,不能替代对 Android 源码及必要运行行为的阅读核验。
|
|
21
22
|
- `.migration/utg/page.json` 是页面、到达路径和导航计划的输入,也是页面 Spec 使用的运行路径依据。
|
|
22
23
|
- `.migration/page-specs/pages.json` 保存 AI 作出的页面范围、顺序、评分和证据决策。
|
|
23
|
-
- 每个 `.migration/page-specs/page_NNNN_<name>-<id>/` 只包含 `spec.md
|
|
24
|
-
- `.migration/page-specs/batch_report.json`
|
|
24
|
+
- 每个 `.migration/page-specs/page_NNNN_<name>-<id>/` 只包含 `spec.md`。
|
|
25
|
+
- `.migration/page-specs/batch_report.json` 是唯一执行账本,记录逐 Spec 的实现、证据、差异和回归结论。主 Agent 在进入开发时按有效计划初始化,恢复时保留已有账本;后续原位更新并保留历史,不得重新生成覆盖。
|
|
25
26
|
- Spec、账本、测试文件和状态字段都是辅助证据,不是应用实现本身。只存在于文档、注释、桩代码或不可达文件中的能力均视为未完成。
|
|
26
27
|
|
|
27
28
|
## 场景与 Skill 路由
|
|
@@ -35,8 +36,9 @@ description: Android 应用到 HarmonyOS 的 AI 驱动迁移主 Agent;按迁
|
|
|
35
36
|
| 从源码生成可审计功能清单、MVP/core/full 阶段、逐功能技术栈/三方 SDK/SO/权限与跨仓实现状态 | `d2h-app-solution` |
|
|
36
37
|
| 从 Android 源码生成或刷新 Facts、UTG、点击路径和 `.migration/utg/page.json` | `d2h-utg-static-generate` |
|
|
37
38
|
| 需要 AI 修复源码派生 UTG,或在 Android 设备上按已有计划采集运行时证据 | `d2h-utg-ai-generate` |
|
|
38
|
-
| 根据 Facts
|
|
39
|
-
|
|
|
39
|
+
| 根据 Facts、源码和 UTG 生成页面计划、完整 `spec.md` 及初始账本 | `d2h-spec-generate` |
|
|
40
|
+
| 根据已确认功能范围与已有页面任务规划里程碑和波次 | `d2h-spec-plan` |
|
|
41
|
+
| 按固定 Spec 范围串行实施、构建、检查并返回提交与证据 | `d2h-spec-develop` |
|
|
40
42
|
| 根据 Android 工程结构与必要源码做目录级架构规划,详列推荐方案并对照另两套;确认并要求创建后落地目录壳子 | `d2h-architecture-plan` |
|
|
41
43
|
| 规划或编写 ArkTS 架构、状态、导航和页面代码 | `arkts-mvvm-architecture` |
|
|
42
44
|
| 生成或执行 Python Hypium 端到端功能测试 | `d2h-hypium-forge` |
|
|
@@ -54,13 +56,9 @@ description: Android 应用到 HarmonyOS 的 AI 驱动迁移主 Agent;按迁
|
|
|
54
56
|
|
|
55
57
|
### 一、启动或恢复
|
|
56
58
|
|
|
57
|
-
加载 `managing-d2h-toolchain` skill 完成基础工具链预检和安装,仅需要执行一次
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
`.migration/progress.json` 就绪(`progress init` 首次创建或恢复时已存在)后,立即加载 `d2h-dashboard` 自动启动实时看板并用默认浏览器打开网页;看板启动或打开失败只记录,不阻塞迁移。
|
|
62
|
-
|
|
63
|
-
设备暂不可用时可以继续静态分析、页面规划和不依赖设备的实现,但交互页面不能标记为验证通过,也不能进入最终完成门禁。
|
|
59
|
+
1. 加载 `managing-d2h-toolchain` skill 完成基础工具链预检和安装,仅需要执行一次
|
|
60
|
+
2. 加载 `preparing-migration-workspace`,完成工具链、Android/HarmonyOS 工程、迁移工作区、配置、基线和设备检查。迁移工作区使用 Android 工程父目录下的 `<工程名>-migration/.migration/`,不得写入 Android 工程内部。
|
|
61
|
+
3. `.migration/progress.json` 就绪(`progress init` 首次创建或恢复时已存在)后,立即加载 `d2h-dashboard` 自动启动实时看板并用默认浏览器打开网页;看板启动或打开失败只记录,不阻塞迁移。
|
|
64
62
|
|
|
65
63
|
### 二、功能清单生成
|
|
66
64
|
|
|
@@ -68,29 +66,21 @@ description: Android 应用到 HarmonyOS 的 AI 驱动迁移主 Agent;按迁
|
|
|
68
66
|
|
|
69
67
|
### 三、HarmonyOS 工程架构设计
|
|
70
68
|
|
|
71
|
-
1. 加载 `d2h-architecture-plan`,输入 Android
|
|
69
|
+
1. 加载 `d2h-architecture-plan`,输入 Android 工程目录、已确认功能范围和第二阶段已有功能分析作为定位线索。遵循该 Skill 的默认 Android 阅读范围、鸿蒙工程结合选择及目录级分析深度,不另做全量扫描或完整业务链审计。
|
|
72
70
|
2. 将规划写入 `.migration/architecture-plan/architecture-plan.md`:默认详列推荐方案目录与归属,另两套给结构差异对照。沿用该 Skill 的基础依赖/业务 feature 分层和共享所有权规则;候选页面族是目录设计依据,不是最终页面/Spec 清单。
|
|
73
71
|
3. 完整迁移中记录用户实际选定的方案与修订意见;确认当前方案且要求创建后,按该 Skill 的目录落地流程创建或复用基础工程、补齐关键目录并保存 `shell-receipt.json`。已有“采用推荐并创建”授权直接执行;预检已有壳则复用,不把目录壳子当成注册完成的模块或业务实现。
|
|
74
72
|
4. 创建/复用后核对 `.migration/config.json` 的 `harmonyProject` 与实际目标根一致;路径变化时通过现有 CLI 配置入口同步。向后续阶段交接当前规划路径、选定方案、目标根、模块/目录归属、共享所有者与必要前置,实际落地时再附 receipt 及未完成项。完整迁移的架构阶段须完成选型,以及本次要求的创建/复用后才能标记完成;仅请求规划则按 Skill 的规划交付条件结束。
|
|
75
73
|
|
|
76
|
-
选型尚未明确时,可以继续下一阶段不依赖目标结构的 Android 分析;确认前不据候选方案创建业务目录或固定 Spec 的目标归属。只影响实现的 SDK/Native 未知保留为相关能力前置;仍影响模块/目录的未知明确待决范围,不伪称结构已经确定。
|
|
77
|
-
|
|
78
74
|
### 四、Android 工程分析
|
|
79
75
|
|
|
80
76
|
1. 加载 `d2h-utg-static-generate`,生成或刷新 Facts、UTG、点击路径和 `.migration/utg/page.json`,并对照真实 Android 源码核验页面、入口、交互、数据流和 unresolved 项。
|
|
81
|
-
2.
|
|
82
|
-
3. Facts 或 UTG 未覆盖、但源码中真实存在的行为仍须纳入页面 Spec,并在 `batch_report.json` 中记录发现与处理情况。
|
|
83
|
-
4. 发现架构规划遗漏的职责、共享状态或依赖冲突时,返回架构阶段局部修订受影响归属,保留已有用户选择;涉及重要取舍时展示变更,不重做全部架构分析,也不由页面候选静默裁剪真实业务。
|
|
77
|
+
2. 加载 `d2h-utg-ai-generate` 补充 utg 未识别的项目。
|
|
84
78
|
|
|
85
79
|
### 五、spec 设计与生成
|
|
86
|
-
加载 `d2h-spec-generate`,由 AI 基于当前 Facts、`.migration/feature-analysis/` 的功能清单、`.migration/utg/page.json`、Android 源码、已选定架构和实际 HarmonyOS 工程状态完成:
|
|
87
|
-
|
|
88
|
-
1. 识别所有页面、Dialog、Sheet 和具有独立行为的页面模式。
|
|
89
|
-
2. 决定页面依赖、开发顺序、评分与证据账本,写入 `.migration/page-specs/pages.json`。
|
|
90
|
-
3. 为每个 `page_NNNN_<name>-<id>` 生成且只生成一个 `spec.md`。
|
|
91
|
-
4. 使用该 Skill 自带的 `build_batch_report.py` 生成初始 `batch_report.json`。
|
|
92
80
|
|
|
93
|
-
`d2h-spec-generate
|
|
81
|
+
1. 加载 `d2h-spec-generate`,根据 Facts、`.migration/utg/page.json`、源码和目标工程现状确定页面边界、依赖与顺序,生成 `pages.json`、页面 `spec.md` 和初始 `batch_report.json`。已有产物按该技能规则复用,不能覆盖执行历史。
|
|
82
|
+
2. 将已确认功能范围、选定架构及已有页面产物交给 `d2h-spec-plan`,规划范围映射、任务排序、里程碑和波次;主 Agent 按技能要求核对规划结果。
|
|
83
|
+
3. 执行顺序以 spec-plan 的里程碑、波次和任务排序为准;页面归属、生成时的顺序和依赖作为规划依据。排序不得违反实际前置,不拆合 Spec、不改变正文布局或账本任务身份。
|
|
94
84
|
|
|
95
85
|
### 六、代码转换
|
|
96
86
|
|
|
@@ -101,33 +91,23 @@ description: Android 应用到 HarmonyOS 的 AI 驱动迁移主 Agent;按迁
|
|
|
101
91
|
- 迁移字符串和多语言时使用 `arkts-i18n`,禁止用 `.ets` 硬编码代替字符串资源迁移。
|
|
102
92
|
- 转换图片和 drawable 时使用 `android2hmos_resources_convert`;发现尺寸或比例问题时使用 `arkts-icon-sizing`。
|
|
103
93
|
|
|
94
|
+
2. 加载 `d2h-spec-develop`,主 Agent 按有效计划初始化或恢复 `batch_report.json`,按里程碑、波次和任务排序严格串行推进。任意时刻只派发一个页面,由一个独立 page-worker 完成当前页面闭环:
|
|
104
95
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
d. 页面实现与测试通过后,在 `batch_report.json` 当前页面明细中记录真实实现文件、Android 源码依据、本次构建与 Forge 测试的实际结果及证据路径,以及差异或阻塞。未产出或未保存的结果、日志如实记录为缺失,不得填写假定存在的路径或据此标记通过。
|
|
111
|
-
e. 主 Agent 完成当前页面的实现提交,原位更新 `batch_report.json`,并按 Skill 的页面完成清单复核实现、构建、测试、证据、提交和工作区状态。
|
|
112
|
-
f. 前页面未闭环、仍有页面所属未提交修改或复核失败时,只能继续修复当前页面。当前页面完整闭环并通过主 Agent 复核后,同一 worker 才能继续批次内下一页;当前批次全部闭环后,主 Agent 才能选择下一批页面并派发新的 worker。
|
|
96
|
+
a. 主 Agent 按账本中的有效规划,只从纳入的任务中,根据实际前置证据选择当前波次内按任务排序最早未完成且前置满足的任务,固定本次任务 ID、版本和允许路径;未纳入任务不得因规格已生成而派发。
|
|
97
|
+
b. 向 page-worker 交接详细 Spec、源码与目标工程、Git 基线、真实共享接口和检查要求。worker 加载 `d2h-spec-develop`,只实施当前页面,按技能完成构建、测试、提交及账本更新,返回变更、证据和缺口。
|
|
98
|
+
c. 主 Agent 按页面流程组织检查;需要生成或更新 Python Hypium 测试资产时加载 `d2h-hypium-forge`。核对实际断言、执行结果和证据,未执行、缺失或过期的结果不能标记通过。
|
|
99
|
+
d. 主 Agent 复核作用域提交和工作区,核对 `batch_report.json` 中记录的真实实现文件、来源、本次构建与测试证据、差异及阻塞,原位更新并保留历史。
|
|
100
|
+
e. 当前任务闭环后再按计划选择下一任务;受阻时继续修复当前任务或记录外部阻塞。里程碑与波次组织交付顺序,不拆分页面闭环或改变验收要求。
|
|
113
101
|
|
|
114
102
|
若当前环境不支持独立 page-worker,必须明确报告该开发模式无法执行,不能静默改成主 Agent 批量开发。
|
|
115
103
|
|
|
116
|
-
### 七、测试与交付
|
|
117
|
-
|
|
118
|
-
全部页面达到 `implemented/passed/passed` 后:
|
|
119
|
-
|
|
120
|
-
1. 加载 `d2h-hypium-forge`,在已安装当前 HAP 的目标设备上执行覆盖全部迁移范围内功能场景的完整 Python Hypium 回归,保留本次实际执行结果和日志。核对用例范围、执行数和各项状态;零执行、失败、错误或必测场景被跳过、未执行时均不能通过,历史 PASS 不能替代本次完整回归。
|
|
121
|
-
2. 需要诊断 UI 自动化、构建或运行故障时加载 `harmonyos-migration-playbook`;失败必须回到对应页面修复,不能降低验收标准。
|
|
122
|
-
3. 主 Agent 对照各页 Spec、源码、实际实现和设备结果完成行为审查,将结论、被测 HAP 与设备、完整回归结果和实际证据路径、差异及未解决问题记录到 `batch_report.json` 的批次回归部分。直接核对账本队列、页面明细、汇总和引用证据的一致性,满足完成条件后才能宣布迁移完成。
|
|
123
|
-
4. 完整结束或明确中止后加载 `reviewing-migration-process` 生成流程复盘;复盘不是完成条件。
|
|
124
|
-
|
|
125
104
|
## 持续执行与人工介入
|
|
126
105
|
|
|
127
106
|
迁移开始后默认连续执行,不得在页面或阶段之间询问“是否继续”。只有以下情况允许暂停:
|
|
128
107
|
|
|
129
108
|
- 禁止依据模型自行估算的“剩余 token”“上下文百分比”“本轮剩余容量”等决定停止、收尾、汇报后等待或要求用户开启新会话。此类估算不可信。
|
|
130
109
|
- 用户主动中断、修改需求或发出新指令。
|
|
110
|
+
- 首次范围尚未确认或用户正在调整功能清单;收到明确回答后从对应环节继续,已有有效选择不重复询问。
|
|
131
111
|
- 架构选型或重要修订需要用户决定时,只等待依赖该选择的目标目录落地/Spec 分配;独立的 Android 分析可继续。仅请求架构规划则交付即可,不强求立即选型;已有“采用推荐并创建”明确授权时记录后继续,不重复询问。
|
|
132
112
|
- 真机签名、开发者账号、权限或凭据必须由用户完成,且没有可用替代方案。
|
|
133
113
|
- 设备、CLI、构建环境或外部服务持续不可用,完成自诊和有限重试后仍确认是外部问题。
|
|
@@ -153,12 +133,12 @@ f. 前页面未闭环、仍有页面所属未提交修改或复核失败时,
|
|
|
153
133
|
|
|
154
134
|
## 完成条件
|
|
155
135
|
|
|
156
|
-
|
|
136
|
+
以下条件按本次已确认开发范围核对;计划未纳入的任务保留规格和账本状态,不阻塞本次范围交付,也不得将本次完成表述为全量迁移完成。只有同时满足以下条件,才允许宣布本次范围完成:
|
|
157
137
|
|
|
158
138
|
- Preflight、Facts、UTG、页面 Spec、`batch_report.json` 和证据对应当前源码。
|
|
159
139
|
- `pages.json` 覆盖全部已知页面或明确记录排除原因。
|
|
160
140
|
- 每个已知页面、Dialog、Sheet 和关键模式都有唯一 `spec.md`,页面包中没有额外产物。
|
|
161
|
-
- `batch_report.json`
|
|
141
|
+
- `batch_report.json` 覆盖当前确认范围内的全部 Spec,逐项验收、波次目标和页面约定范围均已满足,没有未解决阻塞;以当前账本契约与实际证据核验,不以旧页面状态字段替代逐项验收。
|
|
162
142
|
- 所有 Spec 功能项都有真实、可达的 HarmonyOS 实现。
|
|
163
143
|
- HarmonyOS 工程构建、安装、启动成功;当前 HAP 的 Forge 完整回归通过,没有失败、错误或必测场景未执行。
|
|
164
144
|
- `batch_report.json` 已记录最终行为审查、完整回归结论及实际证据路径,队列、页面明细和汇总一致。
|
|
@@ -11,10 +11,12 @@ import { fileURLToPath } from 'node:url';
|
|
|
11
11
|
import path from 'node:path';
|
|
12
12
|
import os from 'node:os';
|
|
13
13
|
import { inspectInstallation, installOpenCode } from '../src/install-opencode.js';
|
|
14
|
+
import { findMetricsPluginCacheDirs, metricsPluginCacheRoots } from '../src/metrics-plugin.js';
|
|
14
15
|
import { inspectToolchain, installToolchain, loadToolchain } from '../src/toolchain.js';
|
|
15
16
|
import fs from 'node:fs';
|
|
16
17
|
import { inspectVSCodeInstallation, installVSCode } from '../src/install-vscode.js';
|
|
17
18
|
import { codexConfigRoot, inspectCodexInstallation, installCodex } from '../src/install-codex.js';
|
|
19
|
+
import { installTuiExtension, inspectTuiExtension } from '../src/install-tui-extension.js';
|
|
18
20
|
import { runWorkflow } from '../src/workflow.js';
|
|
19
21
|
const help = `Install this package's skills and agents into OpenCode, DevEco Code or Codex.
|
|
20
22
|
|
|
@@ -86,6 +88,12 @@ try {
|
|
|
86
88
|
const results = inspectToolchain(packageRoot);
|
|
87
89
|
for (const item of results)
|
|
88
90
|
console.log(`${item.status}: ${item.package} expected ${item.expectedVersion}, installed ${item.installedVersion ?? 'missing'}; capabilities ${JSON.stringify(item.capabilities)}`);
|
|
91
|
+
const pluginCache = agent === 'codex' ? [] : findMetricsPluginCacheDirs(metricsPluginCacheRoots(agent));
|
|
92
|
+
console.log(`plugin cache: ${pluginCache.length ? `${pluginCache.join(', ')}; cleared by d2h install/upgrade` : 'none'}`);
|
|
93
|
+
if (agent === 'opencode' || agent === 'vscode') {
|
|
94
|
+
const tui = inspectTuiExtension({ agent: agent === 'vscode' ? 'vscode' : 'opencode', extensionDir });
|
|
95
|
+
console.log(`${tui.status}: opencode-tui-extension ${tui.summary}`);
|
|
96
|
+
}
|
|
89
97
|
const checkerUrl = new URL('../../scripts/check-environment.mjs', import.meta.url);
|
|
90
98
|
const { main } = await import(__rewriteRelativeImportExtension(checkerUrl.href));
|
|
91
99
|
const environmentExit = await main([]);
|
|
@@ -157,18 +165,24 @@ try {
|
|
|
157
165
|
console.log(`definitions ${installation.status}: ${installation.summary}`);
|
|
158
166
|
for (const item of inspectToolchain(packageRoot))
|
|
159
167
|
console.log(`${item.status}: ${item.package} expected ${item.expectedVersion}, installed ${item.installedVersion ?? 'missing'}`);
|
|
168
|
+
const pluginCache = options.agent === 'codex' ? [] : findMetricsPluginCacheDirs(metricsPluginCacheRoots(options.agent));
|
|
169
|
+
console.log(`plugin cache: ${pluginCache.length ? `${pluginCache.join(', ')}; cleared by d2h install/upgrade` : 'none'}`);
|
|
160
170
|
}
|
|
161
171
|
else if (!skipTools)
|
|
162
172
|
installToolchain(packageRoot, { dryRun: options.dryRun, force: options.force });
|
|
163
173
|
else if (!explicitSource && !options.dryRun)
|
|
164
174
|
console.log(`Skipped managed CLI installation (${Object.keys(loadToolchain(packageRoot).tools).join(', ')}).`);
|
|
165
175
|
if (!checkOnly) {
|
|
166
|
-
|
|
167
|
-
|
|
176
|
+
let vscodeExtensionRoot;
|
|
177
|
+
if (options.agent === 'vscode') {
|
|
178
|
+
vscodeExtensionRoot = installVSCode({ sourceDir: options.sourceDir, extensionDir, remote, dryRun: options.dryRun }).extensionRoot;
|
|
179
|
+
}
|
|
168
180
|
else if (options.agent === 'codex')
|
|
169
181
|
installCodex({ ...options, remote });
|
|
170
182
|
else
|
|
171
183
|
installOpenCode({ ...options, remote });
|
|
184
|
+
if ((options.agent === 'opencode' || options.agent === 'vscode') && !skipTools)
|
|
185
|
+
installTuiExtension({ dryRun: options.dryRun, force: options.force, extensionRoot: vscodeExtensionRoot });
|
|
172
186
|
if (!options.dryRun) {
|
|
173
187
|
const target = options.agent === 'vscode' ? 'VS Code HarmonyOS Dev Assistant' :
|
|
174
188
|
options.agent === 'deveco' ? 'DevEco Code' : options.agent === 'codex' ? 'Codex' : 'OpenCode';
|
|
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import os from 'node:os';
|
|
4
4
|
import crypto from 'node:crypto';
|
|
5
|
-
import { updateMetricsPlugin } from './metrics-plugin.js';
|
|
5
|
+
import { clearMetricsPluginCache, findMetricsPluginCacheDirs, metricsPluginCacheRoots, updateMetricsPlugin } from './metrics-plugin.js';
|
|
6
6
|
export function stat(file) {
|
|
7
7
|
try {
|
|
8
8
|
return fs.lstatSync(file);
|
|
@@ -136,7 +136,7 @@ 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, log = console.log }) {
|
|
139
|
+
export function installOpenCode({ sourceDir, configDir, agent = 'opencode', link = false, force = false, dryRun = false, remote = false, pluginCacheRoots, log = console.log }) {
|
|
140
140
|
if (!['opencode', 'deveco'].includes(agent))
|
|
141
141
|
throw new Error(`unsupported agent: ${agent}`);
|
|
142
142
|
const application = agent === 'deveco' ? 'DevEco Code' : 'OpenCode';
|
|
@@ -257,6 +257,16 @@ export function installOpenCode({ sourceDir, configDir, agent = 'opencode', link
|
|
|
257
257
|
fs.rmSync(temporary);
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
|
+
const pluginCacheRoot = pluginCacheRoots ?? metricsPluginCacheRoots(agent);
|
|
261
|
+
if (dryRun) {
|
|
262
|
+
for (const dir of findMetricsPluginCacheDirs(pluginCacheRoot))
|
|
263
|
+
log(`would remove metrics plugin cache: ${dir}`);
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
const cleared = clearMetricsPluginCache({ roots: pluginCacheRoot, log });
|
|
267
|
+
for (const failure of cleared.failures)
|
|
268
|
+
log(`warning: failed to clear metrics plugin cache: ${failure}`);
|
|
269
|
+
}
|
|
260
270
|
log(`${application} installation ${dryRun ? 'preview' : 'complete'}: ${skills} skill(s), ${agents} agent(s).`);
|
|
261
271
|
log(`Config directory: ${configRoot}`);
|
|
262
272
|
if (!dryRun)
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { run } from './toolchain.js';
|
|
5
|
+
import { locateVSCodeExtension } from './install-vscode.js';
|
|
6
|
+
export const tuiExtension = { name: 'opencode-tui-extension', version: '0.1.1' };
|
|
7
|
+
function bundledOpenCodeBinary(extensionRoot) {
|
|
8
|
+
const executable = process.platform === 'win32' ? 'opencode.exe' : 'opencode';
|
|
9
|
+
return path.join(extensionRoot, 'resources', 'opencode', 'bin', process.platform, process.arch, executable);
|
|
10
|
+
}
|
|
11
|
+
function majorVersion(output) {
|
|
12
|
+
const major = Number(output.match(/(\d+)\.\d+\.\d+/)?.[1]);
|
|
13
|
+
return Number.isInteger(major) && major > 0 ? major : null;
|
|
14
|
+
}
|
|
15
|
+
function bundledMajorVersion(binary, runner) {
|
|
16
|
+
const version = runner(binary, ['--version']);
|
|
17
|
+
if (version.status === 0) {
|
|
18
|
+
const major = majorVersion(`${version.stdout}\n${version.stderr}`);
|
|
19
|
+
if (major === 1 || major === 2)
|
|
20
|
+
return major;
|
|
21
|
+
}
|
|
22
|
+
const help = runner(binary, ['--help']);
|
|
23
|
+
const text = `${help.stdout}\n${help.stderr}`;
|
|
24
|
+
if (help.status !== 0 || !/Commands:/.test(text))
|
|
25
|
+
return null;
|
|
26
|
+
return /^\s*USAGE\b/m.test(text) ? 2 : 1;
|
|
27
|
+
}
|
|
28
|
+
export function installTuiExtension({ dryRun = false, force = false, extensionRoot, runner = run, log = console.log } = {}) {
|
|
29
|
+
const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
30
|
+
const globalRoot = runner(npm, ['root', '--global']);
|
|
31
|
+
if (globalRoot.status !== 0) {
|
|
32
|
+
log(`warning: cannot inspect global npm root; skipped ${tuiExtension.name}`);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const linkedPath = path.join(globalRoot.stdout.trim(), tuiExtension.name);
|
|
36
|
+
const linked = fs.existsSync(linkedPath) && fs.lstatSync(linkedPath).isSymbolicLink();
|
|
37
|
+
if (linked && !force) {
|
|
38
|
+
log(`preserved npm link ${tuiExtension.name} at ${linkedPath}`);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const coordinate = `${tuiExtension.name}@${tuiExtension.version}`;
|
|
42
|
+
if (dryRun) {
|
|
43
|
+
log(`would install ${coordinate}`);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const install = runner(npm, ['install', '--global', coordinate]);
|
|
47
|
+
if (install.status !== 0) {
|
|
48
|
+
log(`warning: failed to install ${coordinate}: ${install.stderr || install.error?.message || 'unknown error'}`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
log(`installed ${coordinate}`);
|
|
52
|
+
}
|
|
53
|
+
let setupArgs = ['setup'];
|
|
54
|
+
let env;
|
|
55
|
+
if (extensionRoot) {
|
|
56
|
+
const configDir = path.join(extensionRoot, 'resources', 'opencode');
|
|
57
|
+
const binary = bundledOpenCodeBinary(extensionRoot);
|
|
58
|
+
if (!fs.existsSync(binary)) {
|
|
59
|
+
log(`warning: bundled opencode binary not found: ${binary}; skipped ${tuiExtension.name} registration`);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const major = bundledMajorVersion(binary, runner);
|
|
63
|
+
if (major !== 1 && major !== 2) {
|
|
64
|
+
log(`warning: cannot detect bundled opencode version at ${binary}; skipped ${tuiExtension.name} registration`);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
setupArgs = ['setup', major === 1 ? '--v1' : '--v2'];
|
|
68
|
+
env = { ...process.env, OPENCODE_CONFIG_DIR: configDir };
|
|
69
|
+
if (dryRun) {
|
|
70
|
+
log(`would register ${tuiExtension.name} for bundled opencode v${major} into ${configDir}`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else if (dryRun) {
|
|
75
|
+
log(`would register ${tuiExtension.name} (setup)`);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const bin = process.platform === 'win32' ? `${tuiExtension.name}.cmd` : tuiExtension.name;
|
|
79
|
+
const setup = runner(bin, setupArgs, env ? { env } : undefined);
|
|
80
|
+
if (setup.status !== 0) {
|
|
81
|
+
log(`warning: ${tuiExtension.name} setup failed: ${setup.stderr || 'unknown error'}`);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
log(`registered ${tuiExtension.name} (TUI status banner)${extensionRoot ? ` into ${path.join(extensionRoot, 'resources', 'opencode')}` : ''}; restart to activate`);
|
|
85
|
+
}
|
|
86
|
+
function readJsonIfPresent(file) {
|
|
87
|
+
try {
|
|
88
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function registeredIn(config, key) {
|
|
95
|
+
return Array.isArray(config?.[key]) && config[key].some(entry => String(entry).includes(tuiExtension.name));
|
|
96
|
+
}
|
|
97
|
+
export function inspectTuiExtension({ agent, extensionDir, runner = run }) {
|
|
98
|
+
const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
99
|
+
const globalRoot = runner(npm, ['root', '--global']);
|
|
100
|
+
const installedDir = globalRoot.status === 0 ? path.join(globalRoot.stdout.trim(), tuiExtension.name) : undefined;
|
|
101
|
+
const manifest = installedDir ? readJsonIfPresent(path.join(installedDir, 'package.json')) : undefined;
|
|
102
|
+
const installedVersion = typeof manifest?.version === 'string' ? manifest.version : undefined;
|
|
103
|
+
if (!installedVersion)
|
|
104
|
+
return { status: 'warning', summary: 'not installed globally; rerun d2h install' };
|
|
105
|
+
if (agent === 'opencode') {
|
|
106
|
+
const configDir = process.env.OPENCODE_CONFIG_DIR || path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config'), 'opencode');
|
|
107
|
+
const where = [
|
|
108
|
+
registeredIn(readJsonIfPresent(path.join(configDir, 'tui.json')), 'plugin') ? 'tui.json' : undefined,
|
|
109
|
+
registeredIn(readJsonIfPresent(path.join(configDir, 'cli.json')), 'plugins') ? 'cli.json' : undefined,
|
|
110
|
+
].filter(Boolean);
|
|
111
|
+
if (!where.length)
|
|
112
|
+
return { status: 'warning', summary: `${installedVersion} installed but not registered under ${configDir}; rerun d2h install` };
|
|
113
|
+
return { status: 'passed', summary: `${installedVersion} registered (${where.join(', ')})` };
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
const root = locateVSCodeExtension(extensionDir);
|
|
117
|
+
const binary = bundledOpenCodeBinary(root);
|
|
118
|
+
if (!fs.existsSync(binary))
|
|
119
|
+
return { status: 'warning', summary: `${installedVersion} installed but bundled opencode binary missing: ${binary}` };
|
|
120
|
+
const major = bundledMajorVersion(binary, runner);
|
|
121
|
+
if (major !== 1 && major !== 2)
|
|
122
|
+
return { status: 'warning', summary: `${installedVersion} installed but bundled opencode version undetected` };
|
|
123
|
+
const file = major === 1 ? 'tui.json' : 'cli.json';
|
|
124
|
+
const configDir = path.join(root, 'resources', 'opencode');
|
|
125
|
+
if (!registeredIn(readJsonIfPresent(path.join(configDir, file)), major === 1 ? 'plugin' : 'plugins')) {
|
|
126
|
+
return { status: 'warning', summary: `${installedVersion} installed but not registered in ${path.join(configDir, file)}; rerun d2h install` };
|
|
127
|
+
}
|
|
128
|
+
return { status: 'passed', summary: `${installedVersion} registered for bundled opencode v${major} (${file})` };
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
return { status: 'warning', summary: `${installedVersion} installed but VS Code extension not found: ${error instanceof Error ? error.message : String(error)}` };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import crypto from 'node:crypto';
|
|
5
|
-
import { updateMetricsPlugin } from './metrics-plugin.js';
|
|
5
|
+
import { clearMetricsPluginCache, findMetricsPluginCacheDirs, metricsPluginCacheRoots, updateMetricsPlugin } from './metrics-plugin.js';
|
|
6
6
|
const extensionPrefix = 'huaweideveloperserviceplatform.harmonyosdevassistantforvscode-';
|
|
7
7
|
const modeLabel = '安卓转鸿蒙';
|
|
8
8
|
function digest(file) {
|
|
@@ -118,7 +118,7 @@ function copyWithBackup(source, destination, backupRoot, root) {
|
|
|
118
118
|
}
|
|
119
119
|
return true;
|
|
120
120
|
}
|
|
121
|
-
export function installVSCode({ sourceDir, extensionDir, bundleCacheRoot, remote = false, dryRun = false, log = console.log }) {
|
|
121
|
+
export function installVSCode({ sourceDir, extensionDir, bundleCacheRoot, pluginCacheRoots, remote = false, dryRun = false, log = console.log }) {
|
|
122
122
|
const sourceRoot = fs.realpathSync(sourceDir);
|
|
123
123
|
const root = validatedRoot(locateVSCodeExtension(extensionDir));
|
|
124
124
|
const cacheRoot = path.resolve(bundleCacheRoot ?? path.join(os.homedir(), '.harmonybot', 'opencode-bundle', 'vscode'));
|
|
@@ -147,6 +147,8 @@ export function installVSCode({ sourceDir, extensionDir, bundleCacheRoot, remote
|
|
|
147
147
|
for (const entry of patches)
|
|
148
148
|
log(`would update ${entry.file}`);
|
|
149
149
|
log(`would remove VS Code bundle cache ${cacheRoot}`);
|
|
150
|
+
for (const dir of findMetricsPluginCacheDirs(pluginCacheRoots ?? metricsPluginCacheRoots('vscode')))
|
|
151
|
+
log(`would remove metrics plugin cache: ${dir}`);
|
|
150
152
|
return { extensionRoot: root, changed: false };
|
|
151
153
|
}
|
|
152
154
|
if (!/^name: d2h\r?$/m.test(fs.readFileSync(path.join(sourceRoot, 'agents', 'd2h.md'), 'utf8'))) {
|
|
@@ -176,6 +178,9 @@ export function installVSCode({ sourceDir, extensionDir, bundleCacheRoot, remote
|
|
|
176
178
|
if (!changed)
|
|
177
179
|
fs.rmdirSync(backupRoot);
|
|
178
180
|
fs.rmSync(cacheRoot, { recursive: true, force: true });
|
|
181
|
+
const cleared = clearMetricsPluginCache({ roots: pluginCacheRoots ?? metricsPluginCacheRoots('vscode'), log });
|
|
182
|
+
for (const failure of cleared.failures)
|
|
183
|
+
log(`warning: failed to clear metrics plugin cache: ${failure}`);
|
|
179
184
|
log(`VS Code D2H ${changed ? 'installed' : 'unchanged'} at ${root}${changed ? `; backup: ${backupRoot}` : ''}; cleared bundle cache: ${cacheRoot}; restart VS Code to rebuild it`);
|
|
180
185
|
return { extensionRoot: root, changed, backupRoot: changed ? backupRoot : undefined };
|
|
181
186
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
1
4
|
export const liteMetricsPlugin = 'opencode-metrics-plugin-lite';
|
|
2
5
|
export const remoteMetricsPlugin = 'opencode-metrics-plugin';
|
|
6
|
+
const metricsPluginCachePrefix = 'opencode-metrics-plugin';
|
|
3
7
|
export function updateMetricsPlugin(config, remote = false) {
|
|
4
8
|
const plugins = config.plugin ?? [];
|
|
5
9
|
if (!Array.isArray(plugins))
|
|
@@ -18,3 +22,53 @@ export function updateMetricsPlugin(config, remote = false) {
|
|
|
18
22
|
filtered[filtered.findIndex(isMetrics)] = selectedEntry;
|
|
19
23
|
config.plugin = filtered;
|
|
20
24
|
}
|
|
25
|
+
// OpenCode resolves npm plugins with Bun into XDG-style cache directories on every
|
|
26
|
+
// platform (no ~/Library/Caches on macOS, no %LocalAppData% on Windows).
|
|
27
|
+
export function metricsPluginCacheRoots(agent, home = os.homedir()) {
|
|
28
|
+
const children = ['packages', 'node_modules'];
|
|
29
|
+
if (agent === 'vscode') {
|
|
30
|
+
const cache = path.join(home, '.harmonybot', 'opencode', 'vscode', 'cache', 'opencode');
|
|
31
|
+
return children.map(child => path.join(cache, child));
|
|
32
|
+
}
|
|
33
|
+
const cacheHome = process.env.XDG_CACHE_HOME || path.join(home, '.cache');
|
|
34
|
+
const names = agent === 'deveco' ? ['opencode', 'deveco'] : ['opencode'];
|
|
35
|
+
return names.flatMap(name => children.map(child => path.join(cacheHome, name, child)));
|
|
36
|
+
}
|
|
37
|
+
export function findMetricsPluginCacheDirs(roots) {
|
|
38
|
+
const dirs = [];
|
|
39
|
+
for (const root of roots) {
|
|
40
|
+
let children;
|
|
41
|
+
try {
|
|
42
|
+
children = fs.readdirSync(root, { withFileTypes: true });
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (error.code === 'ENOENT')
|
|
46
|
+
continue;
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
for (const child of children.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
50
|
+
if (child.isDirectory() && child.name.toLowerCase().startsWith(metricsPluginCachePrefix))
|
|
51
|
+
dirs.push(path.join(root, child.name));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return dirs;
|
|
55
|
+
}
|
|
56
|
+
export function clearMetricsPluginCache({ roots, dryRun = false, log = () => { } }) {
|
|
57
|
+
const deleted = [];
|
|
58
|
+
const failures = [];
|
|
59
|
+
for (const dir of findMetricsPluginCacheDirs(roots)) {
|
|
60
|
+
if (dryRun) {
|
|
61
|
+
log(`would remove metrics plugin cache: ${dir}`);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
66
|
+
deleted.push(dir);
|
|
67
|
+
log(`cleared metrics plugin cache: ${dir}`);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
failures.push(`${dir}: ${error instanceof Error ? error.message : String(error)}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return { deleted, failures };
|
|
74
|
+
}
|
package/dist/src/toolchain.js
CHANGED
|
@@ -18,7 +18,7 @@ export function loadToolchain(root) {
|
|
|
18
18
|
}
|
|
19
19
|
return value;
|
|
20
20
|
}
|
|
21
|
-
export const run = (command, args) => {
|
|
21
|
+
export const run = (command, args, options) => {
|
|
22
22
|
let executable = command;
|
|
23
23
|
let parameters = args;
|
|
24
24
|
if (process.platform === 'win32') {
|
|
@@ -28,7 +28,7 @@ export const run = (command, args) => {
|
|
|
28
28
|
executable = 'powershell.exe';
|
|
29
29
|
parameters = ['-NoProfile', '-NonInteractive', '-EncodedCommand', Buffer.from(script, 'utf16le').toString('base64')];
|
|
30
30
|
}
|
|
31
|
-
const result = spawnSync(executable, parameters, { encoding: 'utf8', windowsHide: true, timeout: 300000 });
|
|
31
|
+
const result = spawnSync(executable, parameters, { encoding: 'utf8', windowsHide: true, timeout: 300000, env: options?.env, cwd: options?.cwd });
|
|
32
32
|
return { status: result.status, stdout: result.stdout ?? '', stderr: result.stderr ?? '', error: result.error };
|
|
33
33
|
};
|
|
34
34
|
function version(output) { return output.match(/\b\d+\.\d+\.\d+\b/)?.[0] ?? null; }
|
package/package.json
CHANGED
|
@@ -7,6 +7,8 @@ description: Extract an auditable inventory.json containing a one-to-four-level
|
|
|
7
7
|
|
|
8
8
|
从“用户能看到并操作什么”出发重建功能树。不要把目录树、类名列表或字符串资源列表直接当成功能清单。
|
|
9
9
|
|
|
10
|
+
本 Skill 负责代码事实与功能清单,不处理迁移范围、架构选型或实施计划调整。仅用户选择变化时交调用方规划处理;补充分析时保留已有用户范围决定,不重新推算或覆盖 `should_develop`。
|
|
11
|
+
|
|
10
12
|
## 输入与默认值
|
|
11
13
|
|
|
12
14
|
收集以下输入;只有缺失项会实质改变结果时才询问:
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: d2h-architecture-plan
|
|
3
3
|
description: >-
|
|
4
|
-
用于 Android 转 HarmonyOS
|
|
5
|
-
|
|
4
|
+
用于 Android 转 HarmonyOS 的架构评估、目录规划和方案选型。读取 Android 源码,以 JSON 交付项目简介、原工程分析和三套嵌套目录,供看板展示推荐与用户选择;
|
|
5
|
+
看板确认或 question 工具回答统一落盘,目录实施读取 JSON 后复用或创建基础工程、补齐所选目录。
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Android 源码 → 鸿蒙架构与目录规划
|
|
@@ -12,24 +12,34 @@ description: >-
|
|
|
12
12
|
## 输入与边界
|
|
13
13
|
|
|
14
14
|
- 必需输入只有 Android 源码根目录,可独立执行。按用户范围识别实际应用、运行时模块、技术栈和目标设备;源码缺失或目标能力未知时标明影响。
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
15
|
+
- 默认读取 Android 工程源码及其相关资源、构建声明;不自动读取鸿蒙业务源码,也不为寻找鸿蒙参考实现扩大扫描范围。上下文已指向鸿蒙目标时,按 [source-review.md](references/source-review.md) 做最小辨别,区分自动生成的模板壳、已有业务工程和性质未明的工程。
|
|
16
|
+
- 已确认仍为自动生成模板壳的工程(包括 Preflight 创建的工程)作为后续落地基础,不作为业务架构依据,不触发“是否结合现有鸿蒙工程”的询问。职责与目录由 Android 事实及目标要求决定,不能被空壳的默认结构限制。
|
|
17
|
+
- 确认鸿蒙工程已存在,且含业务实现或最小辨别后性质仍不明确,用户又尚未决定是否结合时,询问一次:“是否结合现有鸿蒙工程的业务实现进行架构规划?默认仅分析 Android 工程。”仅提供输出路径或配置中的目标路径不单独证明已有业务工程或用户选择结合。
|
|
18
|
+
- 用户明确要求结合/复用鸿蒙业务实现时,按约定范围读取;明确选择不结合时,只分析 Android。同一工程、同一任务范围内沿用已有明确选择,不重复询问;用户改变选择时据此调整。尚未答复期间可继续 Android 侧分析,不扩读鸿蒙业务源码,也不把沉默记为用户拒绝。复用基础工程、核对配置或创建目录的授权不自动扩大为分析已有业务实现。
|
|
18
19
|
- 已有功能清单、Facts、规划可作导航线索,用当前源码核验。
|
|
19
|
-
-
|
|
20
|
+
- 默认交付 `architecture-plan.json` 作为看板决策事实源,同时保留 `architecture-plan.md` 作为现有主流程使用的阅读视图;推荐、选择和目录以 JSON 为准,两者同步。不生成持久化的全量文件清单、源码快照、import/调用图或扫描基线。已有大型扫描产物按问题查询,不整体读入或为更新规划重新生成。
|
|
20
21
|
- 源工程只读;默认在同级 `<工程名>-migration/.migration/architecture-plan/` 交付。已有文件先阅读,保留用户批注,修订时同步受影响部分。
|
|
21
|
-
-
|
|
22
|
+
- 分析分支和目录组织依据本次读取范围内的工程事实与迁移目标确定,参考示例按实际需要选用。基础配置核对可用于工程复用判断;未读取的鸿蒙业务实现不作已核验的能力复用依据。
|
|
22
23
|
|
|
23
24
|
## 架构规划
|
|
24
25
|
|
|
25
26
|
1. 按 [source-review.md](references/source-review.md) 从构建声明、入口/导航和主要源码目录建立结构地图,识别基础依赖、页面业务、共享业务及装配。仅当证据不足会改变拆合、归属或依赖方向时,定点读取相关源码;边界可解释后停止扩读。
|
|
26
|
-
2. 按 [layout-reference.md](references/layout-reference.md) 设计原结构对照 `android-mirror`、鸿蒙优选 `harmony-practice`、融合 `hybrid
|
|
27
|
-
3.
|
|
27
|
+
2. 按 [layout-reference.md](references/layout-reference.md) 设计原结构对照 `android-mirror`、鸿蒙优选 `harmony-practice`、融合 `hybrid`,共用范围地图;已有选定方案时围绕它修订并同步受影响的对照。融合结构以基础依赖保留原模块/包族、业务按 feature 承载页面为原则,需要详细展开时读 [hybrid-design.md](references/hybrid-design.md),不展开逐页实施计划。
|
|
28
|
+
3. 读取 [plan-contract.md](references/plan-contract.md) 和 [json-contract.md](references/json-contract.md),JSON 聚焦三部分:项目简介、Android 工程分析与风险、三套可独立展开的目录树;推荐/选择及最小回传元数据沿用契约。每套仅 `id/name/summary/directoryTree`,不生成机器映射表、依赖图、共享所有者或逐方案收益成本数组。每个目录都有相对路径与简介,三套均展开到可选型、可创建的关键目录粒度,不用文字差异、通配符或引用另一套目录代替树。必要的归属/依赖/共享边界在 Markdown 简记,复核与目录一致。
|
|
29
|
+
4. 运行 `python <本Skill目录>/scripts/architecture_plan.py validate <产物目录>/architecture-plan.json`,再同步 Markdown 阅读视图。向调用方交接 JSON/Markdown 路径、`planId` 和待决项;三套方案的选择单位是整套目录方案,展开/折叠及点击单个节点不改变选择。
|
|
30
|
+
|
|
31
|
+
`androidAnalysis` 固定为简短的 `summary`、按语言/界面/存储/网络四类归纳的 `techStack`、最多五项的 `risks`。风险只含名称与迁移影响;字段与类型见 JSON 契约。用用户能理解的文字说明关键事实,不堆叠工具和架构缩写,不输出源码目录清单或独立未决清单;详细核验线索放 Markdown。
|
|
28
32
|
|
|
29
33
|
本 Skill 交付架构与转换交接设计;并行候选表示具备独立转换的架构条件,实际派发、开发和验收由调用方的执行流程决定。
|
|
30
34
|
|
|
31
35
|
## 选型与可选落地
|
|
32
36
|
|
|
33
|
-
|
|
37
|
+
选型、接收回答和恢复实施时读取 [selection-flow.md](references/selection-flow.md)。仅规划时交付即可;需要选型时,模型填写推荐,`selectedProposalId` 初始为 `null`。有效选择不重复询问,风险仅展示、不要求逐项答复,也不因风险非空而阻塞选型或目录创建。
|
|
38
|
+
|
|
39
|
+
看板“确定”和 OpenCode `question` 回答是同一个确认步骤的两个入口;已有明确对话授权也可沿用。真实提交先写独立请求文件,脚本校验后保存 `architecture-selection.json` 并更新规划选择。不得先覆盖已确认文件,不把默认项、未提交/取消或模型推荐当用户答案。主规划只保留 `selectedProposalId`,不嵌套完整确认。
|
|
40
|
+
|
|
41
|
+
创建流程的提示需明确“确定后创建或复用基础工程并补齐目录”,一次确认记为 `select-and-create`,不追加“是否继续”;只选型则记为 `select`。question 回答也必须落盘,不只留在上下文。实施前运行 `read-selection` 重新核对规划、确认及原始意见,再按选定 ID 读取目录树;写入失败、不一致或有未处理的布局修改时不执行旧树。记录恢复使用统一流程的显式恢复入口。
|
|
42
|
+
|
|
43
|
+
用户通过对话调整 JSON,并同步 Markdown。仅修改说明或风险时保留有效确认;影响目录、目标位置或授权范围时,先清理当前确认和旧选择,再更新展示并按实际授权确认。技术未知由 Agent 在实施时核查;必要输入/授权缺失时只询问缺失项。
|
|
34
44
|
|
|
35
|
-
|
|
45
|
+
需要落地时读取 [directory-creation.md](references/directory-creation.md)。沿用 Preflight 目标与基础工程,普通文件工具补齐选定目录,确实无基础工程时才用本机 DevEco CLI 创建;不生成业务实现、不构建或运行应用。看板服务器、提交端点与会话通知由外部适配方提供,本 Skill 不提供监听器,也不把“文件已写入”当作 Agent 已被唤醒。
|