@buaa_smat/hometrans 26.0.1 → 26.0.3

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.
Files changed (1053) hide show
  1. package/README.md +14 -7
  2. package/agents/code-reviewer.md +25 -138
  3. package/dist/cli/index.js +4 -1
  4. package/dist/cli/init.js +131 -26
  5. package/dist/cli/uninstall.js +5 -5
  6. package/dist/platform/language.js +77 -0
  7. package/env-requirements.json +30 -5
  8. package/i18n/FILE-NAMES.md +9 -0
  9. package/i18n/agents/code-reviewer.md +364 -0
  10. package/i18n/agents/model-render-worker.md +38 -0
  11. package/i18n/agents/specgen-worker.md +18 -0
  12. package/i18n/commands/hometrans.md +17 -0
  13. package/i18n/skills/a2h-app-migrate/SKILL.md +198 -0
  14. package/i18n/skills/a2h-app-migrate/references/config.example.json +28 -0
  15. package/i18n/skills/a2h-app-migrate/references/specs.example.json +19 -0
  16. package/i18n/skills/a2h-app-migrate/references/stage-map.md +50 -0
  17. package/i18n/skills/a2h-app-migrate/references/workflow.yaml +1760 -0
  18. package/i18n/skills/a2h-app-migrate/scripts/check_spec_gen_done.mjs +114 -0
  19. package/i18n/skills/a2h-app-migrate/scripts/env_preflight.mjs +1588 -0
  20. package/i18n/skills/a2h-app-migrate/scripts/human_review_gate.mjs +657 -0
  21. package/i18n/skills/a2h-app-migrate/scripts/validate_workflow.mjs +541 -0
  22. package/i18n/skills/a2h-app-migrate/test/test_android_index.mjs +131 -0
  23. package/i18n/skills/a2h-app-migrate/test/test_arch_done.mjs +54 -0
  24. package/i18n/skills/a2h-app-migrate/test/test_build_fixer_contract.mjs +98 -0
  25. package/i18n/skills/a2h-app-migrate/test/test_config_example.mjs +42 -0
  26. package/i18n/skills/a2h-app-migrate/test/test_ensure_utg_snapshot.mjs +147 -0
  27. package/i18n/skills/a2h-app-migrate/test/test_env_requirements.mjs +698 -0
  28. package/i18n/skills/a2h-app-migrate/test/test_finalize.mjs +89 -0
  29. package/i18n/skills/a2h-app-migrate/test/test_image_probe.mjs +120 -0
  30. package/i18n/skills/a2h-app-migrate/test/test_interaction.mjs +122 -0
  31. package/i18n/skills/a2h-app-migrate/test/test_preflight_report.mjs +93 -0
  32. package/i18n/skills/a2h-app-migrate/test/test_resume_plan.mjs +219 -0
  33. package/i18n/skills/a2h-app-migrate/test/test_resume_summary.mjs +196 -0
  34. package/i18n/skills/a2h-app-migrate/test/test_reuse_static_utg.mjs +100 -0
  35. package/i18n/skills/a2h-app-migrate/test/test_run_dir.mjs +488 -0
  36. package/i18n/skills/a2h-app-migrate/test/test_skill_doc.mjs +144 -0
  37. package/i18n/skills/a2h-app-migrate/test/test_spec_gen_done.mjs +146 -0
  38. package/i18n/skills/a2h-app-migrate/test/test_spec_gen_gate.mjs +161 -0
  39. package/i18n/skills/a2h-app-migrate/test/test_specs_json_preflight.mjs +76 -0
  40. package/i18n/skills/a2h-app-migrate/test/test_ui_batch_gate.mjs +226 -0
  41. package/i18n/skills/a2h-app-migrate/test/test_user_facing_progress.mjs +43 -0
  42. package/i18n/skills/a2h-app-migrate/test/test_utg_static_done.mjs +171 -0
  43. package/i18n/skills/a2h-app-migrate/test/test_validate_workflow_bilingual.mjs +87 -0
  44. package/i18n/skills/a2h-arch-generate/SKILL.md +375 -0
  45. package/i18n/skills/a2h-arch-generate/examples/reconcile-existing-project.md +107 -0
  46. package/i18n/skills/a2h-arch-generate/examples/simple-conversion-backend.md +70 -0
  47. package/i18n/skills/a2h-arch-generate/references/arkts-mvvm-v2.md +1407 -0
  48. package/i18n/skills/a2h-arch-generate/references/artifact-contracts.generate.md +120 -0
  49. package/i18n/skills/a2h-arch-generate/references/artifact-contracts.reconcile.md +123 -0
  50. package/i18n/skills/a2h-arch-generate/references/bpta-layered-architecture-design.md +88 -0
  51. package/i18n/skills/a2h-arch-generate/references/database-schema-recovery.md +107 -0
  52. package/i18n/skills/a2h-arch-generate/references/existing-target-annotation.md +68 -0
  53. package/i18n/skills/a2h-arch-generate/references/harmony-project-inspection.md +150 -0
  54. package/i18n/skills/a2h-arch-generate/references/harmony-target-architecture.md +94 -0
  55. package/i18n/skills/a2h-arch-generate/references/homegraph-workflow.md +120 -0
  56. package/i18n/skills/a2h-arch-generate/references/source-baseline.md +93 -0
  57. package/i18n/skills/a2h-arch-generate/scripts/generate_source_baseline.mjs +360 -0
  58. package/i18n/skills/a2h-arch-generate/scripts/inspect_harmony_target.mjs +798 -0
  59. package/i18n/skills/a2h-arch-generate/scripts/lib/contract_terms.mjs +40 -0
  60. package/i18n/skills/a2h-arch-generate/scripts/module_create/generate.mjs +639 -0
  61. package/i18n/skills/a2h-arch-generate/scripts/module_create/testdata/reconcile-layer-PROJECT_DESIGN.md +47 -0
  62. package/i18n/skills/a2h-arch-generate/scripts/module_create/testdata/single-entry-PROJECT_DESIGN.md +15 -0
  63. package/i18n/skills/a2h-arch-generate/scripts/module_create/testdata/three-layer-PROJECT_DESIGN.md +36 -0
  64. package/i18n/skills/a2h-arch-generate/scripts/module_create/testdata/verification-report.md +150 -0
  65. package/i18n/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/pages.json +5 -0
  66. package/i18n/skills/a2h-arch-generate/scripts/tests/e2e/run_e2e.mjs +548 -0
  67. package/i18n/skills/a2h-arch-generate/scripts/tests/run_tests.mjs +1261 -0
  68. package/i18n/skills/a2h-arch-generate/scripts/tests/test_module_templates.mjs +70 -0
  69. package/i18n/skills/a2h-arch-generate/scripts/validate_architecture_docs.mjs +851 -0
  70. package/i18n/skills/a2h-arch-generate/scripts/validate_data_docs.mjs +982 -0
  71. package/i18n/skills/a2h-arkts-logic-coder/references/ISSUES.md +9 -0
  72. package/i18n/skills/a2h-arkts-logic-coder/references/code-generation.md +192 -0
  73. package/i18n/skills/a2h-arkts-logic-coder/references/spec-design.md +303 -0
  74. package/i18n/skills/a2h-arkts-logic-coder/scripts/design/move_spec_technical_reference.mjs +162 -0
  75. package/i18n/skills/a2h-arkts-logic-coder/scripts/design/validate_spec_design_output.mjs +298 -0
  76. package/i18n/skills/a2h-arkts-logic-coder/scripts/state_doc.mjs +587 -0
  77. package/i18n/skills/a2h-arkts-logic-coder/scripts/test_check_units.ts +149 -0
  78. package/i18n/skills/a2h-arkts-logic-coder/test/golden/move_design.md +18 -0
  79. package/i18n/skills/a2h-arkts-logic-coder/test/golden/move_design_crlf.md +18 -0
  80. package/i18n/skills/a2h-arkts-logic-coder/test/golden/move_spec.md +7 -0
  81. package/i18n/skills/a2h-arkts-logic-coder/test/golden/validate_issue_file.md +12 -0
  82. package/i18n/skills/a2h-arkts-logic-coder/test/golden/validate_issues.json +57 -0
  83. package/i18n/skills/a2h-arkts-logic-coder/test/test_spec_design_scripts.mjs +547 -0
  84. package/i18n/skills/a2h-arkts-logic-coder/test/test_state_doc.mjs +352 -0
  85. package/i18n/skills/a2h-batch-ui-align/SKILL.md +323 -0
  86. package/i18n/skills/a2h-batch-ui-align/references/cards/alignment.md +31 -0
  87. package/i18n/skills/a2h-batch-ui-align/references/cards/build.md +13 -0
  88. package/i18n/skills/a2h-batch-ui-align/references/cards/canvas.md +17 -0
  89. package/i18n/skills/a2h-batch-ui-align/references/cards/dynamics.md +27 -0
  90. package/i18n/skills/a2h-batch-ui-align/references/cards/geometry.md +80 -0
  91. package/i18n/skills/a2h-batch-ui-align/references/cards/interaction.md +22 -0
  92. package/i18n/skills/a2h-batch-ui-align/references/cards/resources.md +87 -0
  93. package/i18n/skills/a2h-batch-ui-align/references/cards/state-v1.md +29 -0
  94. package/i18n/skills/a2h-batch-ui-align/references/cards/state.md +14 -0
  95. package/i18n/skills/a2h-batch-ui-align/references/cards/widgets.md +57 -0
  96. package/i18n/skills/a2h-batch-ui-align/references/cards/window.md +29 -0
  97. package/i18n/skills/a2h-batch-ui-align/references/checker-rules.md +705 -0
  98. package/i18n/skills/a2h-batch-ui-align/references/conversion-procedure.md +417 -0
  99. package/i18n/skills/a2h-batch-ui-align/references/incremental-scope.md +139 -0
  100. package/i18n/skills/a2h-batch-ui-align/references/lottie-integration.md +43 -0
  101. package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +2549 -0
  102. package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +560 -0
  103. package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +148 -0
  104. package/i18n/skills/a2h-batch-ui-align/references/state-mgmt/_decorator-quickref.md +220 -0
  105. package/i18n/skills/a2h-batch-ui-align/references/state-mgmt/_paradigm-selection.md +28 -0
  106. package/i18n/skills/a2h-batch-ui-align/references/step3-capture.md +216 -0
  107. package/i18n/skills/a2h-batch-ui-align/references/step4-prepare.md +203 -0
  108. package/i18n/skills/a2h-batch-ui-align/references/step5-convert.md +210 -0
  109. package/i18n/skills/a2h-batch-ui-align/scripts/android_parse_fast.ts +2005 -0
  110. package/i18n/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +1748 -0
  111. package/i18n/skills/a2h-batch-ui-align/scripts/databinding_analyzer_design.md +79 -0
  112. package/i18n/skills/a2h-batch-ui-align/scripts/detect_paradigm.mjs +245 -0
  113. package/i18n/skills/a2h-batch-ui-align/scripts/draw_coverage.mjs +264 -0
  114. package/i18n/skills/a2h-batch-ui-align/scripts/export_ui_info.mjs +1787 -0
  115. package/i18n/skills/a2h-batch-ui-align/scripts/gen_rule_docs.mjs +100 -0
  116. package/i18n/skills/a2h-batch-ui-align/scripts/generate_pages_json.mjs +612 -0
  117. package/i18n/skills/a2h-batch-ui-align/scripts/group_pack.mjs +1836 -0
  118. package/i18n/skills/a2h-batch-ui-align/scripts/image_probe.mjs +405 -0
  119. package/i18n/skills/a2h-batch-ui-align/scripts/measure_pack.ts +1406 -0
  120. package/i18n/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +1226 -0
  121. package/i18n/skills/a2h-batch-ui-align/scripts/shell_contract.mjs +1220 -0
  122. package/i18n/skills/a2h-batch-ui-align/scripts/state_doc.mjs +412 -0
  123. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/core/cli.ts +134 -0
  124. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/core/i18n.ts +18 -0
  125. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/main.ts +173 -0
  126. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/a11y.ts +629 -0
  127. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/android_immersive.ts +125 -0
  128. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/attr_chain.ts +67 -0
  129. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/block_comment_break.ts +64 -0
  130. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/blur_mirrored.ts +134 -0
  131. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/builder_call_sites.ts +242 -0
  132. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/builder_invokes_callback.ts +136 -0
  133. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/canvas.ts +255 -0
  134. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/color_string.ts +109 -0
  135. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/column_shrink.ts +154 -0
  136. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/constant_coordinate.ts +39 -0
  137. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/container_align.ts +140 -0
  138. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/entry_root_builtin.ts +69 -0
  139. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/entry_route.ts +114 -0
  140. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/fixed_size_safe_area.ts +103 -0
  141. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/format_string.ts +157 -0
  142. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/framework_dialog.ts +110 -0
  143. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/framework_picker.ts +115 -0
  144. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/layout_placement.ts +551 -0
  145. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/media_content.ts +138 -0
  146. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +374 -0
  147. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/offset_in_scroll.ts +163 -0
  148. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/orphan_component.ts +119 -0
  149. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/padding_in_size.ts +119 -0
  150. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/page_reachability.ts +94 -0
  151. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/path_commands_vp.ts +50 -0
  152. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/percent_height_in_scroll.ts +80 -0
  153. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/popup_menu.ts +137 -0
  154. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/r_template_string.ts +37 -0
  155. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/request_permission.ts +98 -0
  156. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/resource_as_string.ts +68 -0
  157. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/root_weight.ts +97 -0
  158. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/safe_area_clipping.ts +168 -0
  159. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/scroll_align.ts +75 -0
  160. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/scroll_delta.ts +178 -0
  161. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/sdk_api.ts +195 -0
  162. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/shared_chrome.ts +73 -0
  163. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/sheet_blur.ts +95 -0
  164. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/shell_content.ts +198 -0
  165. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/stack_occluding.ts +118 -0
  166. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/state_decorators.ts +73 -0
  167. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/state_name_shadows.ts +93 -0
  168. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/string_quote_leak.ts +73 -0
  169. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/surface_stroke.ts +50 -0
  170. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/theme_color.ts +123 -0
  171. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/track_getter.ts +132 -0
  172. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/wide_constant_width.ts +53 -0
  173. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/window_mode.ts +67 -0
  174. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_a11y.test.mjs +598 -0
  175. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_blur.test.mjs +217 -0
  176. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_builder_calls.test.mjs +323 -0
  177. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_fidelity.test.mjs +507 -0
  178. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_layout_placement.test.mjs +427 -0
  179. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_occlusion_offset_format.test.mjs +372 -0
  180. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_review_fixes.test.mjs +298 -0
  181. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_rules.test.mjs +365 -0
  182. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_scroll_padding_raster.test.mjs +262 -0
  183. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_weight_color.test.mjs +473 -0
  184. package/i18n/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set.test.mjs +560 -0
  185. package/i18n/skills/a2h-batch-ui-align/scripts/tests/draw_coverage.test.mjs +245 -0
  186. package/i18n/skills/a2h-batch-ui-align/scripts/tests/export_ui_info.test.mjs +742 -0
  187. package/i18n/skills/a2h-batch-ui-align/scripts/tests/generate_pages_json.test.mjs +123 -0
  188. package/i18n/skills/a2h-batch-ui-align/scripts/tests/group_pack.test.mjs +363 -0
  189. package/i18n/skills/a2h-batch-ui-align/scripts/tests/image_probe.test.mjs +243 -0
  190. package/i18n/skills/a2h-batch-ui-align/scripts/tests/measure_pack.test.mjs +324 -0
  191. package/i18n/skills/a2h-batch-ui-align/scripts/tests/occlusion.test.mjs +102 -0
  192. package/i18n/skills/a2h-batch-ui-align/scripts/tests/phase5_check.test.mjs +325 -0
  193. package/i18n/skills/a2h-batch-ui-align/scripts/tests/skill_doc_contract.test.mjs +48 -0
  194. package/i18n/skills/a2h-batch-ui-align/scripts/tests/state_doc.test.mjs +387 -0
  195. package/i18n/skills/a2h-batch-ui-align/scripts/tests/static_check_registry.test.mjs +122 -0
  196. package/i18n/skills/a2h-batch-ui-align/scripts/tests/text_color_diff.test.mjs +250 -0
  197. package/i18n/skills/a2h-batch-ui-align/scripts/text_color_diff.mjs +470 -0
  198. package/i18n/skills/a2h-coldstart-smoke-gate/SKILL.md +59 -0
  199. package/i18n/skills/a2h-dashboard-render/SKILL.md +73 -0
  200. package/i18n/skills/a2h-dashboard-render/references/artifact-contract.jsonc +117 -0
  201. package/i18n/skills/a2h-dashboard-render/references/artifact-registry-spec.md +67 -0
  202. package/i18n/skills/a2h-dashboard-render/references/dashboard-guide.md +91 -0
  203. package/i18n/skills/a2h-dashboard-render/references/dashboard.config.example.json +19 -0
  204. package/i18n/skills/a2h-dashboard-render/scripts/dashboard.mjs +3245 -0
  205. package/i18n/skills/a2h-dashboard-render/scripts/device_capture.mjs +2048 -0
  206. package/i18n/skills/a2h-dashboard-render/test/fixtures/page_capture/expected.json +156 -0
  207. package/i18n/skills/a2h-dashboard-render/test/fixtures/page_capture/hmos.json +1 -0
  208. package/i18n/skills/a2h-dashboard-render/test/fixtures/page_capture/list.xml +1 -0
  209. package/i18n/skills/a2h-dashboard-render/test/test_artifact_contract.mjs +168 -0
  210. package/i18n/skills/a2h-dashboard-render/test/test_dashboard_architecture.mjs +118 -0
  211. package/i18n/skills/a2h-dashboard-render/test/test_dashboard_build.mjs +93 -0
  212. package/i18n/skills/a2h-dashboard-render/test/test_dashboard_i18n.mjs +154 -0
  213. package/i18n/skills/a2h-dashboard-render/test/test_dashboard_node.mjs +1369 -0
  214. package/i18n/skills/a2h-dashboard-render/test/test_dashboard_spec_pipeline.mjs +318 -0
  215. package/i18n/skills/a2h-dashboard-render/test/test_dashboard_ui_pipeline.mjs +81 -0
  216. package/i18n/skills/a2h-dashboard-render/test/test_device_capture_env.mjs +115 -0
  217. package/i18n/skills/a2h-dashboard-render/test/test_device_capture_policy.mjs +411 -0
  218. package/i18n/skills/a2h-dashboard-render/test/test_page_capture.mjs +147 -0
  219. package/i18n/skills/a2h-dashboard-render/test/test_usage_readers.mjs +512 -0
  220. package/i18n/skills/a2h-fix-build-errors/SKILL.md +304 -0
  221. package/i18n/skills/a2h-fix-build-errors/references/arkts-strict-patterns.md +219 -0
  222. package/i18n/skills/a2h-fix-build-errors/references/rdb-entity-pattern.md +131 -0
  223. package/i18n/skills/a2h-module-semantic-docs/SKILL.md +227 -0
  224. package/i18n/skills/a2h-module-semantic-docs/test/golden/module_structure.json +187 -0
  225. package/i18n/skills/a2h-module-semantic-docs/test/golden/module_understanding.json +351 -0
  226. package/i18n/skills/a2h-module-semantic-docs/test/golden/module_update_plan.json +495 -0
  227. package/i18n/skills/a2h-module-semantic-docs/test/golden/project_directory_structure.json +157 -0
  228. package/i18n/skills/a2h-module-semantic-docs/test/test_scan_and_commit.mjs +388 -0
  229. package/i18n/skills/a2h-page-specgen/SKILL.md +136 -0
  230. package/i18n/skills/a2h-page-specgen/references/body-language.md +177 -0
  231. package/i18n/skills/a2h-page-specgen/references/gates.md +262 -0
  232. package/i18n/skills/a2h-page-specgen/references/page-inventory.md +173 -0
  233. package/i18n/skills/a2h-page-specgen/references/spec-template.md +207 -0
  234. package/i18n/skills/a2h-page-specgen/scripts/facts-build.mjs +1504 -0
  235. package/i18n/skills/a2h-page-specgen/scripts/footprint.mjs +1528 -0
  236. package/i18n/skills/a2h-page-specgen/scripts/gate.mjs +576 -0
  237. package/i18n/skills/a2h-page-specgen/scripts/interactions.mjs +138 -0
  238. package/i18n/skills/a2h-page-specgen/scripts/lib/contracts.mjs +262 -0
  239. package/i18n/skills/a2h-page-specgen/scripts/lib/hg.mjs +176 -0
  240. package/i18n/skills/a2h-page-specgen/scripts/lib/prose.mjs +248 -0
  241. package/i18n/skills/a2h-page-specgen/scripts/lib/reach.mjs +53 -0
  242. package/i18n/skills/a2h-page-specgen/scripts/prepare.mjs +506 -0
  243. package/i18n/skills/a2h-page-specgen/scripts/render.mjs +299 -0
  244. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/acceptance.mjs +616 -0
  245. package/i18n/skills/a2h-page-specgen/scripts/test/contracts.test.mjs +234 -0
  246. package/i18n/skills/a2h-page-specgen/scripts/test/facts.test.mjs +1166 -0
  247. package/i18n/skills/a2h-page-specgen/scripts/test/finalize.test.mjs +74 -0
  248. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/facts/i18n/zh.js.txt +8 -0
  249. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-b+zh+Hans/strings.xml +7 -0
  250. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-zh/strings.xml +8 -0
  251. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/utg/click_paths.json +28 -0
  252. package/i18n/skills/a2h-page-specgen/scripts/test/footprint-resolve.test.mjs +758 -0
  253. package/i18n/skills/a2h-page-specgen/scripts/test/fsx.test.mjs +32 -0
  254. package/i18n/skills/a2h-page-specgen/scripts/test/gate-partial.test.mjs +54 -0
  255. package/i18n/skills/a2h-page-specgen/scripts/test/gate.test.mjs +271 -0
  256. package/i18n/skills/a2h-page-specgen/scripts/test/helpers.mjs +54 -0
  257. package/i18n/skills/a2h-page-specgen/scripts/test/hg.test.mjs +171 -0
  258. package/i18n/skills/a2h-page-specgen/scripts/test/integration.test.mjs +301 -0
  259. package/i18n/skills/a2h-page-specgen/scripts/test/interactions.test.mjs +83 -0
  260. package/i18n/skills/a2h-page-specgen/scripts/test/inventory.test.mjs +139 -0
  261. package/i18n/skills/a2h-page-specgen/scripts/test/keys.test.mjs +774 -0
  262. package/i18n/skills/a2h-page-specgen/scripts/test/plan-build.test.mjs +1011 -0
  263. package/i18n/skills/a2h-page-specgen/scripts/test/prompt-tpl.test.mjs +77 -0
  264. package/i18n/skills/a2h-page-specgen/scripts/test/prose.test.mjs +419 -0
  265. package/i18n/skills/a2h-page-specgen/scripts/test/reach.test.mjs +93 -0
  266. package/i18n/skills/a2h-page-specgen/scripts/test/recovery-e2e.test.mjs +323 -0
  267. package/i18n/skills/a2h-page-specgen/scripts/test/recovery.test.mjs +546 -0
  268. package/i18n/skills/a2h-page-specgen/scripts/test/render.test.mjs +511 -0
  269. package/i18n/skills/a2h-page-specgen/scripts/test/submit.test.mjs +701 -0
  270. package/i18n/skills/a2h-page-specgen/scripts/test/utg-io.test.mjs +90 -0
  271. package/i18n/skills/a2h-page-specgen/scripts/test/waker-process.test.mjs +1765 -0
  272. package/i18n/skills/a2h-resource-convert/SKILL.md +367 -0
  273. package/i18n/skills/a2h-resource-convert/references/code-vector-icon-rules.md +335 -0
  274. package/i18n/skills/a2h-resource-convert/references/incremental-page-migration.md +251 -0
  275. package/i18n/skills/a2h-resource-convert/references/lottie-conversion-rules.md +219 -0
  276. package/i18n/skills/a2h-resource-convert/references/resource-mapping-rules.md +493 -0
  277. package/i18n/skills/a2h-resource-convert/references/step4-resource-types.md +249 -0
  278. package/i18n/skills/a2h-resource-convert/references/step7-report-template.md +217 -0
  279. package/i18n/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +2532 -0
  280. package/i18n/skills/a2h-resource-convert/scripts/tests/docs_only_i18n.test.mjs +44 -0
  281. package/i18n/skills/a2h-spec-design-pipeline/SKILL.md +278 -0
  282. package/i18n/skills/a2h-spec-design-pipeline/references/coding-loop.md +260 -0
  283. package/i18n/skills/a2h-spec-design-pipeline/references/merge-queue.md +163 -0
  284. package/i18n/skills/a2h-spec-design-pipeline/references/scripts.md +44 -0
  285. package/i18n/skills/a2h-spec-design-pipeline/references/specs.example.json +19 -0
  286. package/i18n/skills/a2h-spec-design-pipeline/scripts/plan_groups.ts +589 -0
  287. package/i18n/skills/a2h-spec-design-pipeline/scripts/test_plan_groups.ts +506 -0
  288. package/i18n/skills/a2h-spec-generate/SKILL.md +375 -0
  289. package/i18n/skills/a2h-spec-generate/references/batch-mode.md +215 -0
  290. package/i18n/skills/a2h-spec-generate/references/delete-blast-radius.md +3 -0
  291. package/i18n/skills/a2h-spec-generate/references/dispatch-watchdog.md +150 -0
  292. package/i18n/skills/a2h-spec-generate/references/fusion-task-contract.md +184 -0
  293. package/i18n/skills/a2h-spec-generate/references/input-formats.md +27 -0
  294. package/i18n/skills/a2h-spec-generate/references/library-evidence.md +3 -0
  295. package/i18n/skills/a2h-spec-generate/references/method-discipline.md +64 -0
  296. package/i18n/skills/a2h-spec-generate/references/optional-gates.json +45 -0
  297. package/i18n/skills/a2h-spec-generate/references/recall-guide.md +84 -0
  298. package/i18n/skills/a2h-spec-generate/references/recall-terse.md +3 -0
  299. package/i18n/skills/a2h-spec-generate/references/recall-uniapp.md +10 -0
  300. package/i18n/skills/a2h-spec-generate/references/requirement-scope.md +122 -0
  301. package/i18n/skills/a2h-spec-generate/references/review-checklist.md +22 -0
  302. package/i18n/skills/a2h-spec-generate/references/spec-sample-complex.md +80 -0
  303. package/i18n/skills/a2h-spec-generate/references/spec-sample-transfer.md +43 -0
  304. package/i18n/skills/a2h-spec-generate/references/spec-samples.md +65 -0
  305. package/i18n/skills/a2h-spec-generate/references/specs.schema.json +85 -0
  306. package/i18n/skills/a2h-spec-generate/references/synthesis-rules.md +145 -0
  307. package/i18n/skills/a2h-spec-generate/references/transfer-file.md +5 -0
  308. package/i18n/skills/a2h-spec-generate/references/transfer-socket.md +5 -0
  309. package/i18n/skills/a2h-spec-generate/references/worker-rules.md +129 -0
  310. package/i18n/skills/a2h-spec-generate/scripts/check-fused-spec.mjs +702 -0
  311. package/i18n/skills/a2h-spec-generate/scripts/check_spec.ts +515 -0
  312. package/i18n/skills/a2h-spec-generate/scripts/collect-specs.mjs +727 -0
  313. package/i18n/skills/a2h-spec-generate/scripts/feature-stem.mjs +151 -0
  314. package/i18n/skills/a2h-spec-generate/scripts/parse_requirements.ts +515 -0
  315. package/i18n/skills/a2h-spec-generate/scripts/prepare-facts.mjs +313 -0
  316. package/i18n/skills/a2h-spec-generate/scripts/publish-specs.mjs +354 -0
  317. package/i18n/skills/a2h-spec-generate/scripts/regroup-by-page.mjs +669 -0
  318. package/i18n/skills/a2h-spec-generate/scripts/render-tasks.mjs +385 -0
  319. package/i18n/skills/a2h-spec-generate/scripts/report.mjs +136 -0
  320. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/build.ts +2217 -0
  321. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/component-variants.ts +845 -0
  322. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/policy.ts +572 -0
  323. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/traceability.ts +580 -0
  324. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/analysis/req-model/build.ts +1265 -0
  325. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/area-facts.ts +1057 -0
  326. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/behavior-seed.ts +565 -0
  327. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/library-evidence.ts +544 -0
  328. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/navigation-guard.ts +363 -0
  329. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/schema.ts +317 -0
  330. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/selfcheck.ts +707 -0
  331. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/spec-bindings.ts +436 -0
  332. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/task-contract.ts +608 -0
  333. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/contracts.ts +650 -0
  334. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/task-contract.ts +178 -0
  335. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/tree-sitter-adapter.ts +923 -0
  336. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/model/finalize.ts +912 -0
  337. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/model/task.ts +279 -0
  338. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/requirement-scope.ts +163 -0
  339. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/source-index/homegraph.ts +1039 -0
  340. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/validation/req-text.ts +256 -0
  341. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fixtures/fusion-run.ts +243 -0
  342. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-area-facts.test.ts +576 -0
  343. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-detectors.test.ts +176 -0
  344. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-e2e.test.ts +103 -0
  345. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-schema.test.ts +111 -0
  346. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-selfcheck.test.ts +307 -0
  347. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-contract.test.ts +340 -0
  348. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-finalize.test.ts +1857 -0
  349. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-navigation-guard.test.ts +262 -0
  350. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-prepare.test.ts +722 -0
  351. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-scope.test.ts +339 -0
  352. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-selfcheck.test.ts +1253 -0
  353. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-spec.test.ts +608 -0
  354. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/model-scope.test.ts +411 -0
  355. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/model-task-contract.test.ts +300 -0
  356. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/model-v4.test.ts +1061 -0
  357. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/uniapp-scanner.test.ts +159 -0
  358. package/i18n/skills/a2h-spec-generate/template/REQ.txt +22 -0
  359. package/i18n/skills/a2h-spec-generate/template/REQ.xlsx +0 -0
  360. package/i18n/skills/a2h-spec-generate/test/check-fused-spec.test.mjs +847 -0
  361. package/i18n/skills/a2h-spec-generate/test/check-spec.test.ts +415 -0
  362. package/i18n/skills/a2h-spec-generate/test/collect-specs.test.mjs +808 -0
  363. package/i18n/skills/a2h-spec-generate/test/feature-stem.test.mjs +157 -0
  364. package/i18n/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/components/MyCard.vue +9 -0
  365. package/i18n/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/feature/editor/index.vue +1 -0
  366. package/i18n/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/detail/index.vue +1 -0
  367. package/i18n/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/home/index.vue +33 -0
  368. package/i18n/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/settings/index.vue +1 -0
  369. package/i18n/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages.json +23 -0
  370. package/i18n/skills/a2h-spec-generate/test/inspect-uniapp.test.mjs +54 -0
  371. package/i18n/skills/a2h-spec-generate/test/prepare-facts.test.mjs +41 -0
  372. package/i18n/skills/a2h-spec-generate/test/publish-specs.test.mjs +295 -0
  373. package/i18n/skills/a2h-spec-generate/test/regroup-by-page.test.mjs +354 -0
  374. package/i18n/skills/a2h-spec-generate/test/render-tasks.test.mjs +596 -0
  375. package/i18n/skills/a2h-spec-generate/test/report.test.mjs +47 -0
  376. package/i18n/skills/a2h-utg-explorer/SKILL.md +120 -0
  377. package/i18n/skills/a2h-utg-explorer/references/architecture.md +279 -0
  378. package/i18n/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +918 -0
  379. package/i18n/skills/a2h-utg-explorer/scripts/final_utg.mjs +446 -0
  380. package/i18n/skills/a2h-utg-explorer/scripts/hint_check.mjs +147 -0
  381. package/i18n/skills/a2h-utg-explorer/scripts/hint_source.mjs +119 -0
  382. package/i18n/skills/a2h-utg-explorer/scripts/recover_b.mjs +550 -0
  383. package/i18n/skills/a2h-utg-explorer/scripts/recover_d.mjs +380 -0
  384. package/i18n/skills/a2h-utg-explorer/scripts/tests/attest.test.mjs +66 -0
  385. package/i18n/skills/a2h-utg-explorer/scripts/tests/compose_identity.test.mjs +302 -0
  386. package/i18n/skills/a2h-utg-explorer/scripts/tests/content_wait.test.mjs +207 -0
  387. package/i18n/skills/a2h-utg-explorer/scripts/tests/direct_launch.test.mjs +130 -0
  388. package/i18n/skills/a2h-utg-explorer/scripts/tests/final_utg.test.mjs +135 -0
  389. package/i18n/skills/a2h-utg-explorer/scripts/tests/generalization_fixes.test.mjs +252 -0
  390. package/i18n/skills/a2h-utg-explorer/scripts/tests/hint_check.test.mjs +129 -0
  391. package/i18n/skills/a2h-utg-explorer/scripts/tests/interruptions.test.mjs +492 -0
  392. package/i18n/skills/a2h-utg-explorer/scripts/tests/launch_bridge.test.mjs +199 -0
  393. package/i18n/skills/a2h-utg-explorer/scripts/tests/overflow_prefix.test.mjs +327 -0
  394. package/i18n/skills/a2h-utg-explorer/scripts/tests/overlay_identity.test.mjs +204 -0
  395. package/i18n/skills/a2h-utg-explorer/scripts/tests/page_identity_tiers.test.mjs +393 -0
  396. package/i18n/skills/a2h-utg-explorer/scripts/tests/pager_navigation.test.mjs +119 -0
  397. package/i18n/skills/a2h-utg-explorer/scripts/tests/panel_routes.test.mjs +208 -0
  398. package/i18n/skills/a2h-utg-explorer/scripts/tests/pipeline.test.mjs +240 -0
  399. package/i18n/skills/a2h-utg-explorer/scripts/tests/recover_b.test.mjs +173 -0
  400. package/i18n/skills/a2h-utg-explorer/scripts/tests/recover_d.test.mjs +280 -0
  401. package/i18n/skills/a2h-utg-explorer/scripts/tests/robustness_fixes.test.mjs +345 -0
  402. package/i18n/skills/a2h-utg-explorer/scripts/tests/runner_capabilities.test.mjs +194 -0
  403. package/i18n/skills/a2h-utg-explorer/scripts/tests/semantics.test.mjs +102 -0
  404. package/i18n/skills/a2h-utg-explorer/scripts/tests/state_ambiguity.test.mjs +92 -0
  405. package/i18n/skills/a2h-utg-explorer/scripts/tests/twin_opener.test.mjs +119 -0
  406. package/i18n/skills/a2h-utg-explorer/scripts/tests/variant_strings.test.mjs +63 -0
  407. package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +1412 -0
  408. package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +2037 -0
  409. package/i18n/skills/a2h-utg-static/SKILL.md +368 -0
  410. package/i18n/skills/a2h-utg-static/references/ui-elements-static-utg-schema.md +248 -0
  411. package/i18n/skills/a2h-utg-static/references/view-interactions.md +215 -0
  412. package/i18n/skills/a2h-utg-static/scripts/assemble.mjs +2120 -0
  413. package/i18n/skills/a2h-utg-static/scripts/audit.mjs +268 -0
  414. package/i18n/skills/a2h-utg-static/scripts/click_paths.mjs +609 -0
  415. package/i18n/skills/a2h-utg-static/scripts/compose_body_text.mjs +250 -0
  416. package/i18n/skills/a2h-utg-static/scripts/compose_titles.mjs +374 -0
  417. package/i18n/skills/a2h-utg-static/scripts/compose_widgets.mjs +498 -0
  418. package/i18n/skills/a2h-utg-static/scripts/fragment_nav.mjs +1137 -0
  419. package/i18n/skills/a2h-utg-static/scripts/hybrid_scope.mjs +660 -0
  420. package/i18n/skills/a2h-utg-static/scripts/interaction_sites.mjs +267 -0
  421. package/i18n/skills/a2h-utg-static/scripts/label_resolve.mjs +913 -0
  422. package/i18n/skills/a2h-utg-static/scripts/nl_hints.mjs +517 -0
  423. package/i18n/skills/a2h-utg-static/scripts/presenter_nav.mjs +490 -0
  424. package/i18n/skills/a2h-utg-static/scripts/static_prior.mjs +956 -0
  425. package/i18n/skills/a2h-utg-static/scripts/tests/regression_matrix.mjs +1261 -0
  426. package/i18n/skills/a2h-utg-static/scripts/tests/test_callee_string_default.mjs +30 -0
  427. package/i18n/skills/a2h-utg-static/scripts/tests/test_chrome_tokens.mjs +60 -0
  428. package/i18n/skills/a2h-utg-static/scripts/tests/test_commented_out_trigger.mjs +111 -0
  429. package/i18n/skills/a2h-utg-static/scripts/tests/test_compose_res_text.mjs +108 -0
  430. package/i18n/skills/a2h-utg-static/scripts/tests/test_compose_vm_nav.mjs +289 -0
  431. package/i18n/skills/a2h-utg-static/scripts/tests/test_disabled_guard.mjs +42 -0
  432. package/i18n/skills/a2h-utg-static/scripts/tests/test_drawer_panel_gesture.mjs +140 -0
  433. package/i18n/skills/a2h-utg-static/scripts/tests/test_fresh_branch_guard.mjs +49 -0
  434. package/i18n/skills/a2h-utg-static/scripts/tests/test_hint_language.mjs +136 -0
  435. package/i18n/skills/a2h-utg-static/scripts/tests/test_hybrid_bundle_attribution.mjs +74 -0
  436. package/i18n/skills/a2h-utg-static/scripts/tests/test_hybrid_bundled_pages.mjs +181 -0
  437. package/i18n/skills/a2h-utg-static/scripts/tests/test_hybrid_scope.mjs +293 -0
  438. package/i18n/skills/a2h-utg-static/scripts/tests/test_hybrid_title_renders.mjs +118 -0
  439. package/i18n/skills/a2h-utg-static/scripts/tests/test_label_accessor_forms.mjs +187 -0
  440. package/i18n/skills/a2h-utg-static/scripts/tests/test_label_source.mjs +70 -0
  441. package/i18n/skills/a2h-utg-static/scripts/tests/test_launch_intent_guard.mjs +67 -0
  442. package/i18n/skills/a2h-utg-static/scripts/tests/test_login_interceptor.mjs +368 -0
  443. package/i18n/skills/a2h-utg-static/scripts/tests/test_mode_and_cb_param.mjs +172 -0
  444. package/i18n/skills/a2h-utg-static/scripts/tests/test_module_strings.mjs +44 -0
  445. package/i18n/skills/a2h-utg-static/scripts/tests/test_nl_hint_grammar.mjs +42 -0
  446. package/i18n/skills/a2h-utg-static/scripts/tests/test_nl_hints_gate.mjs +85 -0
  447. package/i18n/skills/a2h-utg-static/scripts/tests/test_nl_hints_off_path.mjs +67 -0
  448. package/i18n/skills/a2h-utg-static/scripts/tests/test_non_gesture_step_flag.mjs +62 -0
  449. package/i18n/skills/a2h-utg-static/scripts/tests/test_preference_widgets.mjs +48 -0
  450. package/i18n/skills/a2h-utg-static/scripts/tests/test_read_text_crlf.mjs +41 -0
  451. package/i18n/skills/a2h-utg-static/scripts/tests/test_sealed_dialog_state.mjs +148 -0
  452. package/i18n/skills/a2h-utg-static/scripts/tests/test_state_specific_hop.mjs +130 -0
  453. package/i18n/skills/a2h-utg-static/scripts/tests/test_synthetic_label_identity.mjs +51 -0
  454. package/i18n/skills/a2h-utg-static/scripts/tests/test_template_title.mjs +61 -0
  455. package/i18n/skills/a2h-utg-static/scripts/tests/test_ui_elements_flow_filter.mjs +110 -0
  456. package/i18n/skills/a2h-utg-static/scripts/tests/test_uniapp_data_table.mjs +340 -0
  457. package/i18n/skills/a2h-utg-static/scripts/tests/test_uniapp_relative_url.mjs +125 -0
  458. package/i18n/skills/a2h-utg-static/scripts/tests/test_uniapp_source.mjs +231 -0
  459. package/i18n/skills/a2h-utg-static/scripts/tests/test_viewpage_nav.mjs +340 -0
  460. package/i18n/skills/a2h-utg-static/scripts/uniapp_nav.mjs +1351 -0
  461. package/i18n/skills/a2h-utg-static/scripts/uniapp_widgets.mjs +244 -0
  462. package/i18n/skills/a2h-utg-static/tools/convert_static_utg_to_ui_elements.ts +769 -0
  463. package/package.json +13 -160
  464. package/platforms/deveco/agents/code-reviewer.frontmatter.md +1 -1
  465. package/platforms/opencode/agents/code-reviewer.frontmatter.md +1 -1
  466. package/skills/a2h-app-migrate/SKILL.md +17 -6
  467. package/skills/a2h-app-migrate/references/config.example.json +1 -0
  468. package/skills/a2h-app-migrate/references/stage-map.md +3 -1
  469. package/skills/a2h-app-migrate/references/workflow.yaml +138 -47
  470. package/skills/a2h-app-migrate/scripts/check_spec_gen_done.mjs +1 -2
  471. package/skills/a2h-app-migrate/scripts/env_preflight.mjs +105 -39
  472. package/skills/a2h-app-migrate/scripts/human_review_gate.mjs +7 -8
  473. package/skills/a2h-app-migrate/scripts/ledger.mjs +17 -5
  474. package/skills/a2h-app-migrate/scripts/resume_plan.mjs +43 -7
  475. package/skills/a2h-app-migrate/scripts/run_dir.mjs +127 -41
  476. package/skills/a2h-app-migrate/scripts/spec_layout.mjs +2 -0
  477. package/skills/a2h-app-migrate/scripts/validate_workflow.mjs +38 -0
  478. package/skills/a2h-app-migrate/test/test_android_index.mjs +131 -0
  479. package/skills/a2h-app-migrate/test/test_apk_preflight.mjs +63 -0
  480. package/skills/a2h-app-migrate/test/test_arch_done.mjs +54 -0
  481. package/skills/a2h-app-migrate/test/test_build_fixer_contract.mjs +98 -0
  482. package/skills/a2h-app-migrate/test/test_config_example.mjs +42 -0
  483. package/skills/a2h-app-migrate/test/test_devecocli_docs_preflight.mjs +32 -0
  484. package/skills/a2h-app-migrate/test/test_ensure_utg_snapshot.mjs +147 -0
  485. package/skills/a2h-app-migrate/test/test_entry_guards.mjs +102 -0
  486. package/skills/a2h-app-migrate/test/test_env_requirements.mjs +698 -0
  487. package/skills/a2h-app-migrate/test/test_finalize.mjs +89 -0
  488. package/skills/a2h-app-migrate/test/test_gate_checkpoint.mjs +146 -0
  489. package/skills/a2h-app-migrate/test/test_hmos_fingerprint.mjs +68 -0
  490. package/skills/a2h-app-migrate/test/test_i18n_engine_mirror.mjs +51 -0
  491. package/skills/a2h-app-migrate/test/test_image_probe.mjs +120 -0
  492. package/skills/a2h-app-migrate/test/test_infer_android_root.mjs +91 -0
  493. package/skills/a2h-app-migrate/test/test_interaction.mjs +122 -0
  494. package/skills/a2h-app-migrate/test/test_json_io.mjs +32 -0
  495. package/skills/a2h-app-migrate/test/test_leaf_questions.mjs +111 -0
  496. package/skills/a2h-app-migrate/test/test_module_docs_done.mjs +53 -0
  497. package/skills/a2h-app-migrate/test/test_parse_args.mjs +69 -0
  498. package/skills/a2h-app-migrate/test/test_preflight_report.mjs +93 -0
  499. package/skills/a2h-app-migrate/test/test_resume_plan.mjs +219 -0
  500. package/skills/a2h-app-migrate/test/test_resume_summary.mjs +196 -0
  501. package/skills/a2h-app-migrate/test/test_reuse_static_utg.mjs +100 -0
  502. package/skills/a2h-app-migrate/test/test_run_dir.mjs +488 -0
  503. package/skills/a2h-app-migrate/test/test_skill_doc.mjs +144 -0
  504. package/skills/a2h-app-migrate/test/test_spec_engine_acceptance.mjs +94 -0
  505. package/skills/a2h-app-migrate/test/test_spec_engine_contract.mjs +147 -0
  506. package/skills/a2h-app-migrate/test/test_spec_gen_done.mjs +146 -0
  507. package/skills/a2h-app-migrate/test/test_spec_gen_gate.mjs +161 -0
  508. package/skills/a2h-app-migrate/test/test_spec_pipeline_done.mjs +344 -0
  509. package/skills/a2h-app-migrate/test/test_specs_json_preflight.mjs +76 -0
  510. package/skills/a2h-app-migrate/test/test_ui_batch_done.mjs +53 -0
  511. package/skills/a2h-app-migrate/test/test_ui_batch_gate.mjs +226 -0
  512. package/skills/a2h-app-migrate/test/test_uniapp_preflight.mjs +83 -0
  513. package/skills/a2h-app-migrate/test/test_user_facing_progress.mjs +43 -0
  514. package/skills/a2h-app-migrate/test/test_utg_dirs.mjs +41 -0
  515. package/skills/a2h-app-migrate/test/test_utg_static_done.mjs +178 -0
  516. package/skills/a2h-app-migrate/test/test_validate_races.mjs +50 -0
  517. package/skills/a2h-app-migrate/test/test_validate_workflow_bilingual.mjs +87 -0
  518. package/skills/a2h-arch-generate/SKILL.md +1 -1
  519. package/skills/a2h-arch-generate/references/database-schema-recovery.md +2 -2
  520. package/skills/a2h-arch-generate/references/harmony-project-inspection.md +8 -8
  521. package/skills/a2h-arch-generate/references/homegraph-workflow.md +15 -6
  522. package/skills/a2h-arch-generate/references/module-evidence-subagent.md +2 -2
  523. package/skills/a2h-arch-generate/references/source-baseline.md +2 -2
  524. package/skills/a2h-arch-generate/scripts/generate_source_baseline.mjs +35 -46
  525. package/skills/a2h-arch-generate/scripts/inspect_harmony_target.mjs +33 -40
  526. package/skills/a2h-arch-generate/scripts/module_create/generate.mjs +2 -3
  527. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/build.gradle +11 -0
  528. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/src/main/AndroidManifest.xml +12 -0
  529. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/src/main/java/com/example/notes/MainActivity.kt +8 -0
  530. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/src/main/java/com/example/notes/NotesStore.kt +17 -0
  531. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/build.gradle +3 -0
  532. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/settings.gradle +1 -0
  533. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/AppScope/app.json5 +8 -0
  534. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/build-profile.json5 +14 -0
  535. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/common/utils/build-profile.json5 +7 -0
  536. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/common/utils/oh-package.json5 +1 -0
  537. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/common/utils/src/main/ets/utils/Format.ets +3 -0
  538. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/home/build-profile.json5 +7 -0
  539. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/home/oh-package.json5 +1 -0
  540. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/home/src/main/ets/pages/Home.ets +3 -0
  541. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/sync/build-profile.json5 +7 -0
  542. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/sync/oh-package.json5 +1 -0
  543. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/sync/src/main/ets/engine/SyncEngine.ets +3 -0
  544. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/hvigorfile.ts +1 -0
  545. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/oh-package.json5 +1 -0
  546. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/products/app/build-profile.json5 +7 -0
  547. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/products/app/oh-package.json5 +9 -0
  548. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/products/app/src/main/ets/pages/Index.ets +7 -0
  549. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/App.vue +10 -0
  550. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/manifest.json +6 -0
  551. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/pages/index/index.vue +16 -0
  552. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/pages.json +5 -0
  553. package/skills/a2h-arch-generate/scripts/tests/e2e/run_e2e.mjs +548 -0
  554. package/skills/a2h-arch-generate/scripts/tests/run_tests.mjs +1260 -0
  555. package/skills/a2h-arch-generate/scripts/tests/test_cleanup.mjs +191 -0
  556. package/skills/a2h-arch-generate/scripts/tests/test_console_encoding.mjs +52 -0
  557. package/skills/a2h-arch-generate/scripts/tests/test_git_root.mjs +34 -0
  558. package/skills/a2h-arch-generate/scripts/tests/test_module_templates.mjs +70 -0
  559. package/skills/a2h-arch-generate/scripts/tests/test_router.mjs +138 -0
  560. package/skills/a2h-arch-generate/scripts/validate_architecture_docs.mjs +2 -5
  561. package/skills/a2h-arkts-logic-coder/SKILL.md +21 -2
  562. package/skills/a2h-arkts-logic-coder/references/ISSUES.md +1 -0
  563. package/skills/a2h-arkts-logic-coder/references/code-generation.md +62 -0
  564. package/skills/a2h-arkts-logic-coder/references/spec-design.md +4 -0
  565. package/skills/a2h-arkts-logic-coder/scripts/design/validate_spec_design_output.mjs +22 -25
  566. package/skills/a2h-arkts-logic-coder/scripts/state_doc.mjs +583 -0
  567. package/skills/a2h-arkts-logic-coder/test/golden/inspect_happy.json +20 -0
  568. package/skills/a2h-arkts-logic-coder/test/golden/move_design.md +18 -0
  569. package/skills/a2h-arkts-logic-coder/test/golden/move_design_crlf.md +18 -0
  570. package/skills/a2h-arkts-logic-coder/test/golden/move_spec.md +7 -0
  571. package/skills/a2h-arkts-logic-coder/test/golden/resolve_cases.json +36 -0
  572. package/skills/a2h-arkts-logic-coder/test/golden/validate_issue_file.md +12 -0
  573. package/skills/a2h-arkts-logic-coder/test/golden/validate_issues.json +57 -0
  574. package/skills/a2h-arkts-logic-coder/test/test_spec_design_scripts.mjs +547 -0
  575. package/skills/a2h-arkts-logic-coder/test/test_state_doc.mjs +352 -0
  576. package/skills/a2h-batch-ui-align/SKILL.md +6 -4
  577. package/skills/a2h-batch-ui-align/references/cards/geometry.md +1 -1
  578. package/skills/a2h-batch-ui-align/references/cards/resources.md +4 -0
  579. package/skills/a2h-batch-ui-align/references/cards/widgets.md +22 -3
  580. package/skills/a2h-batch-ui-align/references/checker-rules.md +66 -3
  581. package/skills/a2h-batch-ui-align/references/conversion-procedure.md +45 -8
  582. package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +7 -5
  583. package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +2 -2
  584. package/skills/a2h-batch-ui-align/references/step4-prepare.md +4 -2
  585. package/skills/a2h-batch-ui-align/references/step5-convert.md +7 -5
  586. package/skills/a2h-batch-ui-align/scripts/android_parse_fast.ts +6 -7
  587. package/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +84 -7
  588. package/skills/a2h-batch-ui-align/scripts/draw_coverage.mjs +264 -0
  589. package/skills/a2h-batch-ui-align/scripts/evidence_gate.mjs +229 -0
  590. package/skills/a2h-batch-ui-align/scripts/export_ui_info.mjs +1 -2
  591. package/skills/a2h-batch-ui-align/scripts/generate_pages_json.mjs +4 -5
  592. package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +88 -26
  593. package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +305 -12
  594. package/skills/a2h-batch-ui-align/scripts/image_probe.mjs +231 -54
  595. package/skills/a2h-batch-ui-align/scripts/measure_pack.ts +8 -9
  596. package/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +18 -5
  597. package/skills/a2h-batch-ui-align/scripts/shell_contract.mjs +103 -3
  598. package/skills/a2h-batch-ui-align/scripts/static_check/core/android.ts +231 -0
  599. package/skills/a2h-batch-ui-align/scripts/static_check/core/i18n.ts +1 -5
  600. package/skills/a2h-batch-ui-align/scripts/static_check/main.ts +14 -8
  601. package/skills/a2h-batch-ui-align/scripts/static_check/registry.ts +8 -0
  602. package/skills/a2h-batch-ui-align/scripts/static_check/rules/android_immersive.ts +3 -3
  603. package/skills/a2h-batch-ui-align/scripts/static_check/rules/blur_mirrored.ts +2 -2
  604. package/skills/a2h-batch-ui-align/scripts/static_check/rules/builder_invokes_callback.ts +84 -19
  605. package/skills/a2h-batch-ui-align/scripts/static_check/rules/color_string.ts +11 -4
  606. package/skills/a2h-batch-ui-align/scripts/static_check/rules/constant_coordinate.ts +2 -2
  607. package/skills/a2h-batch-ui-align/scripts/static_check/rules/framework_dialog.ts +110 -0
  608. package/skills/a2h-batch-ui-align/scripts/static_check/rules/framework_picker.ts +5 -5
  609. package/skills/a2h-batch-ui-align/scripts/static_check/rules/media_content.ts +2 -2
  610. package/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +66 -2
  611. package/skills/a2h-batch-ui-align/scripts/static_check/rules/padding_in_size.ts +119 -0
  612. package/skills/a2h-batch-ui-align/scripts/static_check/rules/popup_menu.ts +81 -8
  613. package/skills/a2h-batch-ui-align/scripts/static_check/rules/scroll_delta.ts +178 -0
  614. package/skills/a2h-batch-ui-align/scripts/static_check/rules/theme_color.ts +123 -0
  615. package/skills/a2h-batch-ui-align/scripts/static_check/rules/window_mode.ts +2 -3
  616. package/skills/a2h-batch-ui-align/scripts/static_check/scan_file.ts +6 -0
  617. package/skills/a2h-batch-ui-align/scripts/tests/agent_cli.test.mjs +217 -0
  618. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_a11y.test.mjs +598 -0
  619. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_align_tint.test.mjs +312 -0
  620. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_blur.test.mjs +217 -0
  621. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_builder_calls.test.mjs +323 -0
  622. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_canvas_pct.test.mjs +312 -0
  623. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_fidelity.test.mjs +507 -0
  624. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_layout_placement.test.mjs +427 -0
  625. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_occlusion_offset_format.test.mjs +372 -0
  626. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_review_fixes.test.mjs +298 -0
  627. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_rule_smoke.test.mjs +235 -0
  628. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_rules.test.mjs +365 -0
  629. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_scroll_padding_raster.test.mjs +262 -0
  630. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_scroll_safearea.test.mjs +742 -0
  631. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_shell.test.mjs +91 -0
  632. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_theme.test.mjs +86 -0
  633. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_weight_color.test.mjs +473 -0
  634. package/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set.test.mjs +567 -0
  635. package/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set_scope.test.mjs +290 -0
  636. package/skills/a2h-batch-ui-align/scripts/tests/color_utils_asset.test.mjs +74 -0
  637. package/skills/a2h-batch-ui-align/scripts/tests/detect_paradigm.test.mjs +260 -0
  638. package/skills/a2h-batch-ui-align/scripts/tests/draw_coverage.test.mjs +244 -0
  639. package/skills/a2h-batch-ui-align/scripts/tests/evidence_gate.test.mjs +420 -0
  640. package/skills/a2h-batch-ui-align/scripts/tests/export_scroll_states.test.mjs +31 -0
  641. package/skills/a2h-batch-ui-align/scripts/tests/export_ui_info.test.mjs +742 -0
  642. package/skills/a2h-batch-ui-align/scripts/tests/generate_pages_json.test.mjs +123 -0
  643. package/skills/a2h-batch-ui-align/scripts/tests/group_commit.test.mjs +126 -0
  644. package/skills/a2h-batch-ui-align/scripts/tests/group_pack.test.mjs +363 -0
  645. package/skills/a2h-batch-ui-align/scripts/tests/group_queue.test.mjs +1628 -0
  646. package/skills/a2h-batch-ui-align/scripts/tests/group_watch.test.mjs +215 -0
  647. package/skills/a2h-batch-ui-align/scripts/tests/harmony_index.test.mjs +95 -0
  648. package/skills/a2h-batch-ui-align/scripts/tests/host_env.test.mjs +115 -0
  649. package/skills/a2h-batch-ui-align/scripts/tests/image_probe.test.mjs +243 -0
  650. package/skills/a2h-batch-ui-align/scripts/tests/measure_pack.test.mjs +324 -0
  651. package/skills/a2h-batch-ui-align/scripts/tests/occlusion.test.mjs +102 -0
  652. package/skills/a2h-batch-ui-align/scripts/tests/phase5_check.test.mjs +325 -0
  653. package/skills/a2h-batch-ui-align/scripts/tests/shell_contract.test.mjs +297 -0
  654. package/skills/a2h-batch-ui-align/scripts/tests/skill_doc_contract.test.mjs +48 -0
  655. package/skills/a2h-batch-ui-align/scripts/tests/state_doc.test.mjs +387 -0
  656. package/skills/a2h-batch-ui-align/scripts/tests/static_check_registry.test.mjs +122 -0
  657. package/skills/a2h-batch-ui-align/scripts/tests/test_bfs_exit.ts +49 -0
  658. package/skills/a2h-batch-ui-align/scripts/tests/text_color_diff.test.mjs +250 -0
  659. package/skills/a2h-dashboard-render/scripts/dashboard.mjs +12 -14
  660. package/skills/a2h-dashboard-render/scripts/device_capture.mjs +29 -30
  661. package/skills/a2h-dashboard-render/test/fixtures/page_capture/broken.xml +1 -0
  662. package/skills/a2h-dashboard-render/test/fixtures/page_capture/expected.json +156 -0
  663. package/skills/a2h-dashboard-render/test/fixtures/page_capture/hmos.json +1 -0
  664. package/skills/a2h-dashboard-render/test/fixtures/page_capture/list.xml +1 -0
  665. package/skills/a2h-dashboard-render/test/fixtures/page_capture/nested_scroll.xml +1 -0
  666. package/skills/a2h-dashboard-render/test/test_artifact_contract.mjs +168 -0
  667. package/skills/a2h-dashboard-render/test/test_cli_check_registry.mjs +99 -0
  668. package/skills/a2h-dashboard-render/test/test_dashboard_architecture.mjs +118 -0
  669. package/skills/a2h-dashboard-render/test/test_dashboard_build.mjs +93 -0
  670. package/skills/a2h-dashboard-render/test/test_dashboard_i18n.mjs +203 -0
  671. package/skills/a2h-dashboard-render/test/test_dashboard_node.mjs +1369 -0
  672. package/skills/a2h-dashboard-render/test/test_dashboard_spec_pipeline.mjs +318 -0
  673. package/skills/a2h-dashboard-render/test/test_dashboard_ui_pipeline.mjs +81 -0
  674. package/skills/a2h-dashboard-render/test/test_device_capture_env.mjs +115 -0
  675. package/skills/a2h-dashboard-render/test/test_device_capture_policy.mjs +411 -0
  676. package/skills/a2h-dashboard-render/test/test_page_capture.mjs +147 -0
  677. package/skills/a2h-dashboard-render/test/test_usage_readers.mjs +512 -0
  678. package/skills/a2h-module-semantic-docs/test/golden/module_structure.json +187 -0
  679. package/skills/a2h-module-semantic-docs/test/golden/module_understanding.json +351 -0
  680. package/skills/a2h-module-semantic-docs/test/golden/module_update_plan.json +495 -0
  681. package/skills/a2h-module-semantic-docs/test/golden/project_directory_structure.json +157 -0
  682. package/skills/a2h-module-semantic-docs/test/test_scan_and_commit.mjs +388 -0
  683. package/skills/a2h-page-specgen/SKILL.md +136 -0
  684. package/skills/a2h-page-specgen/references/body-language.md +177 -0
  685. package/skills/a2h-page-specgen/references/evidence.md +70 -0
  686. package/skills/a2h-page-specgen/references/execution-model.md +255 -0
  687. package/skills/a2h-page-specgen/references/footprint-and-grouping.md +250 -0
  688. package/skills/a2h-page-specgen/references/gates.md +255 -0
  689. package/skills/a2h-page-specgen/references/page-inventory.md +173 -0
  690. package/skills/a2h-page-specgen/references/spec-template.md +207 -0
  691. package/skills/a2h-page-specgen/scripts/dispatch.mjs +209 -0
  692. package/skills/a2h-page-specgen/scripts/facts-build.mjs +1504 -0
  693. package/skills/a2h-page-specgen/scripts/finalize.mjs +422 -0
  694. package/skills/a2h-page-specgen/scripts/footprint.mjs +1528 -0
  695. package/skills/a2h-page-specgen/scripts/gate.mjs +558 -0
  696. package/skills/a2h-page-specgen/scripts/interactions.mjs +137 -0
  697. package/skills/a2h-page-specgen/scripts/inventory.mjs +269 -0
  698. package/skills/a2h-page-specgen/scripts/lib/contracts.mjs +255 -0
  699. package/skills/a2h-page-specgen/scripts/lib/deps-source.mjs +399 -0
  700. package/skills/a2h-page-specgen/scripts/lib/draft-store.mjs +137 -0
  701. package/skills/a2h-page-specgen/scripts/lib/footprint-roles.mjs +278 -0
  702. package/skills/a2h-page-specgen/scripts/lib/fsx.mjs +79 -0
  703. package/skills/a2h-page-specgen/scripts/lib/hg.mjs +175 -0
  704. package/skills/a2h-page-specgen/scripts/lib/ledger.mjs +355 -0
  705. package/skills/a2h-page-specgen/scripts/lib/prose.mjs +234 -0
  706. package/skills/a2h-page-specgen/scripts/lib/reach.mjs +53 -0
  707. package/skills/a2h-page-specgen/scripts/lib/source-text.mjs +391 -0
  708. package/skills/a2h-page-specgen/scripts/lib/symbols.mjs +125 -0
  709. package/skills/a2h-page-specgen/scripts/lib/utg-io.mjs +110 -0
  710. package/skills/a2h-page-specgen/scripts/lib/waker-event-store.mjs +658 -0
  711. package/skills/a2h-page-specgen/scripts/prepare.mjs +492 -0
  712. package/skills/a2h-page-specgen/scripts/render.mjs +317 -0
  713. package/skills/a2h-page-specgen/scripts/report.mjs +7 -0
  714. package/skills/a2h-page-specgen/scripts/submission.mjs +532 -0
  715. package/skills/a2h-page-specgen/scripts/submit.mjs +79 -0
  716. package/skills/a2h-page-specgen/scripts/test/acceptance/README.md +77 -0
  717. package/skills/a2h-page-specgen/scripts/test/acceptance/acceptance.mjs +590 -0
  718. package/skills/a2h-page-specgen/scripts/test/acceptance/cases.example.json +57 -0
  719. package/skills/a2h-page-specgen/scripts/test/contracts.test.mjs +207 -0
  720. package/skills/a2h-page-specgen/scripts/test/dispatch.test.mjs +258 -0
  721. package/skills/a2h-page-specgen/scripts/test/facts.test.mjs +1164 -0
  722. package/skills/a2h-page-specgen/scripts/test/finalize.test.mjs +74 -0
  723. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Api.kt +20 -0
  724. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/BothAnnotations.kt +28 -0
  725. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Cache.kt +7 -0
  726. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Comments.kt +26 -0
  727. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Mmkv.kt +7 -0
  728. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Models.kt +19 -0
  729. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Pair.kt +7 -0
  730. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Prefs.kt +9 -0
  731. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Room.kt +11 -0
  732. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Sample.kt +43 -0
  733. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Templates.kt +34 -0
  734. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Timeouts.kt +8 -0
  735. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/androidTest/Helper.kt +5 -0
  736. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/build.gradle.kts +16 -0
  737. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/i18n/en.js.txt +5 -0
  738. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/i18n/zh.js.txt +4 -0
  739. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/libs.versions.toml +14 -0
  740. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/package.json +10 -0
  741. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values/strings.xml +10 -0
  742. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-b+zh+Hans/strings.xml +4 -0
  743. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-land/strings.xml +5 -0
  744. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-night/strings.xml +5 -0
  745. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-v21/strings.xml +4 -0
  746. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-zh/strings.xml +4 -0
  747. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/test/Legacy.kt +4 -0
  748. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/weather.proto +11 -0
  749. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-container/src/AppPreferences.kt +13 -0
  750. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-container/src/SettingsViewModel.kt +16 -0
  751. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-dao/src/UserDao.kt +28 -0
  752. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-moko/i18n/src/commonMain/moko-resources/base/strings.xml +6 -0
  753. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-moko/i18n/src/commonMain/moko-resources/fil/strings.xml +6 -0
  754. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/res/values/arrays.xml +25 -0
  755. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/res/values/strings.xml +10 -0
  756. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/res/xml/prefs.xml +27 -0
  757. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/src/Api.java +19 -0
  758. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/src/Datastore.kt +12 -0
  759. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/src/Settings.java +13 -0
  760. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/src/forecast.js +14 -0
  761. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/src/store.js +14 -0
  762. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-receiver/src/BasePreferences.kt +13 -0
  763. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-receiver/src/Screen.kt +14 -0
  764. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-receiver/src/UiPreferences.kt +8 -0
  765. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-retrofit/src/AuthAPI.kt +26 -0
  766. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/AndroidManifest.xml +20 -0
  767. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/feature/auth/navigation/ScreenRoute.kt +8 -0
  768. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/pages.json +19 -0
  769. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/src/components/Widget.vue +11 -0
  770. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/src/pages/detail/detail.vue +14 -0
  771. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/src/pages/index/index.vue +24 -0
  772. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/src/store/userStore.js +11 -0
  773. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/src/uni_modules/uview-ui/components/u-thing.js +5 -0
  774. package/skills/a2h-page-specgen/scripts/test/fixtures/fp.mkdb.mjs +144 -0
  775. package/skills/a2h-page-specgen/scripts/test/fixtures/hg.mkdb.mjs +94 -0
  776. package/skills/a2h-page-specgen/scripts/test/fixtures/src/MainFragment.java +6 -0
  777. package/skills/a2h-page-specgen/scripts/test/fixtures/src/ManyListeners.java +12 -0
  778. package/skills/a2h-page-specgen/scripts/test/fixtures/src/PlainActivity.java +3 -0
  779. package/skills/a2h-page-specgen/scripts/test/fixtures/utg/click_paths.json +28 -0
  780. package/skills/a2h-page-specgen/scripts/test/fixtures/utg/fold-chain/utg.json +12 -0
  781. package/skills/a2h-page-specgen/scripts/test/fixtures/utg/utg.json +34 -0
  782. package/skills/a2h-page-specgen/scripts/test/footprint-resolve.test.mjs +758 -0
  783. package/skills/a2h-page-specgen/scripts/test/footprint-roles.test.mjs +172 -0
  784. package/skills/a2h-page-specgen/scripts/test/fsx.test.mjs +32 -0
  785. package/skills/a2h-page-specgen/scripts/test/gate-partial.test.mjs +54 -0
  786. package/skills/a2h-page-specgen/scripts/test/gate.test.mjs +222 -0
  787. package/skills/a2h-page-specgen/scripts/test/helpers.mjs +54 -0
  788. package/skills/a2h-page-specgen/scripts/test/hg.test.mjs +171 -0
  789. package/skills/a2h-page-specgen/scripts/test/integration.test.mjs +301 -0
  790. package/skills/a2h-page-specgen/scripts/test/interactions.test.mjs +45 -0
  791. package/skills/a2h-page-specgen/scripts/test/inventory.test.mjs +139 -0
  792. package/skills/a2h-page-specgen/scripts/test/keys.test.mjs +774 -0
  793. package/skills/a2h-page-specgen/scripts/test/ledger.test.mjs +464 -0
  794. package/skills/a2h-page-specgen/scripts/test/plan-build.test.mjs +1011 -0
  795. package/skills/a2h-page-specgen/scripts/test/prepare-index.test.mjs +120 -0
  796. package/skills/a2h-page-specgen/scripts/test/prompt-tpl.test.mjs +68 -0
  797. package/skills/a2h-page-specgen/scripts/test/prose.test.mjs +390 -0
  798. package/skills/a2h-page-specgen/scripts/test/protocol-docs.test.mjs +167 -0
  799. package/skills/a2h-page-specgen/scripts/test/reach.test.mjs +93 -0
  800. package/skills/a2h-page-specgen/scripts/test/recovery-e2e.test.mjs +323 -0
  801. package/skills/a2h-page-specgen/scripts/test/recovery.test.mjs +546 -0
  802. package/skills/a2h-page-specgen/scripts/test/render.test.mjs +503 -0
  803. package/skills/a2h-page-specgen/scripts/test/source-text.test.mjs +181 -0
  804. package/skills/a2h-page-specgen/scripts/test/submit.test.mjs +701 -0
  805. package/skills/a2h-page-specgen/scripts/test/utg-io.test.mjs +90 -0
  806. package/skills/a2h-page-specgen/scripts/test/waker-event-store.test.mjs +1365 -0
  807. package/skills/a2h-page-specgen/scripts/test/waker-process.test.mjs +1765 -0
  808. package/skills/a2h-page-specgen/scripts/test/waker.test.mjs +1979 -0
  809. package/skills/a2h-page-specgen/scripts/test/watchdog.test.mjs +313 -0
  810. package/skills/a2h-page-specgen/scripts/waker.mjs +1234 -0
  811. package/skills/a2h-page-specgen/scripts/watchdog.mjs +298 -0
  812. package/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +49 -51
  813. package/skills/a2h-resource-convert/scripts/tests/adaptive_icon.test.mjs +182 -0
  814. package/skills/a2h-resource-convert/scripts/tests/app_identity.test.mjs +206 -0
  815. package/skills/a2h-resource-convert/scripts/tests/docs_only_i18n.test.mjs +44 -0
  816. package/skills/a2h-spec-design-pipeline/SKILL.md +79 -78
  817. package/skills/a2h-spec-design-pipeline/references/coding-loop.md +51 -12
  818. package/skills/a2h-spec-design-pipeline/references/execution-model.md +24 -6
  819. package/skills/a2h-spec-design-pipeline/references/final-report-template.md +3 -2
  820. package/skills/a2h-spec-design-pipeline/references/initialization.md +15 -4
  821. package/skills/a2h-spec-design-pipeline/references/merge-queue.md +82 -41
  822. package/skills/a2h-spec-design-pipeline/references/resolver-prompt.md +61 -0
  823. package/skills/a2h-spec-design-pipeline/references/scripts.md +19 -10
  824. package/skills/a2h-spec-design-pipeline/references/shared-layer.md +267 -0
  825. package/skills/a2h-spec-design-pipeline/references/state-and-resume.md +61 -8
  826. package/skills/a2h-spec-design-pipeline/references/static-defect-gate.md +62 -13
  827. package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleMeta.json +8 -0
  828. package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleSet.json +8 -0
  829. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/http-extra-data-empty-string-cn.md +55 -0
  830. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/http-extra-data-empty-string-en.md +60 -0
  831. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/HttpExtraDataEmptyStringCheck.js +488 -0
  832. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/index.js +11 -0
  833. package/skills/a2h-spec-design-pipeline/rules/migration-rules/package.json +17 -0
  834. package/skills/a2h-spec-design-pipeline/scripts/branch_landed.ts +12 -38
  835. package/skills/a2h-spec-design-pipeline/scripts/dispatch/evidence.mjs +40 -5
  836. package/skills/a2h-spec-design-pipeline/scripts/dispatch/fold.mjs +18 -0
  837. package/skills/a2h-spec-design-pipeline/scripts/dispatch/landing.mjs +74 -0
  838. package/skills/a2h-spec-design-pipeline/scripts/dispatch/progress.mjs +1 -1
  839. package/skills/a2h-spec-design-pipeline/scripts/dispatch/wait.mjs +1 -1
  840. package/skills/a2h-spec-design-pipeline/scripts/dispatch/worktree.mjs +2 -2
  841. package/skills/a2h-spec-design-pipeline/scripts/dispatch.mjs +128 -5
  842. package/skills/a2h-spec-design-pipeline/scripts/ensure_wt_index.ts +98 -35
  843. package/skills/a2h-spec-design-pipeline/scripts/homecheck_scan.ts +218 -37
  844. package/skills/a2h-spec-design-pipeline/scripts/lib/shared_classes.ts +113 -0
  845. package/skills/a2h-spec-design-pipeline/scripts/lib/shared_docs.ts +202 -0
  846. package/skills/a2h-spec-design-pipeline/scripts/lib/wiring.ts +58 -0
  847. package/skills/a2h-spec-design-pipeline/scripts/plan_groups.ts +6 -7
  848. package/skills/a2h-spec-design-pipeline/scripts/resolve_wiring.ts +3 -0
  849. package/skills/a2h-spec-design-pipeline/scripts/resolver_prompt.ts +348 -0
  850. package/skills/a2h-spec-design-pipeline/scripts/scan_shared.ts +642 -0
  851. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_commands.mjs +15 -5
  852. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_e2e.mjs +7 -2
  853. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_evidence.mjs +104 -1
  854. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_fold.mjs +24 -0
  855. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_landing.mjs +394 -0
  856. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_progress.mjs +24 -1
  857. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_wait.mjs +14 -0
  858. package/skills/a2h-spec-design-pipeline/scripts/test_ensure_wt_index.ts +163 -5
  859. package/skills/a2h-spec-design-pipeline/scripts/test_homecheck_scan.ts +15 -7
  860. package/skills/a2h-spec-design-pipeline/scripts/test_resolve_wiring.ts +14 -0
  861. package/skills/a2h-spec-design-pipeline/scripts/test_resolver_prompt.ts +350 -0
  862. package/skills/a2h-spec-design-pipeline/scripts/test_scan_shared.ts +996 -0
  863. package/skills/a2h-spec-design-pipeline/scripts/test_shared_classes.ts +80 -0
  864. package/skills/a2h-spec-design-pipeline/scripts/test_shared_docs.ts +205 -0
  865. package/skills/a2h-spec-design-pipeline/scripts/test_shared_layer_docs.ts +121 -0
  866. package/skills/a2h-spec-design-pipeline/scripts/test_shared_layer_e2e.ts +85 -0
  867. package/skills/a2h-spec-design-pipeline/scripts/test_validate_shared_manifest.ts +720 -0
  868. package/skills/a2h-spec-design-pipeline/scripts/test_wiring.ts +40 -0
  869. package/skills/a2h-spec-design-pipeline/scripts/validate_shared_manifest.ts +566 -0
  870. package/skills/a2h-spec-generate/SKILL.md +87 -21
  871. package/skills/a2h-spec-generate/references/batch-mode.md +78 -17
  872. package/skills/a2h-spec-generate/references/dispatch-watchdog.md +150 -0
  873. package/skills/a2h-spec-generate/references/fusion-task-contract.md +7 -0
  874. package/skills/a2h-spec-generate/references/review-checklist.md +1 -0
  875. package/skills/a2h-spec-generate/references/synthesis-rules.md +4 -2
  876. package/skills/a2h-spec-generate/references/worker-rules.md +6 -3
  877. package/skills/a2h-spec-generate/scripts/check-fused-spec.mjs +4 -5
  878. package/skills/a2h-spec-generate/scripts/check_spec.ts +145 -14
  879. package/skills/a2h-spec-generate/scripts/collect-specs.mjs +261 -19
  880. package/skills/a2h-spec-generate/scripts/dispatch-watch.mjs +1168 -0
  881. package/skills/a2h-spec-generate/scripts/feature-stem.mjs +1 -2
  882. package/skills/a2h-spec-generate/scripts/publish-specs.mjs +1 -2
  883. package/skills/a2h-spec-generate/scripts/regroup-by-page.mjs +1 -2
  884. package/skills/a2h-spec-generate/scripts/render-tasks.mjs +25 -46
  885. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/build.ts +26 -27
  886. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/component-variants.ts +3 -6
  887. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/policy.ts +31 -32
  888. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/traceability.ts +2 -3
  889. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/req-model/build.ts +15 -26
  890. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/area-facts.ts +102 -81
  891. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/behavior-seed.ts +39 -19
  892. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/library-evidence.ts +12 -13
  893. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/navigation-guard.ts +363 -0
  894. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/task-contract.ts +35 -196
  895. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/contracts.ts +3 -1
  896. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/task-contract.ts +22 -96
  897. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/tree-sitter-adapter.ts +3 -4
  898. package/skills/a2h-spec-generate/scripts/reqgen/src/model/contracts.ts +1 -1
  899. package/skills/a2h-spec-generate/scripts/reqgen/src/model/finalize.ts +74 -7
  900. package/skills/a2h-spec-generate/scripts/reqgen/src/model/prepare.ts +51 -7
  901. package/skills/a2h-spec-generate/scripts/reqgen/src/model/task.ts +42 -111
  902. package/skills/a2h-spec-generate/scripts/reqgen/src/requirement-scope.ts +1 -20
  903. package/skills/a2h-spec-generate/scripts/reqgen/src/source-index/homegraph.ts +1 -2
  904. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/req-text.ts +3 -4
  905. package/skills/a2h-spec-generate/scripts/reqgen/test/control-fact-join.test.ts +50 -0
  906. package/skills/a2h-spec-generate/scripts/reqgen/test/control-name-uniapp.test.ts +75 -0
  907. package/skills/a2h-spec-generate/scripts/reqgen/test/cross-area-anchor.test.ts +256 -0
  908. package/skills/a2h-spec-generate/scripts/reqgen/test/fixtures/fusion-run.ts +243 -0
  909. package/skills/a2h-spec-generate/scripts/reqgen/test/fixtures/zip.ts +63 -0
  910. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-area-facts.test.ts +650 -0
  911. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-detectors.test.ts +176 -0
  912. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-e2e.test.ts +103 -0
  913. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-schema.test.ts +111 -0
  914. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-seed.test.ts +195 -0
  915. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-selfcheck.test.ts +307 -0
  916. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-contract.test.ts +347 -0
  917. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-finalize.test.ts +1948 -0
  918. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-library-evidence.test.ts +239 -0
  919. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-navigation-guard.test.ts +277 -0
  920. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-prepare.test.ts +844 -0
  921. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-scope.test.ts +339 -0
  922. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-selfcheck.test.ts +1253 -0
  923. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-spec.test.ts +608 -0
  924. package/skills/a2h-spec-generate/scripts/reqgen/test/model-cli-blockers.test.ts +117 -0
  925. package/skills/a2h-spec-generate/scripts/reqgen/test/model-scope.test.ts +411 -0
  926. package/skills/a2h-spec-generate/scripts/reqgen/test/model-seeds.test.ts +175 -0
  927. package/skills/a2h-spec-generate/scripts/reqgen/test/model-task-contract.test.ts +300 -0
  928. package/skills/a2h-spec-generate/scripts/reqgen/test/model-v4.test.ts +1061 -0
  929. package/skills/a2h-spec-generate/scripts/reqgen/test/specgen-completeness.test.ts +286 -0
  930. package/skills/a2h-spec-generate/scripts/reqgen/test/stagem-stored-path.test.ts +25 -0
  931. package/skills/a2h-spec-generate/scripts/reqgen/test/uniapp-scanner.test.ts +159 -0
  932. package/skills/a2h-spec-generate/scripts/reqgen/test/zip.test.ts +61 -0
  933. package/skills/a2h-spec-generate/test/check-fused-spec.test.mjs +879 -0
  934. package/skills/a2h-spec-generate/test/check-spec.test.ts +430 -0
  935. package/skills/a2h-spec-generate/test/collect-specs.test.mjs +811 -0
  936. package/skills/a2h-spec-generate/test/detect-project.test.mjs +37 -0
  937. package/skills/a2h-spec-generate/test/dispatch-watch.test.mjs +606 -0
  938. package/skills/a2h-spec-generate/test/ensure-index.test.mjs +230 -0
  939. package/skills/a2h-spec-generate/test/feature-stem.test.mjs +157 -0
  940. package/skills/a2h-spec-generate/test/fixtures/android/app/src/main/AndroidManifest.xml +3 -0
  941. package/skills/a2h-spec-generate/test/fixtures/android/build.gradle +3 -0
  942. package/skills/a2h-spec-generate/test/fixtures/android/settings.gradle +3 -0
  943. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/package.json +9 -0
  944. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/App.vue +8 -0
  945. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/components/MyCard.vue +9 -0
  946. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/feature/editor/index.vue +1 -0
  947. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/main.ts +6 -0
  948. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/manifest.json +4 -0
  949. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/detail/index.vue +1 -0
  950. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/home/index.vue +33 -0
  951. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/settings/index.vue +1 -0
  952. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages.json +23 -0
  953. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/services/items.ts +3 -0
  954. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/tsconfig.json +8 -0
  955. package/skills/a2h-spec-generate/test/fixtures/unknown/README.txt +1 -0
  956. package/skills/a2h-spec-generate/test/inspect-uniapp.test.mjs +54 -0
  957. package/skills/a2h-spec-generate/test/prepare-facts.test.mjs +41 -0
  958. package/skills/a2h-spec-generate/test/publication-verdict.test.mjs +182 -0
  959. package/skills/a2h-spec-generate/test/publish-specs.test.mjs +295 -0
  960. package/skills/a2h-spec-generate/test/regroup-by-page.test.mjs +354 -0
  961. package/skills/a2h-spec-generate/test/render-tasks.test.mjs +596 -0
  962. package/skills/a2h-spec-generate/test/report.test.mjs +47 -0
  963. package/skills/a2h-utg-explorer/references/architecture.md +4 -0
  964. package/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +64 -80
  965. package/skills/a2h-utg-explorer/scripts/hint_check.mjs +1 -2
  966. package/skills/a2h-utg-explorer/scripts/recover.mjs +1 -1
  967. package/skills/a2h-utg-explorer/scripts/rejudge.mjs +5 -3
  968. package/skills/a2h-utg-explorer/scripts/tests/attest.test.mjs +66 -0
  969. package/skills/a2h-utg-explorer/scripts/tests/calendar_round_fixes.test.mjs +244 -0
  970. package/skills/a2h-utg-explorer/scripts/tests/chain.test.mjs +45 -0
  971. package/skills/a2h-utg-explorer/scripts/tests/compose_identity.test.mjs +302 -0
  972. package/skills/a2h-utg-explorer/scripts/tests/content_wait.test.mjs +207 -0
  973. package/skills/a2h-utg-explorer/scripts/tests/coverage_rules.test.mjs +104 -0
  974. package/skills/a2h-utg-explorer/scripts/tests/d_prereqs.test.mjs +231 -0
  975. package/skills/a2h-utg-explorer/scripts/tests/device_health.test.mjs +160 -0
  976. package/skills/a2h-utg-explorer/scripts/tests/device_locale_identity.test.mjs +77 -0
  977. package/skills/a2h-utg-explorer/scripts/tests/device_lock_retry.test.mjs +187 -0
  978. package/skills/a2h-utg-explorer/scripts/tests/direct_launch.test.mjs +130 -0
  979. package/skills/a2h-utg-explorer/scripts/tests/explorer_review_fixes.test.mjs +137 -0
  980. package/skills/a2h-utg-explorer/scripts/tests/final_utg.test.mjs +135 -0
  981. package/skills/a2h-utg-explorer/scripts/tests/first_round_phases.test.mjs +16 -0
  982. package/skills/a2h-utg-explorer/scripts/tests/fresh_state_plan.test.mjs +78 -0
  983. package/skills/a2h-utg-explorer/scripts/tests/generalization_fixes.test.mjs +252 -0
  984. package/skills/a2h-utg-explorer/scripts/tests/hint_check.test.mjs +129 -0
  985. package/skills/a2h-utg-explorer/scripts/tests/holds_without_data_parity.test.mjs +26 -0
  986. package/skills/a2h-utg-explorer/scripts/tests/interruptions.test.mjs +492 -0
  987. package/skills/a2h-utg-explorer/scripts/tests/launch_bridge.test.mjs +199 -0
  988. package/skills/a2h-utg-explorer/scripts/tests/launch_failure.test.mjs +40 -0
  989. package/skills/a2h-utg-explorer/scripts/tests/node_coverage.test.mjs +193 -0
  990. package/skills/a2h-utg-explorer/scripts/tests/overflow_prefix.test.mjs +327 -0
  991. package/skills/a2h-utg-explorer/scripts/tests/overlay_identity.test.mjs +204 -0
  992. package/skills/a2h-utg-explorer/scripts/tests/page_identity_tiers.test.mjs +393 -0
  993. package/skills/a2h-utg-explorer/scripts/tests/pager_navigation.test.mjs +119 -0
  994. package/skills/a2h-utg-explorer/scripts/tests/panel_routes.test.mjs +208 -0
  995. package/skills/a2h-utg-explorer/scripts/tests/pipeline.test.mjs +240 -0
  996. package/skills/a2h-utg-explorer/scripts/tests/recover.test.mjs +212 -0
  997. package/skills/a2h-utg-explorer/scripts/tests/recover_b.test.mjs +173 -0
  998. package/skills/a2h-utg-explorer/scripts/tests/recover_d.test.mjs +280 -0
  999. package/skills/a2h-utg-explorer/scripts/tests/review_fixes.test.mjs +213 -0
  1000. package/skills/a2h-utg-explorer/scripts/tests/robustness_fixes.test.mjs +345 -0
  1001. package/skills/a2h-utg-explorer/scripts/tests/run_cycle.test.mjs +454 -0
  1002. package/skills/a2h-utg-explorer/scripts/tests/runner_capabilities.test.mjs +194 -0
  1003. package/skills/a2h-utg-explorer/scripts/tests/scope.test.mjs +229 -0
  1004. package/skills/a2h-utg-explorer/scripts/tests/scroll_sweep.test.mjs +336 -0
  1005. package/skills/a2h-utg-explorer/scripts/tests/semantics.test.mjs +102 -0
  1006. package/skills/a2h-utg-explorer/scripts/tests/snapshot_integrity.test.mjs +142 -0
  1007. package/skills/a2h-utg-explorer/scripts/tests/state_ambiguity.test.mjs +92 -0
  1008. package/skills/a2h-utg-explorer/scripts/tests/string_tables_twin_ties.test.mjs +83 -0
  1009. package/skills/a2h-utg-explorer/scripts/tests/tar_fixture.mjs +12 -0
  1010. package/skills/a2h-utg-explorer/scripts/tests/twin_opener.test.mjs +119 -0
  1011. package/skills/a2h-utg-explorer/scripts/tests/u2_backend.test.mjs +346 -0
  1012. package/skills/a2h-utg-explorer/scripts/tests/ui_state_anchors.test.mjs +112 -0
  1013. package/skills/a2h-utg-explorer/scripts/tests/variant_strings.test.mjs +63 -0
  1014. package/skills/a2h-utg-explorer/scripts/tests/worklist_parts.test.mjs +24 -0
  1015. package/skills/a2h-utg-explorer/scripts/utg_explorer/adapters.mjs +13 -3
  1016. package/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +107 -65
  1017. package/skills/a2h-utg-explorer/scripts/utg_explorer/strings.mjs +155 -0
  1018. package/skills/a2h-utg-static/scripts/assemble.mjs +28 -3
  1019. package/skills/a2h-utg-static/scripts/click_paths.mjs +19 -20
  1020. package/skills/a2h-utg-static/scripts/compose_overlay.mjs +102 -2
  1021. package/skills/a2h-utg-static/scripts/fragment_nav.mjs +2 -3
  1022. package/skills/a2h-utg-static/scripts/nl_hints.mjs +2 -3
  1023. package/skills/a2h-utg-static/scripts/presenter_nav.mjs +1 -2
  1024. package/skills/a2h-utg-static/scripts/route_interceptor.mjs +21 -7
  1025. package/skills/a2h-utg-static/scripts/static_prior.mjs +26 -29
  1026. package/skills/a2h-utg-static/scripts/tests/test_activity_gates.mjs +84 -0
  1027. package/skills/a2h-utg-static/scripts/tests/test_login_interceptor.mjs +38 -0
  1028. package/skills/a2h-utg-static/scripts/tests/test_route_token_words.mjs +29 -1
  1029. package/skills/a2h-app-migrate/scripts/i18n-term.d.mts +0 -5
  1030. package/skills/a2h-app-migrate/scripts/i18n-term.mjs +0 -54
  1031. package/skills/a2h-arch-generate/scripts/i18n-term.d.mts +0 -5
  1032. package/skills/a2h-arch-generate/scripts/i18n-term.mjs +0 -54
  1033. package/skills/a2h-arkts-logic-coder/scripts/design/i18n-term.d.mts +0 -5
  1034. package/skills/a2h-arkts-logic-coder/scripts/design/i18n-term.mjs +0 -54
  1035. package/skills/a2h-batch-ui-align/references/source-only-tier.md +0 -38
  1036. package/skills/a2h-batch-ui-align/scripts/i18n-term.d.mts +0 -5
  1037. package/skills/a2h-batch-ui-align/scripts/i18n-term.mjs +0 -54
  1038. package/skills/a2h-dashboard-render/scripts/i18n-term.d.mts +0 -5
  1039. package/skills/a2h-dashboard-render/scripts/i18n-term.mjs +0 -54
  1040. package/skills/a2h-resource-convert/scripts/i18n-term.d.mts +0 -5
  1041. package/skills/a2h-resource-convert/scripts/i18n-term.mjs +0 -54
  1042. package/skills/a2h-spec-design-pipeline/scripts/i18n-term.d.mts +0 -5
  1043. package/skills/a2h-spec-design-pipeline/scripts/i18n-term.mjs +0 -54
  1044. package/skills/a2h-spec-design-pipeline/scripts/test_i18n_term.ts +0 -70
  1045. package/skills/a2h-spec-generate/scripts/i18n-term.d.mts +0 -5
  1046. package/skills/a2h-spec-generate/scripts/i18n-term.mjs +0 -54
  1047. package/skills/a2h-spec-generate/scripts/reqgen/src/i18n-term.d.mts +0 -5
  1048. package/skills/a2h-spec-generate/scripts/reqgen/src/i18n-term.mjs +0 -54
  1049. package/skills/a2h-utg-explorer/scripts/i18n-term.d.mts +0 -5
  1050. package/skills/a2h-utg-explorer/scripts/i18n-term.mjs +0 -54
  1051. package/skills/a2h-utg-static/scripts/i18n-term.d.mts +0 -5
  1052. package/skills/a2h-utg-static/scripts/i18n-term.mjs +0 -54
  1053. package/skills/a2h-utg-static/scripts/tests/test_i18n_term.mjs +0 -155
@@ -0,0 +1,2048 @@
1
+ /**
2
+ * Live device capture for the dependency-free Node dashboard.
3
+ *
4
+ * Source-side Android screenshots are immutable pipeline inputs: when every
5
+ * page declared by ui_info already has meta.json, view.xml and a screenshot,
6
+ * the dashboard reuses them and never contacts ADB. HarmonyOS capture is a
7
+ * single startup snapshot. Browser reloads only rebuild HTML from artifacts;
8
+ * they never trigger another device capture.
9
+ */
10
+
11
+ import fs from 'node:fs';
12
+ import path from 'node:path';
13
+ import { spawn } from 'node:child_process';
14
+ import { fileURLToPath } from 'node:url';
15
+
16
+ // Capture captions and validation reasons are business text in the installed language
17
+ //; dashboard.mjs trCaptureDetail renders either form in the display language.
18
+ const listJoin = (items) => items.join(', ');
19
+ // Validation reasons that the state-retry loop re-checks, in both forms.
20
+ const RETRYABLE_REASON = /^Target state is missing visible content|^The page structure did not change after the tap/;
21
+
22
+ const MODULE_DIR = path.dirname(fileURLToPath(import.meta.url));
23
+ // page_capture.mjs (zero-dependency Node; port of the removed a2h-utg-crawler's
24
+ // page_capture.py) runs under this same Node, so live capture needs no Python.
25
+ // Its CLI (--device/--serial/-o/--max-scrolls/--stability-only) matches the calls below.
26
+ const PAGE_CAPTURE_SCRIPT = path.resolve(MODULE_DIR, 'page_capture.mjs');
27
+ const NODE = process.execPath;
28
+
29
+ // Windows env blocks may store the variable as "Path"; Node's process.env
30
+ // bridges both spellings, but copied env objects do not. An explicitly
31
+ // configured empty PATH stays empty — callers use it to simulate a PATH-less
32
+ // environment — so only an undefined PATH falls back to the other spelling.
33
+ function envPathValue(env = process.env) {
34
+ if (env.PATH !== undefined) return String(env.PATH);
35
+ if (env.Path !== undefined) return String(env.Path);
36
+ return '';
37
+ }
38
+
39
+ const STARTUP_DEVICE_WAIT_MS = 60_000;
40
+
41
+ function readText(file) {
42
+ try { return fs.readFileSync(file, 'utf8'); } catch { return '';
43
+ }
44
+ }
45
+
46
+ function readJson(file) {
47
+ try { return JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, '')); } catch { return null; }
48
+ }
49
+
50
+ function writeJson(file, value) {
51
+ fs.writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
52
+ }
53
+
54
+ function exists(file) {
55
+ try { return fs.existsSync(file); } catch { return false; }
56
+ }
57
+
58
+ function safeName(value) {
59
+ return String(value || 'Page').replace(/[^\p{L}\p{N}_.-]+/gu, '_').replace(/^_+|_+$/g, '') || 'Page';
60
+ }
61
+
62
+ function normalizedPage(value) {
63
+ return safeName(String(value || '').split(/[\\/]/).at(-1).replace(/\.(ets|cj)$/i, '')).toLowerCase();
64
+ }
65
+
66
+ function decodeXml(value) {
67
+ return String(value || '').replace(/&(#x?[0-9a-f]+|amp|lt|gt|quot|apos);/gi, (match, entity) => {
68
+ const named = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'" };
69
+ if (!entity.startsWith('#')) return named[entity.toLowerCase()] ?? match;
70
+ const code = entity[1]?.toLowerCase() === 'x'
71
+ ? Number.parseInt(entity.slice(2), 16)
72
+ : Number.parseInt(entity.slice(1), 10);
73
+ return Number.isFinite(code) ? String.fromCodePoint(code) : match;
74
+ });
75
+ }
76
+
77
+ function xmlAttributes(raw) {
78
+ const attrs = {};
79
+ const pattern = /([^\s=/>]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;
80
+ let match;
81
+ while ((match = pattern.exec(raw))) attrs[match[1]] = decodeXml(match[2] ?? match[3] ?? '');
82
+ return attrs;
83
+ }
84
+
85
+ function truthyXml(value) {
86
+ return /^(1|true|yes)$/i.test(String(value || ''));
87
+ }
88
+
89
+ function clickableElementsFromXml(xml, scrollIndex = 0) {
90
+ const rows = [];
91
+ const seen = new Set();
92
+ const pattern = /<node\b([^>]*)>/gi;
93
+ let match;
94
+ while ((match = pattern.exec(String(xml || '')))) {
95
+ const attrs = xmlAttributes(match[1]);
96
+ if (attrs.enabled && !truthyXml(attrs.enabled)) continue;
97
+ if (![attrs.clickable, attrs['long-clickable'], attrs.checkable].some(truthyXml)) continue;
98
+ const bounds = String(attrs.bounds || '').match(/\[(-?\d+),(-?\d+)\]\[(-?\d+),(-?\d+)\]/);
99
+ if (!bounds) continue;
100
+ const [, x1, y1, x2, y2] = bounds.map(Number);
101
+ if (x2 <= x1 || y2 <= y1) continue;
102
+ const key = `${x1},${y1},${x2},${y2}`;
103
+ if (seen.has(key)) continue;
104
+ seen.add(key);
105
+ rows.push({
106
+ class: attrs.class || attrs.type || '',
107
+ 'resource-id': attrs['resource-id'] || attrs.id || '',
108
+ text: attrs.text || '',
109
+ 'content-desc': attrs['content-desc'] || attrs.description || '',
110
+ bounds: `[${x1},${y1}][${x2},${y2}]`,
111
+ center: [Math.trunc((x1 + x2) / 2), Math.trunc((y1 + y2) / 2)],
112
+ scroll_index: scrollIndex,
113
+ });
114
+ }
115
+ return rows;
116
+ }
117
+
118
+ function parsedBounds(value) {
119
+ const match = String(value || '').match(/\[(-?\d+),(-?\d+)\]\[(-?\d+),(-?\d+)\]/);
120
+ return match ? match.slice(1).map(Number) : null;
121
+ }
122
+
123
+ function boundsContain(outerValue, innerValue) {
124
+ const outer = parsedBounds(outerValue);
125
+ const inner = parsedBounds(innerValue);
126
+ if (!outer || !inner) return false;
127
+ // ArkUI can report a Text child a few pixels wider than its clickable Row
128
+ // because glyph/layout bounds are not clipped to the hit-test rectangle.
129
+ // The child's centre is the stable ownership signal in that case.
130
+ const centerX = (inner[0] + inner[2]) / 2;
131
+ const centerY = (inner[1] + inner[3]) / 2;
132
+ return outer[0] <= centerX && centerX <= outer[2]
133
+ && outer[1] <= centerY && centerY <= outer[3];
134
+ }
135
+
136
+ function scopedClickableElementsFromXml(xml, expectedVisible = [], scrollIndex = 0) {
137
+ const scope = expectedVisible.length ? smallestExpectedScope(xml, expectedVisible, true) : String(xml || '');
138
+ const rows = clickableElementsFromXml(scope, scrollIndex);
139
+ const nodes = [];
140
+ const stack = [];
141
+ const pattern = /<node\b([^>]*?)(\/?)>|<\/node\s*>/gi;
142
+ let match;
143
+ while ((match = pattern.exec(scope))) {
144
+ if (match[0].startsWith('</')) {
145
+ const node = stack.pop();
146
+ if (node) node.end = pattern.lastIndex;
147
+ continue;
148
+ }
149
+ const node = { attrs: xmlAttributes(match[1]), start: match.index, end: pattern.lastIndex };
150
+ nodes.push(node);
151
+ if (match[2] !== '/') stack.push(node);
152
+ }
153
+ while (stack.length) stack.pop().end = scope.length;
154
+ const labelled = rows.map((row) => {
155
+ const owner = nodes.find((node) => {
156
+ const attrs = node.attrs;
157
+ return String(attrs.bounds || '') === String(row.bounds || '')
158
+ && String(attrs.class || attrs.type || '') === String(row.class || '')
159
+ && [attrs.clickable, attrs['long-clickable'], attrs.checkable].some(truthyXml);
160
+ });
161
+ const ownerXml = owner ? scope.slice(owner.start, owner.end) : '';
162
+ const labels = [...ownerXml.matchAll(/<node\b([^>]*)>/gi)]
163
+ .flatMap((item) => {
164
+ const attrs = xmlAttributes(item[1]);
165
+ return [attrs.text, attrs['content-desc']];
166
+ })
167
+ .map((value) => String(value || '').trim())
168
+ .filter(Boolean)
169
+ .sort((left, right) => right.length - left.length);
170
+ return labels[0] ? { ...row, text: labels[0] } : row;
171
+ });
172
+ return labelled.filter((row, index) => {
173
+ // ArkUI selection rows commonly expose both the whole Row and its nested
174
+ // Radio/Checkbox/Toggle as clickable. They are one user action, so keep
175
+ // the larger semantic row and discard only the nested selection control.
176
+ if (/^(?:Radio|Checkbox|Toggle)$/i.test(String(row.class || ''))) {
177
+ const owner = labelled.find((candidate, candidateIndex) => candidateIndex !== index
178
+ && !/^(?:Radio|Checkbox|Toggle)$/i.test(String(candidate.class || ''))
179
+ && boundsContain(candidate.bounds, row.bounds)
180
+ && candidate.bounds !== row.bounds);
181
+ if (owner) return false;
182
+ }
183
+ return !labelled.slice(0, index).some((candidate) => (
184
+ candidate.bounds === row.bounds && candidate.class === row.class && candidate.text === row.text
185
+ ));
186
+ });
187
+ }
188
+
189
+ function enrichCaptureMeta(dir, options = {}) {
190
+ const metaFile = path.join(dir, 'meta.json');
191
+ const meta = readJson(metaFile) ?? {};
192
+ const xmlFiles = fs.readdirSync(dir, { withFileTypes: true })
193
+ .filter((item) => item.isFile() && /^view(?:_scroll_\d+)?\.xml$/i.test(item.name))
194
+ .map((item) => item.name)
195
+ .sort((left, right) => {
196
+ const a = Number(left.match(/(\d+)/)?.[1] ?? 0);
197
+ const b = Number(right.match(/(\d+)/)?.[1] ?? 0);
198
+ return a - b;
199
+ });
200
+ const clickable = [];
201
+ xmlFiles.forEach((name, index) => clickable.push(...scopedClickableElementsFromXml(
202
+ readText(path.join(dir, name)),
203
+ Array.isArray(options.expectedVisible) ? options.expectedVisible : [],
204
+ index,
205
+ )));
206
+ if (clickable.length) meta.clickable_elements = clickable;
207
+ meta.capture_origin = 'node-dashboard-live';
208
+ meta.captured_at = meta.timestamp || new Date().toISOString();
209
+ writeJson(metaFile, meta);
210
+ return meta;
211
+ }
212
+
213
+ function captureStructureSignature(metaFile) {
214
+ const xml = readText(path.join(path.dirname(metaFile), 'view.xml'));
215
+ const nodes = [];
216
+ const pattern = /<node\b([^>]*)>/gi;
217
+ let match;
218
+ while ((match = pattern.exec(xml))) {
219
+ const attrs = xmlAttributes(match[1]);
220
+ nodes.push([
221
+ attrs.class || attrs.type || '',
222
+ attrs.bounds || '',
223
+ String(attrs.clickable || '').toLowerCase(),
224
+ String(attrs['long-clickable'] || '').toLowerCase(),
225
+ String(attrs.checkable || '').toLowerCase(),
226
+ String(attrs.scrollable || '').toLowerCase(),
227
+ String(attrs.focusable || '').toLowerCase(),
228
+ // Text is also evidence of "the page changed": two structurally identical pages that differ only in
229
+ // wording (home button "Tap me to jump" → sub-page button "Tap me to go back") must count as navigated, otherwise they
230
+ // get falsely reported as "no structural change after the tap".
231
+ String(attrs.text || '').toLowerCase(),
232
+ String(attrs['content-desc'] || '').toLowerCase(),
233
+ ].join('|'));
234
+ }
235
+ if (nodes.length) return nodes.join('\n');
236
+ const clickable = readJson(metaFile)?.clickable_elements || [];
237
+ return clickable.map((item) => [
238
+ item.class || '',
239
+ item.bounds || '',
240
+ Array.isArray(item.center) ? item.center.join(',') : '',
241
+ String(item.text || item['content-desc'] || '').toLowerCase(),
242
+ ].join('|')).join('\n');
243
+ }
244
+
245
+ function captureStateChanged(beforeMetaFile, afterMetaFile) {
246
+ if (!beforeMetaFile || !afterMetaFile || !exists(beforeMetaFile) || !exists(afterMetaFile)) return false;
247
+ const before = captureStructureSignature(beforeMetaFile);
248
+ const after = captureStructureSignature(afterMetaFile);
249
+ return Boolean(before && after && before !== after);
250
+ }
251
+
252
+ function screenshotIn(dir, hmos = false) {
253
+ const names = hmos
254
+ ? ['long_screenshot.jpeg', 'long_screenshot.jpg', 'long_screenshot.png', 'screenshot.jpeg', 'screenshot.jpg', 'screenshot.png']
255
+ : ['long_screenshot.png', 'long_screenshot.jpeg', 'long_screenshot.jpg', 'screenshot.png', 'screenshot.jpeg', 'screenshot.jpg'];
256
+ return names.map((name) => path.join(dir, name)).find((file) => {
257
+ try { return fs.statSync(file).isFile() && fs.statSync(file).size > 0; } catch { return false; }
258
+ }) || '';
259
+ }
260
+
261
+ function smallestExpectedScope(xml, expectedVisible, preserveCase = false) {
262
+ const expected = expectedVisible.map((value) => String(value || '').trim().toLowerCase()).filter(Boolean);
263
+ if (!expected.length) return String(xml || '').toLowerCase();
264
+ const roots = [];
265
+ const stack = [];
266
+ const tagPattern = /<node\b([^>]*?)(\/?)>|<\/node\s*>/gi;
267
+ let tag;
268
+ while ((tag = tagPattern.exec(String(xml || '')))) {
269
+ if (tag[0].startsWith('</')) {
270
+ const node = stack.pop();
271
+ if (node) node.end = tagPattern.lastIndex;
272
+ continue;
273
+ }
274
+ const node = {
275
+ attrs: xmlAttributes(tag[1]),
276
+ start: tag.index,
277
+ end: tagPattern.lastIndex,
278
+ depth: stack.length,
279
+ children: [],
280
+ };
281
+ if (stack.length) stack.at(-1).children.push(node);
282
+ else roots.push(node);
283
+ if (tag[2] === '/') node.end = tagPattern.lastIndex;
284
+ else stack.push(node);
285
+ }
286
+ while (stack.length) {
287
+ const node = stack.pop();
288
+ node.end = String(xml || '').length;
289
+ }
290
+ const matches = [];
291
+ const visit = (node) => {
292
+ const raw = String(xml || '').slice(node.start, node.end);
293
+ const blob = raw.toLowerCase();
294
+ if (expected.every((value) => blob.includes(value))) matches.push({ node, blob, raw });
295
+ node.children.forEach(visit);
296
+ };
297
+ roots.forEach(visit);
298
+ // An overlay/dialog is normally the deepest and smallest subtree containing
299
+ // every required label. Scoping forbidden-label checks to that subtree
300
+ // prevents the still-rendered page underneath the overlay from being
301
+ // mistaken for a different dialog state.
302
+ matches.sort((left, right) => right.node.depth - left.node.depth || left.blob.length - right.blob.length);
303
+ if (!matches[0]) return preserveCase ? String(xml || '') : String(xml || '').toLowerCase();
304
+ return preserveCase ? matches[0].raw : matches[0].blob;
305
+ }
306
+
307
+ function parseBoundsRect(raw) {
308
+ const match = String(raw || '').match(/\[(-?\d+),(-?\d+)\]\[(-?\d+),(-?\d+)\]/);
309
+ if (!match) return null;
310
+ const [, x1, y1, x2, y2] = match.map(Number);
311
+ return { x1, y1, x2, y2 };
312
+ }
313
+
314
+ function screenBoundsFromXml(xml) {
315
+ const match = String(xml || '').match(/<node\b[^>]*bounds="\[(\d+),(\d+)\]\[(\d+),(\d+)\]"/);
316
+ if (!match) return null;
317
+ const width = Number(match[3]) - Number(match[1]);
318
+ const height = Number(match[4]) - Number(match[2]);
319
+ return width > 0 && height > 0 ? { width, height } : null;
320
+ }
321
+
322
+ // Clickable-element geometry normalized to the screen rectangle, so Android
323
+ // and HarmonyOS captures at different resolutions become comparable. The
324
+ // authoritative screen size is the recorder's device_info (wm size); the
325
+ // view-tree root bounds are only a fallback — dialog dumps can carry a root
326
+ // smaller than the physical screen and would push normalized y past 1.
327
+ function normalizedStructure(elements, xml, screenHint = null) {
328
+ const hintWidth = Number(screenHint?.width_px ?? screenHint?.width);
329
+ const hintHeight = Number(screenHint?.height_px ?? screenHint?.height);
330
+ const hint = hintWidth > 0 && hintHeight > 0 ? { width: hintWidth, height: hintHeight } : null;
331
+ const screen = hint || screenBoundsFromXml(xml);
332
+ if (!screen) return [];
333
+ const seen = new Set();
334
+ const rows = [];
335
+ for (const item of (Array.isArray(elements) ? elements : [])) {
336
+ const rect = parseBoundsRect(item?.bounds);
337
+ if (!rect) continue;
338
+ const row = {
339
+ cx: (rect.x1 + rect.x2) / 2 / screen.width,
340
+ cy: (rect.y1 + rect.y2) / 2 / screen.height,
341
+ w: (rect.x2 - rect.x1) / screen.width,
342
+ h: (rect.y2 - rect.y1) / screen.height,
343
+ text: String(item?.text || '').trim(),
344
+ };
345
+ // The crawler can record the same control twice (parent + child with
346
+ // identical bounds). Collapse near-identical geometry so one real element
347
+ // counts once; duplicates would both dilute the match ratio and surface
348
+ // as fake extras on the other side.
349
+ const key = [row.cx, row.cy, row.w, row.h].map((value) => value.toFixed(2)).join(',');
350
+ if (seen.has(key)) continue;
351
+ seen.add(key);
352
+ rows.push(row);
353
+ }
354
+ return rows;
355
+ }
356
+
357
+ // Every visible text of a source page (view texts + clickable texts), used to
358
+ // tell "foreign" unmatched elements (dialog buttons from another state) from
359
+ // wording the target page itself legitimately shows.
360
+ function xmlTextCorpus(xml, elements) {
361
+ const values = [...String(xml || '').matchAll(/text="([^"]+)"/g)].map((match) => match[1]);
362
+ for (const item of Array.isArray(elements) ? elements : []) {
363
+ if (item?.text) values.push(String(item.text));
364
+ }
365
+ return values.map((value) => value.toLowerCase()).join('\n');
366
+ }
367
+
368
+ // Positional matching between the expected (Android source state) and the
369
+ // actual (captured HarmonyOS state) clickable sets. Structure — not wording —
370
+ // decides whether the target state was reached; migrated apps may legitimately
371
+ // reword labels while keeping the layout.
372
+ function compareStructure(expected, actual, tolerance = 0.18) {
373
+ if (!expected.length || !actual.length) {
374
+ return { matchedCount: 0, expectedCount: expected.length, matchedRatio: 0, extras: [] };
375
+ }
376
+ const used = new Set();
377
+ const matches = [];
378
+ // Pass 1: anchor identical-text pairs (within a loose positional sanity
379
+ // window) before positional matching. Without this, an overlay sitting
380
+ // between two list rows can steal a row's positional match and let the
381
+ // real row surface as an "extra".
382
+ const pending = [];
383
+ for (const exp of expected) {
384
+ if (!exp.text) { pending.push(exp); continue; }
385
+ const wanted = exp.text.toLowerCase();
386
+ let best = -1;
387
+ let bestDistance = Number.POSITIVE_INFINITY;
388
+ actual.forEach((act, index) => {
389
+ if (used.has(index) || String(act.text || '').trim().toLowerCase() !== wanted) return;
390
+ const distance = Math.hypot(exp.cx - act.cx, exp.cy - act.cy);
391
+ if (distance < bestDistance) { bestDistance = distance; best = index; }
392
+ });
393
+ if (best >= 0 && bestDistance <= 0.3) {
394
+ used.add(best);
395
+ matches.push({ expected: exp, actual: actual[best] });
396
+ } else {
397
+ pending.push(exp);
398
+ }
399
+ }
400
+ // Pass 2: greedy nearest-center matching for everything else — reworded
401
+ // labels and textless icons still pair positionally.
402
+ for (const exp of pending) {
403
+ let best = -1;
404
+ let bestDistance = Number.POSITIVE_INFINITY;
405
+ actual.forEach((act, index) => {
406
+ if (used.has(index)) return;
407
+ const distance = Math.hypot(exp.cx - act.cx, exp.cy - act.cy);
408
+ if (distance < bestDistance) { bestDistance = distance; best = index; }
409
+ });
410
+ if (best >= 0 && bestDistance <= tolerance) {
411
+ used.add(best);
412
+ matches.push({ expected: exp, actual: actual[best] });
413
+ }
414
+ }
415
+ const extras = actual.filter((_, index) => !used.has(index));
416
+ // Text agreement among the POSITIONALLY matched pairs. A global "text appears
417
+ // somewhere" check cannot separate an overlay from the page beneath (the
418
+ // settings rows repeat the dialog option labels), so compare the wording at
419
+ // the matched positions instead: a reworded label still counts when one text
420
+ // contains the other ("Select language" ↔ "Language").
421
+ let matchedTextTotal = 0;
422
+ let agreedTextTotal = 0;
423
+ for (const match of matches) {
424
+ const expectedText = String(match.expected.text || '').trim().toLowerCase();
425
+ if (!expectedText) continue;
426
+ matchedTextTotal += 1;
427
+ const actualText = String(match.actual.text || '').trim().toLowerCase();
428
+ if (actualText && (actualText === expectedText
429
+ || actualText.includes(expectedText) || expectedText.includes(actualText))) {
430
+ agreedTextTotal += 1;
431
+ }
432
+ }
433
+ return {
434
+ matchedCount: matches.length,
435
+ expectedCount: expected.length,
436
+ matchedRatio: matches.length / expected.length,
437
+ matchedTextTotal,
438
+ agreedTextTotal,
439
+ extras,
440
+ };
441
+ }
442
+
443
+ function validateHmosCapture(dir, expectedNames = [], options = {}) {
444
+ const meta = readJson(path.join(dir, 'meta.json'));
445
+ const screenshot = screenshotIn(dir, true);
446
+ if (!meta || !screenshot) return { ok: false, reason: "meta.json or the screenshot file is missing", actualPage: '' };
447
+ const actualPage = String(meta.page_name || '');
448
+ const expected = expectedNames.map(normalizedPage).filter(Boolean);
449
+ const actualIdentity = normalizedPage(actualPage);
450
+ // Some HDC/uitest versions omit pagePath and report "unknown". In that
451
+ // case the caller must provide an independent runtime fingerprint (for
452
+ // example the navigation click that was just executed). Never treat an
453
+ // unknown identity as a successful match by itself.
454
+ if ((!actualIdentity || actualIdentity === 'unknown') && !options.allowUnknown) {
455
+ return { ok: false, reason: "HDC returned no verifiable page_name", actualPage };
456
+ }
457
+ if (actualIdentity && actualIdentity !== 'unknown' && expected.length && !expected.includes(actualIdentity)) {
458
+ return { ok: false, reason: `The actual page is ${actualPage || "unknown page"}, which does not match the target ${expectedNames.join('/')}`, actualPage };
459
+ }
460
+ const pageXml = readText(path.join(dir, 'view.xml'));
461
+ const expectedBundle = String(options.expectedBundle || '').trim().toLowerCase();
462
+ const observedBundles = [...pageXml.matchAll(/\bpackage="([^"]+)"/gi)]
463
+ .map((match) => String(match[1] || '').trim().toLowerCase())
464
+ .filter(Boolean);
465
+ if (expectedBundle && options.requireBundle && !observedBundles.length) {
466
+ return { ok: false, reason: "The HDC page tree returned no foreground app bundle; the screenshot cannot be attributed", actualPage };
467
+ }
468
+ if (expectedBundle && observedBundles.length && !observedBundles.includes(expectedBundle)) {
469
+ return { ok: false, reason: `The foreground page does not belong to ${options.expectedBundle} (actually ${listJoin([...new Set(observedBundles)])})`, actualPage };
470
+ }
471
+ const visibleText = `${pageXml}\n${(meta.clickable_elements || [])
472
+ .flatMap((item) => [item.text, item['content-desc'], item['resource-id']])
473
+ .filter(Boolean)
474
+ .join('\n')}`.toLowerCase();
475
+ const expectedVisible = Array.isArray(options.expectedVisible) ? options.expectedVisible : [];
476
+ const forbiddenVisible = Array.isArray(options.forbiddenVisible) ? options.forbiddenVisible : [];
477
+ // Structure gate: compare clickable-element geometry (normalized to the
478
+ // screen) against the Android source state instead of requiring the
479
+ // Android wording to appear verbatim — migrated apps may reword labels
480
+ // while keeping the layout. Unmatched elements whose text the target page
481
+ // never shows (dialog buttons from another state) flag overlay residue.
482
+ const actualStructure = normalizedStructure(meta.clickable_elements, pageXml, meta.device_info);
483
+ const expectedStructure = Array.isArray(options.expectedStructure) ? options.expectedStructure : [];
484
+ const expectedTexts = String(options.expectedTexts || '').toLowerCase();
485
+ let gateFailure = '';
486
+ if (expectedStructure.length && actualStructure.length) {
487
+ const comparison = compareStructure(expectedStructure, actualStructure);
488
+ // Structure alone cannot separate layouts that share a shape (the four
489
+ // preference dialogs all render option/option/Cancel at the same spots), so
490
+ // the wording at the matched positions must also agree — tolerantly
491
+ // (containment counts, and half of the textual pairs is enough to survive
492
+ // a couple of reworded labels).
493
+ const textAgreementOk = !comparison.matchedTextTotal
494
+ || comparison.agreedTextTotal / comparison.matchedTextTotal >= 0.5;
495
+ if (comparison.matchedRatio < 0.5) {
496
+ gateFailure = `Page structure does not match the target state (${comparison.matchedCount}/${comparison.expectedCount} element positions correspond)`;
497
+ } else if (!textAgreementOk) {
498
+ gateFailure = `Target-state text mismatch (${comparison.matchedTextTotal} text-bearing elements located, only ${comparison.agreedTextTotal} of them agree with the target)`;
499
+ } else if (comparison.extras.length <= comparison.expectedCount) {
500
+ // Only inspect unmatched elements for foreign text when both sides expose
501
+ // a comparable number of clickables. When the captured dump marks far
502
+ // more elements clickable than the source dump (different UI-toolkit
503
+ // hit-testing), the surplus is granularity noise, not overlay evidence.
504
+ const foreignExtras = comparison.extras
505
+ .filter((item) => item.text && item.text.length >= 2 && !expectedTexts.includes(item.text.toLowerCase()))
506
+ .map((item) => item.text);
507
+ if (foreignExtras.length >= 2) {
508
+ gateFailure = `The screenshot shows ${foreignExtras.length} text element(s) that do not belong to the target state (${listJoin(foreignExtras.slice(0, 3))}); likely a leftover overlay or dialog`;
509
+ }
510
+ }
511
+ } else if (expectedVisible.length) {
512
+ const missing = expectedVisible.filter((value) => !visibleText.includes(String(value).toLowerCase()));
513
+ if (missing.length) gateFailure = `Target state is missing visible content: ${listJoin(missing)}`;
514
+ }
515
+ if (gateFailure) return { ok: false, reason: gateFailure, actualPage };
516
+ const expectedScope = smallestExpectedScope(pageXml, expectedVisible);
517
+ const forbidden = forbiddenVisible.find((value) => expectedScope.includes(String(value).toLowerCase()));
518
+ if (forbidden) return { ok: false, reason: `The screenshot shows content from another state: ${forbidden}`, actualPage };
519
+ if (options.mustDifferFromMeta && !captureStateChanged(options.mustDifferFromMeta, path.join(dir, 'meta.json'))) {
520
+ return { ok: false, reason: "The page structure did not change after the tap; the target page or dialog did not actually open", actualPage };
521
+ }
522
+ return { ok: true, actualPage, screenshot };
523
+ }
524
+
525
+ function assertWithin(root, target) {
526
+ const base = path.resolve(root);
527
+ const resolved = path.resolve(target);
528
+ const relative = path.relative(base, resolved);
529
+ if (!relative || relative.startsWith('..') || path.isAbsolute(relative)) {
530
+ if (resolved !== base) throw new Error(`Refusing to operate outside the capture directory: ${resolved}`);
531
+ }
532
+ }
533
+
534
+ function removeGeneratedDir(root, target) {
535
+ assertWithin(root, target);
536
+ fs.rmSync(target, { recursive: true, force: true });
537
+ }
538
+
539
+ function atomicPromoteCapture(captureRoot, pendingDir, finalDir) {
540
+ assertWithin(captureRoot, pendingDir);
541
+ assertWithin(captureRoot, finalDir);
542
+ // A leftover backup means a previous promote crashed between its two renames:
543
+ // restore it before replacing, so the previous cache survives.
544
+ const backup = `${finalDir}.previous`;
545
+ assertWithin(captureRoot, backup);
546
+ if (!exists(finalDir) && exists(backup)) fs.renameSync(backup, finalDir);
547
+ if (exists(backup)) removeGeneratedDir(captureRoot, backup);
548
+ if (exists(finalDir)) fs.renameSync(finalDir, backup);
549
+ try {
550
+ fs.renameSync(pendingDir, finalDir);
551
+ if (exists(backup)) removeGeneratedDir(captureRoot, backup);
552
+ } catch (error) {
553
+ if (exists(finalDir)) removeGeneratedDir(captureRoot, finalDir);
554
+ if (exists(backup)) fs.renameSync(backup, finalDir);
555
+ throw error;
556
+ }
557
+ }
558
+
559
+ function runCommand(command, args, options = {}) {
560
+ return new Promise((resolve) => {
561
+ let stdout = '';
562
+ let stderr = '';
563
+ let settled = false;
564
+ let timer = null;
565
+ let child;
566
+ const finish = (result) => {
567
+ if (settled) return;
568
+ settled = true;
569
+ if (timer) clearTimeout(timer);
570
+ resolve({ stdout, stderr, ...result });
571
+ };
572
+ try {
573
+ child = spawn(command, args, {
574
+ cwd: options.cwd,
575
+ env: options.env || process.env,
576
+ windowsHide: true,
577
+ stdio: ['ignore', 'pipe', 'pipe'],
578
+ });
579
+ } catch (error) {
580
+ finish({ code: null, error });
581
+ return;
582
+ }
583
+ child.stdout?.on('data', (chunk) => { stdout += chunk.toString('utf8'); });
584
+ child.stderr?.on('data', (chunk) => { stderr += chunk.toString('utf8'); });
585
+ child.on('error', (error) => finish({ code: null, error }));
586
+ child.on('close', (code, signal) => finish({ code, signal }));
587
+ timer = setTimeout(() => {
588
+ child.kill('SIGTERM');
589
+ finish({ code: null, timedOut: true, error: new Error(`Command timed out (${options.timeoutMs || 10_000}ms)`) });
590
+ }, options.timeoutMs || 10_000);
591
+ });
592
+ }
593
+
594
+ function executableCandidates(name, env = process.env) {
595
+ const executable = process.platform === 'win32' && !name.endsWith('.exe') ? `${name}.exe` : name;
596
+ const fromPath = envPathValue(env).split(path.delimiter).filter(Boolean).map((dir) => path.join(dir, executable));
597
+ const home = env.USERPROFILE || env.HOME || '';
598
+ const extra = name.startsWith('hdc') ? [
599
+ env.HOMETRANS_HDC,
600
+ env.HDC_PATH,
601
+ env.DEVECO_SDK_HOME && path.join(env.DEVECO_SDK_HOME, 'default', 'openharmony', 'toolchains', executable),
602
+ env.DEVECO_SDK_HOME && path.join(env.DEVECO_SDK_HOME, 'openharmony', 'toolchains', executable),
603
+ env.HARMONYOS_SDK_HOME && path.join(env.HARMONYOS_SDK_HOME, 'default', 'openharmony', 'toolchains', executable),
604
+ env.HARMONYOS_SDK_HOME && path.join(env.HARMONYOS_SDK_HOME, 'openharmony', 'toolchains', executable),
605
+ env.OHOS_SDK_HOME && path.join(env.OHOS_SDK_HOME, 'default', 'openharmony', 'toolchains', executable),
606
+ env.OHOS_SDK_HOME && path.join(env.OHOS_SDK_HOME, 'openharmony', 'toolchains', executable),
607
+ env.DEVECO_HOME && path.join(env.DEVECO_HOME, 'sdk', 'default', 'openharmony', 'toolchains', executable),
608
+ env.LOCALAPPDATA && path.join(env.LOCALAPPDATA, 'Huawei', 'Sdk', 'default', 'openharmony', 'toolchains', executable),
609
+ home && path.join(home, 'AppData', 'Local', 'OpenHarmony', 'Sdk', 'default', 'openharmony', 'toolchains', executable),
610
+ home && path.join(home, 'AppData', 'Local', 'Huawei', 'Sdk', 'default', 'openharmony', 'toolchains', executable),
611
+ home && path.join(home, 'Library', 'Huawei', 'Sdk', 'default', 'openharmony', 'toolchains', executable),
612
+ home && path.join(home, 'Library', 'OpenHarmony', 'Sdk', 'default', 'openharmony', 'toolchains', executable),
613
+ home && path.join(home, 'Huawei', 'Sdk', 'default', 'openharmony', 'toolchains', executable),
614
+ home && path.join(home, 'OpenHarmony', 'Sdk', 'default', 'openharmony', 'toolchains', executable),
615
+ ] : [];
616
+ return [...extra, ...fromPath].filter(Boolean);
617
+ }
618
+
619
+ function findExecutable(name, env = process.env) {
620
+ const candidates = executableCandidates(name, env);
621
+ const visible = candidates.find((candidate) => exists(candidate));
622
+ if (visible) return visible;
623
+ // A managed/sandboxed process may be denied even for a valid SDK path.
624
+ // Preserve an explicitly configured SDK location so the runner reports the
625
+ // real launch error and the dashboard can visibly fall back to its cache.
626
+ if (name.startsWith('hdc')) {
627
+ if (env.HOMETRANS_HDC) return env.HOMETRANS_HDC;
628
+ const sdk = env.DEVECO_SDK_HOME || env.HARMONYOS_SDK_HOME || env.OHOS_SDK_HOME;
629
+ if (sdk) return path.join(sdk, 'default', 'openharmony', 'toolchains', process.platform === 'win32' ? 'hdc.exe' : 'hdc');
630
+ if (env.DEVECO_HOME) return path.join(env.DEVECO_HOME, 'sdk', 'default', 'openharmony', 'toolchains', process.platform === 'win32' ? 'hdc.exe' : 'hdc');
631
+ }
632
+ return '';
633
+ }
634
+
635
+ function commandFailure(result, fallback) {
636
+ if (result.timedOut) return result.error?.message || fallback;
637
+ if (result.error) return result.error.message;
638
+ const detail = `${result.stdout || ''}\n${result.stderr || ''}`.trim();
639
+ return detail.slice(-600) || fallback;
640
+ }
641
+
642
+ async function detectHdc(runner = runCommand, env = process.env) {
643
+ const executable = findExecutable('hdc', env);
644
+ if (!executable) return { connected: false, executable: '', targets: [], detail: "hdc not found; using the local cache" };
645
+ const result = await runner(executable, ['list', 'targets'], { timeoutMs: 5_000, env });
646
+ if (result.code !== 0) return { connected: false, executable, targets: [], detail: `hdc check failed: ${commandFailure(result, 'unknown error')}` };
647
+ const targets = String(result.stdout || '').split(/\r?\n/).map((line) => line.trim())
648
+ .filter((line) => line && !/\[Empty\]/i.test(line));
649
+ return { connected: targets.length > 0, executable, targets, detail: targets.length ? `Connected: ${targets.join(', ')}` : "No HarmonyOS device detected; using the local cache" };
650
+ }
651
+
652
+ function captureRootFor(entry) {
653
+ return path.resolve(entry.ui_capture_dir || path.join(entry.path, '.hometrans', 'dashboard-ui-capture'));
654
+ }
655
+
656
+ function uiInfoRootFor(entry) {
657
+ const candidates = [
658
+ entry.ui_info_root,
659
+ entry.android_project_dir ? path.join(entry.android_project_dir, 'ui_info') : '',
660
+ path.join(entry.path, 'ui_info'),
661
+ path.join(entry.path, '.hometrans', 'ui_info'),
662
+ ].filter(Boolean).map((candidate) => path.resolve(candidate));
663
+ return candidates.find((candidate) => exists(path.join(candidate, 'index.json')))
664
+ || candidates.find((candidate) => exists(candidate))
665
+ || candidates[0]
666
+ || path.join(entry.path, 'ui_info');
667
+ }
668
+
669
+ function hmosCaptureProjectRoot(entry) {
670
+ return path.resolve(entry.hmos_capture_project_dir || entry.path);
671
+ }
672
+
673
+ function localProperty(root, key) {
674
+ const escaped = key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
675
+ const raw = readText(path.join(root, 'local.properties')).match(new RegExp(`^${escaped}=(.+)$`, 'mi'))?.[1]?.trim();
676
+ return raw ? raw.replace(/\\:/g, ':').replace(/\\+/g, '\\') : '';
677
+ }
678
+
679
+ function listRecursively(root, predicate, maxDepth = 8, depth = 0, rows = []) {
680
+ if (!root || !exists(root) || depth > maxDepth) return rows;
681
+ let entries = [];
682
+ try { entries = fs.readdirSync(root, { withFileTypes: true }); } catch { return rows; }
683
+ for (const entry of entries) {
684
+ const file = path.join(root, entry.name);
685
+ if (entry.isDirectory()) listRecursively(file, predicate, maxDepth, depth + 1, rows);
686
+ else if (entry.isFile() && predicate(file)) rows.push(file);
687
+ }
688
+ return rows;
689
+ }
690
+
691
+ function latestSignedHap(root, explicit = '') {
692
+ if (explicit) {
693
+ const selected = path.resolve(explicit);
694
+ if (!exists(selected)) throw new Error(`The explicitly specified HAP does not exist: ${selected}`);
695
+ if (!/\.hap$/i.test(selected)) throw new Error(`The explicitly specified file is not a HAP: ${selected}`);
696
+ if (/unsigned/i.test(path.basename(selected))) throw new Error(`The explicitly specified file is an unsigned HAP and cannot be used for device capture: ${selected}`);
697
+ return selected;
698
+ }
699
+ const candidates = listRecursively(root, (file) => (
700
+ /signed\.hap$/i.test(path.basename(file))
701
+ && !/unsigned/i.test(path.basename(file))
702
+ && (file.split(path.sep).some((part) => part.toLowerCase() === 'build') || file.includes(`${path.sep}.hometrans${path.sep}`))
703
+ ), 10);
704
+ return candidates.sort((left, right) => fs.statSync(right).mtimeMs - fs.statSync(left).mtimeMs)[0] || '';
705
+ }
706
+
707
+ function json5String(file, key) {
708
+ const escaped = key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
709
+ return readText(file).match(new RegExp(`(?:["']?${escaped}["']?)\\s*:\\s*["']([^"']+)["']`, 'i'))?.[1] || '';
710
+ }
711
+
712
+ // JSON5 comment stripper (keeps string contents intact) so structural scans
713
+ // cannot be fooled by commented-out ability entries.
714
+ function stripJson5Comments(text) {
715
+ let out = '';
716
+ let quote = '';
717
+ let escaped = false;
718
+ let line = false;
719
+ let block = false;
720
+ for (let i = 0; i < text.length; i += 1) {
721
+ const char = text[i];
722
+ const next = text[i + 1] || '';
723
+ if (line) { if (char === '\n') { line = false; out += char; } continue; }
724
+ if (block) { if (char === '*' && next === '/') { block = false; i += 1; } continue; }
725
+ if (quote) {
726
+ out += char;
727
+ if (escaped) escaped = false;
728
+ else if (char === '\\') escaped = true;
729
+ else if (char === quote) quote = '';
730
+ continue;
731
+ }
732
+ if (char === '/' && next === '/') { line = true; i += 1; continue; }
733
+ if (char === '/' && next === '*') { block = true; i += 1; continue; }
734
+ if (char === '"' || char === "'" || char === '`') { quote = char; out += char; continue; }
735
+ out += char;
736
+ }
737
+ return out;
738
+ }
739
+
740
+ // Slice the balanced block starting at openIndex, skipping brackets inside
741
+ // strings. Returns '' when unbalanced.
742
+ function balancedSlice(text, openIndex, openChar = '{', closeChar = '}') {
743
+ let depth = 0;
744
+ let quote = '';
745
+ let escaped = false;
746
+ for (let i = openIndex; i < text.length; i += 1) {
747
+ const char = text[i];
748
+ if (quote) {
749
+ if (escaped) escaped = false;
750
+ else if (char === '\\') escaped = true;
751
+ else if (char === quote) quote = '';
752
+ continue;
753
+ }
754
+ if (char === '"' || char === "'" || char === '`') { quote = char; continue; }
755
+ if (char === openChar) depth += 1;
756
+ else if (char === closeChar) {
757
+ depth -= 1;
758
+ if (depth === 0) return text.slice(openIndex, i + 1);
759
+ }
760
+ }
761
+ return '';
762
+ }
763
+
764
+ // The ability's own `name`, read only at the object's top level so a nested
765
+ // metadata entry (e.g. { "name": "ohos.ability.shortcuts" }) written before it
766
+ // cannot win.
767
+ function topLevelAbilityName(objectText) {
768
+ let depth = 0;
769
+ let quote = '';
770
+ let escaped = false;
771
+ for (let i = 1; i < objectText.length - 1; i += 1) {
772
+ const char = objectText[i];
773
+ if (quote) {
774
+ if (escaped) escaped = false;
775
+ else if (char === '\\') escaped = true;
776
+ else if (char === quote) quote = '';
777
+ continue;
778
+ }
779
+ if (char === '"' || char === "'") {
780
+ let j = i + 1;
781
+ let value = '';
782
+ while (j < objectText.length && objectText[j] !== char) {
783
+ if (objectText[j] === '\\') j += 1;
784
+ value += objectText[j];
785
+ j += 1;
786
+ }
787
+ if (depth === 0 && /^name$/i.test(value.trim())) {
788
+ const match = objectText.slice(j + 1).match(/^\s*:\s*["']([^"']*)["']/);
789
+ if (match) return match[1];
790
+ }
791
+ i = j;
792
+ continue;
793
+ }
794
+ if (char === '{' || char === '[') depth += 1;
795
+ else if (char === '}' || char === ']') depth -= 1;
796
+ }
797
+ return '';
798
+ }
799
+
800
+ function moduleAbilities(text) {
801
+ const clean = stripJson5Comments(text);
802
+ const start = clean.search(/["']abilities["']\s*:\s*\[/i);
803
+ if (start < 0) return [];
804
+ const open = clean.indexOf('[', start);
805
+ if (open < 0) return [];
806
+ const arrayText = balancedSlice(clean, open, '[', ']');
807
+ if (!arrayText) return [];
808
+ const abilities = [];
809
+ let cursor = 0;
810
+ while (cursor < arrayText.length) {
811
+ const brace = arrayText.indexOf('{', cursor);
812
+ if (brace < 0) break;
813
+ const body = balancedSlice(arrayText, brace, '{', '}');
814
+ if (!body) break;
815
+ cursor = brace + body.length;
816
+ abilities.push({
817
+ name: topLevelAbilityName(body),
818
+ // The launcher entry is the ability declaring the home entity, with the
819
+ // home action (older `action.system.home` / newer `ohos.want.action.home`).
820
+ home: /entity\.system\.home/i.test(body)
821
+ && /(?:action\.system\.home|ohos\.want\.action\.home)/i.test(body),
822
+ });
823
+ }
824
+ return abilities;
825
+ }
826
+
827
+ // `aa start -a` needs the ability's own name from module.json5's abilities[]
828
+ // array, not the module-level mainElement string. Priority mirrors the
829
+ // launcher: home-skills ability → the one named by mainElement (when it really
830
+ // exists in the array) → the first ability → the caller's legacy fallback.
831
+ function json5AbilityName(file, mainElement = '') {
832
+ const text = readText(file);
833
+ if (!text) return '';
834
+ const abilities = moduleAbilities(text);
835
+ if (!abilities.length) return '';
836
+ const home = abilities.find((item) => item.name && item.home);
837
+ if (home) return home.name;
838
+ const wanted = String(mainElement || '').trim().toLowerCase();
839
+ const named = wanted ? abilities.find((item) => item.name && item.name.toLowerCase() === wanted) : null;
840
+ if (named) return named.name;
841
+ if (abilities[0]?.name) return abilities[0].name;
842
+ return '';
843
+ }
844
+
845
+ function hmosIdentity(root) {
846
+ const app = path.join(root, 'AppScope', 'app.json5');
847
+ const modules = listRecursively(root, (file) => path.basename(file).toLowerCase() === 'module.json5' && file.includes(`${path.sep}src${path.sep}main${path.sep}`), 6);
848
+ const entryModule = modules.find((file) => /(?:["']?type["']?\s*:\s*["']entry["'])/i.test(readText(file)))
849
+ || modules.find((file) => json5String(file, 'mainElement'))
850
+ || modules[0]
851
+ || '';
852
+ return {
853
+ bundle: json5String(app, 'bundleName'),
854
+ ability: json5AbilityName(entryModule, json5String(entryModule, 'mainElement'))
855
+ || json5String(entryModule, 'mainElement')
856
+ || json5String(entryModule, 'name'),
857
+ moduleFile: entryModule,
858
+ moduleRoot: entryModule ? path.resolve(entryModule, '..', '..', '..') : '',
859
+ };
860
+ }
861
+
862
+ function hmosSdkFromEntry(entry) {
863
+ for (const root of [entry.hmos_capture_project_dir, entry.path].filter(Boolean)) {
864
+ const sdk = localProperty(root, 'hwsdk.dir') || localProperty(root, 'sdk.dir');
865
+ if (sdk) return sdk;
866
+ }
867
+ return '';
868
+ }
869
+
870
+ function balancedBlockEnd(text, start) {
871
+ let depth = 0;
872
+ let quote = '';
873
+ let escaped = false;
874
+ for (let index = start; index < text.length; index += 1) {
875
+ const char = text[index];
876
+ if (quote) {
877
+ if (escaped) escaped = false;
878
+ else if (char === '\\') escaped = true;
879
+ else if (char === quote) quote = '';
880
+ continue;
881
+ }
882
+ if (char === '"' || char === "'" || char === '`') { quote = char; continue; }
883
+ if (char === '{') depth += 1;
884
+ if (char === '}' && --depth === 0) return index;
885
+ }
886
+ return text.length - 1;
887
+ }
888
+
889
+ function etsMethods(text) {
890
+ const methods = new Map();
891
+ const pattern = /(?:private\s+|public\s+|protected\s+)?([A-Za-z_$][\w$]*)\s*\([^)]*\)\s*(?::\s*[^\{]+)?\{/g;
892
+ let match;
893
+ while ((match = pattern.exec(text))) {
894
+ const open = text.indexOf('{', match.index + match[0].length - 1);
895
+ const end = balancedBlockEnd(text, open);
896
+ methods.set(match[1], { body: text.slice(open + 1, end), start: match.index, end });
897
+ pattern.lastIndex = end + 1;
898
+ }
899
+ return methods;
900
+ }
901
+
902
+ function hmosPageFiles(root) {
903
+ const identity = hmosIdentity(root);
904
+ const moduleRoot = identity.moduleRoot || root;
905
+ return [
906
+ ...listRecursively(path.join(moduleRoot, 'src', 'main', 'ets', 'pages'), (file) => /\.ets$/i.test(file), 6),
907
+ ...listRecursively(path.join(moduleRoot, 'src', 'main', 'cangjie', 'pages'), (file) => /\.cj$/i.test(file), 6),
908
+ ].sort();
909
+ }
910
+
911
+ function entryPageName(root) {
912
+ const pages = hmosPageFiles(root);
913
+ const entry = pages.find((file) => /@Entry\b/.test(readText(file)) && /\bbuild\s*\(/.test(readText(file)))
914
+ || pages.find((file) => /\bbuild\s*\(/.test(readText(file)));
915
+ return entry ? path.basename(entry, path.extname(entry)) : '';
916
+ }
917
+
918
+ function captureBinding(entry, pageName, fallbackSequence) {
919
+ const bindings = entry.ui_page_bindings || {};
920
+ const pair = Object.entries(bindings).find(([key, value]) => (
921
+ normalizedPage(key) === normalizedPage(pageName)
922
+ || normalizedPage(value?.component) === normalizedPage(pageName)
923
+ || normalizedPage(value?.capture_name) === normalizedPage(pageName)
924
+ ));
925
+ const value = pair?.[1] || {};
926
+ return {
927
+ sequence: Number(value.capture_seq) || fallbackSequence,
928
+ cacheName: value.capture_name || pageName,
929
+ clickPath: Array.isArray(value.capture_click_path) ? value.capture_click_path : null,
930
+ expectedVisible: Array.isArray(value.capture_expect_text) ? value.capture_expect_text : [],
931
+ forbiddenVisible: Array.isArray(value.capture_forbid_text) ? value.capture_forbid_text : [],
932
+ captureScroll: value.capture_scroll !== false,
933
+ };
934
+ }
935
+
936
+ function sourceStepKey(step) {
937
+ return String(step?.resource_id || step?.['resource-id'] || step?.text || step?.['content-desc'] || step?.element || '').trim().toLowerCase();
938
+ }
939
+
940
+ function sameSourcePath(left, right) {
941
+ if (left.length !== right.length) return false;
942
+ return left.every((step, index) => sourceStepKey(step) === sourceStepKey(right[index]));
943
+ }
944
+
945
+ function sourceStepSelector(step, parentState) {
946
+ const clickables = Array.isArray(parentState?.clickable_elements) ? parentState.clickable_elements : [];
947
+ const resourceId = String(step?.resource_id || step?.['resource-id'] || '').trim();
948
+ // The new-generation UTG explorer carries the tap label in the label field (the old crawler used text).
949
+ const text = String(step?.text || step?.label || '').trim();
950
+ const description = String(step?.content_desc || step?.['content-desc'] || '').trim();
951
+ const element = String(step?.element || '').trim();
952
+ let index = clickables.findIndex((candidate) => resourceId && String(candidate?.['resource-id'] || candidate?.resource_id || '').trim() === resourceId);
953
+ if (index < 0) index = clickables.findIndex((candidate) => text && String(candidate?.text || '').trim() === text);
954
+ if (index < 0) index = clickables.findIndex((candidate) => description && String(candidate?.['content-desc'] || candidate?.content_desc || '').trim() === description);
955
+ const resourceLabel = resourceId.split('/').pop()?.replace(/(?:button|btn)$/i, '').trim() || '';
956
+ // Prefer the semantic label before a shared resource id (for example every
957
+ // option in an Android single-choice dialog uses android:id/text1).
958
+ const texts = [...new Set([text, description, element, resourceLabel].filter(Boolean))];
959
+ const center = Array.isArray(step?.center) && step.center.length === 2 ? step.center.map(Number) : null;
960
+ // Record where the control sat on the SOURCE screen (normalized). Migrated
961
+ // HarmonyOS controls frequently lose their label (icon buttons carry no
962
+ // text/desc/id), so the normalized position is the geometry that survives
963
+ // wording changes and resolution differences for the positional fallback.
964
+ const screenHint = parentState?.device_info;
965
+ const screenWidth = Number(screenHint?.width_px ?? screenHint?.width);
966
+ const screenHeight = Number(screenHint?.height_px ?? screenHint?.height);
967
+ const relative = center && screenWidth > 0 && screenHeight > 0
968
+ ? [center[0] / screenWidth, center[1] / screenHeight]
969
+ : null;
970
+ return {
971
+ ...(texts[0] ? { text: texts[0], texts } : {}),
972
+ ...(index >= 0 ? { ordinal: index + 1 } : {}),
973
+ ...(center ? { center } : {}),
974
+ ...(relative ? { relative } : {}),
975
+ ...(step?.scroll_info ? { scrollInfo: step.scroll_info } : {}),
976
+ ...((step?.['long-clickable'] || step?.long_clickable) ? { longClickable: true } : {}),
977
+ };
978
+ }
979
+
980
+ // --- New-generation navigation (.hometrans/utg_static) -----------------------
981
+ // a2h-app-migrate keeps navigation in the UTG workspace instead of ui_info:
982
+ // click_paths.json : node id -> ordered steps (tap label / labels_alt / action)
983
+ // ui_elements.json : ui_info page key -> aliases (UTG node ids) + elements
984
+ // utg.json : nodes carry a slug matching the ui_info folder name
985
+ // The legacy convention (click_path inside ui_info/meta.json) stays untouched;
986
+ // this only fills the gap when a page has no legacy click_path.
987
+ function normalizedNavKey(value) {
988
+ return String(value || '').trim().toLowerCase().replace(/[-_]+/g, '_');
989
+ }
990
+
991
+ function utgNavigation(entry) {
992
+ const raw = entry.utg_static_dir;
993
+ const base = path.resolve(raw
994
+ ? (path.isAbsolute(raw) ? raw : path.join(entry.path, raw))
995
+ : path.join(entry.path, '.hometrans', 'utg_static'));
996
+ const clickPaths = readJson(path.join(base, 'click_paths.json'));
997
+ if (!clickPaths || !clickPaths.paths || typeof clickPaths.paths !== 'object') return null;
998
+ const uiElements = readJson(path.join(base, 'ui_elements.json')) || {};
999
+ const utg = readJson(path.join(base, 'utg.json')) || {};
1000
+ const slugToNode = new Map();
1001
+ for (const node of (Array.isArray(utg.nodes) ? utg.nodes : [])) {
1002
+ if (node?.slug) slugToNode.set(String(node.slug).toLowerCase(), String(node.id));
1003
+ }
1004
+ const keyToNode = new Map();
1005
+ for (const [key, value] of Object.entries(uiElements.pages || {})) {
1006
+ const aliases = Array.isArray(value?.aliases) ? value.aliases : [];
1007
+ if (aliases.length) keyToNode.set(normalizedNavKey(key), String(aliases[0]));
1008
+ }
1009
+ return { clickPaths, slugToNode, keyToNode };
1010
+ }
1011
+
1012
+ // Match a ui_info page to a UTG node: exact by folder slug / page key first,
1013
+ // then by the recorded ui_sequence label chain for crawler-named dynamic states
1014
+ // (dyn_NNN) that carry no static identity of their own.
1015
+ function utgNodeForPage(page, navigation, uiSequence) {
1016
+ if (!navigation) return '';
1017
+ const pageId = String(page?.page_id || '');
1018
+ const bySlug = navigation.slugToNode.get(pageId.toLowerCase());
1019
+ if (bySlug) return bySlug;
1020
+ const byKey = navigation.keyToNode.get(normalizedNavKey(pageId));
1021
+ if (byKey) return byKey;
1022
+ const clicks = String(uiSequence || '').split('→').map((token) => token.trim()).filter(Boolean).slice(1);
1023
+ if (!clicks.length) return '';
1024
+ let best = '';
1025
+ let bestScore = 0;
1026
+ for (const [nodeId, value] of Object.entries(navigation.clickPaths.paths)) {
1027
+ const labels = (Array.isArray(value?.labels) ? value.labels : []).map((label) => String(label).trim()).filter(Boolean);
1028
+ let score = 0;
1029
+ if (labels.length === clicks.length
1030
+ && clicks.every((token) => labels.some((label) => label.toLowerCase() === token.toLowerCase()))) {
1031
+ score = 100 + labels.length;
1032
+ } else if (!labels.length && clicks.length === 1
1033
+ && String(nodeId).split(':').pop().toLowerCase() === clicks[0].toLowerCase()) {
1034
+ // No-tap state: the crawler names the reached component in the sequence.
1035
+ score = 50;
1036
+ }
1037
+ if (score > bestScore) { bestScore = score; best = nodeId; }
1038
+ }
1039
+ return best;
1040
+ }
1041
+
1042
+ // Convert a click_paths node entry into the dashboard's click-step format,
1043
+ // keeping the tap chain only (launch / default / guarded branch steps are
1044
+ // navigation bookkeeping, not clicks). The UTG labels describe the ANDROID
1045
+ // app; the migrated HarmonyOS controls may carry no matching label, so each
1046
+ // step also gets the source capture's geometry (center / ordinal) as a
1047
+ // fallback — the same last-resort the legacy click_path steps carry.
1048
+ function utgClickSteps(pathEntry, labelIndex) {
1049
+ const steps = Array.isArray(pathEntry?.steps) ? pathEntry.steps : [];
1050
+ const labels = Array.isArray(pathEntry?.labels) ? pathEntry.labels : [];
1051
+ const labelsAlt = Array.isArray(pathEntry?.labels_alt) ? pathEntry.labels_alt : [];
1052
+ const lookupSource = (wanted) => {
1053
+ const needle = String(wanted || '').trim().toLowerCase();
1054
+ if (!needle || !labelIndex) return null;
1055
+ if (labelIndex.has(needle)) return labelIndex.get(needle);
1056
+ for (const [key, hit] of labelIndex) {
1057
+ if (key.includes(needle) || needle.includes(key)) return hit;
1058
+ }
1059
+ return null;
1060
+ };
1061
+ const result = [];
1062
+ let tapIndex = 0;
1063
+ for (const step of steps) {
1064
+ if (String(step?.action || '') !== 'tap') continue;
1065
+ const candidates = [step?.label, labels[tapIndex], labelsAlt[tapIndex]]
1066
+ .map((value) => String(value || '').trim()).filter(Boolean);
1067
+ const texts = [...new Set(candidates)];
1068
+ tapIndex += 1;
1069
+ if (!texts.length) continue;
1070
+ let center = null;
1071
+ let ordinal = 0;
1072
+ let relative = null;
1073
+ for (const candidate of texts) {
1074
+ const hit = lookupSource(candidate);
1075
+ if (!hit) continue;
1076
+ const rect = parseBoundsRect(hit.item?.bounds);
1077
+ if (rect) center = [Math.trunc((rect.x1 + rect.x2) / 2), Math.trunc((rect.y1 + rect.y2) / 2)];
1078
+ else if (Array.isArray(hit.item?.center) && hit.item.center.length === 2) center = hit.item.center.map(Number);
1079
+ ordinal = hit.index + 1;
1080
+ const hint = hit.state?.device_info;
1081
+ const screenWidth = Number(hint?.width_px ?? hint?.width);
1082
+ const screenHeight = Number(hint?.height_px ?? hint?.height);
1083
+ if (center && screenWidth > 0 && screenHeight > 0) {
1084
+ relative = [center[0] / screenWidth, center[1] / screenHeight];
1085
+ }
1086
+ break;
1087
+ }
1088
+ result.push({
1089
+ text: texts[0],
1090
+ texts,
1091
+ ...(center ? { center } : {}),
1092
+ ...(relative ? { relative } : {}),
1093
+ ...(ordinal ? { ordinal } : {}),
1094
+ });
1095
+ }
1096
+ return result;
1097
+ }
1098
+
1099
+ function sourceUiCapturePlan(entry, entryName) {
1100
+ const targetRoot = path.resolve(entry.path);
1101
+ const progress = [
1102
+ path.join(targetRoot, 'ui_info', 'batch_progress.json'),
1103
+ path.join(targetRoot, '.hometrans', 'ui_info', 'batch_progress.json'),
1104
+ ].map(readJson).find((value) => value?.pages && typeof value.pages === 'object');
1105
+ const infoRoot = uiInfoRootFor(entry);
1106
+ let sourceIndex = readJson(path.join(infoRoot, 'index.json'));
1107
+ // Current captures carry pages.json (topological page list), not the legacy
1108
+ // index.json. Its folders are named by slug(node_id) — activity_*, fragment_*,
1109
+ // overlay_*, mode_*, route_*, dyn_NNN — not page_NNN_*, so accept any folder
1110
+ // carrying a meta.json and use pages.json's order as the sequence source.
1111
+ const crawlerPages = readJson(path.join(infoRoot, 'pages.json'));
1112
+ if (!Array.isArray(sourceIndex)) {
1113
+ sourceIndex = [];
1114
+ let items = [];
1115
+ try { items = fs.readdirSync(infoRoot, { withFileTypes: true }); } catch { items = []; }
1116
+ // Crawler's pages.json (if present) is the authoritative topo order; when
1117
+ // absent, fall back to the legacy page_NNN_* convention below.
1118
+ const orderedDirs = (Array.isArray(crawlerPages?.pages) ? crawlerPages.pages : [])
1119
+ .map((row) => path.basename(String(row?.page_dir || '')))
1120
+ .filter(Boolean);
1121
+ const dirSet = new Set(items.filter((item) => item.isDirectory()).map((item) => item.name));
1122
+ // Skip crawler internal dirs (_attempts, _dyn_tmp_*); only keep folders that
1123
+ // actually hold a meta.json.
1124
+ const seen = new Set();
1125
+ const collect = (dirName) => {
1126
+ if (!dirName || seen.has(dirName) || !dirSet.has(dirName)) return;
1127
+ seen.add(dirName);
1128
+ const meta = readJson(path.join(infoRoot, dirName, 'meta.json'));
1129
+ if (meta && typeof meta === 'object') sourceIndex.push({ page_id: dirName, ...meta });
1130
+ };
1131
+ orderedDirs.forEach(collect);
1132
+ if (!sourceIndex.length) {
1133
+ for (const item of items) {
1134
+ if (!item.isDirectory() || /^page_\d+_/i.test(item.name)) collect(item.name);
1135
+ else if (/^(?:activity|fragment|overlay|mode|route|dyn)_/i.test(item.name)) collect(item.name);
1136
+ }
1137
+ }
1138
+ // Sort by pages.json topo order when available; otherwise leave dir order.
1139
+ if (orderedDirs.length) {
1140
+ const rank = new Map(orderedDirs.map((dir, index) => [dir, index]));
1141
+ sourceIndex.sort((left, right) =>
1142
+ (rank.get(String(left?.page_id || '')) ?? Number.POSITIVE_INFINITY)
1143
+ - (rank.get(String(right?.page_id || '')) ?? Number.POSITIVE_INFINITY));
1144
+ }
1145
+ }
1146
+ if (!sourceIndex.length) return [];
1147
+ const byId = new Map(sourceIndex.map((page) => [String(page?.page_id || '').toLowerCase(), page]));
1148
+ const taskIds = progress
1149
+ ? Object.keys(progress.pages).filter((id) => byId.has(id.toLowerCase()))
1150
+ : sourceIndex.map((page) => String(page?.page_id || '')).filter(Boolean);
1151
+ if (!taskIds.length) return [];
1152
+ // Preserve sourceIndex order (pages.json topo order when present). Fall back
1153
+ // to a numeric prefix only for legacy page_NNN_* names.
1154
+ const orderRank = new Map(sourceIndex.map((page, index) => [String(page?.page_id || '').toLowerCase(), index]));
1155
+ taskIds.sort((left, right) =>
1156
+ (orderRank.get(left.toLowerCase()) ?? Number.POSITIVE_INFINITY)
1157
+ - (orderRank.get(right.toLowerCase()) ?? Number.POSITIVE_INFINITY)
1158
+ || Number(left.match(/(\d+)/)?.[1] || 0) - Number(right.match(/(\d+)/)?.[1] || 0));
1159
+ const plan = [];
1160
+ // Lazy: load the UTG navigation workspace only when some page lacks the
1161
+ // legacy ui_info click_path (new-generation projects).
1162
+ let navigation = null;
1163
+ let navigationLoaded = false;
1164
+ const ensureNavigation = () => {
1165
+ if (!navigationLoaded) { navigation = utgNavigation(entry); navigationLoaded = true; }
1166
+ return navigation;
1167
+ };
1168
+ const uiSequenceByDir = new Map((Array.isArray(crawlerPages?.pages) ? crawlerPages.pages : [])
1169
+ .map((row) => [path.basename(String(row?.page_dir || '')), String(row?.ui_sequence || '')]));
1170
+ // Label -> source geometry across every captured page: a tap step happens on
1171
+ // some earlier state (the home page for "button settings", the settings page
1172
+ // for "Select language"), which can be a different ui_info capture than the
1173
+ // step's target page.
1174
+ const sourceLabelIndex = new Map();
1175
+ for (const page of sourceIndex) {
1176
+ for (const [index, item] of (Array.isArray(page.clickable_elements) ? page.clickable_elements : []).entries()) {
1177
+ for (const value of [item?.text, item?.['content-desc'], item?.['resource-id']]) {
1178
+ const key = String(value || '').trim().toLowerCase();
1179
+ if (key && !sourceLabelIndex.has(key)) sourceLabelIndex.set(key, { item, index, state: page });
1180
+ }
1181
+ }
1182
+ }
1183
+ for (const taskId of taskIds) {
1184
+ const sourcePage = byId.get(taskId.toLowerCase());
1185
+ const sourcePath = Array.isArray(sourcePage?.click_path) ? sourcePage.click_path : [];
1186
+ let clickPath = sourcePath.map((step, stepIndex) => {
1187
+ // The new-generation UTG explorer's click_path array starts with a launch bookkeeping step and carries
1188
+ // tap labels in the label field; the legacy mapping only consumes tap — bookkeeping steps are skipped
1189
+ // (old-format steps have no action field, behavior unchanged), otherwise they get mapped to empty step
1190
+ // objects and every real-device navigation step reports "tap target not found in the current state: undefined".
1191
+ if (step?.action && step.action !== 'tap') return null;
1192
+ const prefix = sourcePath.slice(0, stepIndex);
1193
+ const parentState = sourceIndex.find((page) => sameSourcePath(Array.isArray(page?.click_path) ? page.click_path : [], prefix));
1194
+ return sourceStepSelector(step, parentState);
1195
+ }).filter(Boolean);
1196
+ // A page resolved through the UTG workspace may live on a different ArkUI
1197
+ // page than the app entry (e.g. the Settings page hosting the dialogs), so
1198
+ // the entry-page name no longer identifies it. Identity is then left to the
1199
+ // bundle + structure gates. The legacy click_path path keeps its name gate.
1200
+ let viaUtg = false;
1201
+ // New-generation click_path pages have the same property: the migrated
1202
+ // landing page is routinely NOT the entry page (SubActivity → pages/SubPage.ets),
1203
+ // so the entry-name gate would misflag every correct capture as mismatched.
1204
+ const newGeneration = sourcePath.some((step) => step?.action);
1205
+ if (!clickPath.length) {
1206
+ const nav = ensureNavigation();
1207
+ const nodeId = utgNodeForPage(sourcePage, nav, uiSequenceByDir.get(String(sourcePage?.page_id || '')));
1208
+ const node = nodeId && nav ? nav.clickPaths.paths[nodeId] : null;
1209
+ if (node) { clickPath = utgClickSteps(node, sourceLabelIndex); viaUtg = true; }
1210
+ }
1211
+ const expectedVisible = clickPath.length
1212
+ ? [...new Set((sourcePage?.clickable_elements || []).map((item) => String(item?.text || '').trim()).filter(Boolean))].slice(0, 6)
1213
+ : [];
1214
+ const sourceDir = path.join(infoRoot, String(sourcePage?.page_id || ''));
1215
+ const sourceXml = readText(path.join(sourceDir, 'view.xml'));
1216
+ const expectedStructure = normalizedStructure(sourcePage?.clickable_elements, sourceXml, sourcePage?.device_info);
1217
+ const expectedTexts = xmlTextCorpus(sourceXml, sourcePage?.clickable_elements);
1218
+ const sequence = Number(taskId.match(/page_(\d+)/i)?.[1])
1219
+ || (orderRank.has(taskId.toLowerCase()) ? orderRank.get(taskId.toLowerCase()) + 1 : 0)
1220
+ || plan.length + 1;
1221
+ plan.push({
1222
+ name: taskId,
1223
+ stateLabel: sourcePage?.label || sourcePage?.page_name || taskId,
1224
+ expectedNames: viaUtg || newGeneration ? [] : [entryName],
1225
+ sequence,
1226
+ cacheName: taskId,
1227
+ clickPath,
1228
+ expectedVisible,
1229
+ expectedStructure,
1230
+ expectedTexts,
1231
+ forbiddenVisible: [],
1232
+ captureScroll: Array.isArray(sourcePage?.screenshots) && sourcePage.screenshots.length > 1,
1233
+ taskId,
1234
+ });
1235
+ }
1236
+ return plan;
1237
+ }
1238
+
1239
+ function localAndroidScreenshots(entry) {
1240
+ const infoRoot = uiInfoRootFor(entry);
1241
+ const plan = sourceUiCapturePlan(entry, path.basename(entry.path));
1242
+ if (!plan.length) return { complete: false, found: 0, planned: 0, root: infoRoot, missing: [] };
1243
+ const missing = [];
1244
+ let found = 0;
1245
+ for (const page of plan) {
1246
+ const pageDir = path.join(infoRoot, page.taskId || page.name);
1247
+ const validation = validateAndroidCapture(pageDir);
1248
+ if (validation.ok) found += 1;
1249
+ else missing.push({ page: page.taskId || page.name, reason: validation.reason });
1250
+ }
1251
+ return { complete: missing.length === 0, found, planned: plan.length, root: infoRoot, missing };
1252
+ }
1253
+
1254
+ function arktsCapturePlan(entry) {
1255
+ const root = hmosCaptureProjectRoot(entry);
1256
+ const pageFiles = hmosPageFiles(root);
1257
+ const entryName = entryPageName(root);
1258
+ if (!Object.keys(entry.ui_page_bindings || {}).length) {
1259
+ const sourcePlan = sourceUiCapturePlan(entry, entryName);
1260
+ if (sourcePlan.length) return sourcePlan;
1261
+ }
1262
+ if (!entryName && !Object.keys(entry.ui_page_bindings || {}).length) return [];
1263
+ const entryFile = pageFiles.find((file) => path.basename(file, path.extname(file)) === entryName);
1264
+ const firstName = entryName || Object.keys(entry.ui_page_bindings || {})[0];
1265
+ const first = captureBinding(entry, firstName, 1);
1266
+ const plan = [{ name: firstName, expectedNames: [firstName], clickOrdinal: null, ...first }];
1267
+ if (entryFile && /\.cj$/i.test(entryFile)) {
1268
+ const planned = new Set(plan.map((item) => normalizedPage(item.name)));
1269
+ for (const [component, binding] of Object.entries(entry.ui_page_bindings || {})) {
1270
+ if (planned.has(normalizedPage(component)) || !Array.isArray(binding?.capture_click_path) || !binding.capture_click_path.length) continue;
1271
+ const bound = captureBinding(entry, component, plan.length + 1);
1272
+ plan.push({ name: component, stateLabel: binding.title || component, expectedNames: [binding.expected_page || firstName], ...bound });
1273
+ }
1274
+ return plan;
1275
+ }
1276
+ if (!entryFile) {
1277
+ const planned = new Set(plan.map((item) => normalizedPage(item.name)));
1278
+ for (const [component, binding] of Object.entries(entry.ui_page_bindings || {})) {
1279
+ if (planned.has(normalizedPage(component)) || !Array.isArray(binding?.capture_click_path) || !binding.capture_click_path.length) continue;
1280
+ const bound = captureBinding(entry, component, plan.length + 1);
1281
+ plan.push({ name: component, stateLabel: binding.title || component, expectedNames: [binding.expected_page || firstName], ...bound });
1282
+ }
1283
+ return plan;
1284
+ }
1285
+ const methods = etsMethods(readText(entryFile));
1286
+ const build = methods.get('build')?.body || '';
1287
+ for (const file of pageFiles) {
1288
+ const name = path.basename(file, path.extname(file));
1289
+ if (name === entryName || !/\bbuild\s*\(/.test(readText(file))) continue;
1290
+ let handler = '';
1291
+ for (const [methodName, method] of methods) {
1292
+ const routes = [...method.body.matchAll(/router\.(?:pushUrl|replaceUrl)\s*\([\s\S]*?url\s*:\s*["']pages\/([^"']+)["']/g)];
1293
+ if (routes.some((route) => normalizedPage(route[1]) === normalizedPage(name))) { handler = methodName; break; }
1294
+ }
1295
+ if (!handler) {
1296
+ plan.push({ name, error: `the entry page has no router path to pages/${name}`, ...captureBinding(entry, name, plan.length + 1) });
1297
+ continue;
1298
+ }
1299
+ const call = new RegExp(`\\bthis\\.${handler.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*\\(`).exec(build);
1300
+ const clickOrdinal = call ? [...build.slice(0, call.index).matchAll(/\.onClick\s*\(/g)].length : 0;
1301
+ plan.push({
1302
+ name,
1303
+ handler,
1304
+ clickOrdinal,
1305
+ error: clickOrdinal > 0 ? '' : `cannot determine the entry tap position for ${handler}`,
1306
+ expectedNames: [name],
1307
+ ...captureBinding(entry, name, plan.length + 1),
1308
+ });
1309
+ }
1310
+ const planned = new Set(plan.map((item) => normalizedPage(item.name)));
1311
+ for (const [component, binding] of Object.entries(entry.ui_page_bindings || {})) {
1312
+ if (planned.has(normalizedPage(component)) || !Array.isArray(binding?.capture_click_path) || !binding.capture_click_path.length) continue;
1313
+ const bound = captureBinding(entry, component, plan.length + 1);
1314
+ plan.push({
1315
+ name: component,
1316
+ stateLabel: binding.title || component,
1317
+ expectedNames: [binding.expected_page || entryName],
1318
+ clickPath: bound.clickPath,
1319
+ sequence: bound.sequence,
1320
+ cacheName: bound.cacheName,
1321
+ expectedVisible: bound.expectedVisible,
1322
+ forbiddenVisible: bound.forbiddenVisible,
1323
+ captureScroll: bound.captureScroll,
1324
+ });
1325
+ planned.add(normalizedPage(component));
1326
+ }
1327
+ return plan;
1328
+ }
1329
+
1330
+ // Positional fallback for click steps whose label did not survive migration
1331
+ // (icon buttons on HarmonyOS often carry no text/desc/id at all). The source
1332
+ // control's normalized position is matched against the live capture's
1333
+ // clickables, also normalized — so resolution differences and small layout
1334
+ // shifts are absorbed. Full-screen hit-test containers are excluded: their
1335
+ // centers sit near the middle of the screen and would shadow real controls.
1336
+ const POSITIONAL_MAX_DISTANCE = 0.15;
1337
+
1338
+ function positionalClickCoordinate(metaFile, step) {
1339
+ const relative = Array.isArray(step?.relative) && step.relative.length === 2
1340
+ ? step.relative.map(Number) : null;
1341
+ if (!relative || !Number.isFinite(relative[0]) || !Number.isFinite(relative[1])) return null;
1342
+ const meta = readJson(metaFile) || {};
1343
+ const clickables = Array.isArray(meta.clickable_elements) ? meta.clickable_elements : [];
1344
+ const screenHint = meta.device_info;
1345
+ const hintWidth = Number(screenHint?.width_px ?? screenHint?.width);
1346
+ const hintHeight = Number(screenHint?.height_px ?? screenHint?.height);
1347
+ const screen = hintWidth > 0 && hintHeight > 0
1348
+ ? { width: hintWidth, height: hintHeight }
1349
+ : screenBoundsFromXml(readText(path.join(path.dirname(metaFile), 'view.xml')));
1350
+ if (!screen) return null;
1351
+ const screenArea = screen.width * screen.height;
1352
+ let best = null;
1353
+ let bestDistance = POSITIONAL_MAX_DISTANCE;
1354
+ for (const candidate of clickables) {
1355
+ const center = Array.isArray(candidate?.center) && candidate.center.length === 2
1356
+ ? candidate.center.map(Number) : null;
1357
+ if (!center || center.some((value) => !Number.isFinite(value))) continue;
1358
+ const rect = parseBoundsRect(candidate.bounds);
1359
+ if (rect && screenArea > 0 && (rect.x2 - rect.x1) * (rect.y2 - rect.y1) > screenArea * 0.5) continue;
1360
+ const distance = Math.hypot(center[0] / screen.width - relative[0], center[1] / screen.height - relative[1]);
1361
+ if (distance < bestDistance) {
1362
+ bestDistance = distance;
1363
+ best = center;
1364
+ }
1365
+ }
1366
+ return best;
1367
+ }
1368
+
1369
+ function clickCoordinate(metaFile, step, options = {}) {
1370
+ const clickable = readJson(metaFile)?.clickable_elements || [];
1371
+ if (step && typeof step === 'object') {
1372
+ const requestedValues = [...new Set([
1373
+ step.text,
1374
+ step.label,
1375
+ ...(Array.isArray(step.texts) ? step.texts : []),
1376
+ ].map((value) => String(value || '').trim().toLowerCase()).filter(Boolean))];
1377
+ for (const requested of requestedValues) {
1378
+ const values = (candidate) => [candidate.text, candidate['content-desc'], candidate['resource-id']]
1379
+ .map((value) => String(value || '').trim().toLowerCase())
1380
+ .filter(Boolean);
1381
+ // Match an exact label first. Python's quick-capture helper also
1382
+ // accepts a contained keyword (for translated/annotated labels), so use
1383
+ // that only when no exact live-tree label exists.
1384
+ const item = clickable.find((candidate) => values(candidate).includes(requested))
1385
+ || clickable.find((candidate) => values(candidate).some((value) => value.includes(requested)));
1386
+ if (Array.isArray(item?.center) && item.center.length === 2) return item.center.map(Number);
1387
+ // HDC frequently puts the visible label on a non-clickable Text child
1388
+ // while the surrounding Row owns the click action. Resolve that label
1389
+ // back to its nearest clickable ancestor, matching the Python navigator.
1390
+ const xml = readText(path.join(path.dirname(metaFile), 'view.xml'));
1391
+ const stack = [];
1392
+ const tagPattern = /<node\b([^>]*?)(\/?)>|<\/node\s*>/gi;
1393
+ let tag;
1394
+ while ((tag = tagPattern.exec(xml))) {
1395
+ if (tag[0].startsWith('</')) { stack.pop(); continue; }
1396
+ const attrs = xmlAttributes(tag[1]);
1397
+ const labels = [attrs.text, attrs['content-desc'], attrs['resource-id']]
1398
+ .map((value) => String(value || '').trim().toLowerCase()).filter(Boolean);
1399
+ const current = { attrs };
1400
+ stack.push(current);
1401
+ if (labels.includes(requested) || labels.some((value) => value.includes(requested))) {
1402
+ const owner = [...stack].reverse().find((node) => (
1403
+ [node.attrs.clickable, node.attrs['long-clickable'], node.attrs.checkable].some(truthyXml)
1404
+ ));
1405
+ const bounds = String(owner?.attrs.bounds || '').match(/\[(-?\d+),(-?\d+)\]\[(-?\d+),(-?\d+)\]/);
1406
+ if (bounds) {
1407
+ const [, x1, y1, x2, y2] = bounds.map(Number);
1408
+ return [Math.trunc((x1 + x2) / 2), Math.trunc((y1 + y2) / 2)];
1409
+ }
1410
+ }
1411
+ if (tag[2] === '/') stack.pop();
1412
+ }
1413
+ }
1414
+ if (options.requireLiveLabel) return null;
1415
+ // Semantic ladder, position before raw geometry: the label survived →
1416
+ // click the live twin; otherwise the normalized source position picks the
1417
+ // nearest live clickable; only then fall back to the raw Android center
1418
+ // (wrong once the resolution differs) and the recorded ordinal.
1419
+ const positional = positionalClickCoordinate(metaFile, step);
1420
+ if (positional) return positional;
1421
+ const fallback = Array.isArray(step.center) && step.center.length === 2 ? step.center.map(Number) : null;
1422
+ step = Number(step.ordinal);
1423
+ if ((!Number.isInteger(step) || step < 1 || step > clickable.length) && fallback) return fallback;
1424
+ }
1425
+ const ordinal = Number(step);
1426
+ if (!Number.isInteger(ordinal) || ordinal < 1 || ordinal > clickable.length) return null;
1427
+ const center = clickable[ordinal - 1]?.center;
1428
+ return Array.isArray(center) && center.length === 2 ? center.map(Number) : null;
1429
+ }
1430
+
1431
+ function permissionAllowCoordinate(metaFile) {
1432
+ const labels = [
1433
+ 'only this time',
1434
+ 'while using the app',
1435
+ 'while using the app',
1436
+ 'only this time',
1437
+ 'while using the app',
1438
+ 'always allow',
1439
+ 'allow',
1440
+ 'while using the app',
1441
+ 'allow only while using the app',
1442
+ 'only this time',
1443
+ 'allow',
1444
+ ];
1445
+ for (const text of labels) {
1446
+ const coordinate = clickCoordinate(metaFile, { text });
1447
+ if (coordinate) return coordinate;
1448
+ }
1449
+ return null;
1450
+ }
1451
+
1452
+ function isPermissionCapture(dir) {
1453
+ const meta = readJson(path.join(dir, 'meta.json')) || {};
1454
+ const xml = readText(path.join(dir, 'view.xml'));
1455
+ return normalizedPage(meta.page_name) === 'permissiongrantdialog'
1456
+ || /permission_dialog_vertical_button/i.test(xml)
1457
+ || /while using the app|allow only while using the app|only this time|allow(?: access)?/i.test(xml);
1458
+ }
1459
+
1460
+ function toolEnvironment(executable, env = process.env) {
1461
+ const folder = path.dirname(executable);
1462
+ // Windows env blocks may store the variable as "Path"; Node's process.env
1463
+ // bridges both spellings, but a spread copy does not. Read either spelling
1464
+ // and emit a single canonical PATH so child spawns can resolve executables.
1465
+ const base = envPathValue(env);
1466
+ const merged = { ...env, PATH: `${folder}${path.delimiter}${base}` };
1467
+ delete merged.Path;
1468
+ return merged;
1469
+ }
1470
+
1471
+ function hdcTargetArgs(target) {
1472
+ return target ? ['-t', target] : [];
1473
+ }
1474
+
1475
+ function selectTarget(platform, targets, entry = {}) {
1476
+ const configured = String(entry.hmos_device || '').trim();
1477
+ if (configured) {
1478
+ if (!targets.includes(configured)) throw new Error(`Configured ${platform} device ${configured} is not connected; available: ${targets.join(', ') || 'none'}`);
1479
+ return configured;
1480
+ }
1481
+ return targets[0] || '';
1482
+ }
1483
+
1484
+ function validateAndroidCapture(dir, expectedPackage = '', options = {}) {
1485
+ const metaFile = path.join(dir, 'meta.json');
1486
+ const meta = readJson(metaFile);
1487
+ const screenshot = screenshotIn(dir, false);
1488
+ const xmlFile = path.join(dir, 'view.xml');
1489
+ if (!meta || !exists(xmlFile) || !screenshot) return { ok: false, reason: "meta.json, view.xml, or the screenshot file is missing" };
1490
+ if (expectedPackage) {
1491
+ const evidence = `${JSON.stringify(meta.activity_info || {})}\n${readText(xmlFile)}`.toLowerCase();
1492
+ if (!evidence.includes(String(expectedPackage).toLowerCase())) {
1493
+ return { ok: false, reason: `The foreground page does not belong to ${expectedPackage}` };
1494
+ }
1495
+ }
1496
+ if (options.mustDifferFromMeta && !captureStateChanged(options.mustDifferFromMeta, metaFile)) {
1497
+ return { ok: false, reason: "The page structure did not change after the tap; the target page or dialog did not actually open" };
1498
+ }
1499
+ return { ok: true, screenshot };
1500
+ }
1501
+
1502
+ async function runHdc(executable, args, context, timeoutMs = 30_000) {
1503
+ const result = await context.runner(executable, [...hdcTargetArgs(context.device), ...args], { cwd: context.cwd, timeoutMs, env: context.env });
1504
+ if (result.code !== 0) throw new Error(commandFailure(result, `hdc ${args.join(' ')} failed`));
1505
+ return result;
1506
+ }
1507
+
1508
+ async function launchHmosAbility(entry, identity, context) {
1509
+ const projectRoot = hmosCaptureProjectRoot(entry);
1510
+ // `aa force-stop` is best-effort: a first install or platform version can
1511
+ // report a non-zero code even though the following cold start is valid.
1512
+ // The start command itself remains a strict, receipt-validated gate.
1513
+ await context.runner(context.executable, [...hdcTargetArgs(context.device), 'shell', 'aa', 'force-stop', identity.bundle], {
1514
+ cwd: projectRoot, timeoutMs: 15_000, env: context.env,
1515
+ });
1516
+ const result = await runHdc(context.executable, ['shell', 'aa', 'start', '-a', identity.ability, '-b', identity.bundle], { ...context, cwd: projectRoot });
1517
+ const output = `${result.stdout || ''}\n${result.stderr || ''}`;
1518
+ if (!/start ability successfully/i.test(output)) {
1519
+ throw new Error(`aa start returned no standard success receipt: ${output.trim().slice(-400) || 'no output'}`);
1520
+ }
1521
+ }
1522
+
1523
+ async function captureHdcState(captureRoot, outputDir, projectRoot, context, maxScrolls = 0, attempts = 3) {
1524
+ const limit = Math.max(1, Number(attempts) || 1);
1525
+ let result = { code: null, stdout: '', stderr: '' };
1526
+ for (let attempt = 1; attempt <= limit; attempt += 1) {
1527
+ if (exists(outputDir)) removeGeneratedDir(captureRoot, outputDir);
1528
+ result = await context.runner(NODE, [
1529
+ PAGE_CAPTURE_SCRIPT, '--device', 'hdc', '--serial', context.device,
1530
+ '-o', outputDir, '--max-scrolls', String(maxScrolls),
1531
+ ], { cwd: projectRoot, timeoutMs: context.timeoutMs || 90_000, env: context.env });
1532
+ if (result.code === 0 && exists(path.join(outputDir, 'meta.json'))) {
1533
+ return { ok: true, result, attempts: attempt };
1534
+ }
1535
+ if (exists(outputDir)) removeGeneratedDir(captureRoot, outputDir);
1536
+ if (attempt < limit) await new Promise((resolve) => setTimeout(resolve, 600 * attempt));
1537
+ }
1538
+ return { ok: false, result, attempts: limit };
1539
+ }
1540
+
1541
+ async function captureHmosEntry(entry, context) {
1542
+ const projectRoot = hmosCaptureProjectRoot(entry);
1543
+ const hap = latestSignedHap(projectRoot, entry.hmos_hap);
1544
+ if (!hap) throw new Error('No installable *-signed.hap found (unsigned HAPs are not used for device capture)');
1545
+ const identity = hmosIdentity(projectRoot);
1546
+ if (!identity.bundle || !identity.ability) throw new Error('Cannot determine bundleName or mainElement from app.json5/module.json5');
1547
+ if (!exists(PAGE_CAPTURE_SCRIPT)) throw new Error(`HDC page capture script not found: ${PAGE_CAPTURE_SCRIPT}`);
1548
+ const captureRoot = captureRootFor(entry);
1549
+ fs.mkdirSync(captureRoot, { recursive: true });
1550
+ const fullPlan = arktsCapturePlan(entry);
1551
+ const requestedSequences = new Set((Array.isArray(entry.hmos_capture_sequences) ? entry.hmos_capture_sequences : [])
1552
+ .map(Number).filter((value) => Number.isInteger(value) && value > 0));
1553
+ const plan = requestedSequences.size
1554
+ ? fullPlan.filter((page) => requestedSequences.has(Number(page.sequence)))
1555
+ : fullPlan;
1556
+ if (!plan.length) throw new Error('No ArkTS page was discovered in the entry module; configure ui_page_bindings for explicit capture navigation');
1557
+ // Skip reinstall when the same bundleName is already installed — preserves the skip state of first-run
1558
+ // onboarding pages, so apps with a privacy-consent page (like CoolMall) don't get stuck on it every capture.
1559
+ // A changed HAP (code update) still forces reinstall — the HAP path's mtime is compared with the device install time.
1560
+ const hdcList = await context.runner(context.executable, [...hdcTargetArgs(context.device), 'shell', 'bm', 'dump', '-a'], {
1561
+ cwd: projectRoot, timeoutMs: 30_000, env: context.env,
1562
+ });
1563
+ const listOutput = `${hdcList.stdout || ''}\n${hdcList.stderr || ''}`;
1564
+ const alreadyInstalled = listOutput.includes(identity.bundle);
1565
+ if (!alreadyInstalled) {
1566
+ const install = await context.runner(context.executable, [...hdcTargetArgs(context.device), 'install', '-r', hap], { cwd: projectRoot, timeoutMs: 90_000, env: context.env });
1567
+ const installOutput = `${install.stdout || ''}\n${install.stderr || ''}`;
1568
+ if (install.code !== 0 && !/successfully/i.test(installOutput)) throw new Error(`HAP install failed: ${commandFailure(install, 'unknown error')}`);
1569
+ }
1570
+ let captured = 0;
1571
+ let entryMeta = '';
1572
+ const errors = [];
1573
+ const warnings = [];
1574
+ const captureAttempts = Math.max(1, Number(entry.hmos_capture_attempts) || 3);
1575
+ const captureTimeoutMs = Number(entry.hmos_capture_timeout_ms) || 90_000;
1576
+ const stateRetryLimit = Math.max(0, Number(entry.hmos_state_retry_limit) || 2);
1577
+ const captureContext = { ...context, timeoutMs: captureTimeoutMs };
1578
+ for (const page of plan) {
1579
+ if (page.error) { errors.push(`${page.name}: ${page.error}`); continue; }
1580
+ const pendingDir = path.join(captureRoot, `.pending_hmos_${page.sequence}_${safeName(page.cacheName)}_${process.pid}`);
1581
+ const finalDir = path.join(captureRoot, `hmos_page_${page.sequence}_${safeName(page.cacheName)}`);
1582
+ const cachedMeta = path.join(finalDir, 'meta.json');
1583
+ if (exists(pendingDir)) removeGeneratedDir(captureRoot, pendingDir);
1584
+ await launchHmosAbility(entry, identity, context);
1585
+ // A live weather page can still be replacing its startup/loading layer at
1586
+ // 1.5s. Clicking during that transition is accepted by `uiInput` but is
1587
+ // discarded by ArkUI, which previously saved the unchanged home page as a
1588
+ // secondary state. Match the stable manual/Android capture settle window.
1589
+ await new Promise((resolve) => setTimeout(resolve, Number(entry.capture_launch_wait_ms) || 4_000));
1590
+ const clickPath = page.clickPath || (page.clickOrdinal ? [page.clickOrdinal] : []);
1591
+ let currentMeta = entryMeta;
1592
+ let navigationFailed = false;
1593
+ const traversed = [];
1594
+ if (clickPath.length) {
1595
+ const rootStateDir = path.join(captureRoot, `.pending_navigation_${process.pid}_${page.sequence}_root`);
1596
+ if (exists(rootStateDir)) removeGeneratedDir(captureRoot, rootStateDir);
1597
+ let rootCapture = await captureHdcState(captureRoot, rootStateDir, projectRoot, captureContext, 0, captureAttempts);
1598
+ let rootState = rootCapture.result;
1599
+ if (!rootCapture.ok) {
1600
+ errors.push(`${page.name}: still cannot capture the navigation start page after ${rootCapture.attempts} first-round retries`);
1601
+ navigationFailed = true;
1602
+ } else {
1603
+ enrichCaptureMeta(rootStateDir);
1604
+ currentMeta = path.join(rootStateDir, 'meta.json');
1605
+ }
1606
+ // A newly installed app can present multiple permission sheets one
1607
+ // after another. Drain every sheet before resolving an ordinal click;
1608
+ // otherwise "first clickable" refers to the system dialog instead of
1609
+ // the app's search/settings button and the exposed home page is falsely
1610
+ // recorded as the requested secondary state.
1611
+ let rootPermissionAttempts = 0;
1612
+ while (!navigationFailed && isPermissionCapture(rootStateDir) && rootPermissionAttempts < 4) {
1613
+ const permissionCenter = permissionAllowCoordinate(currentMeta);
1614
+ if (!permissionCenter) {
1615
+ errors.push(`${page.name}: a system permission dialog was detected before navigation, but no allow button was found`);
1616
+ navigationFailed = true;
1617
+ break;
1618
+ }
1619
+ await runHdc(context.executable, ['shell', 'uitest', 'uiInput', 'click', String(permissionCenter[0]), String(permissionCenter[1])], { ...context, cwd: projectRoot });
1620
+ removeGeneratedDir(captureRoot, rootStateDir);
1621
+ await new Promise((resolve) => setTimeout(resolve, 1_500));
1622
+ rootCapture = await captureHdcState(captureRoot, rootStateDir, projectRoot, captureContext, 0, captureAttempts);
1623
+ rootState = rootCapture.result;
1624
+ if (!rootCapture.ok) {
1625
+ errors.push(`${page.name}: after handling the system permission dialog, still cannot recapture the navigation start after ${rootCapture.attempts} first-round retries`);
1626
+ navigationFailed = true;
1627
+ break;
1628
+ }
1629
+ enrichCaptureMeta(rootStateDir);
1630
+ currentMeta = path.join(rootStateDir, 'meta.json');
1631
+ rootPermissionAttempts += 1;
1632
+ }
1633
+ if (!navigationFailed && isPermissionCapture(rootStateDir)) {
1634
+ errors.push(`${page.name}: still a system permission dialog after ${rootPermissionAttempts} consecutive attempts`);
1635
+ navigationFailed = true;
1636
+ }
1637
+ }
1638
+ if (navigationFailed) continue;
1639
+ for (let stepIndex = 0; stepIndex < clickPath.length; stepIndex += 1) {
1640
+ const step = clickPath[stepIndex];
1641
+ const click = clickCoordinate(currentMeta, step);
1642
+ if (!click) {
1643
+ const stepLabel = typeof step === 'object' ? (step.text || step.label || step.ordinal) : step;
1644
+ errors.push(`${page.name}: tap target not found in the current state: ${stepLabel}`);
1645
+ navigationFailed = true;
1646
+ break;
1647
+ }
1648
+ await runHdc(context.executable, ['shell', 'uitest', 'uiInput', 'click', String(click[0]), String(click[1])], { ...context, cwd: projectRoot });
1649
+ await new Promise((resolve) => setTimeout(resolve, Number(entry.capture_navigation_wait_ms) || 1_200));
1650
+ traversed.push(step);
1651
+ if (stepIndex < clickPath.length - 1) {
1652
+ const navigationDir = path.join(captureRoot, `.pending_navigation_${process.pid}_${page.sequence}_${stepIndex}`);
1653
+ if (exists(navigationDir)) removeGeneratedDir(captureRoot, navigationDir);
1654
+ let navigationCapture = await captureHdcState(captureRoot, navigationDir, projectRoot, captureContext, 0, captureAttempts);
1655
+ if (!navigationCapture.ok) {
1656
+ errors.push(`${page.name}: intermediate navigation state capture still failed after ${navigationCapture.attempts} first-round retries`);
1657
+ navigationFailed = true;
1658
+ break;
1659
+ }
1660
+ enrichCaptureMeta(navigationDir);
1661
+ const nextStep = clickPath[stepIndex + 1];
1662
+ let nextMeta = path.join(navigationDir, 'meta.json');
1663
+ let transitionRetries = 0;
1664
+ // A successful dump only proves that *some* state was captured. It
1665
+ // does not prove the preceding click opened the requested layer. Do
1666
+ // not advance to Android fallback coordinates until the next live
1667
+ // HarmonyOS click target is actually visible.
1668
+ while (!clickCoordinate(nextMeta, nextStep, { requireLiveLabel: true }) && transitionRetries < stateRetryLimit) {
1669
+ transitionRetries += 1;
1670
+ await runHdc(context.executable, ['shell', 'uitest', 'uiInput', 'click', String(click[0]), String(click[1])], { ...context, cwd: projectRoot });
1671
+ await new Promise((resolve) => setTimeout(resolve, (Number(entry.capture_navigation_wait_ms) || 1_200) + transitionRetries * 600));
1672
+ navigationCapture = await captureHdcState(captureRoot, navigationDir, projectRoot, captureContext, 0, captureAttempts);
1673
+ if (!navigationCapture.ok) break;
1674
+ enrichCaptureMeta(navigationDir);
1675
+ nextMeta = path.join(navigationDir, 'meta.json');
1676
+ }
1677
+ if (!navigationCapture.ok) {
1678
+ const nextLabel = typeof nextStep === 'object' ? (nextStep.text || nextStep.label || nextStep.ordinal) : nextStep;
1679
+ errors.push(`${page.name}: capturing the intermediate state after tap step ${stepIndex + 1} failed; next target is ${nextLabel}`);
1680
+ navigationFailed = true;
1681
+ break;
1682
+ }
1683
+ currentMeta = nextMeta;
1684
+ }
1685
+ }
1686
+ if (navigationFailed) continue;
1687
+ // Stability precheck: after a click path, wait until two consecutive
1688
+ // layout dumps are identical before the final screenshot, so a
1689
+ // still-closing dialog or mid-transition layer is not frozen into the
1690
+ // capture. A timeout here is not an error — the structure validation
1691
+ // remains the acceptance gate.
1692
+ if (clickPath.length) {
1693
+ const stabilityDir = path.join(captureRoot, `.pending_stability_${page.sequence}_${process.pid}`);
1694
+ if (exists(stabilityDir)) removeGeneratedDir(captureRoot, stabilityDir);
1695
+ await context.runner(NODE, [
1696
+ PAGE_CAPTURE_SCRIPT, '--device', 'hdc', '--serial', context.device,
1697
+ '-o', stabilityDir, '--stability-only',
1698
+ ], { cwd: projectRoot, timeoutMs: 60_000, env: context.env });
1699
+ if (exists(stabilityDir)) removeGeneratedDir(captureRoot, stabilityDir);
1700
+ }
1701
+ const maxScrolls = page.captureScroll === false ? 0 : (Number(entry.capture_max_scrolls) || 10);
1702
+ let pageCapture = await captureHdcState(captureRoot, pendingDir, projectRoot, captureContext, maxScrolls, captureAttempts);
1703
+ let result = pageCapture.result;
1704
+ if (!pageCapture.ok) {
1705
+ errors.push(`${page.name}: screenshot still failed after ${pageCapture.attempts} first-round retries: ${commandFailure(result, 'screenshot command failed')}`);
1706
+ // A long-scroll frame can fail after a valid entry capture was already
1707
+ // promoted by a previous attempt. Keep navigation independent: reuse
1708
+ // that validated entry geometry so one flaky frame does not suppress
1709
+ // every secondary page in the same freshly installed app.
1710
+ if (!clickPath.length && exists(cachedMeta)) entryMeta = cachedMeta;
1711
+ continue;
1712
+ }
1713
+ let meta = enrichCaptureMeta(pendingDir, { expectedVisible: page.expectedVisible });
1714
+ let pageXml = readText(path.join(pendingDir, 'view.xml'));
1715
+ let permissionDialog = normalizedPage(meta.page_name) === 'permissiongrantdialog'
1716
+ || /while using the app|only this time|allow(?: access)?/i.test(pageXml);
1717
+ let permissionFailed = false;
1718
+ let permissionAttempts = 0;
1719
+ while (permissionDialog && permissionAttempts < 3) {
1720
+ const permissionCenter = permissionAllowCoordinate(path.join(pendingDir, 'meta.json'));
1721
+ if (!permissionCenter) {
1722
+ removeGeneratedDir(captureRoot, pendingDir);
1723
+ errors.push(`${page.name}: a system permission dialog was detected, but no "allow" button was found; the old cache is kept`);
1724
+ permissionFailed = true;
1725
+ break;
1726
+ }
1727
+ await runHdc(context.executable, ['shell', 'uitest', 'uiInput', 'click', String(permissionCenter[0]), String(permissionCenter[1])], { ...context, cwd: projectRoot });
1728
+ removeGeneratedDir(captureRoot, pendingDir);
1729
+ await new Promise((resolve) => setTimeout(resolve, 800));
1730
+ pageCapture = await captureHdcState(captureRoot, pendingDir, projectRoot, captureContext, maxScrolls, captureAttempts);
1731
+ result = pageCapture.result;
1732
+ if (!pageCapture.ok) {
1733
+ errors.push(`${page.name}: screenshot still failed after handling the permission dialog and ${pageCapture.attempts} first-round retries; the old cache is kept`);
1734
+ permissionFailed = true;
1735
+ break;
1736
+ }
1737
+ meta = enrichCaptureMeta(pendingDir, { expectedVisible: page.expectedVisible });
1738
+ pageXml = readText(path.join(pendingDir, 'view.xml'));
1739
+ permissionDialog = normalizedPage(meta.page_name) === 'permissiongrantdialog'
1740
+ || /while using the app|only this time|allow(?: access)?/i.test(pageXml);
1741
+ permissionAttempts += 1;
1742
+ }
1743
+ if (permissionFailed) continue;
1744
+ if (permissionDialog) {
1745
+ removeGeneratedDir(captureRoot, pendingDir);
1746
+ errors.push(`${page.name}: still a system permission dialog after ${permissionAttempts} consecutive attempts; refusing to save it as an app page`);
1747
+ continue;
1748
+ }
1749
+ let validationBaselineMeta = currentMeta;
1750
+ const validatePending = () => validateHmosCapture(pendingDir, page.expectedNames || [page.name], {
1751
+ // A cold Ability launch (and, for secondary pages, a just-validated
1752
+ // entry click path) is an independent runtime fingerprint. Some HDC
1753
+ // versions still omit pagePath and report "unknown"; allow that narrow
1754
+ // case while continuing to reject every explicit mismatched page name.
1755
+ allowUnknown: true,
1756
+ expectedBundle: identity.bundle,
1757
+ requireBundle: true,
1758
+ expectedVisible: page.expectedVisible,
1759
+ expectedStructure: page.expectedStructure,
1760
+ expectedTexts: page.expectedTexts,
1761
+ forbiddenVisible: page.forbiddenVisible,
1762
+ mustDifferFromMeta: clickPath.length ? validationBaselineMeta : '',
1763
+ });
1764
+ let validation = validatePending();
1765
+ let stateRetries = 0;
1766
+ let stateRetryFailure = '';
1767
+ // A page click can be accepted by uitest while ArkUI is still replacing
1768
+ // the previous layer. Recover inside this one startup batch: inspect the
1769
+ // rejected state, resume from the latest click-path step still visible,
1770
+ // replay the remaining suffix, and recapture. This is finite work in the
1771
+ // first round; it does not restore background polling or browser-triggered
1772
+ // screenshots.
1773
+ while (!validation.ok
1774
+ && clickPath.length
1775
+ && stateRetries < stateRetryLimit
1776
+ && RETRYABLE_REASON.test(validation.reason)) {
1777
+ stateRetries += 1;
1778
+ // Validation scopes markers to the expected *final* page. When the
1779
+ // rejected state is still a modal, that intentionally hides the modal
1780
+ // controls from meta.clickable_elements. Re-enrich without final-page
1781
+ // scoping before recovery so English/Русский (or another top overlay
1782
+ // action) remains clickable.
1783
+ enrichCaptureMeta(pendingDir);
1784
+ let replayMeta = path.join(pendingDir, 'meta.json');
1785
+ let resumeAt = -1;
1786
+ for (let index = clickPath.length - 1; index >= 0; index -= 1) {
1787
+ if (clickCoordinate(replayMeta, clickPath[index], { requireLiveLabel: true })) {
1788
+ resumeAt = index;
1789
+ break;
1790
+ }
1791
+ }
1792
+ if (resumeAt >= 0) {
1793
+ for (let index = resumeAt; index < clickPath.length; index += 1) {
1794
+ const retryClick = clickCoordinate(replayMeta, clickPath[index]);
1795
+ if (!retryClick) {
1796
+ stateRetryFailure = `first-round state retry ${stateRetries} cannot continue tapping step ${index + 1}`;
1797
+ break;
1798
+ }
1799
+ if (index === clickPath.length - 1) {
1800
+ if (path.resolve(path.dirname(replayMeta)) === path.resolve(pendingDir)) {
1801
+ const retryBaselineDir = path.join(captureRoot, `.pending_navigation_${process.pid}_${page.sequence}_retry_${stateRetries}_baseline`);
1802
+ if (exists(retryBaselineDir)) removeGeneratedDir(captureRoot, retryBaselineDir);
1803
+ fs.cpSync(pendingDir, retryBaselineDir, { recursive: true });
1804
+ validationBaselineMeta = path.join(retryBaselineDir, 'meta.json');
1805
+ } else {
1806
+ validationBaselineMeta = replayMeta;
1807
+ }
1808
+ }
1809
+ await runHdc(context.executable, ['shell', 'uitest', 'uiInput', 'click', String(retryClick[0]), String(retryClick[1])], { ...context, cwd: projectRoot });
1810
+ await new Promise((resolve) => setTimeout(resolve, (Number(entry.capture_navigation_wait_ms) || 1_200) + stateRetries * 600));
1811
+ if (index < clickPath.length - 1) {
1812
+ const retryNavigationDir = path.join(captureRoot, `.pending_navigation_${process.pid}_${page.sequence}_retry_${stateRetries}_${index}`);
1813
+ const retryNavigation = await captureHdcState(captureRoot, retryNavigationDir, projectRoot, captureContext, 0, captureAttempts);
1814
+ if (!retryNavigation.ok) {
1815
+ stateRetryFailure = `first-round state retry ${stateRetries}: intermediate navigation capture failed`;
1816
+ break;
1817
+ }
1818
+ enrichCaptureMeta(retryNavigationDir);
1819
+ replayMeta = path.join(retryNavigationDir, 'meta.json');
1820
+ }
1821
+ }
1822
+ } else {
1823
+ await new Promise((resolve) => setTimeout(resolve, 1_200 + stateRetries * 600));
1824
+ }
1825
+ if (stateRetryFailure) break;
1826
+ pageCapture = await captureHdcState(captureRoot, pendingDir, projectRoot, captureContext, maxScrolls, captureAttempts);
1827
+ if (!pageCapture.ok) {
1828
+ stateRetryFailure = `screenshot command still failed after first-round state retry ${stateRetries}`;
1829
+ break;
1830
+ }
1831
+ meta = enrichCaptureMeta(pendingDir, { expectedVisible: page.expectedVisible });
1832
+ pageXml = readText(path.join(pendingDir, 'view.xml'));
1833
+ validation = validatePending();
1834
+ }
1835
+ // Advisory verdict: a mismatched capture is still real evidence of what
1836
+ // the device actually showed (navigation that did not take, reworded
1837
+ // labels, an overlay). It is promoted like any other capture and the
1838
+ // mismatch rides along in meta.json plus a status-bar warning — a correct
1839
+ // page whose wording drifted must not leave an empty slot.
1840
+ const retryNote = stateRetries ? `; ${stateRetries} internal first-round retries${stateRetryFailure ? ` (${stateRetryFailure})` : ''}` : '';
1841
+ atomicPromoteCapture(captureRoot, pendingDir, finalDir);
1842
+ const promotedMeta = path.join(finalDir, 'meta.json');
1843
+ const promotedMetaJson = readJson(promotedMeta);
1844
+ if (promotedMetaJson) {
1845
+ promotedMetaJson.validation = {
1846
+ verdict: validation.ok ? 'match' : 'mismatch',
1847
+ ...(validation.ok ? {} : { reason: validation.reason }),
1848
+ state_retries: stateRetries,
1849
+ checked_at: new Date().toISOString(),
1850
+ };
1851
+ writeJson(promotedMeta, promotedMetaJson);
1852
+ }
1853
+ if (!validation.ok) {
1854
+ warnings.push(`${page.name}: does not fully match the source page, kept (${validation.reason}${retryNote})`);
1855
+ }
1856
+ if (!clickPath.length) entryMeta = promotedMeta;
1857
+ captured += 1;
1858
+ }
1859
+ for (const item of fs.readdirSync(captureRoot, { withFileTypes: true })) {
1860
+ if (!item.isDirectory() || !item.name.startsWith(`.pending_navigation_${process.pid}_`)) continue;
1861
+ removeGeneratedDir(captureRoot, path.join(captureRoot, item.name));
1862
+ }
1863
+ if (!captured) {
1864
+ // The denominator truth travels with the error: #refreshPlatform's "X/Y pages succeeded" caliber uses
1865
+ // planned (planned page count), not the error count — multi-page failures used to be joined into one error, displaying 0/2 as 0/1.
1866
+ const message = plan.length ? errors.join(';') : 'no capturable pages (no source page snapshots found)';
1867
+ throw Object.assign(new Error(message), { planned: plan.length });
1868
+ }
1869
+ return { captured, planned: plan.length, errors, warnings };
1870
+ }
1871
+
1872
+ function platformState(status, detail = '', extra = {}) {
1873
+ return { status, detail, usingCache: status !== 'ready', updatedAt: new Date().toISOString(), ...extra };
1874
+ }
1875
+
1876
+ class DeviceCaptureManager {
1877
+ constructor(entries, options = {}) {
1878
+ this.entries = entries;
1879
+ this.runner = options.runner || runCommand;
1880
+ this.env = { ...process.env, ...(options.env || {}) };
1881
+ // A spread copy of process.env loses Node's PATH/Path case bridging on
1882
+ // Windows; without this, every env.PATH lookup below sees an empty PATH
1883
+ // and child spawns (hdc) fail with ENOENT. An explicitly
1884
+ // configured empty PATH stays empty — callers use it to simulate a
1885
+ // PATH-less environment.
1886
+ if (this.env.PATH === undefined && this.env.Path !== undefined) this.env.PATH = this.env.Path;
1887
+ if (!this.env.HOMETRANS_HDC) this.env.HOMETRANS_HDC = entries.map((entry) => entry.hmos_hdc).find(Boolean) || '';
1888
+ if (!this.env.DEVECO_SDK_HOME && !this.env.HARMONYOS_SDK_HOME && !this.env.OHOS_SDK_HOME) {
1889
+ const sdk = entries.map(hmosSdkFromEntry).find(Boolean);
1890
+ if (sdk) this.env.DEVECO_SDK_HOME = sdk;
1891
+ }
1892
+ this.pollMs = options.pollMs || 2_000;
1893
+ this.startupDeviceWaitMs = options.startupDeviceWaitMs ?? STARTUP_DEVICE_WAIT_MS;
1894
+ this.retryAfterMs = options.retryAfterMs ?? Number.POSITIVE_INFINITY;
1895
+ this.timer = null;
1896
+ this.started = false;
1897
+ this.refreshing = false;
1898
+ this.attempts = { android: { signature: '', at: 0, failed: false }, hmos: { signature: '', at: 0, failed: false } };
1899
+ this.state = {
1900
+ android: platformState('checking', "Checking UI migration artifact screenshots"),
1901
+ hmos: platformState('checking', "Checking HDC devices"),
1902
+ };
1903
+ }
1904
+
1905
+ snapshot() {
1906
+ return JSON.parse(JSON.stringify(this.state));
1907
+ }
1908
+
1909
+ async refresh(options = {}) {
1910
+ if (this.refreshing) return this.snapshot();
1911
+ this.refreshing = true;
1912
+ try {
1913
+ // The board never captures the Android side: source screenshots come
1914
+ // straight from the UI migration artifacts (ui_info), so no ADB device
1915
+ // is detected or driven — only HarmonyOS gets a live capture round.
1916
+ this.#useLocalAndroidScreenshots(this.entries.map(localAndroidScreenshots));
1917
+ const hdc = await detectHdc(this.runner, this.env);
1918
+ await this.#refreshPlatform('hmos', hdc, options.force);
1919
+ return this.snapshot();
1920
+ } finally {
1921
+ this.refreshing = false;
1922
+ }
1923
+ }
1924
+
1925
+ #useLocalAndroidScreenshots(evidence) {
1926
+ const captured = evidence.reduce((total, item) => total + item.found, 0);
1927
+ const planned = evidence.reduce((total, item) => total + item.planned, 0);
1928
+ const roots = evidence.map((item) => item.root);
1929
+ this.attempts.android = { signature: `local:${roots.join('|')}`, at: Date.now(), failed: false };
1930
+ const detail = planned > captured
1931
+ ? `Using ${captured}/${planned} UI migration artifact screenshot(s); missing pages show a placeholder on the source side`
1932
+ : `Reused ${captured} UI migration artifact screenshot(s)`;
1933
+ this.state.android = platformState('ready', detail, { captured, planned, roots, targets: [], usingCache: true, source: 'local-ui-info' });
1934
+ }
1935
+
1936
+ async #refreshPlatform(platform, connection, force = false) {
1937
+ if (!connection.connected) {
1938
+ this.attempts[platform] = { signature: '', at: 0, failed: false };
1939
+ this.state[platform] = platformState('disconnected', connection.detail, { targets: [] });
1940
+ return;
1941
+ }
1942
+ const signature = connection.targets.join('|');
1943
+ const prior = this.attempts[platform];
1944
+ const retryDue = prior.failed && Date.now() - prior.at >= this.retryAfterMs;
1945
+ if (!force && prior.signature === signature && !retryDue) return;
1946
+ this.attempts[platform] = { signature, at: Date.now(), failed: false };
1947
+ this.state[platform] = platformState('capturing', `${connection.detail}, capturing from the connected device`, { targets: connection.targets, usingCache: true });
1948
+ const errors = [];
1949
+ const warnings = [];
1950
+ let captured = 0;
1951
+ let planned = 0;
1952
+ for (const entry of this.entries) {
1953
+ try {
1954
+ entry.ui_capture_dir = captureRootFor(entry);
1955
+ const device = selectTarget(platform, connection.targets, entry);
1956
+ const result = await captureHmosEntry(entry, { runner: this.runner, executable: connection.executable, device, env: toolEnvironment(connection.executable, this.env) });
1957
+ captured += result.captured;
1958
+ planned += Number(result.planned) || 0;
1959
+ errors.push(...result.errors.map((error) => `${entry.name}/${error}`));
1960
+ warnings.push(...(Array.isArray(result.warnings) ? result.warnings : []).map((warning) => `${entry.name}/${warning}`));
1961
+ } catch (error) {
1962
+ errors.push(`${entry.name}: ${error.message || error}`);
1963
+ planned += Number(error?.planned) || 0;
1964
+ }
1965
+ }
1966
+ if (errors.length) {
1967
+ this.attempts[platform].failed = true;
1968
+ // Keep the status bar readable: the per-page failure details (often long,
1969
+ // e.g. "activity_MainActivity: screenshot still failed after 3 retries within the first round: …") are kept
1970
+ // on `errors` for debugging, NOT dumped into the one-line caption. The
1971
+ // renderLiveCaptureState bar already prefixes "Local cache fallback · " when
1972
+ // status==='error', so detail here only states the success/failure tally.
1973
+ // Denominator = planned page count, not error count: one aggregated error can cover several pages, and one
1974
+ // page can produce several error messages. When capture never even started (no plan could be built,
1975
+ // e.g. a missing signed HAP), state the reason honestly instead of forcing the X/Y formula.
1976
+ const detail = planned > 0
1977
+ ? `HarmonyOS capture succeeded for ${captured}/${planned} page(s); the rest fell back to the local cache`
1978
+ : `HarmonyOS capture could not start: ${errors[0]}`;
1979
+ this.state[platform] = platformState(
1980
+ 'error',
1981
+ detail,
1982
+ { targets: connection.targets, captured, errors, warnings, errorCount: errors.length },
1983
+ );
1984
+ } else {
1985
+ const detail = warnings.length
1986
+ ? `Captured ${captured} page(s) from the connected HarmonyOS device, ${warnings.length} of them do not fully match the source page (kept)`
1987
+ : `Captured ${captured} page(s) from the connected HarmonyOS device`;
1988
+ this.state[platform] = platformState('ready', detail, { targets: connection.targets, captured, warnings, usingCache: false });
1989
+ }
1990
+ }
1991
+
1992
+ start() {
1993
+ if (this.started) return;
1994
+ this.started = true;
1995
+ // One command invocation means one capture round. Browser reloads and
1996
+ // long-running server lifetime only rescan artifacts; they never recapture
1997
+ // a page or reinstall an app behind the user's back.
1998
+ const startedAt = Date.now();
1999
+ const tick = () => void this.refresh({ force: false }).then(() => {
2000
+ if (this.attempts.hmos.signature || Date.now() - startedAt >= this.startupDeviceWaitMs) this.stop();
2001
+ }).catch((error) => {
2002
+ const detail = error?.stack || error?.message || String(error);
2003
+ // Device capture is auxiliary. A failure must remain visible in the
2004
+ // dashboard and fall back to cache, never terminate the HTTP service.
2005
+ // The Android side never captures, so only HarmonyOS can fail here.
2006
+ this.state.hmos = platformState('error', `Device capture failed; using the local cache: ${detail}`, { errors: [detail] });
2007
+ console.error(`[a2h-dashboard-render] Device capture failed (the dashboard server keeps running): ${detail}`);
2008
+ });
2009
+ // No capture timer: one dashboard process performs exactly one startup
2010
+ // round. Browser refreshes only reread artifacts.
2011
+ tick();
2012
+ }
2013
+
2014
+ stop() {
2015
+ if (this.timer) clearInterval(this.timer);
2016
+ this.timer = null;
2017
+ }
2018
+ }
2019
+
2020
+ export {
2021
+ DeviceCaptureManager,
2022
+ RETRYABLE_REASON,
2023
+ arktsCapturePlan,
2024
+ atomicPromoteCapture,
2025
+ captureStateChanged,
2026
+ clickCoordinate,
2027
+ clickableElementsFromXml,
2028
+ captureHdcState,
2029
+ detectHdc,
2030
+ enrichCaptureMeta,
2031
+ entryPageName,
2032
+ findExecutable,
2033
+ hmosIdentity,
2034
+ hmosSdkFromEntry,
2035
+ hmosCaptureProjectRoot,
2036
+ latestSignedHap,
2037
+ launchHmosAbility,
2038
+ localAndroidScreenshots,
2039
+ permissionAllowCoordinate,
2040
+ positionalClickCoordinate,
2041
+ selectTarget,
2042
+ sourceUiCapturePlan,
2043
+ uiInfoRootFor,
2044
+ validateAndroidCapture,
2045
+ validateHmosCapture,
2046
+ normalizedStructure,
2047
+ xmlTextCorpus,
2048
+ };