@buaa_smat/hometrans 26.0.5 → 26.0.6

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 (472) hide show
  1. package/README.md +249 -279
  2. package/agents/code-reviewer.md +1 -1
  3. package/dist/cli/editors.json +20 -0
  4. package/dist/platform/registry.js +1 -0
  5. package/dist/platform/validate.js +2 -1
  6. package/i18n/agents/code-reviewer.md +1 -1
  7. package/i18n/platforms/atomcode/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  8. package/i18n/platforms/claude-code/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  9. package/i18n/platforms/codebuddy/skills/a2h-app-migrate/SKILL.unique.md +8 -0
  10. package/i18n/platforms/codex/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  11. package/i18n/platforms/cursor/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  12. package/i18n/platforms/deveco/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  13. package/i18n/platforms/opencode/skills/a2h-app-migrate/SKILL.unique.md +10 -0
  14. package/i18n/platforms/qoder/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  15. package/i18n/platforms/qoder-cn/skills/a2h-app-migrate/SKILL.unique.md +8 -0
  16. package/i18n/platforms/trae/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  17. package/i18n/platforms/trae-cn/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  18. package/i18n/skills/a2h-app-migrate/SKILL.md +32 -15
  19. package/i18n/skills/a2h-app-migrate/references/stage-map.md +4 -2
  20. package/i18n/skills/a2h-app-migrate/references/workflow.yaml +148 -89
  21. package/i18n/skills/a2h-app-migrate/scripts/env_preflight.mjs +1 -1
  22. package/i18n/skills/a2h-app-migrate/scripts/validate_workflow.mjs +51 -2
  23. package/i18n/skills/a2h-app-migrate/test/test_build_fixer_contract.mjs +1 -1
  24. package/i18n/skills/a2h-app-migrate/test/test_interaction.mjs +0 -2
  25. package/i18n/skills/a2h-app-migrate/test/test_resume_plan.mjs +1 -1
  26. package/i18n/skills/a2h-app-migrate/test/test_skill_doc.mjs +1 -1
  27. package/i18n/skills/a2h-app-migrate/test/test_specs_json_preflight.mjs +1 -1
  28. package/i18n/skills/a2h-app-migrate/test/test_utg_static_done.mjs +9 -3
  29. package/i18n/skills/a2h-app-migrate/test/test_validate_workflow_bilingual.mjs +4 -2
  30. package/i18n/skills/a2h-arkts-logic-coder/SKILL.md +8 -7
  31. package/i18n/skills/a2h-arkts-logic-coder/references/ISSUES.md +2 -2
  32. package/i18n/skills/a2h-arkts-logic-coder/references/code-generation.md +33 -12
  33. package/i18n/skills/a2h-batch-ui-align/SKILL.md +14 -12
  34. package/i18n/skills/a2h-batch-ui-align/references/cards/alignment.md +1 -0
  35. package/i18n/skills/a2h-batch-ui-align/references/cards/canvas.md +1 -0
  36. package/i18n/skills/a2h-batch-ui-align/references/cards/dynamics.md +32 -1
  37. package/i18n/skills/a2h-batch-ui-align/references/cards/geometry.md +3 -2
  38. package/i18n/skills/a2h-batch-ui-align/references/cards/interaction.md +4 -0
  39. package/i18n/skills/a2h-batch-ui-align/references/cards/resources.md +19 -1
  40. package/i18n/skills/a2h-batch-ui-align/references/cards/widgets.md +13 -1
  41. package/i18n/skills/a2h-batch-ui-align/references/cards/window.md +2 -2
  42. package/i18n/skills/a2h-batch-ui-align/references/checker-rules.md +205 -7
  43. package/i18n/skills/a2h-batch-ui-align/references/conversion-procedure.md +10 -17
  44. package/i18n/skills/a2h-batch-ui-align/references/incremental-scope.md +3 -4
  45. package/i18n/skills/a2h-batch-ui-align/references/lottie-integration.md +47 -2
  46. package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +52 -328
  47. package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +1 -138
  48. package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +2 -11
  49. package/i18n/skills/a2h-batch-ui-align/references/state-mgmt/_paradigm-selection.md +1 -1
  50. package/i18n/skills/a2h-batch-ui-align/references/step3-capture.md +8 -23
  51. package/i18n/skills/a2h-batch-ui-align/references/step4-prepare.md +2 -1
  52. package/i18n/skills/a2h-batch-ui-align/references/step5-convert.md +17 -9
  53. package/i18n/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +239 -16
  54. package/i18n/skills/a2h-batch-ui-align/scripts/group_pack.mjs +6 -0
  55. package/i18n/skills/a2h-batch-ui-align/scripts/icon_coverage.mjs +6 -3
  56. package/i18n/skills/a2h-batch-ui-align/scripts/measure_pack.ts +170 -10
  57. package/i18n/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +42 -1
  58. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/main.ts +20 -1
  59. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/attr_chain.ts +81 -0
  60. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/click_handler.ts +140 -0
  61. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/collapsing_toolbar.ts +124 -0
  62. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/compose_semantics.ts +287 -0
  63. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/flowitem_width.ts +78 -0
  64. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/hit_test.ts +194 -8
  65. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/inset_stacked.ts +138 -0
  66. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/int_division.ts +181 -0
  67. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/layout_placement.ts +62 -2
  68. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/lottie_path.ts +77 -0
  69. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/lottie_ready.ts +109 -0
  70. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +88 -18
  71. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/relative_container_cycle.ts +140 -0
  72. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/relative_container_height.ts +2 -2
  73. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/see_through_overlay.ts +149 -0
  74. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/sheet_builder.ts +139 -0
  75. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/sheet_show_close.ts +53 -0
  76. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/space_between_optional.ts +115 -0
  77. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/theme_color.ts +7 -1
  78. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/width_fill.ts +160 -0
  79. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_inset_stacked.test.mjs +155 -0
  80. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_layout_placement.test.mjs +60 -0
  81. package/i18n/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set.test.mjs +38 -0
  82. package/i18n/skills/a2h-module-semantic-docs/SKILL.md +3 -2
  83. package/i18n/skills/a2h-page-specgen/SKILL.md +36 -5
  84. package/i18n/skills/a2h-page-specgen/references/behavior-ledger.md +89 -21
  85. package/i18n/skills/a2h-page-specgen/references/gates.md +33 -7
  86. package/i18n/skills/a2h-page-specgen/references/scenario-authoring.md +67 -13
  87. package/i18n/skills/a2h-page-specgen/references/spec-example.md +166 -32
  88. package/i18n/skills/a2h-page-specgen/references/spec-template.md +8 -5
  89. package/i18n/skills/a2h-page-specgen/scripts/behavior-audit.mjs +37 -1
  90. package/i18n/skills/a2h-page-specgen/scripts/behavior-discovery.mjs +241 -22
  91. package/i18n/skills/a2h-page-specgen/scripts/behavior-model.mjs +29 -2
  92. package/i18n/skills/a2h-page-specgen/scripts/behavior-reconcile.mjs +32 -0
  93. package/i18n/skills/a2h-page-specgen/scripts/contract-calls.mjs +715 -0
  94. package/i18n/skills/a2h-page-specgen/scripts/footprint.mjs +129 -2
  95. package/i18n/skills/a2h-page-specgen/scripts/gate.mjs +19 -10
  96. package/i18n/skills/a2h-page-specgen/scripts/lib/contracts.mjs +62 -3
  97. package/i18n/skills/a2h-page-specgen/scripts/lib/graph-evidence.mjs +27 -0
  98. package/i18n/skills/a2h-page-specgen/scripts/lib/hg.mjs +116 -6
  99. package/i18n/skills/a2h-page-specgen/scripts/operation-evidence.mjs +270 -29
  100. package/i18n/skills/a2h-page-specgen/scripts/prepare.mjs +26 -14
  101. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md +118 -25
  102. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md +104 -19
  103. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.prompt.md +118 -25
  104. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.worker.md +104 -19
  105. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.discovery.json +216 -216
  106. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.json +1 -1
  107. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.post-review.json +2 -2
  108. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.prompt.md +118 -25
  109. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.worker.md +100 -15
  110. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.prompt.md +118 -25
  111. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.worker.md +104 -19
  112. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/run.mjs +155 -3
  113. package/i18n/skills/a2h-page-specgen/scripts/test/android-operation-evidence.test.mjs +529 -1
  114. package/i18n/skills/a2h-page-specgen/scripts/test/behavior-audit-pre.test.mjs +27 -0
  115. package/i18n/skills/a2h-page-specgen/scripts/test/behavior-discovery.test.mjs +158 -0
  116. package/i18n/skills/a2h-page-specgen/scripts/test/behavior-fixtures.mjs +11 -13
  117. package/i18n/skills/a2h-page-specgen/scripts/test/behavior-reconcile.test.mjs +97 -0
  118. package/i18n/skills/a2h-page-specgen/scripts/test/contract-calls.test.mjs +737 -0
  119. package/i18n/skills/a2h-page-specgen/scripts/test/contracts.test.mjs +75 -3
  120. package/i18n/skills/a2h-page-specgen/scripts/test/finalize.test.mjs +24 -0
  121. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/hg.mkdb.mjs +124 -0
  122. package/i18n/skills/a2h-page-specgen/scripts/test/footprint-resolve.test.mjs +6 -2
  123. package/i18n/skills/a2h-page-specgen/scripts/test/gate.test.mjs +106 -1
  124. package/i18n/skills/a2h-page-specgen/scripts/test/graph-evidence.test.mjs +32 -0
  125. package/i18n/skills/a2h-page-specgen/scripts/test/hg.test.mjs +12 -0
  126. package/i18n/skills/a2h-page-specgen/scripts/test/operation-reviews.test.mjs +6 -1
  127. package/i18n/skills/a2h-page-specgen/scripts/test/prompt-tpl.test.mjs +11 -3
  128. package/i18n/skills/a2h-page-specgen/scripts/test/protocol-docs.test.mjs +1 -1
  129. package/i18n/skills/a2h-page-specgen/scripts/test/recovery-e2e.test.mjs +1 -0
  130. package/i18n/skills/a2h-page-specgen/scripts/test/submit.test.mjs +159 -27
  131. package/i18n/skills/a2h-resource-convert/SKILL.md +1 -1
  132. package/i18n/skills/a2h-resource-convert/references/lottie-conversion-rules.md +2 -2
  133. package/i18n/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +124 -8
  134. package/i18n/skills/a2h-resource-convert/scripts/sync-framework-strings.mjs +147 -0
  135. package/i18n/skills/a2h-resource-convert/scripts/tests/framework_strings.test.mjs +131 -0
  136. package/i18n/skills/a2h-spec-design-pipeline/SKILL.md +15 -12
  137. package/i18n/skills/a2h-spec-design-pipeline/references/coding-loop.md +38 -10
  138. package/i18n/skills/a2h-spec-design-pipeline/references/initialization.md +2 -2
  139. package/i18n/skills/a2h-spec-design-pipeline/references/post-loop.md +2 -2
  140. package/i18n/skills/a2h-spec-design-pipeline/references/reply-recovery.md +172 -0
  141. package/i18n/skills/a2h-spec-design-pipeline/references/review-loop.md +2 -2
  142. package/i18n/skills/a2h-spec-design-pipeline/references/scripts.md +5 -3
  143. package/i18n/skills/a2h-spec-design-pipeline/references/state-and-resume.md +7 -1
  144. package/i18n/skills/a2h-spec-design-pipeline/scripts/plan_groups.ts +1 -1
  145. package/i18n/skills/a2h-spec-design-pipeline/scripts/test_plan_groups.ts +2 -0
  146. package/i18n/skills/a2h-spec-generate/references/input-formats.md +1 -1
  147. package/i18n/skills/a2h-utg-explorer/SKILL.md +11 -5
  148. package/i18n/skills/a2h-utg-explorer/references/architecture.md +37 -19
  149. package/i18n/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +48 -3
  150. package/i18n/skills/a2h-utg-explorer/scripts/final_utg.mjs +21 -0
  151. package/i18n/skills/a2h-utg-explorer/scripts/recover_d.mjs +67 -8
  152. package/i18n/skills/a2h-utg-explorer/scripts/tests/diagnostics.test.mjs +32 -0
  153. package/i18n/skills/a2h-utg-explorer/scripts/tests/dialog_own_layout.test.mjs +40 -0
  154. package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +63 -2
  155. package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +143 -14
  156. package/i18n/skills/a2h-utg-static/SKILL.md +3 -3
  157. package/i18n/skills/a2h-utg-static/references/ui-elements-static-utg-schema.md +4 -3
  158. package/i18n/skills/a2h-utg-static/scripts/click_paths.mjs +1 -1
  159. package/i18n/skills/a2h-utg-static/scripts/tests/test_compose_res_text.mjs +25 -0
  160. package/i18n/skills/a2h-utg-static/tools/convert_static_utg_to_ui_elements.ts +1 -0
  161. package/package.json +2 -1
  162. package/platforms/atomcode/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  163. package/platforms/claude-code/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  164. package/platforms/codebuddy/agents/build-fixer.frontmatter.md +5 -0
  165. package/platforms/codebuddy/agents/code-reviewer.frontmatter.md +5 -0
  166. package/platforms/codebuddy/agents/model-render-worker.frontmatter.md +5 -0
  167. package/platforms/codebuddy/agents/model-worker.frontmatter.md +5 -0
  168. package/platforms/codebuddy/agents/specgen-worker.frontmatter.md +5 -0
  169. package/platforms/codebuddy/skills/a2h-app-migrate/SKILL.unique.md +8 -0
  170. package/platforms/codex/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  171. package/platforms/cursor/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  172. package/platforms/deveco/agents/build-fixer.frontmatter.md +2 -0
  173. package/platforms/deveco/agents/code-reviewer.frontmatter.md +2 -0
  174. package/platforms/deveco/agents/model-render-worker.frontmatter.md +2 -0
  175. package/platforms/deveco/agents/model-worker.frontmatter.md +2 -0
  176. package/platforms/deveco/agents/specgen-worker.frontmatter.md +2 -0
  177. package/platforms/deveco/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  178. package/platforms/opencode/agents/build-fixer.frontmatter.md +2 -0
  179. package/platforms/opencode/agents/code-reviewer.frontmatter.md +2 -0
  180. package/platforms/opencode/agents/model-render-worker.frontmatter.md +2 -0
  181. package/platforms/opencode/agents/model-worker.frontmatter.md +2 -0
  182. package/platforms/opencode/agents/specgen-worker.frontmatter.md +2 -0
  183. package/platforms/opencode/skills/a2h-app-migrate/SKILL.unique.md +10 -0
  184. package/platforms/qoder/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  185. package/platforms/qoder-cn/skills/a2h-app-migrate/SKILL.unique.md +8 -0
  186. package/platforms/trae/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  187. package/platforms/trae-cn/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  188. package/skills/a2h-app-migrate/SKILL.md +31 -14
  189. package/skills/a2h-app-migrate/references/stage-map.md +4 -2
  190. package/skills/a2h-app-migrate/references/workflow.yaml +152 -89
  191. package/skills/a2h-app-migrate/scripts/assert_dag_complete.mjs +1 -1
  192. package/skills/a2h-app-migrate/scripts/check_ui_batch_done.mjs +28 -11
  193. package/skills/a2h-app-migrate/scripts/dag_action_catalog.mjs +76 -0
  194. package/skills/a2h-app-migrate/scripts/dag_production_executor.mjs +60 -5
  195. package/skills/a2h-app-migrate/scripts/dag_runner.mjs +184 -4
  196. package/skills/a2h-app-migrate/scripts/env_preflight.mjs +1 -1
  197. package/skills/a2h-app-migrate/scripts/ledger.mjs +2 -2
  198. package/skills/a2h-app-migrate/scripts/resume_plan.mjs +3 -3
  199. package/skills/a2h-app-migrate/scripts/validate_workflow.mjs +51 -2
  200. package/skills/a2h-app-migrate/test/test_dag_blocked_guard.mjs +291 -0
  201. package/skills/a2h-app-migrate/test/test_dag_production.mjs +40 -0
  202. package/skills/a2h-app-migrate/test/test_dag_runner.mjs +4 -3
  203. package/skills/a2h-app-migrate/test/test_i18n_engine_mirror.mjs +1 -1
  204. package/skills/a2h-app-migrate/test/test_interaction.mjs +0 -2
  205. package/skills/a2h-app-migrate/test/test_resume_plan.mjs +1 -1
  206. package/skills/a2h-app-migrate/test/test_skill_doc.mjs +1 -1
  207. package/skills/a2h-app-migrate/test/test_spec_engine_contract.mjs +1 -1
  208. package/skills/a2h-app-migrate/test/test_specs_json_preflight.mjs +1 -1
  209. package/skills/a2h-app-migrate/test/test_ui_batch_done.mjs +36 -0
  210. package/skills/a2h-app-migrate/test/test_utg_static_done.mjs +19 -6
  211. package/skills/a2h-app-migrate/test/test_validate_workflow_bilingual.mjs +4 -2
  212. package/skills/a2h-arkts-logic-coder/SKILL.md +8 -7
  213. package/skills/a2h-arkts-logic-coder/references/ISSUES.md +2 -2
  214. package/skills/a2h-arkts-logic-coder/references/code-generation.md +33 -12
  215. package/skills/a2h-batch-ui-align/SKILL.md +14 -12
  216. package/skills/a2h-batch-ui-align/references/cards/alignment.md +1 -0
  217. package/skills/a2h-batch-ui-align/references/cards/canvas.md +1 -0
  218. package/skills/a2h-batch-ui-align/references/cards/dynamics.md +32 -1
  219. package/skills/a2h-batch-ui-align/references/cards/geometry.md +3 -2
  220. package/skills/a2h-batch-ui-align/references/cards/interaction.md +4 -0
  221. package/skills/a2h-batch-ui-align/references/cards/resources.md +19 -1
  222. package/skills/a2h-batch-ui-align/references/cards/widgets.md +13 -1
  223. package/skills/a2h-batch-ui-align/references/cards/window.md +2 -2
  224. package/skills/a2h-batch-ui-align/references/checker-rules.md +205 -7
  225. package/skills/a2h-batch-ui-align/references/conversion-procedure.md +10 -17
  226. package/skills/a2h-batch-ui-align/references/incremental-scope.md +3 -4
  227. package/skills/a2h-batch-ui-align/references/lottie-integration.md +47 -2
  228. package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +52 -328
  229. package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +1 -138
  230. package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +2 -11
  231. package/skills/a2h-batch-ui-align/references/state-mgmt/_/350/214/203/345/274/217/351/200/211/346/213/251/350/257/264/346/230/216.md +1 -1
  232. package/skills/a2h-batch-ui-align/references/step3-capture.md +8 -23
  233. package/skills/a2h-batch-ui-align/references/step4-prepare.md +2 -1
  234. package/skills/a2h-batch-ui-align/references/step5-convert.md +17 -9
  235. package/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +239 -16
  236. package/skills/a2h-batch-ui-align/scripts/group_commit.mjs +6 -1
  237. package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +6 -0
  238. package/skills/a2h-batch-ui-align/scripts/group_pass.mjs +270 -0
  239. package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +134 -16
  240. package/skills/a2h-batch-ui-align/scripts/group_watch.mjs +39 -8
  241. package/skills/a2h-batch-ui-align/scripts/icon_coverage.mjs +6 -3
  242. package/skills/a2h-batch-ui-align/scripts/measure_pack.ts +170 -10
  243. package/skills/a2h-batch-ui-align/scripts/module_placement.mjs +189 -0
  244. package/skills/a2h-batch-ui-align/scripts/overlay_effects.mjs +205 -0
  245. package/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +42 -1
  246. package/skills/a2h-batch-ui-align/scripts/static_check/main.ts +20 -1
  247. package/skills/a2h-batch-ui-align/scripts/static_check/registry.ts +28 -0
  248. package/skills/a2h-batch-ui-align/scripts/static_check/rules/attr_chain.ts +81 -0
  249. package/skills/a2h-batch-ui-align/scripts/static_check/rules/click_handler.ts +140 -0
  250. package/skills/a2h-batch-ui-align/scripts/static_check/rules/collapsing_toolbar.ts +124 -0
  251. package/skills/a2h-batch-ui-align/scripts/static_check/rules/compose_semantics.ts +287 -0
  252. package/skills/a2h-batch-ui-align/scripts/static_check/rules/flowitem_width.ts +78 -0
  253. package/skills/a2h-batch-ui-align/scripts/static_check/rules/hit_test.ts +194 -8
  254. package/skills/a2h-batch-ui-align/scripts/static_check/rules/inset_stacked.ts +138 -0
  255. package/skills/a2h-batch-ui-align/scripts/static_check/rules/int_division.ts +181 -0
  256. package/skills/a2h-batch-ui-align/scripts/static_check/rules/layout_placement.ts +62 -2
  257. package/skills/a2h-batch-ui-align/scripts/static_check/rules/lottie_path.ts +77 -0
  258. package/skills/a2h-batch-ui-align/scripts/static_check/rules/lottie_ready.ts +109 -0
  259. package/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +88 -18
  260. package/skills/a2h-batch-ui-align/scripts/static_check/rules/relative_container_cycle.ts +140 -0
  261. package/skills/a2h-batch-ui-align/scripts/static_check/rules/relative_container_height.ts +2 -2
  262. package/skills/a2h-batch-ui-align/scripts/static_check/rules/see_through_overlay.ts +149 -0
  263. package/skills/a2h-batch-ui-align/scripts/static_check/rules/sheet_builder.ts +139 -0
  264. package/skills/a2h-batch-ui-align/scripts/static_check/rules/sheet_show_close.ts +53 -0
  265. package/skills/a2h-batch-ui-align/scripts/static_check/rules/space_between_optional.ts +115 -0
  266. package/skills/a2h-batch-ui-align/scripts/static_check/rules/theme_color.ts +7 -1
  267. package/skills/a2h-batch-ui-align/scripts/static_check/rules/width_fill.ts +160 -0
  268. package/skills/a2h-batch-ui-align/scripts/static_check/scan_file.ts +28 -0
  269. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_chrome_defaults.test.mjs +328 -0
  270. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_click_handler.test.mjs +127 -0
  271. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_compose_semantics.test.mjs +150 -0
  272. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_hit_test.test.mjs +117 -0
  273. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_inset_stacked.test.mjs +155 -0
  274. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_layout_placement.test.mjs +60 -0
  275. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_rule_smoke.test.mjs +413 -0
  276. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_runtime_api.test.mjs +159 -0
  277. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_sheet_builder.test.mjs +192 -0
  278. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_theme.test.mjs +4 -2
  279. package/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set.test.mjs +38 -0
  280. package/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set_compose.test.mjs +106 -0
  281. package/skills/a2h-batch-ui-align/scripts/tests/group_commit.test.mjs +15 -0
  282. package/skills/a2h-batch-ui-align/scripts/tests/group_pass.test.mjs +150 -0
  283. package/skills/a2h-batch-ui-align/scripts/tests/group_queue.test.mjs +125 -0
  284. package/skills/a2h-batch-ui-align/scripts/tests/group_watch.test.mjs +56 -0
  285. package/skills/a2h-batch-ui-align/scripts/tests/measure_pack_icon_leaf.test.mjs +143 -0
  286. package/skills/a2h-batch-ui-align/scripts/tests/module_placement.test.mjs +248 -0
  287. package/skills/a2h-batch-ui-align/scripts/tests/overlay_effects.test.mjs +214 -0
  288. package/skills/a2h-fix-build-errors/references/known-patterns.md +5 -5
  289. package/skills/a2h-module-semantic-docs/SKILL.md +3 -2
  290. package/skills/a2h-module-semantic-docs/scripts/commit_module_state.mjs +10 -0
  291. package/skills/a2h-module-semantic-docs/scripts/design_baseline.mjs +158 -0
  292. package/skills/a2h-module-semantic-docs/test/test_design_baseline.mjs +128 -0
  293. package/skills/a2h-page-specgen/SKILL.md +36 -5
  294. package/skills/a2h-page-specgen/references/behavior-ledger.md +88 -21
  295. package/skills/a2h-page-specgen/references/evidence.md +2 -1
  296. package/skills/a2h-page-specgen/references/execution-model.md +13 -5
  297. package/skills/a2h-page-specgen/references/gates.md +33 -7
  298. package/skills/a2h-page-specgen/references/scenario-authoring.md +67 -13
  299. package/skills/a2h-page-specgen/references/spec-example.md +166 -32
  300. package/skills/a2h-page-specgen/references/spec-template.md +8 -5
  301. package/skills/a2h-page-specgen/scripts/behavior-audit.mjs +40 -2
  302. package/skills/a2h-page-specgen/scripts/behavior-discovery.mjs +241 -22
  303. package/skills/a2h-page-specgen/scripts/behavior-model.mjs +29 -2
  304. package/skills/a2h-page-specgen/scripts/behavior-reconcile.mjs +35 -2
  305. package/skills/a2h-page-specgen/scripts/contract-calls.mjs +715 -0
  306. package/skills/a2h-page-specgen/scripts/finalize.mjs +55 -2
  307. package/skills/a2h-page-specgen/scripts/footprint.mjs +129 -2
  308. package/skills/a2h-page-specgen/scripts/gate.mjs +20 -11
  309. package/skills/a2h-page-specgen/scripts/lib/contracts.mjs +56 -3
  310. package/skills/a2h-page-specgen/scripts/lib/graph-evidence.mjs +27 -0
  311. package/skills/a2h-page-specgen/scripts/lib/hg.mjs +114 -5
  312. package/skills/a2h-page-specgen/scripts/lib/ledger.mjs +20 -3
  313. package/skills/a2h-page-specgen/scripts/operation-evidence.mjs +270 -29
  314. package/skills/a2h-page-specgen/scripts/prepare.mjs +25 -14
  315. package/skills/a2h-page-specgen/scripts/report.mjs +26 -5
  316. package/skills/a2h-page-specgen/scripts/submission.mjs +69 -2
  317. package/skills/a2h-page-specgen/scripts/submit.mjs +105 -4
  318. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md +110 -18
  319. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md +97 -12
  320. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.prompt.md +110 -18
  321. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.worker.md +97 -12
  322. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.discovery.json +224 -224
  323. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.json +1 -1
  324. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.post-review.json +2 -2
  325. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.prompt.md +110 -18
  326. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.worker.md +97 -12
  327. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.prompt.md +110 -18
  328. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.worker.md +97 -12
  329. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/run.mjs +153 -3
  330. package/skills/a2h-page-specgen/scripts/test/android-operation-evidence.test.mjs +529 -1
  331. package/skills/a2h-page-specgen/scripts/test/behavior-audit-pre.test.mjs +27 -0
  332. package/skills/a2h-page-specgen/scripts/test/behavior-discovery.test.mjs +158 -0
  333. package/skills/a2h-page-specgen/scripts/test/behavior-fixtures.mjs +11 -13
  334. package/skills/a2h-page-specgen/scripts/test/behavior-reconcile.test.mjs +97 -0
  335. package/skills/a2h-page-specgen/scripts/test/contract-calls.test.mjs +737 -0
  336. package/skills/a2h-page-specgen/scripts/test/contracts.test.mjs +82 -3
  337. package/skills/a2h-page-specgen/scripts/test/finalize.test.mjs +24 -0
  338. package/skills/a2h-page-specgen/scripts/test/fixtures/hg.mkdb.mjs +11 -0
  339. package/skills/a2h-page-specgen/scripts/test/footprint-resolve.test.mjs +6 -2
  340. package/skills/a2h-page-specgen/scripts/test/gate.test.mjs +94 -1
  341. package/skills/a2h-page-specgen/scripts/test/graph-evidence.test.mjs +32 -0
  342. package/skills/a2h-page-specgen/scripts/test/hg.test.mjs +14 -0
  343. package/skills/a2h-page-specgen/scripts/test/ledger.test.mjs +49 -1
  344. package/skills/a2h-page-specgen/scripts/test/operation-reviews.test.mjs +6 -1
  345. package/skills/a2h-page-specgen/scripts/test/prompt-tpl.test.mjs +12 -4
  346. package/skills/a2h-page-specgen/scripts/test/protocol-docs.test.mjs +1 -1
  347. package/skills/a2h-page-specgen/scripts/test/recovery-e2e.test.mjs +1 -0
  348. package/skills/a2h-page-specgen/scripts/test/report.test.mjs +80 -1
  349. package/skills/a2h-page-specgen/scripts/test/submit.test.mjs +159 -27
  350. package/skills/a2h-page-specgen/scripts/test/waker-process.test.mjs +23 -0
  351. package/skills/a2h-page-specgen/scripts/waker.mjs +8 -1
  352. package/skills/a2h-resource-convert/SKILL.md +1 -1
  353. package/skills/a2h-resource-convert/data/framework-strings/NOTICE +10 -0
  354. package/skills/a2h-resource-convert/data/framework-strings/manifest.json +90 -0
  355. package/skills/a2h-resource-convert/data/framework-strings/strings.json +382 -0
  356. package/skills/a2h-resource-convert/references/conversion-rules.md +7 -1
  357. package/skills/a2h-resource-convert/references/lottie-conversion-rules.md +2 -2
  358. package/skills/a2h-resource-convert/references/step5-reference-resolution.md +16 -0
  359. package/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +124 -8
  360. package/skills/a2h-resource-convert/scripts/sync-framework-strings.mjs +147 -0
  361. package/skills/a2h-resource-convert/scripts/tests/framework_strings.test.mjs +131 -0
  362. package/skills/a2h-spec-design-pipeline/SKILL.md +14 -11
  363. package/skills/a2h-spec-design-pipeline/references/coding-loop.md +38 -10
  364. package/skills/a2h-spec-design-pipeline/references/execution-model.md +3 -0
  365. package/skills/a2h-spec-design-pipeline/references/final-report-template.md +6 -3
  366. package/skills/a2h-spec-design-pipeline/references/initialization.md +2 -2
  367. package/skills/a2h-spec-design-pipeline/references/post-loop.md +2 -2
  368. package/skills/a2h-spec-design-pipeline/references/reply-recovery.md +172 -0
  369. package/skills/a2h-spec-design-pipeline/references/review-loop.md +2 -2
  370. package/skills/a2h-spec-design-pipeline/references/scripts.md +4 -3
  371. package/skills/a2h-spec-design-pipeline/references/shared-layer.md +24 -19
  372. package/skills/a2h-spec-design-pipeline/references/state-and-resume.md +7 -1
  373. package/skills/a2h-spec-design-pipeline/references/static-defect-gate.md +12 -5
  374. package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleMeta.json +5 -0
  375. package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleSet.json +4 -0
  376. package/skills/a2h-spec-design-pipeline/rules/migration-rules/data/README.md +27 -3
  377. package/skills/a2h-spec-design-pipeline/rules/migration-rules/data/api-param-contract.json +46 -1
  378. package/skills/a2h-spec-design-pipeline/rules/migration-rules/data/api-permission-map.json +2511 -295
  379. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/api-permission-declared-cn.md +27 -72
  380. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/api-permission-declared-en.md +39 -83
  381. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-runtime-pitfall-cn.md +132 -101
  382. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-runtime-pitfall-en.md +158 -115
  383. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/platform-api-contract-cn.md +60 -93
  384. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/platform-api-contract-en.md +73 -100
  385. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/route-page-side-effect-import-cn.md +52 -0
  386. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/route-page-side-effect-import-en.md +59 -0
  387. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/ApiPermissionDeclaredCheck.js +57 -8
  388. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/ArkUIRuntimePitfallCheck.js +475 -18
  389. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/PlatformApiContractCheck.js +472 -4
  390. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/RoutePageSideEffectImportCheck.js +570 -0
  391. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/arkui/RouteParamCarrierSubCheck.js +1053 -0
  392. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/sql/SqlIdentifierAnalysis.js +427 -0
  393. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/index.js +7 -1
  394. package/skills/a2h-spec-design-pipeline/rules/migration-rules/package.json +1 -1
  395. package/skills/a2h-spec-design-pipeline/scripts/plan_groups.ts +1 -1
  396. package/skills/a2h-spec-design-pipeline/scripts/settle.ts +785 -0
  397. package/skills/a2h-spec-design-pipeline/scripts/test_api_permission_declared.ts +286 -0
  398. package/skills/a2h-spec-design-pipeline/scripts/test_arkui_runtime_pitfall.ts +166 -2
  399. package/skills/a2h-spec-design-pipeline/scripts/test_docs_refresh_contract.ts +40 -0
  400. package/skills/a2h-spec-design-pipeline/scripts/test_plan_groups.ts +2 -0
  401. package/skills/a2h-spec-design-pipeline/scripts/test_platform_api_contract.ts +350 -7
  402. package/skills/a2h-spec-design-pipeline/scripts/test_route_page_side_effect_import.ts +185 -0
  403. package/skills/a2h-spec-design-pipeline/scripts/test_route_param_carrier.ts +341 -0
  404. package/skills/a2h-spec-design-pipeline/scripts/test_settle.ts +593 -0
  405. package/skills/a2h-spec-design-pipeline/scripts/test_shared_layer_docs.ts +92 -1
  406. package/skills/a2h-spec-design-pipeline/scripts/test_sql_identifier_analysis.ts +137 -0
  407. package/skills/a2h-spec-generate/references/input-formats.md +1 -1
  408. package/skills/a2h-utg-explorer/SKILL.md +11 -5
  409. package/skills/a2h-utg-explorer/references/architecture.md +37 -19
  410. package/skills/a2h-utg-explorer/scripts/audit.mjs +6 -2
  411. package/skills/a2h-utg-explorer/scripts/close_phases.mjs +8 -5
  412. package/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +95 -19
  413. package/skills/a2h-utg-explorer/scripts/d_prereqs.mjs +192 -4
  414. package/skills/a2h-utg-explorer/scripts/final_utg.mjs +21 -0
  415. package/skills/a2h-utg-explorer/scripts/panel_routes.mjs +1 -1
  416. package/skills/a2h-utg-explorer/scripts/plan.mjs +16 -1
  417. package/skills/a2h-utg-explorer/scripts/predicates.mjs +270 -0
  418. package/skills/a2h-utg-explorer/scripts/promote_dynamic.mjs +2 -0
  419. package/skills/a2h-utg-explorer/scripts/recover.mjs +4 -3
  420. package/skills/a2h-utg-explorer/scripts/recover_d.mjs +67 -8
  421. package/skills/a2h-utg-explorer/scripts/rejudge.mjs +4 -3
  422. package/skills/a2h-utg-explorer/scripts/report.mjs +32 -2
  423. package/skills/a2h-utg-explorer/scripts/run_cycle.mjs +103 -36
  424. package/skills/a2h-utg-explorer/scripts/run_device.mjs +3 -8
  425. package/skills/a2h-utg-explorer/scripts/schedule_states.mjs +189 -0
  426. package/skills/a2h-utg-explorer/scripts/tests/calendar_round_fixes.test.mjs +9 -0
  427. package/skills/a2h-utg-explorer/scripts/tests/coverage_rules.test.mjs +11 -0
  428. package/skills/a2h-utg-explorer/scripts/tests/d_prereqs.test.mjs +31 -2
  429. package/skills/a2h-utg-explorer/scripts/tests/device_lock_retry.test.mjs +1 -1
  430. package/skills/a2h-utg-explorer/scripts/tests/diagnostics.test.mjs +32 -0
  431. package/skills/a2h-utg-explorer/scripts/tests/dialog_own_layout.test.mjs +40 -0
  432. package/skills/a2h-utg-explorer/scripts/tests/explorer_review_fixes.test.mjs +4 -1
  433. package/skills/a2h-utg-explorer/scripts/tests/hybrid_route.test.mjs +6 -28
  434. package/skills/a2h-utg-explorer/scripts/tests/in_route_surface.test.mjs +125 -0
  435. package/skills/a2h-utg-explorer/scripts/tests/list_probe_target_wait.test.mjs +86 -0
  436. package/skills/a2h-utg-explorer/scripts/tests/multi_host.test.mjs +167 -0
  437. package/skills/a2h-utg-explorer/scripts/tests/nested_list.test.mjs +58 -0
  438. package/skills/a2h-utg-explorer/scripts/tests/overlay_opener.test.mjs +100 -0
  439. package/skills/a2h-utg-explorer/scripts/tests/pipeline.test.mjs +8 -1
  440. package/skills/a2h-utg-explorer/scripts/tests/pr169_review_fixes.test.mjs +1 -0
  441. package/skills/a2h-utg-explorer/scripts/tests/pr191_review_fixes.test.mjs +2 -31
  442. package/skills/a2h-utg-explorer/scripts/tests/review_fixes.test.mjs +1 -1
  443. package/skills/a2h-utg-explorer/scripts/tests/run_cycle.test.mjs +56 -7
  444. package/skills/a2h-utg-explorer/scripts/tests/snapshot_integrity.test.mjs +117 -6
  445. package/skills/a2h-utg-explorer/scripts/tests/state_inventory.test.mjs +414 -0
  446. package/skills/a2h-utg-explorer/scripts/tests/tree_unreliable.test.mjs +197 -0
  447. package/skills/a2h-utg-explorer/scripts/utg_explorer/adapters.mjs +196 -30
  448. package/skills/a2h-utg-explorer/scripts/utg_explorer/hosts.mjs +146 -0
  449. package/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +63 -2
  450. package/skills/a2h-utg-explorer/scripts/utg_explorer/states.mjs +286 -0
  451. package/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +197 -19
  452. package/skills/a2h-utg-static/SKILL.md +3 -3
  453. package/skills/a2h-utg-static/references/extractors.md +7 -0
  454. package/skills/a2h-utg-static/references/ui-elements-static-utg-schema.md +4 -3
  455. package/skills/a2h-utg-static/scripts/click_paths.mjs +1 -1
  456. package/skills/a2h-utg-static/scripts/compose_overlay.mjs +642 -22
  457. package/skills/a2h-utg-static/scripts/tests/test_compose_res_text.mjs +25 -0
  458. package/skills/a2h-utg-static/scripts/tests/test_in_route_surface.mjs +123 -0
  459. package/skills/a2h-utg-static/scripts/tests/test_overlay_host_effects.mjs +239 -0
  460. package/skills/a2h-utg-static/scripts/tests/test_shared_host_depths.mjs +48 -0
  461. package/skills/a2h-utg-static/scripts/utg_html.mjs +2 -0
  462. package/skills/a2h-utg-static/tools/convert_static_utg_to_ui_elements.ts +1 -0
  463. package/i18n/skills/a2h-app-migrate/references/specs.example.json +0 -19
  464. package/i18n/skills/a2h-batch-ui-align/scripts/databinding_analyzer_design.md +0 -79
  465. package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/state_phase.mjs +0 -47
  466. package/resource/convert_pipeline_process.svg +0 -114
  467. package/resource/project_architecture.svg +0 -120
  468. package/resource/set_environment.png +0 -0
  469. package/resource/set_multimodel.png +0 -0
  470. package/skills/a2h-app-migrate/references/specs.example.json +0 -19
  471. package/skills/a2h-batch-ui-align/scripts/databinding_analyzer_design.md +0 -79
  472. package/skills/a2h-utg-explorer/scripts/utg_explorer/state_phase.mjs +0 -47
@@ -24,6 +24,7 @@
24
24
  import * as fs from 'node:fs';
25
25
  import * as os from 'node:os';
26
26
  import { fileURLToPath } from 'node:url';
27
+ import { inflateSync } from 'node:zlib';
27
28
  import { spawnSync } from 'node:child_process';
28
29
  import {
29
30
  get, mget, truthy, or, pyStr, pyIn, pyEq, pyRepr, pyRe, reFindall, reFullmatch, pyInt, toInt, toFloat, fmtFixed,
@@ -116,6 +117,11 @@ function walkTar(length, block, want) {
116
117
  return missing.length ? `tar archive lacks ${missing.join(', ')}` : null;
117
118
  }
118
119
 
120
+ /** Data-dir entries no snapshot archives or restore clears (see DeviceAdapter.appDataEntries). */
121
+ export const APP_DATA_SKIP = new Set(['.', '..', 'cache', 'code_cache', 'lib', '.utg_restore', '.utg_restore.ok']);
122
+ /** restore_app_data unpacks here, inside the app's data dir, before it replaces anything. */
123
+ const RESTORE_STAGE = '.utg_restore';
124
+
119
125
  /** AdapterError (RuntimeError subclass in Python): str(exc) is the message. */
120
126
  export class AdapterError extends Error {
121
127
  constructor(message = '') { super(String(message)); this.name = 'AdapterError'; }
@@ -251,6 +257,17 @@ export function matching(nodes, selector) {
251
257
  }
252
258
 
253
259
  /** rule_matches(observation, rule): positive evidence required; absence alone proves nothing. */
260
+ /**
261
+ * No app-data wipe while the data the device was handed over with could not be archived:
262
+ * d_prereqs.mjs initial sets config.user_state_protected when run-as is unavailable, and a
263
+ * clear or restore would then lose the user's login and content for good (states.mjs).
264
+ */
265
+ export function assertDataChangeAllowed(config, kind) {
266
+ if (get(config, 'user_state_protected') === true) {
267
+ throw new AdapterError(`user-state-protected: ${kind} refused; the device's original app data could not be archived (no run-as), so it would be lost`);
268
+ }
269
+ }
270
+
254
271
  export function ruleMatches(observation, rule) {
255
272
  if (!(truthy(get(rule, 'activity')) || truthy(get(rule, 'all')) || truthy(get(rule, 'any')))) { return false; }
256
273
  if (truthy(get(rule, 'activity')) && get(observation, 'activity') !== rule.activity) { return false; }
@@ -658,60 +675,78 @@ export function imeSwitcherFocus(dump) {
658
675
  return !!m && /^(?:IME Switcher Menu|Select input method|Choose input method)$/i.test(m[1].trim());
659
676
  }
660
677
 
678
+ /** Visible nodes (`visible-to-user="true"`, or no such attribute) in a slice of dump XML. */
679
+ const visibleInXml = (xml) => [...xml.matchAll(/<node\b[^>]*>/g)].filter((m) => !/visible-to-user="false"/.test(m[0])).length;
680
+
661
681
  /**
662
682
  * The all-windows hierarchy `xml` cut to its first (topmost) window root owned by `pkg`, or null.
663
- * Root order is the server's window order, topmost first.
683
+ * Root order is the server's window order, topmost first. `skipEmpty`: a root with fewer than
684
+ * MIN_VISIBLE_APP_NODES visible nodes (an app window that draws nothing: a leftover, never-shown
685
+ * root) yields to the next app root; the first app root is still returned when every one is empty.
664
686
  */
665
- export function topWindowOf(xml, pkg) {
687
+ export function topWindowOf(xml, pkg, { skipEmpty = false } = {}) {
666
688
  const text = pyStr(xml);
667
689
  const open = text.indexOf('<hierarchy');
668
690
  if (open < 0) { return null; }
669
691
  const headEnd = text.indexOf('>', open) + 1;
670
692
  const re = /<(\/?)node\b([^>]*?)(\/?)>/g;
671
693
  re.lastIndex = headEnd;
672
- let depth = 0; let start = -1; let m;
694
+ let depth = 0; let start = -1; let m; let fallback = null;
695
+ const take = (slice) => {
696
+ const cut = text.slice(0, headEnd) + slice + '</hierarchy>';
697
+ if (!skipEmpty || visibleInXml(slice) >= MIN_VISIBLE_APP_NODES) { return cut; }
698
+ fallback ??= cut; return null;
699
+ };
673
700
  while ((m = re.exec(text)) !== null) {
674
701
  if (m[1]) {
675
702
  depth--;
676
- if (depth === 0 && start >= 0) { return text.slice(0, headEnd) + text.slice(start, re.lastIndex) + '</hierarchy>'; }
703
+ if (depth === 0 && start >= 0) { const cut = take(text.slice(start, re.lastIndex)); if (cut) { return cut; } start = -1; }
677
704
  continue;
678
705
  }
679
- if (depth === 0 && start < 0 && m[2].includes(`package="${pkg}"`)) { start = m.index; if (m[3]) { return text.slice(0, headEnd) + m[0] + '</hierarchy>'; } }
706
+ if (depth === 0 && start < 0 && m[2].includes(`package="${pkg}"`)) {
707
+ if (m[3]) { const cut = take(m[0]); if (cut) { return cut; } continue; }
708
+ start = m.index;
709
+ }
680
710
  if (!m[3]) { depth++; }
681
711
  }
682
- return null;
712
+ return fallback;
683
713
  }
684
714
 
685
715
  /**
686
716
  * `uiautomator dump --windows` output (`<window>` → `<hierarchy>` → root `<node>`, windows in
687
717
  * z-order, topmost first, child windows nested in their parent) cut to the first window root
688
718
  * owned by `pkg`, as a plain one-window hierarchy; null when no window root is the app's.
719
+ * `skipEmpty` as topWindowOf.
689
720
  */
690
- export function topWindowOfWindows(xml, pkg) {
721
+ export function topWindowOfWindows(xml, pkg, { skipEmpty = false } = {}) {
691
722
  const text = pyStr(xml);
692
723
  const re = /<(\/?)(window|hierarchy|node)\b([^>]*?)(\/?)>/g;
693
- const stack = []; let start = -1; let rootDepth = -1; let m;
724
+ const head = '<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\' ?><hierarchy rotation="0">';
725
+ const stack = []; let start = -1; let rootDepth = -1; let m; let fallback = null;
726
+ const take = (slice) => {
727
+ const cut = head + slice + '</hierarchy>';
728
+ if (!skipEmpty || visibleInXml(slice) >= MIN_VISIBLE_APP_NODES) { return cut; }
729
+ fallback ??= cut; return null;
730
+ };
694
731
  while ((m = re.exec(text)) !== null) {
695
732
  const [, closing, tag, attrs, selfClosing] = m;
696
733
  if (closing) {
697
734
  stack.pop();
698
735
  if (start >= 0 && tag === 'node' && stack.length === rootDepth) {
699
- return '<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\' ?><hierarchy rotation="0">'
700
- + text.slice(start, re.lastIndex) + '</hierarchy>';
736
+ const cut = take(text.slice(start, re.lastIndex)); if (cut) { return cut; }
737
+ start = -1;
701
738
  }
702
739
  continue;
703
740
  }
704
741
  const isRoot = tag === 'node' && stack.length >= 2 && stack[stack.length - 1] === 'hierarchy'
705
742
  && stack[stack.length - 2] === 'window';
706
743
  if (start < 0 && isRoot && attrs.includes(`package="${pkg}"`)) {
707
- if (selfClosing) {
708
- return '<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\' ?><hierarchy rotation="0">' + m[0] + '</hierarchy>';
709
- }
744
+ if (selfClosing) { const cut = take(m[0]); if (cut) { return cut; } continue; }
710
745
  start = m.index; rootDepth = stack.length;
711
746
  }
712
747
  if (!selfClosing) { stack.push(tag); }
713
748
  }
714
- return null;
749
+ return fallback;
715
750
  }
716
751
 
717
752
  const LIVE_PIDS = new Set();
@@ -762,6 +797,62 @@ export function canonicalComponent(component) {
762
797
  const f0 = (x) => fmtFixed(x, 0);
763
798
  const floorDiv = (a, b) => Math.floor(a / b);
764
799
  const PNG_MAGIC = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
800
+
801
+ /** Share of sampled pixels in one colour at or above which a screenshot is blank (pngUniform). */
802
+ export const BLANK_PNG_SHARE = 0.98;
803
+
804
+ /**
805
+ * pngUniform(png, share = BLANK_PNG_SHARE) -> true when the screenshot is (nearly) one colour, false
806
+ * when it shows content, null when it cannot be read (not 8-bit RGB/RGBA/grey, interlaced, corrupt).
807
+ * Samples every 8th pixel of every 8th row; the status-bar icons stay under 2%.
808
+ */
809
+ export function pngUniform(png, share = BLANK_PNG_SHARE) {
810
+ try {
811
+ if (!Buffer.isBuffer(png) || png.length < 33 || !png.subarray(0, 8).equals(PNG_MAGIC)) { return null; }
812
+ let at = 8; let w = 0; let h = 0; let ch = 0; const idat = [];
813
+ while (at + 8 <= png.length) {
814
+ const len = png.readUInt32BE(at); const type = png.toString('latin1', at + 4, at + 8); const body = png.subarray(at + 8, at + 8 + len);
815
+ if (type === 'IHDR') {
816
+ w = body.readUInt32BE(0); h = body.readUInt32BE(4);
817
+ ch = { 0: 1, 2: 3, 4: 2, 6: 4 }[body[9]] ?? 0;
818
+ if (body[8] !== 8 || body[12] !== 0 || !ch) { return null; }
819
+ } else if (type === 'IDAT') { idat.push(body); } else if (type === 'IEND') { break; }
820
+ at += 12 + len;
821
+ }
822
+ if (!w || !h) { return null; }
823
+ const raw = inflateSync(Buffer.concat(idat)); const stride = w * ch;
824
+ let prev = Buffer.alloc(stride); const counts = new Map(); let total = 0;
825
+ for (let y = 0; y < h; y++) {
826
+ const ft = raw[y * (stride + 1)]; const line = raw.subarray(y * (stride + 1) + 1, (y + 1) * (stride + 1)); const cur = Buffer.alloc(stride);
827
+ for (let x = 0; x < stride; x++) {
828
+ const a = x >= ch ? cur[x - ch] : 0; const b = prev[x]; const c = x >= ch ? prev[x - ch] : 0;
829
+ const p = a + b - c; const pa = Math.abs(p - a); const pb = Math.abs(p - b); const pc = Math.abs(p - c);
830
+ const pred = ft === 1 ? a : ft === 2 ? b : ft === 3 ? (a + b) >> 1 : ft === 4 ? (pa <= pb && pa <= pc ? a : pb <= pc ? b : c) : 0;
831
+ cur[x] = (line[x] + pred) & 0xff;
832
+ }
833
+ prev = cur;
834
+ if (y % 8) { continue; }
835
+ for (let x = 0; x < w; x += 8) {
836
+ const k = cur.toString('latin1', x * ch, x * ch + Math.min(ch, 3));
837
+ counts.set(k, (counts.get(k) ?? 0) + 1); total += 1;
838
+ }
839
+ }
840
+ return total > 0 && Math.max(...counts.values()) / total >= share;
841
+ } catch { return null; }
842
+ }
843
+
844
+ /** Fewest visible app nodes a dump needs before its tree is taken to show the screen (sparseAppTree). */
845
+ export const MIN_VISIBLE_APP_NODES = 2;
846
+ /**
847
+ * sparseAppTree(nodes, pkg): the dump holds no usable view of the app: fewer than
848
+ * MIN_VISIBLE_APP_NODES visible nodes of `pkg` (only a root, or every node visible-to-user="false").
849
+ * A Compose `Popup` / `Dialog` is a window of its own; a dump of the wrong (or not yet laid out)
850
+ * window looks like this while the screenshot shows the popup.
851
+ */
852
+ export function sparseAppTree(nodes, pkg) {
853
+ const own = (nodes || []).filter((n) => truthy(get(n, 'visible', true)) && (!truthy(pkg) || !truthy(get(n, 'package')) || get(n, 'package') === pkg));
854
+ return own.length < MIN_VISIBLE_APP_NODES;
855
+ }
765
856
  const LIVE_SHELLS = new Set();
766
857
  process.on('exit', () => killPidsSync([...LIVE_SHELLS]));
767
858
  // Ctrl+C / kill: exit through process.exit so the 'exit' handlers above (shells, u2 server,
@@ -801,6 +892,17 @@ export class DeviceAdapter {
801
892
  return proc.returncode === 0 && proc.stdout.includes('uid=');
802
893
  }
803
894
 
895
+ /**
896
+ * Top-level entries of the app's data dir (run-as), less what is rebuilt or not the app's:
897
+ * cache, code_cache, and the lib symlink to the native libraries. [] when the app never ran.
898
+ */
899
+ appDataEntries() {
900
+ const pkg = get(this.config, 'package');
901
+ if (!truthy(pkg)) { throw new AdapterError('appDataEntries requires config.package'); }
902
+ return this._shell('run-as', pkg, 'ls', '-a').split(/\r?\n/).map((s) => s.trim())
903
+ .filter((s) => s && !APP_DATA_SKIP.has(s) && reFullmatch(pyRe('[\\w.-]+'), s));
904
+ }
905
+
804
906
  /** _run(args, binary=False): one-shot command; device-timeout / stderr tail as AdapterError. */
805
907
  _run(args, binary = false) {
806
908
  if (binary && typeof binary === 'object') { binary = !!binary.binary; }
@@ -970,11 +1072,11 @@ export class DeviceAdapter {
970
1072
  }
971
1073
 
972
1074
  /** _dump_uiautomator(tree, expected_component, popup_pkg=null) -> root Element (bounded retry). */
973
- _dumpUiautomator(tree, expectedComponent, popupPkg = null) {
1075
+ _dumpUiautomator(tree, expectedComponent, popupPkg = null, { skipEmpty = false } = {}) {
974
1076
  const attempts = Math.max(1, toInt(get(this.config, 'ui_dump_retries', get(this.config, 'uiautomator_dump_retries', 3))));
975
1077
  const settle = Math.max(0.0, toFloat(get(this.config, 'ui_dump_retry_settle_seconds', get(this.config, 'settle_seconds', 0.3))));
976
1078
  let last = null;
977
- if (get(this.config, 'layout_backend') === 'u2') { return this._dumpU2(tree, expectedComponent, attempts, settle, popupPkg); }
1079
+ if (get(this.config, 'layout_backend') === 'u2') { return this._dumpU2(tree, expectedComponent, attempts, settle, popupPkg, { skipEmpty }); }
978
1080
  if (truthy(get(this.config, 'ui_dump_stream', false))) {
979
1081
  try {
980
1082
  const raw = this._run([...this.adb, 'exec-out', 'uiautomator', 'dump', '/dev/tty'], true);
@@ -1021,7 +1123,7 @@ export class DeviceAdapter {
1021
1123
  continue;
1022
1124
  }
1023
1125
  if (allWindows) {
1024
- const cut = topWindowOfWindows(readText(tree, { encoding: 'utf-8', errors: 'replace' }), popupPkg);
1126
+ const cut = topWindowOfWindows(readText(tree, { encoding: 'utf-8', errors: 'replace' }), popupPkg, { skipEmpty });
1025
1127
  if (cut !== null) { writeText(tree, cut); }
1026
1128
  }
1027
1129
  try { root = etParse(tree); } catch (e) {
@@ -1064,12 +1166,12 @@ export class DeviceAdapter {
1064
1166
  * the active-window dump never contains) all windows are dumped and the app's topmost window
1065
1167
  * kept: the server lists windows top-first.
1066
1168
  */
1067
- _dumpU2(tree, expectedComponent, attempts, settle, popupPkg = null) {
1169
+ _dumpU2(tree, expectedComponent, attempts, settle, popupPkg = null, { skipEmpty = false } = {}) {
1068
1170
  let last = null;
1069
1171
  for (let attempt = 0; attempt < attempts; attempt++) {
1070
1172
  try {
1071
1173
  let xml = this._u2Device().dumpHierarchy({ compressed: false, root_in_active: popupPkg === null });
1072
- if (popupPkg !== null) { xml = topWindowOf(xml, popupPkg) ?? this._u2Device().dumpHierarchy({ compressed: false, root_in_active: true }); }
1174
+ if (popupPkg !== null) { xml = topWindowOf(xml, popupPkg, { skipEmpty }) ?? this._u2Device().dumpHierarchy({ compressed: false, root_in_active: true }); }
1073
1175
  writeText(tree, xml);
1074
1176
  return etParse(tree);
1075
1177
  } catch (e) {
@@ -1143,6 +1245,34 @@ export class DeviceAdapter {
1143
1245
  const png = this._screenshot();
1144
1246
  if (!(png.length >= 8 && png.subarray(0, 8).equals(PNG_MAGIC))) { throw new AdapterError('Device returned an invalid PNG'); }
1145
1247
  fs.writeFileSync(screenshot, png);
1248
+ // A dump with no usable view of the app under a screenshot that shows something: the dump caught
1249
+ // the wrong window or one not laid out yet (a Compose Popup / Dialog is a window of its own; measured
1250
+ // on a Compose app: 22 popup captures held only an invisible root FrameLayout). Dump every window
1251
+ // once more after a settle, keeping the app's topmost window that draws something (an empty
1252
+ // root yields to the next app window only when dumpsys shows no app popup window it could be),
1253
+ // and use that tree when it shows more. Still empty: `tree_unreliable`, never a new page.
1254
+ let treeUnreliable = null; let redump = null;
1255
+ if (sparseAppTree(nodes, pkg) && pngUniform(png) === false) {
1256
+ if (tree.endsWith('.xml') && get(this.config, 'tree_redump', true) !== false) {
1257
+ const first = fs.existsSync(tree) ? fs.readFileSync(tree) : null;
1258
+ const restore = () => { if (first !== null) { fs.writeFileSync(tree, first); } };
1259
+ const shown = (ns) => ns.filter((n) => truthy(get(n, 'visible', true)) && (!truthy(get(n, 'package')) || get(n, 'package') === pkg)).length;
1260
+ try {
1261
+ time.sleep(Math.max(0.0, toFloat(get(this.config, 'tree_redump_settle_seconds', 0.5))));
1262
+ const root = this._dumpUiautomator(tree, component, pkg, { skipEmpty: !appPopupWindow(focus, pkg) });
1263
+ const convert = (el) => { const d = {}; for (const k of keysOf(el.attrib)) { dset(d, k, el.attrib[k]); } d.children = el.children.map(convert); return d; };
1264
+ const again = normalizeNodes(root.children.map(convert));
1265
+ if (shown(again) > shown(nodes)) { nodes = again; redump = 'all-windows'; } else { restore(); }
1266
+ } catch (e) {
1267
+ if (!(e instanceof AdapterError)) { throw e; }
1268
+ restore();
1269
+ }
1270
+ }
1271
+ // Only once the app has shown a usable tree this session: an app whose tree never carries
1272
+ // views (a canvas, Flutter without semantics) stays as it was.
1273
+ if (sparseAppTree(nodes, pkg) && this._appShowedTree) { treeUnreliable = 'no-visible-app-node'; }
1274
+ }
1275
+ if (!sparseAppTree(nodes, pkg)) { this._appShowedTree = true; }
1146
1276
  const [finalComponent, finalFocus] = this._foreground();
1147
1277
  // Spelling aside (canonicalComponent), focus landing or leaving mid-capture is a change too: the
1148
1278
  // dump may show the window before the switch and the screenshot the one after it.
@@ -1159,6 +1289,8 @@ export class DeviceAdapter {
1159
1289
  if (shown !== pkg) { result.component_package = pkg; }
1160
1290
  if (secureFocus(focus)) { result.screen_blocked = 'flag-secure'; }
1161
1291
  if (imeSwitcherDismissed) { result.ime_switcher_dismissed = imeSwitcherDismissed; }
1292
+ if (redump) { result.tree_redump = redump; }
1293
+ if (treeUnreliable) { result.tree_unreliable = treeUnreliable; }
1162
1294
  result.identity = resolveIdentity(result, this.config);
1163
1295
  writeJson(pJoin(capture, 'observation.json'), result);
1164
1296
  return result;
@@ -1281,13 +1413,15 @@ export class DeviceAdapter {
1281
1413
  throw new AdapterError('snapshot_app_data needs config.package, config.snapshot_dir and a .tar inside it');
1282
1414
  }
1283
1415
  if (fs.existsSync(archive)) { throw new AdapterError('snapshot archive already exists; never overwrite a fixture: ' + archive); }
1284
- const wanted = get(action, 'dirs', ['databases', 'shared_prefs', 'files']).filter((d) => reFullmatch(pyRe('[\\w.-]+'), pyStr(d)));
1285
1416
  this._shell('am', 'force-stop', pkg);
1286
- // Only the dirs the app has (many never write shared_prefs), and tar's stderr kept out of
1287
- // the archive: exec-out puts it in the same stream (see tarProblem).
1288
- const present = new Set(this._shell('run-as', pkg, 'ls', '-a').split(/\r?\n/).map((s) => s.trim()));
1289
- const dirs = wanted.filter((d) => present.has(d));
1290
- if (!dirs.length) { throw new AdapterError(`snapshot_app_data failed: ${pkg} has none of ${wanted.join(', ')}`); }
1417
+ // Every top-level entry of the data dir by default (app_webview, no_backup, app_flutter hold
1418
+ // logins too), or `dirs` when given; only what the app has, and tar's stderr kept out of the
1419
+ // archive: exec-out puts it in the same stream (see tarProblem).
1420
+ const present = this.appDataEntries();
1421
+ const given = get(action, 'dirs', null);
1422
+ const wanted = Array.isArray(given) ? given.filter((d) => reFullmatch(pyRe('[\\w.-]+'), pyStr(d))) : present;
1423
+ const dirs = wanted.filter((d) => present.includes(d));
1424
+ if (!dirs.length) { throw new AdapterError(`snapshot_app_data failed: ${pkg} has ${Array.isArray(given) ? 'none of ' + wanted.join(', ') : 'no app data'}`); }
1291
1425
  const proc = subprocessRun([...this.adb, 'exec-out',
1292
1426
  `run-as ${shlexQuote(pkg)} tar -cf - ${dirs.map((d) => shlexQuote(d)).join(' ')} 2>/dev/null`], { timeout: this.timeout });
1293
1427
  const bad = proc.returncode ? 'adb exit ' + proc.returncode : tarProblem(proc.stdout, dirs);
@@ -1297,6 +1431,7 @@ export class DeviceAdapter {
1297
1431
  pMkdir(pParent(archive), { parents: true, exist_ok: true });
1298
1432
  fs.writeFileSync(archive, proc.stdout);
1299
1433
  } else if (kind === 'clear_app_data') {
1434
+ assertDataChangeAllowed(this.config, kind);
1300
1435
  const pkg = get(this.config, 'package');
1301
1436
  if (!truthy(pkg)) { throw new AdapterError('clear_app_data requires config.package'); }
1302
1437
  const out = this._shell('pm', 'clear', pkg);
@@ -1311,6 +1446,7 @@ export class DeviceAdapter {
1311
1446
  writeText(archive, jsonDumps({ schema: 'utg-replay/1', package: get(this.config, 'package'),
1312
1447
  steps: get(action, 'steps', []), from: get(action, 'from') }, { ensure_ascii: false, indent: 1 }));
1313
1448
  } else if (kind === 'restore_app_data') {
1449
+ assertDataChangeAllowed(this.config, kind);
1314
1450
  const pkg = get(this.config, 'package');
1315
1451
  const archive = pathStr(get(action, 'archive', ''));
1316
1452
  if (!truthy(pkg) || !pIsFile(archive)) { throw new AdapterError('restore_app_data requires config.package and an existing archive'); }
@@ -1320,12 +1456,42 @@ export class DeviceAdapter {
1320
1456
  const bad = tarProblem(data);
1321
1457
  if (bad) { throw new AdapterError(`restore_app_data failed: ${bad} in ${archive}; delete it so it is taken again`); }
1322
1458
  this._shell('am', 'force-stop', pkg);
1323
- const dirs = get(action, 'clear_dirs', []).filter((d) => reFullmatch(pyRe('[\\w.-]+'), pyStr(d)));
1324
- if (dirs.length) {
1325
- this._run([...this.adb, 'shell', 'run-as ' + shlexQuote(pkg) + ' rm -rf ' + dirs.map((d) => shlexQuote(d)).join(' ')]);
1459
+ const cd = get(action, 'clear_dirs', []);
1460
+ const dirs = (cd === 'all' ? this.appDataEntries() : (Array.isArray(cd) ? cd : []))
1461
+ .filter((d) => reFullmatch(pyRe('[\\w.-]+'), pyStr(d)));
1462
+ // Unpacked into a staging dir first and swapped in only then: removing the data before an unpack
1463
+ // that times out (a few hundred MB on command_timeout) left the device with no data at all.
1464
+ // exec-in does not return the device-side tar's status, so tar itself leaves a sentinel next to the
1465
+ // staging dir when it exits 0: a partial unpack (disk full, a bad block) has none and is discarded.
1466
+ const stage = RESTORE_STAGE;
1467
+ const ok = `${RESTORE_STAGE}.ok`;
1468
+ const runAs = (script) => [...this.adb, 'shell', `run-as ${shlexQuote(pkg)} sh -c ${shlexQuote(script)}`];
1469
+ const discard = () => { try { this._run(runAs(`rm -rf ${stage} ${ok}`)); } catch { /* best effort */ } };
1470
+ this._run(runAs(`rm -rf ${stage} ${ok} && mkdir ${stage}`));
1471
+ // config.restore_base_timeout (default 30 s) plus 1 s per 2 MB, never below command_timeout
1472
+ const unpackS = Math.max(this.timeout, toFloat(get(this.config, 'restore_base_timeout', 30)) + data.length / (2 * 1024 * 1024));
1473
+ let proc;
1474
+ try {
1475
+ proc = subprocessRun([...this.adb, 'exec-in', 'run-as', pkg, 'sh', '-c', shlexQuote(`cd ${stage} && tar -xf - && touch ../${ok}`)],
1476
+ { input: data, timeout: unpackS });
1477
+ } catch (e) {
1478
+ discard();
1479
+ if (e instanceof TimeoutExpired) {
1480
+ throw new AdapterError(`restore_app_data failed before any app data was removed: unpack timed out after ${Math.round(unpackS)} s`);
1481
+ }
1482
+ throw e;
1483
+ }
1484
+ const done = !proc.returncode && this._shell('run-as', pkg, 'ls', '-a').split(/\r?\n/).map((s) => s.trim()).includes(ok);
1485
+ if (!done) {
1486
+ discard();
1487
+ throw new AdapterError('restore_app_data failed before any app data was removed: '
1488
+ + (proc.returncode ? strTail(decodeReplace(proc.stderr), 600) : 'tar did not finish the unpack'));
1326
1489
  }
1327
- const proc = subprocessRun([...this.adb, 'exec-in', 'run-as', pkg, 'tar', '-xf', '-'], { input: data, timeout: this.timeout });
1328
- if (proc.returncode) { throw new AdapterError('restore_app_data failed: ' + strTail(decodeReplace(proc.stderr), 600)); }
1490
+ // Each staged entry replaces the one of its name: `mv dir .` onto an existing dir would move it inside
1491
+ // (shared_prefs/shared_prefs) and the app would read the old data. clear_dirs removes the rest.
1492
+ const clear = dirs.length ? `rm -rf ${dirs.map((d) => shlexQuote(d)).join(' ')} && ` : '';
1493
+ this._run(runAs(`${clear}for e in ${stage}/* ${stage}/.[!.]*; do [ -e "$e" ] || continue; `
1494
+ + `n=\${e##*/}; rm -rf "./$n" && mv "$e" . || exit 1; done; rmdir ${stage} && rm -f ${ok}`));
1329
1495
  } else if (kind === 'back') {
1330
1496
  this._shell('input', 'keyevent', 'KEYCODE_BACK');
1331
1497
  } else if (kind === 'hide_ime') {
@@ -0,0 +1,146 @@
1
+ /**
2
+ * hosts.mjs — one target, several source hosts.
3
+ *
4
+ * A surface built by a shared composable / helper (an overlay opened from a panel that two routes
5
+ * both render) has an incoming edge from every host that renders it. Each edge compiles to its own
6
+ * task, and they differ only in how hard their host is to reach: one host may be the launch page,
7
+ * another reachable only through a data-backed list row. Measured (a Compose weather app): six
8
+ * overlays were compiled only from the host behind an empty city list, every task ended
9
+ * `target-unverified` on that unverified host, while the other host was verified 94 times.
10
+ *
11
+ * - annotateHosts(tasks, verified): per (target, mechanism family) with 2+ distinct sources, order the
12
+ * tasks by hostCost (a verified host first, then fewest data preconditions, then shortest replay)
13
+ * and give each task `host_alternatives` (the other tasks, in that order) and `host_rank`.
14
+ * - isHostFailure(result, opts): the task failed because of its host (the source page was not
15
+ * reached or not verified), not because of its own trigger.
16
+ * - alternativeHost(task, byId, opts): the next alternative task to try for the same target.
17
+ * - hostsTried(results, taskById): every host tried for one target, for the gap report.
18
+ *
19
+ * Generic: no app names, no page names. Exports: hostFamily, hostCost, orderHosts, annotateHosts, isHostFailure,
20
+ * HOST_FAILURE_RE, HOST_COMPILE_ISSUES, alternativeHost, hostsTried, baseTaskId, HOST_RETRY_TAG.
21
+ */
22
+
23
+ /** Mechanisms that open the same kind of surface over / inside a host count as one family. */
24
+ const FAMILIES = {
25
+ 'open-overlay': 'overlay', 'show-dialog': 'overlay', 'open-dialog': 'overlay', 'open-sheet': 'overlay',
26
+ 'open-menu': 'overlay', 'popup': 'overlay', 'surface-switch': 'surface',
27
+ };
28
+ export const hostFamily = (mechanism) => FAMILIES[mechanism] ?? (mechanism || 'unknown');
29
+
30
+ const LIST_STEPS = new Set(['click_list_item', 'long_click_list_item']);
31
+ const steps = (t) => [...(t?.replay ?? []), ...(t?.prelude ?? []), ...(t?.action ? [t.action] : [])];
32
+
33
+ /**
34
+ * [unverified host, data preconditions, replay length]: compared lexicographically, lower first.
35
+ * Data preconditions: the task's phase requirements plus every list-row step (a row exists only
36
+ * when the app holds data).
37
+ */
38
+ export function hostCost(task, verified = new Set()) {
39
+ const data = (task?.requires ?? []).length + steps(task).filter((s) => LIST_STEPS.has(s?.type)).length;
40
+ return [verified.has(task?.source_static) ? 0 : 1, data, (task?.replay ?? []).length];
41
+ }
42
+ const cmp = (a, b) => { for (let i = 0; i < a.length; i++) { if (a[i] !== b[i]) { return a[i] - b[i]; } } return 0; };
43
+
44
+ /** The task id a variant (`<id>@<phase>`) or a host retry was made from. */
45
+ export const baseTaskId = (id) => String(id ?? '').split('@')[0];
46
+ /** Task id suffix of a host retry run inside another task's phase. */
47
+ export const HOST_RETRY_TAG = '@host-retry:';
48
+
49
+ /**
50
+ * orderHosts(tasks, verified, { annotate, variants }) -> tasks in run order. Tasks into one target by
51
+ * one mechanism family from 2+ distinct source hosts swap places among themselves so the cheapest
52
+ * host (hostCost) comes first; every other task keeps its place, and a group of one host is left
53
+ * untouched. `annotate`: also set `host_rank` (0 = tried first) and `host_alternatives` (the other
54
+ * task ids, cheapest first). `variants`: group variant tasks (`<id>@<phase>`) too (the runner orders
55
+ * one phase's list; the compiler annotates base tasks only).
56
+ */
57
+ export function orderHosts(tasks, verified = new Set(), { annotate = false, variants = false } = {}) {
58
+ const groups = new Map();
59
+ tasks.forEach((t, i) => {
60
+ if (!t || t.purpose !== 'navigate' || !t.target_static || !t.source_static) { return; }
61
+ if (!variants && String(t.task_id).includes('@')) { return; }
62
+ const k = `${t.target_static}|${hostFamily(t.provenance?.mechanism)}`;
63
+ if (!groups.has(k)) { groups.set(k, []); }
64
+ groups.get(k).push(i);
65
+ });
66
+ const out = [...tasks];
67
+ for (const idxs of groups.values()) {
68
+ if (new Set(idxs.map((i) => tasks[i].source_static)).size < 2) { continue; }
69
+ // stable: equal costs keep their compile order
70
+ const ranked = [...idxs].sort((a, b) => cmp(hostCost(tasks[a], verified), hostCost(tasks[b], verified)) || a - b);
71
+ ranked.forEach((ti, rank) => {
72
+ const t = tasks[ti];
73
+ if (annotate) {
74
+ t.host_rank = rank;
75
+ t.host_alternatives = ranked.filter((x) => x !== ti).map((x) => tasks[x].task_id);
76
+ }
77
+ out[idxs[rank]] = t;
78
+ });
79
+ }
80
+ return out;
81
+ }
82
+
83
+ /** annotateHosts(tasks, verified): orderHosts over the compiled (base) tasks, annotated. */
84
+ export const annotateHosts = (tasks, verified = new Set()) => orderHosts(tasks, verified, { annotate: true });
85
+
86
+ /** Failure reasons that are about the host page, not the task's own trigger. */
87
+ export const HOST_FAILURE_RE = /^(?:source-unverified:|replay-target-unverified:|selector unavailable on non-app\/empty UI|list-item: the probing page is unverified|source-chain-missing|no-route|no route)|probing page is unverified/;
88
+ /** Compile issues that leave the host unreachable (the target's own trigger may still be fine). */
89
+ export const HOST_COMPILE_ISSUES = ['missing-source-path', 'entry-requires-external-surface', 'missing-replay-selector',
90
+ 'replay-depth-exceeded', 'unsupported-swipe-gesture'];
91
+ const NOT_RUN = new Set(['confirmed', 'device-error', 'budget-exhausted', 'skipped']);
92
+
93
+ /**
94
+ * isHostFailure(result, { hostVerified }): a task_result payload that failed because its host was
95
+ * not reached or not verified: the source stage failed, a compile issue left the host unreachable,
96
+ * the reason names the host, or (`hostVerified === false`, known only to the runner) the target
97
+ * stage ran on a host that was never verified (attested only).
98
+ */
99
+ export function isHostFailure(result, { hostVerified = null } = {}) {
100
+ if (!result || NOT_RUN.has(result.outcome) || result.retrying) { return false; }
101
+ if (result.stage === 'source') { return true; }
102
+ const reason = String(result.reason ?? '');
103
+ if (HOST_FAILURE_RE.test(reason)) { return true; }
104
+ if (result.outcome === 'unsupported') {
105
+ const issues = Array.isArray(result.compile_issues) ? result.compile_issues : reason.split(/,\s*/);
106
+ return issues.some((x) => HOST_COMPILE_ISSUES.some((h) => String(x).startsWith(h)));
107
+ }
108
+ return hostVerified === false;
109
+ }
110
+
111
+ const subset = (a, b) => (a ?? []).every((x) => (b ?? []).includes(x));
112
+
113
+ /**
114
+ * alternativeHost(task, byId, { tried, requires, inPhase, started }) -> the next alternative task
115
+ * (cheapest host first) that can run in the current phase, or null. Skipped: a host already tried
116
+ * for this target (`tried`: source ids), a task not compiled, one that the current phase runs
117
+ * anyway (`inPhase`: task ids, base ids too) or has already started (`started(id)`), and one whose
118
+ * requirements the current phase (`requires`) does not hold.
119
+ */
120
+ export function alternativeHost(task, byId, { tried = new Set(), requires = [], inPhase = new Set(), started = () => false } = {}) {
121
+ for (const id of task?.host_alternatives ?? []) {
122
+ const alt = byId.get(id);
123
+ if (!alt || alt.status !== 'compiled' || tried.has(alt.source_static)) { continue; }
124
+ if (inPhase.has(id) || started(id)) { continue; }
125
+ if (!subset(alt.requires, requires)) { continue; }
126
+ return alt;
127
+ }
128
+ return null;
129
+ }
130
+
131
+ /**
132
+ * hostsTried(results, taskById) -> [{source, task_id, outcome, reason}], one per distinct source host,
133
+ * ordered by each host's last attempt (its last result kept): what the gap report lists for a target that
134
+ * stayed uncovered after several hosts.
135
+ */
136
+ export function hostsTried(results, taskById) {
137
+ const by = new Map();
138
+ for (const r of results) {
139
+ const t = taskById.get(r.task_id) ?? taskById.get(baseTaskId(r.task_id)) ?? {};
140
+ const source = r.source_static ?? t.source_static;
141
+ if (!source) { continue; }
142
+ by.delete(source);
143
+ by.set(source, { source, task_id: r.task_id, outcome: r.outcome, reason: r.reason ?? r.outcome });
144
+ }
145
+ return [...by.values()];
146
+ }
@@ -855,6 +855,7 @@ function _resolveBySource(observation, nodes, catalog) {
855
855
  weakBody = candidates[0].weak; candidates = [];
856
856
  }
857
857
  }
858
+ if (candidates.length) { candidates = _surfaceOverHost(candidates, nodes, catalog, observation, tabBar); }
858
859
  if (!candidates.length) {
859
860
  for (const [ident, page] of Object.entries(catalog)) {
860
861
  const hasList = nodes.some((n) => g(n, 'resource_id') === 'android:id/list');
@@ -882,6 +883,43 @@ function _resolveBySource(observation, nodes, catalog) {
882
883
 
883
884
  export const _SCREEN_KINDS = ['fragment', 'activity', 'screen', 'compose-route', 'panel', 'view-page'];
884
885
 
886
+ /**
887
+ * keepTreeUnreliable(observation, prev, next) -> the resolution a re-judge (rejudge / recover) keeps:
888
+ * a capture whose tree the adapter marked `tree_unreliable` stays `tree-unreliable` (with the
889
+ * candidate target the runner gave it, `prev.candidate_for`) unless the new catalog verifies it.
890
+ */
891
+ export function keepTreeUnreliable(observation, prev, next) {
892
+ if (!truthy(g(observation, 'tree_unreliable')) || ['verified', 'foreign-package'].includes(g(next, 'status'))) { return next; }
893
+ const want = g(prev || {}, 'candidate_for');
894
+ return { status: 'tree-unreliable', reason: observation.tree_unreliable, candidates: [], ...(truthy(want) ? { candidate_for: want } : {}) };
895
+ }
896
+
897
+ /** Catalog kinds a host route swaps in by a state flag (a2h-utg-static `in-route-surface`, id `surface:<Composable>`). */
898
+ export const SURFACE_KINDS = ['in-route-surface'];
899
+
900
+ /**
901
+ * _surfaceOverHost(candidates, nodes, catalog, observation, tabBar) -> candidates. An in-route surface
902
+ * renders inside its host's window, under the host's own bar and tabs, so the host's anchors (its
903
+ * toolbar title, its tab, its body texts) stay on screen with it and the tiers above name the host.
904
+ * When a surface of a candidate host (`opened_from` / `host_node`) has its own body anchors on screen
905
+ * (the same test as any page's body text), the surface is what the screen shows, as an overlay
906
+ * is identified over its host by its own texts. No surface anchor on screen: the candidates stand.
907
+ */
908
+ export function _surfaceOverHost(candidates, nodes, catalog, observation, tabBar = null) {
909
+ const hosts = new Set(candidates.map((c) => g(c, 'static_id')).filter((x) => truthy(x)));
910
+ if (!hosts.size) { return candidates; }
911
+ const surfaces = {};
912
+ for (const [ident, page] of Object.entries(catalog)) {
913
+ if (!SURFACE_KINDS.includes(g(page, 'kind'))) { continue; }
914
+ const on = [...(g(page, 'opened_from', []) || []), g(page, 'host_node')].filter((x) => truthy(x));
915
+ if (on.some((h) => hosts.has(h)) || hosts.has(ident)) { dset(surfaces, ident, page); }
916
+ }
917
+ if (!Object.keys(surfaces).length) { return candidates; }
918
+ const own = _bodyTextCandidates(nodes, surfaces, observation, tabBar);
919
+ if (!own.length || own[0].weak) { return candidates; }
920
+ return own.map((c) => ({ ...c, reason: 'in-route-surface-body-text' }));
921
+ }
922
+
885
923
  /** _share_row_container(nodes, texts): >=2 of `texts` are rows of ONE list. */
886
924
  export function _shareRowContainer(nodes, texts) {
887
925
  const rowList = (n) => {
@@ -1208,6 +1246,22 @@ export function _tabTitleCandidates(nodes, catalog, observation) {
1208
1246
 
1209
1247
  const setKey = (xs) => JSON.stringify(sortedStr(new Set(xs)));
1210
1248
 
1249
+ /** Unique own ids a dialog must show, and the share of its unique ids that must be visible. */
1250
+ export const DIALOG_OWN_MIN = 3;
1251
+ export const DIALOG_OWN_COVER = 0.8;
1252
+
1253
+ /**
1254
+ * dialogShown(shown, visible, counts): a dialog/sheet layout is open on screen without any
1255
+ * framework modal marker. At least DIALOG_OWN_MIN of the ids only this layout declares are
1256
+ * visible, and they are at least DIALOG_OWN_COVER of those ids. A few shared or stray ids
1257
+ * (two rows reused inline on a page) never qualify.
1258
+ */
1259
+ export function dialogShown(shown, visible, counts) {
1260
+ const unique = [...new Set(shown)].filter((r) => counts.get(r) === 1);
1261
+ const seen = unique.filter((r) => visible.has(r));
1262
+ return seen.length >= DIALOG_OWN_MIN && seen.length >= DIALOG_OWN_COVER * unique.length;
1263
+ }
1264
+
1211
1265
  /** _own_widget_candidates(nodes, catalog, observation): identify a page by ids only its layout declares. */
1212
1266
  export function _ownWidgetCandidates(nodes, catalog, observation) {
1213
1267
  const overlay = new Set();
@@ -1244,9 +1298,16 @@ export function _ownWidgetCandidates(nodes, catalog, observation) {
1244
1298
  for (const { ids } of groups.values()) { for (const r of ids) { counts.set(r, (counts.get(r) ?? 0) + 1); } }
1245
1299
  const modalOpen = g(observation, 'window') === 'dialog' || nodes.some((n) =>
1246
1300
  ['alertTitle', 'parentPanel', 'design_bottom_sheet'].includes(tail(S(g(n, 'resource_id', '')))));
1301
+ // A dialog/sheet is admitted when the framework marks a modal, or when its own layout is itself
1302
+ // the evidence that it is open (dialogShown). Measured (universalapp TV 2026-11-25): a full-screen
1303
+ // DialogFragment renders in window "main" with no alertTitle; all 9 ids only its layout declares
1304
+ // were on screen, yet the capture fell through to exact-activity on the host.
1305
+ const shownIds = (page) => { const hidden = g(page, 'hidden_ids', []); return g(page, 'widget_ids', []).filter((r) => !hidden.includes(r)); };
1306
+ const admitted = (page) => !['dialog', 'sheet'].includes(g(page, 'kind')) || modalOpen
1307
+ || dialogShown(shownIds(page), visible, counts);
1247
1308
  let scored = [];
1248
1309
  for (const [ident, page] of Object.entries(catalog)) {
1249
- if (['dialog', 'sheet'].includes(g(page, 'kind')) && !modalOpen) { continue; }
1310
+ if (!admitted(page)) { continue; }
1250
1311
  const unique = sortedStr(g(page, 'widget_ids', []).filter((r) => counts.get(r) === 1 && visible.has(r)));
1251
1312
  const hiddenIds = g(page, 'hidden_ids', []);
1252
1313
  const shown = g(page, 'widget_ids', []).filter((r) => !hiddenIds.includes(r));
@@ -1256,7 +1317,7 @@ export function _ownWidgetCandidates(nodes, catalog, observation) {
1256
1317
  if (!scored.length) {
1257
1318
  const own = [];
1258
1319
  for (const [ident, page] of Object.entries(catalog)) {
1259
- if (['dialog', 'sheet'].includes(g(page, 'kind')) && !modalOpen) { continue; }
1320
+ if (!admitted(page)) { continue; }
1260
1321
  if (!_hostCompatible(page, catalog, observation)) { continue; }
1261
1322
  const ids = new Set(g(page, 'widget_ids', []));
1262
1323
  const informative = new Set([...ids].filter((r) => visible.has(r) && (counts.get(r) ?? 0) <= 5));