@buaa_smat/hometrans 0.1.20 → 26.0.0-devecocli.2

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 (981) hide show
  1. package/agents/build-fixer.md +406 -0
  2. package/agents/code-reviewer.md +461 -496
  3. package/agents/model-render-worker.md +34 -0
  4. package/agents/model-worker.md +23 -0
  5. package/agents/specgen-worker.md +18 -0
  6. package/commands/hometrans.md +17 -0
  7. package/devecocli-plugin/common.ts +2203 -0
  8. package/devecocli-plugin/install.ts +61 -0
  9. package/devecocli-plugin/uninstall.ts +26 -0
  10. package/devecocli-plugin/update.ts +66 -0
  11. package/index.js +1418 -0
  12. package/package.json +81 -64
  13. package/platforms/atomcode/agents/build-fixer.frontmatter.md +6 -0
  14. package/platforms/atomcode/agents/code-reviewer.frontmatter.md +6 -0
  15. package/platforms/atomcode/agents/model-render-worker.frontmatter.md +6 -0
  16. package/platforms/atomcode/agents/model-worker.frontmatter.md +6 -0
  17. package/platforms/atomcode/agents/specgen-worker.frontmatter.md +6 -0
  18. package/platforms/deveco/agents/build-fixer.frontmatter.md +5 -0
  19. package/platforms/deveco/agents/code-reviewer.frontmatter.md +5 -0
  20. package/platforms/deveco/agents/model-render-worker.frontmatter.md +5 -0
  21. package/platforms/deveco/agents/model-worker.frontmatter.md +5 -0
  22. package/platforms/deveco/agents/specgen-worker.frontmatter.md +5 -0
  23. package/platforms/opencode/agents/build-fixer.frontmatter.md +5 -0
  24. package/platforms/opencode/agents/code-reviewer.frontmatter.md +5 -0
  25. package/platforms/opencode/agents/model-render-worker.frontmatter.md +5 -0
  26. package/platforms/opencode/agents/model-worker.frontmatter.md +5 -0
  27. package/platforms/opencode/agents/specgen-worker.frontmatter.md +5 -0
  28. package/plugin.jsonc +12 -0
  29. package/skills/a2h-app-migrate/SKILL.md +181 -0
  30. package/skills/a2h-app-migrate/references/config.example.json +27 -0
  31. package/skills/a2h-app-migrate/references/specs.example.json +19 -0
  32. package/skills/a2h-app-migrate/references/stage-map.md +33 -0
  33. package/skills/a2h-app-migrate/references/workflow.yaml +1600 -0
  34. package/skills/a2h-app-migrate/scripts/android_index.mjs +109 -0
  35. package/skills/a2h-app-migrate/scripts/check_arch_done.mjs +80 -0
  36. package/skills/a2h-app-migrate/scripts/check_module_docs_done.mjs +95 -0
  37. package/skills/a2h-app-migrate/scripts/check_signing.mjs +152 -0
  38. package/skills/a2h-app-migrate/scripts/check_spec_gen_done.mjs +114 -0
  39. package/skills/a2h-app-migrate/scripts/check_spec_pipeline_done.mjs +277 -0
  40. package/skills/a2h-app-migrate/scripts/check_ui_batch_done.mjs +77 -0
  41. package/skills/a2h-app-migrate/scripts/check_utg_static_done.mjs +147 -0
  42. package/skills/a2h-app-migrate/scripts/cli_values.mjs +32 -0
  43. package/skills/a2h-app-migrate/scripts/env_preflight.mjs +1388 -0
  44. package/skills/a2h-app-migrate/scripts/human_review_gate.mjs +651 -0
  45. package/skills/a2h-app-migrate/scripts/infer_android_root.mjs +53 -0
  46. package/skills/a2h-app-migrate/scripts/json_io.mjs +35 -0
  47. package/skills/a2h-app-migrate/scripts/ledger.mjs +104 -0
  48. package/skills/a2h-app-migrate/scripts/lib-yaml-lite.mjs +288 -0
  49. package/skills/a2h-app-migrate/scripts/paths_preflight.mjs +713 -0
  50. package/skills/a2h-app-migrate/scripts/resume_plan.mjs +205 -0
  51. package/skills/a2h-app-migrate/scripts/reuse_static_utg.mjs +121 -0
  52. package/skills/a2h-app-migrate/scripts/run_dir.mjs +212 -0
  53. package/skills/a2h-app-migrate/scripts/spec_layout.mjs +30 -0
  54. package/skills/a2h-app-migrate/scripts/validate_workflow.mjs +455 -0
  55. package/skills/a2h-app-migrate/test/test_android_index.mjs +80 -0
  56. package/skills/a2h-app-migrate/test/test_apk_preflight.mjs +63 -0
  57. package/skills/a2h-app-migrate/test/test_arch_done.mjs +54 -0
  58. package/skills/a2h-app-migrate/test/test_build_fixer_contract.mjs +92 -0
  59. package/skills/a2h-app-migrate/test/test_config_example.mjs +42 -0
  60. package/skills/a2h-app-migrate/test/test_entry_guards.mjs +93 -0
  61. package/skills/a2h-app-migrate/test/test_env_requirements.mjs +505 -0
  62. package/skills/a2h-app-migrate/test/test_finalize.mjs +89 -0
  63. package/skills/a2h-app-migrate/test/test_gate_checkpoint.mjs +146 -0
  64. package/skills/a2h-app-migrate/test/test_hmos_fingerprint.mjs +68 -0
  65. package/skills/a2h-app-migrate/test/test_infer_android_root.mjs +91 -0
  66. package/skills/a2h-app-migrate/test/test_interaction.mjs +122 -0
  67. package/skills/a2h-app-migrate/test/test_json_io.mjs +32 -0
  68. package/skills/a2h-app-migrate/test/test_leaf_questions.mjs +109 -0
  69. package/skills/a2h-app-migrate/test/test_module_docs_done.mjs +53 -0
  70. package/skills/a2h-app-migrate/test/test_parse_args.mjs +69 -0
  71. package/skills/a2h-app-migrate/test/test_preflight_report.mjs +83 -0
  72. package/skills/a2h-app-migrate/test/test_resume_plan.mjs +144 -0
  73. package/skills/a2h-app-migrate/test/test_reuse_static_utg.mjs +100 -0
  74. package/skills/a2h-app-migrate/test/test_run_dir.mjs +315 -0
  75. package/skills/a2h-app-migrate/test/test_skill_doc.mjs +133 -0
  76. package/skills/a2h-app-migrate/test/test_spec_gen_done.mjs +133 -0
  77. package/skills/a2h-app-migrate/test/test_spec_gen_gate.mjs +158 -0
  78. package/skills/a2h-app-migrate/test/test_spec_pipeline_done.mjs +181 -0
  79. package/skills/a2h-app-migrate/test/test_specs_json_preflight.mjs +76 -0
  80. package/skills/a2h-app-migrate/test/test_ui_batch_done.mjs +53 -0
  81. package/skills/a2h-app-migrate/test/test_ui_batch_gate.mjs +226 -0
  82. package/skills/a2h-app-migrate/test/test_utg_dirs.mjs +39 -0
  83. package/skills/a2h-app-migrate/test/test_utg_static_done.mjs +168 -0
  84. package/skills/a2h-app-migrate/test/test_validate_races.mjs +50 -0
  85. package/skills/a2h-arch-generate/SKILL.md +375 -0
  86. package/skills/a2h-arch-generate/examples/reconcile-existing-project.md +107 -0
  87. package/skills/a2h-arch-generate/examples/simple-conversion-android.md +103 -0
  88. package/skills/a2h-arch-generate/examples/simple-conversion-backend.md +70 -0
  89. package/skills/a2h-arch-generate/examples/simple-conversion-uniapp.md +106 -0
  90. package/skills/a2h-arch-generate/references/artifact-contracts.generate.md +120 -0
  91. package/skills/a2h-arch-generate/references/artifact-contracts.reconcile.md +123 -0
  92. package/skills/a2h-arch-generate/references/bpta-layered-architecture-design.md +88 -0
  93. package/skills/a2h-arch-generate/references/clustering-guidance.md +33 -0
  94. package/skills/a2h-arch-generate/references/database-schema-recovery.md +107 -0
  95. package/skills/a2h-arch-generate/references/existing-target-annotation.md +68 -0
  96. package/skills/a2h-arch-generate/references/harmony-project-inspection.md +150 -0
  97. package/skills/a2h-arch-generate/references/harmony-target-architecture.md +94 -0
  98. package/skills/a2h-arch-generate/references/homegraph-workflow.md +120 -0
  99. package/skills/a2h-arch-generate/references/module-evidence-subagent.md +45 -0
  100. package/skills/a2h-arch-generate/references/reconciliation-model.md +204 -0
  101. package/skills/a2h-arch-generate/references/scope-policy.md +28 -0
  102. package/skills/a2h-arch-generate/references/semantic-review.md +65 -0
  103. package/skills/a2h-arch-generate/references/source-baseline.md +93 -0
  104. package/skills/a2h-arch-generate/references/source-ecosystems.md +54 -0
  105. package/skills/a2h-arch-generate/references/transformation-model.md +78 -0
  106. package/skills/a2h-arch-generate/scripts/check_module_staleness.mjs +284 -0
  107. package/skills/a2h-arch-generate/scripts/cleanup_intermediates.mjs +260 -0
  108. package/skills/a2h-arch-generate/scripts/compute_processing_order.mjs +325 -0
  109. package/skills/a2h-arch-generate/scripts/create_project.mjs +149 -0
  110. package/skills/a2h-arch-generate/scripts/dump_core_facts.mjs +151 -0
  111. package/skills/a2h-arch-generate/scripts/extract_core_components.mjs +167 -0
  112. package/skills/a2h-arch-generate/scripts/generate_source_baseline.mjs +363 -0
  113. package/skills/a2h-arch-generate/scripts/generate_state.mjs +60 -0
  114. package/skills/a2h-arch-generate/scripts/inspect_and_route.mjs +326 -0
  115. package/skills/a2h-arch-generate/scripts/inspect_android_project.mjs +3739 -0
  116. package/skills/a2h-arch-generate/scripts/inspect_harmony_target.mjs +800 -0
  117. package/skills/a2h-arch-generate/scripts/inspect_project.mjs +251 -0
  118. package/skills/a2h-arch-generate/scripts/inspect_uniapp_project.mjs +809 -0
  119. package/skills/a2h-arch-generate/scripts/lib/py_compat.mjs +1454 -0
  120. package/skills/a2h-arch-generate/scripts/module_create/create.mjs +136 -0
  121. package/skills/a2h-arch-generate/scripts/module_create/generate.mjs +636 -0
  122. package/skills/a2h-arch-generate/scripts/module_create/hap/build-profile.json5 +33 -0
  123. package/skills/a2h-arch-generate/scripts/module_create/hap/hvigorfile.ts +6 -0
  124. package/skills/a2h-arch-generate/scripts/module_create/hap/obfuscation-rules.txt +23 -0
  125. package/skills/a2h-arch-generate/scripts/module_create/hap/oh-package.json5 +10 -0
  126. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/ets/applicationability/ApplicationAbility.ets +43 -0
  127. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/ets/pages/Index.ets +23 -0
  128. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/module.json5 +26 -0
  129. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/element/color.json +8 -0
  130. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/element/float.json +8 -0
  131. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/element/string.json +16 -0
  132. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/media/background.png +0 -0
  133. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/media/foreground.png +0 -0
  134. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/media/layered_image.json +7 -0
  135. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/media/startIcon.png +0 -0
  136. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/profile/main_pages.json +5 -0
  137. package/skills/a2h-arch-generate/scripts/module_create/hap/src/mock/mock-config.json5 +2 -0
  138. package/skills/a2h-arch-generate/scripts/module_create/hap/src/ohosTest/ets/test/Ability.test.ets +35 -0
  139. package/skills/a2h-arch-generate/scripts/module_create/hap/src/ohosTest/ets/test/List.test.ets +5 -0
  140. package/skills/a2h-arch-generate/scripts/module_create/hap/src/ohosTest/module.json5 +11 -0
  141. package/skills/a2h-arch-generate/scripts/module_create/hap/src/test/List.test.ets +5 -0
  142. package/skills/a2h-arch-generate/scripts/module_create/hap/src/test/LocalUnit.test.ets +33 -0
  143. package/skills/a2h-arch-generate/scripts/module_create/har/Index.ets +1 -0
  144. package/skills/a2h-arch-generate/scripts/module_create/har/build-profile.json5 +36 -0
  145. package/skills/a2h-arch-generate/scripts/module_create/har/hvigorfile.ts +6 -0
  146. package/skills/a2h-arch-generate/scripts/module_create/har/obfuscation-rules.txt +23 -0
  147. package/skills/a2h-arch-generate/scripts/module_create/har/oh-package.json5 +9 -0
  148. package/skills/a2h-arch-generate/scripts/module_create/har/src/main/ets/components/MainPage.ets +19 -0
  149. package/skills/a2h-arch-generate/scripts/module_create/har/src/main/module.json5 +9 -0
  150. package/skills/a2h-arch-generate/scripts/module_create/har/src/main/resources/base/element/float.json +8 -0
  151. package/skills/a2h-arch-generate/scripts/module_create/har/src/main/resources/base/element/string.json +8 -0
  152. package/skills/a2h-arch-generate/scripts/module_create/har/src/ohosTest/ets/test/Ability.test.ets +35 -0
  153. package/skills/a2h-arch-generate/scripts/module_create/har/src/ohosTest/ets/test/List.test.ets +5 -0
  154. package/skills/a2h-arch-generate/scripts/module_create/har/src/ohosTest/module.json5 +11 -0
  155. package/skills/a2h-arch-generate/scripts/module_create/har/src/test/List.test.ets +5 -0
  156. package/skills/a2h-arch-generate/scripts/module_create/har/src/test/LocalUnit.test.ets +33 -0
  157. package/skills/a2h-arch-generate/scripts/module_create/hsp/Index.ets +1 -0
  158. package/skills/a2h-arch-generate/scripts/module_create/hsp/build-profile.json5 +36 -0
  159. package/skills/a2h-arch-generate/scripts/module_create/hsp/consumer-rules.txt +0 -0
  160. package/skills/a2h-arch-generate/scripts/module_create/hsp/hvigorfile.ts +6 -0
  161. package/skills/a2h-arch-generate/scripts/module_create/hsp/obfuscation-rules.txt +23 -0
  162. package/skills/a2h-arch-generate/scripts/module_create/hsp/oh-package.json5 +10 -0
  163. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/ets/pages/Index.ets +20 -0
  164. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/ets/utils/Calc.ets +3 -0
  165. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/module.json5 +12 -0
  166. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/resources/base/element/float.json +8 -0
  167. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/resources/base/element/string.json +8 -0
  168. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/resources/base/profile/main_pages.json +5 -0
  169. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/ohosTest/ets/test/Ability.test.ets +35 -0
  170. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/ohosTest/ets/test/List.test.ets +5 -0
  171. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/ohosTest/module.json5 +11 -0
  172. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/test/List.test.ets +5 -0
  173. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/test/LocalUnit.test.ets +33 -0
  174. package/skills/a2h-arch-generate/scripts/module_create/testdata/reconcile-layer-PROJECT_DESIGN.md +47 -0
  175. package/skills/a2h-arch-generate/scripts/module_create/testdata/single-entry-PROJECT_DESIGN.md +15 -0
  176. package/skills/a2h-arch-generate/scripts/module_create/testdata/three-layer-PROJECT_DESIGN.md +36 -0
  177. package/skills/a2h-arch-generate/scripts/module_create/testdata/verification-report.md +150 -0
  178. package/skills/a2h-arch-generate/scripts/resolve_android_stores.mjs +529 -0
  179. package/skills/a2h-arch-generate/scripts/scaffold_project.mjs +230 -0
  180. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/build.gradle +11 -0
  181. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/src/main/AndroidManifest.xml +12 -0
  182. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/src/main/java/com/example/notes/MainActivity.kt +8 -0
  183. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/src/main/java/com/example/notes/NotesStore.kt +17 -0
  184. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/build.gradle +3 -0
  185. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/settings.gradle +1 -0
  186. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/AppScope/app.json5 +8 -0
  187. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/build-profile.json5 +14 -0
  188. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/common/utils/build-profile.json5 +7 -0
  189. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/common/utils/oh-package.json5 +1 -0
  190. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/common/utils/src/main/ets/utils/Format.ets +3 -0
  191. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/home/build-profile.json5 +7 -0
  192. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/home/oh-package.json5 +1 -0
  193. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/home/src/main/ets/pages/Home.ets +3 -0
  194. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/sync/build-profile.json5 +7 -0
  195. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/sync/oh-package.json5 +1 -0
  196. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/sync/src/main/ets/engine/SyncEngine.ets +3 -0
  197. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/hvigorfile.ts +1 -0
  198. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/oh-package.json5 +1 -0
  199. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/products/app/build-profile.json5 +7 -0
  200. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/products/app/oh-package.json5 +9 -0
  201. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/products/app/src/main/ets/pages/Index.ets +7 -0
  202. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/App.vue +10 -0
  203. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/manifest.json +6 -0
  204. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/pages/index/index.vue +16 -0
  205. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/pages.json +5 -0
  206. package/skills/a2h-arch-generate/scripts/tests/e2e/run_e2e.mjs +548 -0
  207. package/skills/a2h-arch-generate/scripts/tests/run_tests.mjs +1122 -0
  208. package/skills/a2h-arch-generate/scripts/tests/test_cleanup.mjs +191 -0
  209. package/skills/a2h-arch-generate/scripts/tests/test_console_encoding.mjs +52 -0
  210. package/skills/a2h-arch-generate/scripts/tests/test_git_root.mjs +34 -0
  211. package/skills/a2h-arch-generate/scripts/tests/test_router.mjs +138 -0
  212. package/skills/a2h-arch-generate/scripts/validate_architecture_docs.mjs +829 -0
  213. package/skills/a2h-arch-generate/scripts/validate_data_docs.mjs +937 -0
  214. package/skills/a2h-arch-generate/scripts/validate_homegraph_artifacts.mjs +542 -0
  215. package/skills/a2h-arch-generate/scripts/validate_incremental_docs.mjs +415 -0
  216. package/skills/a2h-arkts-logic-coder/SKILL.md +125 -0
  217. package/skills/a2h-arkts-logic-coder/references/ISSUES.md +6 -0
  218. package/skills/a2h-arkts-logic-coder/references/code-generation.md +124 -0
  219. package/skills/a2h-arkts-logic-coder/scripts/check_module_scope.ts +224 -0
  220. package/skills/a2h-arkts-logic-coder/scripts/check_mvvm.ts +377 -0
  221. package/skills/a2h-arkts-logic-coder/scripts/stop_check_hook.ts +443 -0
  222. package/skills/a2h-arkts-logic-coder/scripts/test_check_scripts.ts +211 -0
  223. package/skills/a2h-arkts-logic-coder/scripts/test_worktree_compat.ts +81 -0
  224. package/skills/a2h-batch-ui-align/SKILL.md +309 -0
  225. package/skills/a2h-batch-ui-align/assets/ColorUtils.ets +81 -0
  226. package/skills/a2h-batch-ui-align/flowchart.html +271 -0
  227. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/conversion-procedure.md +523 -661
  228. package/skills/a2h-batch-ui-align/references/incremental-scope.md +139 -0
  229. package/skills/a2h-batch-ui-align/references/lottie-integration.md +43 -0
  230. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +8 -8
  231. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +3 -0
  232. package/skills/a2h-batch-ui-align/references/source-only-tier.md +32 -0
  233. package/skills/a2h-batch-ui-align/references/step3-capture.md +211 -0
  234. package/skills/a2h-batch-ui-align/references/step4-prepare.md +192 -0
  235. package/skills/a2h-batch-ui-align/references/step5-convert.md +202 -0
  236. package/skills/a2h-batch-ui-align/scripts/agent_cli.mjs +572 -0
  237. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/scripts/android_parse_fast.ts +246 -39
  238. package/skills/a2h-batch-ui-align/scripts/answers_check.mjs +86 -0
  239. package/skills/a2h-batch-ui-align/scripts/arkts_static_check.ts +2689 -0
  240. package/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +1656 -0
  241. package/skills/a2h-batch-ui-align/scripts/databinding_analyzer_design.md +79 -0
  242. package/skills/a2h-batch-ui-align/scripts/detach.mjs +258 -0
  243. package/skills/a2h-batch-ui-align/scripts/export_ui_info.mjs +1524 -0
  244. package/skills/a2h-batch-ui-align/scripts/generate_pages_json.mjs +612 -0
  245. package/skills/a2h-batch-ui-align/scripts/group_commit.mjs +166 -0
  246. package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +1437 -0
  247. package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +1869 -0
  248. package/skills/a2h-batch-ui-align/scripts/group_watch.mjs +696 -0
  249. package/skills/a2h-batch-ui-align/scripts/harmony_index.mjs +218 -0
  250. package/skills/a2h-batch-ui-align/scripts/host_env.mjs +208 -0
  251. package/skills/a2h-batch-ui-align/scripts/measure_pack.ts +1229 -0
  252. package/skills/a2h-batch-ui-align/scripts/occlusion.mjs +141 -0
  253. package/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +1124 -0
  254. package/skills/a2h-batch-ui-align/scripts/shell_contract.mjs +996 -0
  255. package/skills/a2h-batch-ui-align/scripts/tests/agent_cli.test.mjs +217 -0
  256. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_align_tint.test.mjs +253 -0
  257. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_rules.test.mjs +365 -0
  258. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_shell.test.mjs +72 -0
  259. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_weight_color.test.mjs +353 -0
  260. package/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set.test.mjs +345 -0
  261. package/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set_scope.test.mjs +290 -0
  262. package/skills/a2h-batch-ui-align/scripts/tests/color_utils_asset.test.mjs +74 -0
  263. package/skills/a2h-batch-ui-align/scripts/tests/export_ui_info.test.mjs +507 -0
  264. package/skills/a2h-batch-ui-align/scripts/tests/generate_pages_json.test.mjs +123 -0
  265. package/skills/a2h-batch-ui-align/scripts/tests/group_commit.test.mjs +126 -0
  266. package/skills/a2h-batch-ui-align/scripts/tests/group_pack.test.mjs +189 -0
  267. package/skills/a2h-batch-ui-align/scripts/tests/group_queue.test.mjs +1451 -0
  268. package/skills/a2h-batch-ui-align/scripts/tests/group_watch.test.mjs +215 -0
  269. package/skills/a2h-batch-ui-align/scripts/tests/harmony_index.test.mjs +95 -0
  270. package/skills/a2h-batch-ui-align/scripts/tests/host_env.test.mjs +115 -0
  271. package/skills/a2h-batch-ui-align/scripts/tests/measure_pack.test.mjs +170 -0
  272. package/skills/a2h-batch-ui-align/scripts/tests/occlusion.test.mjs +102 -0
  273. package/skills/a2h-batch-ui-align/scripts/tests/phase5_check.test.mjs +244 -0
  274. package/skills/a2h-batch-ui-align/scripts/tests/shell_contract.test.mjs +130 -0
  275. package/skills/a2h-batch-ui-align/scripts/tests/test_bfs_exit.ts +49 -0
  276. package/skills/a2h-coldstart-smoke-gate/SKILL.md +57 -0
  277. package/skills/a2h-dashboard-render/SKILL.md +65 -0
  278. package/skills/a2h-dashboard-render/references/artifact-contract.jsonc +147 -0
  279. package/skills/a2h-dashboard-render/references/artifact-registry-spec.md +67 -0
  280. package/skills/a2h-dashboard-render/references/dashboard.config.example.json +19 -0
  281. package/skills/a2h-dashboard-render/references//347/234/213/346/235/277/350/257/264/346/230/216.md +83 -0
  282. package/skills/a2h-dashboard-render/scripts/artifact_contract.mjs +138 -0
  283. package/skills/a2h-dashboard-render/scripts/check-registry.mjs +87 -0
  284. package/skills/a2h-dashboard-render/scripts/dashboard.mjs +3215 -0
  285. package/skills/a2h-dashboard-render/scripts/device_capture.mjs +2010 -0
  286. package/skills/a2h-dashboard-render/scripts/page_capture.mjs +828 -0
  287. package/skills/a2h-dashboard-render/scripts/usage_readers.mjs +459 -0
  288. package/skills/a2h-dashboard-render/scripts/usage_worker.mjs +13 -0
  289. package/skills/a2h-dashboard-render/test/fixtures/page_capture/broken.xml +1 -0
  290. package/skills/a2h-dashboard-render/test/fixtures/page_capture/expected.json +156 -0
  291. package/skills/a2h-dashboard-render/test/fixtures/page_capture/hmos.json +1 -0
  292. package/skills/a2h-dashboard-render/test/fixtures/page_capture/list.xml +1 -0
  293. package/skills/a2h-dashboard-render/test/fixtures/page_capture/nested_scroll.xml +1 -0
  294. package/skills/a2h-dashboard-render/test/test_artifact_contract.mjs +170 -0
  295. package/skills/a2h-dashboard-render/test/test_cli_check_registry.mjs +99 -0
  296. package/skills/a2h-dashboard-render/test/test_dashboard_architecture.mjs +182 -0
  297. package/skills/a2h-dashboard-render/test/test_dashboard_build.mjs +64 -0
  298. package/skills/a2h-dashboard-render/test/test_dashboard_node.mjs +1172 -0
  299. package/skills/a2h-dashboard-render/test/test_dashboard_spec_pipeline.mjs +251 -0
  300. package/skills/a2h-dashboard-render/test/test_dashboard_ui_pipeline.mjs +81 -0
  301. package/skills/a2h-dashboard-render/test/test_device_capture_env.mjs +115 -0
  302. package/skills/a2h-dashboard-render/test/test_device_capture_policy.mjs +303 -0
  303. package/skills/a2h-dashboard-render/test/test_page_capture.mjs +147 -0
  304. package/skills/a2h-dashboard-render/test/test_usage_readers.mjs +444 -0
  305. package/skills/{hmos-fix-build-errors → a2h-fix-build-errors}/SKILL.md +305 -293
  306. package/skills/a2h-module-semantic-docs/SKILL.md +227 -0
  307. package/skills/a2h-module-semantic-docs/scripts/commit_module_state.mjs +168 -0
  308. package/skills/a2h-module-semantic-docs/scripts/lib/py_compat.mjs +688 -0
  309. package/skills/a2h-module-semantic-docs/scripts/scan_modules.mjs +1021 -0
  310. package/skills/a2h-module-semantic-docs/test/golden/module_structure.json +187 -0
  311. package/skills/a2h-module-semantic-docs/test/golden/module_understanding.json +351 -0
  312. package/skills/a2h-module-semantic-docs/test/golden/module_update_plan.json +495 -0
  313. package/skills/a2h-module-semantic-docs/test/golden/project_directory_structure.json +157 -0
  314. package/skills/a2h-module-semantic-docs/test/test_scan_and_commit.mjs +388 -0
  315. package/skills/a2h-resource-convert/SKILL.md +369 -0
  316. package/skills/{hmos-resources-convert → a2h-resource-convert}/references/code-vector-icon-rules.md +4 -4
  317. package/skills/{hmos-resources-convert → a2h-resource-convert}/references/conversion-rules.md +16 -5
  318. package/skills/a2h-resource-convert/references/incremental-page-migration.md +251 -0
  319. package/skills/{hmos-resources-convert → a2h-resource-convert}/references/lottie-conversion-rules.md +17 -17
  320. package/skills/{hmos-resources-convert → a2h-resource-convert}/references/resource-mapping-rules.md +15 -4
  321. package/skills/a2h-resource-convert/references/step3_5-dependency-filter.md +54 -0
  322. package/skills/a2h-resource-convert/references/step4-qualifiers-and-values.md +142 -0
  323. package/skills/a2h-resource-convert/references/step4-resource-types.md +249 -0
  324. package/skills/a2h-resource-convert/references/step5-reference-resolution.md +154 -0
  325. package/skills/a2h-resource-convert/references/step7-report-template.md +217 -0
  326. package/skills/{hmos-resources-convert → a2h-resource-convert}/references/xml-drawable-to-svg-rules.md +38 -0
  327. package/skills/{hmos-resources-convert → a2h-resource-convert}/scripts/a2h_resource_convert.ts +456 -90
  328. package/skills/a2h-resource-convert/scripts/a2h_resource_incremental.ts +1072 -0
  329. package/skills/a2h-resource-convert/scripts/app_identity.ts +947 -0
  330. package/skills/{hmos-resources-convert → a2h-resource-convert}/scripts/code_vector_icons.ts +19 -3
  331. package/skills/a2h-resource-convert/scripts/extract_page_resources.ts +989 -0
  332. package/skills/a2h-resource-convert/scripts/extract_project_resources.ts +1464 -0
  333. package/skills/a2h-resource-convert/scripts/tests/adaptive_icon.test.mjs +182 -0
  334. package/skills/a2h-resource-convert/scripts/tests/app_identity.test.mjs +206 -0
  335. package/skills/a2h-spec-design/SKILL.md +336 -0
  336. package/skills/a2h-spec-design/scripts/inspect_spec_design_inputs.mjs +146 -0
  337. package/skills/a2h-spec-design/scripts/lib/py_compat.mjs +481 -0
  338. package/skills/a2h-spec-design/scripts/move_spec_technical_reference.mjs +159 -0
  339. package/skills/a2h-spec-design/scripts/resolve_module_design.mjs +102 -0
  340. package/skills/a2h-spec-design/scripts/validate_spec_design_output.mjs +285 -0
  341. package/skills/a2h-spec-design/test/golden/inspect_happy.json +20 -0
  342. package/skills/a2h-spec-design/test/golden/move_design.md +18 -0
  343. package/skills/a2h-spec-design/test/golden/move_design_crlf.md +18 -0
  344. package/skills/a2h-spec-design/test/golden/move_spec.md +7 -0
  345. package/skills/a2h-spec-design/test/golden/resolve_cases.json +36 -0
  346. package/skills/a2h-spec-design/test/golden/validate_issue_file.md +12 -0
  347. package/skills/a2h-spec-design/test/golden/validate_issues.json +57 -0
  348. package/skills/a2h-spec-design/test/test_spec_design_scripts.mjs +381 -0
  349. package/skills/a2h-spec-design-pipeline/SKILL.md +228 -0
  350. package/skills/a2h-spec-design-pipeline/package.json +4 -0
  351. package/skills/a2h-spec-design-pipeline/references/coding-loop.md +63 -0
  352. package/skills/a2h-spec-design-pipeline/references/execution-model.md +69 -0
  353. package/skills/a2h-spec-design-pipeline/references/final-report-template.md +24 -0
  354. package/skills/a2h-spec-design-pipeline/references/initialization.md +57 -0
  355. package/skills/a2h-spec-design-pipeline/references/merge-queue.md +21 -0
  356. package/skills/a2h-spec-design-pipeline/references/scripts.md +27 -0
  357. package/skills/a2h-spec-design-pipeline/references/specs.example.json +19 -0
  358. package/skills/a2h-spec-design-pipeline/references/state-and-resume.md +21 -0
  359. package/skills/a2h-spec-design-pipeline/scripts/atomic_write.ts +42 -0
  360. package/skills/a2h-spec-design-pipeline/scripts/audit_claims.ts +252 -0
  361. package/skills/a2h-spec-design-pipeline/scripts/branch_landed.ts +77 -0
  362. package/skills/a2h-spec-design-pipeline/scripts/deps_ready.ts +195 -0
  363. package/skills/a2h-spec-design-pipeline/scripts/ensure_wt_index.ts +651 -0
  364. package/skills/a2h-spec-design-pipeline/scripts/git_baseline.ts +124 -0
  365. package/skills/a2h-spec-design-pipeline/scripts/inflight.mjs +944 -0
  366. package/skills/a2h-spec-design-pipeline/scripts/lib/bgcli.mjs +95 -0
  367. package/skills/a2h-spec-design-pipeline/scripts/plan_groups.ts +502 -0
  368. package/skills/a2h-spec-design-pipeline/scripts/plan_waves.ts +475 -0
  369. package/skills/a2h-spec-design-pipeline/scripts/reconcile.mjs +218 -0
  370. package/skills/a2h-spec-design-pipeline/scripts/resolve_wiring.ts +164 -0
  371. package/skills/a2h-spec-design-pipeline/scripts/test_atomic_write.ts +44 -0
  372. package/skills/a2h-spec-design-pipeline/scripts/test_audit_claims.ts +301 -0
  373. package/skills/a2h-spec-design-pipeline/scripts/test_bgcli.mjs +64 -0
  374. package/skills/a2h-spec-design-pipeline/scripts/test_branch_landed.ts +87 -0
  375. package/skills/a2h-spec-design-pipeline/scripts/test_deps_ready.ts +265 -0
  376. package/skills/a2h-spec-design-pipeline/scripts/test_ensure_wt_index.ts +675 -0
  377. package/skills/a2h-spec-design-pipeline/scripts/test_git_baseline.ts +105 -0
  378. package/skills/a2h-spec-design-pipeline/scripts/test_inflight.mjs +452 -0
  379. package/skills/a2h-spec-design-pipeline/scripts/test_plan_groups.ts +375 -0
  380. package/skills/a2h-spec-design-pipeline/scripts/test_plan_waves.ts +561 -0
  381. package/skills/a2h-spec-design-pipeline/scripts/test_reconcile.mjs +182 -0
  382. package/skills/a2h-spec-design-pipeline/scripts/test_resolve_wiring.ts +138 -0
  383. package/skills/a2h-spec-design-pipeline/scripts/test_watchdog.mjs +289 -0
  384. package/skills/a2h-spec-design-pipeline/scripts/watchdog.mjs +441 -0
  385. package/skills/a2h-spec-generate/SKILL.md +285 -0
  386. package/skills/a2h-spec-generate/package.json +9 -0
  387. package/skills/a2h-spec-generate/references/batch-mode.md +151 -0
  388. package/skills/a2h-spec-generate/references/delete-blast-radius.md +3 -0
  389. package/skills/a2h-spec-generate/references/fusion-task-contract.md +114 -0
  390. package/skills/a2h-spec-generate/references/input-formats.md +27 -0
  391. package/skills/a2h-spec-generate/references/library-evidence.md +3 -0
  392. package/skills/a2h-spec-generate/references/method-discipline.md +64 -0
  393. package/skills/a2h-spec-generate/references/optional-gates.json +45 -0
  394. package/skills/a2h-spec-generate/references/recall-guide.md +83 -0
  395. package/skills/a2h-spec-generate/references/recall-terse.md +3 -0
  396. package/skills/a2h-spec-generate/references/recall-uniapp.md +10 -0
  397. package/skills/a2h-spec-generate/references/requirement-scope.md +122 -0
  398. package/skills/a2h-spec-generate/references/review-checklist.md +21 -0
  399. package/skills/a2h-spec-generate/references/spec-sample-complex.md +80 -0
  400. package/skills/a2h-spec-generate/references/spec-sample-transfer.md +43 -0
  401. package/skills/a2h-spec-generate/references/spec-samples.md +65 -0
  402. package/skills/a2h-spec-generate/references/specs.schema.json +79 -0
  403. package/skills/a2h-spec-generate/references/synthesis-rules.md +143 -0
  404. package/skills/a2h-spec-generate/references/transfer-file.md +5 -0
  405. package/skills/a2h-spec-generate/references/transfer-socket.md +5 -0
  406. package/skills/a2h-spec-generate/references/worker-rules.md +126 -0
  407. package/skills/a2h-spec-generate/scripts/check-fused-spec.mjs +514 -0
  408. package/skills/a2h-spec-generate/scripts/check_spec.ts +361 -0
  409. package/skills/a2h-spec-generate/scripts/collect-specs.mjs +470 -0
  410. package/skills/a2h-spec-generate/scripts/detect-project.mjs +271 -0
  411. package/skills/a2h-spec-generate/scripts/ensure-index.mjs +188 -0
  412. package/skills/a2h-spec-generate/scripts/feature-stem.mjs +150 -0
  413. package/skills/a2h-spec-generate/scripts/inspect-uniapp.mjs +733 -0
  414. package/skills/{hmos-spec-generate → a2h-spec-generate}/scripts/parse_requirements.ts +1 -1
  415. package/skills/a2h-spec-generate/scripts/prepare-facts.mjs +307 -0
  416. package/skills/a2h-spec-generate/scripts/publication-verdict.mjs +171 -0
  417. package/skills/a2h-spec-generate/scripts/publish-specs.mjs +280 -0
  418. package/skills/a2h-spec-generate/scripts/render-tasks.mjs +399 -0
  419. package/skills/a2h-spec-generate/scripts/report.mjs +132 -0
  420. package/skills/a2h-spec-generate/scripts/reqgen/assets/dashboard.html +149 -0
  421. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-api.js +49 -0
  422. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-code-view.js +140 -0
  423. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-format.js +16 -0
  424. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-handoff.js +42 -0
  425. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-splitters.js +78 -0
  426. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-state.js +47 -0
  427. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-tree.js +194 -0
  428. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-virtual-list.js +118 -0
  429. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz.css +245 -0
  430. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz.html +99 -0
  431. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz.js +220 -0
  432. package/skills/a2h-spec-generate/scripts/reqgen/package-lock.json +47 -0
  433. package/skills/a2h-spec-generate/scripts/reqgen/package.json +23 -0
  434. package/skills/a2h-spec-generate/scripts/reqgen/src/agent-render/serve.ts +95 -0
  435. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/callback-call-sites.ts +82 -0
  436. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/area-ownership.ts +496 -0
  437. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/build.ts +2217 -0
  438. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/callback-flow.ts +386 -0
  439. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/component-variants.ts +845 -0
  440. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/index.ts +24 -0
  441. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/index.ts +22 -0
  442. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/policy.ts +572 -0
  443. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/traceability.ts +580 -0
  444. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/req-model/build.ts +1270 -0
  445. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/req-model/index.ts +10 -0
  446. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/req-model/projection.ts +804 -0
  447. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/req-model/render-projection.ts +51 -0
  448. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/source-facts/android-interaction-registry.ts +286 -0
  449. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/source-facts/builder.ts +453 -0
  450. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/source-facts/compose-api-registry.ts +526 -0
  451. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/source-facts/index.ts +15 -0
  452. package/skills/a2h-spec-generate/scripts/reqgen/src/connector/index.ts +1 -0
  453. package/skills/a2h-spec-generate/scripts/reqgen/src/connector/utg-inbound.ts +763 -0
  454. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/area-graph.ts +383 -0
  455. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/artifact.ts +68 -0
  456. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/common.ts +88 -0
  457. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/diagnostic.ts +64 -0
  458. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/gap-audit.ts +113 -0
  459. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/index.ts +12 -0
  460. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/name-traceability.ts +108 -0
  461. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/raw-fact.ts +377 -0
  462. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/req-model.ts +238 -0
  463. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/run.ts +134 -0
  464. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/semantic-completeness.ts +35 -0
  465. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/source-facts.ts +48 -0
  466. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/utg.ts +133 -0
  467. package/skills/a2h-spec-generate/scripts/reqgen/src/core/output-guard.ts +42 -0
  468. package/skills/a2h-spec-generate/scripts/reqgen/src/core/stable-id.ts +118 -0
  469. package/skills/a2h-spec-generate/scripts/reqgen/src/cross-area-tally-cli.ts +179 -0
  470. package/skills/a2h-spec-generate/scripts/reqgen/src/dashboard-cli.ts +188 -0
  471. package/skills/a2h-spec-generate/scripts/reqgen/src/dump/dump.ts +1184 -0
  472. package/skills/a2h-spec-generate/scripts/reqgen/src/dump/index.ts +1 -0
  473. package/skills/a2h-spec-generate/scripts/reqgen/src/dump-cli.ts +373 -0
  474. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/area-facts.ts +1014 -0
  475. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/area-output.ts +32 -0
  476. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/schema.ts +142 -0
  477. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/selfcheck.ts +312 -0
  478. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/spec-bindings.ts +310 -0
  479. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/task-contract.ts +685 -0
  480. package/skills/a2h-spec-generate/scripts/reqgen/src/graph/paths.ts +575 -0
  481. package/skills/a2h-spec-generate/scripts/reqgen/src/homegraph-cli.ts +50 -0
  482. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/android-resource-resolver.ts +391 -0
  483. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/androidx-preference-contracts.ts +44 -0
  484. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/contracts.ts +640 -0
  485. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/cross-area.ts +207 -0
  486. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/finalizer.ts +1297 -0
  487. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/identity.ts +186 -0
  488. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/index.ts +16 -0
  489. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/planner.ts +312 -0
  490. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/preference-enrichment.ts +793 -0
  491. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/raw-facts.ts +355 -0
  492. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/rules.ts +271 -0
  493. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/scanner.ts +666 -0
  494. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/schema.ts +365 -0
  495. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/stable-key.ts +144 -0
  496. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/task-contract.ts +301 -0
  497. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/tree-sitter-adapter.ts +923 -0
  498. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/uniapp-utg-adapter.ts +543 -0
  499. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/xml-adapter.ts +262 -0
  500. package/skills/a2h-spec-generate/scripts/reqgen/src/model/assemble.ts +2079 -0
  501. package/skills/a2h-spec-generate/scripts/reqgen/src/model/contracts.ts +157 -0
  502. package/skills/a2h-spec-generate/scripts/reqgen/src/model/finalize.ts +809 -0
  503. package/skills/a2h-spec-generate/scripts/reqgen/src/model/index.ts +17 -0
  504. package/skills/a2h-spec-generate/scripts/reqgen/src/model/io.ts +165 -0
  505. package/skills/a2h-spec-generate/scripts/reqgen/src/model/prepare.ts +806 -0
  506. package/skills/a2h-spec-generate/scripts/reqgen/src/model/query.ts +360 -0
  507. package/skills/a2h-spec-generate/scripts/reqgen/src/model/seeds.ts +218 -0
  508. package/skills/a2h-spec-generate/scripts/reqgen/src/model/spec-bindings-sidecar.ts +240 -0
  509. package/skills/a2h-spec-generate/scripts/reqgen/src/model/task.ts +359 -0
  510. package/skills/a2h-spec-generate/scripts/reqgen/src/model-cli.ts +500 -0
  511. package/skills/a2h-spec-generate/scripts/reqgen/src/pipeline/index.ts +7 -0
  512. package/skills/a2h-spec-generate/scripts/reqgen/src/pipeline/output.ts +307 -0
  513. package/skills/a2h-spec-generate/scripts/reqgen/src/requirement-scope.ts +172 -0
  514. package/skills/a2h-spec-generate/scripts/reqgen/src/source-cov/index.ts +1 -0
  515. package/skills/a2h-spec-generate/scripts/reqgen/src/source-cov/source-cov.ts +176 -0
  516. package/skills/a2h-spec-generate/scripts/reqgen/src/source-index/homegraph.ts +1039 -0
  517. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/area-graph.ts +490 -0
  518. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/index.ts +23 -0
  519. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/req-model.ts +957 -0
  520. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/req-text.ts +248 -0
  521. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/semantic-area-graph.ts +1600 -0
  522. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/types.ts +10 -0
  523. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/artifact-data.ts +201 -0
  524. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-api.ts +74 -0
  525. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-code-view.ts +180 -0
  526. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-format.ts +18 -0
  527. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-handoff.ts +55 -0
  528. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-splitters.ts +78 -0
  529. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-state.ts +66 -0
  530. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-tree.ts +232 -0
  531. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-virtual-list.ts +179 -0
  532. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz.ts +240 -0
  533. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/contracts.d.ts +86 -0
  534. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/index.ts +3 -0
  535. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/server.ts +239 -0
  536. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/source-project.ts +316 -0
  537. package/skills/a2h-spec-generate/scripts/reqgen/src/viz-cli.ts +200 -0
  538. package/skills/a2h-spec-generate/scripts/reqgen/test/control-fact-join.test.ts +50 -0
  539. package/skills/a2h-spec-generate/scripts/reqgen/test/control-name-uniapp.test.ts +75 -0
  540. package/skills/a2h-spec-generate/scripts/reqgen/test/cross-area-anchor.test.ts +256 -0
  541. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-area-facts.test.ts +576 -0
  542. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-contract.test.ts +290 -0
  543. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-finalize.test.ts +1323 -0
  544. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-prepare.test.ts +574 -0
  545. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-scope.test.ts +339 -0
  546. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-selfcheck.test.ts +831 -0
  547. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-spec.test.ts +548 -0
  548. package/skills/a2h-spec-generate/scripts/reqgen/test/model-cli-blockers.test.ts +117 -0
  549. package/skills/a2h-spec-generate/scripts/reqgen/test/model-scope.test.ts +396 -0
  550. package/skills/a2h-spec-generate/scripts/reqgen/test/model-seeds.test.ts +175 -0
  551. package/skills/a2h-spec-generate/scripts/reqgen/test/model-task-contract.test.ts +298 -0
  552. package/skills/a2h-spec-generate/scripts/reqgen/test/model-v4.test.ts +1061 -0
  553. package/skills/a2h-spec-generate/scripts/reqgen/test/specgen-completeness.test.ts +286 -0
  554. package/skills/a2h-spec-generate/scripts/reqgen/test/stagem-stored-path.test.ts +25 -0
  555. package/skills/a2h-spec-generate/scripts/reqgen/test/uniapp-scanner.test.ts +159 -0
  556. package/skills/a2h-spec-generate/scripts/reqgen/tsconfig.json +16 -0
  557. package/skills/a2h-spec-generate/scripts/reqgen/tsconfig.viz-client.json +12 -0
  558. package/skills/a2h-spec-generate/test/check-fused-spec.test.mjs +632 -0
  559. package/skills/a2h-spec-generate/test/check-spec.test.ts +200 -0
  560. package/skills/a2h-spec-generate/test/collect-specs.test.mjs +538 -0
  561. package/skills/a2h-spec-generate/test/detect-project.test.mjs +37 -0
  562. package/skills/a2h-spec-generate/test/ensure-index.test.mjs +45 -0
  563. package/skills/a2h-spec-generate/test/feature-stem.test.mjs +147 -0
  564. package/skills/a2h-spec-generate/test/fixtures/android/app/src/main/AndroidManifest.xml +3 -0
  565. package/skills/a2h-spec-generate/test/fixtures/android/build.gradle +3 -0
  566. package/skills/a2h-spec-generate/test/fixtures/android/settings.gradle +3 -0
  567. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/package.json +9 -0
  568. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/App.vue +8 -0
  569. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/components/MyCard.vue +9 -0
  570. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/feature/editor/index.vue +1 -0
  571. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/main.ts +6 -0
  572. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/manifest.json +4 -0
  573. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/detail/index.vue +1 -0
  574. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/home/index.vue +33 -0
  575. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/settings/index.vue +1 -0
  576. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages.json +23 -0
  577. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/services/items.ts +3 -0
  578. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/tsconfig.json +8 -0
  579. package/skills/a2h-spec-generate/test/fixtures/unknown/README.txt +1 -0
  580. package/skills/a2h-spec-generate/test/inspect-uniapp.test.mjs +54 -0
  581. package/skills/a2h-spec-generate/test/publication-verdict.test.mjs +157 -0
  582. package/skills/a2h-spec-generate/test/publish-specs.test.mjs +282 -0
  583. package/skills/a2h-spec-generate/test/render-tasks.test.mjs +593 -0
  584. package/skills/a2h-utg-explorer/SKILL.md +120 -0
  585. package/skills/a2h-utg-explorer/assets/final_viewer.html +64 -0
  586. package/skills/a2h-utg-explorer/assets/u2.LICENSE +21 -0
  587. package/skills/a2h-utg-explorer/assets/u2.NOTICE +25 -0
  588. package/skills/a2h-utg-explorer/assets/u2.jar +0 -0
  589. package/skills/a2h-utg-explorer/references/architecture.md +270 -0
  590. package/skills/a2h-utg-explorer/references/protocol.md +9 -0
  591. package/skills/a2h-utg-explorer/scripts/app_settings.mjs +143 -0
  592. package/skills/a2h-utg-explorer/scripts/audit.mjs +167 -0
  593. package/skills/a2h-utg-explorer/scripts/close_phases.mjs +66 -0
  594. package/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +749 -0
  595. package/skills/a2h-utg-explorer/scripts/d_prereqs.mjs +597 -0
  596. package/skills/a2h-utg-explorer/scripts/device_health.mjs +227 -0
  597. package/skills/a2h-utg-explorer/scripts/direct_launch.mjs +276 -0
  598. package/skills/a2h-utg-explorer/scripts/evidence.mjs +108 -0
  599. package/skills/a2h-utg-explorer/scripts/final_utg.mjs +376 -0
  600. package/skills/a2h-utg-explorer/scripts/hint_check.mjs +89 -0
  601. package/skills/a2h-utg-explorer/scripts/plan.mjs +258 -0
  602. package/skills/a2h-utg-explorer/scripts/promote_dynamic.mjs +170 -0
  603. package/skills/a2h-utg-explorer/scripts/recover.mjs +467 -0
  604. package/skills/a2h-utg-explorer/scripts/recover_b.mjs +542 -0
  605. package/skills/a2h-utg-explorer/scripts/recover_d.mjs +302 -0
  606. package/skills/a2h-utg-explorer/scripts/rejudge.mjs +203 -0
  607. package/skills/a2h-utg-explorer/scripts/report.mjs +143 -0
  608. package/skills/a2h-utg-explorer/scripts/run_cycle.mjs +831 -0
  609. package/skills/a2h-utg-explorer/scripts/run_device.mjs +137 -0
  610. package/skills/a2h-utg-explorer/scripts/tests/attest.test.mjs +66 -0
  611. package/skills/a2h-utg-explorer/scripts/tests/chain.test.mjs +45 -0
  612. package/skills/a2h-utg-explorer/scripts/tests/compose_identity.test.mjs +207 -0
  613. package/skills/a2h-utg-explorer/scripts/tests/coverage_rules.test.mjs +104 -0
  614. package/skills/a2h-utg-explorer/scripts/tests/d_prereqs.test.mjs +223 -0
  615. package/skills/a2h-utg-explorer/scripts/tests/device_health.test.mjs +88 -0
  616. package/skills/a2h-utg-explorer/scripts/tests/device_lock_retry.test.mjs +187 -0
  617. package/skills/a2h-utg-explorer/scripts/tests/direct_launch.test.mjs +130 -0
  618. package/skills/a2h-utg-explorer/scripts/tests/explorer_review_fixes.test.mjs +136 -0
  619. package/skills/a2h-utg-explorer/scripts/tests/final_utg.test.mjs +135 -0
  620. package/skills/a2h-utg-explorer/scripts/tests/first_round_phases.test.mjs +16 -0
  621. package/skills/a2h-utg-explorer/scripts/tests/generalization_fixes.test.mjs +251 -0
  622. package/skills/a2h-utg-explorer/scripts/tests/hint_check.test.mjs +42 -0
  623. package/skills/a2h-utg-explorer/scripts/tests/interruptions.test.mjs +162 -0
  624. package/skills/a2h-utg-explorer/scripts/tests/node_coverage.test.mjs +193 -0
  625. package/skills/a2h-utg-explorer/scripts/tests/overflow_prefix.test.mjs +204 -0
  626. package/skills/a2h-utg-explorer/scripts/tests/page_identity_tiers.test.mjs +355 -0
  627. package/skills/a2h-utg-explorer/scripts/tests/pipeline.test.mjs +240 -0
  628. package/skills/a2h-utg-explorer/scripts/tests/recover.test.mjs +212 -0
  629. package/skills/a2h-utg-explorer/scripts/tests/recover_b.test.mjs +173 -0
  630. package/skills/a2h-utg-explorer/scripts/tests/recover_d.test.mjs +207 -0
  631. package/skills/a2h-utg-explorer/scripts/tests/review_fixes.test.mjs +213 -0
  632. package/skills/a2h-utg-explorer/scripts/tests/robustness_fixes.test.mjs +345 -0
  633. package/skills/a2h-utg-explorer/scripts/tests/run_cycle.test.mjs +453 -0
  634. package/skills/a2h-utg-explorer/scripts/tests/runner_capabilities.test.mjs +131 -0
  635. package/skills/a2h-utg-explorer/scripts/tests/scope.test.mjs +229 -0
  636. package/skills/a2h-utg-explorer/scripts/tests/scroll_sweep.test.mjs +321 -0
  637. package/skills/a2h-utg-explorer/scripts/tests/semantics.test.mjs +102 -0
  638. package/skills/a2h-utg-explorer/scripts/tests/twin_opener.test.mjs +119 -0
  639. package/skills/a2h-utg-explorer/scripts/tests/u2_backend.test.mjs +346 -0
  640. package/skills/a2h-utg-explorer/scripts/tests/ui_state_anchors.test.mjs +112 -0
  641. package/skills/a2h-utg-explorer/scripts/tests/variant_strings.test.mjs +63 -0
  642. package/skills/a2h-utg-explorer/scripts/tests/worklist_parts.test.mjs +24 -0
  643. package/skills/a2h-utg-explorer/scripts/utg_explorer/_device_io.mjs +244 -0
  644. package/skills/a2h-utg-explorer/scripts/utg_explorer/_py.mjs +2097 -0
  645. package/skills/a2h-utg-explorer/scripts/utg_explorer/adapters.mjs +1213 -0
  646. package/skills/a2h-utg-explorer/scripts/utg_explorer/attest.mjs +63 -0
  647. package/skills/a2h-utg-explorer/scripts/utg_explorer/chain.mjs +63 -0
  648. package/skills/a2h-utg-explorer/scripts/utg_explorer/coverage.mjs +89 -0
  649. package/skills/a2h-utg-explorer/scripts/utg_explorer/device_lock.mjs +46 -0
  650. package/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +1136 -0
  651. package/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +1513 -0
  652. package/skills/a2h-utg-explorer/scripts/variant.mjs +75 -0
  653. package/skills/a2h-utg-explorer/scripts/worklist_parts.mjs +122 -0
  654. package/skills/a2h-utg-static/SKILL.md +361 -0
  655. package/skills/a2h-utg-static/config.json +19 -0
  656. package/skills/a2h-utg-static/references/extractors.md +217 -0
  657. package/skills/a2h-utg-static/references/ui-elements-static-utg-schema.md +248 -0
  658. package/skills/a2h-utg-static/references/view-interactions.md +215 -0
  659. package/skills/a2h-utg-static/scripts/_graph.mjs +361 -0
  660. package/skills/a2h-utg-static/scripts/_py.mjs +2177 -0
  661. package/skills/a2h-utg-static/scripts/_spawn.mjs +45 -0
  662. package/skills/a2h-utg-static/scripts/activity_nav.mjs +738 -0
  663. package/skills/a2h-utg-static/scripts/activity_widgets.mjs +254 -0
  664. package/skills/a2h-utg-static/scripts/adapter_nav.mjs +229 -0
  665. package/skills/a2h-utg-static/scripts/androidfragment_nav.mjs +208 -0
  666. package/skills/a2h-utg-static/scripts/assemble.mjs +2065 -0
  667. package/skills/a2h-utg-static/scripts/audit.mjs +268 -0
  668. package/skills/a2h-utg-static/scripts/carry_answers.mjs +201 -0
  669. package/skills/a2h-utg-static/scripts/click_paths.mjs +594 -0
  670. package/skills/a2h-utg-static/scripts/compose_body_text.mjs +172 -0
  671. package/skills/a2h-utg-static/scripts/compose_merge.mjs +263 -0
  672. package/skills/a2h-utg-static/scripts/compose_nav.mjs +1216 -0
  673. package/skills/a2h-utg-static/scripts/compose_navbar_nav.mjs +238 -0
  674. package/skills/a2h-utg-static/scripts/compose_overlay.mjs +2760 -0
  675. package/skills/a2h-utg-static/scripts/compose_titles.mjs +365 -0
  676. package/skills/a2h-utg-static/scripts/compose_widgets.mjs +498 -0
  677. package/skills/a2h-utg-static/scripts/dialog_listener_nav.mjs +237 -0
  678. package/skills/a2h-utg-static/scripts/dialogshow_nav.mjs +308 -0
  679. package/skills/a2h-utg-static/scripts/fragfactory_nav.mjs +170 -0
  680. package/skills/a2h-utg-static/scripts/fragment_nav.mjs +1136 -0
  681. package/skills/a2h-utg-static/scripts/guard_subjects.mjs +162 -0
  682. package/skills/a2h-utg-static/scripts/hg_query.mjs +137 -0
  683. package/skills/a2h-utg-static/scripts/host_resolve.mjs +393 -0
  684. package/skills/a2h-utg-static/scripts/hybrid_bundle.mjs +165 -0
  685. package/skills/a2h-utg-static/scripts/hybrid_pages.mjs +713 -0
  686. package/skills/a2h-utg-static/scripts/hybrid_scope.mjs +660 -0
  687. package/skills/a2h-utg-static/scripts/interaction_sites.mjs +267 -0
  688. package/skills/a2h-utg-static/scripts/io_utils.mjs +59 -0
  689. package/skills/a2h-utg-static/scripts/label_resolve.mjs +864 -0
  690. package/skills/a2h-utg-static/scripts/launch_extras.mjs +91 -0
  691. package/skills/a2h-utg-static/scripts/layout_resolve.mjs +148 -0
  692. package/skills/a2h-utg-static/scripts/manifest.mjs +483 -0
  693. package/skills/a2h-utg-static/scripts/measure/measure_corpus.mjs +297 -0
  694. package/skills/a2h-utg-static/scripts/measure/measure_guards.mjs +98 -0
  695. package/skills/a2h-utg-static/scripts/media_browse_nav.mjs +356 -0
  696. package/skills/a2h-utg-static/scripts/menu_nav.mjs +603 -0
  697. package/skills/a2h-utg-static/scripts/navactions_nav.mjs +255 -0
  698. package/skills/a2h-utg-static/scripts/nl_hints.mjs +453 -0
  699. package/skills/a2h-utg-static/scripts/orphan_overlay_nav.mjs +89 -0
  700. package/skills/a2h-utg-static/scripts/phase_plan.mjs +108 -0
  701. package/skills/a2h-utg-static/scripts/phase_planner.mjs +119 -0
  702. package/skills/a2h-utg-static/scripts/plaindialog_nav.mjs +411 -0
  703. package/skills/a2h-utg-static/scripts/preference_nav.mjs +761 -0
  704. package/skills/a2h-utg-static/scripts/preference_widgets.mjs +142 -0
  705. package/skills/a2h-utg-static/scripts/presenter_nav.mjs +490 -0
  706. package/skills/a2h-utg-static/scripts/registry_nav.mjs +288 -0
  707. package/skills/a2h-utg-static/scripts/run_pipeline.mjs +870 -0
  708. package/skills/a2h-utg-static/scripts/scope_utils.mjs +430 -0
  709. package/skills/a2h-utg-static/scripts/screen_merge.mjs +287 -0
  710. package/skills/a2h-utg-static/scripts/screen_nav.mjs +279 -0
  711. package/skills/a2h-utg-static/scripts/single_host_nav.mjs +291 -0
  712. package/skills/a2h-utg-static/scripts/starter_nav.mjs +198 -0
  713. package/skills/a2h-utg-static/scripts/state_guard.mjs +579 -0
  714. package/skills/a2h-utg-static/scripts/static_prior.mjs +904 -0
  715. package/skills/a2h-utg-static/scripts/tests/_zipw.mjs +28 -0
  716. package/skills/a2h-utg-static/scripts/tests/probe_autoload.mjs +108 -0
  717. package/skills/a2h-utg-static/scripts/tests/probe_layout_fragments.mjs +90 -0
  718. package/skills/a2h-utg-static/scripts/tests/probe_unknown_scope.mjs +61 -0
  719. package/skills/a2h-utg-static/scripts/tests/regression_matrix.mjs +1261 -0
  720. package/skills/a2h-utg-static/scripts/tests/test_activity_alias_launcher.mjs +90 -0
  721. package/skills/a2h-utg-static/scripts/tests/test_activity_supertype_chain.mjs +106 -0
  722. package/skills/a2h-utg-static/scripts/tests/test_bottom_sheet_container.mjs +58 -0
  723. package/skills/a2h-utg-static/scripts/tests/test_branch_guard.mjs +19 -0
  724. package/skills/a2h-utg-static/scripts/tests/test_callee_string_default.mjs +30 -0
  725. package/skills/a2h-utg-static/scripts/tests/test_carry_answers.mjs +103 -0
  726. package/skills/a2h-utg-static/scripts/tests/test_chrome_tokens.mjs +60 -0
  727. package/skills/a2h-utg-static/scripts/tests/test_commented_out_trigger.mjs +111 -0
  728. package/skills/a2h-utg-static/scripts/tests/test_commit_scope.mjs +113 -0
  729. package/skills/a2h-utg-static/scripts/tests/test_compose_file_private_route.mjs +117 -0
  730. package/skills/a2h-utg-static/scripts/tests/test_compose_nested_graph.mjs +166 -0
  731. package/skills/a2h-utg-static/scripts/tests/test_compose_route_holder_collision.mjs +112 -0
  732. package/skills/a2h-utg-static/scripts/tests/test_compose_vm_nav.mjs +267 -0
  733. package/skills/a2h-utg-static/scripts/tests/test_custom_source_root.mjs +71 -0
  734. package/skills/a2h-utg-static/scripts/tests/test_defensive_null_guard.mjs +77 -0
  735. package/skills/a2h-utg-static/scripts/tests/test_dialog_orphan_entries.mjs +99 -0
  736. package/skills/a2h-utg-static/scripts/tests/test_dialog_page_owner.mjs +69 -0
  737. package/skills/a2h-utg-static/scripts/tests/test_dialogshow_builder_forms.mjs +96 -0
  738. package/skills/a2h-utg-static/scripts/tests/test_dialogshow_java_factory.mjs +37 -0
  739. package/skills/a2h-utg-static/scripts/tests/test_disabled_guard.mjs +42 -0
  740. package/skills/a2h-utg-static/scripts/tests/test_drawer_panel_gesture.mjs +140 -0
  741. package/skills/a2h-utg-static/scripts/tests/test_edge_dedupe_by_gesture.mjs +111 -0
  742. package/skills/a2h-utg-static/scripts/tests/test_edge_provenance_lint.mjs +70 -0
  743. package/skills/a2h-utg-static/scripts/tests/test_enclosing_gesture.mjs +69 -0
  744. package/skills/a2h-utg-static/scripts/tests/test_external_surface_roots.mjs +43 -0
  745. package/skills/a2h-utg-static/scripts/tests/test_find_package_indirect.mjs +67 -0
  746. package/skills/a2h-utg-static/scripts/tests/test_forwarding_wrapper.mjs +38 -0
  747. package/skills/a2h-utg-static/scripts/tests/test_fragment_containment.mjs +85 -0
  748. package/skills/a2h-utg-static/scripts/tests/test_fragment_helper_trigger.mjs +92 -0
  749. package/skills/a2h-utg-static/scripts/tests/test_graph.mjs +55 -0
  750. package/skills/a2h-utg-static/scripts/tests/test_guard_clause.mjs +86 -0
  751. package/skills/a2h-utg-static/scripts/tests/test_hint_language.mjs +119 -0
  752. package/skills/a2h-utg-static/scripts/tests/test_host_kind_by_chain.mjs +68 -0
  753. package/skills/a2h-utg-static/scripts/tests/test_hybrid_bundle_attribution.mjs +74 -0
  754. package/skills/a2h-utg-static/scripts/tests/test_hybrid_bundled_pages.mjs +181 -0
  755. package/skills/a2h-utg-static/scripts/tests/test_hybrid_scope.mjs +293 -0
  756. package/skills/a2h-utg-static/scripts/tests/test_hybrid_title_renders.mjs +118 -0
  757. package/skills/a2h-utg-static/scripts/tests/test_interaction_sites.mjs +272 -0
  758. package/skills/a2h-utg-static/scripts/tests/test_item_data_instance.mjs +51 -0
  759. package/skills/a2h-utg-static/scripts/tests/test_kotlin_fn_spans.mjs +69 -0
  760. package/skills/a2h-utg-static/scripts/tests/test_label_accessor_forms.mjs +187 -0
  761. package/skills/a2h-utg-static/scripts/tests/test_label_source.mjs +70 -0
  762. package/skills/a2h-utg-static/scripts/tests/test_launch_intent_guard.mjs +67 -0
  763. package/skills/a2h-utg-static/scripts/tests/test_layout_declared_fragment.mjs +103 -0
  764. package/skills/a2h-utg-static/scripts/tests/test_listener_call_forms.mjs +79 -0
  765. package/skills/a2h-utg-static/scripts/tests/test_listener_receiver_binding.mjs +47 -0
  766. package/skills/a2h-utg-static/scripts/tests/test_manifest_exported_default.mjs +40 -0
  767. package/skills/a2h-utg-static/scripts/tests/test_manifest_filters_modules.mjs +84 -0
  768. package/skills/a2h-utg-static/scripts/tests/test_manifest_srcfile.mjs +68 -0
  769. package/skills/a2h-utg-static/scripts/tests/test_mode_and_cb_param.mjs +172 -0
  770. package/skills/a2h-utg-static/scripts/tests/test_module_namespace.mjs +33 -0
  771. package/skills/a2h-utg-static/scripts/tests/test_module_strings.mjs +44 -0
  772. package/skills/a2h-utg-static/scripts/tests/test_multiple_entry_contracts.mjs +80 -0
  773. package/skills/a2h-utg-static/scripts/tests/test_nav_graph_xml.mjs +35 -0
  774. package/skills/a2h-utg-static/scripts/tests/test_nl_hint_grammar.mjs +42 -0
  775. package/skills/a2h-utg-static/scripts/tests/test_nl_hints_gate.mjs +85 -0
  776. package/skills/a2h-utg-static/scripts/tests/test_node_id_collision.mjs +57 -0
  777. package/skills/a2h-utg-static/scripts/tests/test_non_gesture_step_flag.mjs +62 -0
  778. package/skills/a2h-utg-static/scripts/tests/test_out_of_scope_and_settings.mjs +72 -0
  779. package/skills/a2h-utg-static/scripts/tests/test_overload_and_climb.mjs +86 -0
  780. package/skills/a2h-utg-static/scripts/tests/test_pager_page_source.mjs +78 -0
  781. package/skills/a2h-utg-static/scripts/tests/test_pager_position_zero.mjs +65 -0
  782. package/skills/a2h-utg-static/scripts/tests/test_pager_variant_guard.mjs +172 -0
  783. package/skills/a2h-utg-static/scripts/tests/test_pipeline_llm_phases.mjs +107 -0
  784. package/skills/a2h-utg-static/scripts/tests/test_plain_dialog_nodes.mjs +167 -0
  785. package/skills/a2h-utg-static/scripts/tests/test_plaindialog_shared_anchor.mjs +117 -0
  786. package/skills/a2h-utg-static/scripts/tests/test_preference_click_nav.mjs +98 -0
  787. package/skills/a2h-utg-static/scripts/tests/test_preference_host_binding.mjs +87 -0
  788. package/skills/a2h-utg-static/scripts/tests/test_preference_nesting.mjs +183 -0
  789. package/skills/a2h-utg-static/scripts/tests/test_preference_widgets.mjs +48 -0
  790. package/skills/a2h-utg-static/scripts/tests/test_read_text_crlf.mjs +41 -0
  791. package/skills/a2h-utg-static/scripts/tests/test_resolver_tier_parity.mjs +126 -0
  792. package/skills/a2h-utg-static/scripts/tests/test_result_launcher.mjs +142 -0
  793. package/skills/a2h-utg-static/scripts/tests/test_review_fixes.mjs +135 -0
  794. package/skills/a2h-utg-static/scripts/tests/test_route_token_words.mjs +66 -0
  795. package/skills/a2h-utg-static/scripts/tests/test_same_name_decl_scope.mjs +236 -0
  796. package/skills/a2h-utg-static/scripts/tests/test_scope_utils.mjs +85 -0
  797. package/skills/a2h-utg-static/scripts/tests/test_sealed_dialog_state.mjs +148 -0
  798. package/skills/a2h-utg-static/scripts/tests/test_shared_overlay_split.mjs +63 -0
  799. package/skills/a2h-utg-static/scripts/tests/test_slug_parity.mjs +58 -0
  800. package/skills/a2h-utg-static/scripts/tests/test_starter_node_id.mjs +41 -0
  801. package/skills/a2h-utg-static/scripts/tests/test_state_guard_arity.mjs +109 -0
  802. package/skills/a2h-utg-static/scripts/tests/test_state_guard_commented_candidates.mjs +68 -0
  803. package/skills/a2h-utg-static/scripts/tests/test_state_guard_model_gates.mjs +127 -0
  804. package/skills/a2h-utg-static/scripts/tests/test_state_specific_hop.mjs +130 -0
  805. package/skills/a2h-utg-static/scripts/tests/test_synthetic_label_identity.mjs +51 -0
  806. package/skills/a2h-utg-static/scripts/tests/test_template_method_layout.mjs +81 -0
  807. package/skills/a2h-utg-static/scripts/tests/test_template_title.mjs +58 -0
  808. package/skills/a2h-utg-static/scripts/tests/test_trigger_id_spelling.mjs +68 -0
  809. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_action_override.mjs +91 -0
  810. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_flow_filter.mjs +110 -0
  811. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_nl_hint_key.mjs +89 -0
  812. package/skills/a2h-utg-static/scripts/tests/test_uiless_host_fold.mjs +98 -0
  813. package/skills/a2h-utg-static/scripts/tests/test_uniapp_source.mjs +231 -0
  814. package/skills/a2h-utg-static/scripts/tests/test_view_click_refs.mjs +104 -0
  815. package/skills/a2h-utg-static/scripts/tests/test_view_id_label.mjs +69 -0
  816. package/skills/a2h-utg-static/scripts/tests/test_view_interactions.mjs +346 -0
  817. package/skills/a2h-utg-static/scripts/tests/test_viewpage_nav.mjs +273 -0
  818. package/skills/a2h-utg-static/scripts/tests/test_vm_nav_helper_navigate.mjs +98 -0
  819. package/skills/a2h-utg-static/scripts/tests/test_widget_class_scope.mjs +92 -0
  820. package/skills/a2h-utg-static/scripts/tests/test_window_nav_kotlin.mjs +158 -0
  821. package/skills/a2h-utg-static/scripts/tests/test_worklist_parts.mjs +65 -0
  822. package/skills/a2h-utg-static/scripts/uniapp_nav.mjs +1119 -0
  823. package/skills/a2h-utg-static/scripts/uniapp_widgets.mjs +244 -0
  824. package/skills/a2h-utg-static/scripts/utg_html.mjs +721 -0
  825. package/skills/a2h-utg-static/scripts/view_interactions.mjs +799 -0
  826. package/skills/a2h-utg-static/scripts/view_widgets.mjs +512 -0
  827. package/skills/a2h-utg-static/scripts/viewpage_nav.mjs +485 -0
  828. package/skills/a2h-utg-static/scripts/vm_nav.mjs +422 -0
  829. package/skills/a2h-utg-static/scripts/window_nav.mjs +240 -0
  830. package/skills/a2h-utg-static/scripts/worklist_parts.mjs +154 -0
  831. package/skills/a2h-utg-static/tools/convert_static_utg_to_ui_elements.ts +769 -0
  832. package/skills/a2h-utg-static/tools/package.json +3 -0
  833. package/README.md +0 -445
  834. package/agents/logic-coder.md +0 -224
  835. package/agents/logic-context-builder.md +0 -212
  836. package/agents/scripts/hmos-precheck/backends/arkts.mjs +0 -567
  837. package/agents/scripts/hmos-precheck/backends/arkts_diff.mjs +0 -159
  838. package/agents/scripts/hmos-precheck/backends/arkts_project_rules.mjs +0 -398
  839. package/agents/scripts/hmos-precheck/backends/codelinter.mjs +0 -250
  840. package/agents/scripts/hmos-precheck/backends/project_integrity.mjs +0 -321
  841. package/agents/scripts/hmos-precheck/backends/static_precheck.mjs +0 -247
  842. package/agents/scripts/hmos-precheck/core/config.mjs +0 -184
  843. package/agents/scripts/hmos-precheck/core/diagnostic_scope.mjs +0 -20
  844. package/agents/scripts/hmos-precheck/core/process_adapter.mjs +0 -47
  845. package/agents/scripts/hmos-precheck/core/project_catalog.mjs +0 -50
  846. package/agents/scripts/hmos-precheck/core/result_projection.mjs +0 -147
  847. package/agents/scripts/hmos-precheck/core/scope_plan.mjs +0 -131
  848. package/agents/scripts/hmos-precheck/core/sdk_context.mjs +0 -67
  849. package/agents/scripts/hmos-precheck/docs/architecture.md +0 -37
  850. package/agents/scripts/hmos-precheck/docs/performance-optimization.md +0 -28
  851. package/agents/scripts/hmos-precheck/docs/upstream-reference.json +0 -19
  852. package/agents/scripts/hmos-precheck/docs/validation.md +0 -50
  853. package/agents/scripts/hmos-precheck/index.mjs +0 -17
  854. package/agents/scripts/hmos-precheck/invocation.mjs +0 -231
  855. package/agents/scripts/hmos-precheck/rules/rule_case_matrix.csv +0 -32
  856. package/agents/scripts/hmos-precheck/rules/rule_inventory.csv +0 -64
  857. package/agents/scripts/hmos-precheck/rules/rule_inventory.mjs +0 -59
  858. package/agents/scripts/hmos-precheck/rules/rule_policy.mjs +0 -54
  859. package/agents/scripts/platform_query.mjs +0 -626
  860. package/agents/scripts/platform_query.test.mjs +0 -422
  861. package/agents/self-test-fixer.md +0 -298
  862. package/agents/self-tester.md +0 -55
  863. package/agents/test-case-generation-generator.md +0 -317
  864. package/agents/test-case-generation-validator.md +0 -231
  865. package/dist/cli/config-store.js +0 -310
  866. package/dist/cli/config.js +0 -44
  867. package/dist/cli/env-vars.js +0 -127
  868. package/dist/cli/index.js +0 -56
  869. package/dist/cli/init.js +0 -1187
  870. package/dist/cli/uninstall.js +0 -427
  871. package/dist/utils/regex.js +0 -8
  872. package/env-requirements.json +0 -179
  873. package/resource/choose_editor.png +0 -0
  874. package/resource/convert_pipeline_process.svg +0 -103
  875. package/resource/project_architecture.svg +0 -122
  876. package/resource/set_environment.png +0 -0
  877. package/resource/set_multimodel.png +0 -0
  878. package/resource/set_sdk.png +0 -0
  879. package/resource/title_dark.png +0 -0
  880. package/skills/hmos-batch-ui-align/SKILL.md +0 -413
  881. package/skills/hmos-batch-ui-align/scripts/arkts_static_check.ts +0 -1592
  882. package/skills/hmos-batch-ui-align/scripts/measure_pack.ts +0 -752
  883. package/skills/hmos-convert-pipeline/SKILL.md +0 -486
  884. package/skills/hmos-incremental-ui-align/README.md +0 -251
  885. package/skills/hmos-incremental-ui-align/SKILL.md +0 -375
  886. package/skills/hmos-incremental-ui-align/diff_analysis.md +0 -53
  887. package/skills/hmos-incremental-ui-align/page_align.md +0 -62
  888. package/skills/hmos-incremental-ui-align/references/Comparison_Template.md +0 -38
  889. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Link/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/217/214/345/220/221/345/220/214/346/255/245.md +0 -648
  890. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Observed/350/243/205/351/245/260/345/231/250/345/222/214@ObjectLink/350/243/205/351/245/260/345/231/250/357/274/232/345/265/214/345/245/227/347/261/273/345/257/271/350/261/241/345/261/236/346/200/247/345/217/230/345/214/226.md +0 -2089
  891. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Prop/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/215/225/345/220/221/345/220/214/346/255/245.md +0 -1033
  892. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Provide/350/243/205/351/245/260/345/231/250/345/222/214@Consume/350/243/205/351/245/260/345/231/250/357/274/232/344/270/216/345/220/216/344/273/243/347/273/204/344/273/266/345/217/214/345/220/221/345/220/214/346/255/245.md +0 -1183
  893. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@State/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/347/212/266/346/200/201.md +0 -576
  894. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Track/350/243/205/351/245/260/345/231/250/357/274/232class/345/257/271/350/261/241/345/261/236/346/200/247/347/272/247/346/233/264/346/226/260.md +0 -297
  895. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Watch/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/346/233/264/346/224/271/351/200/232/347/237/245.md +0 -395
  896. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/AppStorage/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200/347/232/204UI/347/212/266/346/200/201/345/255/230/345/202/250.md +0 -903
  897. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/Environment/357/274/232/350/256/276/345/244/207/347/216/257/345/242/203/346/237/245/350/257/242.md +0 -106
  898. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/LocalStorage/357/274/232/351/241/265/351/235/242/347/272/247UI/347/212/266/346/200/201/345/255/230/345/202/250.md +0 -1178
  899. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/MVVM/346/250/241/345/274/217V1.md +0 -911
  900. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/PersistentStorage/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +0 -355
  901. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243//347/256/241/347/220/206/345/272/224/347/224/250/346/213/245/346/234/211/347/232/204/347/212/266/346/200/201/346/246/202/350/277/260.md +0 -11
  902. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/!!/350/257/255/346/263/225/357/274/232/345/217/214/345/220/221/347/273/221/345/256/232.md +0 -206
  903. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Computed/350/243/205/351/245/260/345/231/250/357/274/232/350/256/241/347/256/227/345/261/236/346/200/247.md +0 -373
  904. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Event/350/243/205/351/245/260/345/231/250/357/274/232/350/247/204/350/214/203/347/273/204/344/273/266/350/276/223/345/207/272.md +0 -158
  905. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Local/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/351/203/250/347/212/266/346/200/201.md +0 -750
  906. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Monitor/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/344/277/256/346/224/271/345/274/202/346/255/245/347/233/221/345/220/254.md +0 -1704
  907. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@ObservedV2/350/243/205/351/245/260/345/231/250/345/222/214@Trace/350/243/205/351/245/260/345/231/250/357/274/232/347/261/273/345/261/236/346/200/247/345/217/230/345/214/226/350/247/202/346/265/213.md +0 -1012
  908. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Once/350/243/205/351/245/260/345/231/250/357/274/232/345/210/235/345/247/213/345/214/226/345/220/214/346/255/245/344/270/200/346/254/241.md +0 -164
  909. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Param/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/244/226/351/203/250/350/276/223/345/205/245.md +0 -840
  910. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Provider/350/243/205/351/245/260/345/231/250/345/222/214@Consumer/350/243/205/351/245/260/345/231/250/357/274/232/350/267/250/347/273/204/344/273/266/345/261/202/347/272/247/345/217/214/345/220/221/345/220/214/346/255/245.md +0 -856
  911. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Type/350/243/205/351/245/260/345/231/250/357/274/232/346/240/207/350/256/260/347/261/273/345/261/236/346/200/247/347/232/204/347/261/273/345/236/213.md +0 -83
  912. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/AppStorageV2/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200UI/347/212/266/346/200/201/345/255/230/345/202/250.md +0 -294
  913. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/PersistenceV2/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +0 -1220
  914. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/_/350/214/203/345/274/217/351/200/211/346/213/251/350/257/264/346/230/216.md +0 -47
  915. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2//347/212/266/346/200/201/347/256/241/347/220/206V1/345/220/221V2/350/277/201/347/247/273/344/270/216/346/267/267/347/224/250/346/214/207/345/257/274.md +0 -840
  916. package/skills/hmos-incremental-ui-align/references/State_Model_Template.md +0 -74
  917. package/skills/hmos-incremental-ui-align/references/UI_Analysis_Template.md +0 -34
  918. package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +0 -2533
  919. package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-interaction-mapping-reference.md +0 -555
  920. package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-layout-mapping-reference.md +0 -117
  921. package/skills/hmos-incremental-ui-align/scripts/app_feature_verify.ts +0 -937
  922. package/skills/hmos-incremental-ui-align/scripts/extract_checklist.ts +0 -343
  923. package/skills/hmos-incremental-ui-align/scripts/navigation-capure.md +0 -76
  924. package/skills/hmos-incremental-ui-align/scripts/page_capture.ts +0 -977
  925. package/skills/hmos-incremental-ui-align/scripts/page_capture_burst.ts +0 -188
  926. package/skills/hmos-integration-test/README.md +0 -341
  927. package/skills/hmos-integration-test/SKILL.md +0 -464
  928. package/skills/hmos-integration-test/scripts/report-tool.ts +0 -791
  929. package/skills/hmos-integration-test/scripts/resolve-metadata-tool.ts +0 -125
  930. package/skills/hmos-integration-test/scripts/self-test-runner.ts +0 -756
  931. package/skills/hmos-integration-test/scripts/testcases-tool.ts +0 -239
  932. package/skills/hmos-resources-convert/SKILL.md +0 -891
  933. package/skills/hmos-spec-generate/SKILL.md +0 -404
  934. package/skills/hmos-test-case-generation/README.md +0 -241
  935. package/skills/hmos-test-case-generation/SKILL.md +0 -324
  936. package/skills/hmos-test-case-generation/references/contract.md +0 -315
  937. package/skills/hmos-test-case-generation/references/review-notes-template.md +0 -84
  938. package/skills/hmos-test-case-generation/references/ui-elements-schema.md +0 -142
  939. package/skills/hmos-test-case-generation/tools/convert_to_ui_elements.ts +0 -550
  940. package/skills/hmos-test-case-generation/tools/validate.ts +0 -1312
  941. package/tools/bfs-crawl/README.md +0 -73
  942. package/tools/bfs-crawl/android_viewtree_bfs_crawler.ts +0 -1662
  943. /package/skills/{hmos-batch-ui-align/references/mvvm-v2/MVVM/346/250/241/345/274/217/357/274/210V2/357/274/211.md" → a2h-arch-generate/references/arkts-mvvm-v2.md} +0 -0
  944. /package/{README.en.md → skills/a2h-arch-generate/scripts/module_create/har/consumer-rules.txt} +0 -0
  945. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +0 -0
  946. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm/@Link/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/217/214/345/220/221/345/220/214/346/255/245.md" +0 -0
  947. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm/@Observed/350/243/205/351/245/260/345/231/250/345/222/214@ObjectLink/350/243/205/351/245/260/345/231/250/357/274/232/345/265/214/345/245/227/347/261/273/345/257/271/350/261/241/345/261/236/346/200/247/345/217/230/345/214/226.md" +0 -0
  948. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm/@Prop/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/215/225/345/220/221/345/220/214/346/255/245.md" +0 -0
  949. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm/@Provide/350/243/205/351/245/260/345/231/250/345/222/214@Consume/350/243/205/351/245/260/345/231/250/357/274/232/344/270/216/345/220/216/344/273/243/347/273/204/344/273/266/345/217/214/345/220/221/345/220/214/346/255/245.md" +0 -0
  950. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm/@State/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/347/212/266/346/200/201.md" +0 -0
  951. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm/@Track/350/243/205/351/245/260/345/231/250/357/274/232class/345/257/271/350/261/241/345/261/236/346/200/247/347/272/247/346/233/264/346/226/260.md" +0 -0
  952. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm/@Watch/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/346/233/264/346/224/271/351/200/232/347/237/245.md" +0 -0
  953. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm/AppStorage/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200/347/232/204UI/347/212/266/346/200/201/345/255/230/345/202/250.md" +0 -0
  954. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm/Environment/357/274/232/350/256/276/345/244/207/347/216/257/345/242/203/346/237/245/350/257/242.md" +0 -0
  955. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm/LocalStorage/357/274/232/351/241/265/351/235/242/347/272/247UI/347/212/266/346/200/201/345/255/230/345/202/250.md" +0 -0
  956. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm/MVVM/346/250/241/345/274/217/357/274/210V1/357/274/211.md" +0 -0
  957. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm/PersistentStorage/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md" +0 -0
  958. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm//347/256/241/347/220/206/345/272/224/347/224/250/346/213/245/346/234/211/347/232/204/347/212/266/346/200/201/346/246/202/350/277/260.md" +0 -0
  959. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/!!/350/257/255/346/263/225/357/274/232/345/217/214/345/220/221/347/273/221/345/256/232.md" +0 -0
  960. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/@Computed/350/243/205/351/245/260/345/231/250/357/274/232/350/256/241/347/256/227/345/261/236/346/200/247.md" +0 -0
  961. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/@Event/350/243/205/351/245/260/345/231/250/357/274/232/350/247/204/350/214/203/347/273/204/344/273/266/350/276/223/345/207/272.md" +0 -0
  962. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/@Local/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/351/203/250/347/212/266/346/200/201.md" +0 -0
  963. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/@Monitor/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/344/277/256/346/224/271/345/274/202/346/255/245/347/233/221/345/220/254.md" +0 -0
  964. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/@ObservedV2/350/243/205/351/245/260/345/231/250/345/222/214@Trace/350/243/205/351/245/260/345/231/250/357/274/232/347/261/273/345/261/236/346/200/247/345/217/230/345/214/226/350/247/202/346/265/213.md" +0 -0
  965. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/@Once/350/243/205/351/245/260/345/231/250/357/274/232/345/210/235/345/247/213/345/214/226/345/220/214/346/255/245/344/270/200/346/254/241.md" +0 -0
  966. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/@Param/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/244/226/351/203/250/350/276/223/345/205/245.md" +0 -0
  967. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/@Provider/350/243/205/351/245/260/345/231/250/345/222/214@Consumer/350/243/205/351/245/260/345/231/250/357/274/232/350/267/250/347/273/204/344/273/266/345/261/202/347/272/247/345/217/214/345/220/221/345/220/214/346/255/245.md" +0 -0
  968. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/@Type/350/243/205/351/245/260/345/231/250/357/274/232/346/240/207/350/256/260/347/261/273/345/261/236/346/200/247/347/232/204/347/261/273/345/236/213.md" +0 -0
  969. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/AppStorageV2/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200UI/347/212/266/346/200/201/345/255/230/345/202/250.md" +0 -0
  970. /package/skills/{hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2 → a2h-batch-ui-align/references/mvvm-v2}/MVVM/346/250/241/345/274/217/357/274/210V2/357/274/211.md" +0 -0
  971. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/PersistenceV2/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md" +0 -0
  972. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/_/350/214/203/345/274/217/351/200/211/346/213/251/350/257/264/346/230/216.md" +0 -0
  973. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/_/350/243/205/351/245/260/345/231/250/351/200/237/346/237/245.md" +0 -0
  974. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2//347/212/266/346/200/201/347/256/241/347/220/206V1/345/220/221V2/350/277/201/347/247/273/344/270/216/346/267/267/347/224/250/346/214/207/345/257/274.md" +0 -0
  975. /package/skills/{hmos-fix-build-errors → a2h-fix-build-errors}/references/arkts-strict-patterns.md +0 -0
  976. /package/skills/{hmos-fix-build-errors → a2h-fix-build-errors}/references/known-patterns.md +0 -0
  977. /package/skills/{hmos-fix-build-errors → a2h-fix-build-errors}/references/rdb-entity-pattern.md +0 -0
  978. /package/skills/{hmos-resources-convert → a2h-resource-convert}/references/dependency-analysis-rules.md +0 -0
  979. /package/skills/{hmos-resources-convert → a2h-resource-convert}/scripts/svg_fidelity_check.ts +0 -0
  980. /package/skills/{hmos-spec-generate → a2h-spec-generate}/template/REQ.txt +0 -0
  981. /package/skills/{hmos-spec-generate → a2h-spec-generate}/template/REQ.xlsx +0 -0
@@ -0,0 +1,1513 @@
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,
39
+ } from './adapters.mjs';
40
+ import { applyStateAnchors, observationMatchesStatic, resolvePage, occludedIndices, resolveTwinByOpener, backCanReach, uiStatesOf } 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
+ export const TRANSIENT_DEVICE_RE = new RegExp(
183
+ "Can't find service|Cannot identify foreground window|device '[^']+' not found|"
184
+ + 'device offline|error: closed|device-timeout|ui-dump-(?:failed|remote-missing)|Foreground changed during capture');
185
+
186
+ const isVisible = (n) => truthy(get(n, 'visible', true));
187
+ /**
188
+ * Selector for scroll container `n` that resolves to it alone in `nodes`: its id, else its class,
189
+ * else its class plus reading-order `index` (a Compose page's one scrollable is an
190
+ * `android.view.View` among dozens of plain ones, so class alone never resolves).
191
+ */
192
+ const scrollSel = (n, nodes = null) => {
193
+ if (truthy(get(n, 'resource_id'))) { return { resource_id: n.resource_id }; }
194
+ const sel = { class: get(n, 'class') };
195
+ if (!nodes || matching(nodes, sel).length <= 1) { return sel; }
196
+ return classIndexSel(n, nodes) ?? sel;
197
+ };
198
+
199
+ /** `{class, index}` naming `n` by its class and reading-order position (adapters.matching's order), or null. */
200
+ function classIndexSel(n, nodes) {
201
+ if (!truthy(get(n, 'class'))) { return null; }
202
+ const same = matching(nodes, { class: n.class });
203
+ const idx = sortedBy(same, (m) => { const b = or(get(m, 'bounds'), [0, 0]); return b.slice(0, 2).reverse(); }).indexOf(n);
204
+ return idx >= 0 ? { class: n.class, index: idx } : null;
205
+ }
206
+ const s200 = (e) => cpSlice(errStr(e), 0, 200);
207
+ const CANDIDATE_KINDS = { click_candidates: 'click', long_click_candidates: 'long_click', double_tap_candidates: 'double_tap' };
208
+
209
+ /**
210
+ * The runtime-permission dialog words its allow button per permission and Android version
211
+ * (「允许」, 「仅在使用该应用时允许」, "While using the app", "Allow all"), so a recipe's label
212
+ * misses on another device. Measured (Salt Player 10-18): three recD scan chains asked for
213
+ * 「仅在使用该应用时允许」 on a media prompt showing 「允许 / 不允许」 and died there. When the
214
+ * screen is that dialog and the step means "allow", press its allow button by the stable
215
+ * permissioncontroller id. Deny is never inferred.
216
+ */
217
+ export const PERMISSION_ALLOW_IDS = ['permission_allow_foreground_only_button', 'permission_allow_button',
218
+ 'permission_allow_all_button', 'permission_allow_one_time_button'];
219
+ const ALLOW_WORDS = /允许|allow|while using/i;
220
+ const DENY_WORDS = /不允许|拒绝|deny|don.t allow/i;
221
+
222
+ /**
223
+ * Runtime permissions the package holds, from `dumpsys package <pkg>`: the entries of its
224
+ * `runtime permissions:` sections. Install-time permissions are not listed there. With
225
+ * `{ ungrantedOnly: true }`, only those still `granted=false` (nothing to do for the rest).
226
+ */
227
+ export function runtimePermissions(dump, { ungrantedOnly = false } = {}) {
228
+ const all = new Set(); const granted = new Set();
229
+ let inSection = false; let indent = -1;
230
+ for (const line of pyStr(dump).split(/\r?\n/)) {
231
+ const lead = line.length - line.trimStart().length;
232
+ if (/^\s*runtime permissions:\s*$/.test(line)) { inSection = true; indent = lead; continue; }
233
+ if (!inSection) { continue; }
234
+ const m = /^\s*([\w.]+): granted=(true|false)/.exec(line);
235
+ if (m && lead > indent) { all.add(m[1]); if (m[2] === 'true') { granted.add(m[1]); } continue; }
236
+ inSection = false;
237
+ }
238
+ // A permission listed for several users counts as granted only when every listing grants it.
239
+ for (const line of pyStr(dump).split(/\r?\n/)) {
240
+ const m = /^\s*([\w.]+): granted=false/.exec(line);
241
+ if (m) { granted.delete(m[1]); }
242
+ }
243
+ return [...all].filter((p) => !ungrantedOnly || !granted.has(p)).sort();
244
+ }
245
+
246
+ export function permissionGrant(nodes, selectors, kind = 'click') {
247
+ const isPrompt = nodes.some((n) => pyStr(get(n, 'resource_id', '')).endsWith('permissioncontroller:id/grant_dialog'));
248
+ if (!isPrompt) { return null; }
249
+ const labels = selectors.map((s) => pyStr(or(get(s, 'text'), get(s, 'content_desc'))));
250
+ if (!labels.some((t) => ALLOW_WORDS.test(t) && !DENY_WORDS.test(t))) { return null; }
251
+ for (const id of PERMISSION_ALLOW_IDS) {
252
+ const hit = nodes.filter((n) => isVisible(n) && pyStr(get(n, 'resource_id', '')).endsWith(':id/' + id));
253
+ if (hit.length === 1) { return { type: kind, selector: { resource_id: hit[0].resource_id } }; }
254
+ }
255
+ return null;
256
+ }
257
+
258
+ const uniqueHit = (nodes, selector) => {
259
+ try { return matching(nodes, selector).length === 1; } catch (e) { if (e instanceof AdapterError) { return false; } throw e; }
260
+ };
261
+
262
+ /**
263
+ * Container openers the campaign's own routes already use: the selector groups of `intermediate`
264
+ * replay steps (a hop that opens a popup, overflow or "more" list without changing page), most
265
+ * frequent first, at most `limit`. App-agnostic: nothing is named, only reused.
266
+ */
267
+ export function derivedOverflowOpeners(tasks, limit = 4, depth = 1) {
268
+ const count = new Map(); const groups = new Map();
269
+ for (const t of tasks) {
270
+ const replay = or(get(t, 'replay'), []);
271
+ // Only hops within `depth` of launch (top-level containers: bottom bar, toolbar, drawer); deeper
272
+ // intermediate hops are mostly in-page actions or sub-page navigation. The last replay hop
273
+ // prepares the task's own action and reveals no later step.
274
+ for (const s of replay.slice(0, Math.min(Math.max(0, depth), replay.length - 1))) {
275
+ if (!truthy(get(s, 'intermediate')) || !Object.hasOwn(CANDIDATE_KINDS, get(s, 'type'))) { continue; }
276
+ const sels = or(get(s, 'selectors'), []);
277
+ if (!sels.length) { continue; }
278
+ const k = jsonDumps(sels, { sort_keys: true });
279
+ if (!groups.has(k)) { groups.set(k, sels); }
280
+ count.set(k, (count.get(k) ?? 0) + 1);
281
+ }
282
+ }
283
+ return sortedBy([...groups.keys()], (k) => [-count.get(k), k]).slice(0, Math.max(0, limit)).map((k) => groups.get(k));
284
+ }
285
+
286
+ /** Static kinds that open over their page (what a container opener is expected to show). */
287
+ export const OVERLAY_KINDS = new Set(['menu', 'dialog', 'panel', 'overlay', 'ui-state', 'mode']);
288
+
289
+ /**
290
+ * The click left its page: another activity, or another verified static page that is not an
291
+ * overlay kind (a popup/menu/dialog resolving to its own node still counts as opened in place).
292
+ */
293
+ export function navigatedAway(before, after, catalog = {}) {
294
+ if (get(before, 'activity') !== get(after, 'activity')) { return true; }
295
+ const id = (o) => { const r = or(get(o, 'static_resolution'), {}); return get(r, 'status') === 'verified' ? get(r, 'static_id') : null; };
296
+ const a = id(after);
297
+ if (a === null || a === id(before)) { return false; }
298
+ const kind = get(get(catalog, a, {}), 'kind') ?? pyStr(a).split(':')[0];
299
+ return !OVERLAY_KINDS.has(kind);
300
+ }
301
+
302
+ /** Failure reasons that repeat for every task replaying the same prefix in the same environment. */
303
+ export const PREFIX_FAILURES = ['selector-not-found-after-bounded-scroll', 'replay-target-unverified:',
304
+ 'ambiguous selector', 'list-item:', 'Scroll requires one visible scrollable container'];
305
+
306
+ /** Key of a task's launch plus its first `n` replay steps. */
307
+ export function prefixKey(task, n) {
308
+ return sha256Hex(Buffer.from(jsonDumps([or(get(task, 'source_launch'), {}), or(get(task, 'replay'), []).slice(0, n)],
309
+ { sort_keys: true }), 'utf8')).slice(0, 16);
310
+ }
311
+
312
+ /** Raised instead of replaying a prefix that already failed this run. */
313
+ export class PrefixFailed extends AdapterError {
314
+ constructor(memo, key) {
315
+ super(memo.reason);
316
+ this.name = 'PrefixFailed';
317
+ Object.assign(this, { key, from: memo.task_id, observationId: memo.observation_id, replayIndex: memo.replay_index,
318
+ beforeId: memo.before_id });
319
+ }
320
+ }
321
+
322
+ export class Runner {
323
+ constructor(args) {
324
+ this.args = args;
325
+ this.root = pResolve(args.campaign);
326
+ this.config = readJson(args.config);
327
+ this.doc = readJson(pJoin(this.root, 'campaign.json'));
328
+ this.phase = this.doc.phases.find((p) => p.id === args.phase);
329
+ if (this.phase === undefined) { throw new Error('StopIteration'); }
330
+ this.env = this.phase.environment;
331
+ this.catalog = get(this.doc, 'page_catalog', {});
332
+ // config `state_anchors` (in-page state rules) persist in the campaign, so a later compile,
333
+ // rejudge or report applies the same ones
334
+ if (truthy(get(this.config, 'state_anchors'))) {
335
+ this.doc.state_anchors = { ...(or(get(this.doc, 'state_anchors'), {})), ...this.config.state_anchors };
336
+ applyStateAnchors(this.catalog, this.doc.state_anchors);
337
+ }
338
+ this.device = new DeviceAdapter(this.config, pJoin(this.root, 'artifacts'));
339
+ this.current = null;
340
+ this.used = 0;
341
+ this.stage = 'initial';
342
+ this.mapped = new Set(this.doc.events.filter((e) => e.kind === 'mapping')
343
+ .map((e) => tupleKey(e.environment_id, get(e.payload, 'observation_id'), get(e.payload, 'static_id'))));
344
+ this.coverage = coverageMode(this.config, get(args, 'coverage', null));
345
+ this.covered = coveredStaticIds(this.doc);
346
+ this.swept = new Set();
347
+ for (const e of this.doc.events) {
348
+ if (e.kind !== 'scroll_sweep') { continue; }
349
+ for (const x of [get(e.payload, 'static_id'), ...get(e.payload, 'also_covers', [])]) { if (truthy(x)) { this.swept.add(x); } }
350
+ }
351
+ this.deadline = monotonic() + toFloat(get(this.config, 'max_seconds', 2400));
352
+ this.backExits = backExitPages(this.doc.events);
353
+ }
354
+
355
+ /** A scoped (incremental) campaign settles every node outside its scope (coverage.mjs scopeOf). */
356
+ scopeExcludes(staticId) {
357
+ // membership, not a complement of doc.nodes: `plan --extend` does not refresh doc.nodes
358
+ if (this._scope === undefined) { this._scope = scopeOf(this.doc); }
359
+ return this._scope !== null && !this._scope.has(staticId);
360
+ }
361
+
362
+ save() {
363
+ atomicWriteJson(pJoin(this.root, 'campaign.json'), this.doc);
364
+ this._saved_at = monotonic();
365
+ }
366
+
367
+ /** wait_device(timeout=None): block until input/window services answer; true on a fresh capture. */
368
+ /**
369
+ * Wait until the device answers and a capture succeeds. A device that answers while
370
+ * capture keeps failing has a hung app (a stuck `am start -W` leaves an ANR or a blank
371
+ * window): force-stop it and go home, so one hung launch does not block the phase.
372
+ */
373
+ waitDevice(timeout = null) {
374
+ const deadline = monotonic() + toFloat(or(timeout, () => get(this.config, 'device_recovery_seconds', 120)));
375
+ const unstickAfter = toInt(get(this.config, 'device_unstick_after', 2));
376
+ let answered = 0;
377
+ let unstuck = false;
378
+ while (monotonic() < deadline) {
379
+ try {
380
+ const out = this.device._shell('service', 'check', 'input');
381
+ if (out.includes('found') && !out.includes('not found')) {
382
+ answered += 1;
383
+ if (!unstuck && answered > unstickAfter) {
384
+ unstuck = true;
385
+ const pkg = get(this.config, 'package');
386
+ try {
387
+ if (truthy(pkg)) { this.device._shell('am', 'force-stop', pkg); }
388
+ this.device._shell('input', 'keyevent', 'KEYCODE_HOME');
389
+ } catch { /* the next capture tells */ }
390
+ }
391
+ this.device._foreground();
392
+ this.capture();
393
+ return true;
394
+ }
395
+ } catch { /* retry */ }
396
+ sleep(5);
397
+ }
398
+ return false;
399
+ }
400
+
401
+ emit(kind, payload, evidence = []) {
402
+ const e = event(kind, this.env, payload, evidence);
403
+ this.doc.events.push(e);
404
+ appendText(pJoin(this.root, 'events.jsonl'), jsonDumps(e, { ensure_ascii: false }) + '\n');
405
+ const interval = toFloat(get(this.config, 'save_interval', 15));
406
+ if (['task_result', 'environment_verified', 'discovery_result', 'environment_restored'].includes(kind)
407
+ || monotonic() - (this._saved_at ?? 0) >= interval) { this.save(); }
408
+ return e;
409
+ }
410
+
411
+ capture() {
412
+ const observation = this.device.observe(this.env);
413
+ const resolution = resolveTwinByOpener(
414
+ deps.resolvePage(observation, this.catalog, get(observation, 'identity'), { app_package: get(this.config, 'package') }),
415
+ this.current, this.catalog);
416
+ observation.static_resolution = resolution;
417
+ const states = resolution.status === 'verified' ? uiStatesOf(observation, this.catalog) : [];
418
+ if (states.length) { resolution.ui_states = states; }
419
+ if (resolution.status === 'verified') {
420
+ Object.assign(observation.identity, { family: resolution.static_id, status: 'verified', basis: resolution.anchors, reason: resolution.reason });
421
+ }
422
+ this.current = observation;
423
+ this.emit('observation', observation, Object.values(observation.artifacts));
424
+ if (resolution.status === 'verified') {
425
+ const key = tupleKey(this.env, observation.observation_id, resolution.static_id);
426
+ if (!this.mapped.has(key)) {
427
+ this.emit('mapping', { static_id: resolution.static_id, observation_id: observation.observation_id,
428
+ method: resolution.reason, anchors: resolution.anchors }, Object.values(observation.artifacts));
429
+ this.mapped.add(key);
430
+ if (this._recognized !== undefined) { this._recognized.add(resolution.static_id); }
431
+ }
432
+ if (this.covered !== undefined) { this.covered.add(resolution.static_id); }
433
+ }
434
+ for (const sid of states) {
435
+ const key = tupleKey(this.env, observation.observation_id, sid);
436
+ if (this.mapped.has(key)) { continue; }
437
+ this.emit('mapping', { static_id: sid, observation_id: observation.observation_id, method: 'ui-state-anchor',
438
+ host_static: resolution.static_id }, Object.values(observation.artifacts));
439
+ this.mapped.add(key);
440
+ if (this._recognized !== undefined) { this._recognized.add(sid); }
441
+ if (this.covered !== undefined) { this.covered.add(sid); }
442
+ }
443
+ return observation;
444
+ }
445
+
446
+ at(ident) { return deps.observationMatchesStatic(or(this.current, {}), ident, this.catalog)[0]; }
447
+
448
+ appUiReady() {
449
+ const pkg = mget(this.config, 'package');
450
+ return get(this.current, 'package') === pkg && get(this.current, 'nodes', []).some((n) =>
451
+ get(n, 'package') === pkg && isVisible(n) && truthy(get(n, 'clickable')));
452
+ }
453
+
454
+ atom(action, taskId, purpose) {
455
+ const lifetime = this.doc.events.filter((e) => e.kind === 'attempt_started' && truthy(get(e.payload, 'atomic'))).length;
456
+ // A phase's cleanup runs after its budget is spent by design: restoring the
457
+ // environment never counts against it (measured: a recD phase that used its whole
458
+ // budget then threw from its cleanup, which run_cycle took as a fatal stage error).
459
+ const restoring = purpose === 'restore' && lifetime < toInt(get(this.config, 'max_campaign_actions', 1800));
460
+ if (!restoring && (this.used >= this.args.budget || lifetime >= toInt(get(this.config, 'max_campaign_actions', 1800)) || monotonic() >= this.deadline)) {
461
+ throw new BudgetExhausted('atomic-action/time budget exhausted');
462
+ }
463
+ const before = this.current;
464
+ this.used += 1;
465
+ const started = this.emit('attempt_started', { task_id: taskId, atomic: true, purpose, action, before: before.observation_id });
466
+ this.device.act(action, before);
467
+ this.device.settle();
468
+ let after = this.capture();
469
+ if (get(action, 'type') === 'launch') {
470
+ this.dirty = false;
471
+ const waitS = Math.max(0.0, toFloat(get(this.config, 'launch_ready_seconds', 8)));
472
+ let deadline = monotonic() + waitS;
473
+ while (!this.appUiReady() && monotonic() < deadline) { sleep(0.5); after = this.capture(); }
474
+ for (let k = 0; k < toInt(get(this.config, 'launch_retries', 1)); k++) {
475
+ if (this.appUiReady()) { break; }
476
+ this.device.act(action, after);
477
+ this.device.settle();
478
+ deadline = monotonic() + waitS;
479
+ after = this.capture();
480
+ while (!this.appUiReady() && monotonic() < deadline) { sleep(0.5); after = this.capture(); }
481
+ }
482
+ if (!this.appUiReady()) { throw new AdapterError('launch-ui-not-ready'); }
483
+ }
484
+ const outcome = observationKey(before) === observationKey(after) ? 'no_effect' : 'succeeded';
485
+ return this.emit('action_result', { task_id: taskId, attempt_id: started.id, purpose, outcome,
486
+ before: before.observation_id, after: after.observation_id, action });
487
+ }
488
+
489
+ choose(action) {
490
+ const isCand = Object.hasOwn(CANDIDATE_KINDS, get(action, 'type'));
491
+ const candidates = isCand ? get(action, 'selectors', []) : [get(action, 'selector', {})];
492
+ let ambiguous = false;
493
+ const hidden = occludedIndices(this.current.nodes);
494
+ const live = this.current.nodes.map((n, i) => (!hidden.has(i) ? n : { visible: false }));
495
+ const kindOf = () => get(CANDIDATE_KINDS, get(action, 'type'), get(action, 'type', 'click'));
496
+ for (const selector of candidates) {
497
+ let hits = matching(live, selector);
498
+ hits = hits.filter((n) => get(n, 'bounds', []).length === 4 && n.bounds[2] > n.bounds[0] && n.bounds[3] > n.bounds[1]);
499
+ if (hits.length === 1) {
500
+ const node = hits[0]; const parent = get(node, 'parent_index');
501
+ if (get(node, 'resource_id') === 'android:id/title' && parent !== null
502
+ && get(this.current.nodes[parent], 'class') === 'android.widget.ListView' && !truthy(get(node, 'clickable'))) { continue; }
503
+ return { type: kindOf(), selector };
504
+ }
505
+ if (hits.length > 1) {
506
+ const scoped = { ...selector, actionable: true };
507
+ if (matching(live, scoped).length === 1) { return { type: kindOf(), selector: scoped }; }
508
+ }
509
+ ambiguous = ambiguous || hits.length > 1;
510
+ }
511
+ if (ambiguous) { throw new AdapterError('ambiguous selector; no coordinate guessing'); }
512
+ return permissionGrant(live, candidates, kindOf());
513
+ }
514
+
515
+ listItem() {
516
+ const nodes = this.current.nodes;
517
+ const adapterCls = ['RecyclerView', 'ListView', 'GridView'];
518
+ const hasKids = new Set(nodes.map((c) => get(c, 'parent_index')));
519
+ let lists = [];
520
+ nodes.forEach((n, i) => { if (isVisible(n) && adapterCls.some((c) => pyStr(get(n, 'class', '')).endsWith(c)) && hasKids.has(i)) { lists.push(i); } });
521
+ if (lists.length !== 1) {
522
+ lists = [];
523
+ nodes.forEach((n, i) => { if (truthy(get(n, 'scrollable')) && isVisible(n)) { lists.push(i); } });
524
+ }
525
+ const idxOf = (n) => nodes.findIndex((m) => pyEq(m, n)); // list.index uses ==
526
+ const actionableRow = (child) => {
527
+ const cands = [child, ...nodes.filter((n) => get(n, 'parent_index') === idxOf(child))];
528
+ const lvl1 = cands.slice(1);
529
+ for (const c of lvl1) { const ci = idxOf(c); cands.push(...nodes.filter((n) => get(n, 'parent_index') === ci)); }
530
+ for (const n of cands) {
531
+ if ((truthy(get(n, 'clickable')) || truthy(get(n, 'long-clickable'))) && isVisible(n)
532
+ && !['ImageButton', 'FloatingActionButton'].some((c) => pyStr(get(n, 'class', '')).endsWith(c))
533
+ && get(n, 'bounds', []).length === 4 && n.bounds[3] > n.bounds[1]) { return n; }
534
+ }
535
+ return null;
536
+ };
537
+ const rowsOf = (li) => nodes.filter((n) => get(n, 'parent_index') === li).map(actionableRow).filter((r) => truthy(r));
538
+ // Several scrollables (a Compose page with a header strip and a list): only a container
539
+ // that holds actionable rows is a list; one such container is no ambiguity.
540
+ if (lists.length > 1) {
541
+ const withRows = lists.filter((li) => rowsOf(li).length > 0);
542
+ if (withRows.length === 1) { lists = withRows; }
543
+ }
544
+ if (lists.length !== 1) { throw new AdapterError(`list-item: expected one list, found ${lists.length}`); }
545
+ const rows = rowsOf(lists[0]);
546
+ if (!rows.length) { throw new AdapterError('list-item: list has no actionable rows'); }
547
+ return sortedBy(rows, (n) => [n.bounds[1], n.bounds[0]])[0];
548
+ }
549
+
550
+ reveal(selector, taskId) {
551
+ if (matching(this.current.nodes, selector).length) { return true; }
552
+ if (this.clearInterruption(taskId) && matching(this.current.nodes, selector).length) { return true; }
553
+ if (!this.appUiReady()) { return false; }
554
+ const origin = observationKey(this.current);
555
+ for (const direction of ['down', 'up']) {
556
+ const seen = new Set([observationKey(this.current)]);
557
+ for (let k = 0; k < toInt(get(this.config, 'max_scrolls_per_task', 6)); k++) {
558
+ const conts = this.current.nodes.filter((n) => truthy(get(n, 'scrollable')) && isVisible(n) && !_isHorizontal(n));
559
+ if (conts.length !== 1) { return false; }
560
+ this.atom({ type: 'scroll', selector: scrollSel(conts[0], this.current.nodes), direction }, taskId, 'search');
561
+ if (matching(this.current.nodes, selector).length) { return true; }
562
+ const key = observationKey(this.current);
563
+ if (seen.has(key) || this._backAtOrigin(direction, key, origin)) { break; }
564
+ seen.add(key);
565
+ }
566
+ }
567
+ return false;
568
+ }
569
+
570
+ /**
571
+ * The upward search pass is back where the downward pass started: everything below was
572
+ * already searched, and one more upward swipe at the top of a list is a pull-to-refresh
573
+ * (SwipeRefreshLayout and friends), which starts network work and may open a dialog
574
+ * (measured, AntennaPod: 36 of 65 failed round-1 tasks met a refresh dialog opened this
575
+ * way). `search_above_origin: true` keeps searching above a mid-list origin.
576
+ */
577
+ _backAtOrigin(direction, key, origin) {
578
+ return direction === 'up' && key === origin && !truthy(get(this.config, 'search_above_origin', false));
579
+ }
580
+
581
+ // -- unexpected dialogs -----------------------------------------------------
582
+
583
+ /**
584
+ * A floating window on top of the page: its root does not cover the screen (a uiautomator
585
+ * dump holds the focused window only, so an AlertDialog, a permission prompt or a rating
586
+ * prompt shows as one small root) and it offers something to press. Returns its root
587
+ * bounds, or null.
588
+ */
589
+ modalOverlay() {
590
+ const nodes = get(this.current, 'nodes', []);
591
+ const roots = nodes.filter((n) => get(n, 'parent_index') === null || get(n, 'parent_index') === undefined);
592
+ const info = or(get(this.current, 'device_info'), {});
593
+ const w = toInt(or(get(info, 'width_px'), 0)); const h = toInt(or(get(info, 'height_px'), 0));
594
+ if (roots.length !== 1 || !(w > 0 && h > 0)) { return null; }
595
+ const b = or(get(roots[0], 'bounds'), []);
596
+ if (b.length !== 4) { return null; }
597
+ const share = ((b[2] - b[0]) * (b[3] - b[1])) / (w * h);
598
+ if (share >= toFloat(get(this.config, 'modal_max_screen_share', 0.85))) { return null; }
599
+ return nodes.some((n) => isVisible(n) && truthy(get(n, 'clickable'))) ? b : null;
600
+ }
601
+
602
+ /**
603
+ * Dismiss a dialog nobody asked for -- one that is neither the page the running task starts
604
+ * from nor the page it looks for (`this.keep`) -- so it does not eat the search budget.
605
+ * Action: the first matching `interruption_rules` entry ({id?, when: <rule>, action}), else
606
+ * Back, then the negative button (android:id/button2) for a dialog Back does not close.
607
+ * Each dismissal is an `interruption` event. Returns true when something was dismissed.
608
+ */
609
+ clearInterruption(taskId) {
610
+ const limit = toInt(get(this.config, 'max_interruption_dismissals', 2));
611
+ let dismissed = false;
612
+ for (let k = 0; k < limit; k++) {
613
+ const bounds = this.modalOverlay();
614
+ if (!bounds) { break; }
615
+ const res = or(get(this.current, 'static_resolution'), {});
616
+ if (get(res, 'status') === 'verified' && (this.keep ?? []).includes(get(res, 'static_id'))) { break; }
617
+ const rule = get(this.config, 'interruption_rules', []).find((r) => ruleMatches(this.current, get(r, 'when', {})));
618
+ let action = rule ? rule.action : { type: 'back' };
619
+ if (!rule && k > 0 && matching(this.current.nodes, { resource_name: 'button2' }).length === 1) {
620
+ action = { type: 'click', selector: { resource_name: 'button2' } };
621
+ }
622
+ const texts = this.current.nodes.map((n) => or(get(n, 'text'), get(n, 'content_desc'))).filter((t) => truthy(t));
623
+ const before = this.current.observation_id;
624
+ const result = this.atom(action, taskId, 'dismiss-interruption');
625
+ this.emit('interruption', { task_id: taskId, observation_id: before, bounds, action,
626
+ rule: rule ? get(rule, 'id', null) : null, texts: texts.slice(0, 6).map((t) => cpSlice(pyStr(t), 0, 80)),
627
+ outcome: result.payload.outcome });
628
+ if (result.payload.outcome === 'no_effect' && rule) { break; }
629
+ dismissed = dismissed || result.payload.outcome === 'succeeded';
630
+ }
631
+ return dismissed;
632
+ }
633
+
634
+ // -- top-to-bottom scroll sweep ---------------------------------------------
635
+
636
+ sweepEnabled() { return truthy(get(this.config, 'scroll_sweep', true)); }
637
+
638
+ sweepContainer() {
639
+ const nodes = get(this.current, 'nodes', []);
640
+ const hidden = occludedIndices(nodes);
641
+ const pkg = get(this.config, 'package');
642
+ const minH = toInt(get(this.config, 'sweep_min_height_px', 200));
643
+ let cands = [];
644
+ nodes.forEach((n, i) => {
645
+ const b = or(get(n, 'bounds'), []);
646
+ if (!(truthy(get(n, 'scrollable')) && isVisible(n)) || hidden.has(i) || b.length !== 4) { return; }
647
+ if (_isHorizontal(n) || (b[3] - b[1]) < minH) { return; }
648
+ if (truthy(pkg) && ![null, pkg].includes(get(n, 'package'))) { return; }
649
+ cands.push(n);
650
+ });
651
+ cands = sortedBy(cands, (n) => (n.bounds[2] - n.bounds[0]) * (n.bounds[3] - n.bounds[1]), true);
652
+ for (const n of cands) {
653
+ const sels = [...(truthy(get(n, 'resource_id')) ? [{ resource_id: n.resource_id }] : []), { class: get(n, 'class') }];
654
+ for (const sel of sels) {
655
+ if (!truthy(get(sel, 'class', true))) { continue; }
656
+ const hits = matching(nodes, sel);
657
+ if (hits.length === 1 && hits[0] === n) { return [sel, n]; }
658
+ }
659
+ const sel = classIndexSel(n, nodes);
660
+ if (sel !== null) {
661
+ const hits = matching(nodes, sel);
662
+ if (hits.length === 1 && hits[0] === n) { return [sel, n]; }
663
+ }
664
+ }
665
+ return null;
666
+ }
667
+
668
+ _sameSurface(origin, selector) {
669
+ const cur = this.current;
670
+ if (get(cur, 'package') !== get(origin, 'package') || get(cur, 'activity') !== get(origin, 'activity')
671
+ || get(cur, 'window') !== get(origin, 'window')) { return false; }
672
+ let hits;
673
+ try { hits = matching(get(cur, 'nodes', []), selector); } catch (e) { if (e instanceof AdapterError) { return false; } throw e; }
674
+ return hits.length === 1 && truthy(get(hits[0], 'scrollable'));
675
+ }
676
+
677
+ sweep(staticId, purpose = 'sweep') {
678
+ if (this.swept === undefined) { this.swept = new Set(); }
679
+ if (!(this.sweepEnabled() && truthy(staticId)) || this.swept.has(staticId)) { return false; }
680
+ if (!this.at(staticId)) { return false; }
681
+ const requested = staticId;
682
+ const res = or(get(or(this.current, {}), 'static_resolution'), {});
683
+ if (get(res, 'status') === 'verified' && truthy(get(res, 'static_id')) && res.static_id !== staticId) {
684
+ staticId = res.static_id;
685
+ this.swept.add(requested);
686
+ if (this.swept.has(staticId)) { return false; }
687
+ }
688
+ this.swept.add(staticId);
689
+ const taskId = 'sweep:' + staticId;
690
+ const origin = this.current;
691
+ const found = this.sweepContainer();
692
+ const payload = { static_id: staticId, origin_observation: origin.observation_id, frames: [],
693
+ also_covers: requested === staticId ? [] : [requested], purpose };
694
+ if (!found) {
695
+ payload.outcome = 'no-container';
696
+ this.emit('scroll_sweep', payload);
697
+ return true;
698
+ }
699
+ const [selector, node] = found;
700
+ payload.container = { selector, class: get(node, 'class'), resource_id: get(node, 'resource_id'), bounds: get(node, 'bounds') };
701
+ const others = get(origin, 'nodes', []).filter((n) => truthy(get(n, 'scrollable')) && isVisible(n) && n !== node && !_isHorizontal(n))
702
+ .map((n) => or(get(n, 'resource_id'), get(n, 'class')));
703
+ if (others.length) { payload.unswept_containers = others; }
704
+ const maxScrolls = toInt(get(this.config, 'max_sweep_scrolls', 20));
705
+ let lastSig = _viewSig(origin);
706
+ let outcome = 'truncated'; let swipes = 0;
707
+ try {
708
+ while (swipes <= maxScrolls) {
709
+ this.atom({ type: 'scroll', selector, direction: 'down' }, taskId, purpose);
710
+ swipes += 1;
711
+ if (!this._sameSurface(origin, selector)) { outcome = 'aborted'; payload.abort_reason = 'left-page'; break; }
712
+ const sig = _viewSig(this.current);
713
+ if (sig === lastSig) { outcome = 'complete'; break; }
714
+ if (payload.frames.length >= maxScrolls) { break; }
715
+ lastSig = sig;
716
+ payload.frames.push(this.current.observation_id);
717
+ const r = get(this.current, 'static_resolution', {});
718
+ if (get(r, 'status') === 'verified' && ![null, staticId].includes(get(r, 'static_id')) && !payload.also_covers.includes(r.static_id)) {
719
+ payload.also_covers.push(r.static_id);
720
+ }
721
+ }
722
+ } catch (e) {
723
+ if (e instanceof BudgetExhausted) { outcome = 'budget-exhausted'; }
724
+ else if (e instanceof AdapterError) { outcome = 'aborted'; payload.abort_reason = s200(e); }
725
+ else { throw e; }
726
+ }
727
+ payload.outcome = outcome;
728
+ payload.swipes = swipes;
729
+ if (outcome !== 'aborted' || get(payload, 'abort_reason') !== 'left-page') {
730
+ payload.restored = this._sweepRestore(origin, selector, node, taskId);
731
+ } else { payload.restored = false; }
732
+ if (!payload.restored) { this.dirty = true; }
733
+ for (const x of payload.also_covers) { this.swept.add(x); }
734
+ this.emit('scroll_sweep', payload);
735
+ return true;
736
+ }
737
+
738
+ _atTop(origin, container) {
739
+ const keyed = (obs) => {
740
+ const seen = new Map(); const out = new Map();
741
+ for (const n of get(obs, 'nodes', [])) {
742
+ if (!(isVisible(n) && truthy(get(n, 'resource_id'))) || or(get(n, 'bounds'), []).length !== 4) { continue; }
743
+ const k = tupleKey(n.resource_id, get(n, 'text'));
744
+ seen.set(k, (seen.get(k) ?? 0) + 1);
745
+ out.set(tupleKey(n.resource_id, get(n, 'text'), seen.get(k)), n.bounds);
746
+ }
747
+ return out;
748
+ };
749
+ const a = keyed(origin); const b = keyed(this.current);
750
+ if (a.size !== b.size || [...a.keys()].some((k) => !b.has(k))) { return false; }
751
+ const cb = or(get(container, 'bounds'), [0, 0, 0, 800]);
752
+ const tol = Math.max(24, Math.trunc(0.03 * (cb[3] - cb[1])));
753
+ return [...a.keys()].every((k) => {
754
+ const x = a.get(k); const y = b.get(k);
755
+ return x.slice(0, Math.min(x.length, y.length)).every((v, i) => Math.abs(v - y[i]) <= tol);
756
+ });
757
+ }
758
+
759
+ _sweepRestore(origin, selector, container, taskId) {
760
+ if (this._atTop(origin, container)) { return true; }
761
+ const limit = toInt(get(this.config, 'max_sweep_scrolls', 20)) * 3 + 2;
762
+ let last = _viewSig(this.current);
763
+ try {
764
+ for (let k = 0; k < limit; k++) {
765
+ if (!this._sameSurface(origin, selector)) { return false; }
766
+ this.atom({ type: 'scroll', selector, direction: 'up' }, taskId, 'sweep-restore');
767
+ if (this._atTop(origin, container)) { return true; }
768
+ const sig = _viewSig(this.current);
769
+ if (sig === last) { break; }
770
+ last = sig;
771
+ }
772
+ } catch (e) {
773
+ if (e instanceof BudgetExhausted || e instanceof AdapterError) { return false; }
774
+ throw e;
775
+ }
776
+ return this._atTop(origin, container);
777
+ }
778
+
779
+ sweepBacklog() {
780
+ if (!this.sweepEnabled()) { return; }
781
+ if (this.swept === undefined) { this.swept = new Set(); }
782
+ const mapped = [];
783
+ for (const e of this.doc.events) {
784
+ const sid = get(e.payload, 'static_id');
785
+ if (e.kind === 'mapping' && e.environment_id === this.env && truthy(sid) && !mapped.includes(sid)) { mapped.push(sid); }
786
+ }
787
+ const tasks = get(this.doc, 'tasks', []).filter((t) => get(t, 'phase') === this.phase.id
788
+ && get(t, 'status') === 'compiled' && get(t, 'purpose') !== 'direct-launch');
789
+ for (const sid of mapped) {
790
+ if (this.swept.has(sid) || this.scopeExcludes(sid)) { continue; }
791
+ if (this.at(sid)) { this.sweep(sid, 'sweep-backlog'); continue; }
792
+ const asSource = tasks.find((t) => get(t, 'source_static') === sid) ?? null;
793
+ const asTarget = tasks.find((t) => get(t, 'target_static') === sid) ?? null;
794
+ if (!(asSource || asTarget)) { continue; }
795
+ const route = { ...(asSource || asTarget), task_id: 'sweep:' + sid };
796
+ try {
797
+ this.source(route);
798
+ if (!asSource) {
799
+ for (const step of or(get(route, 'prelude'), [])) { this.seek(step, route.task_id, 'sweep-route'); }
800
+ if (!(truthy(get(route.action, 'automatic')) && this.at(sid))) { this.seek(route.action, route.task_id, 'sweep-route'); }
801
+ }
802
+ } catch (e) {
803
+ if (e instanceof BudgetExhausted) { throw e; }
804
+ this.swept.add(sid);
805
+ this.emit('scroll_sweep', { static_id: sid, outcome: 'unreached', frames: [], also_covers: [],
806
+ purpose: 'sweep-backlog', abort_reason: s200(e) });
807
+ continue;
808
+ }
809
+ if (!this.sweep(sid, 'sweep-backlog') && !this.swept.has(sid)) {
810
+ this.swept.add(sid);
811
+ this.emit('scroll_sweep', { static_id: sid, outcome: 'unreached', frames: [], also_covers: [],
812
+ purpose: 'sweep-backlog', abort_reason: 'page-not-verified-after-route' });
813
+ }
814
+ }
815
+ }
816
+
817
+ /**
818
+ * Selector groups tried after a bounded search fails: `config.overflow_openers` first, then the
819
+ * containers the campaign's own routes already open (see derivedOverflowOpeners).
820
+ */
821
+ overflowOpeners() {
822
+ if (this._openers === undefined) {
823
+ const groups = [...get(this.config, 'overflow_openers', []).map((s) => [s]),
824
+ ...derivedOverflowOpeners(get(this.doc, 'tasks', []), toInt(get(this.config, 'max_derived_overflow_openers', 4)),
825
+ toInt(get(this.config, 'derived_opener_depth', 1)))];
826
+ const seen = new Set();
827
+ this._openers = groups.filter((g) => {
828
+ const k = jsonDumps(g, { sort_keys: true });
829
+ if (seen.has(k)) { return false; }
830
+ seen.add(k); return true;
831
+ });
832
+ }
833
+ return this._openers;
834
+ }
835
+
836
+ seek(action, taskId, purpose) {
837
+ if (truthy(get(action, 'reveal'))) { this.reveal(action.reveal, taskId); }
838
+ if (truthy(get(action, 'when')) && !ruleMatches(this.current, action.when)) {
839
+ this.emit('action_skipped', { task_id: taskId, purpose, reason: 'condition-not-met', action });
840
+ return null;
841
+ }
842
+ const type = get(action, 'type');
843
+ if (type === 'click_list_item' || type === 'long_click_list_item') {
844
+ const row = this.listItem();
845
+ const b = row.bounds;
846
+ const kind = type.startsWith('long') ? 'long_click_point' : 'click_point';
847
+ const rowInfo = {};
848
+ for (const k of ['class', 'resource_id', 'text', 'content_desc', 'bounds']) { rowInfo[k] = get(row, k); }
849
+ 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);
850
+ }
851
+ if (type === 'scroll_page') {
852
+ const sideways = ['left', 'right'].includes(get(action, 'direction'));
853
+ const conts = this.current.nodes.filter((n) => truthy(get(n, 'scrollable')) && isVisible(n) && _isHorizontal(n) === sideways);
854
+ if (conts.length !== 1) { throw new AdapterError('Scroll requires one visible scrollable container'); }
855
+ return this.atom({ type: 'scroll', selector: scrollSel(conts[0], this.current.nodes), direction: get(action, 'direction', 'down') }, taskId, purpose);
856
+ }
857
+ if (!Object.hasOwn(CANDIDATE_KINDS, type)) { return this.atom(action, taskId, purpose); }
858
+ let selected = this.choose(action);
859
+ if (selected) { return this.atom(selected, taskId, purpose); }
860
+ if (this.clearInterruption(taskId)) {
861
+ selected = this.choose(action);
862
+ if (selected) { return this.atom(selected, taskId, purpose); }
863
+ }
864
+ if (!this.appUiReady()) { throw new AdapterError('selector unavailable on non-app/empty UI'); }
865
+ // Content that loads after the page is ready (a list filled from the network or a database):
866
+ // look again while the screen is still changing, for a bounded time, before scrolling. A
867
+ // screen that has settled ends the wait at once. Captures only, no action is spent.
868
+ const waitUntil = monotonic() + Math.max(0, toFloat(get(this.config, 'selector_wait_seconds', 3)));
869
+ let lastKey = observationKey(this.current);
870
+ while (monotonic() < waitUntil) {
871
+ sleep(0.5);
872
+ this.capture();
873
+ selected = this.choose(action);
874
+ if (selected) { return this.atom(selected, taskId, purpose); }
875
+ const key = observationKey(this.current);
876
+ if (key === lastKey) { break; }
877
+ lastKey = key;
878
+ }
879
+ const origin = observationKey(this.current);
880
+ for (const direction of ['down', 'up']) {
881
+ const seen = new Set([observationKey(this.current)]);
882
+ for (let k = 0; k < toInt(get(this.config, 'max_scrolls_per_task', 6)); k++) {
883
+ const containers = this.current.nodes.filter((n) => truthy(get(n, 'scrollable')) && isVisible(n) && !_isHorizontal(n));
884
+ if (containers.length !== 1) { break; }
885
+ this.atom({ type: 'scroll', selector: scrollSel(containers[0], this.current.nodes), direction }, taskId, 'search');
886
+ selected = this.choose(action);
887
+ if (selected) { return this.atom(selected, taskId, purpose); }
888
+ if (this.clearInterruption(taskId)) {
889
+ selected = this.choose(action);
890
+ if (selected) { return this.atom(selected, taskId, purpose); }
891
+ }
892
+ const key = observationKey(this.current);
893
+ if (seen.has(key) || this._backAtOrigin(direction, key, origin)) { break; }
894
+ seen.add(key);
895
+ }
896
+ }
897
+ for (let round = 0; round < toInt(get(this.config, 'max_horizontal_scrolls', 3)); round++) {
898
+ const horiz = this.current.nodes.filter((n) => truthy(get(n, 'scrollable')) && isVisible(n) && _isHorizontal(n)
899
+ && !['ViewPager', 'ViewPager2'].some((c) => pyStr(get(n, 'class', '')).endsWith(c)));
900
+ if (!horiz.length) { break; }
901
+ let moved = false;
902
+ for (const n of horiz) {
903
+ const sel = truthy(get(n, 'resource_id')) ? { resource_id: n.resource_id } : null;
904
+ if (!sel || matching(this.current.nodes, sel).length !== 1) { continue; }
905
+ const key = observationKey(this.current);
906
+ this.atom({ type: 'scroll', selector: sel, direction: 'right' }, taskId, 'search');
907
+ selected = this.choose(action);
908
+ if (selected) { return this.atom(selected, taskId, purpose); }
909
+ moved = moved || observationKey(this.current) !== key;
910
+ }
911
+ if (!moved) { break; }
912
+ }
913
+ const own = new Set(get(action, 'selectors', []).map((s) => jsonDumps(s, { sort_keys: true })));
914
+ const rejected = (this._openersRejected ??= new Set());
915
+ for (const group of this.overflowOpeners()) {
916
+ const gk = jsonDumps(group, { sort_keys: true });
917
+ if (rejected.has(gk)) { continue; }
918
+ const opener = group.find((s) => !own.has(jsonDumps(s, { sort_keys: true })) && uniqueHit(this.current.nodes, s));
919
+ if (!opener) { continue; }
920
+ const before = this.current; const key = observationKey(before);
921
+ this.atom({ type: 'click', selector: opener }, taskId, 'search-overflow');
922
+ selected = this.choose(action);
923
+ if (selected) { return this.atom(selected, taskId, purpose); }
924
+ // A container opens over its page; an opener that changed page is a navigation, not tried again.
925
+ if (navigatedAway(before, this.current, or(this.catalog, {}))) { rejected.add(gk); }
926
+ // Close only what the opener opened; an opener with no visible effect needs no Back.
927
+ if (observationKey(this.current) !== key) { this.atom({ type: 'back' }, taskId, 'search-overflow-close'); }
928
+ }
929
+ throw new AdapterError('selector-not-found-after-bounded-scroll');
930
+ }
931
+
932
+ source(task) {
933
+ const source = task.source_static;
934
+ const dirty = this.dirty ?? false;
935
+ const [matched, how] = deps.observationMatchesStatic(or(this.current, {}), source, this.catalog);
936
+ if (matched && how === 'exact-page' && !dirty) { return; }
937
+ // Back only when it can land on the source: from a root page (or any page the source never
938
+ // opens) it just leaves the app, costing an action before the relaunch below anyway.
939
+ const here = get(get(this.current, 'static_resolution', {}), 'status') === 'verified'
940
+ ? this.current.static_resolution.static_id : null;
941
+ if (this.current.package === mget(this.config, 'package') && !matched && !dirty
942
+ && !(here !== null && (this.backExits ?? new Set()).has(here))
943
+ && backCanReach(this.current, source, this.catalog)) {
944
+ this.atom({ type: 'back' }, task.task_id, 'recover');
945
+ if (here !== null && this.current.package !== mget(this.config, 'package')) {
946
+ (this.backExits ??= new Set()).add(here);
947
+ }
948
+ if (deps.observationMatchesStatic(this.current, source, this.catalog)[1] === 'exact-page') { return; }
949
+ }
950
+ let launch = { ...(or(get(task, 'source_launch'), {})) };
951
+ if (!truthy(launch)) { launch = { type: 'launch', component: mget(this.config, 'launch_component'), restart: true }; }
952
+ // A prefix that already failed this run fails the same way again: report it without replaying.
953
+ const memo = truthy(get(this.config, 'prefix_memo', true)) ? (this._prefixFailures ??= new Map()) : null;
954
+ const replay = mget(task, 'replay');
955
+ if (memo) {
956
+ for (let n = 1; n <= replay.length; n++) {
957
+ const k = prefixKey(task, n);
958
+ if (memo.has(k)) { throw new PrefixFailed(memo.get(k), k); }
959
+ }
960
+ }
961
+ this.atom(launch, task.task_id, 'recover');
962
+ const attested = new Set();
963
+ for (let i = 0; i < replay.length; i++) {
964
+ const step = replay[i];
965
+ const stepStart = get(or(this.current, {}), 'observation_id');
966
+ try {
967
+ const stepResult = this.seek(step, task.task_id, 'replay');
968
+ if (truthy(get(step, 'intermediate')) || !truthy(get(step, 'target_id'))) { continue; }
969
+ if (!this.at(step.target_id)) {
970
+ if (!this.attestedArrival(step.target_id, stepResult, task.task_id)) {
971
+ throw new AdapterError('replay-target-unverified:' + step.target_id);
972
+ }
973
+ attested.add(step.target_id);
974
+ }
975
+ } catch (e) {
976
+ const msg = errStr(e);
977
+ if (memo && e instanceof AdapterError && PREFIX_FAILURES.some((r) => msg.startsWith(r))) {
978
+ memo.set(prefixKey(task, i + 1), { reason: msg, task_id: task.task_id, replay_index: i,
979
+ observation_id: get(or(this.current, {}), 'observation_id'), before_id: stepStart });
980
+ }
981
+ throw e;
982
+ }
983
+ }
984
+ // A transient source (a splash that leaves by itself) is gone once the app is ready; its
985
+ // automatic edges have already fired, so the target check alone decides the task.
986
+ if (truthy(get(get(this.catalog, source, {}), 'transient')) && truthy(get(task.action, 'automatic'))) { return; }
987
+ if (!this.at(source)) { this.clearInterruption(task.task_id); }
988
+ if (!this.at(source)) {
989
+ const ctx = get(task, 'source_context');
990
+ if (!(this.anchorless(source) && (attested.has(source)
991
+ || (truthy(ctx) && (this.at(ctx) || this.transientSuccessor(ctx, source, task.task_id)))
992
+ || (!replay.length && this.launchedInto(source, task.task_id))))) {
993
+ throw new AdapterError('source-unverified:' + source);
994
+ }
995
+ }
996
+ }
997
+
998
+ /**
999
+ * True when the page has no anchor it always shows (title, rows, layout ids). Body texts do
1000
+ * not count: they are presence-only evidence and may sit in a branch or a dialog the page opens.
1001
+ */
1002
+ anchorless(ident) {
1003
+ const page = get(this.catalog, ident, {});
1004
+ return !(truthy(get(page, 'titles')) || truthy(get(page, 'row_titles')) || truthy(get(page, 'widget_ids')));
1005
+ }
1006
+
1007
+ /**
1008
+ * Identity by elimination on this app's own screen: the current capture is in the app package,
1009
+ * not verified as any page, and not claimed by any of `rivals`. Used only for anchorless pages.
1010
+ */
1011
+ _unclaimedAppScreen(rivals = [], candidate = null) {
1012
+ if (get(this.current, 'package') !== get(this.config, 'package')) { return false; }
1013
+ const res = or(get(this.current, 'static_resolution'), {});
1014
+ if (get(res, 'status') === 'verified') { return false; }
1015
+ // A page the resolver has recognized on this device would be recognized again: an
1016
+ // unverified screen is not it.
1017
+ if (candidate !== null && this.recognized(candidate)) { return false; }
1018
+ return !rivals.some((r) => this.at(r));
1019
+ }
1020
+
1021
+ /** The page was verified by its own anchors at least once in this campaign. */
1022
+ recognized(ident) {
1023
+ if (this._recognized === undefined) {
1024
+ this._recognized = new Set(this.doc.events.filter((e) => e.kind === 'mapping').map((e) => get(e.payload, 'static_id')));
1025
+ }
1026
+ return this._recognized.has(ident);
1027
+ }
1028
+
1029
+ /**
1030
+ * `ctx` is a transient entry whose automatic edges lead to `source`: once launched, the screen
1031
+ * that replaced it is `source` unless it is one of the transient page's other successors.
1032
+ */
1033
+ transientSuccessor(ctx, source, taskId) {
1034
+ const page = get(this.catalog, ctx, {});
1035
+ const targets = or(get(page, 'auto_targets'), []);
1036
+ if (!truthy(get(page, 'transient')) || !targets.includes(source)) { return false; }
1037
+ if (!this._unclaimedAppScreen(targets.filter((t) => t !== source), source)) { return false; }
1038
+ this.emit('source_attested', { task_id: taskId, static_id: source, basis: 'transient-successor', context: ctx,
1039
+ observation_id: this.current.observation_id });
1040
+ return true;
1041
+ }
1042
+
1043
+ /** A launch with no replay landed on an anchorless page the launcher's transient entry opens. */
1044
+ launchedInto(source, taskId) {
1045
+ const entries = Object.keys(or(this.catalog, {})).filter((k) => truthy(get(this.catalog[k], 'transient'))
1046
+ && or(get(this.catalog[k], 'auto_targets'), []).includes(source));
1047
+ return entries.length === 1 && this.transientSuccessor(entries[0], source, taskId);
1048
+ }
1049
+
1050
+ /**
1051
+ * Trigger-chain arrival for an anchorless page: the replay step's own gesture ran on the
1052
+ * device and changed the screen, and the screen it reached is the app's, unverified as any page.
1053
+ */
1054
+ attestedArrival(target, stepResult, taskId) {
1055
+ if (!this.anchorless(target) || !truthy(stepResult) || get(stepResult.payload, 'outcome') !== 'succeeded') { return false; }
1056
+ if (!this._unclaimedAppScreen([], target)) { return false; }
1057
+ this.emit('source_attested', { task_id: taskId, static_id: target, basis: 'trigger-chain-replay',
1058
+ action_event_id: stepResult.id, observation_id: this.current.observation_id });
1059
+ return true;
1060
+ }
1061
+
1062
+ runDirect(task, done) {
1063
+ const ident = task.task_id;
1064
+ try {
1065
+ this.stage = 'direct-launch';
1066
+ this.atom(task.source_launch, ident, 'direct-launch');
1067
+ for (const step of or(get(task, 'prelude'), [])) { this.seek(step, ident, 'direct-launch'); }
1068
+ const confirmed = this.at(task.target_static);
1069
+ if (confirmed) { done.add(ident); }
1070
+ this.emit('task_result', { task_id: ident, outcome: confirmed ? 'confirmed' : 'target-unverified',
1071
+ target_static: task.target_static, purpose: 'direct-launch', observation_id: this.current.observation_id });
1072
+ if (confirmed) { this.sweep(task.target_static); }
1073
+ } catch (e) {
1074
+ if (e instanceof BudgetExhausted) {
1075
+ this.emit('task_result', { task_id: ident, outcome: 'budget-exhausted', stage: this.stage });
1076
+ throw e;
1077
+ }
1078
+ this.emit('task_result', { task_id: ident, outcome: 'failed', stage: this.stage, purpose: 'direct-launch',
1079
+ reason: cpSlice(errStr(e), 0, 300), target_static: task.target_static,
1080
+ observation_id: get(or(this.current, {}), 'observation_id') });
1081
+ }
1082
+ }
1083
+
1084
+ attest(task, result) {
1085
+ const obs = new Map();
1086
+ for (const e of this.doc.events) {
1087
+ if (e.kind === 'observation' && e.environment_id === this.env) { obs.set(e.payload.observation_id, e.payload); }
1088
+ }
1089
+ const before = obs.get(result.payload.before) ?? {};
1090
+ const sourceExact = deps.observationMatchesStatic(before, task.source_static, this.catalog)[1] === 'exact-page';
1091
+ const [ok, basis] = deps.triggerAttests(task, before, this.current, get(result.payload, 'action'),
1092
+ this.catalog, get(this.config, 'package'), sourceExact);
1093
+ if (ok) {
1094
+ this.emit('attestation', { static_id: task.target_static, task_id: task.task_id, observation_id: this.current.observation_id,
1095
+ basis: 'trigger-chain', evidence: basis, action_event_id: result.id });
1096
+ }
1097
+ }
1098
+
1099
+ discoveryConfig() {
1100
+ const raw = get(this.config, 'discovery', {});
1101
+ if (!(raw && typeof raw === 'object' && !Array.isArray(raw))) { return {}; }
1102
+ const scoped = get(raw, this.phase.id, raw);
1103
+ return scoped && typeof scoped === 'object' && !Array.isArray(scoped) && truthy(get(scoped, 'enabled')) ? scoped : {};
1104
+ }
1105
+
1106
+ discoveryActions(config) {
1107
+ const actions = this.device.actions(this.current);
1108
+ const allow = get(config, 'allow_actions', []); const deny = get(config, 'deny_actions', []);
1109
+ const allowUnlisted = truthy(get(config, 'allow_unlisted_actions', false));
1110
+ const selected = [];
1111
+ for (const action of actions) {
1112
+ const hits = matching(this.current.nodes, get(action, 'selector', {}));
1113
+ if (hits.length !== 1) { continue; }
1114
+ const scoped = { ...this.current, nodes: [hits[0]] };
1115
+ if (truthy(deny) && deny.some((rule) => ruleMatches(scoped, rule))) { continue; }
1116
+ if (truthy(allow)) { if (!allow.some((rule) => ruleMatches(scoped, rule))) { continue; } }
1117
+ else if (!allowUnlisted) { continue; }
1118
+ selected.push(action);
1119
+ }
1120
+ return selected.slice(0, Math.max(0, toInt(get(config, 'max_actions_per_state', 8))));
1121
+ }
1122
+
1123
+ runDiscovery() {
1124
+ const config = this.discoveryConfig();
1125
+ if (!truthy(config)) { return { enabled: false }; }
1126
+ // discovery walks the app from launch, not toward a node: a scoped campaign has no use for it
1127
+ if (scopeOf(this.doc) !== null) { return { enabled: false, outcome: 'skipped', reason: 'scoped campaign' }; }
1128
+ const maxDepth = Math.max(0, toInt(get(config, 'max_depth', 3)));
1129
+ const maxStates = Math.max(1, toInt(get(config, 'max_states', 30)));
1130
+ const maxExp = () => toInt(get(config, 'max_expansions', 60));
1131
+ const queue = [[]]; const visited = new Set(); let expanded = 0; let transitions = 0; let failures = 0;
1132
+ const hash = (v, n) => sha256Hex(jsonDumps(v, { sort_keys: true })).slice(0, n);
1133
+ const restore = (p) => {
1134
+ this.atom({ type: 'launch', component: mget(this.config, 'launch_component'), restart: true }, 'discovery:restore', 'discover-recover');
1135
+ p.forEach((action, index) => this.atom(action, 'discovery:replay:' + index, 'discover-replay'));
1136
+ };
1137
+ let outcome;
1138
+ try {
1139
+ while (queue.length && visited.size < maxStates) {
1140
+ const p = queue.shift();
1141
+ try { restore(p); } catch (e) {
1142
+ if (e instanceof BudgetExhausted) { throw e; }
1143
+ if (!(e instanceof AdapterError)) { throw e; }
1144
+ failures += 1;
1145
+ this.emit('route_result', { route_id: 'discovery-replay-' + hash(p, 12), outcome: 'failed', reason: errStr(e),
1146
+ observation_id: this.current.observation_id });
1147
+ continue;
1148
+ }
1149
+ const state = observationKey(this.current);
1150
+ if (visited.has(state)) { continue; }
1151
+ visited.add(state);
1152
+ if (p.length >= maxDepth) { continue; }
1153
+ const candidates = this.discoveryActions(config);
1154
+ for (const action of candidates) {
1155
+ if (expanded >= maxExp()) { break; }
1156
+ expanded += 1;
1157
+ try {
1158
+ restore(p);
1159
+ const before = observationKey(this.current);
1160
+ const result = this.atom(action, 'discovery:' + expanded, 'discover');
1161
+ const after = observationKey(this.current);
1162
+ if (before === after) { continue; }
1163
+ transitions += 1;
1164
+ this.emit('route_result', { route_id: 'discovery-' + hash([...p, action], 16), outcome: 'captured',
1165
+ observation_id: this.current.observation_id, action_event_id: result.id, depth: p.length + 1 });
1166
+ if (!visited.has(after) && p.length + 1 < maxDepth) { queue.push([...p, action]); }
1167
+ } catch (e) {
1168
+ if (!(e instanceof AdapterError)) { throw e; }
1169
+ failures += 1;
1170
+ this.emit('route_result', { route_id: 'discovery-action-' + expanded, outcome: 'failed', reason: errStr(e),
1171
+ observation_id: this.current.observation_id });
1172
+ }
1173
+ }
1174
+ if (expanded >= maxExp()) { break; }
1175
+ }
1176
+ outcome = 'completed';
1177
+ } catch (e) {
1178
+ if (!(e instanceof BudgetExhausted)) { throw e; }
1179
+ outcome = 'budget-exhausted';
1180
+ }
1181
+ const result = { enabled: true, outcome, states: visited.size, transitions, expanded_actions: expanded, failures };
1182
+ this.emit('discovery_result', result);
1183
+ return result;
1184
+ }
1185
+
1186
+ _block(reason) { Object.assign(this.phase, { status: 'blocked', reason }); this.save(); }
1187
+
1188
+ /** Blocked because the device did not come back (see DEVICE_UNAVAILABLE_EXIT). */
1189
+ deviceUnavailable() { return this.phase.status === 'blocked' && this.phase.reason === DEVICE_UNAVAILABLE; }
1190
+
1191
+ /**
1192
+ * Grant the app's not-yet-granted runtime permissions (`grant_runtime_permissions`, default
1193
+ * on), so a permission prompt or the settings page the app opens never takes the foreground in
1194
+ * the middle of a capture. A campaign that needs the permission-denied or rationale screens sets
1195
+ * it to false (for the whole config, or runs those phases with a config that does).
1196
+ * Returns [granted, failed].
1197
+ */
1198
+ grantRuntimePermissions() {
1199
+ const pkg = get(this.config, 'package');
1200
+ const granted = []; const failed = [];
1201
+ if (!truthy(pkg) || !truthy(get(this.config, 'grant_runtime_permissions', true))) { return [granted, failed]; }
1202
+ let dump = '';
1203
+ try { dump = this.device._shell('dumpsys', 'package', pkg); } catch { dump = ''; }
1204
+ for (const perm of runtimePermissions(dump, { ungrantedOnly: true })) {
1205
+ try { this.device._shell('pm', 'grant', pkg, perm); granted.push(perm); } catch { failed.push(perm); }
1206
+ }
1207
+ return [granted, failed];
1208
+ }
1209
+
1210
+ /**
1211
+ * Before the fixtures: grant runtime permissions, then leave any other app's screen.
1212
+ * A fixture step that resets app data (`pm clear` revokes every grant) grants them again.
1213
+ * One `environment_prepared` event.
1214
+ */
1215
+ prepareEnvironment() {
1216
+ const pkg = get(this.config, 'package');
1217
+ if (!truthy(pkg)) { return; }
1218
+ const [granted, failed] = this.grantRuntimePermissions();
1219
+ let left = null;
1220
+ const fg = get(this.current, 'package');
1221
+ if (truthy(fg) && fg !== pkg && !truthy(get(this.config, 'keep_foreign_foreground'))) {
1222
+ try { this.device._shell('input', 'keyevent', 'KEYCODE_HOME'); left = fg; } catch { /* the launch decides */ }
1223
+ }
1224
+ this.emit('environment_prepared', { phase: this.phase.id, granted, failed, left_foreground: left });
1225
+ }
1226
+
1227
+ _runFixtures() {
1228
+ for (const action of get(get(this.config, 'fixtures', {}), this.phase.id, [])) {
1229
+ // A fixture's own save step only exists to hand its state to later phases. When the phase
1230
+ // runs again (next round, resume) the archive is the one this fixture already wrote: keep it
1231
+ // (never overwrite) and continue, instead of blocking the phase on its own artifact.
1232
+ if (['snapshot_app_data', 'save_replay'].includes(get(action, 'type')) && truthy(get(action, 'archive'))
1233
+ && fs.existsSync(pathStr(action.archive))) {
1234
+ this.emit('fixture_snapshot_kept', { phase: this.phase.id, type: action.type, archive: pathStr(action.archive) });
1235
+ continue;
1236
+ }
1237
+ if (get(action, 'type') === 'assert') {
1238
+ if (!ruleMatches(this.current, action.rule)) {
1239
+ this._block('fixture-assert-failed: ' + cpSlice(jsonDumps(action.rule, { ensure_ascii: false }), 0, 120));
1240
+ return false;
1241
+ }
1242
+ continue;
1243
+ }
1244
+ try {
1245
+ this.seek(action, 'fixture:' + this.phase.id, 'prepare');
1246
+ if (['clear_app_data', 'restore_app_data'].includes(get(action, 'type'))) { this.grantRuntimePermissions(); }
1247
+ } catch (exc) {
1248
+ if (!(exc instanceof AdapterError)) { throw exc; }
1249
+ try {
1250
+ if (!(TRANSIENT_DEVICE_RE.test(errStr(exc)) && this.waitDevice())) { throw exc; }
1251
+ this.seek(action, 'fixture:' + this.phase.id, 'prepare');
1252
+ } catch (exc2) {
1253
+ if (!(exc2 instanceof AdapterError)) { throw exc2; }
1254
+ const sel = or(get(action, 'selectors'), () => or(get(action, 'selector'), ''));
1255
+ this._block(`fixture-step-failed: ${pyStr(get(action, 'type'))} ${cpSlice(jsonDumps(sel, { ensure_ascii: false }), 0, 80)}: ${errStr(exc2)}`);
1256
+ return false;
1257
+ }
1258
+ }
1259
+ }
1260
+ return true;
1261
+ }
1262
+
1263
+ run() {
1264
+ this.capture();
1265
+ const tasks = get(this.doc, 'tasks', []).filter((t) => t.phase === this.phase.id);
1266
+ const probesFor = get(get(this.config, 'phase_probes', {}), this.phase.id);
1267
+ if (truthy(this.phase.requires) && !truthy(probesFor)) {
1268
+ return this._block('unresolved prerequisites: ' + this.phase.requires.join(', '));
1269
+ }
1270
+ this.prepareEnvironment();
1271
+ if (!this._runFixtures()) { return undefined; }
1272
+ const probes = get(get(this.config, 'phase_probes', {}), this.phase.id, []);
1273
+ if (truthy(probes) && !probes.every((r) => ruleMatches(this.current, r))) { return this._block('state-probe-failed'); }
1274
+ this.emit('environment_verified', { phase: this.phase.id, observation_id: this.current.observation_id,
1275
+ scope: truthy(probes) ? 'configured probes' : 'existing state, no guard assumed' });
1276
+ this.phase.status = 'running'; this.save();
1277
+ let routeFailures = 0;
1278
+ for (const route of get(get(this.config, 'routes', {}), this.phase.id, [])) {
1279
+ try {
1280
+ for (const action of route.actions) {
1281
+ if (get(action, 'type') === 'assert') {
1282
+ if (!ruleMatches(this.current, action.rule)) { throw new AdapterError('route checkpoint failed'); }
1283
+ } else { this.seek(action, 'route:' + route.id, 'discover'); }
1284
+ }
1285
+ this.emit('route_result', { route_id: route.id, outcome: 'captured', observation_id: this.current.observation_id });
1286
+ } catch (e) {
1287
+ if (e instanceof BudgetExhausted) {
1288
+ Object.assign(this.phase, { status: 'budget-exhausted', reason: 'discovery route budget exhausted' }); this.save(); return undefined;
1289
+ }
1290
+ routeFailures += 1;
1291
+ this.emit('route_result', { route_id: route.id, outcome: 'failed', reason: errStr(e), observation_id: this.current.observation_id });
1292
+ }
1293
+ }
1294
+ const starts = counter(this.doc.events.filter((e) => e.kind === 'task_started').map((e) => e.payload.task_id));
1295
+ const phaseTaskIds = new Set(tasks.map((t) => t.task_id));
1296
+ const done = new Set(this.doc.events.filter((e) => e.kind === 'task_result' && e.payload.outcome === 'confirmed'
1297
+ && phaseTaskIds.has(e.payload.task_id)).map((e) => e.payload.task_id));
1298
+ let scheduled = 0;
1299
+ const transient = new Map();
1300
+ const skipped = new Set();
1301
+ try {
1302
+ for (const task of tasks) {
1303
+ const ident = task.task_id;
1304
+ if (done.has(ident) || (starts.get(ident) ?? 0) >= toInt(get(this.config, 'max_task_attempts', 1))) { continue; }
1305
+ if (this.coverage === 'nodes' && this.covered.has(get(task, 'target_static'))) {
1306
+ this.emit('task_skipped', { task_id: ident, target_static: task.target_static, reason: 'target-already-covered' });
1307
+ skipped.add(ident);
1308
+ continue;
1309
+ }
1310
+ // A scoped (incremental) campaign: a target outside the scope is settled, whatever the mode.
1311
+ if (this.scopeExcludes(get(task, 'target_static'))) {
1312
+ this.emit('task_skipped', { task_id: ident, target_static: task.target_static, reason: 'target-out-of-scope' });
1313
+ skipped.add(ident);
1314
+ continue;
1315
+ }
1316
+ if (scheduled >= this.args.max_tasks) { break; }
1317
+ if (task.status !== 'compiled') {
1318
+ const reasons = or(get(task, 'compile_issues'), ['needs-external-assistance']);
1319
+ this.emit('task_result', { task_id: ident, outcome: 'unsupported', reason: reasons.join(', '), compile_issues: reasons });
1320
+ continue;
1321
+ }
1322
+ const invariants = get(get(this.config, 'invariant_probes', {}), this.phase.id, []);
1323
+ if (truthy(invariants) && !invariants.every((p) => ruleMatches(this.current, p))) { return this._block('state-drift'); }
1324
+ scheduled += 1; starts.set(ident, (starts.get(ident) ?? 0) + 1);
1325
+ this.emit('task_started', { task_id: ident, target_static: task.target_static });
1326
+ this.keep = [task.source_static, task.target_static, get(task, 'source_context')].filter((x) => truthy(x));
1327
+ if (get(task, 'purpose') === 'direct-launch') { this.runDirect(task, done); continue; }
1328
+ try {
1329
+ this._runTask(task, ident, done);
1330
+ } catch (exc) {
1331
+ if (exc instanceof BudgetExhausted) {
1332
+ this.emit('task_result', { task_id: ident, outcome: 'budget-exhausted', stage: this.stage });
1333
+ throw exc;
1334
+ }
1335
+ const msg = errStr(exc);
1336
+ if (msg.includes('does not exist') && msg.includes('Activity class')) {
1337
+ this.emit('task_result', { task_id: ident, outcome: 'unsupported', reason: 'entry-component-not-installed',
1338
+ stage: this.stage, target_static: task.target_static });
1339
+ continue;
1340
+ }
1341
+ if (TRANSIENT_DEVICE_RE.test(msg)) {
1342
+ const recovered = this.waitDevice();
1343
+ transient.set(ident, (transient.get(ident) ?? 0) + 1);
1344
+ if (recovered && transient.get(ident) <= toInt(get(this.config, 'max_device_retries', 1))) {
1345
+ starts.set(ident, starts.get(ident) - 1);
1346
+ this.emit('task_result', { task_id: ident, outcome: 'device-error', reason: cpSlice(msg, 0, 200), stage: this.stage,
1347
+ retrying: true, target_static: task.target_static });
1348
+ tasks.push(task);
1349
+ continue;
1350
+ }
1351
+ this.emit('task_result', { task_id: ident, outcome: 'device-error', reason: cpSlice(msg, 0, 200), stage: this.stage,
1352
+ target_static: task.target_static });
1353
+ if (!recovered) { return this._block(DEVICE_UNAVAILABLE); }
1354
+ continue;
1355
+ }
1356
+ const prefix = exc instanceof PrefixFailed
1357
+ ? { prefix_failed_from: exc.from, prefix_key: exc.key, replay_index: exc.replayIndex, prefix_before: exc.beforeId } : {};
1358
+ this.emit('task_result', { task_id: ident, outcome: 'failed', stage: this.stage,
1359
+ unmet_preconditions: or(get(task, 'task_preconditions'), []).map((x) => get(x, 'text')),
1360
+ reason: msg, target_static: task.target_static,
1361
+ observation_id: exc instanceof PrefixFailed ? exc.observationId : this.current.observation_id, ...prefix });
1362
+ }
1363
+ pyPrint(jsonDumps({ task: ident, attempted_this_run: scheduled, confirmed: done.size, atomic_actions: this.used,
1364
+ target: task.target_static }, { ensure_ascii: false }));
1365
+ }
1366
+ } catch (exc) {
1367
+ if (!(exc instanceof BudgetExhausted)) { throw exc; }
1368
+ Object.assign(this.phase, { status: 'budget-exhausted', reason: errStr(exc) }); this.save(); return undefined;
1369
+ }
1370
+ try { this.sweepBacklog(); } catch (e) { if (!(e instanceof BudgetExhausted)) { throw e; } }
1371
+ const discovery = this.runDiscovery();
1372
+ const mapped = new Set(this.doc.events.filter((e) => e.kind === 'mapping' && e.environment_id === this.env)
1373
+ .map((e) => get(e.payload, 'static_id')));
1374
+ const missing = this.phase.obligations.filter((o) => o.type === 'node' && !mapped.has(o.id) && !this.scopeExcludes(o.id));
1375
+ const resolved = new Set([...done, ...skipped]).size;
1376
+ Object.assign(this.phase, {
1377
+ status: resolved === tasks.length && !missing.length && !routeFailures ? 'completed' : 'exhausted-with-gaps',
1378
+ reason: `${done.size}/${tasks.length} tasks confirmed; ${skipped.size} skipped (target already covered or out of scope); `
1379
+ + `${missing.length} node obligations missing; ${routeFailures} routes failed; `
1380
+ + `discovery=${pyStr(get(discovery, 'outcome', 'disabled'))}; coverage=${this.coverage}`,
1381
+ });
1382
+ this.save();
1383
+ return undefined;
1384
+ }
1385
+
1386
+ _runTask(task, ident, done) {
1387
+ this.stage = 'source';
1388
+ this.source(task);
1389
+ if (this.sweep(task.source_static) && (this.dirty ?? false)) { this.source(task); }
1390
+ this.stage = 'target';
1391
+ let result; let mark;
1392
+ if (truthy(get(task.action, 'automatic')) && this.at(task.target_static)) {
1393
+ result = this.emit('action_result', { task_id: ident, purpose: 'target', outcome: 'succeeded',
1394
+ before: this.current.observation_id, after: this.current.observation_id, action: task.action });
1395
+ } else {
1396
+ mark = this.doc.events.length;
1397
+ for (const step of or(get(task, 'prelude'), [])) { this.seek(step, ident, 'target-prelude'); }
1398
+ result = this.seek(task.action, ident, 'target');
1399
+ }
1400
+ const confirmed = this.at(task.target_static);
1401
+ if (confirmed) {
1402
+ let chain = [result];
1403
+ if (!truthy(get(task.action, 'automatic'))) {
1404
+ chain = this.doc.events.slice(mark).filter((e) => e.kind === 'action_result' && get(e.payload, 'task_id') === ident);
1405
+ }
1406
+ const firstBefore = chain[0].payload.before;
1407
+ let beforeObs = {};
1408
+ for (let k = this.doc.events.length - 1; k >= 0; k--) {
1409
+ const e = this.doc.events[k];
1410
+ if (e.kind === 'observation' && get(e.payload, 'observation_id') === firstBefore) { beforeObs = e.payload; break; }
1411
+ }
1412
+ const sourceMatch = deps.observationMatchesStatic(beforeObs, task.source_static, this.catalog)[1];
1413
+ const targetMatch = deps.observationMatchesStatic(this.current, task.target_static, this.catalog)[1];
1414
+ this.emit('edge_mapping', { task_id: ident, static_id: task.target_static, source_static: task.source_static,
1415
+ target_static: task.target_static, action_event_id: result.id, action_chain: chain.map((e) => e.id),
1416
+ before: firstBefore, after: result.payload.after, source_match: sourceMatch,
1417
+ method: get(get(this.current, 'static_resolution', {}), 'reason', targetMatch) });
1418
+ done.add(ident);
1419
+ } else if (!truthy(get(task.action, 'automatic')) && truthy(result)) {
1420
+ this.attest(task, result);
1421
+ } else if (truthy(get(task.action, 'automatic')) && this.anchorless(task.target_static)
1422
+ && truthy(get(get(this.catalog, task.source_static, {}), 'transient'))) {
1423
+ // The transient entry left to an anchorless page: identity by elimination only, so it is
1424
+ // attested (listed apart), never mapped.
1425
+ const rivals = or(get(get(this.catalog, task.source_static, {}), 'auto_targets'), []).filter((t) => t !== task.target_static);
1426
+ if (this._unclaimedAppScreen(rivals, task.target_static)) {
1427
+ this.emit('attestation', { static_id: task.target_static, task_id: ident, observation_id: this.current.observation_id,
1428
+ basis: 'transient-successor', evidence: { context: task.source_static, rivals },
1429
+ action_event_id: truthy(result) ? result.id : null });
1430
+ }
1431
+ }
1432
+ this.emit('task_result', { task_id: ident, outcome: confirmed ? 'confirmed' : 'target-unverified',
1433
+ target_static: task.target_static, observation_id: this.current.observation_id });
1434
+ if (confirmed) { this.sweep(task.target_static); }
1435
+ }
1436
+ }
1437
+
1438
+ /**
1439
+ * back_exit_pages(events): verified pages from which a Back press has already left the app (the
1440
+ * app's root screens, learned from the device). Recovery relaunches from them instead of pressing
1441
+ * Back again. Derived from the event log, so it carries across phases, rounds and resumes.
1442
+ */
1443
+ export function backExitPages(events) {
1444
+ const obs = new Map();
1445
+ for (const e of events) { if (e.kind === 'observation') { obs.set(tupleKey(e.environment_id, get(e.payload, 'observation_id')), e.payload); } }
1446
+ const out = new Set();
1447
+ for (const e of events) {
1448
+ const p = e.payload;
1449
+ if (e.kind !== 'action_result' || get(get(p, 'action', {}), 'type') !== 'back') { continue; }
1450
+ const before = obs.get(tupleKey(e.environment_id, get(p, 'before'))) ?? {};
1451
+ const after = obs.get(tupleKey(e.environment_id, get(p, 'after'))) ?? {};
1452
+ const rb = get(before, 'static_resolution', {}) ?? {};
1453
+ if (get(rb, 'status') === 'verified' && get(get(after, 'static_resolution', {}) ?? {}, 'status') === 'foreign-package') {
1454
+ out.add(rb.static_id);
1455
+ }
1456
+ }
1457
+ return out;
1458
+ }
1459
+
1460
+ /** deviceLock options of a runner: config.device_lock_wait_s (default LOCK_WAIT_S), owner campaign. */
1461
+ export function lockWait(config, campaign) {
1462
+ return { waitS: toFloat(get(config ?? {}, 'device_lock_wait_s', LOCK_WAIT_S)), campaign: pResolve(campaign) };
1463
+ }
1464
+
1465
+ /**
1466
+ * run_campaign_phase(args): run one phase under the device lock, then its cleanup steps. The
1467
+ * Runner (which loads campaign.json and saves it wholesale) is built only once the lock is held,
1468
+ * so a run that waited for another run of this campaign starts from that run's saved document.
1469
+ */
1470
+ export function runCampaignPhase(args) {
1471
+ const config = readJson(args.config);
1472
+ const serial = get(config, 'serial');
1473
+ if (!truthy(serial)) { throw new AdapterError('Explicit serial required to avoid controlling the wrong device'); }
1474
+ let runner = null;
1475
+ let busy = null;
1476
+ try {
1477
+ deviceLock(serial, () => {
1478
+ runner = new Runner(args);
1479
+ try {
1480
+ try {
1481
+ runner.run();
1482
+ } finally {
1483
+ runner.save();
1484
+ const cleanup = get(get(runner.config, 'cleanup', {}), runner.phase.id, []);
1485
+ if (truthy(cleanup)) {
1486
+ for (const action of cleanup) {
1487
+ if (get(action, 'type') === 'assert') {
1488
+ if (!ruleMatches(runner.current, action.rule)) { throw new AdapterError('cleanup postcondition failed'); }
1489
+ } else { runner.seek(action, 'cleanup:' + runner.phase.id, 'restore'); }
1490
+ }
1491
+ runner.emit('environment_restored', { phase: runner.phase.id, observation_id: runner.current.observation_id });
1492
+ }
1493
+ }
1494
+ } finally {
1495
+ // Close (persistent shell, u2 server on device port 9008) while the lock is still held:
1496
+ // a run waiting for the lock would otherwise reuse our live server, which this close kills.
1497
+ runner.device.close();
1498
+ }
1499
+ }, lockWait(config, args.campaign));
1500
+ } catch (e) {
1501
+ if (!(e instanceof DeviceBusy)) { throw e; }
1502
+ busy = e;
1503
+ }
1504
+ // another explorer kept the device: device-unavailable, not a failed phase
1505
+ if (busy) {
1506
+ pyPrintErr(`phase ${pyStr(get(args, 'phase'))} blocked: ${busy.message}`);
1507
+ throw new SystemExit(DEVICE_UNAVAILABLE_EXIT);
1508
+ }
1509
+ if (runner.deviceUnavailable()) {
1510
+ pyPrintErr(`phase ${runner.phase.id} blocked: device-unavailable`);
1511
+ throw new SystemExit(DEVICE_UNAVAILABLE_EXIT);
1512
+ }
1513
+ }