@buaa_smat/hometrans 26.0.1 → 26.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1053) hide show
  1. package/README.md +14 -7
  2. package/agents/code-reviewer.md +25 -138
  3. package/dist/cli/index.js +4 -1
  4. package/dist/cli/init.js +131 -26
  5. package/dist/cli/uninstall.js +5 -5
  6. package/dist/platform/language.js +77 -0
  7. package/env-requirements.json +30 -5
  8. package/i18n/FILE-NAMES.md +9 -0
  9. package/i18n/agents/code-reviewer.md +364 -0
  10. package/i18n/agents/model-render-worker.md +38 -0
  11. package/i18n/agents/specgen-worker.md +18 -0
  12. package/i18n/commands/hometrans.md +17 -0
  13. package/i18n/skills/a2h-app-migrate/SKILL.md +198 -0
  14. package/i18n/skills/a2h-app-migrate/references/config.example.json +28 -0
  15. package/i18n/skills/a2h-app-migrate/references/specs.example.json +19 -0
  16. package/i18n/skills/a2h-app-migrate/references/stage-map.md +50 -0
  17. package/i18n/skills/a2h-app-migrate/references/workflow.yaml +1760 -0
  18. package/i18n/skills/a2h-app-migrate/scripts/check_spec_gen_done.mjs +114 -0
  19. package/i18n/skills/a2h-app-migrate/scripts/env_preflight.mjs +1588 -0
  20. package/i18n/skills/a2h-app-migrate/scripts/human_review_gate.mjs +657 -0
  21. package/i18n/skills/a2h-app-migrate/scripts/validate_workflow.mjs +541 -0
  22. package/i18n/skills/a2h-app-migrate/test/test_android_index.mjs +131 -0
  23. package/i18n/skills/a2h-app-migrate/test/test_arch_done.mjs +54 -0
  24. package/i18n/skills/a2h-app-migrate/test/test_build_fixer_contract.mjs +98 -0
  25. package/i18n/skills/a2h-app-migrate/test/test_config_example.mjs +42 -0
  26. package/i18n/skills/a2h-app-migrate/test/test_ensure_utg_snapshot.mjs +147 -0
  27. package/i18n/skills/a2h-app-migrate/test/test_env_requirements.mjs +698 -0
  28. package/i18n/skills/a2h-app-migrate/test/test_finalize.mjs +89 -0
  29. package/i18n/skills/a2h-app-migrate/test/test_image_probe.mjs +120 -0
  30. package/i18n/skills/a2h-app-migrate/test/test_interaction.mjs +122 -0
  31. package/i18n/skills/a2h-app-migrate/test/test_preflight_report.mjs +93 -0
  32. package/i18n/skills/a2h-app-migrate/test/test_resume_plan.mjs +219 -0
  33. package/i18n/skills/a2h-app-migrate/test/test_resume_summary.mjs +196 -0
  34. package/i18n/skills/a2h-app-migrate/test/test_reuse_static_utg.mjs +100 -0
  35. package/i18n/skills/a2h-app-migrate/test/test_run_dir.mjs +488 -0
  36. package/i18n/skills/a2h-app-migrate/test/test_skill_doc.mjs +144 -0
  37. package/i18n/skills/a2h-app-migrate/test/test_spec_gen_done.mjs +146 -0
  38. package/i18n/skills/a2h-app-migrate/test/test_spec_gen_gate.mjs +161 -0
  39. package/i18n/skills/a2h-app-migrate/test/test_specs_json_preflight.mjs +76 -0
  40. package/i18n/skills/a2h-app-migrate/test/test_ui_batch_gate.mjs +226 -0
  41. package/i18n/skills/a2h-app-migrate/test/test_user_facing_progress.mjs +43 -0
  42. package/i18n/skills/a2h-app-migrate/test/test_utg_static_done.mjs +171 -0
  43. package/i18n/skills/a2h-app-migrate/test/test_validate_workflow_bilingual.mjs +87 -0
  44. package/i18n/skills/a2h-arch-generate/SKILL.md +375 -0
  45. package/i18n/skills/a2h-arch-generate/examples/reconcile-existing-project.md +107 -0
  46. package/i18n/skills/a2h-arch-generate/examples/simple-conversion-backend.md +70 -0
  47. package/i18n/skills/a2h-arch-generate/references/arkts-mvvm-v2.md +1407 -0
  48. package/i18n/skills/a2h-arch-generate/references/artifact-contracts.generate.md +120 -0
  49. package/i18n/skills/a2h-arch-generate/references/artifact-contracts.reconcile.md +123 -0
  50. package/i18n/skills/a2h-arch-generate/references/bpta-layered-architecture-design.md +88 -0
  51. package/i18n/skills/a2h-arch-generate/references/database-schema-recovery.md +107 -0
  52. package/i18n/skills/a2h-arch-generate/references/existing-target-annotation.md +68 -0
  53. package/i18n/skills/a2h-arch-generate/references/harmony-project-inspection.md +150 -0
  54. package/i18n/skills/a2h-arch-generate/references/harmony-target-architecture.md +94 -0
  55. package/i18n/skills/a2h-arch-generate/references/homegraph-workflow.md +120 -0
  56. package/i18n/skills/a2h-arch-generate/references/source-baseline.md +93 -0
  57. package/i18n/skills/a2h-arch-generate/scripts/generate_source_baseline.mjs +360 -0
  58. package/i18n/skills/a2h-arch-generate/scripts/inspect_harmony_target.mjs +798 -0
  59. package/i18n/skills/a2h-arch-generate/scripts/lib/contract_terms.mjs +40 -0
  60. package/i18n/skills/a2h-arch-generate/scripts/module_create/generate.mjs +639 -0
  61. package/i18n/skills/a2h-arch-generate/scripts/module_create/testdata/reconcile-layer-PROJECT_DESIGN.md +47 -0
  62. package/i18n/skills/a2h-arch-generate/scripts/module_create/testdata/single-entry-PROJECT_DESIGN.md +15 -0
  63. package/i18n/skills/a2h-arch-generate/scripts/module_create/testdata/three-layer-PROJECT_DESIGN.md +36 -0
  64. package/i18n/skills/a2h-arch-generate/scripts/module_create/testdata/verification-report.md +150 -0
  65. package/i18n/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/pages.json +5 -0
  66. package/i18n/skills/a2h-arch-generate/scripts/tests/e2e/run_e2e.mjs +548 -0
  67. package/i18n/skills/a2h-arch-generate/scripts/tests/run_tests.mjs +1261 -0
  68. package/i18n/skills/a2h-arch-generate/scripts/tests/test_module_templates.mjs +70 -0
  69. package/i18n/skills/a2h-arch-generate/scripts/validate_architecture_docs.mjs +851 -0
  70. package/i18n/skills/a2h-arch-generate/scripts/validate_data_docs.mjs +982 -0
  71. package/i18n/skills/a2h-arkts-logic-coder/references/ISSUES.md +9 -0
  72. package/i18n/skills/a2h-arkts-logic-coder/references/code-generation.md +192 -0
  73. package/i18n/skills/a2h-arkts-logic-coder/references/spec-design.md +303 -0
  74. package/i18n/skills/a2h-arkts-logic-coder/scripts/design/move_spec_technical_reference.mjs +162 -0
  75. package/i18n/skills/a2h-arkts-logic-coder/scripts/design/validate_spec_design_output.mjs +298 -0
  76. package/i18n/skills/a2h-arkts-logic-coder/scripts/state_doc.mjs +587 -0
  77. package/i18n/skills/a2h-arkts-logic-coder/scripts/test_check_units.ts +149 -0
  78. package/i18n/skills/a2h-arkts-logic-coder/test/golden/move_design.md +18 -0
  79. package/i18n/skills/a2h-arkts-logic-coder/test/golden/move_design_crlf.md +18 -0
  80. package/i18n/skills/a2h-arkts-logic-coder/test/golden/move_spec.md +7 -0
  81. package/i18n/skills/a2h-arkts-logic-coder/test/golden/validate_issue_file.md +12 -0
  82. package/i18n/skills/a2h-arkts-logic-coder/test/golden/validate_issues.json +57 -0
  83. package/i18n/skills/a2h-arkts-logic-coder/test/test_spec_design_scripts.mjs +547 -0
  84. package/i18n/skills/a2h-arkts-logic-coder/test/test_state_doc.mjs +352 -0
  85. package/i18n/skills/a2h-batch-ui-align/SKILL.md +323 -0
  86. package/i18n/skills/a2h-batch-ui-align/references/cards/alignment.md +31 -0
  87. package/i18n/skills/a2h-batch-ui-align/references/cards/build.md +13 -0
  88. package/i18n/skills/a2h-batch-ui-align/references/cards/canvas.md +17 -0
  89. package/i18n/skills/a2h-batch-ui-align/references/cards/dynamics.md +27 -0
  90. package/i18n/skills/a2h-batch-ui-align/references/cards/geometry.md +80 -0
  91. package/i18n/skills/a2h-batch-ui-align/references/cards/interaction.md +22 -0
  92. package/i18n/skills/a2h-batch-ui-align/references/cards/resources.md +87 -0
  93. package/i18n/skills/a2h-batch-ui-align/references/cards/state-v1.md +29 -0
  94. package/i18n/skills/a2h-batch-ui-align/references/cards/state.md +14 -0
  95. package/i18n/skills/a2h-batch-ui-align/references/cards/widgets.md +57 -0
  96. package/i18n/skills/a2h-batch-ui-align/references/cards/window.md +29 -0
  97. package/i18n/skills/a2h-batch-ui-align/references/checker-rules.md +705 -0
  98. package/i18n/skills/a2h-batch-ui-align/references/conversion-procedure.md +417 -0
  99. package/i18n/skills/a2h-batch-ui-align/references/incremental-scope.md +139 -0
  100. package/i18n/skills/a2h-batch-ui-align/references/lottie-integration.md +43 -0
  101. package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +2549 -0
  102. package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +560 -0
  103. package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +148 -0
  104. package/i18n/skills/a2h-batch-ui-align/references/state-mgmt/_decorator-quickref.md +220 -0
  105. package/i18n/skills/a2h-batch-ui-align/references/state-mgmt/_paradigm-selection.md +28 -0
  106. package/i18n/skills/a2h-batch-ui-align/references/step3-capture.md +216 -0
  107. package/i18n/skills/a2h-batch-ui-align/references/step4-prepare.md +203 -0
  108. package/i18n/skills/a2h-batch-ui-align/references/step5-convert.md +210 -0
  109. package/i18n/skills/a2h-batch-ui-align/scripts/android_parse_fast.ts +2005 -0
  110. package/i18n/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +1748 -0
  111. package/i18n/skills/a2h-batch-ui-align/scripts/databinding_analyzer_design.md +79 -0
  112. package/i18n/skills/a2h-batch-ui-align/scripts/detect_paradigm.mjs +245 -0
  113. package/i18n/skills/a2h-batch-ui-align/scripts/draw_coverage.mjs +264 -0
  114. package/i18n/skills/a2h-batch-ui-align/scripts/export_ui_info.mjs +1787 -0
  115. package/i18n/skills/a2h-batch-ui-align/scripts/gen_rule_docs.mjs +100 -0
  116. package/i18n/skills/a2h-batch-ui-align/scripts/generate_pages_json.mjs +612 -0
  117. package/i18n/skills/a2h-batch-ui-align/scripts/group_pack.mjs +1836 -0
  118. package/i18n/skills/a2h-batch-ui-align/scripts/image_probe.mjs +405 -0
  119. package/i18n/skills/a2h-batch-ui-align/scripts/measure_pack.ts +1406 -0
  120. package/i18n/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +1226 -0
  121. package/i18n/skills/a2h-batch-ui-align/scripts/shell_contract.mjs +1220 -0
  122. package/i18n/skills/a2h-batch-ui-align/scripts/state_doc.mjs +412 -0
  123. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/core/cli.ts +134 -0
  124. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/core/i18n.ts +18 -0
  125. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/main.ts +173 -0
  126. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/a11y.ts +629 -0
  127. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/android_immersive.ts +125 -0
  128. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/attr_chain.ts +67 -0
  129. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/block_comment_break.ts +64 -0
  130. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/blur_mirrored.ts +134 -0
  131. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/builder_call_sites.ts +242 -0
  132. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/builder_invokes_callback.ts +136 -0
  133. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/canvas.ts +255 -0
  134. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/color_string.ts +109 -0
  135. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/column_shrink.ts +154 -0
  136. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/constant_coordinate.ts +39 -0
  137. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/container_align.ts +140 -0
  138. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/entry_root_builtin.ts +69 -0
  139. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/entry_route.ts +114 -0
  140. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/fixed_size_safe_area.ts +103 -0
  141. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/format_string.ts +157 -0
  142. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/framework_dialog.ts +110 -0
  143. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/framework_picker.ts +115 -0
  144. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/layout_placement.ts +551 -0
  145. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/media_content.ts +138 -0
  146. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +374 -0
  147. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/offset_in_scroll.ts +163 -0
  148. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/orphan_component.ts +119 -0
  149. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/padding_in_size.ts +119 -0
  150. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/page_reachability.ts +94 -0
  151. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/path_commands_vp.ts +50 -0
  152. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/percent_height_in_scroll.ts +80 -0
  153. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/popup_menu.ts +137 -0
  154. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/r_template_string.ts +37 -0
  155. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/request_permission.ts +98 -0
  156. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/resource_as_string.ts +68 -0
  157. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/root_weight.ts +97 -0
  158. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/safe_area_clipping.ts +168 -0
  159. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/scroll_align.ts +75 -0
  160. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/scroll_delta.ts +178 -0
  161. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/sdk_api.ts +195 -0
  162. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/shared_chrome.ts +73 -0
  163. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/sheet_blur.ts +95 -0
  164. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/shell_content.ts +198 -0
  165. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/stack_occluding.ts +118 -0
  166. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/state_decorators.ts +73 -0
  167. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/state_name_shadows.ts +93 -0
  168. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/string_quote_leak.ts +73 -0
  169. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/surface_stroke.ts +50 -0
  170. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/theme_color.ts +123 -0
  171. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/track_getter.ts +132 -0
  172. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/wide_constant_width.ts +53 -0
  173. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/window_mode.ts +67 -0
  174. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_a11y.test.mjs +598 -0
  175. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_blur.test.mjs +217 -0
  176. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_builder_calls.test.mjs +323 -0
  177. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_fidelity.test.mjs +507 -0
  178. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_layout_placement.test.mjs +427 -0
  179. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_occlusion_offset_format.test.mjs +372 -0
  180. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_review_fixes.test.mjs +298 -0
  181. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_rules.test.mjs +365 -0
  182. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_scroll_padding_raster.test.mjs +262 -0
  183. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_weight_color.test.mjs +473 -0
  184. package/i18n/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set.test.mjs +560 -0
  185. package/i18n/skills/a2h-batch-ui-align/scripts/tests/draw_coverage.test.mjs +245 -0
  186. package/i18n/skills/a2h-batch-ui-align/scripts/tests/export_ui_info.test.mjs +742 -0
  187. package/i18n/skills/a2h-batch-ui-align/scripts/tests/generate_pages_json.test.mjs +123 -0
  188. package/i18n/skills/a2h-batch-ui-align/scripts/tests/group_pack.test.mjs +363 -0
  189. package/i18n/skills/a2h-batch-ui-align/scripts/tests/image_probe.test.mjs +243 -0
  190. package/i18n/skills/a2h-batch-ui-align/scripts/tests/measure_pack.test.mjs +324 -0
  191. package/i18n/skills/a2h-batch-ui-align/scripts/tests/occlusion.test.mjs +102 -0
  192. package/i18n/skills/a2h-batch-ui-align/scripts/tests/phase5_check.test.mjs +325 -0
  193. package/i18n/skills/a2h-batch-ui-align/scripts/tests/skill_doc_contract.test.mjs +48 -0
  194. package/i18n/skills/a2h-batch-ui-align/scripts/tests/state_doc.test.mjs +387 -0
  195. package/i18n/skills/a2h-batch-ui-align/scripts/tests/static_check_registry.test.mjs +122 -0
  196. package/i18n/skills/a2h-batch-ui-align/scripts/tests/text_color_diff.test.mjs +250 -0
  197. package/i18n/skills/a2h-batch-ui-align/scripts/text_color_diff.mjs +470 -0
  198. package/i18n/skills/a2h-coldstart-smoke-gate/SKILL.md +59 -0
  199. package/i18n/skills/a2h-dashboard-render/SKILL.md +73 -0
  200. package/i18n/skills/a2h-dashboard-render/references/artifact-contract.jsonc +117 -0
  201. package/i18n/skills/a2h-dashboard-render/references/artifact-registry-spec.md +67 -0
  202. package/i18n/skills/a2h-dashboard-render/references/dashboard-guide.md +91 -0
  203. package/i18n/skills/a2h-dashboard-render/references/dashboard.config.example.json +19 -0
  204. package/i18n/skills/a2h-dashboard-render/scripts/dashboard.mjs +3245 -0
  205. package/i18n/skills/a2h-dashboard-render/scripts/device_capture.mjs +2048 -0
  206. package/i18n/skills/a2h-dashboard-render/test/fixtures/page_capture/expected.json +156 -0
  207. package/i18n/skills/a2h-dashboard-render/test/fixtures/page_capture/hmos.json +1 -0
  208. package/i18n/skills/a2h-dashboard-render/test/fixtures/page_capture/list.xml +1 -0
  209. package/i18n/skills/a2h-dashboard-render/test/test_artifact_contract.mjs +168 -0
  210. package/i18n/skills/a2h-dashboard-render/test/test_dashboard_architecture.mjs +118 -0
  211. package/i18n/skills/a2h-dashboard-render/test/test_dashboard_build.mjs +93 -0
  212. package/i18n/skills/a2h-dashboard-render/test/test_dashboard_i18n.mjs +154 -0
  213. package/i18n/skills/a2h-dashboard-render/test/test_dashboard_node.mjs +1369 -0
  214. package/i18n/skills/a2h-dashboard-render/test/test_dashboard_spec_pipeline.mjs +318 -0
  215. package/i18n/skills/a2h-dashboard-render/test/test_dashboard_ui_pipeline.mjs +81 -0
  216. package/i18n/skills/a2h-dashboard-render/test/test_device_capture_env.mjs +115 -0
  217. package/i18n/skills/a2h-dashboard-render/test/test_device_capture_policy.mjs +411 -0
  218. package/i18n/skills/a2h-dashboard-render/test/test_page_capture.mjs +147 -0
  219. package/i18n/skills/a2h-dashboard-render/test/test_usage_readers.mjs +512 -0
  220. package/i18n/skills/a2h-fix-build-errors/SKILL.md +304 -0
  221. package/i18n/skills/a2h-fix-build-errors/references/arkts-strict-patterns.md +219 -0
  222. package/i18n/skills/a2h-fix-build-errors/references/rdb-entity-pattern.md +131 -0
  223. package/i18n/skills/a2h-module-semantic-docs/SKILL.md +227 -0
  224. package/i18n/skills/a2h-module-semantic-docs/test/golden/module_structure.json +187 -0
  225. package/i18n/skills/a2h-module-semantic-docs/test/golden/module_understanding.json +351 -0
  226. package/i18n/skills/a2h-module-semantic-docs/test/golden/module_update_plan.json +495 -0
  227. package/i18n/skills/a2h-module-semantic-docs/test/golden/project_directory_structure.json +157 -0
  228. package/i18n/skills/a2h-module-semantic-docs/test/test_scan_and_commit.mjs +388 -0
  229. package/i18n/skills/a2h-page-specgen/SKILL.md +136 -0
  230. package/i18n/skills/a2h-page-specgen/references/body-language.md +177 -0
  231. package/i18n/skills/a2h-page-specgen/references/gates.md +262 -0
  232. package/i18n/skills/a2h-page-specgen/references/page-inventory.md +173 -0
  233. package/i18n/skills/a2h-page-specgen/references/spec-template.md +207 -0
  234. package/i18n/skills/a2h-page-specgen/scripts/facts-build.mjs +1504 -0
  235. package/i18n/skills/a2h-page-specgen/scripts/footprint.mjs +1528 -0
  236. package/i18n/skills/a2h-page-specgen/scripts/gate.mjs +576 -0
  237. package/i18n/skills/a2h-page-specgen/scripts/interactions.mjs +138 -0
  238. package/i18n/skills/a2h-page-specgen/scripts/lib/contracts.mjs +262 -0
  239. package/i18n/skills/a2h-page-specgen/scripts/lib/hg.mjs +176 -0
  240. package/i18n/skills/a2h-page-specgen/scripts/lib/prose.mjs +248 -0
  241. package/i18n/skills/a2h-page-specgen/scripts/lib/reach.mjs +53 -0
  242. package/i18n/skills/a2h-page-specgen/scripts/prepare.mjs +506 -0
  243. package/i18n/skills/a2h-page-specgen/scripts/render.mjs +299 -0
  244. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/acceptance.mjs +616 -0
  245. package/i18n/skills/a2h-page-specgen/scripts/test/contracts.test.mjs +234 -0
  246. package/i18n/skills/a2h-page-specgen/scripts/test/facts.test.mjs +1166 -0
  247. package/i18n/skills/a2h-page-specgen/scripts/test/finalize.test.mjs +74 -0
  248. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/facts/i18n/zh.js.txt +8 -0
  249. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-b+zh+Hans/strings.xml +7 -0
  250. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-zh/strings.xml +8 -0
  251. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/utg/click_paths.json +28 -0
  252. package/i18n/skills/a2h-page-specgen/scripts/test/footprint-resolve.test.mjs +758 -0
  253. package/i18n/skills/a2h-page-specgen/scripts/test/fsx.test.mjs +32 -0
  254. package/i18n/skills/a2h-page-specgen/scripts/test/gate-partial.test.mjs +54 -0
  255. package/i18n/skills/a2h-page-specgen/scripts/test/gate.test.mjs +271 -0
  256. package/i18n/skills/a2h-page-specgen/scripts/test/helpers.mjs +54 -0
  257. package/i18n/skills/a2h-page-specgen/scripts/test/hg.test.mjs +171 -0
  258. package/i18n/skills/a2h-page-specgen/scripts/test/integration.test.mjs +301 -0
  259. package/i18n/skills/a2h-page-specgen/scripts/test/interactions.test.mjs +83 -0
  260. package/i18n/skills/a2h-page-specgen/scripts/test/inventory.test.mjs +139 -0
  261. package/i18n/skills/a2h-page-specgen/scripts/test/keys.test.mjs +774 -0
  262. package/i18n/skills/a2h-page-specgen/scripts/test/plan-build.test.mjs +1011 -0
  263. package/i18n/skills/a2h-page-specgen/scripts/test/prompt-tpl.test.mjs +77 -0
  264. package/i18n/skills/a2h-page-specgen/scripts/test/prose.test.mjs +419 -0
  265. package/i18n/skills/a2h-page-specgen/scripts/test/reach.test.mjs +93 -0
  266. package/i18n/skills/a2h-page-specgen/scripts/test/recovery-e2e.test.mjs +323 -0
  267. package/i18n/skills/a2h-page-specgen/scripts/test/recovery.test.mjs +546 -0
  268. package/i18n/skills/a2h-page-specgen/scripts/test/render.test.mjs +511 -0
  269. package/i18n/skills/a2h-page-specgen/scripts/test/submit.test.mjs +701 -0
  270. package/i18n/skills/a2h-page-specgen/scripts/test/utg-io.test.mjs +90 -0
  271. package/i18n/skills/a2h-page-specgen/scripts/test/waker-process.test.mjs +1765 -0
  272. package/i18n/skills/a2h-resource-convert/SKILL.md +367 -0
  273. package/i18n/skills/a2h-resource-convert/references/code-vector-icon-rules.md +335 -0
  274. package/i18n/skills/a2h-resource-convert/references/incremental-page-migration.md +251 -0
  275. package/i18n/skills/a2h-resource-convert/references/lottie-conversion-rules.md +219 -0
  276. package/i18n/skills/a2h-resource-convert/references/resource-mapping-rules.md +493 -0
  277. package/i18n/skills/a2h-resource-convert/references/step4-resource-types.md +249 -0
  278. package/i18n/skills/a2h-resource-convert/references/step7-report-template.md +217 -0
  279. package/i18n/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +2532 -0
  280. package/i18n/skills/a2h-resource-convert/scripts/tests/docs_only_i18n.test.mjs +44 -0
  281. package/i18n/skills/a2h-spec-design-pipeline/SKILL.md +278 -0
  282. package/i18n/skills/a2h-spec-design-pipeline/references/coding-loop.md +260 -0
  283. package/i18n/skills/a2h-spec-design-pipeline/references/merge-queue.md +163 -0
  284. package/i18n/skills/a2h-spec-design-pipeline/references/scripts.md +44 -0
  285. package/i18n/skills/a2h-spec-design-pipeline/references/specs.example.json +19 -0
  286. package/i18n/skills/a2h-spec-design-pipeline/scripts/plan_groups.ts +589 -0
  287. package/i18n/skills/a2h-spec-design-pipeline/scripts/test_plan_groups.ts +506 -0
  288. package/i18n/skills/a2h-spec-generate/SKILL.md +375 -0
  289. package/i18n/skills/a2h-spec-generate/references/batch-mode.md +215 -0
  290. package/i18n/skills/a2h-spec-generate/references/delete-blast-radius.md +3 -0
  291. package/i18n/skills/a2h-spec-generate/references/dispatch-watchdog.md +150 -0
  292. package/i18n/skills/a2h-spec-generate/references/fusion-task-contract.md +184 -0
  293. package/i18n/skills/a2h-spec-generate/references/input-formats.md +27 -0
  294. package/i18n/skills/a2h-spec-generate/references/library-evidence.md +3 -0
  295. package/i18n/skills/a2h-spec-generate/references/method-discipline.md +64 -0
  296. package/i18n/skills/a2h-spec-generate/references/optional-gates.json +45 -0
  297. package/i18n/skills/a2h-spec-generate/references/recall-guide.md +84 -0
  298. package/i18n/skills/a2h-spec-generate/references/recall-terse.md +3 -0
  299. package/i18n/skills/a2h-spec-generate/references/recall-uniapp.md +10 -0
  300. package/i18n/skills/a2h-spec-generate/references/requirement-scope.md +122 -0
  301. package/i18n/skills/a2h-spec-generate/references/review-checklist.md +22 -0
  302. package/i18n/skills/a2h-spec-generate/references/spec-sample-complex.md +80 -0
  303. package/i18n/skills/a2h-spec-generate/references/spec-sample-transfer.md +43 -0
  304. package/i18n/skills/a2h-spec-generate/references/spec-samples.md +65 -0
  305. package/i18n/skills/a2h-spec-generate/references/specs.schema.json +85 -0
  306. package/i18n/skills/a2h-spec-generate/references/synthesis-rules.md +145 -0
  307. package/i18n/skills/a2h-spec-generate/references/transfer-file.md +5 -0
  308. package/i18n/skills/a2h-spec-generate/references/transfer-socket.md +5 -0
  309. package/i18n/skills/a2h-spec-generate/references/worker-rules.md +129 -0
  310. package/i18n/skills/a2h-spec-generate/scripts/check-fused-spec.mjs +702 -0
  311. package/i18n/skills/a2h-spec-generate/scripts/check_spec.ts +515 -0
  312. package/i18n/skills/a2h-spec-generate/scripts/collect-specs.mjs +727 -0
  313. package/i18n/skills/a2h-spec-generate/scripts/feature-stem.mjs +151 -0
  314. package/i18n/skills/a2h-spec-generate/scripts/parse_requirements.ts +515 -0
  315. package/i18n/skills/a2h-spec-generate/scripts/prepare-facts.mjs +313 -0
  316. package/i18n/skills/a2h-spec-generate/scripts/publish-specs.mjs +354 -0
  317. package/i18n/skills/a2h-spec-generate/scripts/regroup-by-page.mjs +669 -0
  318. package/i18n/skills/a2h-spec-generate/scripts/render-tasks.mjs +385 -0
  319. package/i18n/skills/a2h-spec-generate/scripts/report.mjs +136 -0
  320. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/build.ts +2217 -0
  321. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/component-variants.ts +845 -0
  322. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/policy.ts +572 -0
  323. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/traceability.ts +580 -0
  324. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/analysis/req-model/build.ts +1265 -0
  325. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/area-facts.ts +1057 -0
  326. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/behavior-seed.ts +565 -0
  327. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/library-evidence.ts +544 -0
  328. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/navigation-guard.ts +363 -0
  329. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/schema.ts +317 -0
  330. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/selfcheck.ts +707 -0
  331. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/spec-bindings.ts +436 -0
  332. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/task-contract.ts +608 -0
  333. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/contracts.ts +650 -0
  334. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/task-contract.ts +178 -0
  335. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/tree-sitter-adapter.ts +923 -0
  336. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/model/finalize.ts +912 -0
  337. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/model/task.ts +279 -0
  338. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/requirement-scope.ts +163 -0
  339. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/source-index/homegraph.ts +1039 -0
  340. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/validation/req-text.ts +256 -0
  341. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fixtures/fusion-run.ts +243 -0
  342. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-area-facts.test.ts +576 -0
  343. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-detectors.test.ts +176 -0
  344. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-e2e.test.ts +103 -0
  345. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-schema.test.ts +111 -0
  346. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-selfcheck.test.ts +307 -0
  347. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-contract.test.ts +340 -0
  348. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-finalize.test.ts +1857 -0
  349. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-navigation-guard.test.ts +262 -0
  350. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-prepare.test.ts +722 -0
  351. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-scope.test.ts +339 -0
  352. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-selfcheck.test.ts +1253 -0
  353. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-spec.test.ts +608 -0
  354. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/model-scope.test.ts +411 -0
  355. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/model-task-contract.test.ts +300 -0
  356. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/model-v4.test.ts +1061 -0
  357. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/uniapp-scanner.test.ts +159 -0
  358. package/i18n/skills/a2h-spec-generate/template/REQ.txt +22 -0
  359. package/i18n/skills/a2h-spec-generate/template/REQ.xlsx +0 -0
  360. package/i18n/skills/a2h-spec-generate/test/check-fused-spec.test.mjs +847 -0
  361. package/i18n/skills/a2h-spec-generate/test/check-spec.test.ts +415 -0
  362. package/i18n/skills/a2h-spec-generate/test/collect-specs.test.mjs +808 -0
  363. package/i18n/skills/a2h-spec-generate/test/feature-stem.test.mjs +157 -0
  364. package/i18n/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/components/MyCard.vue +9 -0
  365. package/i18n/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/feature/editor/index.vue +1 -0
  366. package/i18n/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/detail/index.vue +1 -0
  367. package/i18n/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/home/index.vue +33 -0
  368. package/i18n/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/settings/index.vue +1 -0
  369. package/i18n/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages.json +23 -0
  370. package/i18n/skills/a2h-spec-generate/test/inspect-uniapp.test.mjs +54 -0
  371. package/i18n/skills/a2h-spec-generate/test/prepare-facts.test.mjs +41 -0
  372. package/i18n/skills/a2h-spec-generate/test/publish-specs.test.mjs +295 -0
  373. package/i18n/skills/a2h-spec-generate/test/regroup-by-page.test.mjs +354 -0
  374. package/i18n/skills/a2h-spec-generate/test/render-tasks.test.mjs +596 -0
  375. package/i18n/skills/a2h-spec-generate/test/report.test.mjs +47 -0
  376. package/i18n/skills/a2h-utg-explorer/SKILL.md +120 -0
  377. package/i18n/skills/a2h-utg-explorer/references/architecture.md +279 -0
  378. package/i18n/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +918 -0
  379. package/i18n/skills/a2h-utg-explorer/scripts/final_utg.mjs +446 -0
  380. package/i18n/skills/a2h-utg-explorer/scripts/hint_check.mjs +147 -0
  381. package/i18n/skills/a2h-utg-explorer/scripts/hint_source.mjs +119 -0
  382. package/i18n/skills/a2h-utg-explorer/scripts/recover_b.mjs +550 -0
  383. package/i18n/skills/a2h-utg-explorer/scripts/recover_d.mjs +380 -0
  384. package/i18n/skills/a2h-utg-explorer/scripts/tests/attest.test.mjs +66 -0
  385. package/i18n/skills/a2h-utg-explorer/scripts/tests/compose_identity.test.mjs +302 -0
  386. package/i18n/skills/a2h-utg-explorer/scripts/tests/content_wait.test.mjs +207 -0
  387. package/i18n/skills/a2h-utg-explorer/scripts/tests/direct_launch.test.mjs +130 -0
  388. package/i18n/skills/a2h-utg-explorer/scripts/tests/final_utg.test.mjs +135 -0
  389. package/i18n/skills/a2h-utg-explorer/scripts/tests/generalization_fixes.test.mjs +252 -0
  390. package/i18n/skills/a2h-utg-explorer/scripts/tests/hint_check.test.mjs +129 -0
  391. package/i18n/skills/a2h-utg-explorer/scripts/tests/interruptions.test.mjs +492 -0
  392. package/i18n/skills/a2h-utg-explorer/scripts/tests/launch_bridge.test.mjs +199 -0
  393. package/i18n/skills/a2h-utg-explorer/scripts/tests/overflow_prefix.test.mjs +327 -0
  394. package/i18n/skills/a2h-utg-explorer/scripts/tests/overlay_identity.test.mjs +204 -0
  395. package/i18n/skills/a2h-utg-explorer/scripts/tests/page_identity_tiers.test.mjs +393 -0
  396. package/i18n/skills/a2h-utg-explorer/scripts/tests/pager_navigation.test.mjs +119 -0
  397. package/i18n/skills/a2h-utg-explorer/scripts/tests/panel_routes.test.mjs +208 -0
  398. package/i18n/skills/a2h-utg-explorer/scripts/tests/pipeline.test.mjs +240 -0
  399. package/i18n/skills/a2h-utg-explorer/scripts/tests/recover_b.test.mjs +173 -0
  400. package/i18n/skills/a2h-utg-explorer/scripts/tests/recover_d.test.mjs +280 -0
  401. package/i18n/skills/a2h-utg-explorer/scripts/tests/robustness_fixes.test.mjs +345 -0
  402. package/i18n/skills/a2h-utg-explorer/scripts/tests/runner_capabilities.test.mjs +194 -0
  403. package/i18n/skills/a2h-utg-explorer/scripts/tests/semantics.test.mjs +102 -0
  404. package/i18n/skills/a2h-utg-explorer/scripts/tests/state_ambiguity.test.mjs +92 -0
  405. package/i18n/skills/a2h-utg-explorer/scripts/tests/twin_opener.test.mjs +119 -0
  406. package/i18n/skills/a2h-utg-explorer/scripts/tests/variant_strings.test.mjs +63 -0
  407. package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +1412 -0
  408. package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +2037 -0
  409. package/i18n/skills/a2h-utg-static/SKILL.md +368 -0
  410. package/i18n/skills/a2h-utg-static/references/ui-elements-static-utg-schema.md +248 -0
  411. package/i18n/skills/a2h-utg-static/references/view-interactions.md +215 -0
  412. package/i18n/skills/a2h-utg-static/scripts/assemble.mjs +2120 -0
  413. package/i18n/skills/a2h-utg-static/scripts/audit.mjs +268 -0
  414. package/i18n/skills/a2h-utg-static/scripts/click_paths.mjs +609 -0
  415. package/i18n/skills/a2h-utg-static/scripts/compose_body_text.mjs +250 -0
  416. package/i18n/skills/a2h-utg-static/scripts/compose_titles.mjs +374 -0
  417. package/i18n/skills/a2h-utg-static/scripts/compose_widgets.mjs +498 -0
  418. package/i18n/skills/a2h-utg-static/scripts/fragment_nav.mjs +1137 -0
  419. package/i18n/skills/a2h-utg-static/scripts/hybrid_scope.mjs +660 -0
  420. package/i18n/skills/a2h-utg-static/scripts/interaction_sites.mjs +267 -0
  421. package/i18n/skills/a2h-utg-static/scripts/label_resolve.mjs +913 -0
  422. package/i18n/skills/a2h-utg-static/scripts/nl_hints.mjs +517 -0
  423. package/i18n/skills/a2h-utg-static/scripts/presenter_nav.mjs +490 -0
  424. package/i18n/skills/a2h-utg-static/scripts/static_prior.mjs +956 -0
  425. package/i18n/skills/a2h-utg-static/scripts/tests/regression_matrix.mjs +1261 -0
  426. package/i18n/skills/a2h-utg-static/scripts/tests/test_callee_string_default.mjs +30 -0
  427. package/i18n/skills/a2h-utg-static/scripts/tests/test_chrome_tokens.mjs +60 -0
  428. package/i18n/skills/a2h-utg-static/scripts/tests/test_commented_out_trigger.mjs +111 -0
  429. package/i18n/skills/a2h-utg-static/scripts/tests/test_compose_res_text.mjs +108 -0
  430. package/i18n/skills/a2h-utg-static/scripts/tests/test_compose_vm_nav.mjs +289 -0
  431. package/i18n/skills/a2h-utg-static/scripts/tests/test_disabled_guard.mjs +42 -0
  432. package/i18n/skills/a2h-utg-static/scripts/tests/test_drawer_panel_gesture.mjs +140 -0
  433. package/i18n/skills/a2h-utg-static/scripts/tests/test_fresh_branch_guard.mjs +49 -0
  434. package/i18n/skills/a2h-utg-static/scripts/tests/test_hint_language.mjs +136 -0
  435. package/i18n/skills/a2h-utg-static/scripts/tests/test_hybrid_bundle_attribution.mjs +74 -0
  436. package/i18n/skills/a2h-utg-static/scripts/tests/test_hybrid_bundled_pages.mjs +181 -0
  437. package/i18n/skills/a2h-utg-static/scripts/tests/test_hybrid_scope.mjs +293 -0
  438. package/i18n/skills/a2h-utg-static/scripts/tests/test_hybrid_title_renders.mjs +118 -0
  439. package/i18n/skills/a2h-utg-static/scripts/tests/test_label_accessor_forms.mjs +187 -0
  440. package/i18n/skills/a2h-utg-static/scripts/tests/test_label_source.mjs +70 -0
  441. package/i18n/skills/a2h-utg-static/scripts/tests/test_launch_intent_guard.mjs +67 -0
  442. package/i18n/skills/a2h-utg-static/scripts/tests/test_login_interceptor.mjs +368 -0
  443. package/i18n/skills/a2h-utg-static/scripts/tests/test_mode_and_cb_param.mjs +172 -0
  444. package/i18n/skills/a2h-utg-static/scripts/tests/test_module_strings.mjs +44 -0
  445. package/i18n/skills/a2h-utg-static/scripts/tests/test_nl_hint_grammar.mjs +42 -0
  446. package/i18n/skills/a2h-utg-static/scripts/tests/test_nl_hints_gate.mjs +85 -0
  447. package/i18n/skills/a2h-utg-static/scripts/tests/test_nl_hints_off_path.mjs +67 -0
  448. package/i18n/skills/a2h-utg-static/scripts/tests/test_non_gesture_step_flag.mjs +62 -0
  449. package/i18n/skills/a2h-utg-static/scripts/tests/test_preference_widgets.mjs +48 -0
  450. package/i18n/skills/a2h-utg-static/scripts/tests/test_read_text_crlf.mjs +41 -0
  451. package/i18n/skills/a2h-utg-static/scripts/tests/test_sealed_dialog_state.mjs +148 -0
  452. package/i18n/skills/a2h-utg-static/scripts/tests/test_state_specific_hop.mjs +130 -0
  453. package/i18n/skills/a2h-utg-static/scripts/tests/test_synthetic_label_identity.mjs +51 -0
  454. package/i18n/skills/a2h-utg-static/scripts/tests/test_template_title.mjs +61 -0
  455. package/i18n/skills/a2h-utg-static/scripts/tests/test_ui_elements_flow_filter.mjs +110 -0
  456. package/i18n/skills/a2h-utg-static/scripts/tests/test_uniapp_data_table.mjs +340 -0
  457. package/i18n/skills/a2h-utg-static/scripts/tests/test_uniapp_relative_url.mjs +125 -0
  458. package/i18n/skills/a2h-utg-static/scripts/tests/test_uniapp_source.mjs +231 -0
  459. package/i18n/skills/a2h-utg-static/scripts/tests/test_viewpage_nav.mjs +340 -0
  460. package/i18n/skills/a2h-utg-static/scripts/uniapp_nav.mjs +1351 -0
  461. package/i18n/skills/a2h-utg-static/scripts/uniapp_widgets.mjs +244 -0
  462. package/i18n/skills/a2h-utg-static/tools/convert_static_utg_to_ui_elements.ts +769 -0
  463. package/package.json +13 -160
  464. package/platforms/deveco/agents/code-reviewer.frontmatter.md +1 -1
  465. package/platforms/opencode/agents/code-reviewer.frontmatter.md +1 -1
  466. package/skills/a2h-app-migrate/SKILL.md +17 -6
  467. package/skills/a2h-app-migrate/references/config.example.json +1 -0
  468. package/skills/a2h-app-migrate/references/stage-map.md +3 -1
  469. package/skills/a2h-app-migrate/references/workflow.yaml +138 -47
  470. package/skills/a2h-app-migrate/scripts/check_spec_gen_done.mjs +1 -2
  471. package/skills/a2h-app-migrate/scripts/env_preflight.mjs +105 -39
  472. package/skills/a2h-app-migrate/scripts/human_review_gate.mjs +7 -8
  473. package/skills/a2h-app-migrate/scripts/ledger.mjs +17 -5
  474. package/skills/a2h-app-migrate/scripts/resume_plan.mjs +43 -7
  475. package/skills/a2h-app-migrate/scripts/run_dir.mjs +127 -41
  476. package/skills/a2h-app-migrate/scripts/spec_layout.mjs +2 -0
  477. package/skills/a2h-app-migrate/scripts/validate_workflow.mjs +38 -0
  478. package/skills/a2h-app-migrate/test/test_android_index.mjs +131 -0
  479. package/skills/a2h-app-migrate/test/test_apk_preflight.mjs +63 -0
  480. package/skills/a2h-app-migrate/test/test_arch_done.mjs +54 -0
  481. package/skills/a2h-app-migrate/test/test_build_fixer_contract.mjs +98 -0
  482. package/skills/a2h-app-migrate/test/test_config_example.mjs +42 -0
  483. package/skills/a2h-app-migrate/test/test_devecocli_docs_preflight.mjs +32 -0
  484. package/skills/a2h-app-migrate/test/test_ensure_utg_snapshot.mjs +147 -0
  485. package/skills/a2h-app-migrate/test/test_entry_guards.mjs +102 -0
  486. package/skills/a2h-app-migrate/test/test_env_requirements.mjs +698 -0
  487. package/skills/a2h-app-migrate/test/test_finalize.mjs +89 -0
  488. package/skills/a2h-app-migrate/test/test_gate_checkpoint.mjs +146 -0
  489. package/skills/a2h-app-migrate/test/test_hmos_fingerprint.mjs +68 -0
  490. package/skills/a2h-app-migrate/test/test_i18n_engine_mirror.mjs +51 -0
  491. package/skills/a2h-app-migrate/test/test_image_probe.mjs +120 -0
  492. package/skills/a2h-app-migrate/test/test_infer_android_root.mjs +91 -0
  493. package/skills/a2h-app-migrate/test/test_interaction.mjs +122 -0
  494. package/skills/a2h-app-migrate/test/test_json_io.mjs +32 -0
  495. package/skills/a2h-app-migrate/test/test_leaf_questions.mjs +111 -0
  496. package/skills/a2h-app-migrate/test/test_module_docs_done.mjs +53 -0
  497. package/skills/a2h-app-migrate/test/test_parse_args.mjs +69 -0
  498. package/skills/a2h-app-migrate/test/test_preflight_report.mjs +93 -0
  499. package/skills/a2h-app-migrate/test/test_resume_plan.mjs +219 -0
  500. package/skills/a2h-app-migrate/test/test_resume_summary.mjs +196 -0
  501. package/skills/a2h-app-migrate/test/test_reuse_static_utg.mjs +100 -0
  502. package/skills/a2h-app-migrate/test/test_run_dir.mjs +488 -0
  503. package/skills/a2h-app-migrate/test/test_skill_doc.mjs +144 -0
  504. package/skills/a2h-app-migrate/test/test_spec_engine_acceptance.mjs +94 -0
  505. package/skills/a2h-app-migrate/test/test_spec_engine_contract.mjs +147 -0
  506. package/skills/a2h-app-migrate/test/test_spec_gen_done.mjs +146 -0
  507. package/skills/a2h-app-migrate/test/test_spec_gen_gate.mjs +161 -0
  508. package/skills/a2h-app-migrate/test/test_spec_pipeline_done.mjs +344 -0
  509. package/skills/a2h-app-migrate/test/test_specs_json_preflight.mjs +76 -0
  510. package/skills/a2h-app-migrate/test/test_ui_batch_done.mjs +53 -0
  511. package/skills/a2h-app-migrate/test/test_ui_batch_gate.mjs +226 -0
  512. package/skills/a2h-app-migrate/test/test_uniapp_preflight.mjs +83 -0
  513. package/skills/a2h-app-migrate/test/test_user_facing_progress.mjs +43 -0
  514. package/skills/a2h-app-migrate/test/test_utg_dirs.mjs +41 -0
  515. package/skills/a2h-app-migrate/test/test_utg_static_done.mjs +178 -0
  516. package/skills/a2h-app-migrate/test/test_validate_races.mjs +50 -0
  517. package/skills/a2h-app-migrate/test/test_validate_workflow_bilingual.mjs +87 -0
  518. package/skills/a2h-arch-generate/SKILL.md +1 -1
  519. package/skills/a2h-arch-generate/references/database-schema-recovery.md +2 -2
  520. package/skills/a2h-arch-generate/references/harmony-project-inspection.md +8 -8
  521. package/skills/a2h-arch-generate/references/homegraph-workflow.md +15 -6
  522. package/skills/a2h-arch-generate/references/module-evidence-subagent.md +2 -2
  523. package/skills/a2h-arch-generate/references/source-baseline.md +2 -2
  524. package/skills/a2h-arch-generate/scripts/generate_source_baseline.mjs +35 -46
  525. package/skills/a2h-arch-generate/scripts/inspect_harmony_target.mjs +33 -40
  526. package/skills/a2h-arch-generate/scripts/module_create/generate.mjs +2 -3
  527. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/build.gradle +11 -0
  528. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/src/main/AndroidManifest.xml +12 -0
  529. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/src/main/java/com/example/notes/MainActivity.kt +8 -0
  530. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/src/main/java/com/example/notes/NotesStore.kt +17 -0
  531. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/build.gradle +3 -0
  532. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/settings.gradle +1 -0
  533. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/AppScope/app.json5 +8 -0
  534. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/build-profile.json5 +14 -0
  535. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/common/utils/build-profile.json5 +7 -0
  536. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/common/utils/oh-package.json5 +1 -0
  537. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/common/utils/src/main/ets/utils/Format.ets +3 -0
  538. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/home/build-profile.json5 +7 -0
  539. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/home/oh-package.json5 +1 -0
  540. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/home/src/main/ets/pages/Home.ets +3 -0
  541. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/sync/build-profile.json5 +7 -0
  542. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/sync/oh-package.json5 +1 -0
  543. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/sync/src/main/ets/engine/SyncEngine.ets +3 -0
  544. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/hvigorfile.ts +1 -0
  545. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/oh-package.json5 +1 -0
  546. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/products/app/build-profile.json5 +7 -0
  547. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/products/app/oh-package.json5 +9 -0
  548. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/products/app/src/main/ets/pages/Index.ets +7 -0
  549. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/App.vue +10 -0
  550. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/manifest.json +6 -0
  551. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/pages/index/index.vue +16 -0
  552. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/pages.json +5 -0
  553. package/skills/a2h-arch-generate/scripts/tests/e2e/run_e2e.mjs +548 -0
  554. package/skills/a2h-arch-generate/scripts/tests/run_tests.mjs +1260 -0
  555. package/skills/a2h-arch-generate/scripts/tests/test_cleanup.mjs +191 -0
  556. package/skills/a2h-arch-generate/scripts/tests/test_console_encoding.mjs +52 -0
  557. package/skills/a2h-arch-generate/scripts/tests/test_git_root.mjs +34 -0
  558. package/skills/a2h-arch-generate/scripts/tests/test_module_templates.mjs +70 -0
  559. package/skills/a2h-arch-generate/scripts/tests/test_router.mjs +138 -0
  560. package/skills/a2h-arch-generate/scripts/validate_architecture_docs.mjs +2 -5
  561. package/skills/a2h-arkts-logic-coder/SKILL.md +21 -2
  562. package/skills/a2h-arkts-logic-coder/references/ISSUES.md +1 -0
  563. package/skills/a2h-arkts-logic-coder/references/code-generation.md +62 -0
  564. package/skills/a2h-arkts-logic-coder/references/spec-design.md +4 -0
  565. package/skills/a2h-arkts-logic-coder/scripts/design/validate_spec_design_output.mjs +22 -25
  566. package/skills/a2h-arkts-logic-coder/scripts/state_doc.mjs +583 -0
  567. package/skills/a2h-arkts-logic-coder/test/golden/inspect_happy.json +20 -0
  568. package/skills/a2h-arkts-logic-coder/test/golden/move_design.md +18 -0
  569. package/skills/a2h-arkts-logic-coder/test/golden/move_design_crlf.md +18 -0
  570. package/skills/a2h-arkts-logic-coder/test/golden/move_spec.md +7 -0
  571. package/skills/a2h-arkts-logic-coder/test/golden/resolve_cases.json +36 -0
  572. package/skills/a2h-arkts-logic-coder/test/golden/validate_issue_file.md +12 -0
  573. package/skills/a2h-arkts-logic-coder/test/golden/validate_issues.json +57 -0
  574. package/skills/a2h-arkts-logic-coder/test/test_spec_design_scripts.mjs +547 -0
  575. package/skills/a2h-arkts-logic-coder/test/test_state_doc.mjs +352 -0
  576. package/skills/a2h-batch-ui-align/SKILL.md +6 -4
  577. package/skills/a2h-batch-ui-align/references/cards/geometry.md +1 -1
  578. package/skills/a2h-batch-ui-align/references/cards/resources.md +4 -0
  579. package/skills/a2h-batch-ui-align/references/cards/widgets.md +22 -3
  580. package/skills/a2h-batch-ui-align/references/checker-rules.md +66 -3
  581. package/skills/a2h-batch-ui-align/references/conversion-procedure.md +45 -8
  582. package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +7 -5
  583. package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +2 -2
  584. package/skills/a2h-batch-ui-align/references/step4-prepare.md +4 -2
  585. package/skills/a2h-batch-ui-align/references/step5-convert.md +7 -5
  586. package/skills/a2h-batch-ui-align/scripts/android_parse_fast.ts +6 -7
  587. package/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +84 -7
  588. package/skills/a2h-batch-ui-align/scripts/draw_coverage.mjs +264 -0
  589. package/skills/a2h-batch-ui-align/scripts/evidence_gate.mjs +229 -0
  590. package/skills/a2h-batch-ui-align/scripts/export_ui_info.mjs +1 -2
  591. package/skills/a2h-batch-ui-align/scripts/generate_pages_json.mjs +4 -5
  592. package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +88 -26
  593. package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +305 -12
  594. package/skills/a2h-batch-ui-align/scripts/image_probe.mjs +231 -54
  595. package/skills/a2h-batch-ui-align/scripts/measure_pack.ts +8 -9
  596. package/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +18 -5
  597. package/skills/a2h-batch-ui-align/scripts/shell_contract.mjs +103 -3
  598. package/skills/a2h-batch-ui-align/scripts/static_check/core/android.ts +231 -0
  599. package/skills/a2h-batch-ui-align/scripts/static_check/core/i18n.ts +1 -5
  600. package/skills/a2h-batch-ui-align/scripts/static_check/main.ts +14 -8
  601. package/skills/a2h-batch-ui-align/scripts/static_check/registry.ts +8 -0
  602. package/skills/a2h-batch-ui-align/scripts/static_check/rules/android_immersive.ts +3 -3
  603. package/skills/a2h-batch-ui-align/scripts/static_check/rules/blur_mirrored.ts +2 -2
  604. package/skills/a2h-batch-ui-align/scripts/static_check/rules/builder_invokes_callback.ts +84 -19
  605. package/skills/a2h-batch-ui-align/scripts/static_check/rules/color_string.ts +11 -4
  606. package/skills/a2h-batch-ui-align/scripts/static_check/rules/constant_coordinate.ts +2 -2
  607. package/skills/a2h-batch-ui-align/scripts/static_check/rules/framework_dialog.ts +110 -0
  608. package/skills/a2h-batch-ui-align/scripts/static_check/rules/framework_picker.ts +5 -5
  609. package/skills/a2h-batch-ui-align/scripts/static_check/rules/media_content.ts +2 -2
  610. package/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +66 -2
  611. package/skills/a2h-batch-ui-align/scripts/static_check/rules/padding_in_size.ts +119 -0
  612. package/skills/a2h-batch-ui-align/scripts/static_check/rules/popup_menu.ts +81 -8
  613. package/skills/a2h-batch-ui-align/scripts/static_check/rules/scroll_delta.ts +178 -0
  614. package/skills/a2h-batch-ui-align/scripts/static_check/rules/theme_color.ts +123 -0
  615. package/skills/a2h-batch-ui-align/scripts/static_check/rules/window_mode.ts +2 -3
  616. package/skills/a2h-batch-ui-align/scripts/static_check/scan_file.ts +6 -0
  617. package/skills/a2h-batch-ui-align/scripts/tests/agent_cli.test.mjs +217 -0
  618. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_a11y.test.mjs +598 -0
  619. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_align_tint.test.mjs +312 -0
  620. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_blur.test.mjs +217 -0
  621. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_builder_calls.test.mjs +323 -0
  622. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_canvas_pct.test.mjs +312 -0
  623. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_fidelity.test.mjs +507 -0
  624. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_layout_placement.test.mjs +427 -0
  625. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_occlusion_offset_format.test.mjs +372 -0
  626. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_review_fixes.test.mjs +298 -0
  627. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_rule_smoke.test.mjs +235 -0
  628. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_rules.test.mjs +365 -0
  629. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_scroll_padding_raster.test.mjs +262 -0
  630. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_scroll_safearea.test.mjs +742 -0
  631. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_shell.test.mjs +91 -0
  632. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_theme.test.mjs +86 -0
  633. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_weight_color.test.mjs +473 -0
  634. package/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set.test.mjs +567 -0
  635. package/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set_scope.test.mjs +290 -0
  636. package/skills/a2h-batch-ui-align/scripts/tests/color_utils_asset.test.mjs +74 -0
  637. package/skills/a2h-batch-ui-align/scripts/tests/detect_paradigm.test.mjs +260 -0
  638. package/skills/a2h-batch-ui-align/scripts/tests/draw_coverage.test.mjs +244 -0
  639. package/skills/a2h-batch-ui-align/scripts/tests/evidence_gate.test.mjs +420 -0
  640. package/skills/a2h-batch-ui-align/scripts/tests/export_scroll_states.test.mjs +31 -0
  641. package/skills/a2h-batch-ui-align/scripts/tests/export_ui_info.test.mjs +742 -0
  642. package/skills/a2h-batch-ui-align/scripts/tests/generate_pages_json.test.mjs +123 -0
  643. package/skills/a2h-batch-ui-align/scripts/tests/group_commit.test.mjs +126 -0
  644. package/skills/a2h-batch-ui-align/scripts/tests/group_pack.test.mjs +363 -0
  645. package/skills/a2h-batch-ui-align/scripts/tests/group_queue.test.mjs +1628 -0
  646. package/skills/a2h-batch-ui-align/scripts/tests/group_watch.test.mjs +215 -0
  647. package/skills/a2h-batch-ui-align/scripts/tests/harmony_index.test.mjs +95 -0
  648. package/skills/a2h-batch-ui-align/scripts/tests/host_env.test.mjs +115 -0
  649. package/skills/a2h-batch-ui-align/scripts/tests/image_probe.test.mjs +243 -0
  650. package/skills/a2h-batch-ui-align/scripts/tests/measure_pack.test.mjs +324 -0
  651. package/skills/a2h-batch-ui-align/scripts/tests/occlusion.test.mjs +102 -0
  652. package/skills/a2h-batch-ui-align/scripts/tests/phase5_check.test.mjs +325 -0
  653. package/skills/a2h-batch-ui-align/scripts/tests/shell_contract.test.mjs +297 -0
  654. package/skills/a2h-batch-ui-align/scripts/tests/skill_doc_contract.test.mjs +48 -0
  655. package/skills/a2h-batch-ui-align/scripts/tests/state_doc.test.mjs +387 -0
  656. package/skills/a2h-batch-ui-align/scripts/tests/static_check_registry.test.mjs +122 -0
  657. package/skills/a2h-batch-ui-align/scripts/tests/test_bfs_exit.ts +49 -0
  658. package/skills/a2h-batch-ui-align/scripts/tests/text_color_diff.test.mjs +250 -0
  659. package/skills/a2h-dashboard-render/scripts/dashboard.mjs +12 -14
  660. package/skills/a2h-dashboard-render/scripts/device_capture.mjs +29 -30
  661. package/skills/a2h-dashboard-render/test/fixtures/page_capture/broken.xml +1 -0
  662. package/skills/a2h-dashboard-render/test/fixtures/page_capture/expected.json +156 -0
  663. package/skills/a2h-dashboard-render/test/fixtures/page_capture/hmos.json +1 -0
  664. package/skills/a2h-dashboard-render/test/fixtures/page_capture/list.xml +1 -0
  665. package/skills/a2h-dashboard-render/test/fixtures/page_capture/nested_scroll.xml +1 -0
  666. package/skills/a2h-dashboard-render/test/test_artifact_contract.mjs +168 -0
  667. package/skills/a2h-dashboard-render/test/test_cli_check_registry.mjs +99 -0
  668. package/skills/a2h-dashboard-render/test/test_dashboard_architecture.mjs +118 -0
  669. package/skills/a2h-dashboard-render/test/test_dashboard_build.mjs +93 -0
  670. package/skills/a2h-dashboard-render/test/test_dashboard_i18n.mjs +203 -0
  671. package/skills/a2h-dashboard-render/test/test_dashboard_node.mjs +1369 -0
  672. package/skills/a2h-dashboard-render/test/test_dashboard_spec_pipeline.mjs +318 -0
  673. package/skills/a2h-dashboard-render/test/test_dashboard_ui_pipeline.mjs +81 -0
  674. package/skills/a2h-dashboard-render/test/test_device_capture_env.mjs +115 -0
  675. package/skills/a2h-dashboard-render/test/test_device_capture_policy.mjs +411 -0
  676. package/skills/a2h-dashboard-render/test/test_page_capture.mjs +147 -0
  677. package/skills/a2h-dashboard-render/test/test_usage_readers.mjs +512 -0
  678. package/skills/a2h-module-semantic-docs/test/golden/module_structure.json +187 -0
  679. package/skills/a2h-module-semantic-docs/test/golden/module_understanding.json +351 -0
  680. package/skills/a2h-module-semantic-docs/test/golden/module_update_plan.json +495 -0
  681. package/skills/a2h-module-semantic-docs/test/golden/project_directory_structure.json +157 -0
  682. package/skills/a2h-module-semantic-docs/test/test_scan_and_commit.mjs +388 -0
  683. package/skills/a2h-page-specgen/SKILL.md +136 -0
  684. package/skills/a2h-page-specgen/references/body-language.md +177 -0
  685. package/skills/a2h-page-specgen/references/evidence.md +70 -0
  686. package/skills/a2h-page-specgen/references/execution-model.md +255 -0
  687. package/skills/a2h-page-specgen/references/footprint-and-grouping.md +250 -0
  688. package/skills/a2h-page-specgen/references/gates.md +255 -0
  689. package/skills/a2h-page-specgen/references/page-inventory.md +173 -0
  690. package/skills/a2h-page-specgen/references/spec-template.md +207 -0
  691. package/skills/a2h-page-specgen/scripts/dispatch.mjs +209 -0
  692. package/skills/a2h-page-specgen/scripts/facts-build.mjs +1504 -0
  693. package/skills/a2h-page-specgen/scripts/finalize.mjs +422 -0
  694. package/skills/a2h-page-specgen/scripts/footprint.mjs +1528 -0
  695. package/skills/a2h-page-specgen/scripts/gate.mjs +558 -0
  696. package/skills/a2h-page-specgen/scripts/interactions.mjs +137 -0
  697. package/skills/a2h-page-specgen/scripts/inventory.mjs +269 -0
  698. package/skills/a2h-page-specgen/scripts/lib/contracts.mjs +255 -0
  699. package/skills/a2h-page-specgen/scripts/lib/deps-source.mjs +399 -0
  700. package/skills/a2h-page-specgen/scripts/lib/draft-store.mjs +137 -0
  701. package/skills/a2h-page-specgen/scripts/lib/footprint-roles.mjs +278 -0
  702. package/skills/a2h-page-specgen/scripts/lib/fsx.mjs +79 -0
  703. package/skills/a2h-page-specgen/scripts/lib/hg.mjs +175 -0
  704. package/skills/a2h-page-specgen/scripts/lib/ledger.mjs +355 -0
  705. package/skills/a2h-page-specgen/scripts/lib/prose.mjs +234 -0
  706. package/skills/a2h-page-specgen/scripts/lib/reach.mjs +53 -0
  707. package/skills/a2h-page-specgen/scripts/lib/source-text.mjs +391 -0
  708. package/skills/a2h-page-specgen/scripts/lib/symbols.mjs +125 -0
  709. package/skills/a2h-page-specgen/scripts/lib/utg-io.mjs +110 -0
  710. package/skills/a2h-page-specgen/scripts/lib/waker-event-store.mjs +658 -0
  711. package/skills/a2h-page-specgen/scripts/prepare.mjs +492 -0
  712. package/skills/a2h-page-specgen/scripts/render.mjs +317 -0
  713. package/skills/a2h-page-specgen/scripts/report.mjs +7 -0
  714. package/skills/a2h-page-specgen/scripts/submission.mjs +532 -0
  715. package/skills/a2h-page-specgen/scripts/submit.mjs +79 -0
  716. package/skills/a2h-page-specgen/scripts/test/acceptance/README.md +77 -0
  717. package/skills/a2h-page-specgen/scripts/test/acceptance/acceptance.mjs +590 -0
  718. package/skills/a2h-page-specgen/scripts/test/acceptance/cases.example.json +57 -0
  719. package/skills/a2h-page-specgen/scripts/test/contracts.test.mjs +207 -0
  720. package/skills/a2h-page-specgen/scripts/test/dispatch.test.mjs +258 -0
  721. package/skills/a2h-page-specgen/scripts/test/facts.test.mjs +1164 -0
  722. package/skills/a2h-page-specgen/scripts/test/finalize.test.mjs +74 -0
  723. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Api.kt +20 -0
  724. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/BothAnnotations.kt +28 -0
  725. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Cache.kt +7 -0
  726. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Comments.kt +26 -0
  727. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Mmkv.kt +7 -0
  728. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Models.kt +19 -0
  729. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Pair.kt +7 -0
  730. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Prefs.kt +9 -0
  731. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Room.kt +11 -0
  732. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Sample.kt +43 -0
  733. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Templates.kt +34 -0
  734. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/Timeouts.kt +8 -0
  735. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/androidTest/Helper.kt +5 -0
  736. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/build.gradle.kts +16 -0
  737. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/i18n/en.js.txt +5 -0
  738. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/i18n/zh.js.txt +4 -0
  739. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/libs.versions.toml +14 -0
  740. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/package.json +10 -0
  741. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values/strings.xml +10 -0
  742. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-b+zh+Hans/strings.xml +4 -0
  743. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-land/strings.xml +5 -0
  744. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-night/strings.xml +5 -0
  745. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-v21/strings.xml +4 -0
  746. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/res/values-zh/strings.xml +4 -0
  747. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/test/Legacy.kt +4 -0
  748. package/skills/a2h-page-specgen/scripts/test/fixtures/facts/weather.proto +11 -0
  749. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-container/src/AppPreferences.kt +13 -0
  750. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-container/src/SettingsViewModel.kt +16 -0
  751. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-dao/src/UserDao.kt +28 -0
  752. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-moko/i18n/src/commonMain/moko-resources/base/strings.xml +6 -0
  753. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-moko/i18n/src/commonMain/moko-resources/fil/strings.xml +6 -0
  754. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/res/values/arrays.xml +25 -0
  755. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/res/values/strings.xml +10 -0
  756. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/res/xml/prefs.xml +27 -0
  757. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/src/Api.java +19 -0
  758. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/src/Datastore.kt +12 -0
  759. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/src/Settings.java +13 -0
  760. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/src/forecast.js +14 -0
  761. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-pref/src/store.js +14 -0
  762. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-receiver/src/BasePreferences.kt +13 -0
  763. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-receiver/src/Screen.kt +14 -0
  764. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-receiver/src/UiPreferences.kt +8 -0
  765. package/skills/a2h-page-specgen/scripts/test/fixtures/facts-retrofit/src/AuthAPI.kt +26 -0
  766. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/AndroidManifest.xml +20 -0
  767. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/feature/auth/navigation/ScreenRoute.kt +8 -0
  768. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/pages.json +19 -0
  769. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/src/components/Widget.vue +11 -0
  770. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/src/pages/detail/detail.vue +14 -0
  771. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/src/pages/index/index.vue +24 -0
  772. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/src/store/userStore.js +11 -0
  773. package/skills/a2h-page-specgen/scripts/test/fixtures/fp/src/uni_modules/uview-ui/components/u-thing.js +5 -0
  774. package/skills/a2h-page-specgen/scripts/test/fixtures/fp.mkdb.mjs +144 -0
  775. package/skills/a2h-page-specgen/scripts/test/fixtures/hg.mkdb.mjs +94 -0
  776. package/skills/a2h-page-specgen/scripts/test/fixtures/src/MainFragment.java +6 -0
  777. package/skills/a2h-page-specgen/scripts/test/fixtures/src/ManyListeners.java +12 -0
  778. package/skills/a2h-page-specgen/scripts/test/fixtures/src/PlainActivity.java +3 -0
  779. package/skills/a2h-page-specgen/scripts/test/fixtures/utg/click_paths.json +28 -0
  780. package/skills/a2h-page-specgen/scripts/test/fixtures/utg/fold-chain/utg.json +12 -0
  781. package/skills/a2h-page-specgen/scripts/test/fixtures/utg/utg.json +34 -0
  782. package/skills/a2h-page-specgen/scripts/test/footprint-resolve.test.mjs +758 -0
  783. package/skills/a2h-page-specgen/scripts/test/footprint-roles.test.mjs +172 -0
  784. package/skills/a2h-page-specgen/scripts/test/fsx.test.mjs +32 -0
  785. package/skills/a2h-page-specgen/scripts/test/gate-partial.test.mjs +54 -0
  786. package/skills/a2h-page-specgen/scripts/test/gate.test.mjs +222 -0
  787. package/skills/a2h-page-specgen/scripts/test/helpers.mjs +54 -0
  788. package/skills/a2h-page-specgen/scripts/test/hg.test.mjs +171 -0
  789. package/skills/a2h-page-specgen/scripts/test/integration.test.mjs +301 -0
  790. package/skills/a2h-page-specgen/scripts/test/interactions.test.mjs +45 -0
  791. package/skills/a2h-page-specgen/scripts/test/inventory.test.mjs +139 -0
  792. package/skills/a2h-page-specgen/scripts/test/keys.test.mjs +774 -0
  793. package/skills/a2h-page-specgen/scripts/test/ledger.test.mjs +464 -0
  794. package/skills/a2h-page-specgen/scripts/test/plan-build.test.mjs +1011 -0
  795. package/skills/a2h-page-specgen/scripts/test/prepare-index.test.mjs +120 -0
  796. package/skills/a2h-page-specgen/scripts/test/prompt-tpl.test.mjs +68 -0
  797. package/skills/a2h-page-specgen/scripts/test/prose.test.mjs +390 -0
  798. package/skills/a2h-page-specgen/scripts/test/protocol-docs.test.mjs +167 -0
  799. package/skills/a2h-page-specgen/scripts/test/reach.test.mjs +93 -0
  800. package/skills/a2h-page-specgen/scripts/test/recovery-e2e.test.mjs +323 -0
  801. package/skills/a2h-page-specgen/scripts/test/recovery.test.mjs +546 -0
  802. package/skills/a2h-page-specgen/scripts/test/render.test.mjs +503 -0
  803. package/skills/a2h-page-specgen/scripts/test/source-text.test.mjs +181 -0
  804. package/skills/a2h-page-specgen/scripts/test/submit.test.mjs +701 -0
  805. package/skills/a2h-page-specgen/scripts/test/utg-io.test.mjs +90 -0
  806. package/skills/a2h-page-specgen/scripts/test/waker-event-store.test.mjs +1365 -0
  807. package/skills/a2h-page-specgen/scripts/test/waker-process.test.mjs +1765 -0
  808. package/skills/a2h-page-specgen/scripts/test/waker.test.mjs +1979 -0
  809. package/skills/a2h-page-specgen/scripts/test/watchdog.test.mjs +313 -0
  810. package/skills/a2h-page-specgen/scripts/waker.mjs +1234 -0
  811. package/skills/a2h-page-specgen/scripts/watchdog.mjs +298 -0
  812. package/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +49 -51
  813. package/skills/a2h-resource-convert/scripts/tests/adaptive_icon.test.mjs +182 -0
  814. package/skills/a2h-resource-convert/scripts/tests/app_identity.test.mjs +206 -0
  815. package/skills/a2h-resource-convert/scripts/tests/docs_only_i18n.test.mjs +44 -0
  816. package/skills/a2h-spec-design-pipeline/SKILL.md +79 -78
  817. package/skills/a2h-spec-design-pipeline/references/coding-loop.md +51 -12
  818. package/skills/a2h-spec-design-pipeline/references/execution-model.md +24 -6
  819. package/skills/a2h-spec-design-pipeline/references/final-report-template.md +3 -2
  820. package/skills/a2h-spec-design-pipeline/references/initialization.md +15 -4
  821. package/skills/a2h-spec-design-pipeline/references/merge-queue.md +82 -41
  822. package/skills/a2h-spec-design-pipeline/references/resolver-prompt.md +61 -0
  823. package/skills/a2h-spec-design-pipeline/references/scripts.md +19 -10
  824. package/skills/a2h-spec-design-pipeline/references/shared-layer.md +267 -0
  825. package/skills/a2h-spec-design-pipeline/references/state-and-resume.md +61 -8
  826. package/skills/a2h-spec-design-pipeline/references/static-defect-gate.md +62 -13
  827. package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleMeta.json +8 -0
  828. package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleSet.json +8 -0
  829. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/http-extra-data-empty-string-cn.md +55 -0
  830. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/http-extra-data-empty-string-en.md +60 -0
  831. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/HttpExtraDataEmptyStringCheck.js +488 -0
  832. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/index.js +11 -0
  833. package/skills/a2h-spec-design-pipeline/rules/migration-rules/package.json +17 -0
  834. package/skills/a2h-spec-design-pipeline/scripts/branch_landed.ts +12 -38
  835. package/skills/a2h-spec-design-pipeline/scripts/dispatch/evidence.mjs +40 -5
  836. package/skills/a2h-spec-design-pipeline/scripts/dispatch/fold.mjs +18 -0
  837. package/skills/a2h-spec-design-pipeline/scripts/dispatch/landing.mjs +74 -0
  838. package/skills/a2h-spec-design-pipeline/scripts/dispatch/progress.mjs +1 -1
  839. package/skills/a2h-spec-design-pipeline/scripts/dispatch/wait.mjs +1 -1
  840. package/skills/a2h-spec-design-pipeline/scripts/dispatch/worktree.mjs +2 -2
  841. package/skills/a2h-spec-design-pipeline/scripts/dispatch.mjs +128 -5
  842. package/skills/a2h-spec-design-pipeline/scripts/ensure_wt_index.ts +98 -35
  843. package/skills/a2h-spec-design-pipeline/scripts/homecheck_scan.ts +218 -37
  844. package/skills/a2h-spec-design-pipeline/scripts/lib/shared_classes.ts +113 -0
  845. package/skills/a2h-spec-design-pipeline/scripts/lib/shared_docs.ts +202 -0
  846. package/skills/a2h-spec-design-pipeline/scripts/lib/wiring.ts +58 -0
  847. package/skills/a2h-spec-design-pipeline/scripts/plan_groups.ts +6 -7
  848. package/skills/a2h-spec-design-pipeline/scripts/resolve_wiring.ts +3 -0
  849. package/skills/a2h-spec-design-pipeline/scripts/resolver_prompt.ts +348 -0
  850. package/skills/a2h-spec-design-pipeline/scripts/scan_shared.ts +642 -0
  851. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_commands.mjs +15 -5
  852. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_e2e.mjs +7 -2
  853. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_evidence.mjs +104 -1
  854. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_fold.mjs +24 -0
  855. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_landing.mjs +394 -0
  856. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_progress.mjs +24 -1
  857. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_wait.mjs +14 -0
  858. package/skills/a2h-spec-design-pipeline/scripts/test_ensure_wt_index.ts +163 -5
  859. package/skills/a2h-spec-design-pipeline/scripts/test_homecheck_scan.ts +15 -7
  860. package/skills/a2h-spec-design-pipeline/scripts/test_resolve_wiring.ts +14 -0
  861. package/skills/a2h-spec-design-pipeline/scripts/test_resolver_prompt.ts +350 -0
  862. package/skills/a2h-spec-design-pipeline/scripts/test_scan_shared.ts +996 -0
  863. package/skills/a2h-spec-design-pipeline/scripts/test_shared_classes.ts +80 -0
  864. package/skills/a2h-spec-design-pipeline/scripts/test_shared_docs.ts +205 -0
  865. package/skills/a2h-spec-design-pipeline/scripts/test_shared_layer_docs.ts +121 -0
  866. package/skills/a2h-spec-design-pipeline/scripts/test_shared_layer_e2e.ts +85 -0
  867. package/skills/a2h-spec-design-pipeline/scripts/test_validate_shared_manifest.ts +720 -0
  868. package/skills/a2h-spec-design-pipeline/scripts/test_wiring.ts +40 -0
  869. package/skills/a2h-spec-design-pipeline/scripts/validate_shared_manifest.ts +566 -0
  870. package/skills/a2h-spec-generate/SKILL.md +87 -21
  871. package/skills/a2h-spec-generate/references/batch-mode.md +78 -17
  872. package/skills/a2h-spec-generate/references/dispatch-watchdog.md +150 -0
  873. package/skills/a2h-spec-generate/references/fusion-task-contract.md +7 -0
  874. package/skills/a2h-spec-generate/references/review-checklist.md +1 -0
  875. package/skills/a2h-spec-generate/references/synthesis-rules.md +4 -2
  876. package/skills/a2h-spec-generate/references/worker-rules.md +6 -3
  877. package/skills/a2h-spec-generate/scripts/check-fused-spec.mjs +4 -5
  878. package/skills/a2h-spec-generate/scripts/check_spec.ts +145 -14
  879. package/skills/a2h-spec-generate/scripts/collect-specs.mjs +261 -19
  880. package/skills/a2h-spec-generate/scripts/dispatch-watch.mjs +1168 -0
  881. package/skills/a2h-spec-generate/scripts/feature-stem.mjs +1 -2
  882. package/skills/a2h-spec-generate/scripts/publish-specs.mjs +1 -2
  883. package/skills/a2h-spec-generate/scripts/regroup-by-page.mjs +1 -2
  884. package/skills/a2h-spec-generate/scripts/render-tasks.mjs +25 -46
  885. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/build.ts +26 -27
  886. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/component-variants.ts +3 -6
  887. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/policy.ts +31 -32
  888. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/traceability.ts +2 -3
  889. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/req-model/build.ts +15 -26
  890. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/area-facts.ts +102 -81
  891. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/behavior-seed.ts +39 -19
  892. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/library-evidence.ts +12 -13
  893. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/navigation-guard.ts +363 -0
  894. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/task-contract.ts +35 -196
  895. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/contracts.ts +3 -1
  896. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/task-contract.ts +22 -96
  897. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/tree-sitter-adapter.ts +3 -4
  898. package/skills/a2h-spec-generate/scripts/reqgen/src/model/contracts.ts +1 -1
  899. package/skills/a2h-spec-generate/scripts/reqgen/src/model/finalize.ts +74 -7
  900. package/skills/a2h-spec-generate/scripts/reqgen/src/model/prepare.ts +51 -7
  901. package/skills/a2h-spec-generate/scripts/reqgen/src/model/task.ts +42 -111
  902. package/skills/a2h-spec-generate/scripts/reqgen/src/requirement-scope.ts +1 -20
  903. package/skills/a2h-spec-generate/scripts/reqgen/src/source-index/homegraph.ts +1 -2
  904. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/req-text.ts +3 -4
  905. package/skills/a2h-spec-generate/scripts/reqgen/test/control-fact-join.test.ts +50 -0
  906. package/skills/a2h-spec-generate/scripts/reqgen/test/control-name-uniapp.test.ts +75 -0
  907. package/skills/a2h-spec-generate/scripts/reqgen/test/cross-area-anchor.test.ts +256 -0
  908. package/skills/a2h-spec-generate/scripts/reqgen/test/fixtures/fusion-run.ts +243 -0
  909. package/skills/a2h-spec-generate/scripts/reqgen/test/fixtures/zip.ts +63 -0
  910. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-area-facts.test.ts +650 -0
  911. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-detectors.test.ts +176 -0
  912. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-e2e.test.ts +103 -0
  913. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-schema.test.ts +111 -0
  914. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-seed.test.ts +195 -0
  915. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-selfcheck.test.ts +307 -0
  916. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-contract.test.ts +347 -0
  917. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-finalize.test.ts +1948 -0
  918. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-library-evidence.test.ts +239 -0
  919. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-navigation-guard.test.ts +277 -0
  920. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-prepare.test.ts +844 -0
  921. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-scope.test.ts +339 -0
  922. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-selfcheck.test.ts +1253 -0
  923. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-spec.test.ts +608 -0
  924. package/skills/a2h-spec-generate/scripts/reqgen/test/model-cli-blockers.test.ts +117 -0
  925. package/skills/a2h-spec-generate/scripts/reqgen/test/model-scope.test.ts +411 -0
  926. package/skills/a2h-spec-generate/scripts/reqgen/test/model-seeds.test.ts +175 -0
  927. package/skills/a2h-spec-generate/scripts/reqgen/test/model-task-contract.test.ts +300 -0
  928. package/skills/a2h-spec-generate/scripts/reqgen/test/model-v4.test.ts +1061 -0
  929. package/skills/a2h-spec-generate/scripts/reqgen/test/specgen-completeness.test.ts +286 -0
  930. package/skills/a2h-spec-generate/scripts/reqgen/test/stagem-stored-path.test.ts +25 -0
  931. package/skills/a2h-spec-generate/scripts/reqgen/test/uniapp-scanner.test.ts +159 -0
  932. package/skills/a2h-spec-generate/scripts/reqgen/test/zip.test.ts +61 -0
  933. package/skills/a2h-spec-generate/test/check-fused-spec.test.mjs +879 -0
  934. package/skills/a2h-spec-generate/test/check-spec.test.ts +430 -0
  935. package/skills/a2h-spec-generate/test/collect-specs.test.mjs +811 -0
  936. package/skills/a2h-spec-generate/test/detect-project.test.mjs +37 -0
  937. package/skills/a2h-spec-generate/test/dispatch-watch.test.mjs +606 -0
  938. package/skills/a2h-spec-generate/test/ensure-index.test.mjs +230 -0
  939. package/skills/a2h-spec-generate/test/feature-stem.test.mjs +157 -0
  940. package/skills/a2h-spec-generate/test/fixtures/android/app/src/main/AndroidManifest.xml +3 -0
  941. package/skills/a2h-spec-generate/test/fixtures/android/build.gradle +3 -0
  942. package/skills/a2h-spec-generate/test/fixtures/android/settings.gradle +3 -0
  943. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/package.json +9 -0
  944. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/App.vue +8 -0
  945. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/components/MyCard.vue +9 -0
  946. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/feature/editor/index.vue +1 -0
  947. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/main.ts +6 -0
  948. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/manifest.json +4 -0
  949. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/detail/index.vue +1 -0
  950. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/home/index.vue +33 -0
  951. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/settings/index.vue +1 -0
  952. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages.json +23 -0
  953. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/services/items.ts +3 -0
  954. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/tsconfig.json +8 -0
  955. package/skills/a2h-spec-generate/test/fixtures/unknown/README.txt +1 -0
  956. package/skills/a2h-spec-generate/test/inspect-uniapp.test.mjs +54 -0
  957. package/skills/a2h-spec-generate/test/prepare-facts.test.mjs +41 -0
  958. package/skills/a2h-spec-generate/test/publication-verdict.test.mjs +182 -0
  959. package/skills/a2h-spec-generate/test/publish-specs.test.mjs +295 -0
  960. package/skills/a2h-spec-generate/test/regroup-by-page.test.mjs +354 -0
  961. package/skills/a2h-spec-generate/test/render-tasks.test.mjs +596 -0
  962. package/skills/a2h-spec-generate/test/report.test.mjs +47 -0
  963. package/skills/a2h-utg-explorer/references/architecture.md +4 -0
  964. package/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +64 -80
  965. package/skills/a2h-utg-explorer/scripts/hint_check.mjs +1 -2
  966. package/skills/a2h-utg-explorer/scripts/recover.mjs +1 -1
  967. package/skills/a2h-utg-explorer/scripts/rejudge.mjs +5 -3
  968. package/skills/a2h-utg-explorer/scripts/tests/attest.test.mjs +66 -0
  969. package/skills/a2h-utg-explorer/scripts/tests/calendar_round_fixes.test.mjs +244 -0
  970. package/skills/a2h-utg-explorer/scripts/tests/chain.test.mjs +45 -0
  971. package/skills/a2h-utg-explorer/scripts/tests/compose_identity.test.mjs +302 -0
  972. package/skills/a2h-utg-explorer/scripts/tests/content_wait.test.mjs +207 -0
  973. package/skills/a2h-utg-explorer/scripts/tests/coverage_rules.test.mjs +104 -0
  974. package/skills/a2h-utg-explorer/scripts/tests/d_prereqs.test.mjs +231 -0
  975. package/skills/a2h-utg-explorer/scripts/tests/device_health.test.mjs +160 -0
  976. package/skills/a2h-utg-explorer/scripts/tests/device_locale_identity.test.mjs +77 -0
  977. package/skills/a2h-utg-explorer/scripts/tests/device_lock_retry.test.mjs +187 -0
  978. package/skills/a2h-utg-explorer/scripts/tests/direct_launch.test.mjs +130 -0
  979. package/skills/a2h-utg-explorer/scripts/tests/explorer_review_fixes.test.mjs +137 -0
  980. package/skills/a2h-utg-explorer/scripts/tests/final_utg.test.mjs +135 -0
  981. package/skills/a2h-utg-explorer/scripts/tests/first_round_phases.test.mjs +16 -0
  982. package/skills/a2h-utg-explorer/scripts/tests/fresh_state_plan.test.mjs +78 -0
  983. package/skills/a2h-utg-explorer/scripts/tests/generalization_fixes.test.mjs +252 -0
  984. package/skills/a2h-utg-explorer/scripts/tests/hint_check.test.mjs +129 -0
  985. package/skills/a2h-utg-explorer/scripts/tests/holds_without_data_parity.test.mjs +26 -0
  986. package/skills/a2h-utg-explorer/scripts/tests/interruptions.test.mjs +492 -0
  987. package/skills/a2h-utg-explorer/scripts/tests/launch_bridge.test.mjs +199 -0
  988. package/skills/a2h-utg-explorer/scripts/tests/launch_failure.test.mjs +40 -0
  989. package/skills/a2h-utg-explorer/scripts/tests/node_coverage.test.mjs +193 -0
  990. package/skills/a2h-utg-explorer/scripts/tests/overflow_prefix.test.mjs +327 -0
  991. package/skills/a2h-utg-explorer/scripts/tests/overlay_identity.test.mjs +204 -0
  992. package/skills/a2h-utg-explorer/scripts/tests/page_identity_tiers.test.mjs +393 -0
  993. package/skills/a2h-utg-explorer/scripts/tests/pager_navigation.test.mjs +119 -0
  994. package/skills/a2h-utg-explorer/scripts/tests/panel_routes.test.mjs +208 -0
  995. package/skills/a2h-utg-explorer/scripts/tests/pipeline.test.mjs +240 -0
  996. package/skills/a2h-utg-explorer/scripts/tests/recover.test.mjs +212 -0
  997. package/skills/a2h-utg-explorer/scripts/tests/recover_b.test.mjs +173 -0
  998. package/skills/a2h-utg-explorer/scripts/tests/recover_d.test.mjs +280 -0
  999. package/skills/a2h-utg-explorer/scripts/tests/review_fixes.test.mjs +213 -0
  1000. package/skills/a2h-utg-explorer/scripts/tests/robustness_fixes.test.mjs +345 -0
  1001. package/skills/a2h-utg-explorer/scripts/tests/run_cycle.test.mjs +454 -0
  1002. package/skills/a2h-utg-explorer/scripts/tests/runner_capabilities.test.mjs +194 -0
  1003. package/skills/a2h-utg-explorer/scripts/tests/scope.test.mjs +229 -0
  1004. package/skills/a2h-utg-explorer/scripts/tests/scroll_sweep.test.mjs +336 -0
  1005. package/skills/a2h-utg-explorer/scripts/tests/semantics.test.mjs +102 -0
  1006. package/skills/a2h-utg-explorer/scripts/tests/snapshot_integrity.test.mjs +142 -0
  1007. package/skills/a2h-utg-explorer/scripts/tests/state_ambiguity.test.mjs +92 -0
  1008. package/skills/a2h-utg-explorer/scripts/tests/string_tables_twin_ties.test.mjs +83 -0
  1009. package/skills/a2h-utg-explorer/scripts/tests/tar_fixture.mjs +12 -0
  1010. package/skills/a2h-utg-explorer/scripts/tests/twin_opener.test.mjs +119 -0
  1011. package/skills/a2h-utg-explorer/scripts/tests/u2_backend.test.mjs +346 -0
  1012. package/skills/a2h-utg-explorer/scripts/tests/ui_state_anchors.test.mjs +112 -0
  1013. package/skills/a2h-utg-explorer/scripts/tests/variant_strings.test.mjs +63 -0
  1014. package/skills/a2h-utg-explorer/scripts/tests/worklist_parts.test.mjs +24 -0
  1015. package/skills/a2h-utg-explorer/scripts/utg_explorer/adapters.mjs +13 -3
  1016. package/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +107 -65
  1017. package/skills/a2h-utg-explorer/scripts/utg_explorer/strings.mjs +155 -0
  1018. package/skills/a2h-utg-static/scripts/assemble.mjs +28 -3
  1019. package/skills/a2h-utg-static/scripts/click_paths.mjs +19 -20
  1020. package/skills/a2h-utg-static/scripts/compose_overlay.mjs +102 -2
  1021. package/skills/a2h-utg-static/scripts/fragment_nav.mjs +2 -3
  1022. package/skills/a2h-utg-static/scripts/nl_hints.mjs +2 -3
  1023. package/skills/a2h-utg-static/scripts/presenter_nav.mjs +1 -2
  1024. package/skills/a2h-utg-static/scripts/route_interceptor.mjs +21 -7
  1025. package/skills/a2h-utg-static/scripts/static_prior.mjs +26 -29
  1026. package/skills/a2h-utg-static/scripts/tests/test_activity_gates.mjs +84 -0
  1027. package/skills/a2h-utg-static/scripts/tests/test_login_interceptor.mjs +38 -0
  1028. package/skills/a2h-utg-static/scripts/tests/test_route_token_words.mjs +29 -1
  1029. package/skills/a2h-app-migrate/scripts/i18n-term.d.mts +0 -5
  1030. package/skills/a2h-app-migrate/scripts/i18n-term.mjs +0 -54
  1031. package/skills/a2h-arch-generate/scripts/i18n-term.d.mts +0 -5
  1032. package/skills/a2h-arch-generate/scripts/i18n-term.mjs +0 -54
  1033. package/skills/a2h-arkts-logic-coder/scripts/design/i18n-term.d.mts +0 -5
  1034. package/skills/a2h-arkts-logic-coder/scripts/design/i18n-term.mjs +0 -54
  1035. package/skills/a2h-batch-ui-align/references/source-only-tier.md +0 -38
  1036. package/skills/a2h-batch-ui-align/scripts/i18n-term.d.mts +0 -5
  1037. package/skills/a2h-batch-ui-align/scripts/i18n-term.mjs +0 -54
  1038. package/skills/a2h-dashboard-render/scripts/i18n-term.d.mts +0 -5
  1039. package/skills/a2h-dashboard-render/scripts/i18n-term.mjs +0 -54
  1040. package/skills/a2h-resource-convert/scripts/i18n-term.d.mts +0 -5
  1041. package/skills/a2h-resource-convert/scripts/i18n-term.mjs +0 -54
  1042. package/skills/a2h-spec-design-pipeline/scripts/i18n-term.d.mts +0 -5
  1043. package/skills/a2h-spec-design-pipeline/scripts/i18n-term.mjs +0 -54
  1044. package/skills/a2h-spec-design-pipeline/scripts/test_i18n_term.ts +0 -70
  1045. package/skills/a2h-spec-generate/scripts/i18n-term.d.mts +0 -5
  1046. package/skills/a2h-spec-generate/scripts/i18n-term.mjs +0 -54
  1047. package/skills/a2h-spec-generate/scripts/reqgen/src/i18n-term.d.mts +0 -5
  1048. package/skills/a2h-spec-generate/scripts/reqgen/src/i18n-term.mjs +0 -54
  1049. package/skills/a2h-utg-explorer/scripts/i18n-term.d.mts +0 -5
  1050. package/skills/a2h-utg-explorer/scripts/i18n-term.mjs +0 -54
  1051. package/skills/a2h-utg-static/scripts/i18n-term.d.mts +0 -5
  1052. package/skills/a2h-utg-static/scripts/i18n-term.mjs +0 -54
  1053. package/skills/a2h-utg-static/scripts/tests/test_i18n_term.mjs +0 -155
@@ -0,0 +1,2037 @@
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, 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, 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 { triggerAttests } from './attest.mjs';
43
+
44
+ /** Indirection for functions tests replace (Python patches module globals). */
45
+ export const deps = { observationMatchesStatic, resolvePage, triggerAttests };
46
+
47
+ /** deviceLockPath, LOCK_GRACE_S: device_lock.mjs (shared with device_health.mjs). */
48
+ export { deviceLockPath, LOCK_GRACE_S };
49
+
50
+ /** A steal guard older than this (s) belongs to a stealer that died mid-steal. */
51
+ export const STEAL_GUARD_S = 30;
52
+
53
+ /** run_device.mjs exit code for a phase blocked `device-unavailable` (run_cycle.mjs DEVICE_UNAVAILABLE_EXIT). */
54
+ export const DEVICE_UNAVAILABLE_EXIT = 75;
55
+
56
+ /** Default wait (s) for a device lock another explorer holds (config.device_lock_wait_s). */
57
+ export const LOCK_WAIT_S = 300;
58
+ const LOCK_POLL_S = 5;
59
+
60
+ /** The device lock is held by another explorer (`holder`: its parsed lock, or null). */
61
+ export class DeviceBusy extends Error {
62
+ constructor(message, holder = null) { super(message); this.name = 'DeviceBusy'; this.holder = holder; }
63
+ }
64
+
65
+ /** "pid N, campaign <path>, since <ISO time>" from a lock's content (fields it lacks are '?'). */
66
+ export function lockOwner(holder) {
67
+ const h = holder !== null && typeof holder === 'object' ? holder : {};
68
+ const ts = Number(get(h, 'ts'));
69
+ const since = Number.isFinite(ts) && ts > 0 ? new Date(ts * 1000).toISOString() : '?';
70
+ return `pid ${get(h, 'pid') ?? '?'}, campaign ${get(h, 'campaign') ?? '?'}, since ${since}`;
71
+ }
72
+
73
+ /**
74
+ * Exclusive create: `content` is written to a tmp file and hard-linked to `p` (fails if `p`
75
+ * exists), so `p` never exists empty or half written. false = `p` exists.
76
+ */
77
+ function linkCreate(p, content) {
78
+ const tmp = `${p}.${process.pid}.${uuid4Hex().slice(0, 8)}.tmp`;
79
+ fs.writeFileSync(tmp, content);
80
+ try { fs.linkSync(tmp, p); return true; } catch (e) {
81
+ if (e.code === 'EEXIST') { return false; }
82
+ throw e;
83
+ } finally { try { fs.unlinkSync(tmp); } catch { /* gone */ } }
84
+ }
85
+
86
+ /**
87
+ * Remove the stale lock at `lockPath` whose content was read as `seen`. Only the holder of the
88
+ * steal guard `<lock>.steal` (taken with linkCreate) inspects and removes a stale lock, and only
89
+ * while its content is still `seen`: a lock another competitor created meanwhile is never touched
90
+ * (the rename / put-back scheme this replaces could drop a third party's fresh lock and leave two
91
+ * holders). A guard left by a stealer that died is removed after STEAL_GUARD_S.
92
+ * true = the stale lock is gone (the caller then creates its own).
93
+ */
94
+ export function stealStale(lockPath, seen) {
95
+ const guard = `${lockPath}.steal`;
96
+ const token = JSON.stringify({ pid: process.pid, ts: epoch(), id: uuid4Hex() });
97
+ if (!linkCreate(guard, token)) {
98
+ try {
99
+ if (Date.now() / 1000 - fs.statSync(guard).mtimeMs / 1000 >= STEAL_GUARD_S) { fs.unlinkSync(guard); }
100
+ } catch { /* gone */ }
101
+ return false;
102
+ }
103
+ try {
104
+ let cur;
105
+ try { cur = fs.readFileSync(lockPath, 'utf8'); } catch { return true; }
106
+ if (cur !== seen) { return false; }
107
+ try { fs.unlinkSync(lockPath); } catch (e) { if (e.code !== 'ENOENT') { return false; } }
108
+ return true;
109
+ } finally {
110
+ try { if (fs.readFileSync(guard, 'utf8') === token) { fs.unlinkSync(guard); } } catch { /* gone */ }
111
+ }
112
+ }
113
+
114
+ /**
115
+ * deviceLock(serial[, fn][, {waitS, pollS, campaign}]): a held lock is retried every pollS for up
116
+ * to waitS seconds (default 0: fail at once), then DeviceBusy names its owner. The lock records
117
+ * its owner's start time (`started`): a live pid that started at another time reused a dead
118
+ * holder's pid (device_lock.mjs holderGone), so that lock is stale.
119
+ */
120
+ export function deviceLock(serial, fn = null, { waitS = 0, pollS = LOCK_POLL_S, campaign = null } = {}) {
121
+ const lockPath = deviceLockPath(serial);
122
+ const mine = JSON.stringify({ pid: process.pid, ts: epoch(), started: myStartMs(),
123
+ campaign: campaign === null ? null : pathStr(campaign), argv: process.argv.slice(1) });
124
+ const tryCreate = () => linkCreate(lockPath, mine);
125
+ let holder = null;
126
+ const attempt = () => {
127
+ if (tryCreate()) { return true; }
128
+ let text = null; let age = 0;
129
+ holder = null;
130
+ try { text = fs.readFileSync(lockPath, 'utf8'); age = Date.now() / 1000 - fs.statSync(lockPath).mtimeMs / 1000; } catch { text = null; }
131
+ if (text === null) { return tryCreate(); } // released meanwhile
132
+ try { holder = JSON.parse(text); } catch { holder = null; }
133
+ const parsed = holder !== null && typeof holder === 'object';
134
+ const stale = parsed ? holderGone(holder) : age >= LOCK_GRACE_S;
135
+ return stale && stealStale(lockPath, text) && tryCreate();
136
+ };
137
+ const deadline = monotonic() + Math.max(0, toFloat(waitS));
138
+ let acquired = attempt();
139
+ while (!acquired && monotonic() < deadline) {
140
+ sleep(Math.min(Math.max(0.05, toFloat(pollS)), Math.max(0.05, deadline - monotonic())));
141
+ acquired = attempt();
142
+ }
143
+ if (!acquired) {
144
+ const h = holder !== null && typeof holder === 'object' ? holder : null;
145
+ throw new DeviceBusy(`Another explorer owns this device: ${lockOwner(h)}`, h);
146
+ }
147
+ const onExit = () => release();
148
+ function release() {
149
+ process.removeListener('exit', onExit);
150
+ try { if (fs.readFileSync(lockPath, 'utf8') === mine) { fs.unlinkSync(lockPath); } } catch { /* gone */ }
151
+ }
152
+ process.on('exit', onExit);
153
+ if (!fn) { return { release }; }
154
+ try { return fn(); } finally { release(); }
155
+ }
156
+
157
+ /** BudgetExhausted (RuntimeError). */
158
+ export class BudgetExhausted extends Error {
159
+ constructor(message = '') { super(message); this.name = 'BudgetExhausted'; }
160
+ }
161
+
162
+ /** _is_horizontal(n): a sideways scrollable (horizontal class, or a strip >= 3x wider than tall). */
163
+ export function _isHorizontal(n) {
164
+ const cls = pyStr(get(n, 'class', ''));
165
+ if (['HorizontalScrollView', 'ViewPager', 'ViewPager2'].some((x) => cls.endsWith(x))) { return true; }
166
+ const b = or(get(n, 'bounds'), []);
167
+ return b.length === 4 && (b[2] - b[0]) >= 3 * Math.max(1, b[3] - b[1]);
168
+ }
169
+
170
+ const SIG_FIELDS = ['resource_id', 'class', 'text', 'content_desc', 'bounds'];
171
+
172
+ /** _view_sig(observation): every visible node with its bounds (sha256 of sorted-key JSON). */
173
+ export function _viewSig(observation) {
174
+ const value = [get(observation, 'activity'), get(observation, 'window'),
175
+ get(observation, 'nodes', []).filter((n) => truthy(get(n, 'visible', true))).map((n) => SIG_FIELDS.map((k) => get(n, k)))];
176
+ return sha256Hex(jsonDumps(value, { sort_keys: true, ensure_ascii: false }));
177
+ }
178
+
179
+ /** Device-side outages (retried after the device answers again), not app failures. */
180
+ const DEVICE_UNAVAILABLE = 'device-unavailable';
181
+
182
+ /**
183
+ * launchMismatch(msg, launchComponent): a block reason when `am start` could not find a class with
184
+ * the configured launcher's simple name but a different FQN, else null. The caller asks only for a
185
+ * task whose source_launch is the static launcher (`launcher`, compile_tasks launchAction). That is the static UTG
186
+ * resolving `.MainActivity` against the applicationId instead of the namespace (applicationIdSuffix
187
+ * ".debug" etc.): every source launch then fails, and skipping each task as
188
+ * entry-component-not-installed ended a round with nothing captured and no stated cause.
189
+ */
190
+ export function launchMismatch(msg, launchComponent) {
191
+ const m = /Activity class \{([^}]+)\}/.exec(pyStr(msg));
192
+ const cfg = pyStr(launchComponent ?? '');
193
+ if (!m || !cfg.includes('/')) { return null; }
194
+ const tried = m[1];
195
+ const cls = (c) => { const [pk, name] = c.split('/'); return name.startsWith('.') ? pk + name : name; };
196
+ const a = cls(tried); const b = cls(cfg);
197
+ if (a === b || a.split('.').pop() !== b.split('.').pop()) { return null; }
198
+ return `launch-component-mismatch: ${tried} is not installed but config.launch_component is ${cfg}; `
199
+ + 'the static UTG resolved the activity against the applicationId, re-run a2h-utg-static';
200
+ }
201
+
202
+ /**
203
+ * grantRuntimePermissions(device, config): `pm grant` the app's not-yet-granted runtime permissions
204
+ * unless `grant_runtime_permissions` is false. Shared by Runner and d_prereqs snapshot, which both
205
+ * `pm clear` (that revokes every grant) before a launch. Returns [granted, failed].
206
+ */
207
+ export function grantRuntimePermissions(device, config) {
208
+ const pkg = get(config, 'package');
209
+ const granted = []; const failed = [];
210
+ if (!truthy(pkg) || !truthy(get(config, 'grant_runtime_permissions', true))) { return [granted, failed]; }
211
+ let dump = '';
212
+ try { dump = device._shell('dumpsys', 'package', pkg); } catch { dump = ''; }
213
+ for (const perm of runtimePermissions(dump, { ungrantedOnly: true })) {
214
+ try { device._shell('pm', 'grant', pkg, perm); granted.push(perm); } catch { failed.push(perm); }
215
+ }
216
+ return [granted, failed];
217
+ }
218
+
219
+ export const TRANSIENT_DEVICE_RE = new RegExp(
220
+ "Can't find service|Cannot identify foreground window|device '[^']+' not found|"
221
+ + 'device offline|error: closed|device-timeout|ui-dump-(?:failed|remote-missing)|Foreground changed during capture');
222
+
223
+ const isVisible = (n) => truthy(get(n, 'visible', true));
224
+ /** A consent CheckBox's own label ("I have read and agree"), as against an optional one ("Receive push notifications"). */
225
+ const CONSENT_BOX_RE = /have read|agree|accept/i;
226
+ /**
227
+ * A consent dialog's own positive control when it is not android:id/button1 (a custom layout):
228
+ * the whole label is an accept ("Agree", "Agree and continue", "I agree", "Accept", "Agree", "I agree",
229
+ * "Accept & continue"). Anchored, so "Do not agree" / "Disagree" / "I have read and agree" never match.
230
+ */
231
+ const CONSENT_POSITIVE_RE = /^(?:i )?(?:agree|accept)(?: and (?:continue|use|enter|start using))?$|^(?:i )?(?:agree|accept)(?:(?: and| &) (?:continue|proceed))?$/i;
232
+ /** A label that declines or leaves: an app may put that on button1, so its id alone does not make it the accept. */
233
+ const CONSENT_DECLINE_RE = /disagree|do(?:n.t| not) agree|decline|reject|refuse|exit|quit|cancel|not now/i;
234
+ /** A toggle (CheckBox, Switch, ...): pressing it ticks, it does not accept, even when its label is "Agree". */
235
+ const isToggle = (n) => [true, 'true'].includes(get(n, 'checkable'))
236
+ || /(?:CheckBox|Switch|RadioButton|ToggleButton|CheckedTextView)$/.test(pyStr(get(n, 'class', '')));
237
+ /** Adapter containers: a text inside one is a bound row (user or app data), not a layout default. */
238
+ export const LIST_CLASS_RE = /(?:RecyclerView|ListView|GridView|WebView)$/;
239
+ /** A layout default is a short label; a longer text holding a specifier is content (a note, a log line). */
240
+ export const PLACEHOLDER_MAX_CHARS = 40;
241
+ /** A consent dialog's text (Runner.consentAccept): privacy policy / user agreement / terms. */
242
+ export const CONSENT_RE = /privacy agreement|privacy protection|personal information protection|service agreement|privacy policy|terms of (?:service|use)|user agreement/i;
243
+ /**
244
+ * A text the app has not formatted yet: a java.util.Formatter / Android string-resource
245
+ * specifier left as-is (`%1$s`, `%2$d`, `%.1f`, a bare `%s` / `%d`). It is the layout's
246
+ * android:text default, shown until the data arrives and the code calls getString(id, args)
247
+ * (WeatherApp MainFragment 2026-11-04: `Feels like %1$s`, `%1$d km/h` under Chinatown/20°
248
+ * for ~8 s after every launch; the tree did not change while waiting, so settle() took it as
249
+ * settled and the export made that frame the page's screenshot). `50%` / `13% chance` are not
250
+ * specifiers: a conversion letter must follow. A bare one (`%s`, `%02d`, `%,d`, `%tY`) must not
251
+ * touch an ASCII letter or digit (`5%d`, `x%sy`, a URL's `%20`); CJK around it is fine (`<CJK text>%s`).
252
+ */
253
+ 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])/;
254
+ export const unformattedText = (t) => typeof t === 'string' && UNFORMATTED_TEXT.test(t);
255
+ /**
256
+ * Identity of a scroll container found immobile in a search pass: class, id and bounds. Not its
257
+ * `{class, index}` selector: a scroll elsewhere can shift the reading-order index of same-class
258
+ * nodes, while a container that did not move keeps its bounds.
259
+ */
260
+ const stuckKey = (n) => jsonDumps([get(n, 'class') ?? null, get(n, 'resource_id') ?? null, or(get(n, 'bounds'), null)]);
261
+ /**
262
+ * Selector for scroll container `n` that resolves to it alone in `nodes`: its id, else its class,
263
+ * else its class plus reading-order `index` (a Compose page's one scrollable is an
264
+ * `android.view.View` among dozens of plain ones, so class alone never resolves).
265
+ */
266
+ const scrollSel = (n, nodes = null) => {
267
+ if (truthy(get(n, 'resource_id'))) { return { resource_id: n.resource_id }; }
268
+ const sel = { class: get(n, 'class') };
269
+ if (!nodes || matching(nodes, sel).length <= 1) { return sel; }
270
+ return classIndexSel(n, nodes) ?? sel;
271
+ };
272
+
273
+ /** `{class, index}` naming `n` by its class and reading-order position (adapters.matching's order), or null. */
274
+ function classIndexSel(n, nodes) {
275
+ if (!truthy(get(n, 'class'))) { return null; }
276
+ const same = matching(nodes, { class: n.class });
277
+ const idx = sortedBy(same, (m) => { const b = or(get(m, 'bounds'), [0, 0]); return b.slice(0, 2).reverse(); }).indexOf(n);
278
+ return idx >= 0 ? { class: n.class, index: idx } : null;
279
+ }
280
+ /** Atom types that press nothing, so they keep consentAccept's after-launch window open. */
281
+ const PASSIVE_ACTIONS = new Set(['wait', 'scroll']);
282
+ const s200 = (e) => cpSlice(errStr(e), 0, 200);
283
+ const CANDIDATE_KINDS = { click_candidates: 'click', long_click_candidates: 'long_click', double_tap_candidates: 'double_tap' };
284
+
285
+ /**
286
+ * The runtime-permission dialog words its allow button per permission and Android version
287
+ * ("Allow", "Allow only while using this app", "While using the app", "Allow all"), so a recipe's label
288
+ * misses on another device. Measured (Salt Player 10-18): three recD scan chains asked for
289
+ * "Allow only while using this app" on a media prompt showing "Allow / Don't allow" and died there. When the
290
+ * screen is that dialog and the step means "allow", press its allow button by the stable
291
+ * permissioncontroller id. Deny is never inferred.
292
+ */
293
+ export const PERMISSION_ALLOW_IDS = ['permission_allow_foreground_only_button', 'permission_allow_button',
294
+ 'permission_allow_all_button', 'permission_allow_one_time_button'];
295
+ const ALLOW_WORDS = /allow|while using/i;
296
+ const DENY_WORDS = /deny|don.t allow/i;
297
+
298
+ /**
299
+ * Runtime permissions the package holds, from `dumpsys package <pkg>`: the entries of its
300
+ * `runtime permissions:` sections. Install-time permissions are not listed there. With
301
+ * `{ ungrantedOnly: true }`, only those still `granted=false` (nothing to do for the rest).
302
+ */
303
+ export function runtimePermissions(dump, { ungrantedOnly = false } = {}) {
304
+ const all = new Set(); const granted = new Set();
305
+ let inSection = false; let indent = -1;
306
+ for (const line of pyStr(dump).split(/\r?\n/)) {
307
+ const lead = line.length - line.trimStart().length;
308
+ if (/^\s*runtime permissions:\s*$/.test(line)) { inSection = true; indent = lead; continue; }
309
+ if (!inSection) { continue; }
310
+ const m = /^\s*([\w.]+): granted=(true|false)/.exec(line);
311
+ if (m && lead > indent) { all.add(m[1]); if (m[2] === 'true') { granted.add(m[1]); } continue; }
312
+ inSection = false;
313
+ }
314
+ // A permission listed for several users counts as granted only when every listing grants it.
315
+ for (const line of pyStr(dump).split(/\r?\n/)) {
316
+ const m = /^\s*([\w.]+): granted=false/.exec(line);
317
+ if (m) { granted.delete(m[1]); }
318
+ }
319
+ return [...all].filter((p) => !ungrantedOnly || !granted.has(p)).sort();
320
+ }
321
+
322
+ export function permissionGrant(nodes, selectors, kind = 'click') {
323
+ const isPrompt = nodes.some((n) => pyStr(get(n, 'resource_id', '')).endsWith('permissioncontroller:id/grant_dialog'));
324
+ if (!isPrompt) { return null; }
325
+ const labels = selectors.map((s) => pyStr(or(get(s, 'text'), get(s, 'content_desc'))));
326
+ if (!labels.some((t) => ALLOW_WORDS.test(t) && !DENY_WORDS.test(t))) { return null; }
327
+ for (const id of PERMISSION_ALLOW_IDS) {
328
+ const hit = nodes.filter((n) => isVisible(n) && pyStr(get(n, 'resource_id', '')).endsWith(':id/' + id));
329
+ if (hit.length === 1) { return { type: kind, selector: { resource_id: hit[0].resource_id } }; }
330
+ }
331
+ return null;
332
+ }
333
+
334
+ const uniqueHit = (nodes, selector) => {
335
+ try { return matching(nodes, selector).length === 1; } catch (e) { if (e instanceof AdapterError) { return false; } throw e; }
336
+ };
337
+
338
+ /**
339
+ * Container openers the campaign's own routes already use: the selector groups of `intermediate`
340
+ * replay steps (a hop that opens a popup, overflow or "more" list without changing page), most
341
+ * frequent first, at most `limit`. App-agnostic: nothing is named, only reused.
342
+ */
343
+ export function derivedOverflowOpeners(tasks, limit = 4, depth = 1) {
344
+ const count = new Map(); const groups = new Map();
345
+ for (const t of tasks) {
346
+ const replay = or(get(t, 'replay'), []);
347
+ // Only hops within `depth` of launch (top-level containers: bottom bar, toolbar, drawer); deeper
348
+ // intermediate hops are mostly in-page actions or sub-page navigation. The last replay hop
349
+ // prepares the task's own action and reveals no later step.
350
+ for (const s of replay.slice(0, Math.min(Math.max(0, depth), replay.length - 1))) {
351
+ if (!truthy(get(s, 'intermediate')) || !Object.hasOwn(CANDIDATE_KINDS, get(s, 'type'))) { continue; }
352
+ const sels = or(get(s, 'selectors'), []);
353
+ if (!sels.length) { continue; }
354
+ const k = jsonDumps(sels, { sort_keys: true });
355
+ if (!groups.has(k)) { groups.set(k, sels); }
356
+ count.set(k, (count.get(k) ?? 0) + 1);
357
+ }
358
+ }
359
+ return sortedBy([...groups.keys()], (k) => [-count.get(k), k]).slice(0, Math.max(0, limit)).map((k) => groups.get(k));
360
+ }
361
+
362
+ /** Static kinds that open over their page (what a container opener is expected to show). */
363
+ export const OVERLAY_KINDS = new Set(['menu', 'dialog', 'panel', 'overlay', 'ui-state', 'mode']);
364
+
365
+ /**
366
+ * The click left its page: another activity, or another verified static page that is not an
367
+ * overlay kind (a popup/menu/dialog resolving to its own node still counts as opened in place).
368
+ */
369
+ export function navigatedAway(before, after, catalog = {}) {
370
+ if (get(before, 'activity') !== get(after, 'activity')) { return true; }
371
+ const id = (o) => { const r = or(get(o, 'static_resolution'), {}); return get(r, 'status') === 'verified' ? get(r, 'static_id') : null; };
372
+ const a = id(after);
373
+ if (a === null || a === id(before)) { return false; }
374
+ const kind = get(get(catalog, a, {}), 'kind') ?? pyStr(a).split(':')[0];
375
+ return !OVERLAY_KINDS.has(kind);
376
+ }
377
+
378
+ /** Failure reasons that repeat for every task replaying the same prefix in the same environment. */
379
+ export const PREFIX_FAILURES = ['selector-not-found-after-bounded-scroll', 'replay-target-unverified:',
380
+ 'ambiguous selector', 'list-item:', 'Scroll requires one visible scrollable container'];
381
+
382
+ /** Key of a task's launch plus its first `n` replay steps. */
383
+ export function prefixKey(task, n) {
384
+ return sha256Hex(Buffer.from(jsonDumps([or(get(task, 'source_launch'), {}), or(get(task, 'replay'), []).slice(0, n)],
385
+ { sort_keys: true }), 'utf8')).slice(0, 16);
386
+ }
387
+
388
+ /** The page a launch landed on, for the prefix memo: its static id (page:…), else its activity. */
389
+ export function landingOf(observation) {
390
+ const res = or(get(observation, 'static_resolution'), {});
391
+ return get(res, 'status') === 'verified' ? res.static_id : `activity:${get(observation, 'activity') ?? ''}`;
392
+ }
393
+
394
+ /** Raised instead of replaying a prefix that already failed this run. */
395
+ export class PrefixFailed extends AdapterError {
396
+ constructor(memo, key) {
397
+ super(memo.reason);
398
+ this.name = 'PrefixFailed';
399
+ Object.assign(this, { key, from: memo.task_id, observationId: memo.observation_id, replayIndex: memo.replay_index,
400
+ beforeId: memo.before_id });
401
+ }
402
+ }
403
+
404
+ export class Runner {
405
+ constructor(args) {
406
+ this.args = args;
407
+ this.root = pResolve(args.campaign);
408
+ this.config = readJson(args.config);
409
+ this.doc = readJson(pJoin(this.root, 'campaign.json'));
410
+ this.phase = this.doc.phases.find((p) => p.id === args.phase);
411
+ if (this.phase === undefined) { throw new Error('StopIteration'); }
412
+ this.env = this.phase.environment;
413
+ this.catalog = get(this.doc, 'page_catalog', {});
414
+ // config `state_anchors` (in-page state rules) persist in the campaign, so a later compile,
415
+ // rejudge or report applies the same ones
416
+ if (truthy(get(this.config, 'state_anchors'))) {
417
+ this.doc.state_anchors = { ...(or(get(this.doc, 'state_anchors'), {})), ...this.config.state_anchors };
418
+ applyStateAnchors(this.catalog, this.doc.state_anchors);
419
+ }
420
+ this.device = new DeviceAdapter(this.config, pJoin(this.root, 'artifacts'));
421
+ this.current = null;
422
+ this.used = 0;
423
+ this.stage = 'initial';
424
+ this.mapped = new Set(this.doc.events.filter((e) => e.kind === 'mapping')
425
+ .map((e) => tupleKey(e.environment_id, get(e.payload, 'observation_id'), get(e.payload, 'static_id'))));
426
+ this.coverage = coverageMode(this.config, get(args, 'coverage', null));
427
+ this.covered = coveredStaticIds(this.doc);
428
+ this.swept = new Set();
429
+ for (const e of this.doc.events) {
430
+ if (e.kind !== 'scroll_sweep') { continue; }
431
+ for (const x of [get(e.payload, 'static_id'), ...get(e.payload, 'also_covers', [])]) { if (truthy(x)) { this.swept.add(x); } }
432
+ }
433
+ this.deadline = monotonic() + toFloat(get(this.config, 'max_seconds', 2400));
434
+ this.backExits = backExitPages(this.doc.events);
435
+ }
436
+
437
+ /** A scoped (incremental) campaign settles every node outside its scope (coverage.mjs scopeOf). */
438
+ scopeExcludes(staticId) {
439
+ // membership, not a complement of doc.nodes: `plan --extend` does not refresh doc.nodes
440
+ if (this._scope === undefined) { this._scope = scopeOf(this.doc); }
441
+ return this._scope !== null && !this._scope.has(staticId);
442
+ }
443
+
444
+ save() {
445
+ atomicWriteJson(pJoin(this.root, 'campaign.json'), this.doc);
446
+ this._saved_at = monotonic();
447
+ }
448
+
449
+ /** wait_device(timeout=None): block until input/window services answer; true on a fresh capture. */
450
+ /**
451
+ * Wait until the device answers and a capture succeeds. A device that answers while
452
+ * capture keeps failing has a hung app (a stuck `am start -W` leaves an ANR or a blank
453
+ * window): force-stop it and go home, so one hung launch does not block the phase.
454
+ */
455
+ waitDevice(timeout = null) {
456
+ const deadline = monotonic() + toFloat(or(timeout, () => get(this.config, 'device_recovery_seconds', 120)));
457
+ const unstickAfter = toInt(get(this.config, 'device_unstick_after', 2));
458
+ let answered = 0;
459
+ let unstuck = false;
460
+ while (monotonic() < deadline) {
461
+ try {
462
+ const out = this.device._shell('service', 'check', 'input');
463
+ if (out.includes('found') && !out.includes('not found')) {
464
+ answered += 1;
465
+ if (!unstuck && answered > unstickAfter) {
466
+ unstuck = true;
467
+ const pkg = get(this.config, 'package');
468
+ try {
469
+ if (truthy(pkg)) { this.device._shell('am', 'force-stop', pkg); }
470
+ this.device._shell('input', 'keyevent', 'KEYCODE_HOME');
471
+ } catch { /* the next capture tells */ }
472
+ }
473
+ this.device._foreground();
474
+ this.capture({ acceptLoading: true });
475
+ return true;
476
+ }
477
+ } catch { /* retry */ }
478
+ sleep(5);
479
+ }
480
+ return false;
481
+ }
482
+
483
+ emit(kind, payload, evidence = []) {
484
+ const e = event(kind, this.env, payload, evidence);
485
+ this.doc.events.push(e);
486
+ appendText(pJoin(this.root, 'events.jsonl'), jsonDumps(e, { ensure_ascii: false }) + '\n');
487
+ const interval = toFloat(get(this.config, 'save_interval', 15));
488
+ if (['task_result', 'environment_verified', 'discovery_result', 'environment_restored'].includes(kind)
489
+ || monotonic() - (this._saved_at ?? 0) >= interval) { this.save(); }
490
+ return e;
491
+ }
492
+
493
+ /**
494
+ * A verified capture of a page still loading its content: a visible spinner, or a sparse
495
+ * screen (at most 2 labelled app nodes) that shows at most one of the 3+ fixed texts the page's
496
+ * source renders. A Compose spinner is an unlabelled View whose dump does not change while it
497
+ * spins, so settle() takes it for a settled screen (SelectCity on yd-weather 2026-10-30: only
498
+ * the search hint, the city lists still loading). A spinner is a roughly square ProgressBar; a
499
+ * wide one is a bar showing a value (storage used, download), which stays on a loaded page.
500
+ * A visible text still holding a format specifier (`%1$s`, see UNFORMATTED_TEXT) is the
501
+ * layout default before the data is bound: the page is loading, however full it looks. Only a
502
+ * short label outside any list or WebView counts: a row's text is bound data (a note titled
503
+ * `printf("%d")`, a log line `format: %s`) and a long text is content, not a default. A text
504
+ * an upper layer paints over (the host page under a full-screen fragment) is not this page's.
505
+ * a2h-batch-ui-align export_ui_info.mjs placeholderTexts applies the same test to the export.
506
+ */
507
+ looksLoading(observation) {
508
+ const resolution = get(observation, 'static_resolution', {});
509
+ if (get(resolution, 'status') !== 'verified') { return false; }
510
+ const pkg = get(this.config, 'package');
511
+ const own = get(observation, 'nodes', []).filter((n) => isVisible(n) && (!truthy(pkg) || get(n, 'package', pkg) === pkg));
512
+ const spinner = (n) => {
513
+ if (!pyStr(get(n, 'class', '')).endsWith('ProgressBar')) { return false; }
514
+ const b = get(n, 'bounds', []);
515
+ if (!Array.isArray(b) || b.length !== 4) { return true; }
516
+ const w = b[2] - b[0]; const h = b[3] - b[1];
517
+ return w > 0 && h > 0 && Math.max(w, h) <= 2 * Math.min(w, h);
518
+ };
519
+ if (own.some(spinner)) { return true; }
520
+ const nodes = get(observation, 'nodes', []);
521
+ const inList = (n) => {
522
+ const seen = new Set();
523
+ 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')) {
524
+ seen.add(i);
525
+ if (LIST_CLASS_RE.test(pyStr(get(nodes[i], 'class', '')))) { return true; }
526
+ }
527
+ return false;
528
+ };
529
+ const placeholder = (n) => {
530
+ const t = get(n, 'text');
531
+ return unformattedText(t) && [...t].length <= PLACEHOLDER_MAX_CHARS && !isInputNode(n) && !inList(n);
532
+ };
533
+ const covered = new Set([...occludedIndices(nodes)].map((i) => nodes[i]));
534
+ if (own.some((n) => !covered.has(n) && placeholder(n))) { return true; }
535
+ const body = get(get(this.catalog, resolution.static_id, {}), 'body_titles', []) || [];
536
+ if (body.length < 3) { return false; }
537
+ const shown = new Set();
538
+ for (const n of own) {
539
+ for (const k of ['text', 'content_desc']) { if (truthy(get(n, k))) { shown.add(normalized(n[k])); } }
540
+ }
541
+ return shown.size <= 2 && body.filter((t) => shown.has(t)).length <= 1;
542
+ }
543
+
544
+ /**
545
+ * capture({ acceptLoading }): observe, resolve and map. A capture that looksLoading is recorded
546
+ * but not mapped (its screenshot would stand for the page), unless `acceptLoading`; atom() waits
547
+ * for the content and maps the loaded capture instead.
548
+ */
549
+ capture({ acceptLoading = false } = {}) {
550
+ const observation = this.device.observe(this.env);
551
+ // The adapter pressed Back to close an input-method picker before this capture: a device
552
+ // action the transition chain must show (a 'navigated' one also moved the app).
553
+ if (get(observation, 'ime_switcher_dismissed')) {
554
+ this.emit('ime_switcher_dismissed', { observation_id: get(observation, 'observation_id'),
555
+ outcome: observation.ime_switcher_dismissed, action: { type: 'back', automatic: true } });
556
+ }
557
+ const resolution = resolveTwinByOpener(
558
+ deps.resolvePage(observation, this.catalog, get(observation, 'identity'), { app_package: get(this.config, 'package') }),
559
+ this.current, this.catalog);
560
+ observation.static_resolution = resolution;
561
+ const states = resolution.status === 'verified' ? uiStatesOf(observation, this.catalog) : [];
562
+ if (states.length) { resolution.ui_states = states; }
563
+ if (resolution.status === 'verified') {
564
+ Object.assign(observation.identity, { family: resolution.static_id, status: 'verified', basis: resolution.anchors, reason: resolution.reason });
565
+ }
566
+ if (this.looksLoading(observation)) { observation.loading = true; }
567
+ // Seen loaded: its loading passes, so a wait that ran out there was a slow load (awaitContent).
568
+ // Only the first run-out is forgiven: a page that runs out again after that flips between
569
+ // a loading-looking and a loaded view (a spinner a scroll hides) and keeps its zero wait.
570
+ else if (resolution.status === 'verified' && this._loadingStuck?.has(resolution.static_id)
571
+ && !(this._loadingForgiven ??= new Set()).has(resolution.static_id)) {
572
+ this._loadingStuck.delete(resolution.static_id);
573
+ this._loadingForgiven.add(resolution.static_id);
574
+ }
575
+ this.current = observation;
576
+ this.emit('observation', observation, Object.values(observation.artifacts));
577
+ if (observation.loading && !acceptLoading) { return observation; }
578
+ this.mapCapture(observation);
579
+ return observation;
580
+ }
581
+
582
+ /** The `mapping` events of a verified capture: its page, then its in-page states. */
583
+ mapCapture(observation) {
584
+ const resolution = observation.static_resolution;
585
+ const states = get(resolution, 'ui_states', []) || [];
586
+ const loading = observation.loading ? { loading: true } : {};
587
+ if (resolution.status === 'verified') {
588
+ const key = tupleKey(this.env, observation.observation_id, resolution.static_id);
589
+ if (!this.mapped.has(key)) {
590
+ this.emit('mapping', { static_id: resolution.static_id, observation_id: observation.observation_id,
591
+ method: resolution.reason, anchors: resolution.anchors, ...loading }, Object.values(observation.artifacts));
592
+ this.mapped.add(key);
593
+ if (this._recognized !== undefined) { this._recognized.add(resolution.static_id); }
594
+ }
595
+ if (this.covered !== undefined) { this.covered.add(resolution.static_id); }
596
+ }
597
+ for (const sid of states) {
598
+ const key = tupleKey(this.env, observation.observation_id, sid);
599
+ if (this.mapped.has(key)) { continue; }
600
+ this.emit('mapping', { static_id: sid, observation_id: observation.observation_id, method: 'ui-state-anchor',
601
+ host_static: resolution.static_id, ...loading }, Object.values(observation.artifacts));
602
+ this.mapped.add(key);
603
+ if (this._recognized !== undefined) { this._recognized.add(sid); }
604
+ if (this.covered !== undefined) { this.covered.add(sid); }
605
+ }
606
+ return observation;
607
+ }
608
+
609
+ /**
610
+ * awaitContent(observation): while the page looksLoading, capture again every 0.5 s for up to
611
+ * `content_wait_seconds` (default 10). A page that is still loading then is mapped as it is,
612
+ * flagged `loading`. Captures only, no action is spent. A page that ran out the wait is not
613
+ * waited on again until a capture shows it loaded: what looks like loading there may be how the
614
+ * page stays (an empty state, a sparse screen, a spinner or a literal `%s` that never goes), and
615
+ * every later action landing on it would pay the full wait. A page seen loaded since loads
616
+ * slowly rather than never (a slow first fetch), so its next visit waits again.
617
+ */
618
+ awaitContent(observation) {
619
+ let current = observation;
620
+ if (!current || !current.loading) { return current; }
621
+ const stuck = (this._loadingStuck ??= new Set());
622
+ const sid = () => get(get(current, 'static_resolution', {}), 'static_id');
623
+ const wait = stuck.has(sid()) ? 0 : toFloat(get(this.config, 'content_wait_seconds', 10));
624
+ const deadline = monotonic() + Math.max(0, wait);
625
+ while (current.loading && monotonic() < deadline) { sleep(0.5); current = this.capture(); }
626
+ if (current.loading) {
627
+ if (wait > 0) { stuck.add(sid()); }
628
+ this.mapCapture(current);
629
+ }
630
+ return current;
631
+ }
632
+
633
+ at(ident) { return deps.observationMatchesStatic(or(this.current, {}), ident, this.catalog)[0]; }
634
+
635
+ appUiReady() {
636
+ const pkg = mget(this.config, 'package');
637
+ return get(this.current, 'package') === pkg && get(this.current, 'nodes', []).some((n) =>
638
+ get(n, 'package') === pkg && isVisible(n) && truthy(get(n, 'clickable')));
639
+ }
640
+
641
+ atom(action, taskId, purpose) {
642
+ const lifetime = this.doc.events.filter((e) => e.kind === 'attempt_started' && truthy(get(e.payload, 'atomic'))).length;
643
+ // A phase's cleanup runs after its budget is spent by design: restoring the
644
+ // environment never counts against it (measured: a recD phase that used its whole
645
+ // budget then threw from its cleanup, which run_cycle took as a fatal stage error).
646
+ const restoring = purpose === 'restore' && lifetime < toInt(get(this.config, 'max_campaign_actions', 1800));
647
+ if (!restoring && (this.used >= this.args.budget || lifetime >= toInt(get(this.config, 'max_campaign_actions', 1800)) || monotonic() >= this.deadline)) {
648
+ throw new BudgetExhausted('atomic-action/time budget exhausted');
649
+ }
650
+ const before = this.current;
651
+ this.used += 1;
652
+ // A launch that throws must not leave an earlier launch's consent window open.
653
+ if (get(action, 'type') === 'launch') { this._launched = false; }
654
+ const started = this.emit('attempt_started', { task_id: taskId, atomic: true, purpose, action, before: before.observation_id });
655
+ this.device.act(action, before);
656
+ this.device.settle();
657
+ let after = this.capture();
658
+ if (get(action, 'type') === 'launch') {
659
+ this.dirty = false;
660
+ const waitS = Math.max(0.0, toFloat(get(this.config, 'launch_ready_seconds', 8)));
661
+ let deadline = monotonic() + waitS;
662
+ while (!this.appUiReady() && monotonic() < deadline) { sleep(0.5); after = this.capture(); }
663
+ for (let k = 0; k < toInt(get(this.config, 'launch_retries', 1)); k++) {
664
+ if (this.appUiReady()) { break; }
665
+ this.device.act(action, after);
666
+ this.device.settle();
667
+ deadline = monotonic() + waitS;
668
+ after = this.capture();
669
+ while (!this.appUiReady() && monotonic() < deadline) { sleep(0.5); after = this.capture(); }
670
+ }
671
+ if (!this.appUiReady()) { throw new AdapterError('launch-ui-not-ready'); }
672
+ }
673
+ after = this.awaitContent(after);
674
+ // consentAccept: from a launch until the first action that can raise a dialog of its own.
675
+ // Waits and scrolls press nothing (app_settings' launch → wait → replay; a search scroll on
676
+ // the first replay step), and dismissals are the consent handling itself.
677
+ if (get(action, 'type') === 'launch') { this._launched = true; } else if (purpose !== 'dismiss-interruption' && !PASSIVE_ACTIONS.has(get(action, 'type'))) { this._launched = false; }
678
+ const outcome = observationKey(before) === observationKey(after) ? 'no_effect' : 'succeeded';
679
+ return this.emit('action_result', { task_id: taskId, attempt_id: started.id, purpose, outcome,
680
+ before: before.observation_id, after: after.observation_id, action });
681
+ }
682
+
683
+ choose(action) {
684
+ const isCand = Object.hasOwn(CANDIDATE_KINDS, get(action, 'type'));
685
+ const candidates = isCand ? get(action, 'selectors', []) : [get(action, 'selector', {})];
686
+ let ambiguous = false;
687
+ const hidden = occludedIndices(this.current.nodes);
688
+ const live = this.current.nodes.map((n, i) => (!hidden.has(i) ? n : { visible: false }));
689
+ const kindOf = () => get(CANDIDATE_KINDS, get(action, 'type'), get(action, 'type', 'click'));
690
+ for (const selector of candidates) {
691
+ let hits = matching(live, selector);
692
+ hits = hits.filter((n) => get(n, 'bounds', []).length === 4 && n.bounds[2] > n.bounds[0] && n.bounds[3] > n.bounds[1]);
693
+ if (hits.length === 1) {
694
+ const node = hits[0]; const parent = get(node, 'parent_index');
695
+ if (get(node, 'resource_id') === 'android:id/title' && parent !== null
696
+ && get(this.current.nodes[parent], 'class') === 'android.widget.ListView' && !truthy(get(node, 'clickable'))) { continue; }
697
+ return { type: kindOf(), selector };
698
+ }
699
+ if (hits.length > 1) {
700
+ const scoped = { ...selector, actionable: true };
701
+ if (matching(live, scoped).length === 1) { return { type: kindOf(), selector: scoped }; }
702
+ }
703
+ ambiguous = ambiguous || hits.length > 1;
704
+ }
705
+ if (ambiguous) { throw new AdapterError('ambiguous selector; no coordinate guessing'); }
706
+ return permissionGrant(live, candidates, kindOf());
707
+ }
708
+
709
+ listItem() {
710
+ const nodes = this.current.nodes;
711
+ const adapterCls = ['RecyclerView', 'ListView', 'GridView'];
712
+ const hasKids = new Set(nodes.map((c) => get(c, 'parent_index')));
713
+ let lists = [];
714
+ nodes.forEach((n, i) => { if (isVisible(n) && adapterCls.some((c) => pyStr(get(n, 'class', '')).endsWith(c)) && hasKids.has(i)) { lists.push(i); } });
715
+ if (lists.length !== 1) {
716
+ lists = [];
717
+ nodes.forEach((n, i) => { if (truthy(get(n, 'scrollable')) && isVisible(n)) { lists.push(i); } });
718
+ }
719
+ const idxOf = (n) => nodes.findIndex((m) => pyEq(m, n)); // list.index uses ==
720
+ const actionableRow = (child) => {
721
+ const cands = [child, ...nodes.filter((n) => get(n, 'parent_index') === idxOf(child))];
722
+ const lvl1 = cands.slice(1);
723
+ for (const c of lvl1) { const ci = idxOf(c); cands.push(...nodes.filter((n) => get(n, 'parent_index') === ci)); }
724
+ for (const n of cands) {
725
+ if ((truthy(get(n, 'clickable')) || truthy(get(n, 'long-clickable'))) && isVisible(n)
726
+ && !['ImageButton', 'FloatingActionButton'].some((c) => pyStr(get(n, 'class', '')).endsWith(c))
727
+ && get(n, 'bounds', []).length === 4 && n.bounds[3] > n.bounds[1]) { return n; }
728
+ }
729
+ return null;
730
+ };
731
+ const rowsOf = (li) => nodes.filter((n) => get(n, 'parent_index') === li).map(actionableRow).filter((r) => truthy(r));
732
+ // Several scrollables (a Compose page with a header strip and a list): only a container
733
+ // that holds actionable rows is a list; one such container is no ambiguity.
734
+ if (lists.length > 1) {
735
+ const withRows = lists.filter((li) => rowsOf(li).length > 0);
736
+ if (withRows.length === 1) { lists = withRows; }
737
+ }
738
+ if (lists.length !== 1) { throw new AdapterError(`list-item: expected one list, found ${lists.length}`); }
739
+ const rows = rowsOf(lists[0]);
740
+ if (!rows.length) { throw new AdapterError('list-item: list has no actionable rows'); }
741
+ return sortedBy(rows, (n) => [n.bounds[1], n.bounds[0]])[0];
742
+ }
743
+
744
+ reveal(selector, taskId) {
745
+ if (matching(this.current.nodes, selector).length) { return true; }
746
+ if (this.clearInterruption(taskId) && matching(this.current.nodes, selector).length) { return true; }
747
+ if (!this.appUiReady()) { return false; }
748
+ // Positions count (_viewSig): a list of rows without text moves only its bounds.
749
+ const origin = _viewSig(this.current);
750
+ for (const direction of ['down', 'up']) {
751
+ const seen = new Set([_viewSig(this.current)]);
752
+ const stuck = new Set();
753
+ for (let k = 0; k < toInt(get(this.config, 'max_scrolls_per_task', 6)); k++) {
754
+ const found = this.searchContainer(stuck);
755
+ if (!found) { break; }
756
+ const sel = found[1];
757
+ const prev = _viewSig(this.current);
758
+ this.atom({ type: 'scroll', selector: sel, direction }, taskId, 'search');
759
+ if (matching(this.current.nodes, selector).length) { return true; }
760
+ const key = _viewSig(this.current);
761
+ if (key === prev) { stuck.add(stuckKey(found[0])); continue; }
762
+ if (seen.has(key) || this._backAtOrigin(direction, key, origin)) { break; }
763
+ seen.add(key);
764
+ }
765
+ }
766
+ return false;
767
+ }
768
+
769
+ /**
770
+ * The vertical container a bounded search scrolls next, as [node, selector]: the only one, else
771
+ * the largest not yet found immobile in this pass. Requiring exactly one skipped every scroll on
772
+ * screens with several (measured, Simple Calendar week view: hours column, events list and the
773
+ * pager). The selector names this very node: copies sharing a resource id (one per pager page)
774
+ * are told apart by class and position, so one immobile copy does not rule out the others.
775
+ */
776
+ searchContainer(stuck) {
777
+ const nodes = this.current.nodes;
778
+ const own = (n) => (truthy(get(n, 'resource_id')) && matching(nodes, { resource_id: n.resource_id }).length === 1
779
+ ? { resource_id: n.resource_id } : (classIndexSel(n, nodes) ?? scrollSel(n, nodes)));
780
+ const conts = nodes.filter((n) => truthy(get(n, 'scrollable')) && isVisible(n) && !_isHorizontal(n) && !stuck.has(stuckKey(n)))
781
+ .map((n) => [n, own(n)]);
782
+ if (conts.length <= 1) { return conts[0] ?? null; }
783
+ 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]); };
784
+ return sortedBy(conts, (c) => -area(c))[0];
785
+ }
786
+
787
+ /**
788
+ * The upward search pass is back where the downward pass started: everything below was
789
+ * already searched, and one more upward swipe at the top of a list is a pull-to-refresh
790
+ * (SwipeRefreshLayout and friends), which starts network work and may open a dialog
791
+ * (measured, AntennaPod: 36 of 65 failed round-1 tasks met a refresh dialog opened this
792
+ * way). `search_above_origin: true` keeps searching above a mid-list origin.
793
+ */
794
+ _backAtOrigin(direction, key, origin) {
795
+ return direction === 'up' && key === origin && !truthy(get(this.config, 'search_above_origin', false));
796
+ }
797
+
798
+ // -- unexpected dialogs -----------------------------------------------------
799
+
800
+ /**
801
+ * A floating window on top of the page: its root does not cover the screen (a uiautomator
802
+ * dump holds the focused window only, so an AlertDialog, a permission prompt or a rating
803
+ * prompt shows as one small root) and it offers something to press. Returns its root
804
+ * bounds, or null.
805
+ */
806
+ modalOverlay() {
807
+ const nodes = get(this.current, 'nodes', []);
808
+ const roots = nodes.filter((n) => get(n, 'parent_index') === null || get(n, 'parent_index') === undefined);
809
+ const info = or(get(this.current, 'device_info'), {});
810
+ const w = toInt(or(get(info, 'width_px'), 0)); const h = toInt(or(get(info, 'height_px'), 0));
811
+ if (roots.length !== 1 || !(w > 0 && h > 0)) { return null; }
812
+ const b = or(get(roots[0], 'bounds'), []);
813
+ if (b.length !== 4) { return null; }
814
+ const share = ((b[2] - b[0]) * (b[3] - b[1])) / (w * h);
815
+ if (share >= toFloat(get(this.config, 'modal_max_screen_share', 0.85))) { return null; }
816
+ return nodes.some((n) => isVisible(n) && truthy(get(n, 'clickable'))) ? b : null;
817
+ }
818
+
819
+ /**
820
+ * Dismiss a dialog nobody asked for -- one that is neither the page the running task starts
821
+ * from nor the page it looks for (`this.keep`) -- so it does not eat the search budget.
822
+ * Action: the first matching `interruption_rules` entry ({id?, when: <rule>, action}), else
823
+ * the app's own consent dialog is accepted (consentAccept), else Back, then the negative
824
+ * button (android:id/button2) for a dialog Back does not close. A consent dialog that offers a
825
+ * decline (button2, or a label CONSENT_DECLINE_RE names: "Decline and exit") and nothing safe to
826
+ * accept with is left as it is, logged with outcome `unresolved`: there Back closes the Activity
827
+ * and button2 leaves the app. One without a decline (a "Logging in means agreeing to the 'User Agreement'" one-tap login
828
+ * sheet) keeps the generic dismissal. Ticking a consent box does not use up a dismissal (two
829
+ * required boxes, then the accept), up to `limit` ticks.
830
+ * Each dismissal is an `interruption` event. Returns true when something was dismissed.
831
+ */
832
+ clearInterruption(taskId) {
833
+ const limit = toInt(get(this.config, 'max_interruption_dismissals', 2));
834
+ let dismissed = false;
835
+ let ticks = 0;
836
+ for (let k = 0; k < limit + ticks; k++) {
837
+ const bounds = this.modalOverlay();
838
+ if (!bounds) { break; }
839
+ const res = or(get(this.current, 'static_resolution'), {});
840
+ if (get(res, 'status') === 'verified' && (this.keep ?? []).includes(get(res, 'static_id'))) { break; }
841
+ const rule = get(this.config, 'interruption_rules', []).find((r) => ruleMatches(this.current, get(r, 'when', {})));
842
+ const isConsent = !rule && this.consentDialog();
843
+ const consent = isConsent ? this.consentAccept() : null;
844
+ const texts = this.current.nodes.map((n) => or(get(n, 'text'), get(n, 'content_desc'))).filter((t) => truthy(t));
845
+ const before = this.current.observation_id;
846
+ if (isConsent && !consent && this.consentDecline()) {
847
+ this.emit('interruption', { task_id: taskId, observation_id: before, bounds, action: null, rule: 'consent-default',
848
+ texts: texts.slice(0, 6).map((t) => cpSlice(pyStr(t), 0, 80)), outcome: 'unresolved' });
849
+ break;
850
+ }
851
+ let action = rule ? rule.action : (consent ?? { type: 'back' });
852
+ if (!rule && !consent && k > 0 && matching(this.current.nodes, { resource_name: 'button2' }).length === 1) {
853
+ action = { type: 'click', selector: { resource_name: 'button2' } };
854
+ }
855
+ const tick = consent !== null && isToggle(matching(this.current.nodes, consent.selector)[0] ?? {});
856
+ const result = this.atom(action, taskId, 'dismiss-interruption');
857
+ this.emit('interruption', { task_id: taskId, observation_id: before, bounds, action,
858
+ rule: rule ? get(rule, 'id', null) : (consent ? 'consent-default' : null), texts: texts.slice(0, 6).map((t) => cpSlice(pyStr(t), 0, 80)),
859
+ outcome: result.payload.outcome });
860
+ // A rule or a consent click that did nothing would do nothing again; Back/button2 would leave.
861
+ if (result.payload.outcome === 'no_effect' && (rule || consent)) { break; }
862
+ if (tick && ticks < limit) { ticks += 1; }
863
+ dismissed = dismissed || result.payload.outcome === 'succeeded';
864
+ }
865
+ return dismissed;
866
+ }
867
+
868
+ /**
869
+ * The app's own first-launch consent dialog (privacy policy / user agreement): Back closes the
870
+ * Activity and its negative button is "decline and exit", so the generic dismissal leaves the
871
+ * app (measured, where2study 11-04: with reset_between_tasks every task cleared data, met the
872
+ * dialog, pressed Back then button2 "Decline and exit" and ended on the launcher; 0 of 64 tasks
873
+ * confirmed). Accept it with its positive control instead (consentPositive: android:id/button1
874
+ * unless its label declines, else a custom layout's one "Agree"/"Agree and continue"/"Agree" node
875
+ * that is not a toggle). Only when that control is present but disabled is a CheckBox ticked
876
+ * first ("I have read and agree" keeps it disabled until ticked): the first unticked one whose text
877
+ * names consent (one per call, so two required boxes take two), else the only unticked one;
878
+ * several unticked boxes none of which names consent ("Receive push notifications") are not guessed at. Without
879
+ * a safe control it returns null; clearInterruption then leaves a dialog that offers a decline
880
+ * (consentDecline) rather than Back, and dismisses any other the generic way.
881
+ * Which dialogs count is consentDialog's call.
882
+ * `consent_default: false` turns it off. Returns the click action, or null.
883
+ */
884
+ consentAccept() {
885
+ if (!this.consentDialog()) { return null; }
886
+ const nodes = get(this.current, 'nodes', []);
887
+ const positive = this.consentPositive(nodes);
888
+ if (!positive) { return null; }
889
+ // The selector must still name the control itself: matching() drops disabled nodes, so a disabled
890
+ // "Agree" button would leave a same-labelled "Agree" CheckBox as the one hit.
891
+ const live = matching(nodes, positive.selector);
892
+ if (live.length === 1 && live[0] === positive.node) { return { type: 'click', selector: positive.selector }; }
893
+ if (get(positive.node, 'enabled', true) !== false) { return null; }
894
+ // The positive control is there but disabled: tick the box that enables it.
895
+ const boxes = matching(nodes, { checked: false }).filter((n) => pyStr(get(n, 'class', '')).endsWith('CheckBox'));
896
+ const worded = boxes.filter((n) => CONSENT_BOX_RE.test(pyStr(or(get(n, 'text'), get(n, 'content_desc'), ''))));
897
+ const box = worded.length ? worded[0] : (boxes.length === 1 ? boxes[0] : null);
898
+ const selector = box ? classIndexSel(box, nodes) : null;
899
+ const hits = selector ? matching(nodes, selector) : [];
900
+ return hits.length === 1 && hits[0] === box ? { type: 'click', selector } : null;
901
+ }
902
+
903
+ /**
904
+ * Whether the screen is the app's own first-launch consent dialog: the policy wording is read
905
+ * from text and content_desc (a WebView body exposes only the latter). Applies only to a dialog
906
+ * of the app under test (a node without a package counts as its own, as in looksLoading) whose
907
+ * text names a policy or agreement, met after a launch and before any action other than a
908
+ * dismissal (`_launched`, set in atom): a dialog the app raises by itself on start. One that
909
+ * names a policy after the task pressed something ("Withdraw consent", "Delete account", "Logging in means agreeing")
910
+ * confirms that press and keeps the generic dismissal. `consent_default: false` turns it off.
911
+ */
912
+ consentDialog() {
913
+ if (get(this.config, 'consent_default', true) === false || !this._launched) { return false; }
914
+ const pkg = get(this.config, 'package');
915
+ const nodes = get(this.current, 'nodes', []);
916
+ if (truthy(pkg) && (get(this.current, 'package', pkg) !== pkg || !nodes.some((n) => get(n, 'package', pkg) === pkg))) { return false; }
917
+ // content_desc too: a WebView body or a Compose/ImageView label exposes its words only there.
918
+ const text = nodes.flatMap((n) => [get(n, 'text'), get(n, 'content_desc')]).filter((t) => truthy(t)).map((t) => pyStr(t)).join('\n');
919
+ return CONSENT_RE.test(text);
920
+ }
921
+
922
+ /**
923
+ * Whether the consent dialog offers a way to decline: android:id/button2, or a visible control
924
+ * whose whole label declines ("Do not agree", "Decline and exit", CONSENT_DECLINE_RE). On such a dialog Back
925
+ * closes the Activity and button2 leaves the app; one without (a login sheet whose fine print names
926
+ * the agreement) is safe to dismiss with Back.
927
+ */
928
+ consentDecline() {
929
+ const nodes = get(this.current, 'nodes', []);
930
+ return nodes.some((n) => isVisible(n) && (get(n, 'resource_id') === 'android:id/button2'
931
+ || (!isToggle(n) && [get(n, 'text'), get(n, 'content_desc')].some((v) => truthy(v)
932
+ && [...normalized(v)].length <= 12 && CONSENT_DECLINE_RE.test(normalized(v))))));
933
+ }
934
+
935
+ /**
936
+ * The consent dialog's positive control: android:id/button1 (the AlertDialog positive button,
937
+ * its full id) unless its label declines (CONSENT_DECLINE_RE: "Do not agree"/"Exit" put there),
938
+ * else the one visible non-toggle node whose whole text or content_desc is an accept
939
+ * (CONSENT_POSITIVE_RE) -- a custom-layout dialog's "Agree" TextView, not a "Agree" CheckBox,
940
+ * named by class and index when a toggle shares its label. Returns {node, selector}, or null
941
+ * when there is none or more than one.
942
+ */
943
+ consentPositive(nodes) {
944
+ const button1 = nodes.filter((n) => isVisible(n) && get(n, 'resource_id') === 'android:id/button1');
945
+ if (button1.length > 1) { return null; }
946
+ if (button1.length === 1 && !CONSENT_DECLINE_RE.test(normalized(or(get(button1[0], 'text'), get(button1[0], 'content_desc'), '')))) {
947
+ return { node: button1[0], selector: { resource_id: 'android:id/button1' } };
948
+ }
949
+ const hits = [];
950
+ for (const n of nodes) {
951
+ if (!isVisible(n) || isToggle(n)) { continue; }
952
+ for (const key of ['text', 'content_desc']) {
953
+ const v = get(n, key);
954
+ if (truthy(v) && CONSENT_POSITIVE_RE.test(normalized(v))) {
955
+ const sel = { [key]: v };
956
+ hits.push({ node: n, selector: matching(nodes, sel).length > 1 ? (classIndexSel(n, nodes) ?? sel) : sel });
957
+ break;
958
+ }
959
+ }
960
+ }
961
+ return hits.length === 1 ? hits[0] : null;
962
+ }
963
+
964
+ // -- top-to-bottom scroll sweep ---------------------------------------------
965
+
966
+ sweepEnabled() { return truthy(get(this.config, 'scroll_sweep', true)); }
967
+
968
+ sweepContainer() {
969
+ const nodes = get(this.current, 'nodes', []);
970
+ const hidden = occludedIndices(nodes);
971
+ const pkg = get(this.config, 'package');
972
+ const minH = toInt(get(this.config, 'sweep_min_height_px', 200));
973
+ let cands = [];
974
+ nodes.forEach((n, i) => {
975
+ const b = or(get(n, 'bounds'), []);
976
+ if (!(truthy(get(n, 'scrollable')) && isVisible(n)) || hidden.has(i) || b.length !== 4) { return; }
977
+ if (_isHorizontal(n) || (b[3] - b[1]) < minH) { return; }
978
+ if (truthy(pkg) && ![null, pkg].includes(get(n, 'package'))) { return; }
979
+ cands.push(n);
980
+ });
981
+ cands = sortedBy(cands, (n) => (n.bounds[2] - n.bounds[0]) * (n.bounds[3] - n.bounds[1]), true);
982
+ for (const n of cands) {
983
+ const sels = [...(truthy(get(n, 'resource_id')) ? [{ resource_id: n.resource_id }] : []), { class: get(n, 'class') }];
984
+ for (const sel of sels) {
985
+ if (!truthy(get(sel, 'class', true))) { continue; }
986
+ const hits = matching(nodes, sel);
987
+ if (hits.length === 1 && hits[0] === n) { return [sel, n]; }
988
+ }
989
+ const sel = classIndexSel(n, nodes);
990
+ if (sel !== null) {
991
+ const hits = matching(nodes, sel);
992
+ if (hits.length === 1 && hits[0] === n) { return [sel, n]; }
993
+ }
994
+ }
995
+ return null;
996
+ }
997
+
998
+ _sameSurface(origin, selector) {
999
+ const cur = this.current;
1000
+ if (get(cur, 'package') !== get(origin, 'package') || get(cur, 'activity') !== get(origin, 'activity')
1001
+ || get(cur, 'window') !== get(origin, 'window')) { return false; }
1002
+ let hits;
1003
+ try { hits = matching(get(cur, 'nodes', []), selector); } catch (e) { if (e instanceof AdapterError) { return false; } throw e; }
1004
+ return hits.length === 1 && truthy(get(hits[0], 'scrollable'));
1005
+ }
1006
+
1007
+ /**
1008
+ * The selector naming the swept container on the current screen: `selector` while it still
1009
+ * does, else a fresh one for the one scrollable vertical node at the container's bounds, else
1010
+ * null (the page was left). A `{class, index}` selector counts reading-order positions, and a
1011
+ * Compose page's node count above the list changes as it scrolls. Measured (ydweather preview):
1012
+ * the first swipe folded the hi/lo temperature row, index 8 then named a plain View, and the
1013
+ * sweep aborted `left-page` with no frame although the list sat at the same [42,310,1038,2400].
1014
+ */
1015
+ _surfaceSelector(origin, selector, container) {
1016
+ const cur = this.current;
1017
+ if (this._sameSurface(origin, selector)) {
1018
+ // a drifted {class, index} can land on another scrollable (a LazyRow above the list)
1019
+ const [hit] = matching(get(cur, 'nodes', []), selector);
1020
+ if (!_isHorizontal(hit) && get(hit, 'class') === get(container, 'class')) { return selector; }
1021
+ }
1022
+ if (get(cur, 'package') !== get(origin, 'package') || get(cur, 'activity') !== get(origin, 'activity')
1023
+ || get(cur, 'window') !== get(origin, 'window')) { return null; }
1024
+ const ob = or(get(container, 'bounds'), []);
1025
+ if (ob.length !== 4) { return null; }
1026
+ const nodes = get(cur, 'nodes', []);
1027
+ const same = nodes.filter((n) => {
1028
+ const b = or(get(n, 'bounds'), []);
1029
+ return truthy(get(n, 'scrollable')) && isVisible(n) && !_isHorizontal(n) && b.length === 4
1030
+ && get(n, 'class') === get(container, 'class') && b.every((v, i) => Math.abs(v - ob[i]) <= 4);
1031
+ });
1032
+ if (same.length !== 1) { return null; }
1033
+ const n = same[0];
1034
+ for (const sel of [...(truthy(get(n, 'resource_id')) ? [{ resource_id: n.resource_id }] : []), classIndexSel(n, nodes)]) {
1035
+ if (sel === null) { continue; }
1036
+ const hits = matching(nodes, sel);
1037
+ if (hits.length === 1 && hits[0] === n) { return sel; }
1038
+ }
1039
+ return null;
1040
+ }
1041
+
1042
+ sweep(staticId, purpose = 'sweep') {
1043
+ if (this.swept === undefined) { this.swept = new Set(); }
1044
+ if (!(this.sweepEnabled() && truthy(staticId)) || this.swept.has(staticId)) { return false; }
1045
+ if (!this.at(staticId)) { return false; }
1046
+ const requested = staticId;
1047
+ const res = or(get(or(this.current, {}), 'static_resolution'), {});
1048
+ if (get(res, 'status') === 'verified' && truthy(get(res, 'static_id')) && res.static_id !== staticId) {
1049
+ staticId = res.static_id;
1050
+ this.swept.add(requested);
1051
+ if (this.swept.has(staticId)) { return false; }
1052
+ }
1053
+ this.swept.add(staticId);
1054
+ const taskId = 'sweep:' + staticId;
1055
+ const origin = this.current;
1056
+ const found = this.sweepContainer();
1057
+ const payload = { static_id: staticId, origin_observation: origin.observation_id, frames: [],
1058
+ also_covers: requested === staticId ? [] : [requested], purpose };
1059
+ if (!found) {
1060
+ payload.outcome = 'no-container';
1061
+ this.emit('scroll_sweep', payload);
1062
+ return true;
1063
+ }
1064
+ let [selector, node] = found;
1065
+ payload.container = { selector, class: get(node, 'class'), resource_id: get(node, 'resource_id'), bounds: get(node, 'bounds') };
1066
+ const others = get(origin, 'nodes', []).filter((n) => truthy(get(n, 'scrollable')) && isVisible(n) && n !== node && !_isHorizontal(n))
1067
+ .map((n) => or(get(n, 'resource_id'), get(n, 'class')));
1068
+ if (others.length) { payload.unswept_containers = others; }
1069
+ const maxScrolls = toInt(get(this.config, 'max_sweep_scrolls', 20));
1070
+ let lastSig = _viewSig(origin);
1071
+ let outcome = 'truncated'; let swipes = 0;
1072
+ try {
1073
+ while (swipes <= maxScrolls) {
1074
+ this.atom({ type: 'scroll', selector, direction: 'down' }, taskId, purpose);
1075
+ swipes += 1;
1076
+ const still = this._surfaceSelector(origin, selector, node);
1077
+ if (still === null) { outcome = 'aborted'; payload.abort_reason = 'left-page'; break; }
1078
+ selector = still;
1079
+ const sig = _viewSig(this.current);
1080
+ if (sig === lastSig) { outcome = 'complete'; break; }
1081
+ if (payload.frames.length >= maxScrolls) { break; }
1082
+ lastSig = sig;
1083
+ payload.frames.push(this.current.observation_id);
1084
+ const r = get(this.current, 'static_resolution', {});
1085
+ if (get(r, 'status') === 'verified' && ![null, staticId].includes(get(r, 'static_id')) && !payload.also_covers.includes(r.static_id)) {
1086
+ payload.also_covers.push(r.static_id);
1087
+ }
1088
+ }
1089
+ } catch (e) {
1090
+ if (e instanceof BudgetExhausted) { outcome = 'budget-exhausted'; }
1091
+ else if (e instanceof AdapterError) { outcome = 'aborted'; payload.abort_reason = s200(e); }
1092
+ else { throw e; }
1093
+ }
1094
+ payload.outcome = outcome;
1095
+ payload.swipes = swipes;
1096
+ if (outcome !== 'aborted' || get(payload, 'abort_reason') !== 'left-page') {
1097
+ payload.restored = this._sweepRestore(origin, selector, node, taskId);
1098
+ } else { payload.restored = false; }
1099
+ if (!payload.restored) { this.dirty = true; }
1100
+ for (const x of payload.also_covers) { this.swept.add(x); }
1101
+ this.emit('scroll_sweep', payload);
1102
+ return true;
1103
+ }
1104
+
1105
+ _atTop(origin, container) {
1106
+ const keyed = (obs) => {
1107
+ const seen = new Map(); const out = new Map();
1108
+ for (const n of get(obs, 'nodes', [])) {
1109
+ if (!(isVisible(n) && truthy(get(n, 'resource_id'))) || or(get(n, 'bounds'), []).length !== 4) { continue; }
1110
+ const k = tupleKey(n.resource_id, get(n, 'text'));
1111
+ seen.set(k, (seen.get(k) ?? 0) + 1);
1112
+ out.set(tupleKey(n.resource_id, get(n, 'text'), seen.get(k)), n.bounds);
1113
+ }
1114
+ return out;
1115
+ };
1116
+ const a = keyed(origin); const b = keyed(this.current);
1117
+ if (a.size !== b.size || [...a.keys()].some((k) => !b.has(k))) { return false; }
1118
+ const cb = or(get(container, 'bounds'), [0, 0, 0, 800]);
1119
+ const tol = Math.max(24, Math.trunc(0.03 * (cb[3] - cb[1])));
1120
+ return [...a.keys()].every((k) => {
1121
+ const x = a.get(k); const y = b.get(k);
1122
+ return x.slice(0, Math.min(x.length, y.length)).every((v, i) => Math.abs(v - y[i]) <= tol);
1123
+ });
1124
+ }
1125
+
1126
+ _sweepRestore(origin, selector, container, taskId) {
1127
+ if (this._atTop(origin, container)) { return true; }
1128
+ const limit = toInt(get(this.config, 'max_sweep_scrolls', 20)) * 3 + 2;
1129
+ let last = _viewSig(this.current);
1130
+ try {
1131
+ for (let k = 0; k < limit; k++) {
1132
+ const still = this._surfaceSelector(origin, selector, container);
1133
+ if (still === null) { return false; }
1134
+ selector = still;
1135
+ this.atom({ type: 'scroll', selector, direction: 'up' }, taskId, 'sweep-restore');
1136
+ if (this._atTop(origin, container)) { return true; }
1137
+ const sig = _viewSig(this.current);
1138
+ if (sig === last) { break; }
1139
+ last = sig;
1140
+ }
1141
+ } catch (e) {
1142
+ if (e instanceof BudgetExhausted || e instanceof AdapterError) { return false; }
1143
+ throw e;
1144
+ }
1145
+ return this._atTop(origin, container);
1146
+ }
1147
+
1148
+ sweepBacklog() {
1149
+ if (!this.sweepEnabled()) { return; }
1150
+ if (this.swept === undefined) { this.swept = new Set(); }
1151
+ const mapped = [];
1152
+ for (const e of this.doc.events) {
1153
+ const sid = get(e.payload, 'static_id');
1154
+ if (e.kind === 'mapping' && e.environment_id === this.env && truthy(sid) && !mapped.includes(sid)) { mapped.push(sid); }
1155
+ }
1156
+ const tasks = get(this.doc, 'tasks', []).filter((t) => get(t, 'phase') === this.phase.id
1157
+ && get(t, 'status') === 'compiled' && get(t, 'purpose') !== 'direct-launch');
1158
+ for (const sid of mapped) {
1159
+ if (this.swept.has(sid) || this.scopeExcludes(sid)) { continue; }
1160
+ if (this.at(sid)) { this.sweep(sid, 'sweep-backlog'); continue; }
1161
+ const asSource = tasks.find((t) => get(t, 'source_static') === sid) ?? null;
1162
+ const asTarget = tasks.find((t) => get(t, 'target_static') === sid) ?? null;
1163
+ if (!(asSource || asTarget)) { continue; }
1164
+ const route = { ...(asSource || asTarget), task_id: 'sweep:' + sid };
1165
+ try {
1166
+ this.source(route);
1167
+ if (!asSource) {
1168
+ for (const step of or(get(route, 'prelude'), [])) { this.seek(step, route.task_id, 'sweep-route'); }
1169
+ if (!(truthy(get(route.action, 'automatic')) && this.at(sid))) { this.seek(route.action, route.task_id, 'sweep-route'); }
1170
+ }
1171
+ } catch (e) {
1172
+ if (e instanceof BudgetExhausted) { throw e; }
1173
+ this.swept.add(sid);
1174
+ this.emit('scroll_sweep', { static_id: sid, outcome: 'unreached', frames: [], also_covers: [],
1175
+ purpose: 'sweep-backlog', abort_reason: s200(e) });
1176
+ continue;
1177
+ }
1178
+ if (!this.sweep(sid, 'sweep-backlog') && !this.swept.has(sid)) {
1179
+ this.swept.add(sid);
1180
+ this.emit('scroll_sweep', { static_id: sid, outcome: 'unreached', frames: [], also_covers: [],
1181
+ purpose: 'sweep-backlog', abort_reason: 'page-not-verified-after-route' });
1182
+ }
1183
+ }
1184
+ }
1185
+
1186
+ /**
1187
+ * Selector groups tried after a bounded search fails: `config.overflow_openers` first, then the
1188
+ * containers the campaign's own routes already open (see derivedOverflowOpeners).
1189
+ */
1190
+ overflowOpeners() {
1191
+ if (this._openers === undefined) {
1192
+ const groups = [...get(this.config, 'overflow_openers', []).map((s) => [s]),
1193
+ ...derivedOverflowOpeners(get(this.doc, 'tasks', []), toInt(get(this.config, 'max_derived_overflow_openers', 4)),
1194
+ toInt(get(this.config, 'derived_opener_depth', 1)))];
1195
+ const seen = new Set();
1196
+ this._openers = groups.filter((g) => {
1197
+ const k = jsonDumps(g, { sort_keys: true });
1198
+ if (seen.has(k)) { return false; }
1199
+ seen.add(k); return true;
1200
+ });
1201
+ }
1202
+ return this._openers;
1203
+ }
1204
+
1205
+ seek(action, taskId, purpose) {
1206
+ if (truthy(get(action, 'reveal'))) { this.reveal(action.reveal, taskId); }
1207
+ if (truthy(get(action, 'when')) && !ruleMatches(this.current, action.when)) {
1208
+ this.emit('action_skipped', { task_id: taskId, purpose, reason: 'condition-not-met', action });
1209
+ return null;
1210
+ }
1211
+ const type = get(action, 'type');
1212
+ if (type === 'click_list_item' || type === 'long_click_list_item') {
1213
+ const row = this.listItem();
1214
+ const b = row.bounds;
1215
+ const kind = type.startsWith('long') ? 'long_click_point' : 'click_point';
1216
+ const rowInfo = {};
1217
+ for (const k of ['class', 'resource_id', 'text', 'content_desc', 'bounds']) { rowInfo[k] = get(row, k); }
1218
+ 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);
1219
+ }
1220
+ if (type === 'scroll_page') {
1221
+ const sideways = ['left', 'right'].includes(get(action, 'direction'));
1222
+ const conts = this.current.nodes.filter((n) => truthy(get(n, 'scrollable')) && isVisible(n) && _isHorizontal(n) === sideways);
1223
+ if (conts.length !== 1) { throw new AdapterError('Scroll requires one visible scrollable container'); }
1224
+ return this.atom({ type: 'scroll', selector: scrollSel(conts[0], this.current.nodes), direction: get(action, 'direction', 'down') }, taskId, purpose);
1225
+ }
1226
+ if (!Object.hasOwn(CANDIDATE_KINDS, type)) { return this.atom(action, taskId, purpose); }
1227
+ let selected = this.choose(action);
1228
+ if (selected) { return this.atom(selected, taskId, purpose); }
1229
+ if (this.clearInterruption(taskId)) {
1230
+ selected = this.choose(action);
1231
+ if (selected) { return this.atom(selected, taskId, purpose); }
1232
+ }
1233
+ if (!this.appUiReady()) { throw new AdapterError('selector unavailable on non-app/empty UI'); }
1234
+ // Content that loads after the page is ready (a list filled from the network or a database):
1235
+ // look again while the screen is still changing, for a bounded time, before scrolling. A
1236
+ // screen that has settled ends the wait at once. Captures only, no action is spent.
1237
+ const waitUntil = monotonic() + Math.max(0, toFloat(get(this.config, 'selector_wait_seconds', 3)));
1238
+ let lastKey = observationKey(this.current);
1239
+ while (monotonic() < waitUntil) {
1240
+ sleep(0.5);
1241
+ this.capture({ acceptLoading: true });
1242
+ selected = this.choose(action);
1243
+ if (selected) { return this.atom(selected, taskId, purpose); }
1244
+ const key = observationKey(this.current);
1245
+ if (key === lastKey) { break; }
1246
+ lastKey = key;
1247
+ }
1248
+ // Positions count (_viewSig): a list of rows without text moves only its bounds.
1249
+ const origin = _viewSig(this.current);
1250
+ for (const direction of ['down', 'up']) {
1251
+ const seen = new Set([_viewSig(this.current)]);
1252
+ const stuck = new Set();
1253
+ for (let k = 0; k < toInt(get(this.config, 'max_scrolls_per_task', 6)); k++) {
1254
+ const found = this.searchContainer(stuck);
1255
+ if (!found) { break; }
1256
+ const sel = found[1];
1257
+ const prev = _viewSig(this.current);
1258
+ this.atom({ type: 'scroll', selector: sel, direction }, taskId, 'search');
1259
+ selected = this.choose(action);
1260
+ if (selected) { return this.atom(selected, taskId, purpose); }
1261
+ // A dismissed dialog changes the screen without the list moving: measure the list alone.
1262
+ const after = _viewSig(this.current);
1263
+ if (this.clearInterruption(taskId)) {
1264
+ selected = this.choose(action);
1265
+ if (selected) { return this.atom(selected, taskId, purpose); }
1266
+ }
1267
+ const key = _viewSig(this.current);
1268
+ // A container that did not move (a pager, a list already at its end) leaves the others to try.
1269
+ if (after === prev) { stuck.add(stuckKey(found[0])); continue; }
1270
+ if (seen.has(key) || this._backAtOrigin(direction, key, origin)) { break; }
1271
+ seen.add(key);
1272
+ }
1273
+ }
1274
+ for (let round = 0; round < toInt(get(this.config, 'max_horizontal_scrolls', 3)); round++) {
1275
+ const horiz = this.current.nodes.filter((n) => truthy(get(n, 'scrollable')) && isVisible(n) && _isHorizontal(n)
1276
+ && !['ViewPager', 'ViewPager2'].some((c) => pyStr(get(n, 'class', '')).endsWith(c)));
1277
+ if (!horiz.length) { break; }
1278
+ let moved = false;
1279
+ for (const n of horiz) {
1280
+ const sel = truthy(get(n, 'resource_id')) ? { resource_id: n.resource_id } : null;
1281
+ if (!sel || matching(this.current.nodes, sel).length !== 1) { continue; }
1282
+ const key = observationKey(this.current);
1283
+ this.atom({ type: 'scroll', selector: sel, direction: 'right' }, taskId, 'search');
1284
+ selected = this.choose(action);
1285
+ if (selected) { return this.atom(selected, taskId, purpose); }
1286
+ moved = moved || observationKey(this.current) !== key;
1287
+ }
1288
+ if (!moved) { break; }
1289
+ }
1290
+ const own = new Set(get(action, 'selectors', []).map((s) => jsonDumps(s, { sort_keys: true })));
1291
+ const rejected = (this._openersRejected ??= new Set());
1292
+ for (const group of this.overflowOpeners()) {
1293
+ const gk = jsonDumps(group, { sort_keys: true });
1294
+ if (rejected.has(gk)) { continue; }
1295
+ const opener = group.find((s) => !own.has(jsonDumps(s, { sort_keys: true })) && uniqueHit(this.current.nodes, s));
1296
+ if (!opener) { continue; }
1297
+ const before = this.current; const key = observationKey(before);
1298
+ this.atom({ type: 'click', selector: opener }, taskId, 'search-overflow');
1299
+ selected = this.choose(action);
1300
+ if (selected) { return this.atom(selected, taskId, purpose); }
1301
+ // A container opens over its page; an opener that changed page is a navigation, not tried again.
1302
+ if (navigatedAway(before, this.current, or(this.catalog, {}))) { rejected.add(gk); }
1303
+ // Close only what the opener opened; an opener with no visible effect needs no Back.
1304
+ if (observationKey(this.current) !== key) { this.atom({ type: 'back' }, taskId, 'search-overflow-close'); }
1305
+ }
1306
+ throw new AdapterError('selector-not-found-after-bounded-scroll');
1307
+ }
1308
+
1309
+ source(task) {
1310
+ const source = task.source_static;
1311
+ const dirty = this.dirty ?? false;
1312
+ const [matched, how] = deps.observationMatchesStatic(or(this.current, {}), source, this.catalog);
1313
+ // A dialog an earlier task opened still resolves to its host activity: the source "matches" but
1314
+ // its controls sit behind the dialog (measured: a font-size picker left open failed two later
1315
+ // Settings tasks with no scroll). Relaunch instead of searching under it.
1316
+ const srcKind = pyStr(get(get(this.catalog, source, {}), 'kind') ?? pyStr(source).split(':')[0]);
1317
+ const floating = ['panel', 'dialog'].includes(srcKind);
1318
+ // With reset_between_tasks every task starts from cleared data, even one already on its source.
1319
+ if (matched && how === 'exact-page' && !dirty && (floating || !this.modalOverlay()) && !this.resetsBetweenTasks()) { return; }
1320
+ // Back only when it can land on the source: from a root page (or any page the source never
1321
+ // opens) it just leaves the app, costing an action before the relaunch below anyway.
1322
+ const here = get(get(this.current, 'static_resolution', {}), 'status') === 'verified'
1323
+ ? this.current.static_resolution.static_id : null;
1324
+ if (this.current.package === mget(this.config, 'package') && !matched && !dirty && !this.resetsBetweenTasks()
1325
+ && !(here !== null && (this.backExits ?? new Set()).has(here))
1326
+ && backCanReach(this.current, source, this.catalog)) {
1327
+ this.atom({ type: 'back' }, task.task_id, 'recover');
1328
+ if (here !== null && this.current.package !== mget(this.config, 'package')) {
1329
+ (this.backExits ??= new Set()).add(here);
1330
+ }
1331
+ if (deps.observationMatchesStatic(this.current, source, this.catalog)[1] === 'exact-page') { return; }
1332
+ }
1333
+ let launch = { ...(or(get(task, 'source_launch'), {})) };
1334
+ if (!truthy(launch)) { launch = { type: 'launch', component: mget(this.config, 'launch_component'), restart: true }; }
1335
+ // A prefix that already failed this run fails the same way again: report it without replaying.
1336
+ // Only from the same landing: a first-run page (Guide) comes and goes with app data, and a prefix
1337
+ // that failed past it (Home, "Skip" gone) replays fine on a fresh install, and the reverse
1338
+ // (measured, coolmall 2026-11-08: a failure on Home cut 23 tasks that a cleared start would run).
1339
+ // A failure is keyed by the start (`fresh`: data cleared for this task, else `warm`) and the
1340
+ // landing: the page the launch settles on past its own splash, before launchBridge walks a Guide
1341
+ // on to Main (that would make a fresh and a warm start look the same).
1342
+ // The check runs before the clear and launch (each costs actions) when the landing is
1343
+ // predictable: a fresh start always lands the same; a warm one keeps landing where the last warm
1344
+ // one did once that is a page of the launch chain, or (no chain) the last two warm starts agreed.
1345
+ // A first-run page off the chain gives way once its flag is stored, so it is checked after launch.
1346
+ const memo = truthy(get(this.config, 'prefix_memo', true)) ? (this._prefixFailures ??= new Map()) : null;
1347
+ const replay = mget(task, 'replay');
1348
+ const start = this.resetsBetweenTasks() && this._clearedFor !== task.task_id ? 'fresh' : 'warm';
1349
+ const memoHit = (landing) => {
1350
+ if (!memo || landing === undefined) { return; }
1351
+ for (let n = 1; n <= replay.length; n++) {
1352
+ const k = prefixKey(task, n);
1353
+ const e = memo.get(k);
1354
+ if (e && e.start === start && e.landing === landing) { throw new PrefixFailed(e, k); }
1355
+ }
1356
+ };
1357
+ const last = (this._lastLanding ??= {})[start];
1358
+ const chain = or(get(task, 'launch_chain'), []);
1359
+ if (last && (start === 'fresh' || (chain.length ? chain.includes(last.landing) : last.repeated))) { memoHit(last.landing); }
1360
+ this.resetBetweenTasks(task.task_id);
1361
+ this.atom(launch, task.task_id, 'recover');
1362
+ this.waitLaunchPage(task);
1363
+ this._landing = landingOf(this.current);
1364
+ this._start = start;
1365
+ this._lastLanding[start] = { landing: this._landing, repeated: last?.landing === this._landing };
1366
+ memoHit(this._landing);
1367
+ this.launchBridge(task, { waited: true });
1368
+ const attested = new Set();
1369
+ let passedSoFar = 0;
1370
+ for (let i = 0; i < replay.length; i++) {
1371
+ const step = replay[i];
1372
+ const stepStart = get(or(this.current, {}), 'observation_id');
1373
+ // only the leading hops: no replay gesture has run since the launch
1374
+ if (passedSoFar === i && this.replayStepPassed(step)) {
1375
+ passedSoFar += 1;
1376
+ this.emit('replay_step_passed', { task_id: task.task_id, replay_index: i, target_id: step.target_id, observation_id: stepStart });
1377
+ continue;
1378
+ }
1379
+ try {
1380
+ const stepResult = this.seek(step, task.task_id, 'replay');
1381
+ if (truthy(get(step, 'intermediate')) || !truthy(get(step, 'target_id'))) { continue; }
1382
+ if (!this.at(step.target_id)) {
1383
+ if (!this.attestedArrival(step.target_id, stepResult, task.task_id)) {
1384
+ throw new AdapterError('replay-target-unverified:' + step.target_id);
1385
+ }
1386
+ attested.add(step.target_id);
1387
+ }
1388
+ } catch (e) {
1389
+ const msg = errStr(e);
1390
+ if (memo && e instanceof AdapterError && PREFIX_FAILURES.some((r) => msg.startsWith(r))) {
1391
+ memo.set(prefixKey(task, i + 1), { reason: msg, task_id: task.task_id, replay_index: i, start: this._start, landing: this._landing,
1392
+ observation_id: get(or(this.current, {}), 'observation_id'), before_id: stepStart });
1393
+ }
1394
+ throw e;
1395
+ }
1396
+ }
1397
+ // A transient source (a splash that leaves by itself) is gone once the app is ready; its
1398
+ // automatic edges have already fired, so the target check alone decides the task.
1399
+ if (truthy(get(get(this.catalog, source, {}), 'transient')) && truthy(get(task.action, 'automatic'))) { return; }
1400
+ if (!this.at(source)) { this.clearInterruption(task.task_id); }
1401
+ if (!this.at(source)) {
1402
+ const ctx = get(task, 'source_context');
1403
+ if (!(this.anchorless(source) && (attested.has(source)
1404
+ || (truthy(ctx) && (this.at(ctx) || this.transientSuccessor(ctx, source, task.task_id)))
1405
+ || (!replay.length && this.launchedInto(source, task.task_id))))) {
1406
+ throw new AdapterError('source-unverified:' + source);
1407
+ }
1408
+ }
1409
+ }
1410
+
1411
+ /**
1412
+ * A replay tap whose target page is already on screen and whose control is not: a first-run hop
1413
+ * the path carries as a gesture (coolmall Guide "Skip" → Main) is shown only until it stores its
1414
+ * flag, so a relaunch without a data clear lands past it. Measured (coolmall 2026-11-08): a sweep
1415
+ * relaunch stood on Home, "Skip" was searched for by scrolling Home, and the prefix memo failed
1416
+ * 23 of 40 p0-fresh tasks with it. A control still visible is tapped as before.
1417
+ * Not a control of the target page itself (its own label in the catalog): there an absent control
1418
+ * is below the fold, behind a reveal or still loading, and the gesture is still owed. The caller
1419
+ * offers only the leading hops, before any replay gesture ran.
1420
+ */
1421
+ replayStepPassed(step) {
1422
+ if (!Object.hasOwn(CANDIDATE_KINDS, get(step, 'type')) && !['click', 'long_click'].includes(get(step, 'type'))) { return false; }
1423
+ if (truthy(get(step, 'intermediate')) || !truthy(get(step, 'target_id')) || !this.at(step.target_id)) { return false; }
1424
+ const labels = [get(step, 'static_label'), ...or(get(step, 'static_label_alt'), [])].filter(truthy).map((l) => pyStr(l).trim());
1425
+ const own = Object.values(or(get(this.catalog, step.target_id), {})).flatMap((v) => (Array.isArray(v) ? v : [v]))
1426
+ .filter((v) => typeof v === 'string').map((v) => v.trim());
1427
+ if (labels.some((l) => own.includes(l))) { return false; }
1428
+ try { return !this.choose(step); } catch (e) { if (e instanceof AdapterError) { return false; } throw e; }
1429
+ }
1430
+
1431
+ /**
1432
+ * A launch still standing on its own page (`launch_page`, a Splash whose timer outlasts the
1433
+ * settle) is watched for up to `launch_chain_wait_seconds` (default 6) until it leaves it.
1434
+ */
1435
+ waitLaunchPage(task) {
1436
+ const chain = or(get(task, 'launch_chain'), []);
1437
+ const first = get(task, 'launch_page');
1438
+ if (!chain.length || !truthy(first) || chain.includes(first)) { return; }
1439
+ const deadline = monotonic() + Math.max(0, toFloat(get(this.config, 'launch_chain_wait_seconds', 6)));
1440
+ while (this.at(first) && !chain.some((p) => this.at(p)) && monotonic() < deadline) { sleep(0.5); this.capture(); }
1441
+ }
1442
+
1443
+ /**
1444
+ * The launch reached another page (a first-run Guide) instead of the ones it opens by itself
1445
+ * (`launch_chain`, Splash → Main): take that page's compiled exit into the chain. This runs on
1446
+ * every launch that lands off the chain; the exit usually writes the first-run flag, so later
1447
+ * launches stop landing there and the bridge stops firing.
1448
+ * Measured (coolmall 2026-10-29): without it every cold launch stayed on Guide, every task
1449
+ * behind Main failed source-unverified, and Guide was the only page captured.
1450
+ * A launch still on its own page is waited out first (waitLaunchPage): deciding on Splash would
1451
+ * miss the Guide that comes after it. `waited`: the caller already waited (source() does, to take
1452
+ * the landing), so a splash that outlasts the wait is not waited on twice.
1453
+ */
1454
+ launchBridge(task, { waited = false } = {}) {
1455
+ const chain = or(get(task, 'launch_chain'), []);
1456
+ if (!chain.length) { return; }
1457
+ if (!waited) { this.waitLaunchPage(task); }
1458
+ if (get(this.current, 'package') !== get(this.config, 'package') || chain.some((p) => this.at(p))) { return; }
1459
+ const exit = get(this.doc, 'tasks', []).find((t) => get(t, 'status') === 'compiled' && chain.includes(get(t, 'target_static'))
1460
+ && !chain.includes(get(t, 'source_static')) && !truthy(get(t, 'replay')) && !truthy(get(get(t, 'action'), 'automatic'))
1461
+ && get(get(t, 'action'), 'type') !== 'unresolved' && this.at(get(t, 'source_static')));
1462
+ if (!exit) { return; }
1463
+ this.emit('launch_bridge', { task_id: task.task_id, via: exit.task_id, from: exit.source_static, to: exit.target_static,
1464
+ observation_id: get(this.current, 'observation_id') });
1465
+ try {
1466
+ for (const step of [...or(get(exit, 'prelude'), []), exit.action]) { this.seek(step, task.task_id, 'launch-bridge'); }
1467
+ } catch (e) {
1468
+ if (!(e instanceof AdapterError) || TRANSIENT_DEVICE_RE.test(errStr(e))) { throw e; }
1469
+ this.emit('launch_bridge_failed', { task_id: task.task_id, via: exit.task_id, reason: errStr(e) });
1470
+ }
1471
+ }
1472
+
1473
+ /**
1474
+ * True when the page has no anchor it always shows (title, rows, layout ids). Body texts do
1475
+ * not count: they are presence-only evidence and may sit in a branch or a dialog the page opens.
1476
+ */
1477
+ anchorless(ident) {
1478
+ const page = get(this.catalog, ident, {});
1479
+ return !(truthy(get(page, 'titles')) || truthy(get(page, 'row_titles')) || truthy(get(page, 'widget_ids')));
1480
+ }
1481
+
1482
+ /**
1483
+ * Identity by elimination on this app's own screen: the current capture is in the app package,
1484
+ * not verified as any page, and not claimed by any of `rivals`. Used only for anchorless pages.
1485
+ */
1486
+ _unclaimedAppScreen(rivals = [], candidate = null) {
1487
+ if (get(this.current, 'package') !== get(this.config, 'package')) { return false; }
1488
+ const res = or(get(this.current, 'static_resolution'), {});
1489
+ if (get(res, 'status') === 'verified') { return false; }
1490
+ // A page the resolver has recognized on this device would be recognized again: an
1491
+ // unverified screen is not it.
1492
+ if (candidate !== null && this.recognized(candidate)) { return false; }
1493
+ return !rivals.some((r) => this.at(r));
1494
+ }
1495
+
1496
+ /** The page was verified by its own anchors at least once in this campaign. */
1497
+ recognized(ident) {
1498
+ if (this._recognized === undefined) {
1499
+ this._recognized = new Set(this.doc.events.filter((e) => e.kind === 'mapping').map((e) => get(e.payload, 'static_id')));
1500
+ }
1501
+ return this._recognized.has(ident);
1502
+ }
1503
+
1504
+ /**
1505
+ * `ctx` is a transient entry whose automatic edges lead to `source`: once launched, the screen
1506
+ * that replaced it is `source` unless it is one of the transient page's other successors.
1507
+ */
1508
+ transientSuccessor(ctx, source, taskId) {
1509
+ const page = get(this.catalog, ctx, {});
1510
+ const targets = or(get(page, 'auto_targets'), []);
1511
+ if (!truthy(get(page, 'transient')) || !targets.includes(source)) { return false; }
1512
+ if (!this._unclaimedAppScreen(targets.filter((t) => t !== source), source)) { return false; }
1513
+ this.emit('source_attested', { task_id: taskId, static_id: source, basis: 'transient-successor', context: ctx,
1514
+ observation_id: this.current.observation_id });
1515
+ return true;
1516
+ }
1517
+
1518
+ /** A launch with no replay landed on an anchorless page the launcher's transient entry opens. */
1519
+ launchedInto(source, taskId) {
1520
+ const entries = Object.keys(or(this.catalog, {})).filter((k) => truthy(get(this.catalog[k], 'transient'))
1521
+ && or(get(this.catalog[k], 'auto_targets'), []).includes(source));
1522
+ return entries.length === 1 && this.transientSuccessor(entries[0], source, taskId);
1523
+ }
1524
+
1525
+ /**
1526
+ * Trigger-chain arrival for an anchorless page: the replay step's own gesture ran on the
1527
+ * device and changed the screen, and the screen it reached is the app's, unverified as any page.
1528
+ */
1529
+ attestedArrival(target, stepResult, taskId) {
1530
+ if (!this.anchorless(target) || !truthy(stepResult) || get(stepResult.payload, 'outcome') !== 'succeeded') { return false; }
1531
+ if (!this._unclaimedAppScreen([], target)) { return false; }
1532
+ this.emit('source_attested', { task_id: taskId, static_id: target, basis: 'trigger-chain-replay',
1533
+ action_event_id: stepResult.id, observation_id: this.current.observation_id });
1534
+ return true;
1535
+ }
1536
+
1537
+ runDirect(task, done) {
1538
+ const ident = task.task_id;
1539
+ try {
1540
+ this.stage = 'direct-launch';
1541
+ this.resetBetweenTasks(ident);
1542
+ this.atom(task.source_launch, ident, 'direct-launch');
1543
+ for (const step of or(get(task, 'prelude'), [])) { this.seek(step, ident, 'direct-launch'); }
1544
+ // A dialog over the target (a first-launch consent dialog; without a prelude no seek clears it).
1545
+ if (!this.at(task.target_static)) { this.clearInterruption(ident); }
1546
+ const confirmed = this.at(task.target_static);
1547
+ if (confirmed) { done.add(ident); }
1548
+ this.emit('task_result', { task_id: ident, outcome: confirmed ? 'confirmed' : 'target-unverified',
1549
+ target_static: task.target_static, purpose: 'direct-launch', observation_id: this.current.observation_id });
1550
+ if (confirmed) { this.sweep(task.target_static); }
1551
+ } catch (e) {
1552
+ if (e instanceof BudgetExhausted) {
1553
+ this.emit('task_result', { task_id: ident, outcome: 'budget-exhausted', stage: this.stage });
1554
+ throw e;
1555
+ }
1556
+ this.emit('task_result', { task_id: ident, outcome: 'failed', stage: this.stage, purpose: 'direct-launch',
1557
+ reason: cpSlice(errStr(e), 0, 300), target_static: task.target_static,
1558
+ observation_id: get(or(this.current, {}), 'observation_id') });
1559
+ }
1560
+ }
1561
+
1562
+ attest(task, result) {
1563
+ const obs = new Map();
1564
+ for (const e of this.doc.events) {
1565
+ if (e.kind === 'observation' && e.environment_id === this.env) { obs.set(e.payload.observation_id, e.payload); }
1566
+ }
1567
+ const before = obs.get(result.payload.before) ?? {};
1568
+ const sourceExact = deps.observationMatchesStatic(before, task.source_static, this.catalog)[1] === 'exact-page';
1569
+ const [ok, basis] = deps.triggerAttests(task, before, this.current, get(result.payload, 'action'),
1570
+ this.catalog, get(this.config, 'package'), sourceExact);
1571
+ if (ok) {
1572
+ this.emit('attestation', { static_id: task.target_static, task_id: task.task_id, observation_id: this.current.observation_id,
1573
+ basis: 'trigger-chain', evidence: basis, action_event_id: result.id });
1574
+ }
1575
+ }
1576
+
1577
+ discoveryConfig() {
1578
+ const raw = get(this.config, 'discovery', {});
1579
+ if (!(raw && typeof raw === 'object' && !Array.isArray(raw))) { return {}; }
1580
+ const scoped = get(raw, this.phase.id, raw);
1581
+ return scoped && typeof scoped === 'object' && !Array.isArray(scoped) && truthy(get(scoped, 'enabled')) ? scoped : {};
1582
+ }
1583
+
1584
+ discoveryActions(config) {
1585
+ const actions = this.device.actions(this.current);
1586
+ const allow = get(config, 'allow_actions', []); const deny = get(config, 'deny_actions', []);
1587
+ const allowUnlisted = truthy(get(config, 'allow_unlisted_actions', false));
1588
+ const selected = [];
1589
+ for (const action of actions) {
1590
+ const hits = matching(this.current.nodes, get(action, 'selector', {}));
1591
+ if (hits.length !== 1) { continue; }
1592
+ const scoped = { ...this.current, nodes: [hits[0]] };
1593
+ if (truthy(deny) && deny.some((rule) => ruleMatches(scoped, rule))) { continue; }
1594
+ if (truthy(allow)) { if (!allow.some((rule) => ruleMatches(scoped, rule))) { continue; } }
1595
+ else if (!allowUnlisted) { continue; }
1596
+ selected.push(action);
1597
+ }
1598
+ return selected.slice(0, Math.max(0, toInt(get(config, 'max_actions_per_state', 8))));
1599
+ }
1600
+
1601
+ runDiscovery() {
1602
+ const config = this.discoveryConfig();
1603
+ if (!truthy(config)) { return { enabled: false }; }
1604
+ // discovery walks the app from launch, not toward a node: a scoped campaign has no use for it
1605
+ if (scopeOf(this.doc) !== null) { return { enabled: false, outcome: 'skipped', reason: 'scoped campaign' }; }
1606
+ const maxDepth = Math.max(0, toInt(get(config, 'max_depth', 3)));
1607
+ const maxStates = Math.max(1, toInt(get(config, 'max_states', 30)));
1608
+ const maxExp = () => toInt(get(config, 'max_expansions', 60));
1609
+ const queue = [[]]; const visited = new Set(); let expanded = 0; let transitions = 0; let failures = 0;
1610
+ const hash = (v, n) => sha256Hex(jsonDumps(v, { sort_keys: true })).slice(0, n);
1611
+ const restore = (p) => {
1612
+ this.atom({ type: 'launch', component: mget(this.config, 'launch_component'), restart: true }, 'discovery:restore', 'discover-recover');
1613
+ p.forEach((action, index) => this.atom(action, 'discovery:replay:' + index, 'discover-replay'));
1614
+ };
1615
+ let outcome;
1616
+ try {
1617
+ while (queue.length && visited.size < maxStates) {
1618
+ const p = queue.shift();
1619
+ try { restore(p); } catch (e) {
1620
+ if (e instanceof BudgetExhausted) { throw e; }
1621
+ if (!(e instanceof AdapterError)) { throw e; }
1622
+ failures += 1;
1623
+ this.emit('route_result', { route_id: 'discovery-replay-' + hash(p, 12), outcome: 'failed', reason: errStr(e),
1624
+ observation_id: this.current.observation_id });
1625
+ continue;
1626
+ }
1627
+ const state = observationKey(this.current);
1628
+ if (visited.has(state)) { continue; }
1629
+ visited.add(state);
1630
+ if (p.length >= maxDepth) { continue; }
1631
+ const candidates = this.discoveryActions(config);
1632
+ for (const action of candidates) {
1633
+ if (expanded >= maxExp()) { break; }
1634
+ expanded += 1;
1635
+ try {
1636
+ restore(p);
1637
+ const before = observationKey(this.current);
1638
+ const result = this.atom(action, 'discovery:' + expanded, 'discover');
1639
+ const after = observationKey(this.current);
1640
+ if (before === after) { continue; }
1641
+ transitions += 1;
1642
+ this.emit('route_result', { route_id: 'discovery-' + hash([...p, action], 16), outcome: 'captured',
1643
+ observation_id: this.current.observation_id, action_event_id: result.id, depth: p.length + 1 });
1644
+ if (!visited.has(after) && p.length + 1 < maxDepth) { queue.push([...p, action]); }
1645
+ } catch (e) {
1646
+ if (!(e instanceof AdapterError)) { throw e; }
1647
+ failures += 1;
1648
+ this.emit('route_result', { route_id: 'discovery-action-' + expanded, outcome: 'failed', reason: errStr(e),
1649
+ observation_id: this.current.observation_id });
1650
+ }
1651
+ }
1652
+ if (expanded >= maxExp()) { break; }
1653
+ }
1654
+ outcome = 'completed';
1655
+ } catch (e) {
1656
+ if (!(e instanceof BudgetExhausted)) { throw e; }
1657
+ outcome = 'budget-exhausted';
1658
+ }
1659
+ const result = { enabled: true, outcome, states: visited.size, transitions, expanded_actions: expanded, failures };
1660
+ this.emit('discovery_result', result);
1661
+ return result;
1662
+ }
1663
+
1664
+ _block(reason) { Object.assign(this.phase, { status: 'blocked', reason }); this.save(); }
1665
+
1666
+ /** Blocked because the device did not come back (see DEVICE_UNAVAILABLE_EXIT). */
1667
+ deviceUnavailable() { return this.phase.status === 'blocked' && this.phase.reason === DEVICE_UNAVAILABLE; }
1668
+
1669
+ /**
1670
+ * Grant the app's not-yet-granted runtime permissions (`grant_runtime_permissions`, default
1671
+ * on), so a permission prompt or the settings page the app opens never takes the foreground in
1672
+ * the middle of a capture. A campaign that needs the permission-denied or rationale screens sets
1673
+ * it to false (for the whole config, or runs those phases with a config that does).
1674
+ * Returns [granted, failed].
1675
+ */
1676
+ grantRuntimePermissions() { return grantRuntimePermissions(this.device, this.config); }
1677
+
1678
+ /**
1679
+ * `config.reset_between_tasks` (true, or a list of phase ids): clear app data before a task's
1680
+ * launch, so a setting one task changed does not reshape the next one's start page (measured,
1681
+ * Simple Calendar: a task chose the week view, the app stored it, and every later launch opened
1682
+ * on a week view with no FAB). `am start -S` only kills the process. Applies only to a phase with
1683
+ * no fixtures: a fixture-built state would be wiped with nothing to rebuild it.
1684
+ */
1685
+ resetsBetweenTasks() {
1686
+ const want = get(this.config, 'reset_between_tasks', false);
1687
+ const on = Array.isArray(want) ? want.includes(get(this.phase, 'id')) : truthy(want);
1688
+ return on && !get(get(this.config, 'fixtures', {}), get(this.phase, 'id'), []).length;
1689
+ }
1690
+
1691
+ /**
1692
+ * Once per task: a second source() of the same task (after a sweep left the page scrolled) only
1693
+ * needs the relaunch, since nothing between the two calls could store a setting. Each clear
1694
+ * costs an action and a cold start. A backlog sweep route (`sweep:<id>`) is its own visit and
1695
+ * clears again: the task before it may have changed a setting.
1696
+ */
1697
+ resetBetweenTasks(taskId) {
1698
+ if (!this.resetsBetweenTasks() || (taskId !== undefined && this._clearedFor === taskId)) { return; }
1699
+ this.atom({ type: 'clear_app_data' }, taskId, 'recover');
1700
+ this.grantRuntimePermissions();
1701
+ this._clearedFor = taskId;
1702
+ }
1703
+
1704
+ /**
1705
+ * Before the fixtures: grant runtime permissions, then leave any other app's screen.
1706
+ * A fixture step that resets app data (`pm clear` revokes every grant) grants them again.
1707
+ * One `environment_prepared` event.
1708
+ */
1709
+ prepareEnvironment() {
1710
+ const pkg = get(this.config, 'package');
1711
+ if (!truthy(pkg)) { return; }
1712
+ const [granted, failed] = this.grantRuntimePermissions();
1713
+ let left = null;
1714
+ const fg = get(this.current, 'package');
1715
+ if (truthy(fg) && fg !== pkg && !truthy(get(this.config, 'keep_foreign_foreground'))) {
1716
+ try { this.device._shell('input', 'keyevent', 'KEYCODE_HOME'); left = fg; } catch { /* the launch decides */ }
1717
+ }
1718
+ this.emit('environment_prepared', { phase: this.phase.id, granted, failed, left_foreground: left });
1719
+ }
1720
+
1721
+ _runFixtures() {
1722
+ for (const action of get(get(this.config, 'fixtures', {}), this.phase.id, [])) {
1723
+ // A fixture's own save step only exists to hand its state to later phases. When the phase
1724
+ // runs again (next round, resume) the archive is the one this fixture already wrote: keep it
1725
+ // (never overwrite) and continue, instead of blocking the phase on its own artifact.
1726
+ const kept = ['snapshot_app_data', 'save_replay'].includes(get(action, 'type')) && truthy(get(action, 'archive'))
1727
+ && fs.existsSync(pathStr(action.archive));
1728
+ // A kept .tar that is not a whole archive would restore a half state into every later
1729
+ // phase: move it aside (never delete) and let the fixture write it again.
1730
+ const bad = kept && action.type === 'snapshot_app_data' ? tarProblem(pathStr(action.archive)) : null;
1731
+ if (bad) {
1732
+ const aside = `${pathStr(action.archive)}.corrupt-${Date.now()}`;
1733
+ fs.renameSync(pathStr(action.archive), aside);
1734
+ this.emit('fixture_snapshot_corrupt', { phase: this.phase.id, archive: pathStr(action.archive), reason: bad, moved_to: aside });
1735
+ } else if (kept) {
1736
+ this.emit('fixture_snapshot_kept', { phase: this.phase.id, type: action.type, archive: pathStr(action.archive) });
1737
+ continue;
1738
+ }
1739
+ if (get(action, 'type') === 'assert') {
1740
+ if (!ruleMatches(this.current, action.rule)) {
1741
+ this._block('fixture-assert-failed: ' + cpSlice(jsonDumps(action.rule, { ensure_ascii: false }), 0, 120));
1742
+ return false;
1743
+ }
1744
+ continue;
1745
+ }
1746
+ try {
1747
+ this.seek(action, 'fixture:' + this.phase.id, 'prepare');
1748
+ if (['clear_app_data', 'restore_app_data'].includes(get(action, 'type'))) { this.grantRuntimePermissions(); }
1749
+ } catch (exc) {
1750
+ if (!(exc instanceof AdapterError)) { throw exc; }
1751
+ try {
1752
+ if (!(TRANSIENT_DEVICE_RE.test(errStr(exc)) && this.waitDevice())) { throw exc; }
1753
+ this.seek(action, 'fixture:' + this.phase.id, 'prepare');
1754
+ } catch (exc2) {
1755
+ if (!(exc2 instanceof AdapterError)) { throw exc2; }
1756
+ const sel = or(get(action, 'selectors'), () => or(get(action, 'selector'), ''));
1757
+ this._block(`fixture-step-failed: ${pyStr(get(action, 'type'))} ${cpSlice(jsonDumps(sel, { ensure_ascii: false }), 0, 80)}: ${errStr(exc2)}`);
1758
+ return false;
1759
+ }
1760
+ }
1761
+ }
1762
+ return true;
1763
+ }
1764
+
1765
+ run() {
1766
+ this._launched = false;
1767
+ this.awaitContent(this.capture());
1768
+ const tasks = get(this.doc, 'tasks', []).filter((t) => t.phase === this.phase.id);
1769
+ const probesFor = get(get(this.config, 'phase_probes', {}), this.phase.id);
1770
+ if (truthy(this.phase.requires) && !truthy(probesFor)) {
1771
+ return this._block('unresolved prerequisites: ' + this.phase.requires.join(', '));
1772
+ }
1773
+ this.prepareEnvironment();
1774
+ if (!this._runFixtures()) { return undefined; }
1775
+ const probes = get(get(this.config, 'phase_probes', {}), this.phase.id, []);
1776
+ if (truthy(probes) && !probes.every((r) => ruleMatches(this.current, r))) {
1777
+ // What the screen did show: recover_d.mjs offers it back so the probe can be rewritten from
1778
+ // evidence. Measured (ydweather): the recipe reached Main, but its probe asked for a sticky
1779
+ // title that is never in the tree at rest, and Main stayed uncaptured.
1780
+ const shown = [...new Set(get(this.current, 'nodes', []).filter((n) => isVisible(n))
1781
+ .flatMap((n) => [get(n, 'text'), get(n, 'content_desc')]).filter((t) => truthy(t)).map((t) => pyStr(t).trim())
1782
+ .filter((t) => t.length > 0))].slice(0, 200);
1783
+ this.emit('state_probe_failed', { phase: this.phase.id, observation_id: get(this.current, 'observation_id'),
1784
+ activity: get(this.current, 'activity'), visible_texts: shown, probes });
1785
+ return this._block('state-probe-failed');
1786
+ }
1787
+ this.emit('environment_verified', { phase: this.phase.id, observation_id: this.current.observation_id,
1788
+ scope: truthy(probes) ? 'configured probes' : 'existing state, no guard assumed' });
1789
+ this.phase.status = 'running'; this.save();
1790
+ let routeFailures = 0;
1791
+ for (const route of get(get(this.config, 'routes', {}), this.phase.id, [])) {
1792
+ try {
1793
+ for (const action of route.actions) {
1794
+ if (get(action, 'type') === 'assert') {
1795
+ if (!ruleMatches(this.current, action.rule)) { throw new AdapterError('route checkpoint failed'); }
1796
+ } else { this.seek(action, 'route:' + route.id, 'discover'); }
1797
+ }
1798
+ this.emit('route_result', { route_id: route.id, outcome: 'captured', observation_id: this.current.observation_id });
1799
+ } catch (e) {
1800
+ if (e instanceof BudgetExhausted) {
1801
+ Object.assign(this.phase, { status: 'budget-exhausted', reason: 'discovery route budget exhausted' }); this.save(); return undefined;
1802
+ }
1803
+ routeFailures += 1;
1804
+ this.emit('route_result', { route_id: route.id, outcome: 'failed', reason: errStr(e), observation_id: this.current.observation_id });
1805
+ }
1806
+ }
1807
+ const starts = counter(this.doc.events.filter((e) => e.kind === 'task_started').map((e) => e.payload.task_id));
1808
+ const phaseTaskIds = new Set(tasks.map((t) => t.task_id));
1809
+ const done = new Set(this.doc.events.filter((e) => e.kind === 'task_result' && e.payload.outcome === 'confirmed'
1810
+ && phaseTaskIds.has(e.payload.task_id)).map((e) => e.payload.task_id));
1811
+ let scheduled = 0;
1812
+ const transient = new Map();
1813
+ const skipped = new Set();
1814
+ try {
1815
+ for (const task of tasks) {
1816
+ const ident = task.task_id;
1817
+ if (done.has(ident) || (starts.get(ident) ?? 0) >= toInt(get(this.config, 'max_task_attempts', 1))) { continue; }
1818
+ if (this.coverage === 'nodes' && this.covered.has(get(task, 'target_static'))) {
1819
+ this.emit('task_skipped', { task_id: ident, target_static: task.target_static, reason: 'target-already-covered' });
1820
+ skipped.add(ident);
1821
+ continue;
1822
+ }
1823
+ // A scoped (incremental) campaign: a target outside the scope is settled, whatever the mode.
1824
+ if (this.scopeExcludes(get(task, 'target_static'))) {
1825
+ this.emit('task_skipped', { task_id: ident, target_static: task.target_static, reason: 'target-out-of-scope' });
1826
+ skipped.add(ident);
1827
+ continue;
1828
+ }
1829
+ if (scheduled >= this.args.max_tasks) { break; }
1830
+ if (task.status !== 'compiled') {
1831
+ const reasons = or(get(task, 'compile_issues'), ['needs-external-assistance']);
1832
+ this.emit('task_result', { task_id: ident, outcome: 'unsupported', reason: reasons.join(', '), compile_issues: reasons });
1833
+ continue;
1834
+ }
1835
+ const invariants = get(get(this.config, 'invariant_probes', {}), this.phase.id, []);
1836
+ if (truthy(invariants) && !invariants.every((p) => ruleMatches(this.current, p))) { return this._block('state-drift'); }
1837
+ scheduled += 1; starts.set(ident, (starts.get(ident) ?? 0) + 1);
1838
+ this.emit('task_started', { task_id: ident, target_static: task.target_static });
1839
+ this.keep = [task.source_static, task.target_static, get(task, 'source_context')].filter((x) => truthy(x));
1840
+ this._launched = false; // only a launch of this task's own opens the consent window
1841
+ this._clearedFor = null; // every attempt of a task starts from cleared data (resetBetweenTasks)
1842
+ if (get(task, 'purpose') === 'direct-launch') { this.runDirect(task, done); continue; }
1843
+ try {
1844
+ this._runTask(task, ident, done);
1845
+ } catch (exc) {
1846
+ if (exc instanceof BudgetExhausted) {
1847
+ this.emit('task_result', { task_id: ident, outcome: 'budget-exhausted', stage: this.stage });
1848
+ throw exc;
1849
+ }
1850
+ const msg = errStr(exc);
1851
+ if (msg.includes('does not exist') && msg.includes('Activity class')) {
1852
+ // Only a launch of the app's launcher proves a wrong namespace: an uninstalled module may
1853
+ // have its own MainActivity with the same simple name, and that skips just this task.
1854
+ const mismatch = truthy(get(get(task, 'source_launch'), 'launcher'))
1855
+ ? launchMismatch(msg, get(this.config, 'launch_component')) : null;
1856
+ if (mismatch) {
1857
+ this.emit('task_result', { task_id: ident, outcome: 'failed', reason: mismatch, stage: this.stage,
1858
+ target_static: task.target_static });
1859
+ return this._block(mismatch);
1860
+ }
1861
+ this.emit('task_result', { task_id: ident, outcome: 'unsupported', reason: 'entry-component-not-installed',
1862
+ stage: this.stage, target_static: task.target_static });
1863
+ continue;
1864
+ }
1865
+ if (TRANSIENT_DEVICE_RE.test(msg)) {
1866
+ const recovered = this.waitDevice();
1867
+ transient.set(ident, (transient.get(ident) ?? 0) + 1);
1868
+ if (recovered && transient.get(ident) <= toInt(get(this.config, 'max_device_retries', 1))) {
1869
+ starts.set(ident, starts.get(ident) - 1);
1870
+ this.emit('task_result', { task_id: ident, outcome: 'device-error', reason: cpSlice(msg, 0, 200), stage: this.stage,
1871
+ retrying: true, target_static: task.target_static });
1872
+ tasks.push(task);
1873
+ continue;
1874
+ }
1875
+ this.emit('task_result', { task_id: ident, outcome: 'device-error', reason: cpSlice(msg, 0, 200), stage: this.stage,
1876
+ target_static: task.target_static });
1877
+ if (!recovered) { return this._block(DEVICE_UNAVAILABLE); }
1878
+ continue;
1879
+ }
1880
+ const prefix = exc instanceof PrefixFailed
1881
+ ? { prefix_failed_from: exc.from, prefix_key: exc.key, replay_index: exc.replayIndex, prefix_before: exc.beforeId } : {};
1882
+ this.emit('task_result', { task_id: ident, outcome: 'failed', stage: this.stage,
1883
+ unmet_preconditions: or(get(task, 'task_preconditions'), []).map((x) => get(x, 'text')),
1884
+ reason: msg, target_static: task.target_static,
1885
+ observation_id: exc instanceof PrefixFailed ? exc.observationId : this.current.observation_id, ...prefix });
1886
+ }
1887
+ pyPrint(jsonDumps({ task: ident, attempted_this_run: scheduled, confirmed: done.size, atomic_actions: this.used,
1888
+ target: task.target_static }, { ensure_ascii: false }));
1889
+ }
1890
+ } catch (exc) {
1891
+ if (!(exc instanceof BudgetExhausted)) { throw exc; }
1892
+ Object.assign(this.phase, { status: 'budget-exhausted', reason: errStr(exc) }); this.save(); return undefined;
1893
+ }
1894
+ try { this.sweepBacklog(); } catch (e) { if (!(e instanceof BudgetExhausted)) { throw e; } }
1895
+ const discovery = this.runDiscovery();
1896
+ const mapped = new Set(this.doc.events.filter((e) => e.kind === 'mapping' && e.environment_id === this.env)
1897
+ .map((e) => get(e.payload, 'static_id')));
1898
+ const missing = this.phase.obligations.filter((o) => o.type === 'node' && !mapped.has(o.id) && !this.scopeExcludes(o.id));
1899
+ const resolved = new Set([...done, ...skipped]).size;
1900
+ Object.assign(this.phase, {
1901
+ status: resolved === tasks.length && !missing.length && !routeFailures ? 'completed' : 'exhausted-with-gaps',
1902
+ reason: `${done.size}/${tasks.length} tasks confirmed; ${skipped.size} skipped (target already covered or out of scope); `
1903
+ + `${missing.length} node obligations missing; ${routeFailures} routes failed; `
1904
+ + `discovery=${pyStr(get(discovery, 'outcome', 'disabled'))}; coverage=${this.coverage}`,
1905
+ });
1906
+ this.save();
1907
+ return undefined;
1908
+ }
1909
+
1910
+ _runTask(task, ident, done) {
1911
+ this.stage = 'source';
1912
+ this.source(task);
1913
+ if (this.sweep(task.source_static) && (this.dirty ?? false)) { this.source(task); }
1914
+ this.stage = 'target';
1915
+ let result; let mark;
1916
+ if (truthy(get(task.action, 'automatic')) && this.at(task.target_static)) {
1917
+ result = this.emit('action_result', { task_id: ident, purpose: 'target', outcome: 'succeeded',
1918
+ before: this.current.observation_id, after: this.current.observation_id, action: task.action });
1919
+ } else {
1920
+ mark = this.doc.events.length;
1921
+ for (const step of or(get(task, 'prelude'), [])) { this.seek(step, ident, 'target-prelude'); }
1922
+ result = this.seek(task.action, ident, 'target');
1923
+ }
1924
+ const confirmed = this.at(task.target_static);
1925
+ if (confirmed) {
1926
+ let chain = [result];
1927
+ if (!truthy(get(task.action, 'automatic'))) {
1928
+ chain = this.doc.events.slice(mark).filter((e) => e.kind === 'action_result' && get(e.payload, 'task_id') === ident);
1929
+ }
1930
+ const firstBefore = chain[0].payload.before;
1931
+ let beforeObs = {};
1932
+ for (let k = this.doc.events.length - 1; k >= 0; k--) {
1933
+ const e = this.doc.events[k];
1934
+ if (e.kind === 'observation' && get(e.payload, 'observation_id') === firstBefore) { beforeObs = e.payload; break; }
1935
+ }
1936
+ const sourceMatch = deps.observationMatchesStatic(beforeObs, task.source_static, this.catalog)[1];
1937
+ const targetMatch = deps.observationMatchesStatic(this.current, task.target_static, this.catalog)[1];
1938
+ this.emit('edge_mapping', { task_id: ident, static_id: task.target_static, source_static: task.source_static,
1939
+ target_static: task.target_static, action_event_id: result.id, action_chain: chain.map((e) => e.id),
1940
+ before: firstBefore, after: result.payload.after, source_match: sourceMatch,
1941
+ method: get(get(this.current, 'static_resolution', {}), 'reason', targetMatch) });
1942
+ done.add(ident);
1943
+ } else if (!truthy(get(task.action, 'automatic')) && truthy(result)) {
1944
+ this.attest(task, result);
1945
+ } else if (truthy(get(task.action, 'automatic')) && this.anchorless(task.target_static)
1946
+ && truthy(get(get(this.catalog, task.source_static, {}), 'transient'))) {
1947
+ // The transient entry left to an anchorless page: identity by elimination only, so it is
1948
+ // attested (listed apart), never mapped.
1949
+ const rivals = or(get(get(this.catalog, task.source_static, {}), 'auto_targets'), []).filter((t) => t !== task.target_static);
1950
+ if (this._unclaimedAppScreen(rivals, task.target_static)) {
1951
+ this.emit('attestation', { static_id: task.target_static, task_id: ident, observation_id: this.current.observation_id,
1952
+ basis: 'transient-successor', evidence: { context: task.source_static, rivals },
1953
+ action_event_id: truthy(result) ? result.id : null });
1954
+ }
1955
+ }
1956
+ this.emit('task_result', { task_id: ident, outcome: confirmed ? 'confirmed' : 'target-unverified',
1957
+ target_static: task.target_static, observation_id: this.current.observation_id });
1958
+ if (confirmed) { this.sweep(task.target_static); }
1959
+ }
1960
+ }
1961
+
1962
+ /**
1963
+ * back_exit_pages(events): verified pages from which a Back press has already left the app (the
1964
+ * app's root screens, learned from the device). Recovery relaunches from them instead of pressing
1965
+ * Back again. Derived from the event log, so it carries across phases, rounds and resumes.
1966
+ */
1967
+ export function backExitPages(events) {
1968
+ const obs = new Map();
1969
+ for (const e of events) { if (e.kind === 'observation') { obs.set(tupleKey(e.environment_id, get(e.payload, 'observation_id')), e.payload); } }
1970
+ const out = new Set();
1971
+ for (const e of events) {
1972
+ const p = e.payload;
1973
+ if (e.kind !== 'action_result' || get(get(p, 'action', {}), 'type') !== 'back') { continue; }
1974
+ const before = obs.get(tupleKey(e.environment_id, get(p, 'before'))) ?? {};
1975
+ const after = obs.get(tupleKey(e.environment_id, get(p, 'after'))) ?? {};
1976
+ const rb = get(before, 'static_resolution', {}) ?? {};
1977
+ if (get(rb, 'status') === 'verified' && get(get(after, 'static_resolution', {}) ?? {}, 'status') === 'foreign-package') {
1978
+ out.add(rb.static_id);
1979
+ }
1980
+ }
1981
+ return out;
1982
+ }
1983
+
1984
+ /** deviceLock options of a runner: config.device_lock_wait_s (default LOCK_WAIT_S), owner campaign. */
1985
+ export function lockWait(config, campaign) {
1986
+ return { waitS: toFloat(get(config ?? {}, 'device_lock_wait_s', LOCK_WAIT_S)), campaign: pResolve(campaign) };
1987
+ }
1988
+
1989
+ /**
1990
+ * run_campaign_phase(args): run one phase under the device lock, then its cleanup steps. The
1991
+ * Runner (which loads campaign.json and saves it wholesale) is built only once the lock is held,
1992
+ * so a run that waited for another run of this campaign starts from that run's saved document.
1993
+ */
1994
+ export function runCampaignPhase(args) {
1995
+ const config = readJson(args.config);
1996
+ const serial = get(config, 'serial');
1997
+ if (!truthy(serial)) { throw new AdapterError('Explicit serial required to avoid controlling the wrong device'); }
1998
+ let runner = null;
1999
+ let busy = null;
2000
+ try {
2001
+ deviceLock(serial, () => {
2002
+ runner = new Runner(args);
2003
+ try {
2004
+ try {
2005
+ runner.run();
2006
+ } finally {
2007
+ runner.save();
2008
+ const cleanup = get(get(runner.config, 'cleanup', {}), runner.phase.id, []);
2009
+ if (truthy(cleanup)) {
2010
+ for (const action of cleanup) {
2011
+ if (get(action, 'type') === 'assert') {
2012
+ if (!ruleMatches(runner.current, action.rule)) { throw new AdapterError('cleanup postcondition failed'); }
2013
+ } else { runner.seek(action, 'cleanup:' + runner.phase.id, 'restore'); }
2014
+ }
2015
+ runner.emit('environment_restored', { phase: runner.phase.id, observation_id: runner.current.observation_id });
2016
+ }
2017
+ }
2018
+ } finally {
2019
+ // Close (persistent shell, u2 server on device port 9008) while the lock is still held:
2020
+ // a run waiting for the lock would otherwise reuse our live server, which this close kills.
2021
+ runner.device.close();
2022
+ }
2023
+ }, lockWait(config, args.campaign));
2024
+ } catch (e) {
2025
+ if (!(e instanceof DeviceBusy)) { throw e; }
2026
+ busy = e;
2027
+ }
2028
+ // another explorer kept the device: device-unavailable, not a failed phase
2029
+ if (busy) {
2030
+ pyPrintErr(`phase ${pyStr(get(args, 'phase'))} blocked: ${busy.message}`);
2031
+ throw new SystemExit(DEVICE_UNAVAILABLE_EXIT);
2032
+ }
2033
+ if (runner.deviceUnavailable()) {
2034
+ pyPrintErr(`phase ${runner.phase.id} blocked: device-unavailable`);
2035
+ throw new SystemExit(DEVICE_UNAVAILABLE_EXIT);
2036
+ }
2037
+ }