@buaa_smat/hometrans 26.0.2 → 26.0.4

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 (1471) hide show
  1. package/README.md +8 -7
  2. package/agents/code-reviewer.md +111 -154
  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 +436 -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 +206 -0
  14. package/i18n/skills/a2h-app-migrate/references/config.example.json +28 -0
  15. package/i18n/skills/a2h-app-migrate/references/feature-scope.md +121 -0
  16. package/i18n/skills/a2h-app-migrate/references/specs.example.json +19 -0
  17. package/i18n/skills/a2h-app-migrate/references/stage-map.md +50 -0
  18. package/i18n/skills/a2h-app-migrate/references/workflow.yaml +2007 -0
  19. package/i18n/skills/a2h-app-migrate/scripts/check_spec_gen_done.mjs +187 -0
  20. package/i18n/skills/a2h-app-migrate/scripts/env_preflight.mjs +1656 -0
  21. package/i18n/skills/a2h-app-migrate/scripts/human_review_gate.mjs +728 -0
  22. package/i18n/skills/a2h-app-migrate/scripts/validate_workflow.mjs +541 -0
  23. package/i18n/skills/a2h-app-migrate/test/test_android_index.mjs +143 -0
  24. package/i18n/skills/a2h-app-migrate/test/test_arch_done.mjs +54 -0
  25. package/i18n/skills/a2h-app-migrate/test/test_build_fixer_contract.mjs +98 -0
  26. package/i18n/skills/a2h-app-migrate/test/test_config_example.mjs +42 -0
  27. package/i18n/skills/a2h-app-migrate/test/test_ensure_utg_snapshot.mjs +147 -0
  28. package/i18n/skills/a2h-app-migrate/test/test_env_requirements.mjs +713 -0
  29. package/i18n/skills/a2h-app-migrate/test/test_finalize.mjs +117 -0
  30. package/i18n/skills/a2h-app-migrate/test/test_image_probe.mjs +120 -0
  31. package/i18n/skills/a2h-app-migrate/test/test_interaction.mjs +122 -0
  32. package/i18n/skills/a2h-app-migrate/test/test_preflight_report.mjs +93 -0
  33. package/i18n/skills/a2h-app-migrate/test/test_resume_plan.mjs +271 -0
  34. package/i18n/skills/a2h-app-migrate/test/test_resume_summary.mjs +222 -0
  35. package/i18n/skills/a2h-app-migrate/test/test_reuse_static_utg.mjs +136 -0
  36. package/i18n/skills/a2h-app-migrate/test/test_run_dir.mjs +552 -0
  37. package/i18n/skills/a2h-app-migrate/test/test_skill_doc.mjs +144 -0
  38. package/i18n/skills/a2h-app-migrate/test/test_spec_gen_done.mjs +263 -0
  39. package/i18n/skills/a2h-app-migrate/test/test_spec_gen_gate.mjs +165 -0
  40. package/i18n/skills/a2h-app-migrate/test/test_specs_json_preflight.mjs +76 -0
  41. package/i18n/skills/a2h-app-migrate/test/test_ui_batch_gate.mjs +226 -0
  42. package/i18n/skills/a2h-app-migrate/test/test_user_facing_progress.mjs +43 -0
  43. package/i18n/skills/a2h-app-migrate/test/test_utg_static_done.mjs +207 -0
  44. package/i18n/skills/a2h-app-migrate/test/test_validate_workflow_bilingual.mjs +87 -0
  45. package/i18n/skills/a2h-arch-generate/SKILL.md +378 -0
  46. package/i18n/skills/a2h-arch-generate/examples/reconcile-existing-project.md +107 -0
  47. package/i18n/skills/a2h-arch-generate/examples/simple-conversion-backend.md +70 -0
  48. package/i18n/skills/a2h-arch-generate/references/arkts-mvvm-v2.md +1407 -0
  49. package/i18n/skills/a2h-arch-generate/references/artifact-contracts.generate.md +120 -0
  50. package/i18n/skills/a2h-arch-generate/references/artifact-contracts.reconcile.md +123 -0
  51. package/i18n/skills/a2h-arch-generate/references/bpta-layered-architecture-design.md +88 -0
  52. package/i18n/skills/a2h-arch-generate/references/database-schema-recovery.md +107 -0
  53. package/i18n/skills/a2h-arch-generate/references/existing-target-annotation.md +68 -0
  54. package/i18n/skills/a2h-arch-generate/references/harmony-project-inspection.md +150 -0
  55. package/i18n/skills/a2h-arch-generate/references/harmony-target-architecture.md +94 -0
  56. package/i18n/skills/a2h-arch-generate/references/homegraph-workflow.md +131 -0
  57. package/i18n/skills/a2h-arch-generate/references/source-baseline.md +93 -0
  58. package/i18n/skills/a2h-arch-generate/scripts/generate_source_baseline.mjs +360 -0
  59. package/i18n/skills/a2h-arch-generate/scripts/inspect_harmony_target.mjs +798 -0
  60. package/i18n/skills/a2h-arch-generate/scripts/lib/contract_terms.mjs +40 -0
  61. package/i18n/skills/a2h-arch-generate/scripts/module_create/generate.mjs +639 -0
  62. package/i18n/skills/a2h-arch-generate/scripts/module_create/testdata/reconcile-layer-PROJECT_DESIGN.md +47 -0
  63. package/i18n/skills/a2h-arch-generate/scripts/module_create/testdata/single-entry-PROJECT_DESIGN.md +15 -0
  64. package/i18n/skills/a2h-arch-generate/scripts/module_create/testdata/three-layer-PROJECT_DESIGN.md +36 -0
  65. package/i18n/skills/a2h-arch-generate/scripts/module_create/testdata/verification-report.md +150 -0
  66. package/i18n/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/pages.json +5 -0
  67. package/i18n/skills/a2h-arch-generate/scripts/tests/e2e/run_e2e.mjs +548 -0
  68. package/i18n/skills/a2h-arch-generate/scripts/tests/run_tests.mjs +1261 -0
  69. package/i18n/skills/a2h-arch-generate/scripts/tests/test_module_templates.mjs +70 -0
  70. package/i18n/skills/a2h-arch-generate/scripts/validate_architecture_docs.mjs +851 -0
  71. package/i18n/skills/a2h-arch-generate/scripts/validate_data_docs.mjs +982 -0
  72. package/i18n/skills/a2h-arkts-logic-coder/SKILL.md +304 -0
  73. package/i18n/skills/a2h-arkts-logic-coder/references/ISSUES.md +10 -0
  74. package/i18n/skills/a2h-arkts-logic-coder/references/code-generation.md +249 -0
  75. package/i18n/skills/a2h-arkts-logic-coder/references/spec-design.md +344 -0
  76. package/i18n/skills/a2h-arkts-logic-coder/scripts/design/move_spec_technical_reference.mjs +162 -0
  77. package/i18n/skills/a2h-arkts-logic-coder/scripts/design/validate_spec_design_output.mjs +298 -0
  78. package/i18n/skills/a2h-arkts-logic-coder/scripts/state_doc.mjs +877 -0
  79. package/i18n/skills/a2h-arkts-logic-coder/scripts/test_check_units.ts +149 -0
  80. package/i18n/skills/a2h-arkts-logic-coder/test/golden/move_design.md +18 -0
  81. package/i18n/skills/a2h-arkts-logic-coder/test/golden/move_design_crlf.md +18 -0
  82. package/i18n/skills/a2h-arkts-logic-coder/test/golden/move_spec.md +7 -0
  83. package/i18n/skills/a2h-arkts-logic-coder/test/golden/validate_issue_file.md +12 -0
  84. package/i18n/skills/a2h-arkts-logic-coder/test/golden/validate_issues.json +57 -0
  85. package/i18n/skills/a2h-arkts-logic-coder/test/test_spec_design_scripts.mjs +547 -0
  86. package/i18n/skills/a2h-arkts-logic-coder/test/test_state_doc.mjs +597 -0
  87. package/i18n/skills/a2h-batch-ui-align/SKILL.md +372 -0
  88. package/i18n/skills/a2h-batch-ui-align/references/cards/alignment.md +35 -0
  89. package/i18n/skills/a2h-batch-ui-align/references/cards/build.md +13 -0
  90. package/i18n/skills/a2h-batch-ui-align/references/cards/canvas.md +17 -0
  91. package/i18n/skills/a2h-batch-ui-align/references/cards/dynamics.md +27 -0
  92. package/i18n/skills/a2h-batch-ui-align/references/cards/geometry.md +85 -0
  93. package/i18n/skills/a2h-batch-ui-align/references/cards/interaction.md +23 -0
  94. package/i18n/skills/a2h-batch-ui-align/references/cards/resources.md +89 -0
  95. package/i18n/skills/a2h-batch-ui-align/references/cards/state-v1.md +29 -0
  96. package/i18n/skills/a2h-batch-ui-align/references/cards/state.md +14 -0
  97. package/i18n/skills/a2h-batch-ui-align/references/cards/widgets.md +62 -0
  98. package/i18n/skills/a2h-batch-ui-align/references/cards/window.md +30 -0
  99. package/i18n/skills/a2h-batch-ui-align/references/checker-rules.md +930 -0
  100. package/i18n/skills/a2h-batch-ui-align/references/conversion-procedure.md +420 -0
  101. package/i18n/skills/a2h-batch-ui-align/references/incremental-scope.md +158 -0
  102. package/i18n/skills/a2h-batch-ui-align/references/lottie-integration.md +43 -0
  103. package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +2552 -0
  104. package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +560 -0
  105. package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +175 -0
  106. package/i18n/skills/a2h-batch-ui-align/references/state-mgmt/_decorator-quickref.md +251 -0
  107. package/i18n/skills/a2h-batch-ui-align/references/state-mgmt/_paradigm-selection.md +28 -0
  108. package/i18n/skills/a2h-batch-ui-align/references/step3-capture.md +232 -0
  109. package/i18n/skills/a2h-batch-ui-align/references/step4-prepare.md +206 -0
  110. package/i18n/skills/a2h-batch-ui-align/references/step5-convert.md +232 -0
  111. package/i18n/skills/a2h-batch-ui-align/scripts/android_parse_fast.ts +2005 -0
  112. package/i18n/skills/a2h-batch-ui-align/scripts/branch_coverage.mjs +155 -0
  113. package/i18n/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +2118 -0
  114. package/i18n/skills/a2h-batch-ui-align/scripts/databinding_analyzer_design.md +79 -0
  115. package/i18n/skills/a2h-batch-ui-align/scripts/detect_paradigm.mjs +245 -0
  116. package/i18n/skills/a2h-batch-ui-align/scripts/draw_coverage.mjs +264 -0
  117. package/i18n/skills/a2h-batch-ui-align/scripts/export_ui_info.mjs +1805 -0
  118. package/i18n/skills/a2h-batch-ui-align/scripts/gen_rule_docs.mjs +100 -0
  119. package/i18n/skills/a2h-batch-ui-align/scripts/generate_pages_json.mjs +612 -0
  120. package/i18n/skills/a2h-batch-ui-align/scripts/group_pack.mjs +1959 -0
  121. package/i18n/skills/a2h-batch-ui-align/scripts/icon_coverage.mjs +147 -0
  122. package/i18n/skills/a2h-batch-ui-align/scripts/image_probe.mjs +405 -0
  123. package/i18n/skills/a2h-batch-ui-align/scripts/measure_pack.ts +1632 -0
  124. package/i18n/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +1300 -0
  125. package/i18n/skills/a2h-batch-ui-align/scripts/shell_contract.mjs +1234 -0
  126. package/i18n/skills/a2h-batch-ui-align/scripts/state_doc.mjs +417 -0
  127. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/core/cli.ts +134 -0
  128. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/core/i18n.ts +18 -0
  129. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/main.ts +216 -0
  130. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/a11y.ts +615 -0
  131. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/android_immersive.ts +125 -0
  132. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/attr_chain.ts +49 -0
  133. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/block_comment_break.ts +64 -0
  134. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/blur_mirrored.ts +134 -0
  135. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/builder_call_sites.ts +242 -0
  136. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/builder_invokes_callback.ts +136 -0
  137. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/canvas.ts +255 -0
  138. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/color_string.ts +109 -0
  139. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/column_shrink.ts +154 -0
  140. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/constant_coordinate.ts +39 -0
  141. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/container_align.ts +140 -0
  142. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/dialog_backboard.ts +91 -0
  143. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/entry_root_builtin.ts +69 -0
  144. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/entry_route.ts +114 -0
  145. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/event_default_click.ts +179 -0
  146. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/fixed_size_safe_area.ts +103 -0
  147. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/format_string.ts +157 -0
  148. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/framework_dialog.ts +110 -0
  149. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/framework_picker.ts +115 -0
  150. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/hit_test.ts +339 -0
  151. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/image_source.ts +84 -0
  152. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/input_traps.ts +249 -0
  153. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/layout_placement.ts +780 -0
  154. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/lottie_host.ts +145 -0
  155. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/media_content.ts +138 -0
  156. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +408 -0
  157. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/offset_in_scroll.ts +163 -0
  158. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/orphan_component.ts +119 -0
  159. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/overlay_binds.ts +56 -0
  160. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/overlay_string.ts +96 -0
  161. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/padding_in_size.ts +179 -0
  162. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/page_reachability.ts +94 -0
  163. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/path_commands_vp.ts +50 -0
  164. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/percent_height_in_scroll.ts +81 -0
  165. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/popup_menu.ts +137 -0
  166. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/r_template_string.ts +37 -0
  167. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/relative_container_height.ts +102 -0
  168. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/request_permission.ts +98 -0
  169. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/resource_as_string.ts +68 -0
  170. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/root_weight.ts +147 -0
  171. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/runtime_traps.ts +440 -0
  172. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/safe_area_clipping.ts +168 -0
  173. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/scroll_align.ts +127 -0
  174. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/scroll_delta.ts +178 -0
  175. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/sdk_api.ts +195 -0
  176. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/shared_chrome.ts +73 -0
  177. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/sheet_blur.ts +95 -0
  178. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/shell_content.ts +198 -0
  179. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/stack_occluding.ts +118 -0
  180. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/state_decorators.ts +73 -0
  181. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/state_name_shadows.ts +93 -0
  182. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/string_quote_leak.ts +73 -0
  183. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/surface_stroke.ts +50 -0
  184. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/swiper_index.ts +65 -0
  185. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/theme_color.ts +184 -0
  186. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/track_getter.ts +132 -0
  187. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/waterflow_sections.ts +231 -0
  188. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/wide_constant_width.ts +53 -0
  189. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/window_mode.ts +67 -0
  190. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_a11y.test.mjs +598 -0
  191. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_blur.test.mjs +217 -0
  192. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_builder_calls.test.mjs +323 -0
  193. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_fidelity.test.mjs +507 -0
  194. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_input_runtime.test.mjs +514 -0
  195. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_layout_placement.test.mjs +651 -0
  196. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_occlusion_offset_format.test.mjs +372 -0
  197. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_overlay_lottie.test.mjs +199 -0
  198. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_review_fixes.test.mjs +298 -0
  199. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_rules.test.mjs +365 -0
  200. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_scroll_padding_raster.test.mjs +262 -0
  201. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_weight_color.test.mjs +473 -0
  202. package/i18n/skills/a2h-batch-ui-align/scripts/tests/branch_coverage.test.mjs +116 -0
  203. package/i18n/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set.test.mjs +693 -0
  204. package/i18n/skills/a2h-batch-ui-align/scripts/tests/draw_coverage.test.mjs +245 -0
  205. package/i18n/skills/a2h-batch-ui-align/scripts/tests/export_ui_info.test.mjs +742 -0
  206. package/i18n/skills/a2h-batch-ui-align/scripts/tests/generate_pages_json.test.mjs +123 -0
  207. package/i18n/skills/a2h-batch-ui-align/scripts/tests/group_pack.test.mjs +363 -0
  208. package/i18n/skills/a2h-batch-ui-align/scripts/tests/image_probe.test.mjs +243 -0
  209. package/i18n/skills/a2h-batch-ui-align/scripts/tests/measure_pack.test.mjs +326 -0
  210. package/i18n/skills/a2h-batch-ui-align/scripts/tests/occlusion.test.mjs +102 -0
  211. package/i18n/skills/a2h-batch-ui-align/scripts/tests/phase5_check.test.mjs +356 -0
  212. package/i18n/skills/a2h-batch-ui-align/scripts/tests/skill_doc_contract.test.mjs +60 -0
  213. package/i18n/skills/a2h-batch-ui-align/scripts/tests/state_doc.test.mjs +395 -0
  214. package/i18n/skills/a2h-batch-ui-align/scripts/tests/static_check_registry.test.mjs +122 -0
  215. package/i18n/skills/a2h-batch-ui-align/scripts/tests/text_color_diff.test.mjs +250 -0
  216. package/i18n/skills/a2h-batch-ui-align/scripts/text_color_diff.mjs +470 -0
  217. package/i18n/skills/a2h-coldstart-smoke-gate/SKILL.md +62 -0
  218. package/i18n/skills/a2h-dashboard-render/SKILL.md +73 -0
  219. package/i18n/skills/a2h-dashboard-render/references/artifact-contract.jsonc +117 -0
  220. package/i18n/skills/a2h-dashboard-render/references/artifact-registry-spec.md +67 -0
  221. package/i18n/skills/a2h-dashboard-render/references/dashboard-guide.md +91 -0
  222. package/i18n/skills/a2h-dashboard-render/references/dashboard.config.example.json +19 -0
  223. package/i18n/skills/a2h-dashboard-render/scripts/dashboard.mjs +3245 -0
  224. package/i18n/skills/a2h-dashboard-render/scripts/device_capture.mjs +2050 -0
  225. package/i18n/skills/a2h-dashboard-render/test/fixtures/page_capture/expected.json +156 -0
  226. package/i18n/skills/a2h-dashboard-render/test/fixtures/page_capture/hmos.json +1 -0
  227. package/i18n/skills/a2h-dashboard-render/test/fixtures/page_capture/list.xml +1 -0
  228. package/i18n/skills/a2h-dashboard-render/test/test_artifact_contract.mjs +168 -0
  229. package/i18n/skills/a2h-dashboard-render/test/test_dashboard_architecture.mjs +118 -0
  230. package/i18n/skills/a2h-dashboard-render/test/test_dashboard_build.mjs +93 -0
  231. package/i18n/skills/a2h-dashboard-render/test/test_dashboard_i18n.mjs +154 -0
  232. package/i18n/skills/a2h-dashboard-render/test/test_dashboard_node.mjs +1369 -0
  233. package/i18n/skills/a2h-dashboard-render/test/test_dashboard_spec_pipeline.mjs +318 -0
  234. package/i18n/skills/a2h-dashboard-render/test/test_dashboard_ui_pipeline.mjs +81 -0
  235. package/i18n/skills/a2h-dashboard-render/test/test_device_capture_env.mjs +115 -0
  236. package/i18n/skills/a2h-dashboard-render/test/test_device_capture_policy.mjs +411 -0
  237. package/i18n/skills/a2h-dashboard-render/test/test_page_capture.mjs +147 -0
  238. package/i18n/skills/a2h-dashboard-render/test/test_usage_readers.mjs +512 -0
  239. package/i18n/skills/a2h-fix-build-errors/SKILL.md +304 -0
  240. package/i18n/skills/a2h-fix-build-errors/references/arkts-strict-patterns.md +219 -0
  241. package/i18n/skills/a2h-fix-build-errors/references/rdb-entity-pattern.md +131 -0
  242. package/i18n/skills/a2h-module-semantic-docs/SKILL.md +265 -0
  243. package/i18n/skills/a2h-module-semantic-docs/test/golden/module_structure.json +187 -0
  244. package/i18n/skills/a2h-module-semantic-docs/test/golden/module_understanding.json +351 -0
  245. package/i18n/skills/a2h-module-semantic-docs/test/golden/module_update_plan.json +495 -0
  246. package/i18n/skills/a2h-module-semantic-docs/test/golden/project_directory_structure.json +157 -0
  247. package/i18n/skills/a2h-module-semantic-docs/test/test_scan_and_commit.mjs +388 -0
  248. package/i18n/skills/a2h-page-specgen/SKILL.md +239 -0
  249. package/i18n/skills/a2h-page-specgen/references/behavior-ledger.md +1174 -0
  250. package/i18n/skills/a2h-page-specgen/references/body-language.md +179 -0
  251. package/i18n/skills/a2h-page-specgen/references/gates.md +329 -0
  252. package/i18n/skills/a2h-page-specgen/references/page-inventory.md +220 -0
  253. package/i18n/skills/a2h-page-specgen/references/scenario-authoring.md +274 -0
  254. package/i18n/skills/a2h-page-specgen/references/spec-example.md +312 -0
  255. package/i18n/skills/a2h-page-specgen/references/spec-template.md +210 -0
  256. package/i18n/skills/a2h-page-specgen/scripts/behavior-audit.mjs +2436 -0
  257. package/i18n/skills/a2h-page-specgen/scripts/behavior-discovery.mjs +1833 -0
  258. package/i18n/skills/a2h-page-specgen/scripts/behavior-model.mjs +181 -0
  259. package/i18n/skills/a2h-page-specgen/scripts/behavior-reconcile.mjs +1205 -0
  260. package/i18n/skills/a2h-page-specgen/scripts/entry-evidence.mjs +1123 -0
  261. package/i18n/skills/a2h-page-specgen/scripts/facts-build.mjs +1613 -0
  262. package/i18n/skills/a2h-page-specgen/scripts/footprint.mjs +1650 -0
  263. package/i18n/skills/a2h-page-specgen/scripts/gate.mjs +864 -0
  264. package/i18n/skills/a2h-page-specgen/scripts/interactions.mjs +346 -0
  265. package/i18n/skills/a2h-page-specgen/scripts/inventory.mjs +371 -0
  266. package/i18n/skills/a2h-page-specgen/scripts/lib/contracts.mjs +155 -0
  267. package/i18n/skills/a2h-page-specgen/scripts/lib/graph-evidence.mjs +235 -0
  268. package/i18n/skills/a2h-page-specgen/scripts/lib/hg.mjs +684 -0
  269. package/i18n/skills/a2h-page-specgen/scripts/lib/homegraph-process.mjs +102 -0
  270. package/i18n/skills/a2h-page-specgen/scripts/lib/homegraph-query.mjs +161 -0
  271. package/i18n/skills/a2h-page-specgen/scripts/lib/operation-reviews.mjs +913 -0
  272. package/i18n/skills/a2h-page-specgen/scripts/lib/prose.mjs +252 -0
  273. package/i18n/skills/a2h-page-specgen/scripts/lib/reach.mjs +53 -0
  274. package/i18n/skills/a2h-page-specgen/scripts/lib/semantic-detail.mjs +353 -0
  275. package/i18n/skills/a2h-page-specgen/scripts/lib/source-text.mjs +497 -0
  276. package/i18n/skills/a2h-page-specgen/scripts/operation-evidence.mjs +1542 -0
  277. package/i18n/skills/a2h-page-specgen/scripts/prepare.mjs +864 -0
  278. package/i18n/skills/a2h-page-specgen/scripts/render.mjs +276 -0
  279. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/acceptance.mjs +897 -0
  280. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.json +25 -0
  281. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md +373 -0
  282. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md +300 -0
  283. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.json +47 -0
  284. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.prompt.md +373 -0
  285. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.worker.md +300 -0
  286. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.discovery.json +2694 -0
  287. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.json +726 -0
  288. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.post-review.json +108 -0
  289. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.prompt.md +373 -0
  290. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.review.md +65 -0
  291. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.worker.md +267 -0
  292. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.json +57 -0
  293. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.prompt.md +373 -0
  294. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.worker.md +300 -0
  295. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/branch-checklist.md +32 -0
  296. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/gate-results.json +22 -0
  297. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/manifest.json +111 -0
  298. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/portability.test.mjs +141 -0
  299. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/review.md +22 -0
  300. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/run.mjs +553 -0
  301. package/i18n/skills/a2h-page-specgen/scripts/test/android-entry-evidence.test.mjs +585 -0
  302. package/i18n/skills/a2h-page-specgen/scripts/test/android-operation-evidence.test.mjs +755 -0
  303. package/i18n/skills/a2h-page-specgen/scripts/test/behavior-audit-group.test.mjs +546 -0
  304. package/i18n/skills/a2h-page-specgen/scripts/test/behavior-audit-post.test.mjs +655 -0
  305. package/i18n/skills/a2h-page-specgen/scripts/test/behavior-audit-pre.test.mjs +1234 -0
  306. package/i18n/skills/a2h-page-specgen/scripts/test/behavior-component-gate.test.mjs +520 -0
  307. package/i18n/skills/a2h-page-specgen/scripts/test/behavior-discovery.test.mjs +1516 -0
  308. package/i18n/skills/a2h-page-specgen/scripts/test/behavior-finalize.test.mjs +759 -0
  309. package/i18n/skills/a2h-page-specgen/scripts/test/behavior-fixtures.mjs +630 -0
  310. package/i18n/skills/a2h-page-specgen/scripts/test/behavior-model.test.mjs +118 -0
  311. package/i18n/skills/a2h-page-specgen/scripts/test/behavior-reconcile.test.mjs +798 -0
  312. package/i18n/skills/a2h-page-specgen/scripts/test/behavior-regression.test.mjs +886 -0
  313. package/i18n/skills/a2h-page-specgen/scripts/test/contracts.test.mjs +205 -0
  314. package/i18n/skills/a2h-page-specgen/scripts/test/entry-evidence.test.mjs +475 -0
  315. package/i18n/skills/a2h-page-specgen/scripts/test/facts.test.mjs +1205 -0
  316. package/i18n/skills/a2h-page-specgen/scripts/test/finalize.test.mjs +271 -0
  317. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/facts/i18n/zh.js.txt +8 -0
  318. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-b+zh+Hans/strings.xml +7 -0
  319. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-zh/strings.xml +8 -0
  320. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/App.vue +1 -0
  321. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/bundle-conflict-record.json +17 -0
  322. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/bundle-record.json +17 -0
  323. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/manifest.json +3 -0
  324. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/pages/list/index.vue +80 -0
  325. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/pages.json +14 -0
  326. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/source-record.json +15 -0
  327. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/src/components/RefreshPanel.vue +15 -0
  328. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/src/composables/useRefresh.ts +50 -0
  329. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/src/pages/help/index.vue +9 -0
  330. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/src/state/store.ts +4 -0
  331. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/utg/click_paths.json +28 -0
  332. package/i18n/skills/a2h-page-specgen/scripts/test/footprint-resolve.test.mjs +1029 -0
  333. package/i18n/skills/a2h-page-specgen/scripts/test/fsx.test.mjs +32 -0
  334. package/i18n/skills/a2h-page-specgen/scripts/test/gate-partial.test.mjs +143 -0
  335. package/i18n/skills/a2h-page-specgen/scripts/test/gate.test.mjs +1121 -0
  336. package/i18n/skills/a2h-page-specgen/scripts/test/graph-evidence.test.mjs +332 -0
  337. package/i18n/skills/a2h-page-specgen/scripts/test/helpers.mjs +188 -0
  338. package/i18n/skills/a2h-page-specgen/scripts/test/hg.test.mjs +549 -0
  339. package/i18n/skills/a2h-page-specgen/scripts/test/homegraph-process-fixture.mjs +130 -0
  340. package/i18n/skills/a2h-page-specgen/scripts/test/homegraph-query.test.mjs +288 -0
  341. package/i18n/skills/a2h-page-specgen/scripts/test/integration.test.mjs +368 -0
  342. package/i18n/skills/a2h-page-specgen/scripts/test/interactions.test.mjs +348 -0
  343. package/i18n/skills/a2h-page-specgen/scripts/test/inventory.test.mjs +250 -0
  344. package/i18n/skills/a2h-page-specgen/scripts/test/keys.test.mjs +776 -0
  345. package/i18n/skills/a2h-page-specgen/scripts/test/operation-reviews.test.mjs +1002 -0
  346. package/i18n/skills/a2h-page-specgen/scripts/test/plan-build.test.mjs +1103 -0
  347. package/i18n/skills/a2h-page-specgen/scripts/test/prepare-homegraph-reproduction.mjs +365 -0
  348. package/i18n/skills/a2h-page-specgen/scripts/test/prepare-homegraph.test.mjs +569 -0
  349. package/i18n/skills/a2h-page-specgen/scripts/test/prepare-pipeline.test.mjs +326 -0
  350. package/i18n/skills/a2h-page-specgen/scripts/test/prompt-tpl.test.mjs +240 -0
  351. package/i18n/skills/a2h-page-specgen/scripts/test/prose.test.mjs +427 -0
  352. package/i18n/skills/a2h-page-specgen/scripts/test/protocol-docs.test.mjs +531 -0
  353. package/i18n/skills/a2h-page-specgen/scripts/test/reach.test.mjs +93 -0
  354. package/i18n/skills/a2h-page-specgen/scripts/test/recovery-e2e.test.mjs +418 -0
  355. package/i18n/skills/a2h-page-specgen/scripts/test/recovery.test.mjs +1782 -0
  356. package/i18n/skills/a2h-page-specgen/scripts/test/render.test.mjs +536 -0
  357. package/i18n/skills/a2h-page-specgen/scripts/test/review-followup.test.mjs +467 -0
  358. package/i18n/skills/a2h-page-specgen/scripts/test/semantic-detail.test.mjs +949 -0
  359. package/i18n/skills/a2h-page-specgen/scripts/test/submit.test.mjs +1239 -0
  360. package/i18n/skills/a2h-page-specgen/scripts/test/uniapp-operation-evidence.test.mjs +639 -0
  361. package/i18n/skills/a2h-page-specgen/scripts/test/utg-footprint-contract.test.mjs +274 -0
  362. package/i18n/skills/a2h-page-specgen/scripts/test/utg-io.test.mjs +90 -0
  363. package/i18n/skills/a2h-page-specgen/scripts/test/waker-process.test.mjs +1801 -0
  364. package/i18n/skills/a2h-resource-convert/SKILL.md +375 -0
  365. package/i18n/skills/a2h-resource-convert/references/code-vector-icon-rules.md +336 -0
  366. package/i18n/skills/a2h-resource-convert/references/incremental-page-migration.md +272 -0
  367. package/i18n/skills/a2h-resource-convert/references/lottie-conversion-rules.md +226 -0
  368. package/i18n/skills/a2h-resource-convert/references/resource-mapping-rules.md +493 -0
  369. package/i18n/skills/a2h-resource-convert/references/step4-resource-types.md +251 -0
  370. package/i18n/skills/a2h-resource-convert/references/step7-report-template.md +217 -0
  371. package/i18n/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +2596 -0
  372. package/i18n/skills/a2h-resource-convert/scripts/lottie_hosts.ts +415 -0
  373. package/i18n/skills/a2h-resource-convert/scripts/tests/docs_only_i18n.test.mjs +44 -0
  374. package/i18n/skills/a2h-resource-convert/scripts/tests/lottie_hosts.test.mjs +222 -0
  375. package/i18n/skills/a2h-spec-design-pipeline/SKILL.md +238 -0
  376. package/i18n/skills/a2h-spec-design-pipeline/references/coding-loop.md +358 -0
  377. package/i18n/skills/a2h-spec-design-pipeline/references/homegraph-cli.md +307 -0
  378. package/i18n/skills/a2h-spec-design-pipeline/references/initialization.md +103 -0
  379. package/i18n/skills/a2h-spec-design-pipeline/references/merge-queue.md +266 -0
  380. package/i18n/skills/a2h-spec-design-pipeline/references/post-loop.md +23 -0
  381. package/i18n/skills/a2h-spec-design-pipeline/references/review-loop.md +71 -0
  382. package/i18n/skills/a2h-spec-design-pipeline/references/scripts.md +55 -0
  383. package/i18n/skills/a2h-spec-design-pipeline/references/specs.example.json +19 -0
  384. package/i18n/skills/a2h-spec-design-pipeline/references/state-and-resume.md +246 -0
  385. package/i18n/skills/a2h-spec-design-pipeline/scripts/plan_groups.ts +752 -0
  386. package/i18n/skills/a2h-spec-design-pipeline/scripts/test_plan_groups.ts +661 -0
  387. package/i18n/skills/a2h-spec-generate/SKILL.md +375 -0
  388. package/i18n/skills/a2h-spec-generate/references/batch-mode.md +215 -0
  389. package/i18n/skills/a2h-spec-generate/references/delete-blast-radius.md +3 -0
  390. package/i18n/skills/a2h-spec-generate/references/dispatch-watchdog.md +150 -0
  391. package/i18n/skills/a2h-spec-generate/references/fusion-task-contract.md +184 -0
  392. package/i18n/skills/a2h-spec-generate/references/input-formats.md +27 -0
  393. package/i18n/skills/a2h-spec-generate/references/library-evidence.md +3 -0
  394. package/i18n/skills/a2h-spec-generate/references/method-discipline.md +64 -0
  395. package/i18n/skills/a2h-spec-generate/references/optional-gates.json +45 -0
  396. package/i18n/skills/a2h-spec-generate/references/recall-guide.md +84 -0
  397. package/i18n/skills/a2h-spec-generate/references/recall-terse.md +3 -0
  398. package/i18n/skills/a2h-spec-generate/references/recall-uniapp.md +10 -0
  399. package/i18n/skills/a2h-spec-generate/references/requirement-scope.md +122 -0
  400. package/i18n/skills/a2h-spec-generate/references/review-checklist.md +22 -0
  401. package/i18n/skills/a2h-spec-generate/references/spec-sample-complex.md +80 -0
  402. package/i18n/skills/a2h-spec-generate/references/spec-sample-transfer.md +43 -0
  403. package/i18n/skills/a2h-spec-generate/references/spec-samples.md +65 -0
  404. package/i18n/skills/a2h-spec-generate/references/specs.schema.json +85 -0
  405. package/i18n/skills/a2h-spec-generate/references/synthesis-rules.md +145 -0
  406. package/i18n/skills/a2h-spec-generate/references/transfer-file.md +5 -0
  407. package/i18n/skills/a2h-spec-generate/references/transfer-socket.md +5 -0
  408. package/i18n/skills/a2h-spec-generate/references/worker-rules.md +129 -0
  409. package/i18n/skills/a2h-spec-generate/scripts/check-fused-spec.mjs +702 -0
  410. package/i18n/skills/a2h-spec-generate/scripts/check_spec.ts +515 -0
  411. package/i18n/skills/a2h-spec-generate/scripts/collect-specs.mjs +727 -0
  412. package/i18n/skills/a2h-spec-generate/scripts/feature-stem.mjs +151 -0
  413. package/i18n/skills/a2h-spec-generate/scripts/parse_requirements.ts +515 -0
  414. package/i18n/skills/a2h-spec-generate/scripts/prepare-facts.mjs +313 -0
  415. package/i18n/skills/a2h-spec-generate/scripts/publish-specs.mjs +354 -0
  416. package/i18n/skills/a2h-spec-generate/scripts/regroup-by-page.mjs +669 -0
  417. package/i18n/skills/a2h-spec-generate/scripts/render-tasks.mjs +385 -0
  418. package/i18n/skills/a2h-spec-generate/scripts/report.mjs +136 -0
  419. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/build.ts +2217 -0
  420. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/component-variants.ts +845 -0
  421. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/policy.ts +572 -0
  422. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/traceability.ts +580 -0
  423. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/analysis/req-model/build.ts +1265 -0
  424. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/area-facts.ts +1057 -0
  425. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/behavior-seed.ts +565 -0
  426. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/library-evidence.ts +544 -0
  427. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/navigation-guard.ts +363 -0
  428. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/schema.ts +317 -0
  429. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/selfcheck.ts +707 -0
  430. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/spec-bindings.ts +436 -0
  431. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/task-contract.ts +608 -0
  432. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/contracts.ts +650 -0
  433. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/task-contract.ts +178 -0
  434. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/tree-sitter-adapter.ts +923 -0
  435. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/model/finalize.ts +912 -0
  436. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/model/task.ts +279 -0
  437. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/requirement-scope.ts +163 -0
  438. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/source-index/homegraph.ts +1039 -0
  439. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/validation/req-text.ts +256 -0
  440. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fixtures/fusion-run.ts +243 -0
  441. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-area-facts.test.ts +576 -0
  442. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-detectors.test.ts +176 -0
  443. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-e2e.test.ts +103 -0
  444. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-schema.test.ts +111 -0
  445. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-selfcheck.test.ts +307 -0
  446. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-contract.test.ts +340 -0
  447. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-finalize.test.ts +1857 -0
  448. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-navigation-guard.test.ts +262 -0
  449. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-prepare.test.ts +722 -0
  450. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-scope.test.ts +339 -0
  451. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-selfcheck.test.ts +1253 -0
  452. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-spec.test.ts +608 -0
  453. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/model-scope.test.ts +411 -0
  454. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/model-task-contract.test.ts +300 -0
  455. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/model-v4.test.ts +1061 -0
  456. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/uniapp-scanner.test.ts +159 -0
  457. package/i18n/skills/a2h-spec-generate/template/REQ.txt +22 -0
  458. package/i18n/skills/a2h-spec-generate/template/REQ.xlsx +0 -0
  459. package/i18n/skills/a2h-spec-generate/test/check-fused-spec.test.mjs +847 -0
  460. package/i18n/skills/a2h-spec-generate/test/check-spec.test.ts +415 -0
  461. package/i18n/skills/a2h-spec-generate/test/collect-specs.test.mjs +808 -0
  462. package/i18n/skills/a2h-spec-generate/test/feature-stem.test.mjs +157 -0
  463. package/i18n/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/components/MyCard.vue +9 -0
  464. package/i18n/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/feature/editor/index.vue +1 -0
  465. package/i18n/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/detail/index.vue +1 -0
  466. package/i18n/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/home/index.vue +33 -0
  467. package/i18n/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/settings/index.vue +1 -0
  468. package/i18n/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages.json +23 -0
  469. package/i18n/skills/a2h-spec-generate/test/inspect-uniapp.test.mjs +54 -0
  470. package/i18n/skills/a2h-spec-generate/test/prepare-facts.test.mjs +41 -0
  471. package/i18n/skills/a2h-spec-generate/test/publish-specs.test.mjs +295 -0
  472. package/i18n/skills/a2h-spec-generate/test/regroup-by-page.test.mjs +354 -0
  473. package/i18n/skills/a2h-spec-generate/test/render-tasks.test.mjs +596 -0
  474. package/i18n/skills/a2h-spec-generate/test/report.test.mjs +47 -0
  475. package/i18n/skills/a2h-utg-explorer/SKILL.md +126 -0
  476. package/i18n/skills/a2h-utg-explorer/references/architecture.md +282 -0
  477. package/i18n/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +908 -0
  478. package/i18n/skills/a2h-utg-explorer/scripts/final_utg.mjs +446 -0
  479. package/i18n/skills/a2h-utg-explorer/scripts/hint_check.mjs +147 -0
  480. package/i18n/skills/a2h-utg-explorer/scripts/hint_source.mjs +119 -0
  481. package/i18n/skills/a2h-utg-explorer/scripts/hybrid_route_cdp.mjs +376 -0
  482. package/i18n/skills/a2h-utg-explorer/scripts/recover_b.mjs +550 -0
  483. package/i18n/skills/a2h-utg-explorer/scripts/recover_d.mjs +647 -0
  484. package/i18n/skills/a2h-utg-explorer/scripts/seed_recipes.mjs +426 -0
  485. package/i18n/skills/a2h-utg-explorer/scripts/tests/attest.test.mjs +66 -0
  486. package/i18n/skills/a2h-utg-explorer/scripts/tests/compose_identity.test.mjs +302 -0
  487. package/i18n/skills/a2h-utg-explorer/scripts/tests/content_wait.test.mjs +207 -0
  488. package/i18n/skills/a2h-utg-explorer/scripts/tests/diagnostics.test.mjs +252 -0
  489. package/i18n/skills/a2h-utg-explorer/scripts/tests/direct_launch.test.mjs +130 -0
  490. package/i18n/skills/a2h-utg-explorer/scripts/tests/final_utg.test.mjs +135 -0
  491. package/i18n/skills/a2h-utg-explorer/scripts/tests/generalization_fixes.test.mjs +252 -0
  492. package/i18n/skills/a2h-utg-explorer/scripts/tests/hint_check.test.mjs +129 -0
  493. package/i18n/skills/a2h-utg-explorer/scripts/tests/hybrid_route_identity.test.mjs +146 -0
  494. package/i18n/skills/a2h-utg-explorer/scripts/tests/interruptions.test.mjs +614 -0
  495. package/i18n/skills/a2h-utg-explorer/scripts/tests/launch_bridge.test.mjs +214 -0
  496. package/i18n/skills/a2h-utg-explorer/scripts/tests/overflow_prefix.test.mjs +327 -0
  497. package/i18n/skills/a2h-utg-explorer/scripts/tests/overlay_identity.test.mjs +204 -0
  498. package/i18n/skills/a2h-utg-explorer/scripts/tests/page_identity_tiers.test.mjs +393 -0
  499. package/i18n/skills/a2h-utg-explorer/scripts/tests/pager_navigation.test.mjs +119 -0
  500. package/i18n/skills/a2h-utg-explorer/scripts/tests/panel_routes.test.mjs +208 -0
  501. package/i18n/skills/a2h-utg-explorer/scripts/tests/pipeline.test.mjs +240 -0
  502. package/i18n/skills/a2h-utg-explorer/scripts/tests/recover_b.test.mjs +173 -0
  503. package/i18n/skills/a2h-utg-explorer/scripts/tests/recover_d.test.mjs +280 -0
  504. package/i18n/skills/a2h-utg-explorer/scripts/tests/robustness_fixes.test.mjs +345 -0
  505. package/i18n/skills/a2h-utg-explorer/scripts/tests/runner_capabilities.test.mjs +194 -0
  506. package/i18n/skills/a2h-utg-explorer/scripts/tests/seed_recipes.test.mjs +261 -0
  507. package/i18n/skills/a2h-utg-explorer/scripts/tests/semantics.test.mjs +102 -0
  508. package/i18n/skills/a2h-utg-explorer/scripts/tests/state_ambiguity.test.mjs +92 -0
  509. package/i18n/skills/a2h-utg-explorer/scripts/tests/twin_opener.test.mjs +119 -0
  510. package/i18n/skills/a2h-utg-explorer/scripts/tests/variant_strings.test.mjs +63 -0
  511. package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/diagnostics.mjs +196 -0
  512. package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/hybrid_route.mjs +140 -0
  513. package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +1562 -0
  514. package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/state_phase.mjs +47 -0
  515. package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +2714 -0
  516. package/i18n/skills/a2h-utg-static/SKILL.md +372 -0
  517. package/i18n/skills/a2h-utg-static/references/ui-elements-static-utg-schema.md +248 -0
  518. package/i18n/skills/a2h-utg-static/references/view-interactions.md +215 -0
  519. package/i18n/skills/a2h-utg-static/scripts/assemble.mjs +2190 -0
  520. package/i18n/skills/a2h-utg-static/scripts/audit.mjs +268 -0
  521. package/i18n/skills/a2h-utg-static/scripts/click_paths.mjs +720 -0
  522. package/i18n/skills/a2h-utg-static/scripts/compose_body_text.mjs +250 -0
  523. package/i18n/skills/a2h-utg-static/scripts/compose_titles.mjs +374 -0
  524. package/i18n/skills/a2h-utg-static/scripts/compose_widgets.mjs +498 -0
  525. package/i18n/skills/a2h-utg-static/scripts/data_model.mjs +590 -0
  526. package/i18n/skills/a2h-utg-static/scripts/data_producers.mjs +431 -0
  527. package/i18n/skills/a2h-utg-static/scripts/fragment_nav.mjs +1137 -0
  528. package/i18n/skills/a2h-utg-static/scripts/hybrid_scope.mjs +705 -0
  529. package/i18n/skills/a2h-utg-static/scripts/interaction_sites.mjs +267 -0
  530. package/i18n/skills/a2h-utg-static/scripts/label_resolve.mjs +958 -0
  531. package/i18n/skills/a2h-utg-static/scripts/lib/hybrid-provenance.mjs +201 -0
  532. package/i18n/skills/a2h-utg-static/scripts/lib/uniapp-routes.mjs +195 -0
  533. package/i18n/skills/a2h-utg-static/scripts/nl_hints.mjs +545 -0
  534. package/i18n/skills/a2h-utg-static/scripts/presenter_nav.mjs +490 -0
  535. package/i18n/skills/a2h-utg-static/scripts/static_prior.mjs +956 -0
  536. package/i18n/skills/a2h-utg-static/scripts/tests/regression_matrix.mjs +1261 -0
  537. package/i18n/skills/a2h-utg-static/scripts/tests/test_callee_string_default.mjs +30 -0
  538. package/i18n/skills/a2h-utg-static/scripts/tests/test_chrome_tokens.mjs +60 -0
  539. package/i18n/skills/a2h-utg-static/scripts/tests/test_commented_out_trigger.mjs +111 -0
  540. package/i18n/skills/a2h-utg-static/scripts/tests/test_compose_res_text.mjs +125 -0
  541. package/i18n/skills/a2h-utg-static/scripts/tests/test_compose_vm_nav.mjs +289 -0
  542. package/i18n/skills/a2h-utg-static/scripts/tests/test_data_model.mjs +120 -0
  543. package/i18n/skills/a2h-utg-static/scripts/tests/test_data_producers.mjs +113 -0
  544. package/i18n/skills/a2h-utg-static/scripts/tests/test_disabled_guard.mjs +42 -0
  545. package/i18n/skills/a2h-utg-static/scripts/tests/test_drawer_panel_gesture.mjs +140 -0
  546. package/i18n/skills/a2h-utg-static/scripts/tests/test_fresh_branch_guard.mjs +49 -0
  547. package/i18n/skills/a2h-utg-static/scripts/tests/test_hint_language.mjs +136 -0
  548. package/i18n/skills/a2h-utg-static/scripts/tests/test_hybrid_bundle_attribution.mjs +74 -0
  549. package/i18n/skills/a2h-utg-static/scripts/tests/test_hybrid_bundled_pages.mjs +181 -0
  550. package/i18n/skills/a2h-utg-static/scripts/tests/test_hybrid_provenance.mjs +150 -0
  551. package/i18n/skills/a2h-utg-static/scripts/tests/test_hybrid_scope.mjs +457 -0
  552. package/i18n/skills/a2h-utg-static/scripts/tests/test_hybrid_title_renders.mjs +118 -0
  553. package/i18n/skills/a2h-utg-static/scripts/tests/test_label_accessor_forms.mjs +187 -0
  554. package/i18n/skills/a2h-utg-static/scripts/tests/test_label_source.mjs +70 -0
  555. package/i18n/skills/a2h-utg-static/scripts/tests/test_launch_intent_guard.mjs +67 -0
  556. package/i18n/skills/a2h-utg-static/scripts/tests/test_login_interceptor.mjs +368 -0
  557. package/i18n/skills/a2h-utg-static/scripts/tests/test_mode_and_cb_param.mjs +172 -0
  558. package/i18n/skills/a2h-utg-static/scripts/tests/test_module_strings.mjs +78 -0
  559. package/i18n/skills/a2h-utg-static/scripts/tests/test_nl_hint_grammar.mjs +42 -0
  560. package/i18n/skills/a2h-utg-static/scripts/tests/test_nl_hints_gate.mjs +85 -0
  561. package/i18n/skills/a2h-utg-static/scripts/tests/test_nl_hints_off_path.mjs +67 -0
  562. package/i18n/skills/a2h-utg-static/scripts/tests/test_non_gesture_step_flag.mjs +62 -0
  563. package/i18n/skills/a2h-utg-static/scripts/tests/test_preference_widgets.mjs +48 -0
  564. package/i18n/skills/a2h-utg-static/scripts/tests/test_read_text_crlf.mjs +41 -0
  565. package/i18n/skills/a2h-utg-static/scripts/tests/test_sealed_dialog_state.mjs +148 -0
  566. package/i18n/skills/a2h-utg-static/scripts/tests/test_state_specific_hop.mjs +130 -0
  567. package/i18n/skills/a2h-utg-static/scripts/tests/test_synthetic_label_identity.mjs +51 -0
  568. package/i18n/skills/a2h-utg-static/scripts/tests/test_template_title.mjs +61 -0
  569. package/i18n/skills/a2h-utg-static/scripts/tests/test_ui_elements_flow_filter.mjs +110 -0
  570. package/i18n/skills/a2h-utg-static/scripts/tests/test_uniapp_data_table.mjs +340 -0
  571. package/i18n/skills/a2h-utg-static/scripts/tests/test_uniapp_relative_url.mjs +125 -0
  572. package/i18n/skills/a2h-utg-static/scripts/tests/test_uniapp_routes.mjs +161 -0
  573. package/i18n/skills/a2h-utg-static/scripts/tests/test_uniapp_source.mjs +330 -0
  574. package/i18n/skills/a2h-utg-static/scripts/tests/test_utg_specgen_boundary.mjs +45 -0
  575. package/i18n/skills/a2h-utg-static/scripts/tests/test_viewpage_nav.mjs +340 -0
  576. package/i18n/skills/a2h-utg-static/scripts/uniapp_nav.mjs +1394 -0
  577. package/i18n/skills/a2h-utg-static/scripts/uniapp_widgets.mjs +244 -0
  578. package/i18n/skills/a2h-utg-static/tools/convert_static_utg_to_ui_elements.ts +769 -0
  579. package/package.json +11 -161
  580. package/platforms/deveco/agents/code-reviewer.frontmatter.md +1 -1
  581. package/platforms/opencode/agents/code-reviewer.frontmatter.md +1 -1
  582. package/skills/a2h-app-migrate/SKILL.md +31 -12
  583. package/skills/a2h-app-migrate/references/config.example.json +1 -0
  584. package/skills/a2h-app-migrate/references/feature-scope.md +121 -0
  585. package/skills/a2h-app-migrate/references/stage-map.md +4 -2
  586. package/skills/a2h-app-migrate/references/workflow.yaml +427 -103
  587. package/skills/a2h-app-migrate/scripts/android_index.mjs +35 -8
  588. package/skills/a2h-app-migrate/scripts/check_module_docs_done.mjs +39 -1
  589. package/skills/a2h-app-migrate/scripts/check_spec_gen_done.mjs +78 -6
  590. package/skills/a2h-app-migrate/scripts/check_spec_pipeline_done.mjs +144 -9
  591. package/skills/a2h-app-migrate/scripts/check_ui_batch_done.mjs +14 -1
  592. package/skills/a2h-app-migrate/scripts/check_utg_static_done.mjs +46 -5
  593. package/skills/a2h-app-migrate/scripts/diagnose.mjs +162 -0
  594. package/skills/a2h-app-migrate/scripts/env_preflight.mjs +178 -44
  595. package/skills/a2h-app-migrate/scripts/feature_scope.mjs +347 -0
  596. package/skills/a2h-app-migrate/scripts/human_review_gate.mjs +81 -11
  597. package/skills/a2h-app-migrate/scripts/infer_android_root.mjs +17 -1
  598. package/skills/a2h-app-migrate/scripts/ledger.mjs +80 -10
  599. package/skills/a2h-app-migrate/scripts/migration_manifest.mjs +351 -0
  600. package/skills/a2h-app-migrate/scripts/paths_preflight.mjs +9 -23
  601. package/skills/a2h-app-migrate/scripts/resume_plan.mjs +72 -12
  602. package/skills/a2h-app-migrate/scripts/reuse_static_utg.mjs +33 -1
  603. package/skills/a2h-app-migrate/scripts/run_dir.mjs +137 -41
  604. package/skills/a2h-app-migrate/scripts/scope_model.mjs +255 -0
  605. package/skills/a2h-app-migrate/scripts/scope_report.mjs +128 -0
  606. package/skills/a2h-app-migrate/scripts/source_fp.mjs +120 -0
  607. package/skills/a2h-app-migrate/scripts/spec_layout.mjs +2 -0
  608. package/skills/a2h-app-migrate/scripts/validate_workflow.mjs +38 -0
  609. package/skills/a2h-app-migrate/test/test_android_index.mjs +143 -0
  610. package/skills/a2h-app-migrate/test/test_apk_preflight.mjs +63 -0
  611. package/skills/a2h-app-migrate/test/test_arch_done.mjs +54 -0
  612. package/skills/a2h-app-migrate/test/test_build_fixer_contract.mjs +98 -0
  613. package/skills/a2h-app-migrate/test/test_config_example.mjs +42 -0
  614. package/skills/a2h-app-migrate/test/test_devecocli_docs_preflight.mjs +32 -0
  615. package/skills/a2h-app-migrate/test/test_ensure_utg_snapshot.mjs +147 -0
  616. package/skills/a2h-app-migrate/test/test_entry_guards.mjs +102 -0
  617. package/skills/a2h-app-migrate/test/test_env_requirements.mjs +713 -0
  618. package/skills/a2h-app-migrate/test/test_feature_scope.mjs +217 -0
  619. package/skills/a2h-app-migrate/test/test_finalize.mjs +117 -0
  620. package/skills/a2h-app-migrate/test/test_gate_checkpoint.mjs +146 -0
  621. package/skills/a2h-app-migrate/test/test_hmos_fingerprint.mjs +68 -0
  622. package/skills/a2h-app-migrate/test/test_i18n_engine_mirror.mjs +51 -0
  623. package/skills/a2h-app-migrate/test/test_image_probe.mjs +120 -0
  624. package/skills/a2h-app-migrate/test/test_incremental_acceptance.mjs +145 -0
  625. package/skills/a2h-app-migrate/test/test_incremental_phase2.mjs +223 -0
  626. package/skills/a2h-app-migrate/test/test_incremental_phase2_acceptance.mjs +157 -0
  627. package/skills/a2h-app-migrate/test/test_incremental_profile.mjs +84 -0
  628. package/skills/a2h-app-migrate/test/test_infer_android_root.mjs +101 -0
  629. package/skills/a2h-app-migrate/test/test_interaction.mjs +122 -0
  630. package/skills/a2h-app-migrate/test/test_json_io.mjs +32 -0
  631. package/skills/a2h-app-migrate/test/test_leaf_questions.mjs +150 -0
  632. package/skills/a2h-app-migrate/test/test_migration_manifest.mjs +225 -0
  633. package/skills/a2h-app-migrate/test/test_module_docs_done.mjs +86 -0
  634. package/skills/a2h-app-migrate/test/test_parse_args.mjs +69 -0
  635. package/skills/a2h-app-migrate/test/test_preflight_report.mjs +93 -0
  636. package/skills/a2h-app-migrate/test/test_resume_plan.mjs +271 -0
  637. package/skills/a2h-app-migrate/test/test_resume_summary.mjs +222 -0
  638. package/skills/a2h-app-migrate/test/test_reuse_static_utg.mjs +136 -0
  639. package/skills/a2h-app-migrate/test/test_run_dir.mjs +552 -0
  640. package/skills/a2h-app-migrate/test/test_scope_model.mjs +172 -0
  641. package/skills/a2h-app-migrate/test/test_skill_doc.mjs +144 -0
  642. package/skills/a2h-app-migrate/test/test_spec_engine_acceptance.mjs +94 -0
  643. package/skills/a2h-app-migrate/test/test_spec_engine_contract.mjs +155 -0
  644. package/skills/a2h-app-migrate/test/test_spec_gen_done.mjs +263 -0
  645. package/skills/a2h-app-migrate/test/test_spec_gen_gate.mjs +165 -0
  646. package/skills/a2h-app-migrate/test/test_spec_pipeline_done.mjs +511 -0
  647. package/skills/a2h-app-migrate/test/test_specs_json_preflight.mjs +76 -0
  648. package/skills/a2h-app-migrate/test/test_ui_batch_capture_audit.mjs +106 -0
  649. package/skills/a2h-app-migrate/test/test_ui_batch_done.mjs +65 -0
  650. package/skills/a2h-app-migrate/test/test_ui_batch_gate.mjs +226 -0
  651. package/skills/a2h-app-migrate/test/test_uniapp_preflight.mjs +83 -0
  652. package/skills/a2h-app-migrate/test/test_user_facing_progress.mjs +43 -0
  653. package/skills/a2h-app-migrate/test/test_utg_dirs.mjs +41 -0
  654. package/skills/a2h-app-migrate/test/test_utg_static_done.mjs +214 -0
  655. package/skills/a2h-app-migrate/test/test_validate_races.mjs +50 -0
  656. package/skills/a2h-app-migrate/test/test_validate_workflow_bilingual.mjs +87 -0
  657. package/skills/a2h-arch-generate/SKILL.md +20 -17
  658. package/skills/a2h-arch-generate/references/database-schema-recovery.md +2 -2
  659. package/skills/a2h-arch-generate/references/harmony-project-inspection.md +8 -8
  660. package/skills/a2h-arch-generate/references/homegraph-workflow.md +25 -14
  661. package/skills/a2h-arch-generate/references/module-evidence-subagent.md +2 -2
  662. package/skills/a2h-arch-generate/references/source-baseline.md +4 -4
  663. package/skills/a2h-arch-generate/scripts/cleanup_intermediates.mjs +34 -3
  664. package/skills/a2h-arch-generate/scripts/create_project.mjs +24 -1
  665. package/skills/a2h-arch-generate/scripts/generate_source_baseline.mjs +35 -46
  666. package/skills/a2h-arch-generate/scripts/inspect_and_route.mjs +29 -5
  667. package/skills/a2h-arch-generate/scripts/inspect_harmony_target.mjs +33 -40
  668. package/skills/a2h-arch-generate/scripts/module_create/generate.mjs +2 -3
  669. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/build.gradle +11 -0
  670. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/src/main/AndroidManifest.xml +12 -0
  671. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/src/main/java/com/example/notes/MainActivity.kt +8 -0
  672. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/src/main/java/com/example/notes/NotesStore.kt +17 -0
  673. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/build.gradle +3 -0
  674. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/settings.gradle +1 -0
  675. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/AppScope/app.json5 +8 -0
  676. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/build-profile.json5 +14 -0
  677. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/common/utils/build-profile.json5 +7 -0
  678. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/common/utils/oh-package.json5 +1 -0
  679. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/common/utils/src/main/ets/utils/Format.ets +3 -0
  680. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/home/build-profile.json5 +7 -0
  681. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/home/oh-package.json5 +1 -0
  682. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/home/src/main/ets/pages/Home.ets +3 -0
  683. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/sync/build-profile.json5 +7 -0
  684. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/sync/oh-package.json5 +1 -0
  685. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/sync/src/main/ets/engine/SyncEngine.ets +3 -0
  686. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/hvigorfile.ts +1 -0
  687. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/oh-package.json5 +1 -0
  688. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/products/app/build-profile.json5 +7 -0
  689. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/products/app/oh-package.json5 +9 -0
  690. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/products/app/src/main/ets/pages/Index.ets +7 -0
  691. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/App.vue +10 -0
  692. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/manifest.json +6 -0
  693. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/pages/index/index.vue +16 -0
  694. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/pages.json +5 -0
  695. package/skills/a2h-arch-generate/scripts/tests/e2e/run_e2e.mjs +548 -0
  696. package/skills/a2h-arch-generate/scripts/tests/run_tests.mjs +1260 -0
  697. package/skills/a2h-arch-generate/scripts/tests/test_cleanup.mjs +208 -0
  698. package/skills/a2h-arch-generate/scripts/tests/test_console_encoding.mjs +52 -0
  699. package/skills/a2h-arch-generate/scripts/tests/test_git_root.mjs +34 -0
  700. package/skills/a2h-arch-generate/scripts/tests/test_module_templates.mjs +70 -0
  701. package/skills/a2h-arch-generate/scripts/tests/test_router.mjs +164 -0
  702. package/skills/a2h-arch-generate/scripts/validate_architecture_docs.mjs +2 -5
  703. package/skills/a2h-arch-generate/scripts/validate_incremental_docs.mjs +4 -2
  704. package/skills/a2h-arkts-logic-coder/SKILL.md +163 -15
  705. package/skills/a2h-arkts-logic-coder/references/ISSUES.md +3 -1
  706. package/skills/a2h-arkts-logic-coder/references/code-generation.md +120 -1
  707. package/skills/a2h-arkts-logic-coder/references/spec-design.md +46 -11
  708. package/skills/a2h-arkts-logic-coder/scripts/design/validate_spec_design_output.mjs +22 -25
  709. package/skills/a2h-arkts-logic-coder/scripts/state_doc.mjs +873 -0
  710. package/skills/a2h-arkts-logic-coder/test/golden/inspect_happy.json +20 -0
  711. package/skills/a2h-arkts-logic-coder/test/golden/move_design.md +18 -0
  712. package/skills/a2h-arkts-logic-coder/test/golden/move_design_crlf.md +18 -0
  713. package/skills/a2h-arkts-logic-coder/test/golden/move_spec.md +7 -0
  714. package/skills/a2h-arkts-logic-coder/test/golden/resolve_cases.json +36 -0
  715. package/skills/a2h-arkts-logic-coder/test/golden/validate_issue_file.md +12 -0
  716. package/skills/a2h-arkts-logic-coder/test/golden/validate_issues.json +57 -0
  717. package/skills/a2h-arkts-logic-coder/test/test_spec_design_scripts.mjs +547 -0
  718. package/skills/a2h-arkts-logic-coder/test/test_state_doc.mjs +596 -0
  719. package/skills/a2h-batch-ui-align/SKILL.md +78 -26
  720. package/skills/a2h-batch-ui-align/assets/ColorUtils.ets +16 -2
  721. package/skills/a2h-batch-ui-align/references/cards/alignment.md +5 -1
  722. package/skills/a2h-batch-ui-align/references/cards/geometry.md +6 -1
  723. package/skills/a2h-batch-ui-align/references/cards/interaction.md +2 -1
  724. package/skills/a2h-batch-ui-align/references/cards/resources.md +9 -3
  725. package/skills/a2h-batch-ui-align/references/cards/widgets.md +27 -3
  726. package/skills/a2h-batch-ui-align/references/cards/window.md +2 -1
  727. package/skills/a2h-batch-ui-align/references/checker-rules.md +301 -13
  728. package/skills/a2h-batch-ui-align/references/conversion-procedure.md +53 -13
  729. package/skills/a2h-batch-ui-align/references/host-dispatch.md +2 -0
  730. package/skills/a2h-batch-ui-align/references/incremental-scope.md +28 -9
  731. package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +14 -9
  732. package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +2 -2
  733. package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +28 -1
  734. package/skills/a2h-batch-ui-align/references/state-mgmt/_/350/243/205/351/245/260/345/231/250/351/200/237/346/237/245.md +30 -0
  735. package/skills/a2h-batch-ui-align/references/step3-capture.md +25 -6
  736. package/skills/a2h-batch-ui-align/references/step4-prepare.md +7 -2
  737. package/skills/a2h-batch-ui-align/references/step5-convert.md +33 -9
  738. package/skills/a2h-batch-ui-align/scripts/android_parse_fast.ts +6 -7
  739. package/skills/a2h-batch-ui-align/scripts/branch_coverage.mjs +155 -0
  740. package/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +463 -22
  741. package/skills/a2h-batch-ui-align/scripts/capture_audit.mjs +474 -0
  742. package/skills/a2h-batch-ui-align/scripts/capture_fast.mjs +665 -0
  743. package/skills/a2h-batch-ui-align/scripts/capture_verify.mjs +552 -0
  744. package/skills/a2h-batch-ui-align/scripts/detach.mjs +5 -2
  745. package/skills/a2h-batch-ui-align/scripts/draw_coverage.mjs +264 -0
  746. package/skills/a2h-batch-ui-align/scripts/evidence_gate.mjs +263 -0
  747. package/skills/a2h-batch-ui-align/scripts/export_ui_info.mjs +20 -3
  748. package/skills/a2h-batch-ui-align/scripts/generate_pages_json.mjs +4 -5
  749. package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +220 -35
  750. package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +517 -41
  751. package/skills/a2h-batch-ui-align/scripts/icon_coverage.mjs +147 -0
  752. package/skills/a2h-batch-ui-align/scripts/image_probe.mjs +231 -54
  753. package/skills/a2h-batch-ui-align/scripts/list_existing.mjs +141 -0
  754. package/skills/a2h-batch-ui-align/scripts/measure_pack.ts +239 -14
  755. package/skills/a2h-batch-ui-align/scripts/page_gap.mjs +210 -0
  756. package/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +98 -11
  757. package/skills/a2h-batch-ui-align/scripts/progress_identity.mjs +208 -0
  758. package/skills/a2h-batch-ui-align/scripts/scroll_verdict.mjs +62 -0
  759. package/skills/a2h-batch-ui-align/scripts/shell_contract.mjs +118 -4
  760. package/skills/a2h-batch-ui-align/scripts/shell_requests.mjs +273 -0
  761. package/skills/a2h-batch-ui-align/scripts/state_doc.mjs +9 -4
  762. package/skills/a2h-batch-ui-align/scripts/static_check/core/android.ts +231 -0
  763. package/skills/a2h-batch-ui-align/scripts/static_check/core/baseline.ts +79 -0
  764. package/skills/a2h-batch-ui-align/scripts/static_check/core/i18n.ts +1 -5
  765. package/skills/a2h-batch-ui-align/scripts/static_check/core/parse.ts +90 -2
  766. package/skills/a2h-batch-ui-align/scripts/static_check/core/scan.ts +44 -0
  767. package/skills/a2h-batch-ui-align/scripts/static_check/main.ts +61 -12
  768. package/skills/a2h-batch-ui-align/scripts/static_check/registry.ts +32 -0
  769. package/skills/a2h-batch-ui-align/scripts/static_check/rules/a11y.ts +3 -17
  770. package/skills/a2h-batch-ui-align/scripts/static_check/rules/android_immersive.ts +3 -3
  771. package/skills/a2h-batch-ui-align/scripts/static_check/rules/attr_chain.ts +1 -19
  772. package/skills/a2h-batch-ui-align/scripts/static_check/rules/blur_mirrored.ts +2 -2
  773. package/skills/a2h-batch-ui-align/scripts/static_check/rules/builder_invokes_callback.ts +84 -19
  774. package/skills/a2h-batch-ui-align/scripts/static_check/rules/color_string.ts +11 -4
  775. package/skills/a2h-batch-ui-align/scripts/static_check/rules/constant_coordinate.ts +2 -2
  776. package/skills/a2h-batch-ui-align/scripts/static_check/rules/dialog_backboard.ts +91 -0
  777. package/skills/a2h-batch-ui-align/scripts/static_check/rules/event_default_click.ts +179 -0
  778. package/skills/a2h-batch-ui-align/scripts/static_check/rules/framework_dialog.ts +110 -0
  779. package/skills/a2h-batch-ui-align/scripts/static_check/rules/framework_picker.ts +5 -5
  780. package/skills/a2h-batch-ui-align/scripts/static_check/rules/hit_test.ts +339 -0
  781. package/skills/a2h-batch-ui-align/scripts/static_check/rules/image_source.ts +84 -0
  782. package/skills/a2h-batch-ui-align/scripts/static_check/rules/input_traps.ts +249 -0
  783. package/skills/a2h-batch-ui-align/scripts/static_check/rules/layout_placement.ts +234 -5
  784. package/skills/a2h-batch-ui-align/scripts/static_check/rules/lottie_host.ts +145 -0
  785. package/skills/a2h-batch-ui-align/scripts/static_check/rules/media_content.ts +2 -2
  786. package/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +110 -12
  787. package/skills/a2h-batch-ui-align/scripts/static_check/rules/overlay_binds.ts +56 -0
  788. package/skills/a2h-batch-ui-align/scripts/static_check/rules/overlay_string.ts +96 -0
  789. package/skills/a2h-batch-ui-align/scripts/static_check/rules/padding_in_size.ts +179 -0
  790. package/skills/a2h-batch-ui-align/scripts/static_check/rules/percent_height_in_scroll.ts +3 -2
  791. package/skills/a2h-batch-ui-align/scripts/static_check/rules/popup_menu.ts +81 -8
  792. package/skills/a2h-batch-ui-align/scripts/static_check/rules/relative_container_height.ts +102 -0
  793. package/skills/a2h-batch-ui-align/scripts/static_check/rules/root_weight.ts +54 -4
  794. package/skills/a2h-batch-ui-align/scripts/static_check/rules/runtime_traps.ts +440 -0
  795. package/skills/a2h-batch-ui-align/scripts/static_check/rules/scroll_align.ts +75 -23
  796. package/skills/a2h-batch-ui-align/scripts/static_check/rules/scroll_delta.ts +178 -0
  797. package/skills/a2h-batch-ui-align/scripts/static_check/rules/swiper_index.ts +65 -0
  798. package/skills/a2h-batch-ui-align/scripts/static_check/rules/theme_color.ts +184 -0
  799. package/skills/a2h-batch-ui-align/scripts/static_check/rules/waterflow_sections.ts +231 -0
  800. package/skills/a2h-batch-ui-align/scripts/static_check/rules/wide_constant_width.ts +4 -4
  801. package/skills/a2h-batch-ui-align/scripts/static_check/rules/window_mode.ts +2 -3
  802. package/skills/a2h-batch-ui-align/scripts/static_check/scan_file.ts +30 -2
  803. package/skills/a2h-batch-ui-align/scripts/tests/agent_cli.test.mjs +231 -0
  804. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_a11y.test.mjs +598 -0
  805. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_align_tint.test.mjs +312 -0
  806. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_baseline.test.mjs +129 -0
  807. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_blur.test.mjs +217 -0
  808. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_builder_calls.test.mjs +323 -0
  809. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_canvas_pct.test.mjs +312 -0
  810. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_coolmall_runtime2.test.mjs +697 -0
  811. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_fidelity.test.mjs +507 -0
  812. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_hit_test.test.mjs +298 -0
  813. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_input_runtime.test.mjs +514 -0
  814. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_layout_placement.test.mjs +651 -0
  815. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_occlusion_offset_format.test.mjs +372 -0
  816. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_overlay_lottie.test.mjs +199 -0
  817. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_review_fixes.test.mjs +298 -0
  818. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_rule_smoke.test.mjs +269 -0
  819. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_rules.test.mjs +365 -0
  820. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_runtime_api.test.mjs +346 -0
  821. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_scroll_padding_raster.test.mjs +262 -0
  822. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_scroll_safearea.test.mjs +742 -0
  823. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_shell.test.mjs +91 -0
  824. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_theme.test.mjs +86 -0
  825. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_theme_runtime.test.mjs +95 -0
  826. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_weight_color.test.mjs +473 -0
  827. package/skills/a2h-batch-ui-align/scripts/tests/branch_coverage.test.mjs +116 -0
  828. package/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set.test.mjs +693 -0
  829. package/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set_scope.test.mjs +291 -0
  830. package/skills/a2h-batch-ui-align/scripts/tests/capture_audit.test.mjs +179 -0
  831. package/skills/a2h-batch-ui-align/scripts/tests/capture_fast.test.mjs +56 -0
  832. package/skills/a2h-batch-ui-align/scripts/tests/capture_gate.test.mjs +197 -0
  833. package/skills/a2h-batch-ui-align/scripts/tests/capture_review_fixes.test.mjs +322 -0
  834. package/skills/a2h-batch-ui-align/scripts/tests/color_utils_asset.test.mjs +93 -0
  835. package/skills/a2h-batch-ui-align/scripts/tests/detect_paradigm.test.mjs +260 -0
  836. package/skills/a2h-batch-ui-align/scripts/tests/draw_coverage.test.mjs +244 -0
  837. package/skills/a2h-batch-ui-align/scripts/tests/evidence_gate.test.mjs +435 -0
  838. package/skills/a2h-batch-ui-align/scripts/tests/export_scroll_states.test.mjs +31 -0
  839. package/skills/a2h-batch-ui-align/scripts/tests/export_ui_info.test.mjs +742 -0
  840. package/skills/a2h-batch-ui-align/scripts/tests/fixtures/icon_drift_search_sheet/SearchMenuDialog.buggy.ets +95 -0
  841. package/skills/a2h-batch-ui-align/scripts/tests/fixtures/icon_drift_search_sheet/page_0002_SearchMenuFragment/meta.json +21 -0
  842. package/skills/a2h-batch-ui-align/scripts/tests/fixtures/icon_drift_search_sheet/page_0002_SearchMenuFragment/screenshot.png +0 -0
  843. package/skills/a2h-batch-ui-align/scripts/tests/fixtures/icon_drift_search_sheet/page_0002_SearchMenuFragment/view.xml +35 -0
  844. package/skills/a2h-batch-ui-align/scripts/tests/generate_pages_json.test.mjs +123 -0
  845. package/skills/a2h-batch-ui-align/scripts/tests/group_commit.test.mjs +126 -0
  846. package/skills/a2h-batch-ui-align/scripts/tests/group_pack.test.mjs +363 -0
  847. package/skills/a2h-batch-ui-align/scripts/tests/group_pack_evidence.test.mjs +95 -0
  848. package/skills/a2h-batch-ui-align/scripts/tests/group_queue.test.mjs +1782 -0
  849. package/skills/a2h-batch-ui-align/scripts/tests/group_watch.test.mjs +215 -0
  850. package/skills/a2h-batch-ui-align/scripts/tests/harmony_index.test.mjs +95 -0
  851. package/skills/a2h-batch-ui-align/scripts/tests/host_env.test.mjs +115 -0
  852. package/skills/a2h-batch-ui-align/scripts/tests/icon_coverage.test.mjs +314 -0
  853. package/skills/a2h-batch-ui-align/scripts/tests/image_probe.test.mjs +243 -0
  854. package/skills/a2h-batch-ui-align/scripts/tests/list_existing.test.mjs +157 -0
  855. package/skills/a2h-batch-ui-align/scripts/tests/measure_pack.test.mjs +326 -0
  856. package/skills/a2h-batch-ui-align/scripts/tests/occlusion.test.mjs +102 -0
  857. package/skills/a2h-batch-ui-align/scripts/tests/page_gap.test.mjs +115 -0
  858. package/skills/a2h-batch-ui-align/scripts/tests/phase5_check.test.mjs +356 -0
  859. package/skills/a2h-batch-ui-align/scripts/tests/progress_identity.test.mjs +174 -0
  860. package/skills/a2h-batch-ui-align/scripts/tests/shell_contract.test.mjs +302 -0
  861. package/skills/a2h-batch-ui-align/scripts/tests/shell_requests.test.mjs +158 -0
  862. package/skills/a2h-batch-ui-align/scripts/tests/skill_doc_contract.test.mjs +60 -0
  863. package/skills/a2h-batch-ui-align/scripts/tests/state_doc.test.mjs +395 -0
  864. package/skills/a2h-batch-ui-align/scripts/tests/static_check_registry.test.mjs +122 -0
  865. package/skills/a2h-batch-ui-align/scripts/tests/test_bfs_exit.ts +49 -0
  866. package/skills/a2h-batch-ui-align/scripts/tests/text_color_diff.test.mjs +250 -0
  867. package/skills/a2h-coldstart-smoke-gate/SKILL.md +7 -4
  868. package/skills/a2h-dashboard-render/scripts/dashboard.mjs +12 -14
  869. package/skills/a2h-dashboard-render/scripts/device_capture.mjs +29 -30
  870. package/skills/a2h-dashboard-render/test/fixtures/page_capture/broken.xml +1 -0
  871. package/skills/a2h-dashboard-render/test/fixtures/page_capture/expected.json +156 -0
  872. package/skills/a2h-dashboard-render/test/fixtures/page_capture/hmos.json +1 -0
  873. package/skills/a2h-dashboard-render/test/fixtures/page_capture/list.xml +1 -0
  874. package/skills/a2h-dashboard-render/test/fixtures/page_capture/nested_scroll.xml +1 -0
  875. package/skills/a2h-dashboard-render/test/test_artifact_contract.mjs +168 -0
  876. package/skills/a2h-dashboard-render/test/test_cli_check_registry.mjs +99 -0
  877. package/skills/a2h-dashboard-render/test/test_dashboard_architecture.mjs +118 -0
  878. package/skills/a2h-dashboard-render/test/test_dashboard_build.mjs +93 -0
  879. package/skills/a2h-dashboard-render/test/test_dashboard_i18n.mjs +203 -0
  880. package/skills/a2h-dashboard-render/test/test_dashboard_node.mjs +1369 -0
  881. package/skills/a2h-dashboard-render/test/test_dashboard_spec_pipeline.mjs +318 -0
  882. package/skills/a2h-dashboard-render/test/test_dashboard_ui_pipeline.mjs +81 -0
  883. package/skills/a2h-dashboard-render/test/test_device_capture_env.mjs +115 -0
  884. package/skills/a2h-dashboard-render/test/test_device_capture_policy.mjs +411 -0
  885. package/skills/a2h-dashboard-render/test/test_device_locale_dialogs.mjs +17 -0
  886. package/skills/a2h-dashboard-render/test/test_page_capture.mjs +147 -0
  887. package/skills/a2h-dashboard-render/test/test_usage_readers.mjs +512 -0
  888. package/skills/a2h-module-semantic-docs/SKILL.md +51 -13
  889. package/skills/a2h-module-semantic-docs/scripts/scan_modules.mjs +66 -11
  890. package/skills/a2h-module-semantic-docs/test/golden/module_structure.json +187 -0
  891. package/skills/a2h-module-semantic-docs/test/golden/module_understanding.json +351 -0
  892. package/skills/a2h-module-semantic-docs/test/golden/module_update_plan.json +495 -0
  893. package/skills/a2h-module-semantic-docs/test/golden/project_directory_structure.json +157 -0
  894. package/skills/a2h-module-semantic-docs/test/test_incremental_fingerprint.mjs +94 -0
  895. package/skills/a2h-module-semantic-docs/test/test_scan_and_commit.mjs +388 -0
  896. package/skills/a2h-page-specgen/SKILL.md +240 -0
  897. package/skills/a2h-page-specgen/references/behavior-ledger.md +1170 -0
  898. package/skills/a2h-page-specgen/references/body-language.md +179 -0
  899. package/skills/a2h-page-specgen/references/evidence.md +105 -0
  900. package/skills/a2h-page-specgen/references/execution-model.md +364 -0
  901. package/skills/a2h-page-specgen/references/footprint-and-grouping.md +255 -0
  902. package/skills/a2h-page-specgen/references/gates.md +323 -0
  903. package/skills/a2h-page-specgen/references/page-inventory.md +220 -0
  904. package/skills/a2h-page-specgen/references/scenario-authoring.md +272 -0
  905. package/skills/a2h-page-specgen/references/spec-example.md +312 -0
  906. package/skills/a2h-page-specgen/references/spec-template.md +210 -0
  907. package/skills/a2h-page-specgen/scripts/behavior-audit.mjs +2436 -0
  908. package/skills/a2h-page-specgen/scripts/behavior-discovery.mjs +1833 -0
  909. package/skills/a2h-page-specgen/scripts/behavior-model.mjs +181 -0
  910. package/skills/a2h-page-specgen/scripts/behavior-reconcile.mjs +1205 -0
  911. package/skills/a2h-page-specgen/scripts/dispatch.mjs +212 -0
  912. package/skills/a2h-page-specgen/scripts/entry-evidence.mjs +1123 -0
  913. package/skills/a2h-page-specgen/scripts/facts-build.mjs +1613 -0
  914. package/skills/a2h-page-specgen/scripts/finalize.mjs +825 -0
  915. package/skills/a2h-page-specgen/scripts/footprint.mjs +1650 -0
  916. package/skills/a2h-page-specgen/scripts/gate.mjs +848 -0
  917. package/skills/a2h-page-specgen/scripts/interactions.mjs +344 -0
  918. package/skills/a2h-page-specgen/scripts/inventory.mjs +371 -0
  919. package/skills/a2h-page-specgen/scripts/lib/contracts.mjs +155 -0
  920. package/skills/a2h-page-specgen/scripts/lib/deps-source.mjs +399 -0
  921. package/skills/a2h-page-specgen/scripts/lib/draft-store.mjs +229 -0
  922. package/skills/a2h-page-specgen/scripts/lib/footprint-roles.mjs +278 -0
  923. package/skills/a2h-page-specgen/scripts/lib/fsx.mjs +79 -0
  924. package/skills/a2h-page-specgen/scripts/lib/graph-evidence.mjs +235 -0
  925. package/skills/a2h-page-specgen/scripts/lib/hg.mjs +683 -0
  926. package/skills/a2h-page-specgen/scripts/lib/homegraph-process.mjs +102 -0
  927. package/skills/a2h-page-specgen/scripts/lib/homegraph-query.mjs +161 -0
  928. package/skills/a2h-page-specgen/scripts/lib/ledger.mjs +478 -0
  929. package/skills/a2h-page-specgen/scripts/lib/main-module.mjs +24 -0
  930. package/skills/a2h-page-specgen/scripts/lib/operation-reviews.mjs +913 -0
  931. package/skills/a2h-page-specgen/scripts/lib/prose.mjs +238 -0
  932. package/skills/a2h-page-specgen/scripts/lib/reach.mjs +53 -0
  933. package/skills/a2h-page-specgen/scripts/lib/recovery-policy.mjs +28 -0
  934. package/skills/a2h-page-specgen/scripts/lib/scope.mjs +355 -0
  935. package/skills/a2h-page-specgen/scripts/lib/semantic-detail.mjs +353 -0
  936. package/skills/a2h-page-specgen/scripts/lib/source-text.mjs +497 -0
  937. package/skills/a2h-page-specgen/scripts/lib/symbols.mjs +125 -0
  938. package/skills/a2h-page-specgen/scripts/lib/utg-io.mjs +110 -0
  939. package/skills/a2h-page-specgen/scripts/lib/waker-event-store.mjs +658 -0
  940. package/skills/a2h-page-specgen/scripts/operation-evidence.mjs +1542 -0
  941. package/skills/a2h-page-specgen/scripts/prepare.mjs +840 -0
  942. package/skills/a2h-page-specgen/scripts/render.mjs +294 -0
  943. package/skills/a2h-page-specgen/scripts/report.mjs +340 -0
  944. package/skills/a2h-page-specgen/scripts/submission.mjs +697 -0
  945. package/skills/a2h-page-specgen/scripts/submit.mjs +85 -0
  946. package/skills/a2h-page-specgen/scripts/test/acceptance/README.md +77 -0
  947. package/skills/a2h-page-specgen/scripts/test/acceptance/acceptance.mjs +871 -0
  948. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.java +15 -0
  949. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.json +26 -0
  950. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md +347 -0
  951. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md +298 -0
  952. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.java +36 -0
  953. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.json +43 -0
  954. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.prompt.md +347 -0
  955. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.worker.md +298 -0
  956. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.discovery.json +2694 -0
  957. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.json +726 -0
  958. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.post-review.json +108 -0
  959. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.prompt.md +347 -0
  960. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.review.md +65 -0
  961. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.worker.md +265 -0
  962. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.java +47 -0
  963. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.json +54 -0
  964. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.prompt.md +347 -0
  965. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.worker.md +298 -0
  966. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/branch-checklist.md +32 -0
  967. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/gate-results.json +22 -0
  968. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/manifest.json +111 -0
  969. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/portability.test.mjs +141 -0
  970. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/review.md +22 -0
  971. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/run.mjs +515 -0
  972. package/skills/a2h-page-specgen/scripts/test/acceptance/cases.example.json +57 -0
  973. package/skills/a2h-page-specgen/scripts/test/android-entry-evidence.test.mjs +585 -0
  974. package/skills/a2h-page-specgen/scripts/test/android-operation-evidence.test.mjs +755 -0
  975. package/skills/a2h-page-specgen/scripts/test/behavior-audit-group.test.mjs +543 -0
  976. package/skills/a2h-page-specgen/scripts/test/behavior-audit-post.test.mjs +652 -0
  977. package/skills/a2h-page-specgen/scripts/test/behavior-audit-pre.test.mjs +1231 -0
  978. package/skills/a2h-page-specgen/scripts/test/behavior-component-gate.test.mjs +494 -0
  979. package/skills/a2h-page-specgen/scripts/test/behavior-discovery.test.mjs +1513 -0
  980. package/skills/a2h-page-specgen/scripts/test/behavior-finalize.test.mjs +758 -0
  981. package/skills/a2h-page-specgen/scripts/test/behavior-fixtures.mjs +623 -0
  982. package/skills/a2h-page-specgen/scripts/test/behavior-model.test.mjs +116 -0
  983. package/skills/a2h-page-specgen/scripts/test/behavior-reconcile.test.mjs +795 -0
  984. package/skills/a2h-page-specgen/scripts/test/behavior-regression.test.mjs +883 -0
  985. package/skills/a2h-page-specgen/scripts/test/contracts.test.mjs +205 -0
  986. package/skills/a2h-page-specgen/scripts/test/dispatch.test.mjs +258 -0
  987. package/skills/a2h-page-specgen/scripts/test/entry-evidence.test.mjs +475 -0
  988. package/skills/a2h-page-specgen/scripts/test/facts.test.mjs +1203 -0
  989. package/skills/a2h-page-specgen/scripts/test/finalize.test.mjs +243 -0
  990. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Api.kt +20 -0
  991. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/BothAnnotations.kt +28 -0
  992. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Cache.kt +7 -0
  993. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Comments.kt +26 -0
  994. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Mmkv.kt +7 -0
  995. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Models.kt +19 -0
  996. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Pair.kt +7 -0
  997. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Prefs.kt +9 -0
  998. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Room.kt +11 -0
  999. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Sample.kt +43 -0
  1000. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Templates.kt +34 -0
  1001. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Timeouts.kt +8 -0
  1002. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/androidTest/Helper.kt +5 -0
  1003. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/build.gradle.kts +16 -0
  1004. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/i18n/en.js.txt +5 -0
  1005. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/i18n/zh.js.txt +4 -0
  1006. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/libs.versions.toml +14 -0
  1007. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/package.json +10 -0
  1008. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values/strings.xml +10 -0
  1009. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-b+zh+Hans/strings.xml +4 -0
  1010. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-land/strings.xml +5 -0
  1011. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-night/strings.xml +5 -0
  1012. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-v21/strings.xml +4 -0
  1013. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-zh/strings.xml +4 -0
  1014. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/test/Legacy.kt +4 -0
  1015. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/weather.proto +11 -0
  1016. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-container/src/AppPreferences.kt +13 -0
  1017. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-container/src/SettingsViewModel.kt +16 -0
  1018. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-dao/src/UserDao.kt +28 -0
  1019. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-moko/i18n/src/commonMain/moko-resources/base/strings.xml +6 -0
  1020. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-moko/i18n/src/commonMain/moko-resources/fil/strings.xml +6 -0
  1021. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/res/values/arrays.xml +25 -0
  1022. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/res/values/strings.xml +10 -0
  1023. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/res/xml/prefs.xml +27 -0
  1024. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/src/Api.java +19 -0
  1025. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/src/Datastore.kt +12 -0
  1026. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/src/Settings.java +13 -0
  1027. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/src/forecast.js +14 -0
  1028. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/src/store.js +14 -0
  1029. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-receiver/src/BasePreferences.kt +13 -0
  1030. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-receiver/src/Screen.kt +14 -0
  1031. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-receiver/src/UiPreferences.kt +8 -0
  1032. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-retrofit/src/AuthAPI.kt +26 -0
  1033. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/AndroidManifest.xml +20 -0
  1034. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/feature/auth/navigation/ScreenRoute.kt +8 -0
  1035. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/pages.json +19 -0
  1036. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/src/components/Widget.vue +11 -0
  1037. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/src/pages/detail/detail.vue +14 -0
  1038. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/src/pages/index/index.vue +24 -0
  1039. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/src/store/userStore.js +11 -0
  1040. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/src/uni_modules/uview-ui/components/u-thing.js +5 -0
  1041. package/skills/a2h-page-specgen/scripts/test/fixtures/fp.mkdb.mjs +144 -0
  1042. package/skills/a2h-page-specgen/scripts/test/fixtures/hg.mkdb.mjs +112 -0
  1043. package/skills/a2h-page-specgen/scripts/test/fixtures/src/BottomPanels.java +14 -0
  1044. package/skills/a2h-page-specgen/scripts/test/fixtures/src/BottomPanels.kt +14 -0
  1045. package/skills/a2h-page-specgen/scripts/test/fixtures/src/BottomPanelsKotlinForms.kt +12 -0
  1046. package/skills/a2h-page-specgen/scripts/test/fixtures/src/ChildContent.java +6 -0
  1047. package/skills/a2h-page-specgen/scripts/test/fixtures/src/ComposeLifecycle.kt +26 -0
  1048. package/skills/a2h-page-specgen/scripts/test/fixtures/src/LifecycleCallAndOverride.java +10 -0
  1049. package/skills/a2h-page-specgen/scripts/test/fixtures/src/LifecycleHooks.kt +31 -0
  1050. package/skills/a2h-page-specgen/scripts/test/fixtures/src/MainFragment.java +6 -0
  1051. package/skills/a2h-page-specgen/scripts/test/fixtures/src/ManyLifecycleHooks.kt +12 -0
  1052. package/skills/a2h-page-specgen/scripts/test/fixtures/src/ManyListeners.java +12 -0
  1053. package/skills/a2h-page-specgen/scripts/test/fixtures/src/PlainActivity.java +3 -0
  1054. package/skills/a2h-page-specgen/scripts/test/fixtures/src/RefreshOnResume.java +7 -0
  1055. package/skills/a2h-page-specgen/scripts/test/fixtures/src/RefreshResultNoise.kt +36 -0
  1056. package/skills/a2h-page-specgen/scripts/test/fixtures/src/SelectionView.java +5 -0
  1057. package/skills/a2h-page-specgen/scripts/test/fixtures/src/ShowPage.vue +12 -0
  1058. package/skills/a2h-page-specgen/scripts/test/fixtures/src/ThirdPartyLifecycle.kt +25 -0
  1059. package/skills/a2h-page-specgen/scripts/test/fixtures/src/fragment_detail.xml +1 -0
  1060. package/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/App.vue +1 -0
  1061. package/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/bundle-conflict-record.json +17 -0
  1062. package/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/bundle-record.json +17 -0
  1063. package/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/manifest.json +3 -0
  1064. package/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/pages/list/index.vue +80 -0
  1065. package/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/pages.json +14 -0
  1066. package/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/source-record.json +15 -0
  1067. package/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/src/components/RefreshPanel.vue +15 -0
  1068. package/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/src/composables/useRefresh.ts +50 -0
  1069. package/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/src/pages/help/index.vue +9 -0
  1070. package/skills/a2h-page-specgen/scripts/test/fixtures/uniapp-source/src/state/store.ts +4 -0
  1071. package/skills/a2h-page-specgen/scripts/test/fixtures/utg/click_paths.json +28 -0
  1072. package/skills/a2h-page-specgen/scripts/test/fixtures/utg/fold-chain/utg.json +12 -0
  1073. package/skills/a2h-page-specgen/scripts/test/fixtures/utg/utg.json +34 -0
  1074. package/skills/a2h-page-specgen/scripts/test/footprint-resolve.test.mjs +1029 -0
  1075. package/skills/a2h-page-specgen/scripts/test/footprint-roles.test.mjs +172 -0
  1076. package/skills/a2h-page-specgen/scripts/test/fsx.test.mjs +32 -0
  1077. package/skills/a2h-page-specgen/scripts/test/gate-partial.test.mjs +143 -0
  1078. package/skills/a2h-page-specgen/scripts/test/gate.test.mjs +1078 -0
  1079. package/skills/a2h-page-specgen/scripts/test/graph-evidence.test.mjs +332 -0
  1080. package/skills/a2h-page-specgen/scripts/test/helpers.mjs +188 -0
  1081. package/skills/a2h-page-specgen/scripts/test/hg.test.mjs +549 -0
  1082. package/skills/a2h-page-specgen/scripts/test/homegraph-process-fixture.mjs +130 -0
  1083. package/skills/a2h-page-specgen/scripts/test/homegraph-query.test.mjs +288 -0
  1084. package/skills/a2h-page-specgen/scripts/test/integration.test.mjs +368 -0
  1085. package/skills/a2h-page-specgen/scripts/test/interactions.test.mjs +310 -0
  1086. package/skills/a2h-page-specgen/scripts/test/inventory.test.mjs +250 -0
  1087. package/skills/a2h-page-specgen/scripts/test/keys.test.mjs +776 -0
  1088. package/skills/a2h-page-specgen/scripts/test/ledger-lock.test.mjs +77 -0
  1089. package/skills/a2h-page-specgen/scripts/test/ledger.test.mjs +464 -0
  1090. package/skills/a2h-page-specgen/scripts/test/main-module.test.mjs +43 -0
  1091. package/skills/a2h-page-specgen/scripts/test/operation-reviews.test.mjs +1002 -0
  1092. package/skills/a2h-page-specgen/scripts/test/plan-build.test.mjs +1103 -0
  1093. package/skills/a2h-page-specgen/scripts/test/prepare-homegraph-reproduction.mjs +365 -0
  1094. package/skills/a2h-page-specgen/scripts/test/prepare-homegraph.test.mjs +569 -0
  1095. package/skills/a2h-page-specgen/scripts/test/prepare-index.test.mjs +160 -0
  1096. package/skills/a2h-page-specgen/scripts/test/prepare-pipeline.test.mjs +326 -0
  1097. package/skills/a2h-page-specgen/scripts/test/prompt-tpl.test.mjs +236 -0
  1098. package/skills/a2h-page-specgen/scripts/test/prose.test.mjs +398 -0
  1099. package/skills/a2h-page-specgen/scripts/test/protocol-docs.test.mjs +531 -0
  1100. package/skills/a2h-page-specgen/scripts/test/reach.test.mjs +93 -0
  1101. package/skills/a2h-page-specgen/scripts/test/recovery-e2e.test.mjs +418 -0
  1102. package/skills/a2h-page-specgen/scripts/test/recovery-policy.test.mjs +14 -0
  1103. package/skills/a2h-page-specgen/scripts/test/recovery.test.mjs +1782 -0
  1104. package/skills/a2h-page-specgen/scripts/test/render.test.mjs +546 -0
  1105. package/skills/a2h-page-specgen/scripts/test/report.test.mjs +296 -0
  1106. package/skills/a2h-page-specgen/scripts/test/review-followup.test.mjs +467 -0
  1107. package/skills/a2h-page-specgen/scripts/test/scope.test.mjs +292 -0
  1108. package/skills/a2h-page-specgen/scripts/test/semantic-detail.test.mjs +949 -0
  1109. package/skills/a2h-page-specgen/scripts/test/source-text.test.mjs +181 -0
  1110. package/skills/a2h-page-specgen/scripts/test/submit.test.mjs +1231 -0
  1111. package/skills/a2h-page-specgen/scripts/test/uniapp-operation-evidence.test.mjs +639 -0
  1112. package/skills/a2h-page-specgen/scripts/test/utg-footprint-contract.test.mjs +274 -0
  1113. package/skills/a2h-page-specgen/scripts/test/utg-io.test.mjs +90 -0
  1114. package/skills/a2h-page-specgen/scripts/test/waker-event-store.test.mjs +1365 -0
  1115. package/skills/a2h-page-specgen/scripts/test/waker-process.test.mjs +1801 -0
  1116. package/skills/a2h-page-specgen/scripts/test/waker.test.mjs +1993 -0
  1117. package/skills/a2h-page-specgen/scripts/test/watchdog.test.mjs +342 -0
  1118. package/skills/a2h-page-specgen/scripts/waker.mjs +1301 -0
  1119. package/skills/a2h-page-specgen/scripts/watchdog.mjs +299 -0
  1120. package/skills/a2h-resource-convert/SKILL.md +9 -1
  1121. package/skills/a2h-resource-convert/references/code-vector-icon-rules.md +2 -1
  1122. package/skills/a2h-resource-convert/references/incremental-page-migration.md +23 -2
  1123. package/skills/a2h-resource-convert/references/lottie-conversion-rules.md +7 -0
  1124. package/skills/a2h-resource-convert/references/step4-resource-types.md +2 -0
  1125. package/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +115 -53
  1126. package/skills/a2h-resource-convert/scripts/a2h_resource_incremental.ts +68 -0
  1127. package/skills/a2h-resource-convert/scripts/code_vector_icons.ts +45 -3
  1128. package/skills/a2h-resource-convert/scripts/extract_page_resources.ts +42 -5
  1129. package/skills/a2h-resource-convert/scripts/lottie_hosts.ts +415 -0
  1130. package/skills/a2h-resource-convert/scripts/lottie_refs.ts +398 -0
  1131. package/skills/a2h-resource-convert/scripts/merge_mapping.ts +316 -0
  1132. package/skills/a2h-resource-convert/scripts/svg_fidelity_check.ts +2 -1
  1133. package/skills/a2h-resource-convert/scripts/tests/adaptive_icon.test.mjs +182 -0
  1134. package/skills/a2h-resource-convert/scripts/tests/app_identity.test.mjs +206 -0
  1135. package/skills/a2h-resource-convert/scripts/tests/code_vector_guard.test.mjs +75 -0
  1136. package/skills/a2h-resource-convert/scripts/tests/docs_only_i18n.test.mjs +44 -0
  1137. package/skills/a2h-resource-convert/scripts/tests/lottie_hosts.test.mjs +222 -0
  1138. package/skills/a2h-resource-convert/scripts/tests/lottie_incremental.test.mjs +178 -0
  1139. package/skills/a2h-resource-convert/scripts/tests/merge_mapping.test.mjs +201 -0
  1140. package/skills/a2h-spec-design-pipeline/SKILL.md +98 -121
  1141. package/skills/a2h-spec-design-pipeline/references/coding-loop.md +170 -45
  1142. package/skills/a2h-spec-design-pipeline/references/execution-model.md +62 -12
  1143. package/skills/a2h-spec-design-pipeline/references/final-report-template.md +6 -4
  1144. package/skills/a2h-spec-design-pipeline/references/homegraph-cli.md +229 -0
  1145. package/skills/a2h-spec-design-pipeline/references/initialization.md +49 -6
  1146. package/skills/a2h-spec-design-pipeline/references/merge-queue.md +198 -54
  1147. package/skills/a2h-spec-design-pipeline/references/permission-index.json +206 -0
  1148. package/skills/a2h-spec-design-pipeline/references/post-loop.md +23 -0
  1149. package/skills/a2h-spec-design-pipeline/references/resolver-prompt.md +67 -0
  1150. package/skills/a2h-spec-design-pipeline/references/review-loop.md +46 -0
  1151. package/skills/a2h-spec-design-pipeline/references/scripts.md +47 -14
  1152. package/skills/a2h-spec-design-pipeline/references/shared-layer.md +390 -0
  1153. package/skills/a2h-spec-design-pipeline/references/state-and-resume.md +148 -29
  1154. package/skills/a2h-spec-design-pipeline/references/static-defect-gate.md +104 -24
  1155. package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleMeta.json +18 -0
  1156. package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleSet.json +16 -0
  1157. package/skills/a2h-spec-design-pipeline/rules/migration-rules/data/README.md +47 -0
  1158. package/skills/a2h-spec-design-pipeline/rules/migration-rules/data/api-param-contract.json +31 -0
  1159. package/skills/a2h-spec-design-pipeline/rules/migration-rules/data/api-permission-map.json +698 -0
  1160. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/api-permission-declared-cn.md +96 -0
  1161. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/api-permission-declared-en.md +103 -0
  1162. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-runtime-pitfall-cn.md +124 -0
  1163. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-runtime-pitfall-en.md +138 -0
  1164. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/platform-api-contract-cn.md +106 -0
  1165. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/platform-api-contract-en.md +113 -0
  1166. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/ApiPermissionDeclaredCheck.js +705 -0
  1167. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/ArkUIRuntimePitfallCheck.js +1063 -0
  1168. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/PlatformApiContractCheck.js +473 -0
  1169. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/platform/ExtraDataSubCheck.js +485 -0
  1170. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/index.js +13 -0
  1171. package/skills/a2h-spec-design-pipeline/rules/migration-rules/package.json +18 -0
  1172. package/skills/a2h-spec-design-pipeline/scripts/branch_landed.ts +12 -38
  1173. package/skills/a2h-spec-design-pipeline/scripts/check_design_map.ts +108 -0
  1174. package/skills/a2h-spec-design-pipeline/scripts/check_permissions.ts +420 -0
  1175. package/skills/a2h-spec-design-pipeline/scripts/check_review_evidence.ts +45 -0
  1176. package/skills/a2h-spec-design-pipeline/scripts/dispatch/evidence.mjs +95 -7
  1177. package/skills/a2h-spec-design-pipeline/scripts/dispatch/fold.mjs +156 -7
  1178. package/skills/a2h-spec-design-pipeline/scripts/dispatch/landing.mjs +71 -0
  1179. package/skills/a2h-spec-design-pipeline/scripts/dispatch/progress.mjs +22 -3
  1180. package/skills/a2h-spec-design-pipeline/scripts/dispatch/reconcile.mjs +63 -4
  1181. package/skills/a2h-spec-design-pipeline/scripts/dispatch/wait.mjs +33 -3
  1182. package/skills/a2h-spec-design-pipeline/scripts/dispatch/worktree.mjs +2 -2
  1183. package/skills/a2h-spec-design-pipeline/scripts/dispatch.mjs +232 -13
  1184. package/skills/a2h-spec-design-pipeline/scripts/ensure_index.ts +866 -0
  1185. package/skills/a2h-spec-design-pipeline/scripts/fixtures/homecheck-stub.cjs +47 -0
  1186. package/skills/a2h-spec-design-pipeline/scripts/homecheck_scan.ts +220 -44
  1187. package/skills/a2h-spec-design-pipeline/scripts/lib/shared_classes.ts +113 -0
  1188. package/skills/a2h-spec-design-pipeline/scripts/lib/shared_docs.ts +202 -0
  1189. package/skills/a2h-spec-design-pipeline/scripts/lib/wiring.ts +58 -0
  1190. package/skills/a2h-spec-design-pipeline/scripts/plan_groups.ts +178 -14
  1191. package/skills/a2h-spec-design-pipeline/scripts/resolve_wiring.ts +3 -0
  1192. package/skills/a2h-spec-design-pipeline/scripts/resolver_prompt.ts +368 -0
  1193. package/skills/a2h-spec-design-pipeline/scripts/scan_shared.ts +642 -0
  1194. package/skills/a2h-spec-design-pipeline/scripts/sync_permission_index.ts +340 -0
  1195. package/skills/a2h-spec-design-pipeline/scripts/test_api_permission_declared.ts +281 -0
  1196. package/skills/a2h-spec-design-pipeline/scripts/test_arkui_runtime_pitfall.ts +690 -0
  1197. package/skills/a2h-spec-design-pipeline/scripts/test_check_design_map.ts +46 -0
  1198. package/skills/a2h-spec-design-pipeline/scripts/test_check_permissions.ts +201 -0
  1199. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_commands.mjs +42 -8
  1200. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_e2e.mjs +27 -9
  1201. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_evidence.mjs +242 -9
  1202. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_fold.mjs +192 -7
  1203. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_landing.mjs +531 -0
  1204. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_progress.mjs +49 -1
  1205. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_reconcile.mjs +92 -4
  1206. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_wait.mjs +51 -0
  1207. package/skills/a2h-spec-design-pipeline/scripts/test_ensure_index.ts +572 -0
  1208. package/skills/a2h-spec-design-pipeline/scripts/test_ensure_index_real.ts +56 -0
  1209. package/skills/a2h-spec-design-pipeline/scripts/test_homecheck_scan.ts +17 -10
  1210. package/skills/a2h-spec-design-pipeline/scripts/test_homegraph_docs.ts +217 -0
  1211. package/skills/a2h-spec-design-pipeline/scripts/test_permission_index.ts +214 -0
  1212. package/skills/a2h-spec-design-pipeline/scripts/test_plan_groups.ts +155 -0
  1213. package/skills/a2h-spec-design-pipeline/scripts/test_platform_api_contract.ts +308 -0
  1214. package/skills/a2h-spec-design-pipeline/scripts/test_resolve_wiring.ts +14 -0
  1215. package/skills/a2h-spec-design-pipeline/scripts/test_resolver_prompt.ts +401 -0
  1216. package/skills/a2h-spec-design-pipeline/scripts/test_scan_shared.ts +996 -0
  1217. package/skills/a2h-spec-design-pipeline/scripts/test_shared_classes.ts +80 -0
  1218. package/skills/a2h-spec-design-pipeline/scripts/test_shared_docs.ts +205 -0
  1219. package/skills/a2h-spec-design-pipeline/scripts/test_shared_layer_docs.ts +165 -0
  1220. package/skills/a2h-spec-design-pipeline/scripts/test_shared_layer_e2e.ts +85 -0
  1221. package/skills/a2h-spec-design-pipeline/scripts/test_validate_shared_manifest.ts +720 -0
  1222. package/skills/a2h-spec-design-pipeline/scripts/test_wiring.ts +40 -0
  1223. package/skills/a2h-spec-design-pipeline/scripts/validate_shared_manifest.ts +566 -0
  1224. package/skills/a2h-spec-generate/SKILL.md +89 -23
  1225. package/skills/a2h-spec-generate/references/batch-mode.md +78 -17
  1226. package/skills/a2h-spec-generate/references/dispatch-watchdog.md +150 -0
  1227. package/skills/a2h-spec-generate/references/fusion-task-contract.md +7 -0
  1228. package/skills/a2h-spec-generate/references/review-checklist.md +1 -0
  1229. package/skills/a2h-spec-generate/references/specs.schema.json +24 -11
  1230. package/skills/a2h-spec-generate/references/synthesis-rules.md +4 -2
  1231. package/skills/a2h-spec-generate/references/worker-rules.md +6 -3
  1232. package/skills/a2h-spec-generate/scripts/check-fused-spec.mjs +4 -5
  1233. package/skills/a2h-spec-generate/scripts/check_spec.ts +145 -14
  1234. package/skills/a2h-spec-generate/scripts/collect-specs.mjs +261 -19
  1235. package/skills/a2h-spec-generate/scripts/dispatch-watch.mjs +1168 -0
  1236. package/skills/a2h-spec-generate/scripts/ensure-index.mjs +1 -2
  1237. package/skills/a2h-spec-generate/scripts/feature-stem.mjs +1 -2
  1238. package/skills/a2h-spec-generate/scripts/publish-specs.mjs +1 -2
  1239. package/skills/a2h-spec-generate/scripts/regroup-by-page.mjs +1 -2
  1240. package/skills/a2h-spec-generate/scripts/render-tasks.mjs +25 -46
  1241. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/build.ts +26 -27
  1242. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/component-variants.ts +3 -6
  1243. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/policy.ts +31 -32
  1244. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/traceability.ts +2 -3
  1245. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/req-model/build.ts +15 -26
  1246. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/area-facts.ts +102 -81
  1247. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/behavior-seed.ts +39 -19
  1248. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/library-evidence.ts +12 -13
  1249. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/navigation-guard.ts +363 -0
  1250. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/task-contract.ts +35 -196
  1251. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/contracts.ts +3 -1
  1252. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/task-contract.ts +22 -96
  1253. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/tree-sitter-adapter.ts +3 -4
  1254. package/skills/a2h-spec-generate/scripts/reqgen/src/model/contracts.ts +1 -1
  1255. package/skills/a2h-spec-generate/scripts/reqgen/src/model/finalize.ts +74 -7
  1256. package/skills/a2h-spec-generate/scripts/reqgen/src/model/prepare.ts +51 -7
  1257. package/skills/a2h-spec-generate/scripts/reqgen/src/model/task.ts +42 -111
  1258. package/skills/a2h-spec-generate/scripts/reqgen/src/requirement-scope.ts +1 -20
  1259. package/skills/a2h-spec-generate/scripts/reqgen/src/source-index/homegraph.ts +1 -2
  1260. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/req-text.ts +3 -4
  1261. package/skills/a2h-spec-generate/scripts/reqgen/test/control-fact-join.test.ts +50 -0
  1262. package/skills/a2h-spec-generate/scripts/reqgen/test/control-name-uniapp.test.ts +75 -0
  1263. package/skills/a2h-spec-generate/scripts/reqgen/test/cross-area-anchor.test.ts +256 -0
  1264. package/skills/a2h-spec-generate/scripts/reqgen/test/fixtures/fusion-run.ts +243 -0
  1265. package/skills/a2h-spec-generate/scripts/reqgen/test/fixtures/zip.ts +63 -0
  1266. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-area-facts.test.ts +650 -0
  1267. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-detectors.test.ts +176 -0
  1268. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-e2e.test.ts +103 -0
  1269. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-schema.test.ts +111 -0
  1270. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-seed.test.ts +195 -0
  1271. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-selfcheck.test.ts +307 -0
  1272. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-contract.test.ts +347 -0
  1273. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-finalize.test.ts +1948 -0
  1274. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-library-evidence.test.ts +239 -0
  1275. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-navigation-guard.test.ts +277 -0
  1276. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-prepare.test.ts +844 -0
  1277. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-scope.test.ts +339 -0
  1278. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-selfcheck.test.ts +1253 -0
  1279. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-spec.test.ts +608 -0
  1280. package/skills/a2h-spec-generate/scripts/reqgen/test/model-cli-blockers.test.ts +117 -0
  1281. package/skills/a2h-spec-generate/scripts/reqgen/test/model-scope.test.ts +411 -0
  1282. package/skills/a2h-spec-generate/scripts/reqgen/test/model-seeds.test.ts +175 -0
  1283. package/skills/a2h-spec-generate/scripts/reqgen/test/model-task-contract.test.ts +300 -0
  1284. package/skills/a2h-spec-generate/scripts/reqgen/test/model-v4.test.ts +1061 -0
  1285. package/skills/a2h-spec-generate/scripts/reqgen/test/specgen-completeness.test.ts +286 -0
  1286. package/skills/a2h-spec-generate/scripts/reqgen/test/stagem-stored-path.test.ts +25 -0
  1287. package/skills/a2h-spec-generate/scripts/reqgen/test/uniapp-scanner.test.ts +159 -0
  1288. package/skills/a2h-spec-generate/scripts/reqgen/test/zip.test.ts +61 -0
  1289. package/skills/a2h-spec-generate/test/check-fused-spec.test.mjs +879 -0
  1290. package/skills/a2h-spec-generate/test/check-spec.test.ts +430 -0
  1291. package/skills/a2h-spec-generate/test/collect-specs.test.mjs +811 -0
  1292. package/skills/a2h-spec-generate/test/detect-project.test.mjs +37 -0
  1293. package/skills/a2h-spec-generate/test/dispatch-watch.test.mjs +606 -0
  1294. package/skills/a2h-spec-generate/test/ensure-index.test.mjs +229 -0
  1295. package/skills/a2h-spec-generate/test/feature-stem.test.mjs +157 -0
  1296. package/skills/a2h-spec-generate/test/fixtures/android/app/src/main/AndroidManifest.xml +3 -0
  1297. package/skills/a2h-spec-generate/test/fixtures/android/build.gradle +3 -0
  1298. package/skills/a2h-spec-generate/test/fixtures/android/settings.gradle +3 -0
  1299. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/package.json +9 -0
  1300. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/App.vue +8 -0
  1301. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/components/MyCard.vue +9 -0
  1302. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/feature/editor/index.vue +1 -0
  1303. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/main.ts +6 -0
  1304. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/manifest.json +4 -0
  1305. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/detail/index.vue +1 -0
  1306. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/home/index.vue +33 -0
  1307. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/settings/index.vue +1 -0
  1308. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages.json +23 -0
  1309. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/services/items.ts +3 -0
  1310. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/tsconfig.json +8 -0
  1311. package/skills/a2h-spec-generate/test/fixtures/unknown/README.txt +1 -0
  1312. package/skills/a2h-spec-generate/test/inspect-uniapp.test.mjs +54 -0
  1313. package/skills/a2h-spec-generate/test/prepare-facts.test.mjs +41 -0
  1314. package/skills/a2h-spec-generate/test/publication-verdict.test.mjs +182 -0
  1315. package/skills/a2h-spec-generate/test/publish-specs.test.mjs +295 -0
  1316. package/skills/a2h-spec-generate/test/regroup-by-page.test.mjs +354 -0
  1317. package/skills/a2h-spec-generate/test/render-tasks.test.mjs +596 -0
  1318. package/skills/a2h-spec-generate/test/report.test.mjs +47 -0
  1319. package/skills/a2h-utg-explorer/SKILL.md +9 -3
  1320. package/skills/a2h-utg-explorer/references/architecture.md +7 -0
  1321. package/skills/a2h-utg-explorer/scripts/audit.mjs +8 -2
  1322. package/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +120 -85
  1323. package/skills/a2h-utg-explorer/scripts/direct_launch.mjs +47 -2
  1324. package/skills/a2h-utg-explorer/scripts/hint_check.mjs +1 -2
  1325. package/skills/a2h-utg-explorer/scripts/hybrid_route_cdp.mjs +376 -0
  1326. package/skills/a2h-utg-explorer/scripts/plan.mjs +8 -0
  1327. package/skills/a2h-utg-explorer/scripts/recover.mjs +1 -1
  1328. package/skills/a2h-utg-explorer/scripts/recover_d.mjs +288 -21
  1329. package/skills/a2h-utg-explorer/scripts/rejudge.mjs +5 -3
  1330. package/skills/a2h-utg-explorer/scripts/report.mjs +89 -0
  1331. package/skills/a2h-utg-explorer/scripts/run_cycle.mjs +67 -10
  1332. package/skills/a2h-utg-explorer/scripts/run_device.mjs +10 -2
  1333. package/skills/a2h-utg-explorer/scripts/seed_recipes.mjs +426 -0
  1334. package/skills/a2h-utg-explorer/scripts/tests/attest.test.mjs +66 -0
  1335. package/skills/a2h-utg-explorer/scripts/tests/blank_wait.test.mjs +126 -0
  1336. package/skills/a2h-utg-explorer/scripts/tests/calendar_round_fixes.test.mjs +244 -0
  1337. package/skills/a2h-utg-explorer/scripts/tests/chain.test.mjs +45 -0
  1338. package/skills/a2h-utg-explorer/scripts/tests/compose_identity.test.mjs +302 -0
  1339. package/skills/a2h-utg-explorer/scripts/tests/content_wait.test.mjs +207 -0
  1340. package/skills/a2h-utg-explorer/scripts/tests/coverage_rules.test.mjs +104 -0
  1341. package/skills/a2h-utg-explorer/scripts/tests/d_prereqs.test.mjs +231 -0
  1342. package/skills/a2h-utg-explorer/scripts/tests/default_override.test.mjs +109 -0
  1343. package/skills/a2h-utg-explorer/scripts/tests/device_health.test.mjs +160 -0
  1344. package/skills/a2h-utg-explorer/scripts/tests/device_locale_dialogs.test.mjs +29 -0
  1345. package/skills/a2h-utg-explorer/scripts/tests/device_locale_identity.test.mjs +77 -0
  1346. package/skills/a2h-utg-explorer/scripts/tests/device_lock_retry.test.mjs +187 -0
  1347. package/skills/a2h-utg-explorer/scripts/tests/diagnostics.test.mjs +254 -0
  1348. package/skills/a2h-utg-explorer/scripts/tests/direct_launch.test.mjs +130 -0
  1349. package/skills/a2h-utg-explorer/scripts/tests/explorer_review_fixes.test.mjs +137 -0
  1350. package/skills/a2h-utg-explorer/scripts/tests/final_utg.test.mjs +135 -0
  1351. package/skills/a2h-utg-explorer/scripts/tests/first_round_phases.test.mjs +16 -0
  1352. package/skills/a2h-utg-explorer/scripts/tests/foreground_spelling.test.mjs +155 -0
  1353. package/skills/a2h-utg-explorer/scripts/tests/fresh_state_plan.test.mjs +78 -0
  1354. package/skills/a2h-utg-explorer/scripts/tests/generalization_fixes.test.mjs +252 -0
  1355. package/skills/a2h-utg-explorer/scripts/tests/hint_check.test.mjs +129 -0
  1356. package/skills/a2h-utg-explorer/scripts/tests/holds_without_data_parity.test.mjs +26 -0
  1357. package/skills/a2h-utg-explorer/scripts/tests/hybrid_route.test.mjs +120 -0
  1358. package/skills/a2h-utg-explorer/scripts/tests/hybrid_route_identity.test.mjs +146 -0
  1359. package/skills/a2h-utg-explorer/scripts/tests/interruptions.test.mjs +614 -0
  1360. package/skills/a2h-utg-explorer/scripts/tests/launch_bridge.test.mjs +214 -0
  1361. package/skills/a2h-utg-explorer/scripts/tests/launch_failure.test.mjs +40 -0
  1362. package/skills/a2h-utg-explorer/scripts/tests/node_coverage.test.mjs +193 -0
  1363. package/skills/a2h-utg-explorer/scripts/tests/overflow_prefix.test.mjs +327 -0
  1364. package/skills/a2h-utg-explorer/scripts/tests/overlay_identity.test.mjs +204 -0
  1365. package/skills/a2h-utg-explorer/scripts/tests/page_identity_tiers.test.mjs +393 -0
  1366. package/skills/a2h-utg-explorer/scripts/tests/pager_navigation.test.mjs +119 -0
  1367. package/skills/a2h-utg-explorer/scripts/tests/panel_routes.test.mjs +208 -0
  1368. package/skills/a2h-utg-explorer/scripts/tests/pipeline.test.mjs +240 -0
  1369. package/skills/a2h-utg-explorer/scripts/tests/pr169_review_fixes.test.mjs +218 -0
  1370. package/skills/a2h-utg-explorer/scripts/tests/pr191_review_fixes.test.mjs +292 -0
  1371. package/skills/a2h-utg-explorer/scripts/tests/recover.test.mjs +212 -0
  1372. package/skills/a2h-utg-explorer/scripts/tests/recover_b.test.mjs +173 -0
  1373. package/skills/a2h-utg-explorer/scripts/tests/recover_d.test.mjs +280 -0
  1374. package/skills/a2h-utg-explorer/scripts/tests/recover_d_grounding.test.mjs +164 -0
  1375. package/skills/a2h-utg-explorer/scripts/tests/replay_reroute.test.mjs +143 -0
  1376. package/skills/a2h-utg-explorer/scripts/tests/review_fixes.test.mjs +213 -0
  1377. package/skills/a2h-utg-explorer/scripts/tests/robustness_fixes.test.mjs +345 -0
  1378. package/skills/a2h-utg-explorer/scripts/tests/run_cycle.test.mjs +458 -0
  1379. package/skills/a2h-utg-explorer/scripts/tests/run_cycle_follow.test.mjs +35 -0
  1380. package/skills/a2h-utg-explorer/scripts/tests/runner_capabilities.test.mjs +194 -0
  1381. package/skills/a2h-utg-explorer/scripts/tests/scope.test.mjs +229 -0
  1382. package/skills/a2h-utg-explorer/scripts/tests/scroll_sweep.test.mjs +336 -0
  1383. package/skills/a2h-utg-explorer/scripts/tests/seed_recipes.test.mjs +261 -0
  1384. package/skills/a2h-utg-explorer/scripts/tests/semantics.test.mjs +102 -0
  1385. package/skills/a2h-utg-explorer/scripts/tests/snapshot_integrity.test.mjs +142 -0
  1386. package/skills/a2h-utg-explorer/scripts/tests/state_ambiguity.test.mjs +92 -0
  1387. package/skills/a2h-utg-explorer/scripts/tests/string_tables_twin_ties.test.mjs +83 -0
  1388. package/skills/a2h-utg-explorer/scripts/tests/tar_fixture.mjs +12 -0
  1389. package/skills/a2h-utg-explorer/scripts/tests/twin_opener.test.mjs +119 -0
  1390. package/skills/a2h-utg-explorer/scripts/tests/u2_backend.test.mjs +346 -0
  1391. package/skills/a2h-utg-explorer/scripts/tests/ui_state_anchors.test.mjs +112 -0
  1392. package/skills/a2h-utg-explorer/scripts/tests/variant_strings.test.mjs +63 -0
  1393. package/skills/a2h-utg-explorer/scripts/tests/worklist_parts.test.mjs +24 -0
  1394. package/skills/a2h-utg-explorer/scripts/utg_explorer/adapters.mjs +135 -7
  1395. package/skills/a2h-utg-explorer/scripts/utg_explorer/diagnostics.mjs +196 -0
  1396. package/skills/a2h-utg-explorer/scripts/utg_explorer/hybrid_route.mjs +140 -0
  1397. package/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +245 -69
  1398. package/skills/a2h-utg-explorer/scripts/utg_explorer/state_phase.mjs +47 -0
  1399. package/skills/a2h-utg-explorer/scripts/utg_explorer/strings.mjs +164 -0
  1400. package/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +718 -42
  1401. package/skills/a2h-utg-explorer/scripts/variant.mjs +57 -11
  1402. package/skills/a2h-utg-static/SKILL.md +6 -2
  1403. package/skills/a2h-utg-static/scripts/assemble.mjs +93 -3
  1404. package/skills/a2h-utg-static/scripts/click_paths.mjs +135 -25
  1405. package/skills/a2h-utg-static/scripts/compose_body_text.mjs +3 -3
  1406. package/skills/a2h-utg-static/scripts/compose_overlay.mjs +110 -3
  1407. package/skills/a2h-utg-static/scripts/compose_titles.mjs +5 -5
  1408. package/skills/a2h-utg-static/scripts/compose_widgets.mjs +4 -4
  1409. package/skills/a2h-utg-static/scripts/data_model.mjs +590 -0
  1410. package/skills/a2h-utg-static/scripts/data_producers.mjs +431 -0
  1411. package/skills/a2h-utg-static/scripts/fragment_nav.mjs +2 -3
  1412. package/skills/a2h-utg-static/scripts/hybrid_scope.mjs +46 -1
  1413. package/skills/a2h-utg-static/scripts/label_resolve.mjs +49 -4
  1414. package/skills/a2h-utg-static/scripts/lib/hybrid-provenance.mjs +201 -0
  1415. package/skills/a2h-utg-static/scripts/lib/uniapp-routes.mjs +195 -0
  1416. package/skills/a2h-utg-static/scripts/menu_nav.mjs +1 -1
  1417. package/skills/a2h-utg-static/scripts/nl_hints.mjs +34 -7
  1418. package/skills/a2h-utg-static/scripts/presenter_nav.mjs +1 -2
  1419. package/skills/a2h-utg-static/scripts/route_interceptor.mjs +21 -7
  1420. package/skills/a2h-utg-static/scripts/run_pipeline.mjs +86 -4
  1421. package/skills/a2h-utg-static/scripts/static_prior.mjs +26 -29
  1422. package/skills/a2h-utg-static/scripts/tests/test_activity_gates.mjs +84 -0
  1423. package/skills/a2h-utg-static/scripts/tests/test_carry_answers.mjs +30 -0
  1424. package/skills/a2h-utg-static/scripts/tests/test_compose_res_text.mjs +18 -0
  1425. package/skills/a2h-utg-static/scripts/tests/test_data_model.mjs +120 -0
  1426. package/skills/a2h-utg-static/scripts/tests/test_data_producers.mjs +114 -0
  1427. package/skills/a2h-utg-static/scripts/tests/test_guard_kinds_locale.mjs +12 -0
  1428. package/skills/a2h-utg-static/scripts/tests/test_hybrid_provenance.mjs +150 -0
  1429. package/skills/a2h-utg-static/scripts/tests/test_hybrid_scope.mjs +165 -1
  1430. package/skills/a2h-utg-static/scripts/tests/test_library_activity.mjs +45 -0
  1431. package/skills/a2h-utg-static/scripts/tests/test_login_interceptor.mjs +38 -0
  1432. package/skills/a2h-utg-static/scripts/tests/test_module_strings.mjs +35 -1
  1433. package/skills/a2h-utg-static/scripts/tests/test_nl_hints_default_override.mjs +50 -0
  1434. package/skills/a2h-utg-static/scripts/tests/test_pipeline_llm_phases.mjs +21 -0
  1435. package/skills/a2h-utg-static/scripts/tests/test_pr169_review_fixes.mjs +172 -0
  1436. package/skills/a2h-utg-static/scripts/tests/test_redirect_path_cost.mjs +136 -0
  1437. package/skills/a2h-utg-static/scripts/tests/test_route_token_words.mjs +29 -1
  1438. package/skills/a2h-utg-static/scripts/tests/test_uniapp_route_jump.mjs +175 -0
  1439. package/skills/a2h-utg-static/scripts/tests/test_uniapp_routes.mjs +161 -0
  1440. package/skills/a2h-utg-static/scripts/tests/test_uniapp_source.mjs +99 -0
  1441. package/skills/a2h-utg-static/scripts/tests/test_utg_specgen_boundary.mjs +45 -0
  1442. package/skills/a2h-utg-static/scripts/tests/test_vm_nav_helper_navigate.mjs +21 -0
  1443. package/skills/a2h-utg-static/scripts/uniapp_nav.mjs +112 -69
  1444. package/skills/a2h-utg-static/scripts/vm_nav.mjs +9 -1
  1445. package/skills/a2h-app-migrate/scripts/i18n-term.d.mts +0 -5
  1446. package/skills/a2h-app-migrate/scripts/i18n-term.mjs +0 -54
  1447. package/skills/a2h-arch-generate/scripts/i18n-term.d.mts +0 -5
  1448. package/skills/a2h-arch-generate/scripts/i18n-term.mjs +0 -54
  1449. package/skills/a2h-arkts-logic-coder/scripts/design/i18n-term.d.mts +0 -5
  1450. package/skills/a2h-arkts-logic-coder/scripts/design/i18n-term.mjs +0 -54
  1451. package/skills/a2h-batch-ui-align/references/source-only-tier.md +0 -38
  1452. package/skills/a2h-batch-ui-align/scripts/i18n-term.d.mts +0 -5
  1453. package/skills/a2h-batch-ui-align/scripts/i18n-term.mjs +0 -54
  1454. package/skills/a2h-dashboard-render/scripts/i18n-term.d.mts +0 -5
  1455. package/skills/a2h-dashboard-render/scripts/i18n-term.mjs +0 -54
  1456. package/skills/a2h-resource-convert/scripts/i18n-term.d.mts +0 -5
  1457. package/skills/a2h-resource-convert/scripts/i18n-term.mjs +0 -54
  1458. package/skills/a2h-spec-design-pipeline/scripts/ensure_wt_index.ts +0 -885
  1459. package/skills/a2h-spec-design-pipeline/scripts/i18n-term.d.mts +0 -5
  1460. package/skills/a2h-spec-design-pipeline/scripts/i18n-term.mjs +0 -54
  1461. package/skills/a2h-spec-design-pipeline/scripts/test_ensure_wt_index.ts +0 -856
  1462. package/skills/a2h-spec-design-pipeline/scripts/test_i18n_term.ts +0 -70
  1463. package/skills/a2h-spec-generate/scripts/i18n-term.d.mts +0 -5
  1464. package/skills/a2h-spec-generate/scripts/i18n-term.mjs +0 -54
  1465. package/skills/a2h-spec-generate/scripts/reqgen/src/i18n-term.d.mts +0 -5
  1466. package/skills/a2h-spec-generate/scripts/reqgen/src/i18n-term.mjs +0 -54
  1467. package/skills/a2h-utg-explorer/scripts/i18n-term.d.mts +0 -5
  1468. package/skills/a2h-utg-explorer/scripts/i18n-term.mjs +0 -54
  1469. package/skills/a2h-utg-static/scripts/i18n-term.d.mts +0 -5
  1470. package/skills/a2h-utg-static/scripts/i18n-term.mjs +0 -54
  1471. package/skills/a2h-utg-static/scripts/tests/test_i18n_term.mjs +0 -155
@@ -0,0 +1,2714 @@
1
+ /**
2
+ * task_runner.mjs — port of task_runner.py. Verified parent recovery, finite selector search,
3
+ * scroll sweeps and evidence-backed mappings. Synchronous like the Python.
4
+ *
5
+ * Exports: deviceLock, DeviceBusy, lockOwner, lockWait, LOCK_WAIT_S, BudgetExhausted, _isHorizontal, _viewSig, TRANSIENT_DEVICE_RE, fixtureStepTarget, Runner,
6
+ * runCampaignPhase, deps (indirection used by tests to replace imported functions,
7
+ * e.g. deps.observationMatchesStatic, like monkeypatching the Python module global)
8
+ *
9
+ * `args` is a plain object with the argparse attributes: {campaign, config, phase, budget,
10
+ * max_tasks, coverage?}.
11
+ *
12
+ * device_lock: the Python OS advisory lock (msvcrt/fcntl on a byte file) is replaced by an
13
+ * exclusive lock file `<tmp>/utg-explorer-<sha256(serial)[:16]>.lock` (deviceLockPath) holding
14
+ * {"pid", "ts", "started"}. It is written to a tmp file first and hard-linked into place (link fails if the
15
+ * lock exists), so it never exists empty. A lock whose pid is no longer alive, or whose pid is
16
+ * alive but started at another time than `started` (Windows pid reuse), is stale and taken
17
+ * over (stealStale: under a steal guard, only while its content is unchanged); one that does not parse is held while younger than LOCK_GRACE_S (a writer from before this
18
+ * scheme), else stale. The lock also records its owner's campaign and argv. A held lock is waited
19
+ * for up to `waitS` (runCampaignPhase / run_device.mjs: config.device_lock_wait_s, default
20
+ * LOCK_WAIT_S), then raises DeviceBusy('Another explorer owns this device: pid N, campaign <path>,
21
+ * since <time>'); both runners turn that into DEVICE_UNAVAILABLE_EXIT, so run_cycle.mjs ends the
22
+ * call (DeviceDown) instead of recording a failed phase. run_device.mjs uses the same lock on both
23
+ * its paths, and both read campaign.json only once they hold it (a run that waited for the lock
24
+ * would otherwise save over the updates of the run it waited for).
25
+ *
26
+ * A phase blocked `device-unavailable` (the device did not come back within waitDevice) ends
27
+ * runCampaignPhase with SystemExit(DEVICE_UNAVAILABLE_EXIT), so run_cycle.mjs recovers the device
28
+ * and re-runs the phase instead of recording it done.
29
+ */
30
+ import * as fs from 'node:fs';
31
+ import {
32
+ get, mget, truthy, or, pyStr, pyEq, errStr, cpSlice, jsonDumps, sha256Hex, sortedBy, tupleKey, counter,
33
+ appendText, monotonic, sleep, toFloat, toInt, pJoin, pResolve, time as epoch, pyPrint, dset,
34
+ pathStr, uuid4Hex, SystemExit, pyPrintErr,
35
+ } from './_py.mjs';
36
+ import { deviceLockPath, LOCK_GRACE_S, holderGone, myStartMs } from './device_lock.mjs';
37
+ import {
38
+ DeviceAdapter, AdapterError, atomicWriteJson, event, readJson, matching, observationKey, ruleMatches, rowToggle, tarProblem,
39
+ } from './adapters.mjs';
40
+ import { applyStateAnchors, observationMatchesStatic, resolvePage, occludedIndices, resolveTwinByOpener, backCanReach, uiStatesOf, normalized, isInputNode } from './semantics.mjs';
41
+ import { coverageMode, coveredStaticIds, scopeOf } from './coverage.mjs';
42
+ import { COLLAPSE_MIN_CASCADE, collapsedPrefixes, collapseNote, emptyStateComponents, emptyStateShown } from './diagnostics.mjs';
43
+ import { loadStringTables, deviceTextsIn } from './strings.mjs';
44
+ import { triggerAttests } from './attest.mjs';
45
+ import { fallbackScope } from './state_phase.mjs';
46
+
47
+ /** Indirection for functions tests replace (Python patches module globals). */
48
+ export const deps = { observationMatchesStatic, resolvePage, triggerAttests };
49
+
50
+ /** deviceLockPath, LOCK_GRACE_S: device_lock.mjs (shared with device_health.mjs). */
51
+ export { deviceLockPath, LOCK_GRACE_S };
52
+
53
+ /** A steal guard older than this (s) belongs to a stealer that died mid-steal. */
54
+ export const STEAL_GUARD_S = 30;
55
+
56
+ /** run_device.mjs exit code for a phase blocked `device-unavailable` (run_cycle.mjs DEVICE_UNAVAILABLE_EXIT). */
57
+ export const DEVICE_UNAVAILABLE_EXIT = 75;
58
+
59
+ /** Default wait (s) for a device lock another explorer holds (config.device_lock_wait_s). */
60
+ export const LOCK_WAIT_S = 300;
61
+ const LOCK_POLL_S = 5;
62
+
63
+ /** The device lock is held by another explorer (`holder`: its parsed lock, or null). */
64
+ export class DeviceBusy extends Error {
65
+ constructor(message, holder = null) { super(message); this.name = 'DeviceBusy'; this.holder = holder; }
66
+ }
67
+
68
+ /** "pid N, campaign <path>, since <ISO time>" from a lock's content (fields it lacks are '?'). */
69
+ export function lockOwner(holder) {
70
+ const h = holder !== null && typeof holder === 'object' ? holder : {};
71
+ const ts = Number(get(h, 'ts'));
72
+ const since = Number.isFinite(ts) && ts > 0 ? new Date(ts * 1000).toISOString() : '?';
73
+ return `pid ${get(h, 'pid') ?? '?'}, campaign ${get(h, 'campaign') ?? '?'}, since ${since}`;
74
+ }
75
+
76
+ /**
77
+ * Exclusive create: `content` is written to a tmp file and hard-linked to `p` (fails if `p`
78
+ * exists), so `p` never exists empty or half written. false = `p` exists.
79
+ */
80
+ function linkCreate(p, content) {
81
+ const tmp = `${p}.${process.pid}.${uuid4Hex().slice(0, 8)}.tmp`;
82
+ fs.writeFileSync(tmp, content);
83
+ try { fs.linkSync(tmp, p); return true; } catch (e) {
84
+ if (e.code === 'EEXIST') { return false; }
85
+ throw e;
86
+ } finally { try { fs.unlinkSync(tmp); } catch { /* gone */ } }
87
+ }
88
+
89
+ /**
90
+ * Remove the stale lock at `lockPath` whose content was read as `seen`. Only the holder of the
91
+ * steal guard `<lock>.steal` (taken with linkCreate) inspects and removes a stale lock, and only
92
+ * while its content is still `seen`: a lock another competitor created meanwhile is never touched
93
+ * (the rename / put-back scheme this replaces could drop a third party's fresh lock and leave two
94
+ * holders). A guard left by a stealer that died is removed after STEAL_GUARD_S.
95
+ * true = the stale lock is gone (the caller then creates its own).
96
+ */
97
+ export function stealStale(lockPath, seen) {
98
+ const guard = `${lockPath}.steal`;
99
+ const token = JSON.stringify({ pid: process.pid, ts: epoch(), id: uuid4Hex() });
100
+ if (!linkCreate(guard, token)) {
101
+ try {
102
+ if (Date.now() / 1000 - fs.statSync(guard).mtimeMs / 1000 >= STEAL_GUARD_S) { fs.unlinkSync(guard); }
103
+ } catch { /* gone */ }
104
+ return false;
105
+ }
106
+ try {
107
+ let cur;
108
+ try { cur = fs.readFileSync(lockPath, 'utf8'); } catch { return true; }
109
+ if (cur !== seen) { return false; }
110
+ try { fs.unlinkSync(lockPath); } catch (e) { if (e.code !== 'ENOENT') { return false; } }
111
+ return true;
112
+ } finally {
113
+ try { if (fs.readFileSync(guard, 'utf8') === token) { fs.unlinkSync(guard); } } catch { /* gone */ }
114
+ }
115
+ }
116
+
117
+ /**
118
+ * deviceLock(serial[, fn][, {waitS, pollS, campaign}]): a held lock is retried every pollS for up
119
+ * to waitS seconds (default 0: fail at once), then DeviceBusy names its owner. The lock records
120
+ * its owner's start time (`started`): a live pid that started at another time reused a dead
121
+ * holder's pid (device_lock.mjs holderGone), so that lock is stale.
122
+ */
123
+ export function deviceLock(serial, fn = null, { waitS = 0, pollS = LOCK_POLL_S, campaign = null } = {}) {
124
+ const lockPath = deviceLockPath(serial);
125
+ const mine = JSON.stringify({ pid: process.pid, ts: epoch(), started: myStartMs(),
126
+ campaign: campaign === null ? null : pathStr(campaign), argv: process.argv.slice(1) });
127
+ const tryCreate = () => linkCreate(lockPath, mine);
128
+ let holder = null;
129
+ const attempt = () => {
130
+ if (tryCreate()) { return true; }
131
+ let text = null; let age = 0;
132
+ holder = null;
133
+ try { text = fs.readFileSync(lockPath, 'utf8'); age = Date.now() / 1000 - fs.statSync(lockPath).mtimeMs / 1000; } catch { text = null; }
134
+ if (text === null) { return tryCreate(); } // released meanwhile
135
+ try { holder = JSON.parse(text); } catch { holder = null; }
136
+ const parsed = holder !== null && typeof holder === 'object';
137
+ const stale = parsed ? holderGone(holder) : age >= LOCK_GRACE_S;
138
+ return stale && stealStale(lockPath, text) && tryCreate();
139
+ };
140
+ const deadline = monotonic() + Math.max(0, toFloat(waitS));
141
+ let acquired = attempt();
142
+ while (!acquired && monotonic() < deadline) {
143
+ sleep(Math.min(Math.max(0.05, toFloat(pollS)), Math.max(0.05, deadline - monotonic())));
144
+ acquired = attempt();
145
+ }
146
+ if (!acquired) {
147
+ const h = holder !== null && typeof holder === 'object' ? holder : null;
148
+ throw new DeviceBusy(`Another explorer owns this device: ${lockOwner(h)}`, h);
149
+ }
150
+ const onExit = () => release();
151
+ function release() {
152
+ process.removeListener('exit', onExit);
153
+ try { if (fs.readFileSync(lockPath, 'utf8') === mine) { fs.unlinkSync(lockPath); } } catch { /* gone */ }
154
+ }
155
+ process.on('exit', onExit);
156
+ if (!fn) { return { release }; }
157
+ try { return fn(); } finally { release(); }
158
+ }
159
+
160
+ /** BudgetExhausted (RuntimeError). */
161
+ export class BudgetExhausted extends Error {
162
+ constructor(message = '') { super(message); this.name = 'BudgetExhausted'; }
163
+ }
164
+
165
+ /** _is_horizontal(n): a sideways scrollable (horizontal class, or a strip >= 3x wider than tall). */
166
+ export function _isHorizontal(n) {
167
+ const cls = pyStr(get(n, 'class', ''));
168
+ if (['HorizontalScrollView', 'ViewPager', 'ViewPager2'].some((x) => cls.endsWith(x))) { return true; }
169
+ const b = or(get(n, 'bounds'), []);
170
+ return b.length === 4 && (b[2] - b[0]) >= 3 * Math.max(1, b[3] - b[1]);
171
+ }
172
+
173
+ const SIG_FIELDS = ['resource_id', 'class', 'text', 'content_desc', 'bounds'];
174
+
175
+ /** _view_sig(observation): every visible node with its bounds (sha256 of sorted-key JSON). */
176
+ export function _viewSig(observation) {
177
+ const value = [get(observation, 'activity'), get(observation, 'window'),
178
+ get(observation, 'nodes', []).filter((n) => truthy(get(n, 'visible', true))).map((n) => SIG_FIELDS.map((k) => get(n, k)))];
179
+ return sha256Hex(jsonDumps(value, { sort_keys: true, ensure_ascii: false }));
180
+ }
181
+
182
+ /** Device-side outages (retried after the device answers again), not app failures. */
183
+ const DEVICE_UNAVAILABLE = 'device-unavailable';
184
+
185
+ /**
186
+ * launchMismatch(msg, launchComponent): a block reason when `am start` could not find a class with
187
+ * the configured launcher's simple name but a different FQN, else null. The caller asks only for a
188
+ * task whose source_launch is the static launcher (`launcher`, compile_tasks launchAction). That is the static UTG
189
+ * resolving `.MainActivity` against the applicationId instead of the namespace (applicationIdSuffix
190
+ * ".debug" etc.): every source launch then fails, and skipping each task as
191
+ * entry-component-not-installed ended a round with nothing captured and no stated cause.
192
+ */
193
+ export function launchMismatch(msg, launchComponent) {
194
+ const m = /Activity class \{([^}]+)\}/.exec(pyStr(msg));
195
+ const cfg = pyStr(launchComponent ?? '');
196
+ if (!m || !cfg.includes('/')) { return null; }
197
+ const tried = m[1];
198
+ const cls = (c) => { const [pk, name] = c.split('/'); return name.startsWith('.') ? pk + name : name; };
199
+ const a = cls(tried); const b = cls(cfg);
200
+ if (a === b || a.split('.').pop() !== b.split('.').pop()) { return null; }
201
+ return `launch-component-mismatch: ${tried} is not installed but config.launch_component is ${cfg}; `
202
+ + 'the static UTG resolved the activity against the applicationId, re-run a2h-utg-static';
203
+ }
204
+
205
+ /**
206
+ * grantRuntimePermissions(device, config): `pm grant` the app's not-yet-granted runtime permissions
207
+ * unless `grant_runtime_permissions` is false. Shared by Runner and d_prereqs snapshot, which both
208
+ * `pm clear` (that revokes every grant) before a launch. Returns [granted, failed].
209
+ */
210
+ export function grantRuntimePermissions(device, config) {
211
+ const pkg = get(config, 'package');
212
+ const granted = []; const failed = [];
213
+ if (!truthy(pkg) || !truthy(get(config, 'grant_runtime_permissions', true))) { return [granted, failed]; }
214
+ let dump = '';
215
+ try { dump = device._shell('dumpsys', 'package', pkg); } catch { dump = ''; }
216
+ for (const perm of runtimePermissions(dump, { ungrantedOnly: true })) {
217
+ try { device._shell('pm', 'grant', pkg, perm); granted.push(perm); } catch { failed.push(perm); }
218
+ }
219
+ return [granted, failed];
220
+ }
221
+
222
+ export const TRANSIENT_DEVICE_RE = new RegExp(
223
+ "Can't find service|Cannot identify foreground window|device '[^']+' not found|"
224
+ + 'device offline|error: closed|device-timeout|ui-dump-(?:failed|remote-missing)|Foreground changed during capture');
225
+ /**
226
+ * Route-jump failure codes (hybrid_route_cdp.mjs, carried as `hybrid-route[<code>]: ...`). DOWN codes
227
+ * are deterministic and settle the phase's remaining route tasks; TRANSIENT codes are retried.
228
+ */
229
+ export const ROUTE_DOWN_CODES = new Set(['no-devtools-socket', 'uni-absent']);
230
+ export const ROUTE_TRANSIENT_CODES = new Set(['cdp-transient', 'adb-error', 'deadline']);
231
+ /** The code of a `hybrid-route[<code>]: ...` adapter error, else null. */
232
+ export function routeErrorCode(msg) {
233
+ const m = /hybrid-route\[([\w-]+)\]/.exec(String(msg));
234
+ return m ? m[1] : null;
235
+ }
236
+ /** The adapter's error for a foreground that moved between a capture's first and last read. */
237
+ const FOREGROUND_MOVED_RE = /Foreground changed during capture/;
238
+
239
+ /**
240
+ * What a failed fixture step acted on, for its `fixture-step-failed` reason: the selector(s) of a
241
+ * tap, else the launch target (component / component_fqn / uri / intent action). A launch has no
242
+ * selector, so the reason read `launch ""` and hid which component failed (yd-weather 11-14).
243
+ */
244
+ export function fixtureStepTarget(action) {
245
+ for (const k of ['selectors', 'selector', 'component', 'component_fqn', 'uri', 'action']) {
246
+ if (truthy(get(action, k))) { return action[k]; }
247
+ }
248
+ return '';
249
+ }
250
+
251
+ const isVisible = (n) => truthy(get(n, 'visible', true));
252
+ /** Blank waits in a row that ran out before blank frames stop being waited on (Runner.awaitContent). */
253
+ const BLANK_RUN_OUTS = 3;
254
+ /** The distinct visible texts / content descriptions of a capture (at most 200), for a revision item. */
255
+ const visibleTexts = (observation) => [...new Set(get(observation ?? {}, 'nodes', []).filter((n) => isVisible(n))
256
+ .flatMap((n) => [get(n, 'text'), get(n, 'content_desc')]).filter((t) => truthy(t)).map((t) => pyStr(t).trim())
257
+ .filter((t) => t.length > 0))].slice(0, 200);
258
+ /** A consent CheckBox's own label ("I have read and agree"), as against an optional one ("Receive push notifications"). */
259
+ const CONSENT_BOX_RE = /同意|已阅读|have read|agree|accept/i; // device dialogs follow the device locale, not the build language
260
+ /**
261
+ * A consent dialog's own positive control when it is not android:id/button1 (a custom layout):
262
+ * the whole label is an accept ("Agree", "Agree and continue", "I agree", "Accept", "Agree", "I agree",
263
+ * "Accept & continue"). Anchored, so "Do not agree" / "Disagree" / "I have read and agree" never match.
264
+ */
265
+ const CONSENT_POSITIVE_RE = /^(?:我)?(?:同意|接受)(?:并(?:继续|使用|进入|开始使用))?$|^(?:i )?(?:agree|accept)(?: and (?:continue|use|enter|start using))?$|^(?:i )?(?:agree|accept)(?:(?: and| &) (?:continue|proceed))?$/i;
266
+ /** A label that declines or leaves: an app may put that on button1, so its id alone does not make it the accept. */
267
+ const CONSENT_DECLINE_RE = /不同意|拒绝|退出|取消|暂不|disagree|do(?:n.t| not) agree|decline|reject|refuse|exit|quit|cancel|not now/i;
268
+ /**
269
+ * A system dialog's button that stops it coming back. It is matched against the device's own UI,
270
+ * whose language is the phone's, not this install's, so the Chinese labels stay.
271
+ */
272
+ const SYSTEM_DIALOG_SUPPRESS_RE = /^(?:不再显示|不再提示|下次不再提示|don['’]?t show again|do not show again|never show again)$/i;
273
+ /** A toggle (CheckBox, Switch, ...): pressing it ticks, it does not accept, even when its label is "Agree". */
274
+ const isToggle = (n) => [true, 'true'].includes(get(n, 'checkable'))
275
+ || /(?:CheckBox|Switch|RadioButton|ToggleButton|CheckedTextView)$/.test(pyStr(get(n, 'class', '')));
276
+ /** Adapter containers: a text inside one is a bound row (user or app data), not a layout default. */
277
+ export const LIST_CLASS_RE = /(?:RecyclerView|ListView|GridView|WebView)$/;
278
+ /** A layout default is a short label; a longer text holding a specifier is content (a note, a log line). */
279
+ export const PLACEHOLDER_MAX_CHARS = 40;
280
+ /** A consent dialog's text (Runner.consentAccept): privacy policy / user agreement / terms. */
281
+ export const CONSENT_RE = /隐私政策|隐私协议|隐私保护|个人信息保护|用户协议|服务协议|privacy agreement|privacy protection|personal information protection|service agreement|privacy policy|terms of (?:service|use)|user agreement/i;
282
+ /**
283
+ * A text the app has not formatted yet: a java.util.Formatter / Android string-resource
284
+ * specifier left as-is (`%1$s`, `%2$d`, `%.1f`, a bare `%s` / `%d`). It is the layout's
285
+ * android:text default, shown until the data arrives and the code calls getString(id, args)
286
+ * (WeatherApp MainFragment 2026-11-04: `Feels like %1$s`, `%1$d km/h` under Chinatown/20°
287
+ * for ~8 s after every launch; the tree did not change while waiting, so settle() took it as
288
+ * settled and the export made that frame the page's screenshot). `50%` / `13% chance` are not
289
+ * specifiers: a conversion letter must follow. A bare one (`%s`, `%02d`, `%,d`, `%tY`) must not
290
+ * touch an ASCII letter or digit (`5%d`, `x%sy`, a URL's `%20`); CJK around it is fine (`<CJK text>%s`).
291
+ */
292
+ export const UNFORMATTED_TEXT = /%\d+\$[-#+0,(]*\d*(?:\.\d+)?(?:[bBhHsScCdoxXeEfgGaA]|[tT][A-Za-z])|(?<![A-Za-z0-9])%[-#+0,(]*\d*(?:\.\d+)?(?:[sSdfxX]|[tT][A-Za-z])(?![A-Za-z0-9])/;
293
+ export const unformattedText = (t) => typeof t === 'string' && UNFORMATTED_TEXT.test(t);
294
+ /**
295
+ * Identity of a scroll container found immobile in a search pass: class, id and bounds. Not its
296
+ * `{class, index}` selector: a scroll elsewhere can shift the reading-order index of same-class
297
+ * nodes, while a container that did not move keeps its bounds.
298
+ */
299
+ const stuckKey = (n) => jsonDumps([get(n, 'class') ?? null, get(n, 'resource_id') ?? null, or(get(n, 'bounds'), null)]);
300
+ /**
301
+ * Selector for scroll container `n` that resolves to it alone in `nodes`: its id, else its class,
302
+ * else its class plus reading-order `index` (a Compose page's one scrollable is an
303
+ * `android.view.View` among dozens of plain ones, so class alone never resolves).
304
+ */
305
+ const scrollSel = (n, nodes = null) => {
306
+ if (truthy(get(n, 'resource_id'))) { return { resource_id: n.resource_id }; }
307
+ const sel = { class: get(n, 'class') };
308
+ if (!nodes || matching(nodes, sel).length <= 1) { return sel; }
309
+ return classIndexSel(n, nodes) ?? sel;
310
+ };
311
+
312
+ /** `{class, index}` naming `n` by its class and reading-order position (adapters.matching's order), or null. */
313
+ function classIndexSel(n, nodes) {
314
+ if (!truthy(get(n, 'class'))) { return null; }
315
+ const same = matching(nodes, { class: n.class });
316
+ const idx = sortedBy(same, (m) => { const b = or(get(m, 'bounds'), [0, 0]); return b.slice(0, 2).reverse(); }).indexOf(n);
317
+ return idx >= 0 ? { class: n.class, index: idx } : null;
318
+ }
319
+ /** Atom types that press nothing, so they keep consentAccept's after-launch window open. */
320
+ const PASSIVE_ACTIONS = new Set(['wait', 'scroll']);
321
+ const s200 = (e) => cpSlice(errStr(e), 0, 200);
322
+ const CANDIDATE_KINDS = { click_candidates: 'click', long_click_candidates: 'long_click', double_tap_candidates: 'double_tap' };
323
+
324
+ /**
325
+ * The runtime-permission dialog words its allow button per permission and Android version
326
+ * ("Allow", "Allow only while using this app", "While using the app", "Allow all"), so a recipe's label
327
+ * misses on another device. Measured (Salt Player 10-18): three recD scan chains asked for
328
+ * "Allow only while using this app" on a media prompt showing "Allow / Don't allow" and died there. When the
329
+ * screen is that dialog and the step means "allow", press its allow button by the stable
330
+ * permissioncontroller id. Deny is never inferred.
331
+ */
332
+ export const PERMISSION_ALLOW_IDS = ['permission_allow_foreground_only_button', 'permission_allow_button',
333
+ 'permission_allow_all_button', 'permission_allow_one_time_button'];
334
+ const ALLOW_WORDS = /允许|allow|while using/i;
335
+ const DENY_WORDS = /不允许|拒绝|deny|don.t allow/i;
336
+
337
+ /**
338
+ * Runtime permissions the package holds, from `dumpsys package <pkg>`: the entries of its
339
+ * `runtime permissions:` sections. Install-time permissions are not listed there. With
340
+ * `{ ungrantedOnly: true }`, only those still `granted=false` (nothing to do for the rest).
341
+ */
342
+ export function runtimePermissions(dump, { ungrantedOnly = false } = {}) {
343
+ const all = new Set(); const granted = new Set();
344
+ let inSection = false; let indent = -1;
345
+ for (const line of pyStr(dump).split(/\r?\n/)) {
346
+ const lead = line.length - line.trimStart().length;
347
+ if (/^\s*runtime permissions:\s*$/.test(line)) { inSection = true; indent = lead; continue; }
348
+ if (!inSection) { continue; }
349
+ const m = /^\s*([\w.]+): granted=(true|false)/.exec(line);
350
+ if (m && lead > indent) { all.add(m[1]); if (m[2] === 'true') { granted.add(m[1]); } continue; }
351
+ inSection = false;
352
+ }
353
+ // A permission listed for several users counts as granted only when every listing grants it.
354
+ for (const line of pyStr(dump).split(/\r?\n/)) {
355
+ const m = /^\s*([\w.]+): granted=false/.exec(line);
356
+ if (m) { granted.delete(m[1]); }
357
+ }
358
+ return [...all].filter((p) => !ungrantedOnly || !granted.has(p)).sort();
359
+ }
360
+
361
+ export function permissionGrant(nodes, selectors, kind = 'click') {
362
+ const isPrompt = nodes.some((n) => pyStr(get(n, 'resource_id', '')).endsWith('permissioncontroller:id/grant_dialog'));
363
+ if (!isPrompt) { return null; }
364
+ const labels = selectors.map((s) => pyStr(or(get(s, 'text'), get(s, 'content_desc'))));
365
+ if (!labels.some((t) => ALLOW_WORDS.test(t) && !DENY_WORDS.test(t))) { return null; }
366
+ for (const id of PERMISSION_ALLOW_IDS) {
367
+ const hit = nodes.filter((n) => isVisible(n) && pyStr(get(n, 'resource_id', '')).endsWith(':id/' + id));
368
+ if (hit.length === 1) { return { type: kind, selector: { resource_id: hit[0].resource_id } }; }
369
+ }
370
+ return null;
371
+ }
372
+
373
+ const uniqueHit = (nodes, selector) => {
374
+ try { return matching(nodes, selector).length === 1; } catch (e) { if (e instanceof AdapterError) { return false; } throw e; }
375
+ };
376
+
377
+ /**
378
+ * Container openers the campaign's own routes already use: the selector groups of `intermediate`
379
+ * replay steps (a hop that opens a popup, overflow or "more" list without changing page), most
380
+ * frequent first, at most `limit`. App-agnostic: nothing is named, only reused.
381
+ */
382
+ export function derivedOverflowOpeners(tasks, limit = 4, depth = 1) {
383
+ const count = new Map(); const groups = new Map();
384
+ for (const t of tasks) {
385
+ const replay = or(get(t, 'replay'), []);
386
+ // Only hops within `depth` of launch (top-level containers: bottom bar, toolbar, drawer); deeper
387
+ // intermediate hops are mostly in-page actions or sub-page navigation. The last replay hop
388
+ // prepares the task's own action and reveals no later step.
389
+ for (const s of replay.slice(0, Math.min(Math.max(0, depth), replay.length - 1))) {
390
+ if (!truthy(get(s, 'intermediate')) || !Object.hasOwn(CANDIDATE_KINDS, get(s, 'type'))) { continue; }
391
+ const sels = or(get(s, 'selectors'), []);
392
+ if (!sels.length) { continue; }
393
+ const k = jsonDumps(sels, { sort_keys: true });
394
+ if (!groups.has(k)) { groups.set(k, sels); }
395
+ count.set(k, (count.get(k) ?? 0) + 1);
396
+ }
397
+ }
398
+ return sortedBy([...groups.keys()], (k) => [-count.get(k), k]).slice(0, Math.max(0, limit)).map((k) => groups.get(k));
399
+ }
400
+
401
+ /** Static kinds that open over their page (what a container opener is expected to show). */
402
+ export const OVERLAY_KINDS = new Set(['menu', 'dialog', 'panel', 'overlay', 'ui-state', 'mode']);
403
+
404
+ /**
405
+ * The click left its page: another activity, or another verified static page that is not an
406
+ * overlay kind (a popup/menu/dialog resolving to its own node still counts as opened in place).
407
+ */
408
+ export function navigatedAway(before, after, catalog = {}) {
409
+ if (get(before, 'activity') !== get(after, 'activity')) { return true; }
410
+ const id = (o) => { const r = or(get(o, 'static_resolution'), {}); return get(r, 'status') === 'verified' ? get(r, 'static_id') : null; };
411
+ const a = id(after);
412
+ if (a === null || a === id(before)) { return false; }
413
+ const kind = get(get(catalog, a, {}), 'kind') ?? pyStr(a).split(':')[0];
414
+ return !OVERLAY_KINDS.has(kind);
415
+ }
416
+
417
+ /**
418
+ * rowGroups(nodes): containers whose children include at least 3 visible clickable rows of one class
419
+ * and similar height (within 25%), stacked vertically: a list the dump does not flag scrollable.
420
+ * Measured (coolmall 2026-11-16): a region picker sheet's LazyColumn of provinces reported no
421
+ * `scrollable`, so a list step there found no list at all.
422
+ */
423
+ export function rowGroups(nodes) {
424
+ const kids = new Map();
425
+ nodes.forEach((n, i) => { const p = get(n, 'parent_index'); if (p !== null && p !== undefined) { if (!kids.has(p)) { kids.set(p, []); } kids.get(p).push(i); } });
426
+ const hasText = (i, d = 0) => d < 4 && (pyStr(get(nodes[i], 'text', '')).trim() !== '' || (kids.get(i) || []).some((k) => hasText(k, d + 1)));
427
+ const rootW = (() => { const b = get(nodes[0] || {}, 'bounds', []); return b.length === 4 ? b[2] - b[0] : 0; })();
428
+ const out = [];
429
+ for (const [p, ks] of kids) {
430
+ const rows = ks.map((i) => nodes[i]).filter((n) => isVisible(n) && truthy(get(n, 'clickable')) && get(n, 'bounds', []).length === 4);
431
+ // One or two rows (a picker level with one city): every child a full-width clickable row with
432
+ // text, in a container at least half the screen wide; a tab strip, a drag handle or a scrim is not.
433
+ const cb = get(nodes[p] || {}, 'bounds', []);
434
+ if (rows.length && rows.length < 3) {
435
+ const w = cb.length === 4 ? cb[2] - cb[0] : 0;
436
+ const ok = rows.length === ks.length && w > 0 && (!rootW || w >= 0.5 * rootW)
437
+ && rows.every((r) => r.bounds[2] - r.bounds[0] >= 0.9 * w) && ks.every((i) => hasText(i));
438
+ if (ok) { out.push(p); }
439
+ continue;
440
+ }
441
+ if (rows.length < 3) { continue; }
442
+ const cls = pyStr(get(rows[0], 'class', ''));
443
+ if (!rows.every((r) => pyStr(get(r, 'class', '')) === cls)) { continue; }
444
+ const hs = rows.map((r) => r.bounds[3] - r.bounds[1]).sort((a, b) => a - b);
445
+ const tops = rows.map((r) => r.bounds[1]);
446
+ const stacked = tops.every((t, k) => k === 0 || t >= tops[k - 1]);
447
+ // the last row may be cut by the screen edge: compare the full ones
448
+ const full = hs.slice(Math.min(1, hs.length - 3));
449
+ if (stacked && full[0] >= 0.75 * full.at(-1)) { out.push(p); }
450
+ }
451
+ return out;
452
+ }
453
+
454
+ /**
455
+ * sameTemplateRows(nodes, idx): true when the nodes at `idx` are one control repeated by a row
456
+ * template: each lies in a different child ("row") of their deepest common ancestor, every row has
457
+ * the same class tree (texts ignored), and the control sits at the same child path in each. A
458
+ * list's rows qualify; two different buttons that share a label (a tab and a row button, a toolbar
459
+ * and a dialog) never do. Measured (coolmall 2026-11-16): a coupon sheet's "Claim now" per coupon
460
+ * failed three tasks as an ambiguous selector though any row opens the same login page.
461
+ */
462
+ export function sameTemplateRows(nodes, idx) {
463
+ if (idx.length < 2 || idx.some((i) => !(i >= 0 && i < nodes.length))) { return false; }
464
+ const parent = (i) => { const p = get(nodes[i], 'parent_index'); return p === null || p === undefined || !(p >= 0 && p < nodes.length) ? null : p; };
465
+ const chain = (i) => { const out = []; let c = i; const seen = new Set(); while (c !== null && !seen.has(c)) { seen.add(c); out.push(c); c = parent(c); } return out; };
466
+ const chains = idx.map(chain);
467
+ const common = chains[0].find((a) => chains.every((c) => c.includes(a)));
468
+ if (common === undefined || idx.includes(common)) { return false; }
469
+ const rows = chains.map((c) => c[c.indexOf(common) - 1]);
470
+ if (new Set(rows).size !== rows.length) { return false; }
471
+ const kids = new Map();
472
+ nodes.forEach((n, i) => { const p = parent(i); if (p !== null) { if (!kids.has(p)) { kids.set(p, []); } kids.get(p).push(i); } });
473
+ const shape = (i) => `${pyStr(get(nodes[i], 'class', ''))}(${(kids.get(i) || []).map(shape).join(',')})`;
474
+ const pathIn = (row, i) => { const out = []; let c = i; while (c !== row) { const p = parent(c); out.push((kids.get(p) || []).indexOf(c)); c = p; } return out.join('/'); };
475
+ const s0 = shape(rows[0]); const p0 = pathIn(rows[0], idx[0]);
476
+ return rows.every((r, k) => shape(r) === s0 && pathIn(r, idx[k]) === p0);
477
+ }
478
+
479
+ /**
480
+ * writesData(text): a control label that writes to the app's backend when tapped (claim a coupon, add
481
+ * to cart, buy, delete, follow...). Such a control is never chosen by the runner's own loosening (a
482
+ * repeated row control taken by index, a list row probed) unless `config.allow_data_writes` is true.
483
+ * With the switch off a write is the costly mistake, so any label holding a write verb counts
484
+ * (「领取优惠券」「确认支付」「取消关注」「删除订单」「Add to wishlist」), except a label that names a
485
+ * place to go: a 「我的…」 entry or a page of records (「…记录」「…历史」「…列表」「…中心」「…明细」),
486
+ * which only opens a page.
487
+ */
488
+ export const WRITE_LABEL_RE = /领取|领券|加购|加入购物车|购买|抢购|下单|提交|支付|付款|删除|收藏|关注|点赞|兑换|签到|确认收货|取消订单|^\s*\+|\b(?:add to|buy|purchase|claim|redeem|delete|remove|submit|pay|order now|place order|follow|unfollow|like|favou?rite|wishlist|subscribe)\b/i;
489
+ export const NAV_LABEL_RE = /^\s*我的|(?:记录|历史|列表|中心|明细|日历|规则|说明|攻略|详情|管理)\s*(?:\(\d+\))?\s*$|^\s*my\b|\b(?:history|records?|list|center|centre|details?|rules|calendar)\s*$/i;
490
+ export function writesData(text) { return typeof text === 'string' && WRITE_LABEL_RE.test(text) && !NAV_LABEL_RE.test(text); }
491
+
492
+ /** Failure reasons that repeat for every task replaying the same prefix in the same environment. */
493
+ export const PREFIX_FAILURES = ['selector-not-found-after-bounded-scroll', 'replay-target-unverified:',
494
+ 'ambiguous selector', 'list-item:', 'Scroll requires one visible scrollable container', 'needs-data:', 'needs-network:'];
495
+
496
+ /** Key of a task's launch plus its first `n` replay steps. */
497
+ export function prefixKey(task, n) {
498
+ return sha256Hex(Buffer.from(jsonDumps([or(get(task, 'source_launch'), {}), or(get(task, 'replay'), []).slice(0, n)],
499
+ { sort_keys: true }), 'utf8')).slice(0, 16);
500
+ }
501
+
502
+ /** The page a launch landed on, for the prefix memo: its static id (page:…), else its activity. */
503
+ export function landingOf(observation) {
504
+ const res = or(get(observation, 'static_resolution'), {});
505
+ return get(res, 'status') === 'verified' ? res.static_id : `activity:${get(observation, 'activity') ?? ''}`;
506
+ }
507
+
508
+ /** Raised instead of replaying a prefix that already failed this run. */
509
+ export class PrefixFailed extends AdapterError {
510
+ constructor(memo, key) {
511
+ super(memo.reason);
512
+ this.name = 'PrefixFailed';
513
+ Object.assign(this, { key, from: memo.task_id, observationId: memo.observation_id, replayIndex: memo.replay_index,
514
+ beforeId: memo.before_id });
515
+ }
516
+ }
517
+
518
+ export class Runner {
519
+ constructor(args) {
520
+ this.args = args;
521
+ this.root = pResolve(args.campaign);
522
+ this.config = readJson(args.config);
523
+ this.doc = readJson(pJoin(this.root, 'campaign.json'));
524
+ this.phase = this.doc.phases.find((p) => p.id === args.phase);
525
+ if (this.phase === undefined) { throw new Error('StopIteration'); }
526
+ this.env = this.phase.environment;
527
+ this.catalog = get(this.doc, 'page_catalog', {});
528
+ // config `state_anchors` (in-page state rules) persist in the campaign, so a later compile,
529
+ // rejudge or report applies the same ones
530
+ if (truthy(get(this.config, 'state_anchors'))) {
531
+ this.doc.state_anchors = { ...(or(get(this.doc, 'state_anchors'), {})), ...this.config.state_anchors };
532
+ applyStateAnchors(this.catalog, this.doc.state_anchors);
533
+ }
534
+ this.device = new DeviceAdapter(this.config, pJoin(this.root, 'artifacts'));
535
+ this.current = null;
536
+ this.used = 0;
537
+ this.stage = 'initial';
538
+ this.mapped = new Set(this.doc.events.filter((e) => e.kind === 'mapping')
539
+ .map((e) => tupleKey(e.environment_id, get(e.payload, 'observation_id'), get(e.payload, 'static_id'))));
540
+ this.coverage = coverageMode(this.config, get(args, 'coverage', null));
541
+ this.covered = coveredStaticIds(this.doc);
542
+ this.swept = new Set();
543
+ for (const e of this.doc.events) {
544
+ if (e.kind !== 'scroll_sweep') { continue; }
545
+ for (const x of [get(e.payload, 'static_id'), ...get(e.payload, 'also_covers', [])]) { if (truthy(x)) { this.swept.add(x); } }
546
+ }
547
+ this.deadline = monotonic() + toFloat(get(this.config, 'max_seconds', 2400));
548
+ this.backExits = backExitPages(this.doc.events);
549
+ }
550
+
551
+ /** A scoped (incremental) campaign settles every node outside its scope (coverage.mjs scopeOf). */
552
+ scopeExcludes(staticId) {
553
+ // membership, not a complement of doc.nodes: `plan --extend` does not refresh doc.nodes
554
+ if (this._scope === undefined) { this._scope = scopeOf(this.doc); }
555
+ return this._scope !== null && !this._scope.has(staticId);
556
+ }
557
+
558
+ save() {
559
+ atomicWriteJson(pJoin(this.root, 'campaign.json'), this.doc);
560
+ this._saved_at = monotonic();
561
+ }
562
+
563
+ /** wait_device(timeout=None): block until input/window services answer; true on a fresh capture. */
564
+ /**
565
+ * Wait until the device answers and a capture succeeds. A device that answers while
566
+ * capture keeps failing has a hung app (a stuck `am start -W` leaves an ANR or a blank
567
+ * window): force-stop it and go home, so one hung launch does not block the phase.
568
+ */
569
+ waitDevice(timeout = null) {
570
+ const deadline = monotonic() + toFloat(or(timeout, () => get(this.config, 'device_recovery_seconds', 120)));
571
+ const unstickAfter = toInt(get(this.config, 'device_unstick_after', 2));
572
+ let answered = 0;
573
+ let unstuck = false;
574
+ while (monotonic() < deadline) {
575
+ try {
576
+ const out = this.device._shell('service', 'check', 'input');
577
+ if (out.includes('found') && !out.includes('not found')) {
578
+ answered += 1;
579
+ if (!unstuck && answered > unstickAfter) {
580
+ unstuck = true;
581
+ const pkg = get(this.config, 'package');
582
+ try {
583
+ if (truthy(pkg)) { this.device._shell('am', 'force-stop', pkg); }
584
+ this.device._shell('input', 'keyevent', 'KEYCODE_HOME');
585
+ } catch { /* the next capture tells */ }
586
+ }
587
+ this.device._foreground();
588
+ this.capture({ acceptLoading: true });
589
+ return true;
590
+ }
591
+ } catch { /* retry */ }
592
+ sleep(5);
593
+ }
594
+ return false;
595
+ }
596
+
597
+ emit(kind, payload, evidence = []) {
598
+ const e = event(kind, this.env, payload, evidence);
599
+ this.doc.events.push(e);
600
+ appendText(pJoin(this.root, 'events.jsonl'), jsonDumps(e, { ensure_ascii: false }) + '\n');
601
+ const interval = toFloat(get(this.config, 'save_interval', 15));
602
+ if (['task_result', 'environment_verified', 'discovery_result', 'environment_restored'].includes(kind)
603
+ || monotonic() - (this._saved_at ?? 0) >= interval) { this.save(); }
604
+ return e;
605
+ }
606
+
607
+ /**
608
+ * A verified capture of a page still loading its content: a visible spinner, or a sparse
609
+ * screen (at most 2 labelled app nodes) that shows at most one of the 3+ fixed texts the page's
610
+ * source renders. A Compose spinner is an unlabelled View whose dump does not change while it
611
+ * spins, so settle() takes it for a settled screen (SelectCity on yd-weather 2026-10-30: only
612
+ * the search hint, the city lists still loading). A spinner is a roughly square ProgressBar; a
613
+ * wide one is a bar showing a value (storage used, download), which stays on a loaded page.
614
+ * A visible text still holding a format specifier (`%1$s`, see UNFORMATTED_TEXT) is the
615
+ * layout default before the data is bound: the page is loading, however full it looks. Only a
616
+ * short label outside any list or WebView counts: a row's text is bound data (a note titled
617
+ * `printf("%d")`, a log line `format: %s`) and a long text is content, not a default. A text
618
+ * an upper layer paints over (the host page under a full-screen fragment) is not this page's.
619
+ * a2h-batch-ui-align export_ui_info.mjs placeholderTexts applies the same test to the export.
620
+ */
621
+ /**
622
+ * A capture of the app under test with nothing on it yet: its own visible nodes carry no text,
623
+ * no content description and none is clickable. A tap that opens a page captures the frame
624
+ * between the two (the old page gone, the new one not yet laid out), and such a frame resolves
625
+ * to no page, so looksLoading (verified pages only) never waited on it. Measured (coolmall
626
+ * 2026-11-18): every goods-list row tap captured a 38-node frame of bare Views and the list probe
627
+ * judged at once that no row opened the goods page; the same tap followed by a 4 s wait landed
628
+ * on it. Another app's foreground (a launcher, a system dialog) is not this.
629
+ */
630
+ looksBlank(observation) {
631
+ const pkg = get(this.config, 'package');
632
+ if (!truthy(pkg) || get(observation, 'package') !== pkg) { return false; }
633
+ const own = get(observation, 'nodes', []).filter((n) => isVisible(n) && get(n, 'package', pkg) === pkg);
634
+ const blank = !own.some((n) => truthy(get(n, 'clickable')) || pyStr(get(n, 'text', '') ?? '').trim()
635
+ || pyStr(get(n, 'content_desc', '') ?? '').trim());
636
+ // Only for an app that has shown a labelled screen: one whose tree never carries text (a canvas
637
+ // or a Flutter app without semantics) is blank on every capture and would pay the wait on each.
638
+ if (!blank) { this._appShowedText = true; return false; }
639
+ return this._appShowedText === true;
640
+ }
641
+
642
+ looksLoading(observation) {
643
+ const resolution = get(observation, 'static_resolution', {});
644
+ if (get(resolution, 'status') !== 'verified') { return false; }
645
+ const pkg = get(this.config, 'package');
646
+ const own = get(observation, 'nodes', []).filter((n) => isVisible(n) && (!truthy(pkg) || get(n, 'package', pkg) === pkg));
647
+ const spinner = (n) => {
648
+ if (!pyStr(get(n, 'class', '')).endsWith('ProgressBar')) { return false; }
649
+ const b = get(n, 'bounds', []);
650
+ if (!Array.isArray(b) || b.length !== 4) { return true; }
651
+ const w = b[2] - b[0]; const h = b[3] - b[1];
652
+ return w > 0 && h > 0 && Math.max(w, h) <= 2 * Math.min(w, h);
653
+ };
654
+ if (own.some(spinner)) { return true; }
655
+ const nodes = get(observation, 'nodes', []);
656
+ const inList = (n) => {
657
+ const seen = new Set();
658
+ for (let i = get(n, 'parent_index'); i !== null && i !== undefined && i >= 0 && i < nodes.length && !seen.has(i); i = get(nodes[i], 'parent_index')) {
659
+ seen.add(i);
660
+ if (LIST_CLASS_RE.test(pyStr(get(nodes[i], 'class', '')))) { return true; }
661
+ }
662
+ return false;
663
+ };
664
+ const placeholder = (n) => {
665
+ const t = get(n, 'text');
666
+ return unformattedText(t) && [...t].length <= PLACEHOLDER_MAX_CHARS && !isInputNode(n) && !inList(n);
667
+ };
668
+ const covered = new Set([...occludedIndices(nodes)].map((i) => nodes[i]));
669
+ if (own.some((n) => !covered.has(n) && placeholder(n))) { return true; }
670
+ const body = get(get(this.catalog, resolution.static_id, {}), 'body_titles', []) || [];
671
+ if (body.length < 3) { return false; }
672
+ const shown = new Set();
673
+ for (const n of own) {
674
+ for (const k of ['text', 'content_desc']) { if (truthy(get(n, k))) { shown.add(normalized(n[k])); } }
675
+ }
676
+ return shown.size <= 2 && body.filter((t) => shown.has(t)).length <= 1;
677
+ }
678
+
679
+ /**
680
+ * capture({ acceptLoading }): observe, resolve and map. A capture that looksLoading is recorded
681
+ * but not mapped (its screenshot would stand for the page), unless `acceptLoading`; atom() waits
682
+ * for the content and maps the loaded capture instead.
683
+ */
684
+ capture({ acceptLoading = false } = {}) {
685
+ const observation = this.device.observe(this.env);
686
+ // The adapter pressed Back to close an input-method picker before this capture: a device
687
+ // action the transition chain must show (a 'navigated' one also moved the app).
688
+ if (get(observation, 'ime_switcher_dismissed')) {
689
+ this.emit('ime_switcher_dismissed', { observation_id: get(observation, 'observation_id'),
690
+ outcome: observation.ime_switcher_dismissed, action: { type: 'back', automatic: true } });
691
+ }
692
+ const resolution = resolveTwinByOpener(
693
+ deps.resolvePage(observation, this.catalog, get(observation, 'identity'), { app_package: get(this.config, 'package') }),
694
+ this.current, this.catalog);
695
+ observation.static_resolution = resolution;
696
+ const states = resolution.status === 'verified' ? uiStatesOf(observation, this.catalog) : [];
697
+ if (states.length) { resolution.ui_states = states; }
698
+ if (resolution.status === 'verified') {
699
+ Object.assign(observation.identity, { family: resolution.static_id, status: 'verified', basis: resolution.anchors, reason: resolution.reason });
700
+ }
701
+ if (resolution.status === 'verified') { this._lastVerified = resolution.static_id; }
702
+ if (this.looksBlank(observation)) { Object.assign(observation, { loading: true, blank: true }); }
703
+ else if (this.looksLoading(observation)) { observation.loading = true; }
704
+ // Seen loaded: its loading passes, so a wait that ran out there was a slow load (awaitContent).
705
+ // Only the first run-out is forgiven: a page that runs out again after that flips between
706
+ // a loading-looking and a loaded view (a spinner a scroll hides) and keeps its zero wait.
707
+ else if (resolution.status === 'verified' && this._loadingStuck?.has(resolution.static_id)
708
+ && !(this._loadingForgiven ??= new Set()).has(resolution.static_id)) {
709
+ this._loadingStuck.delete(resolution.static_id);
710
+ this._loadingForgiven.add(resolution.static_id);
711
+ }
712
+ this.current = observation;
713
+ this.emit('observation', observation, Object.values(observation.artifacts));
714
+ if (observation.loading && !acceptLoading) { return observation; }
715
+ this.mapCapture(observation);
716
+ return observation;
717
+ }
718
+
719
+ /** The `mapping` events of a verified capture: its page, then its in-page states. */
720
+ mapCapture(observation) {
721
+ const resolution = observation.static_resolution;
722
+ const states = get(resolution, 'ui_states', []) || [];
723
+ const loading = observation.loading ? { loading: true } : {};
724
+ if (resolution.status === 'verified') {
725
+ const key = tupleKey(this.env, observation.observation_id, resolution.static_id);
726
+ if (!this.mapped.has(key)) {
727
+ this.emit('mapping', { static_id: resolution.static_id, observation_id: observation.observation_id,
728
+ method: resolution.reason, anchors: resolution.anchors, ...loading }, Object.values(observation.artifacts));
729
+ this.mapped.add(key);
730
+ if (this._recognized !== undefined) { this._recognized.add(resolution.static_id); }
731
+ }
732
+ if (this.covered !== undefined) { this.covered.add(resolution.static_id); }
733
+ }
734
+ for (const sid of states) {
735
+ const key = tupleKey(this.env, observation.observation_id, sid);
736
+ if (this.mapped.has(key)) { continue; }
737
+ this.emit('mapping', { static_id: sid, observation_id: observation.observation_id, method: 'ui-state-anchor',
738
+ host_static: resolution.static_id, ...loading }, Object.values(observation.artifacts));
739
+ this.mapped.add(key);
740
+ if (this._recognized !== undefined) { this._recognized.add(sid); }
741
+ if (this.covered !== undefined) { this.covered.add(sid); }
742
+ }
743
+ return observation;
744
+ }
745
+
746
+ /**
747
+ * awaitContent(observation): while the page looksLoading, capture again every 0.5 s for up to
748
+ * `content_wait_seconds` (default 10). A page that is still loading then is mapped as it is,
749
+ * flagged `loading`. Captures only, no action is spent. A page that ran out the wait is not
750
+ * waited on again until a capture shows it loaded: what looks like loading there may be how the
751
+ * page stays (an empty state, a sparse screen, a spinner or a literal `%s` that never goes), and
752
+ * every later action landing on it would pay the full wait. A page seen loaded since loads
753
+ * slowly rather than never (a slow first fetch), so its next visit waits again.
754
+ * A blank frame that resolves to no page (looksBlank) waits `blank_wait_seconds` (default 6):
755
+ * with no page to remember it by, one that stayed blank must not cut the wait of the next,
756
+ * unrelated transition. Once BLANK_RUN_OUTS blank waits in a row have run out from one origin (the
757
+ * Activity and the last page verified before the frame), blank frames there are how that screen
758
+ * looks (an image viewer, a canvas) and are no longer waited on; other origins still wait.
759
+ */
760
+ awaitContent(observation) {
761
+ let current = observation;
762
+ if (!current || !current.loading) { return current; }
763
+ const stuck = (this._loadingStuck ??= new Set());
764
+ const sid = () => get(get(current, 'static_resolution', {}), 'static_id');
765
+ const blankOnly = truthy(current.blank) && !truthy(sid());
766
+ const runOuts = (this._blankRunOuts ??= new Map());
767
+ // counted per transition origin: the Activity and the last page verified before the blank frame
768
+ const origin = `${pyStr(get(current, 'activity', ''))}|${pyStr(this._lastVerified ?? '')}`;
769
+ const wait = blankOnly ? ((runOuts.get(origin) ?? 0) >= BLANK_RUN_OUTS ? 0 : toFloat(get(this.config, 'blank_wait_seconds', 6)))
770
+ : stuck.has(sid()) ? 0 : toFloat(get(this.config, 'content_wait_seconds', 10));
771
+ const deadline = monotonic() + Math.max(0, wait);
772
+ while (current.loading && monotonic() < deadline) { sleep(0.5); current = this.capture(); }
773
+ if (blankOnly && wait > 0) { runOuts.set(origin, truthy(current.blank) ? (runOuts.get(origin) ?? 0) + 1 : 0); }
774
+ if (current.loading) {
775
+ if (wait > 0 && truthy(sid())) { stuck.add(sid()); }
776
+ this.mapCapture(current);
777
+ }
778
+ return current;
779
+ }
780
+
781
+ at(ident) { return deps.observationMatchesStatic(or(this.current, {}), ident, this.catalog)[0]; }
782
+
783
+ appUiReady() {
784
+ const pkg = mget(this.config, 'package');
785
+ return get(this.current, 'package') === pkg && get(this.current, 'nodes', []).some((n) =>
786
+ get(n, 'package') === pkg && isVisible(n) && truthy(get(n, 'clickable')));
787
+ }
788
+
789
+ atom(action, taskId, purpose, { restoring: inRestore = false } = {}) {
790
+ const lifetime = this.doc.events.filter((e) => e.kind === 'attempt_started' && truthy(get(e.payload, 'atomic'))).length;
791
+ // A phase's cleanup runs after its budget is spent by design: restoring the
792
+ // environment never counts against it (measured: a recD phase that used its whole
793
+ // budget then threw from its cleanup, which run_cycle took as a fatal stage error).
794
+ // `inRestore`: a dismissal made on behalf of a restore (cleanup's launch met a dialog) shares its exemption.
795
+ const restoring = (purpose === 'restore' || inRestore) && lifetime < toInt(get(this.config, 'max_campaign_actions', 1800));
796
+ if (!restoring && (this.used >= this.args.budget || lifetime >= toInt(get(this.config, 'max_campaign_actions', 1800)) || monotonic() >= this.deadline)) {
797
+ throw new BudgetExhausted('atomic-action/time budget exhausted');
798
+ }
799
+ const before = this.current;
800
+ this.used += 1;
801
+ // A launch that throws must not leave an earlier launch's consent window open.
802
+ if (get(action, 'type') === 'launch') { this._launched = false; }
803
+ const started = this.emit('attempt_started', { task_id: taskId, atomic: true, purpose, action, before: before.observation_id });
804
+ this.device.act(action, before);
805
+ this.device.settle();
806
+ const isLaunch = get(action, 'type') === 'launch';
807
+ // One budget per launch atom for captures the launch's own foreground moves spoil (launchCapture).
808
+ const moves = isLaunch ? { left: Math.max(0, toInt(get(this.config, 'launch_transition_captures', 3))) } : null;
809
+ let after = isLaunch ? this.launchCapture(taskId, moves) : this.capture();
810
+ if (isLaunch) {
811
+ this.dirty = false;
812
+ const waitS = Math.max(0.0, toFloat(get(this.config, 'launch_ready_seconds', 8)));
813
+ let deadline = monotonic() + waitS;
814
+ after = this.waitAppUi(deadline, taskId, after, purpose, moves);
815
+ for (let k = 0; k < toInt(get(this.config, 'launch_retries', 1)); k++) {
816
+ if (this.appUiReady()) { break; }
817
+ this.device.act(action, after);
818
+ this.device.settle();
819
+ deadline = monotonic() + waitS;
820
+ after = this.launchCapture(taskId, moves);
821
+ after = this.waitAppUi(deadline, taskId, after, purpose, moves);
822
+ }
823
+ if (!this.appUiReady()) { throw new AdapterError('launch-ui-not-ready'); }
824
+ }
825
+ after = this.awaitContent(after);
826
+ // consentAccept: from a launch until the first action that can raise a dialog of its own.
827
+ // Waits and scrolls press nothing (app_settings' launch → wait → replay; a search scroll on
828
+ // the first replay step), and dismissals are the consent handling itself.
829
+ if (get(action, 'type') === 'launch') { this._launched = true; } else if (purpose !== 'dismiss-interruption' && !PASSIVE_ACTIONS.has(get(action, 'type'))) { this._launched = false; }
830
+ const outcome = observationKey(before) === observationKey(after) ? 'no_effect' : 'succeeded';
831
+ return this.emit('action_result', { task_id: taskId, attempt_id: started.id, purpose, outcome,
832
+ before: before.observation_id, after: after.observation_id, action });
833
+ }
834
+
835
+ choose(action, { alternates = true } = {}) {
836
+ const isCand = Object.hasOwn(CANDIDATE_KINDS, get(action, 'type'));
837
+ const candidates = isCand ? get(action, 'selectors', []) : [get(action, 'selector', {})];
838
+ const found = this._choose(action, isCand, candidates);
839
+ if (found || !alternates) { return found; }
840
+ // No candidate on screen: the same resources' other values (textAlternatesOf), as extra candidates.
841
+ const extra = [];
842
+ for (const s of candidates) {
843
+ for (const k of ['text', 'content_desc']) {
844
+ if (typeof get(s, k) !== 'string') { continue; }
845
+ for (const alt of this.textAlternatesOf(s[k])) {
846
+ const sel = { ...s, [k]: alt };
847
+ if (!extra.some((x) => jsonDumps(x, { sort_keys: true }) === jsonDumps(sel, { sort_keys: true }))) { extra.push(sel); }
848
+ }
849
+ }
850
+ }
851
+ return extra.length ? this._choose(action, isCand, extra) : found;
852
+ }
853
+
854
+ _choose(action, isCand, candidates) {
855
+ let ambiguous = false;
856
+ const hidden = occludedIndices(this.current.nodes);
857
+ const live = this.current.nodes.map((n, i) => (!hidden.has(i) ? n : { visible: false }));
858
+ const kindOf = () => get(CANDIDATE_KINDS, get(action, 'type'), get(action, 'type', 'click'));
859
+ for (const selector of candidates) {
860
+ let hits = matching(live, selector);
861
+ hits = hits.filter((n) => get(n, 'bounds', []).length === 4 && n.bounds[2] > n.bounds[0] && n.bounds[3] > n.bounds[1]);
862
+ if (hits.length === 1) {
863
+ const node = hits[0]; const parent = get(node, 'parent_index');
864
+ if (get(node, 'resource_id') === 'android:id/title' && parent !== null
865
+ && get(this.current.nodes[parent], 'class') === 'android.widget.ListView' && !truthy(get(node, 'clickable'))) { continue; }
866
+ return { type: kindOf(), selector };
867
+ }
868
+ if (hits.length > 1) {
869
+ const scoped = { ...selector, actionable: true };
870
+ if (matching(live, scoped).length === 1) { return { type: kindOf(), selector: scoped }; }
871
+ // The same control in every row of one list (a "Claim now" per coupon): any row's opens the
872
+ // same page, so the first is taken by its index, never by coordinates (sameTemplateRows).
873
+ // Not a control that writes data (a coupon's claim, a row's add-to-cart) unless writes are allowed.
874
+ const writes = [selector.text, selector.content_desc, ...hits.flatMap((h) => [get(h, 'text'), get(h, 'content_desc')])].some(writesData);
875
+ if (!Object.hasOwn(selector, 'index') && (!writes || get(this.config, 'allow_data_writes') === true)
876
+ && sameTemplateRows(this.current.nodes, hits.map((h) => live.indexOf(h)))) {
877
+ return { type: kindOf(), selector: { ...selector, index: 0 } };
878
+ }
879
+ // A record's own text (a seeding recipe's state label, `record_label`): records are listed in
880
+ // a vertical list, so a match inside a horizontal strip (a filter tab of the same words) is
881
+ // not it. One left: taken by its index among the matches, top-down like `matching`.
882
+ if (truthy(get(action, 'record_label')) && !Object.hasOwn(selector, 'index')) {
883
+ const inStrip = (n) => { let p = get(n, 'parent_index'); for (let d = 0; d < 12 && p !== null && p !== undefined && p >= 0; d++) {
884
+ const a = this.current.nodes[p]; if (truthy(get(a, 'scrollable')) && _isHorizontal(a)) { return true; } p = get(a, 'parent_index'); } return false; };
885
+ const keep = hits.filter((h) => !inStrip(h));
886
+ if (keep.length === 1) {
887
+ const ordered = sortedBy(matching(live, selector), (n) => { const b = get(n, 'bounds', [0, 0]); return [b[1], b[0]]; });
888
+ return { type: kindOf(), selector: { ...selector, index: ordered.indexOf(keep[0]) } };
889
+ }
890
+ }
891
+ }
892
+ ambiguous = ambiguous || hits.length > 1;
893
+ }
894
+ if (ambiguous) { throw new AdapterError('ambiguous selector; no coordinate guessing'); }
895
+ return permissionGrant(live, candidates, kindOf());
896
+ }
897
+
898
+ /**
899
+ * Several lists hold rows and the step names the page a row opens (`target_id`): tap the first row
900
+ * of each, most rows first, until one lands on that page; Back after a row that opened another.
901
+ * At most `max_list_probes` (default 3) lists. Measured (coolmall 2026-11-16): the home page's
902
+ * flash-sale row, category strip and goods grid failed three tasks with "expected one list,
903
+ * found 3" although every goods list opened the same detail page. The landing page is checked
904
+ * by its own identity, so a wrong list is never taken for the right one.
905
+ */
906
+ probeLists(target, tapRow, taskId) {
907
+ const lists = this.listCandidates();
908
+ const before = this.current;
909
+ const origin = get(get(before, 'static_resolution', {}), 'status') === 'verified' ? before.static_resolution.static_id : null;
910
+ let last = null;
911
+ for (let [k, [, row]] of lists.slice(0, Math.max(1, toInt(get(this.config, 'max_list_probes', 3)))).entries()) {
912
+ if (k > 0) {
913
+ if (origin === null) { throw new AdapterError('list-item: the probing page is unverified, so a return to it cannot be checked'); }
914
+ // Back only when the last row left the page: a row that stays (a category chip switching a tab) must not exit it.
915
+ if (!this.at(origin)) { this.atom({ type: 'back' }, taskId, 'list-probe-back'); }
916
+ if (!this.at(origin)) { throw new AdapterError(`list-item: could not return to ${origin} after probing a list`); }
917
+ row = this.listCandidates()[k]?.[1] ?? row;
918
+ }
919
+ last = tapRow(row);
920
+ if (this.at(target)) {
921
+ if (typeof this.emit === 'function') { this.emit('list_probe', { task_id: taskId, target, chosen: k, lists: lists.length }); }
922
+ return last;
923
+ }
924
+ }
925
+ throw new AdapterError(`list-item: none of ${lists.length} lists opened ${target}`);
926
+ }
927
+
928
+ /**
929
+ * [listIndex, firstActionableRow] of every visible list holding rows, most rows first, then top-down.
930
+ * Nested scrollables that offer the same first row are one list (a page container around its grid).
931
+ */
932
+ listCandidates() {
933
+ const out = [];
934
+ for (const li of this._listContainers()) {
935
+ const rows = this._rowsOf(li);
936
+ if (rows.length) { out.push([li, sortedBy(rows, (n) => [n.bounds[1], n.bounds[0]])[0], rows.length]); }
937
+ }
938
+ const seen = new Set();
939
+ return sortedBy(out, (x) => [-x[2], x[1].bounds[1], x[1].bounds[0]])
940
+ .filter(([, r]) => { const k = JSON.stringify(r.bounds); if (seen.has(k)) { return false; } seen.add(k); return true; })
941
+ .map(([li, r]) => [li, r]);
942
+ }
943
+
944
+ _listContainers() {
945
+ const nodes = this.current.nodes;
946
+ const adapterCls = ['RecyclerView', 'ListView', 'GridView'];
947
+ const hasKids = new Set(nodes.map((c) => get(c, 'parent_index')));
948
+ const lists = [];
949
+ nodes.forEach((n, i) => { if (isVisible(n) && adapterCls.some((c) => pyStr(get(n, 'class', '')).endsWith(c)) && hasKids.has(i)) { lists.push(i); } });
950
+ if (lists.length === 1) { return lists; }
951
+ const scrollables = [];
952
+ nodes.forEach((n, i) => { if (truthy(get(n, 'scrollable')) && isVisible(n)) { scrollables.push(i); } });
953
+ return scrollables.length ? scrollables : rowGroups(nodes);
954
+ }
955
+
956
+ _rowsOf(li) {
957
+ const nodes = this.current.nodes;
958
+ const kidsOf = (i) => nodes.map((n, j) => [n, j]).filter(([n]) => get(n, 'parent_index') === i).map(([, j]) => j);
959
+ // a row's own button that writes data (「领取」「加购」) is never the row to probe, unless writes are allowed.
960
+ // A control's label is its own text, else the texts below it (up to 4 levels, not inside another
961
+ // clickable, which is a control of its own): a button labelled by a nested text is a writer when
962
+ // every such text is; a card holding a title, a price and a 「加购」 is not.
963
+ const allowWrites = get(this.config, 'allow_data_writes') === true;
964
+ const textsOf = (k) => [get(nodes[k], 'text'), get(nodes[k], 'content_desc')].filter((t) => typeof t === 'string' && t.trim());
965
+ const labelsOf = (j) => {
966
+ const own = textsOf(j);
967
+ if (own.length) { return own; }
968
+ const out = []; let level = kidsOf(j);
969
+ for (let d = 0; d < 4 && level.length; d++) {
970
+ const next = [];
971
+ for (const k of level) {
972
+ if (truthy(get(nodes[k], 'clickable')) || truthy(get(nodes[k], 'long-clickable'))) { continue; }
973
+ out.push(...textsOf(k)); next.push(...kidsOf(k));
974
+ }
975
+ level = next;
976
+ }
977
+ return out;
978
+ };
979
+ const writer = (j) => {
980
+ if (allowWrites || !(truthy(get(nodes[j], 'clickable')) || truthy(get(nodes[j], 'long-clickable')))) { return false; }
981
+ const ls = labelsOf(j);
982
+ return ls.length > 0 && ls.every(writesData);
983
+ };
984
+ const actionableRow = (ci) => {
985
+ const cands = [ci, ...kidsOf(ci)];
986
+ for (const c of kidsOf(ci)) { cands.push(...kidsOf(c)); }
987
+ for (const j of cands) {
988
+ const n = nodes[j];
989
+ if (j !== ci && writer(j)) { continue; }
990
+ if ((truthy(get(n, 'clickable')) || truthy(get(n, 'long-clickable'))) && isVisible(n)
991
+ && !['ImageButton', 'FloatingActionButton'].some((c) => pyStr(get(n, 'class', '')).endsWith(c))
992
+ && get(n, 'bounds', []).length === 4 && n.bounds[3] > n.bounds[1]) { return n; }
993
+ }
994
+ return null;
995
+ };
996
+ return kidsOf(li).map(actionableRow).filter((r) => truthy(r));
997
+ }
998
+
999
+ listItem() {
1000
+ const nodes = this.current.nodes;
1001
+ const adapterCls = ['RecyclerView', 'ListView', 'GridView'];
1002
+ const hasKids = new Set(nodes.map((c) => get(c, 'parent_index')));
1003
+ let lists = [];
1004
+ nodes.forEach((n, i) => { if (isVisible(n) && adapterCls.some((c) => pyStr(get(n, 'class', '')).endsWith(c)) && hasKids.has(i)) { lists.push(i); } });
1005
+ if (lists.length !== 1) {
1006
+ lists = [];
1007
+ nodes.forEach((n, i) => { if (truthy(get(n, 'scrollable')) && isVisible(n)) { lists.push(i); } });
1008
+ }
1009
+ if (!lists.length) { lists = rowGroups(nodes); }
1010
+ const idxOf = (n) => nodes.findIndex((m) => pyEq(m, n)); // list.index uses ==
1011
+ const actionableRow = (child) => {
1012
+ const cands = [child, ...nodes.filter((n) => get(n, 'parent_index') === idxOf(child))];
1013
+ const lvl1 = cands.slice(1);
1014
+ for (const c of lvl1) { const ci = idxOf(c); cands.push(...nodes.filter((n) => get(n, 'parent_index') === ci)); }
1015
+ for (const n of cands) {
1016
+ if ((truthy(get(n, 'clickable')) || truthy(get(n, 'long-clickable'))) && isVisible(n)
1017
+ && !['ImageButton', 'FloatingActionButton'].some((c) => pyStr(get(n, 'class', '')).endsWith(c))
1018
+ && get(n, 'bounds', []).length === 4 && n.bounds[3] > n.bounds[1]) { return n; }
1019
+ }
1020
+ return null;
1021
+ };
1022
+ const rowsOf = (li) => nodes.filter((n) => get(n, 'parent_index') === li).map(actionableRow).filter((r) => truthy(r));
1023
+ // Several scrollables (a Compose page with a header strip and a list): only a container
1024
+ // that holds actionable rows is a list; one such container is no ambiguity.
1025
+ if (lists.length > 1) {
1026
+ const withRows = lists.filter((li) => rowsOf(li).length > 0);
1027
+ if (withRows.length === 1) { lists = withRows; }
1028
+ }
1029
+ if (lists.length !== 1) { throw new AdapterError(`list-item: expected one list, found ${lists.length}`); }
1030
+ const rows = rowsOf(lists[0]);
1031
+ if (!rows.length) { throw new AdapterError('list-item: list has no actionable rows'); }
1032
+ return sortedBy(rows, (n) => [n.bounds[1], n.bounds[0]])[0];
1033
+ }
1034
+
1035
+ reveal(selector, taskId) {
1036
+ if (matching(this.current.nodes, selector).length) { return true; }
1037
+ if (this.clearInterruption(taskId) && matching(this.current.nodes, selector).length) { return true; }
1038
+ if (!this.appUiReady()) { return false; }
1039
+ // Positions count (_viewSig): a list of rows without text moves only its bounds.
1040
+ const origin = _viewSig(this.current);
1041
+ for (const direction of ['down', 'up']) {
1042
+ const seen = new Set([_viewSig(this.current)]);
1043
+ const stuck = new Set();
1044
+ for (let k = 0; k < toInt(get(this.config, 'max_scrolls_per_task', 6)); k++) {
1045
+ const found = this.searchContainer(stuck);
1046
+ if (!found) { break; }
1047
+ const sel = found[1];
1048
+ const prev = _viewSig(this.current);
1049
+ this.atom({ type: 'scroll', selector: sel, direction }, taskId, 'search');
1050
+ if (matching(this.current.nodes, selector).length) { return true; }
1051
+ const key = _viewSig(this.current);
1052
+ if (key === prev) { stuck.add(stuckKey(found[0])); continue; }
1053
+ if (seen.has(key) || this._backAtOrigin(direction, key, origin)) { break; }
1054
+ seen.add(key);
1055
+ }
1056
+ }
1057
+ return false;
1058
+ }
1059
+
1060
+ /**
1061
+ * The vertical container a bounded search scrolls next, as [node, selector]: the only one, else
1062
+ * the largest not yet found immobile in this pass. Requiring exactly one skipped every scroll on
1063
+ * screens with several (measured, Simple Calendar week view: hours column, events list and the
1064
+ * pager). The selector names this very node: copies sharing a resource id (one per pager page)
1065
+ * are told apart by class and position, so one immobile copy does not rule out the others.
1066
+ */
1067
+ searchContainer(stuck) {
1068
+ const nodes = this.current.nodes;
1069
+ const own = (n) => (truthy(get(n, 'resource_id')) && matching(nodes, { resource_id: n.resource_id }).length === 1
1070
+ ? { resource_id: n.resource_id } : (classIndexSel(n, nodes) ?? scrollSel(n, nodes)));
1071
+ const conts = nodes.filter((n) => truthy(get(n, 'scrollable')) && isVisible(n) && !_isHorizontal(n) && !stuck.has(stuckKey(n)))
1072
+ .map((n) => [n, own(n)]);
1073
+ if (conts.length <= 1) { return conts[0] ?? null; }
1074
+ const area = ([n]) => { const b = or(get(n, 'bounds'), [0, 0, 0, 0]); return Math.max(0, b[2] - b[0]) * Math.max(0, b[3] - b[1]); };
1075
+ return sortedBy(conts, (c) => -area(c))[0];
1076
+ }
1077
+
1078
+ /**
1079
+ * The upward search pass is back where the downward pass started: everything below was
1080
+ * already searched, and one more upward swipe at the top of a list is a pull-to-refresh
1081
+ * (SwipeRefreshLayout and friends), which starts network work and may open a dialog
1082
+ * (measured, AntennaPod: 36 of 65 failed round-1 tasks met a refresh dialog opened this
1083
+ * way). `search_above_origin: true` keeps searching above a mid-list origin.
1084
+ */
1085
+ _backAtOrigin(direction, key, origin) {
1086
+ return direction === 'up' && key === origin && !truthy(get(this.config, 'search_above_origin', false));
1087
+ }
1088
+
1089
+ // -- unexpected dialogs -----------------------------------------------------
1090
+
1091
+ /**
1092
+ * A floating window on top of the page: its root does not cover the screen (a uiautomator
1093
+ * dump holds the focused window only, so an AlertDialog, a permission prompt or a rating
1094
+ * prompt shows as one small root) and it offers something to press. Returns its root
1095
+ * bounds, or null.
1096
+ */
1097
+ modalOverlay() {
1098
+ const nodes = get(this.current, 'nodes', []);
1099
+ const roots = nodes.filter((n) => get(n, 'parent_index') === null || get(n, 'parent_index') === undefined);
1100
+ const info = or(get(this.current, 'device_info'), {});
1101
+ const w = toInt(or(get(info, 'width_px'), 0)); const h = toInt(or(get(info, 'height_px'), 0));
1102
+ if (roots.length !== 1 || !(w > 0 && h > 0)) { return null; }
1103
+ const b = or(get(roots[0], 'bounds'), []);
1104
+ if (b.length !== 4) { return null; }
1105
+ const share = ((b[2] - b[0]) * (b[3] - b[1])) / (w * h);
1106
+ if (share >= toFloat(get(this.config, 'modal_max_screen_share', 0.85))) { return null; }
1107
+ return nodes.some((n) => isVisible(n) && truthy(get(n, 'clickable'))) ? b : null;
1108
+ }
1109
+
1110
+ /**
1111
+ * Dismiss a dialog nobody asked for -- one that is neither the page the running task starts
1112
+ * from nor the page it looks for (`this.keep`) -- so it does not eat the search budget.
1113
+ * Action: the first matching `interruption_rules` entry ({id?, when: <rule>, action}), else
1114
+ * the app's own consent dialog is accepted (consentAccept), else Back, then the negative
1115
+ * button (android:id/button2) for a dialog Back does not close. A consent dialog that offers a
1116
+ * decline (button2, or a label CONSENT_DECLINE_RE names: "Decline and exit") and nothing safe to
1117
+ * accept with is left as it is, logged with outcome `unresolved`: there Back closes the Activity
1118
+ * and button2 leaves the app. One without a decline (a "Logging in means agreeing to the 'User Agreement'" one-tap login
1119
+ * sheet) keeps the generic dismissal. Ticking a consent box does not use up a dismissal (two
1120
+ * required boxes, then the accept), up to `limit` ticks.
1121
+ * Each dismissal is an `interruption` event. Returns true when something was dismissed.
1122
+ */
1123
+ clearInterruption(taskId, { restoring = false } = {}) {
1124
+ const limit = toInt(get(this.config, 'max_interruption_dismissals', 2));
1125
+ let dismissed = false;
1126
+ let ticks = 0;
1127
+ for (let k = 0; k < limit + ticks; k++) {
1128
+ const bounds = this.modalOverlay();
1129
+ if (!bounds) { break; }
1130
+ const res = or(get(this.current, 'static_resolution'), {});
1131
+ if (get(res, 'status') === 'verified' && (this.keep ?? []).includes(get(res, 'static_id'))) { break; }
1132
+ const rule = get(this.config, 'interruption_rules', []).find((r) => ruleMatches(this.current, get(r, 'when', {})));
1133
+ const isConsent = !rule && this.consentDialog();
1134
+ const consent = isConsent ? this.consentAccept() : null;
1135
+ const texts = this.current.nodes.map((n) => or(get(n, 'text'), get(n, 'content_desc'))).filter((t) => truthy(t));
1136
+ const before = this.current.observation_id;
1137
+ if (isConsent && !consent && this.consentDecline()) {
1138
+ this.emit('interruption', { task_id: taskId, observation_id: before, bounds, action: null, rule: 'consent-default',
1139
+ texts: texts.slice(0, 6).map((t) => cpSlice(pyStr(t), 0, 80)), outcome: 'unresolved' });
1140
+ break;
1141
+ }
1142
+ const system = !rule && !consent ? this.systemDialogAction() : null;
1143
+ let action = rule ? rule.action : (consent ?? system ?? { type: 'back' });
1144
+ if (!rule && !consent && !system && k > 0 && matching(this.current.nodes, { resource_name: 'button2' }).length === 1) {
1145
+ action = { type: 'click', selector: { resource_name: 'button2' } };
1146
+ }
1147
+ const tick = consent !== null && isToggle(matching(this.current.nodes, consent.selector)[0] ?? {});
1148
+ const result = this.atom(action, taskId, 'dismiss-interruption', { restoring });
1149
+ this.emit('interruption', { task_id: taskId, observation_id: before, bounds, action,
1150
+ rule: rule ? get(rule, 'id', null) : (consent ? 'consent-default' : (system ? 'system-dialog-default' : null)),
1151
+ texts: texts.slice(0, 6).map((t) => cpSlice(pyStr(t), 0, 80)),
1152
+ outcome: result.payload.outcome });
1153
+ // A rule or a consent click that did nothing would do nothing again; Back/button2 would leave.
1154
+ if (result.payload.outcome === 'no_effect' && (rule || consent || system)) { break; }
1155
+ if (tick && ticks < limit) { ticks += 1; }
1156
+ dismissed = dismissed || result.payload.outcome === 'succeeded';
1157
+ }
1158
+ return dismissed;
1159
+ }
1160
+
1161
+ /**
1162
+ * Whether the app under test is the resumed activity but a system window (package `android`:
1163
+ * the 16 KB page-size compatibility dialog, a "keeps stopping" dialog) is what the dump shows.
1164
+ * Measured (jingmo 2026-11-16): on an x86_64 emulator the 「Android 应用兼容性」 dialog covered
1165
+ * MainActivity after every launch; appUiReady never held, so each launch re-captured for
1166
+ * launch_ready_seconds, relaunched, waited again and threw launch-ui-not-ready: every task
1167
+ * aborted and covered stayed 0. The activity (and `component_package`) still name the app.
1168
+ */
1169
+ coveredBySystemDialog() {
1170
+ const pkg = get(this.config, 'package');
1171
+ const cur = or(this.current, {});
1172
+ const shown = get(cur, 'package');
1173
+ if (!truthy(pkg) || !truthy(shown) || shown === pkg) { return false; }
1174
+ return get(cur, 'component_package') === pkg || pyStr(or(get(cur, 'activity'), '')).startsWith(pkg + '.');
1175
+ }
1176
+
1177
+ /**
1178
+ * The click that closes a system dialog over the app for good: its positive button
1179
+ * (android:id/button1) when it is labelled 「不再显示」 / "Don't show again", so the dialog does
1180
+ * not return on the next relaunch. Any other system dialog keeps the generic dismissal (Back).
1181
+ * Returns the click action, or null.
1182
+ */
1183
+ systemDialogAction() {
1184
+ if (!this.coveredBySystemDialog()) { return null; }
1185
+ const hits = matching(get(this.current, 'nodes', []), { resource_id: 'android:id/button1' });
1186
+ if (hits.length !== 1) { return null; }
1187
+ const label = normalized(or(get(hits[0], 'text'), get(hits[0], 'content_desc'), ''));
1188
+ return SYSTEM_DIALOG_SUPPRESS_RE.test(label) ? { type: 'click', selector: { resource_id: 'android:id/button1' } } : null;
1189
+ }
1190
+
1191
+ /**
1192
+ * Wait for the app's own UI after a launch until `deadline`. A system dialog over the app
1193
+ * (coveredBySystemDialog) is dismissed instead of waited out, at most `max_interruption_dismissals`
1194
+ * times per wait: a dialog that returns at once (no 「不再显示」 to silence it) would otherwise spend
1195
+ * the action budget until the deadline. After that the wait only polls. A launch made by a
1196
+ * restore (`purpose`) keeps its budget exemption for the dismissals. Returns the latest observation.
1197
+ */
1198
+ waitAppUi(deadline, taskId, after, purpose = null, moves = null) {
1199
+ const cap = toInt(get(this.config, 'max_interruption_dismissals', 2));
1200
+ const restoring = purpose === 'restore';
1201
+ let cleared = 0;
1202
+ while (!this.appUiReady() && monotonic() < deadline) {
1203
+ // Every attempt counts toward the cap, not only a successful one: a dialog that ignores Back
1204
+ // and button2 would otherwise be pressed on every poll, spend the action budget, and the
1205
+ // press landing just after it closes could leave the app.
1206
+ if (cleared < cap && this.coveredBySystemDialog()) {
1207
+ cleared += 1;
1208
+ if (this.clearInterruption(taskId, { restoring })) { after = this.current; continue; }
1209
+ }
1210
+ sleep(0.5);
1211
+ after = moves ? this.launchCapture(taskId, moves) : this.capture();
1212
+ }
1213
+ return after;
1214
+ }
1215
+
1216
+ /**
1217
+ * capture() while a launch brings its UI up. The foreground moves there by design: the
1218
+ * starting window gives way to the activity, a SplashActivity hands over to the main one. A
1219
+ * capture that straddles such a move throws `Foreground changed during capture`; under a launch
1220
+ * it is retried, spending `moves.left` (launch_transition_captures, default 3, one budget per
1221
+ * launch atom). The budget is a count, not a time: on a slow device one capture outlasts the
1222
+ * whole launch_ready_seconds wait (measured yd-weather 11-14: ~30 s per capture, 8 s wait), so a
1223
+ * deadline would stop the retry before it ran. Any other error, or a move once the budget is
1224
+ * spent, is thrown as before. Each retry emits `launch_foreground_moved`.
1225
+ */
1226
+ launchCapture(taskId, moves) {
1227
+ for (;;) {
1228
+ try { return this.capture(); } catch (e) {
1229
+ if (!(e instanceof AdapterError) || !FOREGROUND_MOVED_RE.test(errStr(e)) || moves.left <= 0) { throw e; }
1230
+ moves.left -= 1;
1231
+ this.emit('launch_foreground_moved', { task_id: taskId, retries_left: moves.left, reason: s200(e) });
1232
+ sleep(0.5);
1233
+ }
1234
+ }
1235
+ }
1236
+
1237
+ /**
1238
+ * The app's own first-launch consent dialog (privacy policy / user agreement): Back closes the
1239
+ * Activity and its negative button is "decline and exit", so the generic dismissal leaves the
1240
+ * app (measured, where2study 11-04: with reset_between_tasks every task cleared data, met the
1241
+ * dialog, pressed Back then button2 "Decline and exit" and ended on the launcher; 0 of 64 tasks
1242
+ * confirmed). Accept it with its positive control instead (consentPositive: android:id/button1
1243
+ * unless its label declines, else a custom layout's one "Agree"/"Agree and continue"/"Agree" node
1244
+ * that is not a toggle). Only when that control is present but disabled is a CheckBox ticked
1245
+ * first ("I have read and agree" keeps it disabled until ticked): the first unticked one whose text
1246
+ * names consent (one per call, so two required boxes take two), else the only unticked one;
1247
+ * several unticked boxes none of which names consent ("Receive push notifications") are not guessed at. Without
1248
+ * a safe control it returns null; clearInterruption then leaves a dialog that offers a decline
1249
+ * (consentDecline) rather than Back, and dismisses any other the generic way.
1250
+ * Which dialogs count is consentDialog's call.
1251
+ * `consent_default: false` turns it off. Returns the click action, or null.
1252
+ */
1253
+ consentAccept() {
1254
+ if (!this.consentDialog()) { return null; }
1255
+ const nodes = get(this.current, 'nodes', []);
1256
+ const positive = this.consentPositive(nodes);
1257
+ if (!positive) { return null; }
1258
+ // The selector must still name the control itself: matching() drops disabled nodes, so a disabled
1259
+ // "Agree" button would leave a same-labelled "Agree" CheckBox as the one hit.
1260
+ const live = matching(nodes, positive.selector);
1261
+ if (live.length === 1 && live[0] === positive.node) { return { type: 'click', selector: positive.selector }; }
1262
+ if (get(positive.node, 'enabled', true) !== false) { return null; }
1263
+ // The positive control is there but disabled: tick the box that enables it.
1264
+ const boxes = matching(nodes, { checked: false }).filter((n) => pyStr(get(n, 'class', '')).endsWith('CheckBox'));
1265
+ const worded = boxes.filter((n) => CONSENT_BOX_RE.test(pyStr(or(get(n, 'text'), get(n, 'content_desc'), ''))));
1266
+ const box = worded.length ? worded[0] : (boxes.length === 1 ? boxes[0] : null);
1267
+ const selector = box ? classIndexSel(box, nodes) : null;
1268
+ const hits = selector ? matching(nodes, selector) : [];
1269
+ return hits.length === 1 && hits[0] === box ? { type: 'click', selector } : null;
1270
+ }
1271
+
1272
+ /**
1273
+ * Whether the screen is the app's own first-launch consent dialog: the policy wording is read
1274
+ * from text and content_desc (a WebView body exposes only the latter). Applies only to a dialog
1275
+ * of the app under test (a node without a package counts as its own, as in looksLoading) whose
1276
+ * text names a policy or agreement, met after a launch and before any action other than a
1277
+ * dismissal (`_launched`, set in atom): a dialog the app raises by itself on start. One that
1278
+ * names a policy after the task pressed something ("Withdraw consent", "Delete account", "Logging in means agreeing")
1279
+ * confirms that press and keeps the generic dismissal. `consent_default: false` turns it off.
1280
+ */
1281
+ consentDialog() {
1282
+ if (get(this.config, 'consent_default', true) === false || !this._launched) { return false; }
1283
+ const pkg = get(this.config, 'package');
1284
+ const nodes = get(this.current, 'nodes', []);
1285
+ if (truthy(pkg) && (get(this.current, 'package', pkg) !== pkg || !nodes.some((n) => get(n, 'package', pkg) === pkg))) { return false; }
1286
+ // content_desc too: a WebView body or a Compose/ImageView label exposes its words only there.
1287
+ const text = nodes.flatMap((n) => [get(n, 'text'), get(n, 'content_desc')]).filter((t) => truthy(t)).map((t) => pyStr(t)).join('\n');
1288
+ return CONSENT_RE.test(text);
1289
+ }
1290
+
1291
+ /**
1292
+ * Whether the consent dialog offers a way to decline: android:id/button2, or a visible control
1293
+ * whose whole label declines ("Do not agree", "Decline and exit", CONSENT_DECLINE_RE). On such a dialog Back
1294
+ * closes the Activity and button2 leaves the app; one without (a login sheet whose fine print names
1295
+ * the agreement) is safe to dismiss with Back.
1296
+ */
1297
+ consentDecline() {
1298
+ const nodes = get(this.current, 'nodes', []);
1299
+ return nodes.some((n) => isVisible(n) && (get(n, 'resource_id') === 'android:id/button2'
1300
+ || (!isToggle(n) && [get(n, 'text'), get(n, 'content_desc')].some((v) => truthy(v)
1301
+ && [...normalized(v)].length <= 12 && CONSENT_DECLINE_RE.test(normalized(v))))));
1302
+ }
1303
+
1304
+ /**
1305
+ * The consent dialog's positive control: android:id/button1 (the AlertDialog positive button,
1306
+ * its full id) unless its label declines (CONSENT_DECLINE_RE: "Do not agree"/"Exit" put there),
1307
+ * else the one visible non-toggle node whose whole text or content_desc is an accept
1308
+ * (CONSENT_POSITIVE_RE) -- a custom-layout dialog's "Agree" TextView, not a "Agree" CheckBox,
1309
+ * named by class and index when a toggle shares its label. Returns {node, selector}, or null
1310
+ * when there is none or more than one.
1311
+ */
1312
+ consentPositive(nodes) {
1313
+ const button1 = nodes.filter((n) => isVisible(n) && get(n, 'resource_id') === 'android:id/button1');
1314
+ if (button1.length > 1) { return null; }
1315
+ if (button1.length === 1 && !CONSENT_DECLINE_RE.test(normalized(or(get(button1[0], 'text'), get(button1[0], 'content_desc'), '')))) {
1316
+ return { node: button1[0], selector: { resource_id: 'android:id/button1' } };
1317
+ }
1318
+ const hits = [];
1319
+ for (const n of nodes) {
1320
+ if (!isVisible(n) || isToggle(n)) { continue; }
1321
+ for (const key of ['text', 'content_desc']) {
1322
+ const v = get(n, key);
1323
+ if (truthy(v) && CONSENT_POSITIVE_RE.test(normalized(v))) {
1324
+ const sel = { [key]: v };
1325
+ hits.push({ node: n, selector: matching(nodes, sel).length > 1 ? (classIndexSel(n, nodes) ?? sel) : sel });
1326
+ break;
1327
+ }
1328
+ }
1329
+ }
1330
+ return hits.length === 1 ? hits[0] : null;
1331
+ }
1332
+
1333
+ // -- top-to-bottom scroll sweep ---------------------------------------------
1334
+
1335
+ sweepEnabled() { return truthy(get(this.config, 'scroll_sweep', true)); }
1336
+
1337
+ sweepContainer() {
1338
+ const nodes = get(this.current, 'nodes', []);
1339
+ const hidden = occludedIndices(nodes);
1340
+ const pkg = get(this.config, 'package');
1341
+ const minH = toInt(get(this.config, 'sweep_min_height_px', 200));
1342
+ let cands = [];
1343
+ nodes.forEach((n, i) => {
1344
+ const b = or(get(n, 'bounds'), []);
1345
+ if (!(truthy(get(n, 'scrollable')) && isVisible(n)) || hidden.has(i) || b.length !== 4) { return; }
1346
+ if (_isHorizontal(n) || (b[3] - b[1]) < minH) { return; }
1347
+ if (truthy(pkg) && ![null, pkg].includes(get(n, 'package'))) { return; }
1348
+ cands.push(n);
1349
+ });
1350
+ cands = sortedBy(cands, (n) => (n.bounds[2] - n.bounds[0]) * (n.bounds[3] - n.bounds[1]), true);
1351
+ for (const n of cands) {
1352
+ const sels = [...(truthy(get(n, 'resource_id')) ? [{ resource_id: n.resource_id }] : []), { class: get(n, 'class') }];
1353
+ for (const sel of sels) {
1354
+ if (!truthy(get(sel, 'class', true))) { continue; }
1355
+ const hits = matching(nodes, sel);
1356
+ if (hits.length === 1 && hits[0] === n) { return [sel, n]; }
1357
+ }
1358
+ const sel = classIndexSel(n, nodes);
1359
+ if (sel !== null) {
1360
+ const hits = matching(nodes, sel);
1361
+ if (hits.length === 1 && hits[0] === n) { return [sel, n]; }
1362
+ }
1363
+ }
1364
+ return null;
1365
+ }
1366
+
1367
+ _sameSurface(origin, selector) {
1368
+ const cur = this.current;
1369
+ if (get(cur, 'package') !== get(origin, 'package') || get(cur, 'activity') !== get(origin, 'activity')
1370
+ || get(cur, 'window') !== get(origin, 'window')) { return false; }
1371
+ let hits;
1372
+ try { hits = matching(get(cur, 'nodes', []), selector); } catch (e) { if (e instanceof AdapterError) { return false; } throw e; }
1373
+ return hits.length === 1 && truthy(get(hits[0], 'scrollable'));
1374
+ }
1375
+
1376
+ /**
1377
+ * The selector naming the swept container on the current screen: `selector` while it still
1378
+ * does, else a fresh one for the one scrollable vertical node at the container's bounds, else
1379
+ * null (the page was left). A `{class, index}` selector counts reading-order positions, and a
1380
+ * Compose page's node count above the list changes as it scrolls. Measured (ydweather preview):
1381
+ * the first swipe folded the hi/lo temperature row, index 8 then named a plain View, and the
1382
+ * sweep aborted `left-page` with no frame although the list sat at the same [42,310,1038,2400].
1383
+ */
1384
+ _surfaceSelector(origin, selector, container) {
1385
+ const cur = this.current;
1386
+ if (this._sameSurface(origin, selector)) {
1387
+ // a drifted {class, index} can land on another scrollable (a LazyRow above the list)
1388
+ const [hit] = matching(get(cur, 'nodes', []), selector);
1389
+ if (!_isHorizontal(hit) && get(hit, 'class') === get(container, 'class')) { return selector; }
1390
+ }
1391
+ if (get(cur, 'package') !== get(origin, 'package') || get(cur, 'activity') !== get(origin, 'activity')
1392
+ || get(cur, 'window') !== get(origin, 'window')) { return null; }
1393
+ const ob = or(get(container, 'bounds'), []);
1394
+ if (ob.length !== 4) { return null; }
1395
+ const nodes = get(cur, 'nodes', []);
1396
+ const same = nodes.filter((n) => {
1397
+ const b = or(get(n, 'bounds'), []);
1398
+ return truthy(get(n, 'scrollable')) && isVisible(n) && !_isHorizontal(n) && b.length === 4
1399
+ && get(n, 'class') === get(container, 'class') && b.every((v, i) => Math.abs(v - ob[i]) <= 4);
1400
+ });
1401
+ if (same.length !== 1) { return null; }
1402
+ const n = same[0];
1403
+ for (const sel of [...(truthy(get(n, 'resource_id')) ? [{ resource_id: n.resource_id }] : []), classIndexSel(n, nodes)]) {
1404
+ if (sel === null) { continue; }
1405
+ const hits = matching(nodes, sel);
1406
+ if (hits.length === 1 && hits[0] === n) { return sel; }
1407
+ }
1408
+ return null;
1409
+ }
1410
+
1411
+ sweep(staticId, purpose = 'sweep') {
1412
+ if (this.swept === undefined) { this.swept = new Set(); }
1413
+ if (!(this.sweepEnabled() && truthy(staticId)) || this.swept.has(staticId)) { return false; }
1414
+ if (!this.at(staticId)) { return false; }
1415
+ const requested = staticId;
1416
+ const res = or(get(or(this.current, {}), 'static_resolution'), {});
1417
+ if (get(res, 'status') === 'verified' && truthy(get(res, 'static_id')) && res.static_id !== staticId) {
1418
+ staticId = res.static_id;
1419
+ this.swept.add(requested);
1420
+ if (this.swept.has(staticId)) { return false; }
1421
+ }
1422
+ this.swept.add(staticId);
1423
+ const taskId = 'sweep:' + staticId;
1424
+ const origin = this.current;
1425
+ const found = this.sweepContainer();
1426
+ const payload = { static_id: staticId, origin_observation: origin.observation_id, frames: [],
1427
+ also_covers: requested === staticId ? [] : [requested], purpose };
1428
+ if (!found) {
1429
+ payload.outcome = 'no-container';
1430
+ this.emit('scroll_sweep', payload);
1431
+ return true;
1432
+ }
1433
+ let [selector, node] = found;
1434
+ payload.container = { selector, class: get(node, 'class'), resource_id: get(node, 'resource_id'), bounds: get(node, 'bounds') };
1435
+ const others = get(origin, 'nodes', []).filter((n) => truthy(get(n, 'scrollable')) && isVisible(n) && n !== node && !_isHorizontal(n))
1436
+ .map((n) => or(get(n, 'resource_id'), get(n, 'class')));
1437
+ if (others.length) { payload.unswept_containers = others; }
1438
+ const maxScrolls = toInt(get(this.config, 'max_sweep_scrolls', 20));
1439
+ let lastSig = _viewSig(origin);
1440
+ let outcome = 'truncated'; let swipes = 0; let effective = 0;
1441
+ try {
1442
+ while (swipes <= maxScrolls) {
1443
+ this.atom({ type: 'scroll', selector, direction: 'down' }, taskId, purpose);
1444
+ swipes += 1;
1445
+ let still = this._surfaceSelector(origin, selector, node);
1446
+ if (still === null) {
1447
+ // A lazy list can change its node count / indices during the swipe without the page
1448
+ // being left. Re-observe once and resolve the container again before declaring an exit.
1449
+ sleep(0.5);
1450
+ try { this.capture({ acceptLoading: true }); } catch { /* keep the last observation */ }
1451
+ still = this._surfaceSelector(origin, selector, node);
1452
+ if (still === null) { outcome = 'aborted'; payload.abort_reason = 'left-page'; break; }
1453
+ }
1454
+ selector = still;
1455
+ const sig = _viewSig(this.current);
1456
+ if (sig === lastSig) {
1457
+ // No movement: either the page end (after a real scroll) or a container that never
1458
+ // moved. `complete` with 0 frames used to claim the page end and hid every below-fold
1459
+ // section; keep the two apart.
1460
+ outcome = effective > 0 ? 'complete' : 'no-effect';
1461
+ break;
1462
+ }
1463
+ effective += 1;
1464
+ if (payload.frames.length >= maxScrolls) { outcome = 'truncated'; break; }
1465
+ lastSig = sig;
1466
+ payload.frames.push(this.current.observation_id);
1467
+ const r = get(this.current, 'static_resolution', {});
1468
+ if (get(r, 'status') === 'verified' && ![null, staticId].includes(get(r, 'static_id')) && !payload.also_covers.includes(r.static_id)) {
1469
+ payload.also_covers.push(r.static_id);
1470
+ }
1471
+ }
1472
+ } catch (e) {
1473
+ if (e instanceof BudgetExhausted) { outcome = 'budget-exhausted'; }
1474
+ else if (e instanceof AdapterError) { outcome = 'aborted'; payload.abort_reason = s200(e); }
1475
+ else { throw e; }
1476
+ }
1477
+ payload.outcome = outcome;
1478
+ payload.swipes = swipes;
1479
+ payload.effective = effective;
1480
+ if (outcome !== 'aborted' || get(payload, 'abort_reason') !== 'left-page') {
1481
+ payload.restored = this._sweepRestore(origin, selector, node, taskId);
1482
+ } else { payload.restored = false; }
1483
+ if (!payload.restored) { this.dirty = true; }
1484
+ for (const x of payload.also_covers) { this.swept.add(x); }
1485
+ this.emit('scroll_sweep', payload);
1486
+ return true;
1487
+ }
1488
+
1489
+ _atTop(origin, container) {
1490
+ const keyed = (obs) => {
1491
+ const seen = new Map(); const out = new Map();
1492
+ for (const n of get(obs, 'nodes', [])) {
1493
+ if (!(isVisible(n) && truthy(get(n, 'resource_id'))) || or(get(n, 'bounds'), []).length !== 4) { continue; }
1494
+ const k = tupleKey(n.resource_id, get(n, 'text'));
1495
+ seen.set(k, (seen.get(k) ?? 0) + 1);
1496
+ out.set(tupleKey(n.resource_id, get(n, 'text'), seen.get(k)), n.bounds);
1497
+ }
1498
+ return out;
1499
+ };
1500
+ const a = keyed(origin); const b = keyed(this.current);
1501
+ if (a.size !== b.size || [...a.keys()].some((k) => !b.has(k))) { return false; }
1502
+ const cb = or(get(container, 'bounds'), [0, 0, 0, 800]);
1503
+ const tol = Math.max(24, Math.trunc(0.03 * (cb[3] - cb[1])));
1504
+ return [...a.keys()].every((k) => {
1505
+ const x = a.get(k); const y = b.get(k);
1506
+ return x.slice(0, Math.min(x.length, y.length)).every((v, i) => Math.abs(v - y[i]) <= tol);
1507
+ });
1508
+ }
1509
+
1510
+ _sweepRestore(origin, selector, container, taskId) {
1511
+ if (this._atTop(origin, container)) { return true; }
1512
+ const limit = toInt(get(this.config, 'max_sweep_scrolls', 20)) * 3 + 2;
1513
+ let last = _viewSig(this.current);
1514
+ try {
1515
+ for (let k = 0; k < limit; k++) {
1516
+ const still = this._surfaceSelector(origin, selector, container);
1517
+ if (still === null) { return false; }
1518
+ selector = still;
1519
+ this.atom({ type: 'scroll', selector, direction: 'up' }, taskId, 'sweep-restore');
1520
+ if (this._atTop(origin, container)) { return true; }
1521
+ const sig = _viewSig(this.current);
1522
+ if (sig === last) { break; }
1523
+ last = sig;
1524
+ }
1525
+ } catch (e) {
1526
+ if (e instanceof BudgetExhausted || e instanceof AdapterError) { return false; }
1527
+ throw e;
1528
+ }
1529
+ return this._atTop(origin, container);
1530
+ }
1531
+
1532
+ sweepBacklog() {
1533
+ if (!this.sweepEnabled()) { return; }
1534
+ if (this.swept === undefined) { this.swept = new Set(); }
1535
+ const mapped = [];
1536
+ for (const e of this.doc.events) {
1537
+ const sid = get(e.payload, 'static_id');
1538
+ if (e.kind === 'mapping' && e.environment_id === this.env && truthy(sid) && !mapped.includes(sid)) { mapped.push(sid); }
1539
+ }
1540
+ const tasks = get(this.doc, 'tasks', []).filter((t) => get(t, 'phase') === this.phase.id
1541
+ && get(t, 'status') === 'compiled' && get(t, 'purpose') !== 'direct-launch');
1542
+ for (const sid of mapped) {
1543
+ if (this.swept.has(sid) || this.scopeExcludes(sid)) { continue; }
1544
+ if (this.at(sid)) { this.sweep(sid, 'sweep-backlog'); continue; }
1545
+ const asSource = tasks.find((t) => get(t, 'source_static') === sid) ?? null;
1546
+ const asTarget = tasks.find((t) => get(t, 'target_static') === sid) ?? null;
1547
+ if (!(asSource || asTarget)) { continue; }
1548
+ const route = { ...(asSource || asTarget), task_id: 'sweep:' + sid };
1549
+ try {
1550
+ this.source(route);
1551
+ if (!asSource) {
1552
+ for (const step of or(get(route, 'prelude'), [])) { this.seek(step, route.task_id, 'sweep-route'); }
1553
+ if (!(truthy(get(route.action, 'automatic')) && this.at(sid))) { this.seek(route.action, route.task_id, 'sweep-route'); }
1554
+ }
1555
+ } catch (e) {
1556
+ if (e instanceof BudgetExhausted) { throw e; }
1557
+ this.swept.add(sid);
1558
+ this.emit('scroll_sweep', { static_id: sid, outcome: 'unreached', frames: [], also_covers: [],
1559
+ purpose: 'sweep-backlog', abort_reason: s200(e) });
1560
+ continue;
1561
+ }
1562
+ if (!this.sweep(sid, 'sweep-backlog') && !this.swept.has(sid)) {
1563
+ this.swept.add(sid);
1564
+ this.emit('scroll_sweep', { static_id: sid, outcome: 'unreached', frames: [], also_covers: [],
1565
+ purpose: 'sweep-backlog', abort_reason: 'page-not-verified-after-route' });
1566
+ }
1567
+ }
1568
+ }
1569
+
1570
+ /**
1571
+ * Selector groups tried after a bounded search fails: `config.overflow_openers` first, then the
1572
+ * containers the campaign's own routes already open (see derivedOverflowOpeners).
1573
+ */
1574
+ overflowOpeners() {
1575
+ if (this._openers === undefined) {
1576
+ const groups = [...get(this.config, 'overflow_openers', []).map((s) => [s]),
1577
+ ...derivedOverflowOpeners(get(this.doc, 'tasks', []), toInt(get(this.config, 'max_derived_overflow_openers', 4)),
1578
+ toInt(get(this.config, 'derived_opener_depth', 1)))];
1579
+ const seen = new Set();
1580
+ this._openers = groups.filter((g) => {
1581
+ const k = jsonDumps(g, { sort_keys: true });
1582
+ if (seen.has(k)) { return false; }
1583
+ seen.add(k); return true;
1584
+ });
1585
+ }
1586
+ return this._openers;
1587
+ }
1588
+
1589
+ seek(action, taskId, purpose) {
1590
+ if (truthy(get(action, 'reveal'))) { this.reveal(action.reveal, taskId); }
1591
+ if (truthy(get(action, 'when')) && !ruleMatches(this.current, action.when)) {
1592
+ this.emit('action_skipped', { task_id: taskId, purpose, reason: 'condition-not-met', action });
1593
+ return null;
1594
+ }
1595
+ const type = get(action, 'type');
1596
+ if (type === 'click_list_item' || type === 'long_click_list_item') {
1597
+ const kind = type.startsWith('long') ? 'long_click_point' : 'click_point';
1598
+ const tapRow = (row) => {
1599
+ const b = row.bounds; const rowInfo = {};
1600
+ for (const k of ['class', 'resource_id', 'text', 'content_desc', 'bounds']) { rowInfo[k] = get(row, k); }
1601
+ return this.atom({ type: kind, x: Math.floor((b[0] + b[2]) / 2), y: Math.floor((b[1] + b[3]) / 2), row: rowInfo }, taskId, purpose);
1602
+ };
1603
+ // Rows filled from the network or a database arrive after the page itself (measured, coolmall:
1604
+ // the home page's goods were not yet in the tree when the step ran): wait, bounded, for a row.
1605
+ const until = monotonic() + Math.max(0, toFloat(get(this.config, 'list_wait_seconds', 6)));
1606
+ while (!this.listCandidates().length && !this.emptyFailure() && monotonic() < until) { sleep(0.5); this.capture({ acceptLoading: true }); }
1607
+ let row;
1608
+ try { row = this.listItem(); } catch (e) {
1609
+ if (!(e instanceof AdapterError)) { throw e; }
1610
+ const empty = this.emptyFailure();
1611
+ if (empty) { throw empty; }
1612
+ if (/^list-item: expected one list, found (?:[2-9]|\d{2,})/.test(errStr(e)) && truthy(get(action, 'target_id'))) {
1613
+ return this.probeLists(action.target_id, tapRow, taskId);
1614
+ }
1615
+ throw e;
1616
+ }
1617
+ return tapRow(row);
1618
+ }
1619
+ if (type === 'scroll_page') {
1620
+ const sideways = ['left', 'right'].includes(get(action, 'direction'));
1621
+ const conts = this.current.nodes.filter((n) => truthy(get(n, 'scrollable')) && isVisible(n) && _isHorizontal(n) === sideways);
1622
+ if (conts.length !== 1) { throw new AdapterError('Scroll requires one visible scrollable container'); }
1623
+ return this.atom({ type: 'scroll', selector: scrollSel(conts[0], this.current.nodes), direction: get(action, 'direction', 'down') }, taskId, purpose);
1624
+ }
1625
+ if (type === 'toggle_on') {
1626
+ // the two-state control in the row titled `label`: tapped only when it is off
1627
+ const i = rowToggle(this.current.nodes, get(action, 'label'));
1628
+ if (i === null) { throw new AdapterError(`toggle: no single two-state control in the row "${pyStr(get(action, 'label'))}"`); }
1629
+ const n = this.current.nodes[i];
1630
+ if (truthy(get(n, 'checked'))) { return null; }
1631
+ const b = n.bounds;
1632
+ return this.atom({ type: 'click_point', x: Math.floor((b[0] + b[2]) / 2), y: Math.floor((b[1] + b[3]) / 2), row: { class: get(n, 'class'), bounds: b } }, taskId, purpose);
1633
+ }
1634
+ if (!Object.hasOwn(CANDIDATE_KINDS, type)) { return this.atom(action, taskId, purpose); }
1635
+ let selected = this.choose(action);
1636
+ if (selected) { return this.atom(selected, taskId, purpose); }
1637
+ if (this.clearInterruption(taskId)) {
1638
+ selected = this.choose(action);
1639
+ if (selected) { return this.atom(selected, taskId, purpose); }
1640
+ }
1641
+ const between = this.betweenNeighbors(action);
1642
+ if (between) { return this.atom(between, taskId, purpose); }
1643
+ // A soft keyboard left up by the last input covers the bottom of the page (a form's submit
1644
+ // button): close it, never with a bare Back, and look again. Measured (coolmall 2026-11-16):
1645
+ // the address form's "Save" was missing from the tree while the keyboard was shown.
1646
+ if (this.current.nodes.some((n) => /EditText|TextField|AutoComplete/.test(pyStr(get(n, 'class', ''))))
1647
+ && typeof this.device?._imeShown === 'function' && this.device._imeShown()) {
1648
+ this.atom({ type: 'hide_ime' }, taskId, 'hide-ime');
1649
+ selected = this.choose(action);
1650
+ if (selected) { return this.atom(selected, taskId, purpose); }
1651
+ }
1652
+ if (!this.appUiReady()) { throw new AdapterError('selector unavailable on non-app/empty UI'); }
1653
+ // Content that loads after the page is ready (a list filled from the network or a database):
1654
+ // look again while the screen is still changing, for a bounded time, before scrolling. A
1655
+ // screen that has settled ends the wait at once. Captures only, no action is spent.
1656
+ const waitUntil = monotonic() + Math.max(0, toFloat(get(this.config, 'selector_wait_seconds', 3)));
1657
+ let lastKey = observationKey(this.current);
1658
+ while (monotonic() < waitUntil) {
1659
+ sleep(0.5);
1660
+ this.capture({ acceptLoading: true });
1661
+ selected = this.choose(action);
1662
+ if (selected) { return this.atom(selected, taskId, purpose); }
1663
+ const key = observationKey(this.current);
1664
+ if (key === lastKey) { break; }
1665
+ lastKey = key;
1666
+ }
1667
+ // Positions count (_viewSig): a list of rows without text moves only its bounds.
1668
+ const origin = _viewSig(this.current);
1669
+ for (const direction of ['down', 'up']) {
1670
+ const seen = new Set([_viewSig(this.current)]);
1671
+ const stuck = new Set();
1672
+ for (let k = 0; k < toInt(get(this.config, 'max_scrolls_per_task', 6)); k++) {
1673
+ const found = this.searchContainer(stuck);
1674
+ if (!found) { break; }
1675
+ const sel = found[1];
1676
+ const prev = _viewSig(this.current);
1677
+ this.atom({ type: 'scroll', selector: sel, direction }, taskId, 'search');
1678
+ selected = this.choose(action);
1679
+ if (selected) { return this.atom(selected, taskId, purpose); }
1680
+ // A dismissed dialog changes the screen without the list moving: measure the list alone.
1681
+ const after = _viewSig(this.current);
1682
+ if (this.clearInterruption(taskId)) {
1683
+ selected = this.choose(action);
1684
+ if (selected) { return this.atom(selected, taskId, purpose); }
1685
+ }
1686
+ const key = _viewSig(this.current);
1687
+ // A container that did not move (a pager, a list already at its end) leaves the others to try.
1688
+ if (after === prev) { stuck.add(stuckKey(found[0])); continue; }
1689
+ if (seen.has(key) || this._backAtOrigin(direction, key, origin)) { break; }
1690
+ seen.add(key);
1691
+ }
1692
+ }
1693
+ for (let round = 0; round < toInt(get(this.config, 'max_horizontal_scrolls', 3)); round++) {
1694
+ const horiz = this.current.nodes.filter((n) => truthy(get(n, 'scrollable')) && isVisible(n) && _isHorizontal(n)
1695
+ && !['ViewPager', 'ViewPager2'].some((c) => pyStr(get(n, 'class', '')).endsWith(c)));
1696
+ if (!horiz.length) { break; }
1697
+ let moved = false;
1698
+ for (const n of horiz) {
1699
+ const sel = truthy(get(n, 'resource_id')) ? { resource_id: n.resource_id } : null;
1700
+ if (!sel || matching(this.current.nodes, sel).length !== 1) { continue; }
1701
+ const key = observationKey(this.current);
1702
+ this.atom({ type: 'scroll', selector: sel, direction: 'right' }, taskId, 'search');
1703
+ selected = this.choose(action);
1704
+ if (selected) { return this.atom(selected, taskId, purpose); }
1705
+ moved = moved || observationKey(this.current) !== key;
1706
+ }
1707
+ if (!moved) { break; }
1708
+ }
1709
+ const own = new Set(get(action, 'selectors', []).map((s) => jsonDumps(s, { sort_keys: true })));
1710
+ const rejected = (this._openersRejected ??= new Set());
1711
+ for (const group of this.overflowOpeners()) {
1712
+ const gk = jsonDumps(group, { sort_keys: true });
1713
+ if (rejected.has(gk)) { continue; }
1714
+ const opener = group.find((s) => !own.has(jsonDumps(s, { sort_keys: true })) && uniqueHit(this.current.nodes, s));
1715
+ if (!opener) { continue; }
1716
+ const before = this.current; const key = observationKey(before);
1717
+ this.atom({ type: 'click', selector: opener }, taskId, 'search-overflow');
1718
+ selected = this.choose(action);
1719
+ if (selected) { return this.atom(selected, taskId, purpose); }
1720
+ // A container opens over its page; an opener that changed page is a navigation, not tried again.
1721
+ if (navigatedAway(before, this.current, or(this.catalog, {}))) { rejected.add(gk); }
1722
+ // Close only what the opener opened; an opener with no visible effect needs no Back.
1723
+ if (observationKey(this.current) !== key) { this.atom({ type: 'back' }, taskId, 'search-overflow-close'); }
1724
+ }
1725
+ throw this.emptyFailure() ?? new AdapterError('selector-not-found-after-bounded-scroll');
1726
+ }
1727
+
1728
+ /**
1729
+ * A form field whose label the screen does not expose (a picker field under a transparent click
1730
+ * layer: only a text-less clickable shows): when the step names the labels of the fields before and
1731
+ * after it (`neighbors`, from the static form order), the one text-less clickable lying between
1732
+ * them, horizontally overlapping them, is tapped by its centre. Measured (coolmall 2026-11-16): the
1733
+ * address form's "Region" field showed as a bare clickable View between "Phone" and "Street".
1734
+ * -> a click_point action, or null.
1735
+ */
1736
+ betweenNeighbors(action) {
1737
+ const nb = get(action, 'neighbors');
1738
+ if (!Array.isArray(nb) || nb.length !== 2) { return null; }
1739
+ const nodes = this.current.nodes;
1740
+ const find = (t) => { if (!t) { return null; } const h = nodes.filter((n) => isVisible(n) && pyStr(get(n, 'text', '')).trim() === t); return h.length === 1 ? h[0] : null; };
1741
+ const [prev, next] = [find(nb[0]), find(nb[1])];
1742
+ if (!prev && !next) { return null; }
1743
+ const top = prev ? prev.bounds[3] : 0;
1744
+ const bottom = next ? next.bounds[1] : Infinity;
1745
+ const ref = prev || next;
1746
+ const hits = nodes.filter((n) => isVisible(n) && truthy(get(n, 'clickable')) && !pyStr(get(n, 'text', '')).trim()
1747
+ && !pyStr(get(n, 'content_desc') ?? get(n, 'content-desc') ?? '').trim() && get(n, 'bounds', []).length === 4
1748
+ && n.bounds[1] >= top - 8 && n.bounds[3] <= bottom + 8 && n.bounds[0] < ref.bounds[2] && n.bounds[2] > ref.bounds[0]
1749
+ && (n.bounds[3] - n.bounds[1]) > 20);
1750
+ if (hits.length !== 1) { return null; }
1751
+ const b = hits[0].bounds;
1752
+ return { type: 'click_point', x: Math.floor((b[0] + b[2]) / 2), y: Math.floor((b[1] + b[3]) / 2), row: { class: get(hits[0], 'class'), bounds: b, between: nb } };
1753
+ }
1754
+
1755
+ /**
1756
+ * The failure to report instead of a missing selector or list row when the screen shows one of the
1757
+ * app's empty-state components (diagnostics.emptyStateShown): `needs-data:<page> (texts)`, or
1758
+ * `needs-network:` for a failed load. The path may be right; the data it needs is not there.
1759
+ */
1760
+ emptyFailure() {
1761
+ const comps = (this._emptyComponents ??= emptyStateComponents(get(this.doc, 'nodes', [])));
1762
+ const shown = emptyStateShown(this.current, comps);
1763
+ if (!shown) { return null; }
1764
+ const page = get(get(this.current, 'static_resolution', {}), 'status') === 'verified'
1765
+ ? this.current.static_resolution.static_id : `activity:${get(this.current, 'activity') ?? ''}`;
1766
+ return new AdapterError(`needs-${shown.kind}:${page} (${shown.texts.join(' / ')})`);
1767
+ }
1768
+
1769
+ /**
1770
+ * Other values of the resources a selector text belongs to (strings.deviceTextsIn): a key
1771
+ * two modules define differently resolves to one of them on the device, by the merge order of the
1772
+ * build. Measured (coolmall 2026-11-15): a recipe tapped "Phone number" (feature/user) while the device
1773
+ * showed "Phone" (feature/main wins, declared first), and the phase ran none of its tasks.
1774
+ */
1775
+ textAlternatesOf(text) {
1776
+ if (this._stringTables === undefined) {
1777
+ const project = get(this.doc, 'source_project');
1778
+ this._stringTables = null;
1779
+ if (truthy(project)) { try { this._stringTables = loadStringTables(project, get(this.doc, 'locale', 'en')); } catch { /* none */ } }
1780
+ }
1781
+ return this._stringTables ? deviceTextsIn(this._stringTables, text || '') : [];
1782
+ }
1783
+
1784
+ /**
1785
+ * The key of a proven route: the phase environment, the start (`fresh` / `warm`), the page the
1786
+ * launch landed on, and the page reached. A route proven from one start and landing replays only
1787
+ * from the same: a first-run page or cleared data changes what the same taps do.
1788
+ */
1789
+ routeKey(page, start = this._start, landing = this._landing) { return [this.env, start, landing, page].join('\u0000'); }
1790
+
1791
+ /**
1792
+ * recordRoute(page, steps): the replay steps, run from this task's own launch, that the device
1793
+ * verified as reaching `page` (not merely attested). The first route proven to a page is kept for
1794
+ * the rest of the run. Only from a launch made for the current task: a task that started on a page
1795
+ * an earlier task left has no launch the steps start from.
1796
+ */
1797
+ recordRoute(page, steps) {
1798
+ if (!truthy(page) || this._launchedFor === undefined || !Array.isArray(steps) || !steps.length) { return; }
1799
+ const routes = (this._routes ??= new Map());
1800
+ const k = this.routeKey(page);
1801
+ if (!routes.has(k)) { routes.set(k, structuredClone(steps)); }
1802
+ }
1803
+
1804
+ /**
1805
+ * rerouteTask(task, i, start, landing, reason): the task with replay steps 0..i (whose last hop
1806
+ * names the page it opens) replaced by a route this run proved reaches that page from the same
1807
+ * start and landing, or null. Each task is rerouted once: the substitute carries `rerouted_from`.
1808
+ * A failure (an ambiguous selector, a control not found, a list that opened another page) then
1809
+ * repeats for none of the tasks sharing that prefix. Measured (coolmall 2026-11-18): logged-out
1810
+ * tasks replayed a coupon claim to reach Login (an ambiguous selector) while other tasks of the run
1811
+ * had reached Login, and every task behind that hop failed or was cut by the prefix memo.
1812
+ */
1813
+ rerouteTask(task, i, start, landing, reason) {
1814
+ if (!truthy(get(this.config, 'reroute_replay', true)) || truthy(get(task, 'rerouted_from'))) { return null; }
1815
+ const replay = or(get(task, 'replay'), []);
1816
+ const page = get(replay[i] ?? {}, 'target_id');
1817
+ if (!truthy(page) || truthy(get(replay[i], 'intermediate'))) { return null; }
1818
+ const route = (this._routes ?? new Map()).get(this.routeKey(page, start, landing));
1819
+ if (!route || jsonDumps(route, { sort_keys: true }) === jsonDumps(replay.slice(0, i + 1), { sort_keys: true })) { return null; }
1820
+ const alt = { ...task, replay: [...structuredClone(route), ...replay.slice(i + 1)], rerouted_from: { replay_index: i, reason } };
1821
+ this.emit('replay_rerouted', { task_id: task.task_id, page, replay_index: i, reason, route_steps: route.length,
1822
+ start, landing, observation_id: get(or(this.current, {}), 'observation_id') });
1823
+ // the substitute launches again: from cleared data when this one did
1824
+ if (start === 'fresh' && this._clearedFor === task.task_id) { this._clearedFor = undefined; }
1825
+ this._launchedFor = undefined;
1826
+ return alt;
1827
+ }
1828
+
1829
+ source(task) {
1830
+ const source = task.source_static;
1831
+ const dirty = this.dirty ?? false;
1832
+ const [matched, how] = deps.observationMatchesStatic(or(this.current, {}), source, this.catalog);
1833
+ // A dialog an earlier task opened still resolves to its host activity: the source "matches" but
1834
+ // its controls sit behind the dialog (measured: a font-size picker left open failed two later
1835
+ // Settings tasks with no scroll). Relaunch instead of searching under it.
1836
+ const srcKind = pyStr(get(get(this.catalog, source, {}), 'kind') ?? pyStr(source).split(':')[0]);
1837
+ const floating = ['panel', 'dialog'].includes(srcKind);
1838
+ // With reset_between_tasks every task starts from cleared data, even one already on its source.
1839
+ if (matched && how === 'exact-page' && !dirty && (floating || !this.modalOverlay()) && !this.resetsBetweenTasks()) { return; }
1840
+ // Back only when it can land on the source: from a root page (or any page the source never
1841
+ // opens) it just leaves the app, costing an action before the relaunch below anyway.
1842
+ const here = get(get(this.current, 'static_resolution', {}), 'status') === 'verified'
1843
+ ? this.current.static_resolution.static_id : null;
1844
+ if (this.current.package === mget(this.config, 'package') && !matched && !dirty && !this.resetsBetweenTasks()
1845
+ && !(here !== null && (this.backExits ?? new Set()).has(here))
1846
+ && backCanReach(this.current, source, this.catalog)) {
1847
+ this.atom({ type: 'back' }, task.task_id, 'recover');
1848
+ if (here !== null && this.current.package !== mget(this.config, 'package')) {
1849
+ (this.backExits ??= new Set()).add(here);
1850
+ }
1851
+ if (deps.observationMatchesStatic(this.current, source, this.catalog)[1] === 'exact-page') { return; }
1852
+ }
1853
+ let launch = { ...(or(get(task, 'source_launch'), {})) };
1854
+ if (!truthy(launch)) { launch = { type: 'launch', component: mget(this.config, 'launch_component'), restart: true }; }
1855
+ // A prefix that already failed this run fails the same way again: report it without replaying.
1856
+ // Only from the same landing: a first-run page (Guide) comes and goes with app data, and a prefix
1857
+ // that failed past it (Home, "Skip" gone) replays fine on a fresh install, and the reverse
1858
+ // (measured, coolmall 2026-11-08: a failure on Home cut 23 tasks that a cleared start would run).
1859
+ // A failure is keyed by the start (`fresh`: data cleared for this task, else `warm`) and the
1860
+ // landing: the page the launch settles on past its own splash, before launchBridge walks a Guide
1861
+ // on to Main (that would make a fresh and a warm start look the same).
1862
+ // The check runs before the clear and launch (each costs actions) when the landing is
1863
+ // predictable: a fresh start always lands the same; a warm one keeps landing where the last warm
1864
+ // one did once that is a page of the launch chain, or (no chain) the last two warm starts agreed.
1865
+ // A first-run page off the chain gives way once its flag is stored, so it is checked after launch.
1866
+ const memo = truthy(get(this.config, 'prefix_memo', true)) ? (this._prefixFailures ??= new Map()) : null;
1867
+ const replay = mget(task, 'replay');
1868
+ const start = this.resetsBetweenTasks() && this._clearedFor !== task.task_id ? 'fresh' : 'warm';
1869
+ // A failed prefix with a proven route to the page its failing hop opens is replayed through that
1870
+ // route instead (rerouteTask); the reroute runs after the memo check, from the next launch.
1871
+ let reroute = null;
1872
+ const memoHit = (landing) => {
1873
+ if (!memo || landing === undefined) { return; }
1874
+ for (let n = 1; n <= replay.length; n++) {
1875
+ const k = prefixKey(task, n);
1876
+ const e = memo.get(k);
1877
+ if (e && e.start === start && e.landing === landing) {
1878
+ reroute = this.rerouteTask(task, e.replay_index, start, landing, e.reason);
1879
+ if (reroute) { return; }
1880
+ throw new PrefixFailed(e, k);
1881
+ }
1882
+ }
1883
+ };
1884
+ const last = (this._lastLanding ??= {})[start];
1885
+ const chain = or(get(task, 'launch_chain'), []);
1886
+ if (last && (start === 'fresh' || (chain.length ? chain.includes(last.landing) : last.repeated))) { memoHit(last.landing); }
1887
+ if (reroute) { return this.source(reroute); }
1888
+ this.resetBetweenTasks(task.task_id);
1889
+ this.atom(launch, task.task_id, 'recover');
1890
+ this.waitLaunchPage(task);
1891
+ this._landing = landingOf(this.current);
1892
+ this._start = start;
1893
+ this._launchedFor = task.task_id;
1894
+ this._lastLanding[start] = { landing: this._landing, repeated: last?.landing === this._landing };
1895
+ memoHit(this._landing);
1896
+ if (reroute) { return this.source(reroute); }
1897
+ this.launchBridge(task, { waited: true });
1898
+ const attested = new Set();
1899
+ let passedSoFar = 0;
1900
+ for (let i = 0; i < replay.length; i++) {
1901
+ const step = replay[i];
1902
+ const stepStart = get(or(this.current, {}), 'observation_id');
1903
+ // only the leading hops: no replay gesture has run since the launch
1904
+ if (passedSoFar === i && this.replayStepPassed(step)) {
1905
+ passedSoFar += 1;
1906
+ this.emit('replay_step_passed', { task_id: task.task_id, replay_index: i, target_id: step.target_id, observation_id: stepStart });
1907
+ continue;
1908
+ }
1909
+ try {
1910
+ const stepResult = this.seek(step, task.task_id, 'replay');
1911
+ if (truthy(get(step, 'intermediate')) || !truthy(get(step, 'target_id'))) { continue; }
1912
+ if (!this.at(step.target_id)) {
1913
+ if (!this.attestedArrival(step.target_id, stepResult, task.task_id)) {
1914
+ throw new AdapterError('replay-target-unverified:' + step.target_id);
1915
+ }
1916
+ attested.add(step.target_id);
1917
+ } else {
1918
+ this.recordRoute(step.target_id, replay.slice(0, i + 1));
1919
+ }
1920
+ } catch (e) {
1921
+ const msg = errStr(e);
1922
+ if (memo && e instanceof AdapterError && PREFIX_FAILURES.some((r) => msg.startsWith(r))) {
1923
+ memo.set(prefixKey(task, i + 1), { reason: msg, task_id: task.task_id, replay_index: i, start: this._start, landing: this._landing,
1924
+ observation_id: get(or(this.current, {}), 'observation_id'), before_id: stepStart });
1925
+ }
1926
+ if (e instanceof AdapterError && PREFIX_FAILURES.some((r) => msg.startsWith(r))) {
1927
+ const alt = this.rerouteTask(task, i, this._start, this._landing, msg);
1928
+ if (alt) { return this.source(alt); }
1929
+ }
1930
+ throw e;
1931
+ }
1932
+ }
1933
+ // A transient source (a splash that leaves by itself) is gone once the app is ready; its
1934
+ // automatic edges have already fired, so the target check alone decides the task.
1935
+ if (truthy(get(get(this.catalog, source, {}), 'transient')) && truthy(get(task.action, 'automatic'))) { return; }
1936
+ if (!this.at(source)) { this.clearInterruption(task.task_id); }
1937
+ if (!this.at(source)) {
1938
+ const ctx = get(task, 'source_context');
1939
+ // With no replay the launch alone must have opened the chain. Its deepest anchored page is
1940
+ // checkable, so an anchorless source behind it is not taken on the activity's word while
1941
+ // that page is missing (measured, weather 2026-11-14: the settings tap lost from the path,
1942
+ // every preference-dialog task passed on MainActivity and scrolled the main screen).
1943
+ // Only a screen read as other pages proves the launch fell short: verified as a page outside the
1944
+ // chain's tail, or ambiguous among such pages only. A default child that fills the host (its
1945
+ // widgets gone from the dump) is unmapped, and is left to the checks below.
1946
+ const chain = or(get(task, 'launch_chain'), []);
1947
+ const chainHost = replay.length ? undefined : [...chain].reverse().find((p) => p !== source && !this.anchorless(p));
1948
+ const tailIds = chain.slice(chain.indexOf(chainHost));
1949
+ const outside = (id) => truthy(id) && id !== source && !tailIds.includes(id);
1950
+ const shown = or(get(this.current, 'static_resolution'), {});
1951
+ const shownCands = or(get(shown, 'candidates'), []).map((c) => get(c, 'static_id'));
1952
+ const elsewhere = get(shown, 'status') === 'verified' ? outside(get(shown, 'static_id'))
1953
+ : get(shown, 'status') === 'ambiguous' && shownCands.length > 0 && shownCands.every(outside);
1954
+ if (chainHost !== undefined && elsewhere && !this.at(chainHost)) {
1955
+ this.emit('source_chain_missing', { task_id: task.task_id, source, missing: chainHost,
1956
+ observation_id: get(or(this.current, {}), 'observation_id') });
1957
+ throw new AdapterError('source-unverified:' + source);
1958
+ }
1959
+ if (!(this.anchorless(source) && (attested.has(source)
1960
+ || (truthy(ctx) && (this.at(ctx) || this.transientSuccessor(ctx, source, task.task_id)))
1961
+ || (!replay.length && this.launchedInto(source, task.task_id))))) {
1962
+ throw new AdapterError('source-unverified:' + source);
1963
+ }
1964
+ }
1965
+ }
1966
+
1967
+ /**
1968
+ * A replay tap whose target page is already on screen and whose control is not: a first-run hop
1969
+ * the path carries as a gesture (coolmall Guide "Skip" → Main) is shown only until it stores its
1970
+ * flag, so a relaunch without a data clear lands past it. Measured (coolmall 2026-11-08): a sweep
1971
+ * relaunch stood on Home, "Skip" was searched for by scrolling Home, and the prefix memo failed
1972
+ * 23 of 40 p0-fresh tasks with it. A control still visible is tapped as before.
1973
+ * Not a control of the target page itself (its own label in the catalog): there an absent control
1974
+ * is below the fold, behind a reveal or still loading, and the gesture is still owed. The caller
1975
+ * offers only the leading hops, before any replay gesture ran.
1976
+ * `entry_cues` are not the target's own: they are the opener's control texts, on the page before
1977
+ * it. Measured (coolmall 2026-11-15): Main's cues "Skip" / "Get started" read as Main's own controls,
1978
+ * the hop was never passed, and a recovery phase standing on Home failed 20 of 20 tasks behind it.
1979
+ */
1980
+ replayStepPassed(step) {
1981
+ if (!Object.hasOwn(CANDIDATE_KINDS, get(step, 'type')) && !['click', 'long_click'].includes(get(step, 'type'))) { return false; }
1982
+ if (truthy(get(step, 'intermediate')) || !truthy(get(step, 'target_id')) || !this.at(step.target_id)) { return false; }
1983
+ const labels = [get(step, 'static_label'), ...or(get(step, 'static_label_alt'), [])].filter(truthy).map((l) => pyStr(l).trim());
1984
+ const own = Object.entries(or(get(this.catalog, step.target_id), {})).filter(([k]) => k !== 'entry_cues')
1985
+ .flatMap(([, v]) => (Array.isArray(v) ? v : [v]))
1986
+ .filter((v) => typeof v === 'string').map((v) => v.trim());
1987
+ if (labels.some((l) => own.includes(l))) { return false; }
1988
+ try { return !this.choose(step); } catch (e) { if (e instanceof AdapterError) { return false; } throw e; }
1989
+ }
1990
+
1991
+ /**
1992
+ * A launch still standing on its own page (`launch_page`, a Splash whose timer outlasts the
1993
+ * settle) is watched for up to `launch_chain_wait_seconds` (default 6) until it leaves it.
1994
+ */
1995
+ waitLaunchPage(task) {
1996
+ const chain = or(get(task, 'launch_chain'), []);
1997
+ const first = get(task, 'launch_page');
1998
+ if (!chain.length || !truthy(first) || chain.includes(first)) { return; }
1999
+ const deadline = monotonic() + Math.max(0, toFloat(get(this.config, 'launch_chain_wait_seconds', 6)));
2000
+ while (this.at(first) && !chain.some((p) => this.at(p)) && monotonic() < deadline) { sleep(0.5); this.capture(); }
2001
+ }
2002
+
2003
+ /**
2004
+ * The launch reached another page (a first-run Guide) instead of the ones it opens by itself
2005
+ * (`launch_chain`, Splash → Main): take that page's compiled exit into the chain. This runs on
2006
+ * every launch that lands off the chain; the exit usually writes the first-run flag, so later
2007
+ * launches stop landing there and the bridge stops firing.
2008
+ * Measured (coolmall 2026-10-29): without it every cold launch stayed on Guide, every task
2009
+ * behind Main failed source-unverified, and Guide was the only page captured.
2010
+ * A launch still on its own page is waited out first (waitLaunchPage): deciding on Splash would
2011
+ * miss the Guide that comes after it. `waited`: the caller already waited (source() does, to take
2012
+ * the landing), so a splash that outlasts the wait is not waited on twice.
2013
+ */
2014
+ launchBridge(task, { waited = false } = {}) {
2015
+ const chain = or(get(task, 'launch_chain'), []);
2016
+ if (!chain.length) { return; }
2017
+ if (!waited) { this.waitLaunchPage(task); }
2018
+ if (get(this.current, 'package') !== get(this.config, 'package') || chain.some((p) => this.at(p))) { return; }
2019
+ const exit = get(this.doc, 'tasks', []).find((t) => get(t, 'status') === 'compiled' && chain.includes(get(t, 'target_static'))
2020
+ && !chain.includes(get(t, 'source_static')) && !truthy(get(t, 'replay')) && !truthy(get(get(t, 'action'), 'automatic'))
2021
+ && get(get(t, 'action'), 'type') !== 'unresolved' && this.at(get(t, 'source_static')));
2022
+ if (!exit) { return; }
2023
+ this.emit('launch_bridge', { task_id: task.task_id, via: exit.task_id, from: exit.source_static, to: exit.target_static,
2024
+ observation_id: get(this.current, 'observation_id') });
2025
+ try {
2026
+ for (const step of [...or(get(exit, 'prelude'), []), exit.action]) { this.seek(step, task.task_id, 'launch-bridge'); }
2027
+ } catch (e) {
2028
+ if (!(e instanceof AdapterError) || TRANSIENT_DEVICE_RE.test(errStr(e))) { throw e; }
2029
+ this.emit('launch_bridge_failed', { task_id: task.task_id, via: exit.task_id, reason: errStr(e) });
2030
+ }
2031
+ }
2032
+
2033
+ /**
2034
+ * True when the page has no anchor it always shows (title, rows, layout ids). Body texts do
2035
+ * not count: they are presence-only evidence and may sit in a branch or a dialog the page opens.
2036
+ */
2037
+ anchorless(ident) {
2038
+ const page = get(this.catalog, ident, {});
2039
+ return !(truthy(get(page, 'titles')) || truthy(get(page, 'row_titles')) || truthy(get(page, 'widget_ids')));
2040
+ }
2041
+
2042
+ /**
2043
+ * Identity by elimination on this app's own screen: the current capture is in the app package,
2044
+ * not verified as any page, and not claimed by any of `rivals`. Used only for anchorless pages.
2045
+ */
2046
+ _unclaimedAppScreen(rivals = [], candidate = null) {
2047
+ if (get(this.current, 'package') !== get(this.config, 'package')) { return false; }
2048
+ const res = or(get(this.current, 'static_resolution'), {});
2049
+ if (get(res, 'status') === 'verified') { return false; }
2050
+ // A page the resolver has recognized on this device would be recognized again: an
2051
+ // unverified screen is not it.
2052
+ if (candidate !== null && this.recognized(candidate)) { return false; }
2053
+ return !rivals.some((r) => this.at(r));
2054
+ }
2055
+
2056
+ /** The page was verified by its own anchors at least once in this campaign. */
2057
+ recognized(ident) {
2058
+ if (this._recognized === undefined) {
2059
+ this._recognized = new Set(this.doc.events.filter((e) => e.kind === 'mapping').map((e) => get(e.payload, 'static_id')));
2060
+ }
2061
+ return this._recognized.has(ident);
2062
+ }
2063
+
2064
+ /**
2065
+ * `ctx` is a transient entry whose automatic edges lead to `source`: once launched, the screen
2066
+ * that replaced it is `source` unless it is one of the transient page's other successors.
2067
+ */
2068
+ transientSuccessor(ctx, source, taskId) {
2069
+ const page = get(this.catalog, ctx, {});
2070
+ const targets = or(get(page, 'auto_targets'), []);
2071
+ if (!truthy(get(page, 'transient')) || !targets.includes(source)) { return false; }
2072
+ if (!this._unclaimedAppScreen(targets.filter((t) => t !== source), source)) { return false; }
2073
+ this.emit('source_attested', { task_id: taskId, static_id: source, basis: 'transient-successor', context: ctx,
2074
+ observation_id: this.current.observation_id });
2075
+ return true;
2076
+ }
2077
+
2078
+ /** A launch with no replay landed on an anchorless page the launcher's transient entry opens. */
2079
+ launchedInto(source, taskId) {
2080
+ const entries = Object.keys(or(this.catalog, {})).filter((k) => truthy(get(this.catalog[k], 'transient'))
2081
+ && or(get(this.catalog[k], 'auto_targets'), []).includes(source));
2082
+ return entries.length === 1 && this.transientSuccessor(entries[0], source, taskId);
2083
+ }
2084
+
2085
+ /**
2086
+ * Trigger-chain arrival for an anchorless page: the replay step's own gesture ran on the
2087
+ * device and changed the screen, and the screen it reached is the app's, unverified as any page.
2088
+ */
2089
+ attestedArrival(target, stepResult, taskId) {
2090
+ if (!this.anchorless(target) || !truthy(stepResult) || get(stepResult.payload, 'outcome') !== 'succeeded') { return false; }
2091
+ if (!this._unclaimedAppScreen([], target)) { return false; }
2092
+ this.emit('source_attested', { task_id: taskId, static_id: target, basis: 'trigger-chain-replay',
2093
+ action_event_id: stepResult.id, observation_id: this.current.observation_id });
2094
+ return true;
2095
+ }
2096
+
2097
+ runDirect(task, done) {
2098
+ const ident = task.task_id;
2099
+ try {
2100
+ this.stage = 'direct-launch';
2101
+ this.resetBetweenTasks(ident);
2102
+ this.atom(task.source_launch, ident, 'direct-launch');
2103
+ for (const step of or(get(task, 'prelude'), [])) { this.seek(step, ident, 'direct-launch'); }
2104
+ // A dialog over the target (a first-launch consent dialog; without a prelude no seek clears it).
2105
+ if (!this.at(task.target_static)) { this.clearInterruption(ident); }
2106
+ const confirmed = this.at(task.target_static);
2107
+ if (confirmed) { done.add(ident); }
2108
+ this.emit('task_result', { task_id: ident, outcome: confirmed ? 'confirmed' : 'target-unverified',
2109
+ target_static: task.target_static, purpose: 'direct-launch', observation_id: this.current.observation_id });
2110
+ if (confirmed) { this.sweep(task.target_static); }
2111
+ } catch (e) {
2112
+ if (e instanceof BudgetExhausted) {
2113
+ this.emit('task_result', { task_id: ident, outcome: 'budget-exhausted', stage: this.stage });
2114
+ throw e;
2115
+ }
2116
+ this.emit('task_result', { task_id: ident, outcome: 'failed', stage: this.stage, purpose: 'direct-launch',
2117
+ reason: cpSlice(errStr(e), 0, 300), target_static: task.target_static,
2118
+ observation_id: get(or(this.current, {}), 'observation_id') });
2119
+ }
2120
+ }
2121
+
2122
+ attest(task, result) {
2123
+ const obs = new Map();
2124
+ for (const e of this.doc.events) {
2125
+ if (e.kind === 'observation' && e.environment_id === this.env) { obs.set(e.payload.observation_id, e.payload); }
2126
+ }
2127
+ const before = obs.get(result.payload.before) ?? {};
2128
+ const sourceExact = deps.observationMatchesStatic(before, task.source_static, this.catalog)[1] === 'exact-page';
2129
+ const [ok, basis] = deps.triggerAttests(task, before, this.current, get(result.payload, 'action'),
2130
+ this.catalog, get(this.config, 'package'), sourceExact);
2131
+ if (ok) {
2132
+ this.emit('attestation', { static_id: task.target_static, task_id: task.task_id, observation_id: this.current.observation_id,
2133
+ basis: 'trigger-chain', evidence: basis, action_event_id: result.id });
2134
+ }
2135
+ }
2136
+
2137
+ discoveryConfig() {
2138
+ const raw = get(this.config, 'discovery', {});
2139
+ if (!(raw && typeof raw === 'object' && !Array.isArray(raw))) { return {}; }
2140
+ const scoped = get(raw, this.phase.id, raw);
2141
+ return scoped && typeof scoped === 'object' && !Array.isArray(scoped) && truthy(get(scoped, 'enabled')) ? scoped : {};
2142
+ }
2143
+
2144
+ discoveryActions(config) {
2145
+ const actions = this.device.actions(this.current);
2146
+ const allow = get(config, 'allow_actions', []); const deny = get(config, 'deny_actions', []);
2147
+ const allowUnlisted = truthy(get(config, 'allow_unlisted_actions', false));
2148
+ const selected = [];
2149
+ for (const action of actions) {
2150
+ const hits = matching(this.current.nodes, get(action, 'selector', {}));
2151
+ if (hits.length !== 1) { continue; }
2152
+ const scoped = { ...this.current, nodes: [hits[0]] };
2153
+ if (truthy(deny) && deny.some((rule) => ruleMatches(scoped, rule))) { continue; }
2154
+ if (truthy(allow)) { if (!allow.some((rule) => ruleMatches(scoped, rule))) { continue; } }
2155
+ else if (!allowUnlisted) { continue; }
2156
+ selected.push(action);
2157
+ }
2158
+ return selected.slice(0, Math.max(0, toInt(get(config, 'max_actions_per_state', 8))));
2159
+ }
2160
+
2161
+ runDiscovery() {
2162
+ const config = this.discoveryConfig();
2163
+ if (!truthy(config)) { return { enabled: false }; }
2164
+ // discovery walks the app from launch, not toward a node: a scoped campaign has no use for it
2165
+ if (scopeOf(this.doc) !== null) { return { enabled: false, outcome: 'skipped', reason: 'scoped campaign' }; }
2166
+ const maxDepth = Math.max(0, toInt(get(config, 'max_depth', 3)));
2167
+ const maxStates = Math.max(1, toInt(get(config, 'max_states', 30)));
2168
+ const maxExp = () => toInt(get(config, 'max_expansions', 60));
2169
+ const queue = [[]]; const visited = new Set(); let expanded = 0; let transitions = 0; let failures = 0;
2170
+ const hash = (v, n) => sha256Hex(jsonDumps(v, { sort_keys: true })).slice(0, n);
2171
+ const restore = (p) => {
2172
+ this.atom({ type: 'launch', component: mget(this.config, 'launch_component'), restart: true }, 'discovery:restore', 'discover-recover');
2173
+ p.forEach((action, index) => this.atom(action, 'discovery:replay:' + index, 'discover-replay'));
2174
+ };
2175
+ let outcome;
2176
+ try {
2177
+ while (queue.length && visited.size < maxStates) {
2178
+ const p = queue.shift();
2179
+ try { restore(p); } catch (e) {
2180
+ if (e instanceof BudgetExhausted) { throw e; }
2181
+ if (!(e instanceof AdapterError)) { throw e; }
2182
+ failures += 1;
2183
+ this.emit('route_result', { route_id: 'discovery-replay-' + hash(p, 12), outcome: 'failed', reason: errStr(e),
2184
+ observation_id: this.current.observation_id });
2185
+ continue;
2186
+ }
2187
+ const state = observationKey(this.current);
2188
+ if (visited.has(state)) { continue; }
2189
+ visited.add(state);
2190
+ if (p.length >= maxDepth) { continue; }
2191
+ const candidates = this.discoveryActions(config);
2192
+ for (const action of candidates) {
2193
+ if (expanded >= maxExp()) { break; }
2194
+ expanded += 1;
2195
+ try {
2196
+ restore(p);
2197
+ const before = observationKey(this.current);
2198
+ const result = this.atom(action, 'discovery:' + expanded, 'discover');
2199
+ const after = observationKey(this.current);
2200
+ if (before === after) { continue; }
2201
+ transitions += 1;
2202
+ this.emit('route_result', { route_id: 'discovery-' + hash([...p, action], 16), outcome: 'captured',
2203
+ observation_id: this.current.observation_id, action_event_id: result.id, depth: p.length + 1 });
2204
+ if (!visited.has(after) && p.length + 1 < maxDepth) { queue.push([...p, action]); }
2205
+ } catch (e) {
2206
+ if (!(e instanceof AdapterError)) { throw e; }
2207
+ failures += 1;
2208
+ this.emit('route_result', { route_id: 'discovery-action-' + expanded, outcome: 'failed', reason: errStr(e),
2209
+ observation_id: this.current.observation_id });
2210
+ }
2211
+ }
2212
+ if (expanded >= maxExp()) { break; }
2213
+ }
2214
+ outcome = 'completed';
2215
+ } catch (e) {
2216
+ if (!(e instanceof BudgetExhausted)) { throw e; }
2217
+ outcome = 'budget-exhausted';
2218
+ }
2219
+ const result = { enabled: true, outcome, states: visited.size, transitions, expanded_actions: expanded, failures };
2220
+ this.emit('discovery_result', result);
2221
+ return result;
2222
+ }
2223
+
2224
+ _block(reason) { Object.assign(this.phase, { status: 'blocked', reason }); this.save(); }
2225
+
2226
+ /** Blocked because the device did not come back (see DEVICE_UNAVAILABLE_EXIT). */
2227
+ deviceUnavailable() { return this.phase.status === 'blocked' && this.phase.reason === DEVICE_UNAVAILABLE; }
2228
+
2229
+ /**
2230
+ * Grant the app's not-yet-granted runtime permissions (`grant_runtime_permissions`, default
2231
+ * on), so a permission prompt or the settings page the app opens never takes the foreground in
2232
+ * the middle of a capture. A campaign that needs the permission-denied or rationale screens sets
2233
+ * it to false (for the whole config, or runs those phases with a config that does).
2234
+ * Returns [granted, failed].
2235
+ */
2236
+ grantRuntimePermissions() { return grantRuntimePermissions(this.device, this.config); }
2237
+
2238
+ /**
2239
+ * `config.reset_between_tasks` (true, or a list of phase ids): clear app data before a task's
2240
+ * launch, so a setting one task changed does not reshape the next one's start page (measured,
2241
+ * Simple Calendar: a task chose the week view, the app stored it, and every later launch opened
2242
+ * on a week view with no FAB). `am start -S` only kills the process. Applies only to a phase with
2243
+ * no fixtures: a fixture-built state would be wiped with nothing to rebuild it.
2244
+ */
2245
+ resetsBetweenTasks() {
2246
+ const want = get(this.config, 'reset_between_tasks', false);
2247
+ const on = Array.isArray(want) ? want.includes(get(this.phase, 'id')) : truthy(want);
2248
+ return on && !get(get(this.config, 'fixtures', {}), get(this.phase, 'id'), []).length;
2249
+ }
2250
+
2251
+ /**
2252
+ * Once per task: a second source() of the same task (after a sweep left the page scrolled) only
2253
+ * needs the relaunch, since nothing between the two calls could store a setting. Each clear
2254
+ * costs an action and a cold start. A backlog sweep route (`sweep:<id>`) is its own visit and
2255
+ * clears again: the task before it may have changed a setting.
2256
+ */
2257
+ resetBetweenTasks(taskId) {
2258
+ if (!this.resetsBetweenTasks() || (taskId !== undefined && this._clearedFor === taskId)) { return; }
2259
+ this.atom({ type: 'clear_app_data' }, taskId, 'recover');
2260
+ this.grantRuntimePermissions();
2261
+ this._clearedFor = taskId;
2262
+ }
2263
+
2264
+ /**
2265
+ * Before the fixtures: grant runtime permissions, then leave any other app's screen.
2266
+ * A fixture step that resets app data (`pm clear` revokes every grant) grants them again.
2267
+ * One `environment_prepared` event.
2268
+ */
2269
+ prepareEnvironment() {
2270
+ const pkg = get(this.config, 'package');
2271
+ if (!truthy(pkg)) { return; }
2272
+ const [granted, failed] = this.grantRuntimePermissions();
2273
+ let left = null;
2274
+ const fg = get(this.current, 'package');
2275
+ if (truthy(fg) && fg !== pkg && !truthy(get(this.config, 'keep_foreign_foreground'))) {
2276
+ try { this.device._shell('input', 'keyevent', 'KEYCODE_HOME'); left = fg; } catch { /* the launch decides */ }
2277
+ }
2278
+ this.emit('environment_prepared', { phase: this.phase.id, granted, failed, left_foreground: left });
2279
+ }
2280
+
2281
+ _runFixtures() {
2282
+ let skip = 0;
2283
+ // a gesture ran since the last launch / restore: later hops are owed, never "already passed"
2284
+ let gestured = false;
2285
+ for (const action of get(get(this.config, 'fixtures', {}), this.phase.id, [])) {
2286
+ if (skip > 0) { skip -= 1; continue; }
2287
+ // A fixture's own save step only exists to hand its state to later phases. When the phase
2288
+ // runs again (next round, resume) the archive is the one this fixture already wrote: keep it
2289
+ // (never overwrite) and continue, instead of blocking the phase on its own artifact.
2290
+ const kept = ['snapshot_app_data', 'save_replay'].includes(get(action, 'type')) && truthy(get(action, 'archive'))
2291
+ && fs.existsSync(pathStr(action.archive));
2292
+ // A kept .tar that is not a whole archive would restore a half state into every later
2293
+ // phase: move it aside (never delete) and let the fixture write it again.
2294
+ const bad = kept && action.type === 'snapshot_app_data' ? tarProblem(pathStr(action.archive)) : null;
2295
+ if (bad) {
2296
+ const aside = `${pathStr(action.archive)}.corrupt-${Date.now()}`;
2297
+ fs.renameSync(pathStr(action.archive), aside);
2298
+ this.emit('fixture_snapshot_corrupt', { phase: this.phase.id, archive: pathStr(action.archive), reason: bad, moved_to: aside });
2299
+ } else if (kept) {
2300
+ this.emit('fixture_snapshot_kept', { phase: this.phase.id, type: action.type, archive: pathStr(action.archive) });
2301
+ continue;
2302
+ }
2303
+ if (get(action, 'type') === 'assert') {
2304
+ if (!ruleMatches(this.current, action.rule)) {
2305
+ this._block('fixture-assert-failed: ' + cpSlice(jsonDumps(action.rule, { ensure_ascii: false }), 0, 120));
2306
+ return false;
2307
+ }
2308
+ continue;
2309
+ }
2310
+ // `skip_unless { rule, count }`: the next `count` steps run only when the screen matches `rule`
2311
+ // (a seeding recipe creates a record only while its list page shows the empty state, so a
2312
+ // rerun never makes a second one).
2313
+ if (get(action, 'type') === 'skip_unless') {
2314
+ if (!ruleMatches(this.current, get(action, 'rule', {}))) {
2315
+ const n = Math.max(0, toInt(get(action, 'count', 0)));
2316
+ this.emit('fixture_steps_skipped', { phase: this.phase.id, count: n, rule: action.rule, observation_id: get(this.current, 'observation_id') });
2317
+ skip = n;
2318
+ }
2319
+ continue;
2320
+ }
2321
+ // A recipe step compiled from a click path (it names its target page) whose page is already up
2322
+ // and whose control is gone: a first-run hop the warm launch has passed (replayStepPassed).
2323
+ if (!gestured && truthy(get(action, 'target_id')) && this.replayStepPassed(action)) {
2324
+ this.emit('replay_step_passed', { task_id: 'fixture:' + this.phase.id, target_id: action.target_id, observation_id: get(this.current, 'observation_id') });
2325
+ continue;
2326
+ }
2327
+ const at = get(action, 'type');
2328
+ if (['launch', 'clear_app_data', 'restore_app_data'].includes(at)) { gestured = false; }
2329
+ else if (!['wait', 'snapshot_app_data', 'save_replay'].includes(at)) { gestured = true; }
2330
+ try {
2331
+ this.seek(action, 'fixture:' + this.phase.id, 'prepare');
2332
+ if (['clear_app_data', 'restore_app_data'].includes(get(action, 'type'))) { this.grantRuntimePermissions(); }
2333
+ } catch (exc) {
2334
+ if (!(exc instanceof AdapterError)) { throw exc; }
2335
+ try {
2336
+ if (!(TRANSIENT_DEVICE_RE.test(errStr(exc)) && this.waitDevice())) { throw exc; }
2337
+ this.seek(action, 'fixture:' + this.phase.id, 'prepare');
2338
+ } catch (exc2) {
2339
+ if (!(exc2 instanceof AdapterError)) { throw exc2; }
2340
+ const sel = fixtureStepTarget(action);
2341
+ // What the screen did show: recover_d.mjs stepFailures offers the recipe back so its steps
2342
+ // can be rewritten from evidence. Measured (coolmall 2026-11-18): a login recipe tapped
2343
+ // "请输入手机号码" on a screen whose field read "请输入手机号", and the phase stayed blocked.
2344
+ this.emit('fixture_step_failed', { phase: this.phase.id, step: get(action, 'type'), part: get(action, 'recipe_part', null), selector: sel,
2345
+ observation_id: get(this.current, 'observation_id'), activity: get(this.current, 'activity'),
2346
+ visible_texts: visibleTexts(this.current) });
2347
+ this._block(`fixture-step-failed: ${pyStr(get(action, 'type'))} ${cpSlice(jsonDumps(sel, { ensure_ascii: false }), 0, 80)}: ${errStr(exc2)}`);
2348
+ return false;
2349
+ }
2350
+ }
2351
+ }
2352
+ return true;
2353
+ }
2354
+
2355
+ run() {
2356
+ this._launched = false;
2357
+ this.awaitContent(this.capture());
2358
+ const tasks = get(this.doc, 'tasks', []).filter((t) => t.phase === this.phase.id);
2359
+ const probesFor = get(get(this.config, 'phase_probes', {}), this.phase.id);
2360
+ if (truthy(this.phase.requires) && !truthy(probesFor)) {
2361
+ const fallback = fallbackScope(this.config, this.phase, probesFor, this.doc);
2362
+ if (fallback === null) {
2363
+ return this._block('unresolved prerequisites: ' + this.phase.requires.join(', '));
2364
+ }
2365
+ this.emit('state_probe_missing', { phase: this.phase.id, requires: this.phase.requires, fallback });
2366
+ }
2367
+ // A phase that writes to the backend (a seeding recipe) runs only while the switch is still on:
2368
+ // turning `allow_data_writes` off after scheduling stops it on the next run. `writes_data` decides;
2369
+ // a recS- phase with no flag at all was scheduled before the flag existed (seed_recipes apply
2370
+ // backfills it on its next run) and counts as writing until then.
2371
+ const writes = get(this.phase, 'writes_data');
2372
+ const legacySeed = (writes === undefined || writes === null) && String(this.phase.id).startsWith('recS-');
2373
+ if ((writes === true || legacySeed) && get(this.config, 'allow_data_writes') !== true) {
2374
+ return this._block('data-writes-disabled: config.allow_data_writes is not true');
2375
+ }
2376
+ this.prepareEnvironment();
2377
+ if (!this._runFixtures()) { return undefined; }
2378
+ const probes = get(get(this.config, 'phase_probes', {}), this.phase.id, []);
2379
+ if (truthy(probes) && !probes.every((r) => ruleMatches(this.current, r))) {
2380
+ // What the screen did show: recover_d.mjs offers it back so the probe can be rewritten from
2381
+ // evidence. Measured (ydweather): the recipe reached Main, but its probe asked for a sticky
2382
+ // title that is never in the tree at rest, and Main stayed uncaptured.
2383
+ this.emit('state_probe_failed', { phase: this.phase.id, observation_id: get(this.current, 'observation_id'),
2384
+ activity: get(this.current, 'activity'), visible_texts: visibleTexts(this.current), probes });
2385
+ return this._block('state-probe-failed');
2386
+ }
2387
+ this.emit('environment_verified', { phase: this.phase.id, observation_id: this.current.observation_id,
2388
+ scope: truthy(probes) ? 'configured probes'
2389
+ : (truthy(this.phase.requires) ? fallbackScope(this.config, this.phase, probes, this.doc) : 'existing state, no guard assumed') });
2390
+ this.phase.status = 'running'; this.save();
2391
+ let routeFailures = 0;
2392
+ for (const route of get(get(this.config, 'routes', {}), this.phase.id, [])) {
2393
+ try {
2394
+ for (const action of route.actions) {
2395
+ if (get(action, 'type') === 'assert') {
2396
+ if (!ruleMatches(this.current, action.rule)) { throw new AdapterError('route checkpoint failed'); }
2397
+ } else { this.seek(action, 'route:' + route.id, 'discover'); }
2398
+ }
2399
+ this.emit('route_result', { route_id: route.id, outcome: 'captured', observation_id: this.current.observation_id });
2400
+ } catch (e) {
2401
+ if (e instanceof BudgetExhausted) {
2402
+ Object.assign(this.phase, { status: 'budget-exhausted', reason: 'discovery route budget exhausted' }); this.save(); return undefined;
2403
+ }
2404
+ routeFailures += 1;
2405
+ this.emit('route_result', { route_id: route.id, outcome: 'failed', reason: errStr(e), observation_id: this.current.observation_id });
2406
+ }
2407
+ }
2408
+ const runStart = this.doc.events.length;
2409
+ const starts = counter(this.doc.events.filter((e) => e.kind === 'task_started').map((e) => e.payload.task_id));
2410
+ const phaseTaskIds = new Set(tasks.map((t) => t.task_id));
2411
+ const done = new Set(this.doc.events.filter((e) => e.kind === 'task_result' && e.payload.outcome === 'confirmed'
2412
+ && phaseTaskIds.has(e.payload.task_id)).map((e) => e.payload.task_id));
2413
+ let scheduled = 0;
2414
+ const transient = new Map();
2415
+ const skipped = new Set();
2416
+ try {
2417
+ for (const task of tasks) {
2418
+ const ident = task.task_id;
2419
+ if (done.has(ident) || (starts.get(ident) ?? 0) >= toInt(get(this.config, 'max_task_attempts', 1))) { continue; }
2420
+ if (this.coverage === 'nodes' && this.covered.has(get(task, 'target_static'))) {
2421
+ this.emit('task_skipped', { task_id: ident, target_static: task.target_static, reason: 'target-already-covered' });
2422
+ skipped.add(ident);
2423
+ continue;
2424
+ }
2425
+ // A scoped (incremental) campaign: a target outside the scope is settled, whatever the mode.
2426
+ if (this.scopeExcludes(get(task, 'target_static'))) {
2427
+ this.emit('task_skipped', { task_id: ident, target_static: task.target_static, reason: 'target-out-of-scope' });
2428
+ skipped.add(ident);
2429
+ continue;
2430
+ }
2431
+ if (scheduled >= this.args.max_tasks) { break; }
2432
+ if (task.status !== 'compiled') {
2433
+ const reasons = or(get(task, 'compile_issues'), ['needs-external-assistance']);
2434
+ this.emit('task_result', { task_id: ident, outcome: 'unsupported', reason: reasons.join(', '), compile_issues: reasons });
2435
+ continue;
2436
+ }
2437
+ const invariants = get(get(this.config, 'invariant_probes', {}), this.phase.id, []);
2438
+ if (truthy(invariants) && !invariants.every((p) => ruleMatches(this.current, p))) { return this._block('state-drift'); }
2439
+ const isRoute = get(task, 'purpose') === 'route-launch' || get(task.action, 'type') === 'route';
2440
+ // A route task that cannot run (capture disabled, route down for this phase) is settled
2441
+ // without starting it: no task_started, no attempt spent, so a later run still gets it.
2442
+ const routeBlocked = isRoute ? this.routeUnavailable() : null;
2443
+ if (routeBlocked) {
2444
+ this.emit('task_result', { task_id: ident, outcome: 'unsupported', reason: routeBlocked, target_static: task.target_static });
2445
+ continue;
2446
+ }
2447
+ scheduled += 1; starts.set(ident, (starts.get(ident) ?? 0) + 1);
2448
+ this.emit('task_started', { task_id: ident, target_static: task.target_static });
2449
+ this.keep = [task.source_static, task.target_static, get(task, 'source_context')].filter((x) => truthy(x));
2450
+ this._launched = false; // only a launch of this task's own opens the consent window
2451
+ this._clearedFor = null; // every attempt of a task starts from cleared data (resetBetweenTasks)
2452
+ if (get(task, 'purpose') === 'direct-launch') { this.runDirect(task, done); continue; }
2453
+ if (isRoute) {
2454
+ const how = this.runRoute(task, done, transient);
2455
+ if (how === 'retry') { starts.set(ident, starts.get(ident) - 1); tasks.push(task); }
2456
+ if (how === DEVICE_UNAVAILABLE) { return this._block(DEVICE_UNAVAILABLE); }
2457
+ continue;
2458
+ }
2459
+ try {
2460
+ this._runTask(task, ident, done);
2461
+ } catch (exc) {
2462
+ if (exc instanceof BudgetExhausted) {
2463
+ this.emit('task_result', { task_id: ident, outcome: 'budget-exhausted', stage: this.stage });
2464
+ throw exc;
2465
+ }
2466
+ const msg = errStr(exc);
2467
+ if (msg.includes('does not exist') && msg.includes('Activity class')) {
2468
+ // Only a launch of the app's launcher proves a wrong namespace: an uninstalled module may
2469
+ // have its own MainActivity with the same simple name, and that skips just this task.
2470
+ const mismatch = truthy(get(get(task, 'source_launch'), 'launcher'))
2471
+ ? launchMismatch(msg, get(this.config, 'launch_component')) : null;
2472
+ if (mismatch) {
2473
+ this.emit('task_result', { task_id: ident, outcome: 'failed', reason: mismatch, stage: this.stage,
2474
+ target_static: task.target_static });
2475
+ return this._block(mismatch);
2476
+ }
2477
+ this.emit('task_result', { task_id: ident, outcome: 'unsupported', reason: 'entry-component-not-installed',
2478
+ stage: this.stage, target_static: task.target_static });
2479
+ continue;
2480
+ }
2481
+ if (TRANSIENT_DEVICE_RE.test(msg)) {
2482
+ const recovered = this.waitDevice();
2483
+ transient.set(ident, (transient.get(ident) ?? 0) + 1);
2484
+ if (recovered && transient.get(ident) <= toInt(get(this.config, 'max_device_retries', 1))) {
2485
+ starts.set(ident, starts.get(ident) - 1);
2486
+ this.emit('task_result', { task_id: ident, outcome: 'device-error', reason: cpSlice(msg, 0, 200), stage: this.stage,
2487
+ retrying: true, target_static: task.target_static });
2488
+ tasks.push(task);
2489
+ continue;
2490
+ }
2491
+ this.emit('task_result', { task_id: ident, outcome: 'device-error', reason: cpSlice(msg, 0, 200), stage: this.stage,
2492
+ target_static: task.target_static });
2493
+ if (!recovered) { return this._block(DEVICE_UNAVAILABLE); }
2494
+ continue;
2495
+ }
2496
+ const prefix = exc instanceof PrefixFailed
2497
+ ? { prefix_failed_from: exc.from, prefix_key: exc.key, replay_index: exc.replayIndex, prefix_before: exc.beforeId } : {};
2498
+ this.emit('task_result', { task_id: ident, outcome: 'failed', stage: this.stage,
2499
+ unmet_preconditions: or(get(task, 'task_preconditions'), []).map((x) => get(x, 'text')),
2500
+ reason: msg, target_static: task.target_static,
2501
+ observation_id: exc instanceof PrefixFailed ? exc.observationId : this.current.observation_id, ...prefix });
2502
+ }
2503
+ pyPrint(jsonDumps({ task: ident, attempted_this_run: scheduled, confirmed: done.size, atomic_actions: this.used,
2504
+ target: task.target_static }, { ensure_ascii: false }));
2505
+ }
2506
+ } catch (exc) {
2507
+ if (!(exc instanceof BudgetExhausted)) { throw exc; }
2508
+ Object.assign(this.phase, { status: 'budget-exhausted', reason: errStr(exc) }); this.save(); return undefined;
2509
+ }
2510
+ try { this.sweepBacklog(); } catch (e) { if (!(e instanceof BudgetExhausted)) { throw e; } }
2511
+ const discovery = this.runDiscovery();
2512
+ const mapped = new Set(this.doc.events.filter((e) => e.kind === 'mapping' && e.environment_id === this.env)
2513
+ .map((e) => get(e.payload, 'static_id')));
2514
+ const missing = this.phase.obligations.filter((o) => o.type === 'node' && !mapped.has(o.id) && !this.scopeExcludes(o.id));
2515
+ const resolved = new Set([...done, ...skipped]).size;
2516
+ // One failed prefix the memo reused for many tasks: name it, the phase ran little of itself.
2517
+ const byId = new Map(get(this.doc, 'tasks', []).map((t) => [t.task_id, t]));
2518
+ for (const t of tasks) { byId.set(t.task_id, t); }
2519
+ const collapses = collapsedPrefixes(this.doc.events.slice(runStart), byId,
2520
+ { env: this.env, min: toInt(get(this.config, 'collapse_min_cascade', COLLAPSE_MIN_CASCADE)) });
2521
+ for (const c of collapses) { this.emit('phase_collapsed', { phase: this.phase.id, ...c }); }
2522
+ Object.assign(this.phase, {
2523
+ status: resolved === tasks.length && !missing.length && !routeFailures ? 'completed' : 'exhausted-with-gaps',
2524
+ reason: `${done.size}/${tasks.length} tasks confirmed; ${skipped.size} skipped (target already covered or out of scope); `
2525
+ + `${missing.length} node obligations missing; ${routeFailures} routes failed; `
2526
+ + `discovery=${pyStr(get(discovery, 'outcome', 'disabled'))}; coverage=${this.coverage}`
2527
+ + collapses.map((c) => `; COLLAPSED: ${collapseNote(c)}`).join(''),
2528
+ });
2529
+ if (collapses.length) { this.phase.collapsed = collapses.map(({ targets, ...c }) => c); }
2530
+ this.save();
2531
+ return undefined;
2532
+ }
2533
+
2534
+ /**
2535
+ * A uni-app route-jump task: one page = one route inside the shared WebView host, so there is
2536
+ * no Activity to launch and no in-app click path to replay. `route` (DeviceAdapter) executes
2537
+ * uni.reLaunch / uni.switchTab through the WebView, then the normal capture/mapping pipeline
2538
+ * identifies the landing page by its route token.
2539
+ */
2540
+ runRoute(task, done, transient = new Map()) {
2541
+ const ident = task.task_id;
2542
+ this.stage = 'target';
2543
+ try {
2544
+ if (get(this.current, 'package') !== mget(this.config, 'package')) {
2545
+ this.atom({ type: 'launch', component: mget(this.config, 'launch_component'), restart: true }, ident, 'route');
2546
+ }
2547
+ this.seek(task.action, ident, 'target');
2548
+ } catch (exc) {
2549
+ if (exc instanceof BudgetExhausted) { throw exc; }
2550
+ const msg = errStr(exc);
2551
+ const code = routeErrorCode(msg);
2552
+ // Only a deterministic cause takes the route down for the rest of the phase (no DevTools
2553
+ // socket while adb works; uni absent in every target that answered).
2554
+ if (ROUTE_DOWN_CODES.has(code)) {
2555
+ this._hybridRouteDown = msg;
2556
+ this.emit('hybrid_route_unavailable', { task_id: ident, reason: msg, code });
2557
+ } else if (ROUTE_TRANSIENT_CODES.has(code) || TRANSIENT_DEVICE_RE.test(msg)) {
2558
+ // A CDP/adb hiccup: retry the task like a transient device error (_runTask's handling).
2559
+ const device = TRANSIENT_DEVICE_RE.test(msg);
2560
+ const recovered = device ? this.waitDevice() : true;
2561
+ transient.set(ident, (transient.get(ident) ?? 0) + 1);
2562
+ const retrying = recovered && transient.get(ident) <= toInt(get(this.config, 'max_device_retries', 1));
2563
+ this.emit('task_result', { task_id: ident, outcome: device ? 'device-error' : 'failed', stage: 'target',
2564
+ reason: cpSlice(msg, 0, 200), transient: true, ...(retrying ? { retrying: true } : {}), target_static: task.target_static });
2565
+ if (retrying) { return 'retry'; }
2566
+ return recovered ? undefined : DEVICE_UNAVAILABLE;
2567
+ }
2568
+ this.emit('task_result', { task_id: ident, outcome: 'failed', stage: 'target', reason: msg,
2569
+ target_static: task.target_static, observation_id: get(or(this.current, {}), 'observation_id') });
2570
+ return undefined;
2571
+ }
2572
+ const confirmed = this.at(task.target_static);
2573
+ if (confirmed) { done.add(ident); }
2574
+ this.emit('task_result', { task_id: ident, outcome: confirmed ? 'confirmed' : 'target-unverified',
2575
+ purpose: 'route-launch', target_static: task.target_static, observation_id: this.current.observation_id });
2576
+ if (confirmed) { this.sweep(task.target_static); }
2577
+ return undefined;
2578
+ }
2579
+
2580
+ /** Why a route task cannot run in this phase (capture disabled / route down), else null. */
2581
+ routeUnavailable() {
2582
+ if (get(this.config, 'hybrid_route_capture', true) === false) { return 'hybrid-route-capture disabled'; }
2583
+ if (this._hybridRouteDown) { return 'hybrid-route unavailable earlier in this phase: ' + this._hybridRouteDown; }
2584
+ return null;
2585
+ }
2586
+
2587
+ _runTask(task, ident, done) {
2588
+ this.stage = 'source';
2589
+ this.source(task);
2590
+ if (this.sweep(task.source_static) && (this.dirty ?? false)) { this.source(task); }
2591
+ this.stage = 'target';
2592
+ let result; let mark;
2593
+ if (truthy(get(task.action, 'automatic')) && this.at(task.target_static)) {
2594
+ result = this.emit('action_result', { task_id: ident, purpose: 'target', outcome: 'succeeded',
2595
+ before: this.current.observation_id, after: this.current.observation_id, action: task.action });
2596
+ } else {
2597
+ mark = this.doc.events.length;
2598
+ for (const step of or(get(task, 'prelude'), [])) { this.seek(step, ident, 'target-prelude'); }
2599
+ result = this.seek(task.action, ident, 'target');
2600
+ }
2601
+ const confirmed = this.at(task.target_static);
2602
+ if (confirmed) {
2603
+ let chain = [result];
2604
+ if (!truthy(get(task.action, 'automatic'))) {
2605
+ chain = this.doc.events.slice(mark).filter((e) => e.kind === 'action_result' && get(e.payload, 'task_id') === ident);
2606
+ }
2607
+ const firstBefore = chain[0].payload.before;
2608
+ let beforeObs = {};
2609
+ for (let k = this.doc.events.length - 1; k >= 0; k--) {
2610
+ const e = this.doc.events[k];
2611
+ if (e.kind === 'observation' && get(e.payload, 'observation_id') === firstBefore) { beforeObs = e.payload; break; }
2612
+ }
2613
+ const sourceMatch = deps.observationMatchesStatic(beforeObs, task.source_static, this.catalog)[1];
2614
+ const targetMatch = deps.observationMatchesStatic(this.current, task.target_static, this.catalog)[1];
2615
+ this.emit('edge_mapping', { task_id: ident, static_id: task.target_static, source_static: task.source_static,
2616
+ target_static: task.target_static, action_event_id: result.id, action_chain: chain.map((e) => e.id),
2617
+ before: firstBefore, after: result.payload.after, source_match: sourceMatch,
2618
+ method: get(get(this.current, 'static_resolution', {}), 'reason', targetMatch) });
2619
+ done.add(ident);
2620
+ } else if (!truthy(get(task.action, 'automatic')) && truthy(result)) {
2621
+ this.attest(task, result);
2622
+ } else if (truthy(get(task.action, 'automatic')) && this.anchorless(task.target_static)
2623
+ && truthy(get(get(this.catalog, task.source_static, {}), 'transient'))) {
2624
+ // The transient entry left to an anchorless page: identity by elimination only, so it is
2625
+ // attested (listed apart), never mapped.
2626
+ const rivals = or(get(get(this.catalog, task.source_static, {}), 'auto_targets'), []).filter((t) => t !== task.target_static);
2627
+ if (this._unclaimedAppScreen(rivals, task.target_static)) {
2628
+ this.emit('attestation', { static_id: task.target_static, task_id: ident, observation_id: this.current.observation_id,
2629
+ basis: 'transient-successor', evidence: { context: task.source_static, rivals },
2630
+ action_event_id: truthy(result) ? result.id : null });
2631
+ }
2632
+ }
2633
+ this.emit('task_result', { task_id: ident, outcome: confirmed ? 'confirmed' : 'target-unverified',
2634
+ target_static: task.target_static, observation_id: this.current.observation_id });
2635
+ if (confirmed) { this.sweep(task.target_static); }
2636
+ }
2637
+ }
2638
+
2639
+ /**
2640
+ * back_exit_pages(events): verified pages from which a Back press has already left the app (the
2641
+ * app's root screens, learned from the device). Recovery relaunches from them instead of pressing
2642
+ * Back again. Derived from the event log, so it carries across phases, rounds and resumes.
2643
+ */
2644
+ export function backExitPages(events) {
2645
+ const obs = new Map();
2646
+ for (const e of events) { if (e.kind === 'observation') { obs.set(tupleKey(e.environment_id, get(e.payload, 'observation_id')), e.payload); } }
2647
+ const out = new Set();
2648
+ for (const e of events) {
2649
+ const p = e.payload;
2650
+ if (e.kind !== 'action_result' || get(get(p, 'action', {}), 'type') !== 'back') { continue; }
2651
+ const before = obs.get(tupleKey(e.environment_id, get(p, 'before'))) ?? {};
2652
+ const after = obs.get(tupleKey(e.environment_id, get(p, 'after'))) ?? {};
2653
+ const rb = get(before, 'static_resolution', {}) ?? {};
2654
+ if (get(rb, 'status') === 'verified' && get(get(after, 'static_resolution', {}) ?? {}, 'status') === 'foreign-package') {
2655
+ out.add(rb.static_id);
2656
+ }
2657
+ }
2658
+ return out;
2659
+ }
2660
+
2661
+ /** deviceLock options of a runner: config.device_lock_wait_s (default LOCK_WAIT_S), owner campaign. */
2662
+ export function lockWait(config, campaign) {
2663
+ return { waitS: toFloat(get(config ?? {}, 'device_lock_wait_s', LOCK_WAIT_S)), campaign: pResolve(campaign) };
2664
+ }
2665
+
2666
+ /**
2667
+ * run_campaign_phase(args): run one phase under the device lock, then its cleanup steps. The
2668
+ * Runner (which loads campaign.json and saves it wholesale) is built only once the lock is held,
2669
+ * so a run that waited for another run of this campaign starts from that run's saved document.
2670
+ */
2671
+ export function runCampaignPhase(args) {
2672
+ const config = readJson(args.config);
2673
+ const serial = get(config, 'serial');
2674
+ if (!truthy(serial)) { throw new AdapterError('Explicit serial required to avoid controlling the wrong device'); }
2675
+ let runner = null;
2676
+ let busy = null;
2677
+ try {
2678
+ deviceLock(serial, () => {
2679
+ runner = new Runner(args);
2680
+ try {
2681
+ try {
2682
+ runner.run();
2683
+ } finally {
2684
+ runner.save();
2685
+ const cleanup = get(get(runner.config, 'cleanup', {}), runner.phase.id, []);
2686
+ if (truthy(cleanup)) {
2687
+ for (const action of cleanup) {
2688
+ if (get(action, 'type') === 'assert') {
2689
+ if (!ruleMatches(runner.current, action.rule)) { throw new AdapterError('cleanup postcondition failed'); }
2690
+ } else { runner.seek(action, 'cleanup:' + runner.phase.id, 'restore'); }
2691
+ }
2692
+ runner.emit('environment_restored', { phase: runner.phase.id, observation_id: runner.current.observation_id });
2693
+ }
2694
+ }
2695
+ } finally {
2696
+ // Close (persistent shell, u2 server on device port 9008) while the lock is still held:
2697
+ // a run waiting for the lock would otherwise reuse our live server, which this close kills.
2698
+ runner.device.close();
2699
+ }
2700
+ }, lockWait(config, args.campaign));
2701
+ } catch (e) {
2702
+ if (!(e instanceof DeviceBusy)) { throw e; }
2703
+ busy = e;
2704
+ }
2705
+ // another explorer kept the device: device-unavailable, not a failed phase
2706
+ if (busy) {
2707
+ pyPrintErr(`phase ${pyStr(get(args, 'phase'))} blocked: ${busy.message}`);
2708
+ throw new SystemExit(DEVICE_UNAVAILABLE_EXIT);
2709
+ }
2710
+ if (runner.deviceUnavailable()) {
2711
+ pyPrintErr(`phase ${runner.phase.id} blocked: device-unavailable`);
2712
+ throw new SystemExit(DEVICE_UNAVAILABLE_EXIT);
2713
+ }
2714
+ }