@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,3739 @@
1
+ // Resolve a one-time Android analysis scope and inspect deterministic platform/data surfaces.
2
+ // Node.js port of inspect_android_project.py; behavior is identical.
3
+
4
+ import {
5
+ ArgParser,
6
+ expanduser,
7
+ fs,
8
+ isDir,
9
+ isFile,
10
+ path,
11
+ process,
12
+ pyJsonDump,
13
+ pyStrip,
14
+ parseStrictJson,
15
+ resolveLikePython,
16
+ systemExit,
17
+ etToString,
18
+ parseXmlFile,
19
+ } from "./lib/py_compat.mjs";
20
+ import { fileURLToPath, pathToFileURL } from "node:url";
21
+
22
+ const SCHEMA_VERSION = "1.0";
23
+ const ANDROID_NS = "{http://schemas.android.com/apk/res/android}";
24
+ const RELEVANT_EXTENSIONS = new Set([
25
+ ".kt", ".java", ".xml", ".gradle", ".kts", ".aidl", ".proto",
26
+ ".c", ".cc", ".cpp", ".h", ".hpp", ".json", ".properties", ".toml",
27
+ ".bp", ".mk",
28
+ ]);
29
+ const SOURCE_SUFFIXES = new Set([".kt", ".java", ".aidl"]);
30
+ const NATIVE_SUFFIXES = new Set([".c", ".cc", ".cpp", ".h", ".hpp"]);
31
+ const NATIVE_BUILD_FILES = new Set(["CMakeLists.txt", "Android.mk", "Application.mk"]);
32
+ const EXCLUDED_PARTS = new Set([
33
+ ".git", ".gradle", ".idea", ".cxx", "build", "generated", "node_modules",
34
+ "oh_modules", "test", "androidTest", "benchmark", "captures", "out",
35
+ ]);
36
+ const TEST_SOURCE_SETS = new Set(["test", "androidTest", "benchmark", "testFixtures"]);
37
+ const GENERATED_DOCUMENTS = new Set(["project_design.md", "database_design.md", "preferences_design.md"]);
38
+ const HARNESS_MODULE_NAME_PATTERN = /sample|demo|example|playground/i;
39
+ const INTERNAL_PACKAGE_SEGMENTS = new Set(["internal", "impl", "internals"]);
40
+ const GRADLE_PROJECT_DEPENDENCY_PATTERNS = [
41
+ /project\s*\(\s*['"](:[^'"]+)['"]\s*\)/g,
42
+ /project\s*\(\s*path\s*=\s*['"](:[^'"]+)['"]/g,
43
+ /project\s*\(\s*path\s*:\s*['"](:[^'"]+)['"]/g,
44
+ ];
45
+
46
+ const COMPONENT_BASES = {
47
+ Activity: ["entry_points", "Activity"],
48
+ AppCompatActivity: ["entry_points", "Activity"],
49
+ ComponentActivity: ["entry_points", "Activity"],
50
+ FragmentActivity: ["entry_points", "Activity"],
51
+ Fragment: ["entry_points", "Fragment"],
52
+ DialogFragment: ["entry_points", "DialogFlow"],
53
+ BottomSheetDialogFragment: ["entry_points", "DialogFlow"],
54
+ Service: ["background_capabilities", "Service"],
55
+ IntentService: ["background_capabilities", "Service"],
56
+ JobService: ["background_capabilities", "JobService"],
57
+ Worker: ["background_capabilities", "Worker"],
58
+ CoroutineWorker: ["background_capabilities", "Worker"],
59
+ ListenableWorker: ["background_capabilities", "Worker"],
60
+ BroadcastReceiver: ["system_integrations", "BroadcastReceiver"],
61
+ ContentProvider: ["system_integrations", "ContentProvider"],
62
+ AppWidgetProvider: ["system_integrations", "AppWidget"],
63
+ TileService: ["system_integrations", "QuickSettingsTile"],
64
+ AccessibilityService: ["system_integrations", "AccessibilityService"],
65
+ NotificationListenerService: ["system_integrations", "NotificationListenerService"],
66
+ VpnService: ["system_integrations", "VpnService"],
67
+ InputMethodService: ["system_integrations", "InputMethodService"],
68
+ DeviceAdminReceiver: ["system_integrations", "DeviceAdminReceiver"],
69
+ };
70
+
71
+ const PLATFORM_XML_KINDS = {
72
+ "shortcuts.xml": "AppShortcuts",
73
+ "network_security_config.xml": "NetworkSecurityConfiguration",
74
+ "file_paths.xml": "FileProviderPaths",
75
+ "backup_rules.xml": "BackupRules",
76
+ "data_extraction_rules.xml": "DataExtractionRules",
77
+ "widget_info.xml": "AppWidgetConfiguration",
78
+ };
79
+
80
+ const DYNAMIC_PATTERNS = {
81
+ Reflection: /Class\.forName|kotlin\.reflect|\.javaClass\b/g,
82
+ GeneratedRouting: /ARouter|AutoRoute|RouteMap|generated.*route/gi,
83
+ FeatureFlag: /FirebaseRemoteConfig|feature[_ ]?flag|experiment/gi,
84
+ DynamicReceiver: /\bregisterReceiver\s*\(/g,
85
+ DynamicSql: /(?:CREATE|ALTER)\s+TABLE[^\n]*(?:\+|\$\{)/gi,
86
+ };
87
+
88
+ const BACKGROUND_PATTERNS = {
89
+ WorkScheduling: /\bWorkManager\b|enqueueUniqueWork|PeriodicWorkRequest/g,
90
+ AlarmScheduling: /\bAlarmManager\b/g,
91
+ JobScheduling: /\bJobScheduler\b/g,
92
+ ForegroundExecution: /startForeground\s*\(|FOREGROUND_SERVICE/g,
93
+ };
94
+
95
+ const SYSTEM_PATTERNS = {
96
+ Notification: /NotificationCompat|NotificationManager/g,
97
+ BinderIntegration: /\b(?:AIDL|IBinder|Binder)\b/g,
98
+ NativeIntegration: /System\.loadLibrary|external\s+fun|\bnative\s+/g,
99
+ };
100
+
101
+ const APP_STARTUP_INITIALIZER_PATTERN = /class\s+(\w+)\s*(?:\([^)]*\))?\s*:\s*[^\n{]*\bInitializer\s*</g;
102
+
103
+ const PUBLIC_TOP_LEVEL_KOTLIN = new RegExp(
104
+ "^(?:@[\\w.]+(?:\\([^)]*\\))?\\s*)*"
105
+ + "(?:(?:public|open|abstract|sealed|data|final|inline|external|suspend)\\s+)*"
106
+ + "(?<keyword>class|interface|object|fun)\\s+(?<name>\\w+)",
107
+ "gm",
108
+ );
109
+ const PUBLIC_TOP_LEVEL_JAVA = /^public\s+(?:final\s+|abstract\s+|static\s+)*(?:class|interface|enum)\s+(\w+)/gm;
110
+
111
+ const CONSTRAINT_KEYWORDS = new Set([
112
+ "PRIMARY", "FOREIGN", "UNIQUE", "CHECK", "NOT", "NULL", "DEFAULT", "REFERENCES",
113
+ "CONSTRAINT", "COLLATE", "GENERATED", "AUTOINCREMENT",
114
+ ]);
115
+
116
+ // ---------------------------------------------------------------------------
117
+ // Small Python-compat helpers local to this port
118
+ // ---------------------------------------------------------------------------
119
+
120
+ function pyTitle(value) {
121
+ // Python str.title(): uppercase the first character of every alphabetic
122
+ // run and lowercase the rest ("deepLink" -> "Deeplink").
123
+ let out = "";
124
+ let prevAlpha = false;
125
+ for (const ch of value) {
126
+ const isAlpha = /[A-Za-z]/.test(ch);
127
+ if (isAlpha && !prevAlpha) {
128
+ out += ch.toUpperCase();
129
+ } else if (isAlpha) {
130
+ out += ch.toLowerCase();
131
+ } else {
132
+ out += ch;
133
+ }
134
+ prevAlpha = isAlpha;
135
+ }
136
+ return out;
137
+ }
138
+
139
+ function suffixOf(name) {
140
+ const i = name.lastIndexOf(".");
141
+ if (i <= 0 || i === name.length - 1) return "";
142
+ return name.slice(i);
143
+ }
144
+
145
+ // Python `a or b or ...`: fall through on None / [] / {} / "" / 0 / false.
146
+ function pyOr(...values) {
147
+ for (const value of values) {
148
+ if (value === null || value === undefined) continue;
149
+ if (Array.isArray(value) && value.length === 0) continue;
150
+ if (typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0) continue;
151
+ if (typeof value === "string" && value === "") continue;
152
+ if (typeof value === "number" && value === 0) continue;
153
+ if (value === false) continue;
154
+ return value;
155
+ }
156
+ return undefined;
157
+ }
158
+
159
+ function pathExists(p) {
160
+ try {
161
+ fs.statSync(p);
162
+ return true;
163
+ } catch {
164
+ return false;
165
+ }
166
+ }
167
+
168
+ function pathParts(p) {
169
+ // Normalize native separators so Windows paths split correctly.
170
+ return resolveLikePython(p).split(path.sep).join("/").split("/");
171
+ }
172
+
173
+ function* walkAll(root) {
174
+ // rglob("*"): every file and directory under root (recursively).
175
+ const stack = [root];
176
+ while (stack.length > 0) {
177
+ const current = stack.pop();
178
+ let entries;
179
+ try {
180
+ entries = fs.readdirSync(current, { withFileTypes: true });
181
+ } catch {
182
+ continue;
183
+ }
184
+ for (const entry of entries) {
185
+ const child = path.join(current, entry.name);
186
+ yield child;
187
+ if (entry.isDirectory()) {
188
+ stack.push(child);
189
+ }
190
+ }
191
+ }
192
+ }
193
+
194
+ function globDepth1(root, relPattern) {
195
+ // path.glob("*/x/y") — one leading wildcard segment then literal segments.
196
+ const parts = relPattern.split("/");
197
+ if (parts[0] !== "*") {
198
+ const single = path.join(root, relPattern);
199
+ return pathExists(single) ? [single] : [];
200
+ }
201
+ const rest = parts.slice(1).join("/");
202
+ const out = [];
203
+ let names;
204
+ try {
205
+ names = fs.readdirSync(root);
206
+ } catch {
207
+ return out;
208
+ }
209
+ for (const name of names) {
210
+ const candidate = path.join(root, name, rest);
211
+ if (pathExists(candidate)) {
212
+ out.push(candidate);
213
+ }
214
+ }
215
+ return out;
216
+ }
217
+
218
+ function segmentMatcher(segment) {
219
+ // fnmatch-style segment: * and ? do not cross "/", [...] passes through.
220
+ const src = segment
221
+ .replace(/[.+^${}()|[\]\\]/g, "\\$&")
222
+ .replace(/\*/g, "[^/]*")
223
+ .replace(/\?/g, "[^/]");
224
+ return new RegExp(`^${src}$`);
225
+ }
226
+
227
+ function globPattern(base, pattern) {
228
+ // pathlib.Path.glob semantics: "/"-separated segments, `**` crosses any
229
+ // number of directories, the final segment matches files and directories.
230
+ // Returns absolute paths under `base`.
231
+ const segments = pattern.split("/").filter((seg) => seg !== "" && seg !== ".");
232
+ if (segments.length === 0) {
233
+ return pathExists(base) ? [base] : [];
234
+ }
235
+ const results = [];
236
+
237
+ const walk = (dir, segIndex, relParts) => {
238
+ if (segIndex >= segments.length) {
239
+ const full = path.join(base, ...relParts);
240
+ if (pathExists(full)) results.push(full);
241
+ return;
242
+ }
243
+ const seg = segments[segIndex];
244
+ if (seg === "**") {
245
+ // match zero or more directory levels
246
+ walk(dir, segIndex + 1, relParts);
247
+ let entries;
248
+ try {
249
+ entries = fs.readdirSync(dir, { withFileTypes: true });
250
+ } catch {
251
+ return;
252
+ }
253
+ for (const entry of entries) {
254
+ if (entry.isDirectory()) {
255
+ walk(path.join(dir, entry.name), segIndex, [...relParts, entry.name]);
256
+ }
257
+ }
258
+ return;
259
+ }
260
+ const matcher = segmentMatcher(seg);
261
+ let entries;
262
+ try {
263
+ entries = fs.readdirSync(dir, { withFileTypes: true });
264
+ } catch {
265
+ return;
266
+ }
267
+ for (const entry of entries) {
268
+ if (!matcher.test(entry.name)) continue;
269
+ const childRel = [...relParts, entry.name];
270
+ if (segIndex === segments.length - 1) {
271
+ const full = path.join(base, ...childRel);
272
+ if (pathExists(full)) results.push(full);
273
+ } else if (entry.isDirectory()) {
274
+ walk(path.join(dir, entry.name), segIndex + 1, childRel);
275
+ }
276
+ }
277
+ };
278
+
279
+ walk(String(base), 0, []);
280
+ return results;
281
+ }
282
+
283
+ // Minimal TOML subset parser: tables, string values, and inline tables —
284
+ // enough for gradle/libs.versions.toml's [plugins] section.
285
+ function parseTomlSubset(text) {
286
+ const data = {};
287
+ let current = data;
288
+ for (const rawLine of text.split("\n")) {
289
+ const line = rawLine.trim();
290
+ if (line === "" || line.startsWith("#")) continue;
291
+ const tableMatch = /^\[([^\]]+)\]$/.exec(line);
292
+ if (tableMatch) {
293
+ current = data;
294
+ for (const part of tableMatch[1].split(".")) {
295
+ if (!(part in current)) current[part] = {};
296
+ current = current[part];
297
+ }
298
+ continue;
299
+ }
300
+ const eq = line.indexOf("=");
301
+ if (eq < 0) continue;
302
+ const key = pyStrip(line.slice(0, eq));
303
+ let valueText = pyStrip(line.slice(eq + 1));
304
+ const hashIndex = findTomlComment(valueText);
305
+ if (hashIndex >= 0) valueText = pyStrip(valueText.slice(0, hashIndex));
306
+ if (valueText.startsWith("'") && valueText.endsWith("'")) {
307
+ // TOML literal string: no escape processing.
308
+ current[key] = valueText.slice(1, -1);
309
+ } else if (valueText.startsWith("{") && valueText.endsWith("}")) {
310
+ const inline = {};
311
+ for (const piece of splitTomlInline(valueText.slice(1, -1))) {
312
+ const innerEq = piece.indexOf("=");
313
+ if (innerEq < 0) continue;
314
+ const k = pyStrip(piece.slice(0, innerEq));
315
+ let v = pyStrip(piece.slice(innerEq + 1));
316
+ if (v.startsWith('"') && v.endsWith('"')) v = v.slice(1, -1);
317
+ else if (v.startsWith("'") && v.endsWith("'")) v = v.slice(1, -1);
318
+ inline[k] = v;
319
+ }
320
+ current[key] = inline;
321
+ } else if (valueText.startsWith('"') && valueText.endsWith('"')) {
322
+ current[key] = valueText.slice(1, -1);
323
+ } else {
324
+ current[key] = valueText;
325
+ }
326
+ }
327
+ return data;
328
+ }
329
+
330
+ function findTomlComment(value) {
331
+ let inString = false;
332
+ for (let i = 0; i < value.length; i += 1) {
333
+ if (value[i] === '"') inString = !inString;
334
+ if (value[i] === "#" && !inString) return i;
335
+ }
336
+ return -1;
337
+ }
338
+
339
+ function splitTomlInline(value) {
340
+ const parts = [];
341
+ let current = "";
342
+ let inString = false;
343
+ for (const ch of value) {
344
+ if (ch === '"') inString = !inString;
345
+ if (ch === "," && !inString) {
346
+ parts.push(current);
347
+ current = "";
348
+ continue;
349
+ }
350
+ current += ch;
351
+ }
352
+ if (pyStrip(current) !== "") parts.push(current);
353
+ return parts;
354
+ }
355
+
356
+ // ---------------------------------------------------------------------------
357
+ // Module model + shared helpers
358
+ // ---------------------------------------------------------------------------
359
+
360
+ function createModule(moduleId, directory, kind, buildSystem, buildType = "", buildFile = null) {
361
+ return { module_id: moduleId, directory, kind, build_system: buildSystem, build_type: buildType, build_file: buildFile };
362
+ }
363
+
364
+ function atomicWriteJson(p, data) {
365
+ fs.mkdirSync(path.dirname(p), { recursive: true });
366
+ const tmp = path.join(
367
+ path.dirname(p),
368
+ `${path.basename(p)}.${process.pid}.${Date.now()}.${Math.floor(Math.random() * 1e9)}.tmp`,
369
+ );
370
+ try {
371
+ fs.writeFileSync(tmp, `${pyJsonDump(data)}\n`, "utf8");
372
+ fs.renameSync(tmp, p);
373
+ } catch (err) {
374
+ try {
375
+ fs.unlinkSync(tmp);
376
+ } catch { /* best effort */ }
377
+ throw err;
378
+ }
379
+ }
380
+
381
+ export function readText(p) {
382
+ // Python: strict utf-8 first, errors="replace" fallback — readFileSync's
383
+ // utf8 decoding replaces invalid sequences with U+FFFD, matching "replace".
384
+ return fs.readFileSync(p, "utf8");
385
+ }
386
+
387
+ function rel(p, root) {
388
+ return path.relative(resolveLikePython(root), resolveLikePython(p)).split(path.sep).join("/");
389
+ }
390
+
391
+ function relOrAbs(p, root) {
392
+ const resolved = resolveLikePython(p);
393
+ const rootResolved = resolveLikePython(root);
394
+ const value = path.relative(rootResolved, resolved);
395
+ if (value.startsWith("..")) {
396
+ return resolved;
397
+ }
398
+ // Python relative_to(repo) of the repo itself is Path(".") → as_posix "."
399
+ if (value === "") {
400
+ return ".";
401
+ }
402
+ return value.split(path.sep).join("/");
403
+ }
404
+
405
+ function localName(value) {
406
+ const idx = value.lastIndexOf("}");
407
+ return idx >= 0 ? value.slice(idx + 1) : value;
408
+ }
409
+
410
+ function isInternalSourcePath(sourcePath) {
411
+ return sourcePath.split("/").some((part) => INTERNAL_PACKAGE_SEGMENTS.has(part.toLowerCase()));
412
+ }
413
+
414
+ function attr(element, name) {
415
+ for (const [key, value] of Object.entries(element.attrib)) {
416
+ if (localName(key) === name) {
417
+ return value;
418
+ }
419
+ }
420
+ return null;
421
+ }
422
+
423
+ function pathIsExcluded(p) {
424
+ return pathParts(p).some((part) => EXCLUDED_PARTS.has(part));
425
+ }
426
+
427
+ function pomRoot(p) {
428
+ if (!pathExists(p)) {
429
+ return null;
430
+ }
431
+ try {
432
+ return parseXmlFile(p);
433
+ } catch {
434
+ return null;
435
+ }
436
+ }
437
+
438
+ function xmlChildText(element, name) {
439
+ if (element === null || element === undefined) {
440
+ return null;
441
+ }
442
+ for (const child of element.children) {
443
+ if (localName(child.tag) === name) {
444
+ const value = pyStrip(child.text ?? "");
445
+ return value === "" ? null : value;
446
+ }
447
+ }
448
+ return null;
449
+ }
450
+
451
+ function xmlChildren(element, name) {
452
+ if (element === null || element === undefined) {
453
+ return [];
454
+ }
455
+ return element.children.filter((child) => localName(child.tag) === name);
456
+ }
457
+
458
+ function xmlFirst(element, name) {
459
+ const children = xmlChildren(element, name);
460
+ return children.length > 0 ? children[0] : null;
461
+ }
462
+
463
+ function mavenCoordinates(pom) {
464
+ const root = pomRoot(pom);
465
+ if (root === null) {
466
+ return ["", path.basename(path.dirname(String(pom))), "", "jar"];
467
+ }
468
+ const parent = xmlFirst(root, "parent");
469
+ const groupId = xmlChildText(root, "groupId") ?? xmlChildText(parent, "groupId") ?? "";
470
+ const artifactId = xmlChildText(root, "artifactId") ?? path.basename(path.dirname(String(pom)));
471
+ const version = xmlChildText(root, "version") ?? xmlChildText(parent, "version") ?? "";
472
+ const packaging = xmlChildText(root, "packaging") ?? "jar";
473
+ return [groupId, artifactId, version, packaging];
474
+ }
475
+
476
+ function mavenHasAndroidPlugin(pom) {
477
+ const root = pomRoot(pom);
478
+ if (root === null) {
479
+ return false;
480
+ }
481
+ for (const element of root.iter()) {
482
+ if (localName(element.tag) === "artifactId" && ["android-maven-plugin", "maven-android-plugin"].includes(pyStrip(element.text ?? ""))) {
483
+ return true;
484
+ }
485
+ }
486
+ const packaging = mavenCoordinates(pom)[3].toLowerCase();
487
+ return ["apk", "aar", "apklib"].includes(packaging);
488
+ }
489
+
490
+ function strongAospRoot(p) {
491
+ return (
492
+ isDir(path.join(p, "build", "soong"))
493
+ || isDir(path.join(p, "build", "make", "core"))
494
+ || pathExists(path.join(p, "build", "envsetup.sh"))
495
+ );
496
+ }
497
+
498
+ function genericManifestCandidates(p) {
499
+ const candidates = [];
500
+ for (const child of walkAll(p)) {
501
+ if (path.basename(String(child)) === "AndroidManifest.xml" && !pathIsExcluded(child)) {
502
+ candidates.push(child);
503
+ }
504
+ }
505
+ return candidates;
506
+ }
507
+
508
+ function detectBuildSystem(p, requested = "auto") {
509
+ requested = requested.toLowerCase();
510
+ const hasGradle = ["settings.gradle", "settings.gradle.kts"].some((name) => pathExists(path.join(p, name)))
511
+ || ["build.gradle", "build.gradle.kts"].some((name) => pathExists(path.join(p, name)));
512
+ const hasMaven = pathExists(path.join(p, "pom.xml")) && (
513
+ mavenHasAndroidPlugin(path.join(p, "pom.xml"))
514
+ || globDepth1(p, "*/src/main/AndroidManifest.xml").length > 0
515
+ || xmlFirst(pomRoot(path.join(p, "pom.xml")), "modules") !== null
516
+ );
517
+ let hasAosp = strongAospRoot(p) || pathExists(path.join(p, "Android.bp"));
518
+ if (!hasGradle && !hasMaven) {
519
+ hasAosp = hasAosp || pathExists(path.join(p, "Android.mk"));
520
+ }
521
+ const hasGeneric = pathExists(path.join(p, "AndroidManifest.xml")) || globDepth1(p, "*/src/main/AndroidManifest.xml").length > 0;
522
+
523
+ const available = {
524
+ gradle: hasGradle,
525
+ maven: hasMaven,
526
+ aosp: hasAosp,
527
+ generic: hasGeneric,
528
+ };
529
+ if (requested !== "auto") {
530
+ return available[requested] ? requested : null;
531
+ }
532
+ for (const name of ["gradle", "maven", "aosp", "generic"]) {
533
+ if (available[name]) {
534
+ return name;
535
+ }
536
+ }
537
+ return null;
538
+ }
539
+
540
+ function candidateAndroidRoots(root, maxDepth = 3) {
541
+ const candidates = new Set();
542
+ const markers = new Set(["settings.gradle", "settings.gradle.kts", "pom.xml", "Android.bp", "Android.mk"]);
543
+ for (const child of walkAll(root)) {
544
+ if (!isFile(child) || !markers.has(path.basename(String(child))) || pathIsExcluded(child)) {
545
+ continue;
546
+ }
547
+ const parent = path.dirname(String(child));
548
+ const depth = path.relative(resolveLikePython(root), resolveLikePython(parent)).split(path.sep).filter(Boolean).length;
549
+ if (depth <= maxDepth) {
550
+ candidates.add(parent);
551
+ }
552
+ }
553
+ for (const manifest of walkAll(root)) {
554
+ if (path.basename(String(manifest)) !== "AndroidManifest.xml" || pathIsExcluded(manifest)) {
555
+ continue;
556
+ }
557
+ const relativeParts = path.relative(resolveLikePython(root), resolveLikePython(manifest)).split(path.sep);
558
+ if (relativeParts.length > maxDepth + 4) {
559
+ continue;
560
+ }
561
+ const parent = path.dirname(String(manifest));
562
+ if (path.basename(parent) === "main" && path.basename(path.dirname(parent)) === "src") {
563
+ candidates.add(path.dirname(path.dirname(parent)));
564
+ } else {
565
+ candidates.add(parent);
566
+ }
567
+ }
568
+ return [...candidates].sort((a, b) => {
569
+ const aParts = pathParts(a).length;
570
+ const bParts = pathParts(b).length;
571
+ if (aParts !== bParts) return aParts - bParts;
572
+ return String(a) < String(b) ? -1 : String(a) > String(b) ? 1 : 0;
573
+ });
574
+ }
575
+
576
+ function modulePathToDir(value) {
577
+ const trimmed = pyStrip(value).replace(/^['"]+|['"]+$/g, "");
578
+ if (trimmed === "" || trimmed === ":") {
579
+ return ".";
580
+ }
581
+ return trimmed.replace(/^:+/, "").replace(/:/g, "/");
582
+ }
583
+
584
+ function gradleSettingsText(repo) {
585
+ return ["settings.gradle", "settings.gradle.kts"]
586
+ .filter((name) => pathExists(path.join(repo, name)))
587
+ .map((name) => readText(path.join(repo, name)))
588
+ .join("\n");
589
+ }
590
+
591
+ function gradleProjectDirOverrides(repo) {
592
+ const text = gradleSettingsText(repo);
593
+ const result = {};
594
+ const patterns = [
595
+ /project\s*\(\s*['"](:[^'"]+)['"]\s*\)\.projectDir\s*=\s*file\s*\(\s*['"]([^'"]+)['"]/g,
596
+ /project\s*\(\s*['"](:[^'"]+)['"]\s*\)\.projectDir\s*=\s*new\s+File\s*\(\s*rootDir\s*,\s*['"]([^'"]+)['"]/g,
597
+ ];
598
+ for (const pattern of patterns) {
599
+ for (const match of text.matchAll(pattern)) {
600
+ result[match[1]] = resolveLikePython(path.join(repo, match[2]));
601
+ }
602
+ }
603
+ return result;
604
+ }
605
+
606
+ function gradlePluginAliases(repo) {
607
+ const catalog = path.join(repo, "gradle", "libs.versions.toml");
608
+ if (!pathExists(catalog)) {
609
+ return {};
610
+ }
611
+ let data;
612
+ try {
613
+ data = parseTomlSubset(readText(catalog));
614
+ } catch {
615
+ return {};
616
+ }
617
+ const result = {};
618
+ const plugins = data.plugins ?? {};
619
+ if (plugins === null || typeof plugins !== "object") {
620
+ return {};
621
+ }
622
+ for (const [alias, value] of Object.entries(plugins)) {
623
+ let pluginId = null;
624
+ if (typeof value === "string") {
625
+ pluginId = value;
626
+ } else if (value !== null && typeof value === "object") {
627
+ pluginId = value.id ?? null;
628
+ }
629
+ if (pluginId) {
630
+ result[alias.replace(/[-_.]+/g, ".").toLowerCase()] = String(pluginId);
631
+ }
632
+ }
633
+ return result;
634
+ }
635
+
636
+ function classifyGradleModule(text, aliases) {
637
+ const pluginIds = new Set([...text.matchAll(/com\.android\.(?:application|library|dynamic-feature)/g)].map((m) => m[0]));
638
+ for (const match of text.matchAll(/alias\s*\(\s*libs\.plugins\.([A-Za-z0-9_.-]+)\s*\)/g)) {
639
+ const key = match[1].replace(/[-_.]+/g, ".").toLowerCase();
640
+ const pluginId = aliases[key];
641
+ if (pluginId) {
642
+ pluginIds.add(pluginId);
643
+ }
644
+ }
645
+ if (pluginIds.has("com.android.application")) {
646
+ return ["application", "com.android.application"];
647
+ }
648
+ if (pluginIds.has("com.android.dynamic-feature")) {
649
+ return ["dynamic-feature", "com.android.dynamic-feature"];
650
+ }
651
+ if (pluginIds.has("com.android.library")) {
652
+ return ["library", "com.android.library"];
653
+ }
654
+ return ["unknown", ""];
655
+ }
656
+
657
+ function manifestKind(p) {
658
+ let root;
659
+ try {
660
+ root = parseXmlFile(p);
661
+ } catch {
662
+ return "unknown";
663
+ }
664
+ for (const element of root.iter()) {
665
+ if (!["activity", "activity-alias"].includes(localName(element.tag))) {
666
+ continue;
667
+ }
668
+ for (const intentFilter of element.children.filter((child) => localName(child.tag) === "intent-filter")) {
669
+ const categories = intentFilter.children
670
+ .filter((child) => localName(child.tag) === "category")
671
+ .map((child) => child.attrib[`${ANDROID_NS}name`] ?? "");
672
+ if (categories.includes("android.intent.category.LAUNCHER")) {
673
+ return "application";
674
+ }
675
+ }
676
+ }
677
+ return "library";
678
+ }
679
+
680
+ function discoverGradleModules(repo) {
681
+ const declared = new Set();
682
+ const text = gradleSettingsText(repo);
683
+ for (const match of text.matchAll(/\binclude\s*\((.*?)\)/gs)) {
684
+ for (const inner of match[1].matchAll(/['"](:[^'"]+)['"]/g)) {
685
+ declared.add(inner[1]);
686
+ }
687
+ }
688
+ for (const match of text.matchAll(/\binclude\s+([^\n]+)/g)) {
689
+ for (const inner of match[1].matchAll(/['"](:[^'"]+)['"]/g)) {
690
+ declared.add(inner[1]);
691
+ }
692
+ }
693
+
694
+ const overrides = gradleProjectDirOverrides(repo);
695
+ const candidates = {};
696
+ for (const moduleId of declared) {
697
+ candidates[moduleId] = overrides[moduleId] ?? path.join(repo, modulePathToDir(moduleId));
698
+ }
699
+ for (const buildFile of walkAll(repo)) {
700
+ if (!path.basename(String(buildFile)).startsWith("build.gradle") || pathIsExcluded(buildFile)) {
701
+ continue;
702
+ }
703
+ const directory = path.dirname(String(buildFile));
704
+ if (directory === String(repo)) {
705
+ continue;
706
+ }
707
+ const relative = path.relative(String(repo), directory).split(path.sep).join("/");
708
+ const key = `:${relative.replace(/\//g, ":")}`;
709
+ if (!(key in candidates)) {
710
+ candidates[key] = directory;
711
+ }
712
+ }
713
+
714
+ const aliases = gradlePluginAliases(repo);
715
+ const modules = [];
716
+ for (const moduleId of Object.keys(candidates).sort()) {
717
+ const directory = candidates[moduleId];
718
+ if (!pathExists(directory)) {
719
+ continue;
720
+ }
721
+ const buildFiles = [path.join(directory, "build.gradle"), path.join(directory, "build.gradle.kts")]
722
+ .filter((p) => pathExists(p));
723
+ const buildText = buildFiles.map((p) => readText(p)).join("\n");
724
+ let [kind, buildType] = classifyGradleModule(buildText, aliases);
725
+ const manifest = path.join(directory, "src", "main", "AndroidManifest.xml");
726
+ if (kind === "unknown" && pathExists(manifest)) {
727
+ kind = manifestKind(manifest);
728
+ buildType = "manifest-inferred";
729
+ }
730
+ modules.push(createModule(moduleId, directory, kind, "gradle", buildType, buildFiles.length > 0 ? buildFiles[0] : null));
731
+ }
732
+
733
+ if (modules.length === 0) {
734
+ for (const candidate of globDepth1(repo, "*/src/main/AndroidManifest.xml")) {
735
+ const directory = path.dirname(path.dirname(path.dirname(candidate)));
736
+ const relative = path.relative(String(repo), directory).split(path.sep).join("/");
737
+ modules.push(createModule(`:${relative.replace(/\//g, ":")}`, directory, "unknown", "gradle"));
738
+ }
739
+ }
740
+ return modules;
741
+ }
742
+
743
+ function gradleInternalDependencies(module, modules) {
744
+ const text = [path.join(module.directory, "build.gradle"), path.join(module.directory, "build.gradle.kts")]
745
+ .filter((p) => pathExists(p))
746
+ .map((p) => readText(p))
747
+ .join("\n");
748
+ const result = new Set();
749
+ for (const pattern of GRADLE_PROJECT_DEPENDENCY_PATTERNS) {
750
+ for (const match of text.matchAll(pattern)) {
751
+ result.add(match[1]);
752
+ }
753
+ }
754
+ const known = new Set(modules.map((item) => item.module_id));
755
+ for (const match of text.matchAll(/\bprojects\.([A-Za-z0-9_.]+)/g)) {
756
+ const candidate = `:${match[1].replace(/\./g, ":")}`;
757
+ if (known.has(candidate)) {
758
+ result.add(candidate);
759
+ }
760
+ }
761
+ return result;
762
+ }
763
+
764
+ function declaredDynamicFeatures(application) {
765
+ const text = [path.join(application.directory, "build.gradle"), path.join(application.directory, "build.gradle.kts")]
766
+ .filter((p) => pathExists(p))
767
+ .map((p) => readText(p))
768
+ .join("\n");
769
+ const result = new Set();
770
+ for (const block of text.matchAll(/dynamicFeatures\s*(?:=|\+=)\s*(?:setOf|listOf)?\s*\((.*?)\)/gs)) {
771
+ for (const inner of block[1].matchAll(/['"](:[^'"]+)['"]/g)) {
772
+ result.add(inner[1]);
773
+ }
774
+ }
775
+ for (const block of text.matchAll(/dynamicFeatures\s*(?:=|\+=)\s*\[(.*?)\]/gs)) {
776
+ for (const inner of block[1].matchAll(/['"](:[^'"]+)['"]/g)) {
777
+ result.add(inner[1]);
778
+ }
779
+ }
780
+ for (const match of text.matchAll(/dynamicFeatures\s*(?:\+=|\.add\s*\()\s*['"](:[^'"]+)['"]/g)) {
781
+ result.add(match[1]);
782
+ }
783
+ return result;
784
+ }
785
+
786
+ function buildGradleGraph(modules) {
787
+ const known = new Set(modules.map((module) => module.module_id));
788
+ const graph = {};
789
+ for (const module of modules) {
790
+ graph[module.module_id] = new Set();
791
+ }
792
+ for (const module of modules) {
793
+ for (const dep of gradleInternalDependencies(module, modules)) {
794
+ if (known.has(dep)) {
795
+ graph[module.module_id].add(dep);
796
+ }
797
+ }
798
+ if (module.kind === "application") {
799
+ for (const dep of declaredDynamicFeatures(module)) {
800
+ if (known.has(dep)) {
801
+ graph[module.module_id].add(dep);
802
+ }
803
+ }
804
+ }
805
+ }
806
+ const out = {};
807
+ for (const [key, value] of Object.entries(graph)) {
808
+ out[key] = [...value].filter((item) => item !== key).sort();
809
+ }
810
+ return out;
811
+ }
812
+
813
+ function mavenModuleId(pom) {
814
+ const [groupId, artifactId] = mavenCoordinates(pom);
815
+ return groupId ? `${groupId}:${artifactId}` : artifactId;
816
+ }
817
+
818
+ function mavenModulePaths(pom, profile = "auto") {
819
+ const root = pomRoot(pom);
820
+ if (root === null) {
821
+ return [];
822
+ }
823
+ const result = [];
824
+ const modules = xmlFirst(root, "modules");
825
+ for (const element of xmlChildren(modules, "module")) {
826
+ const value = pyStrip(element.text ?? "");
827
+ if (value !== "") {
828
+ result.push(resolveLikePython(path.join(path.dirname(String(pom)), value)));
829
+ }
830
+ }
831
+ if (profile !== "auto") {
832
+ const profiles = xmlFirst(root, "profiles");
833
+ for (const profileElement of xmlChildren(profiles, "profile")) {
834
+ if (xmlChildText(profileElement, "id") !== profile) {
835
+ continue;
836
+ }
837
+ const profileModules = xmlFirst(profileElement, "modules");
838
+ for (const element of xmlChildren(profileModules, "module")) {
839
+ const value = pyStrip(element.text ?? "");
840
+ if (value !== "") {
841
+ result.push(resolveLikePython(path.join(path.dirname(String(pom)), value)));
842
+ }
843
+ }
844
+ }
845
+ }
846
+ return result;
847
+ }
848
+
849
+ function classifyMavenModule(pom) {
850
+ const packaging = mavenCoordinates(pom)[3].toLowerCase();
851
+ if (packaging === "apk") {
852
+ return ["application", "apk"];
853
+ }
854
+ if (packaging === "aar" || packaging === "apklib") {
855
+ return ["library", packaging];
856
+ }
857
+ if (packaging === "jar" && (pathExists(path.join(path.dirname(String(pom)), "src", "main", "AndroidManifest.xml")) || mavenHasAndroidPlugin(pom))) {
858
+ return ["library", "jar"];
859
+ }
860
+ return ["unknown", packaging];
861
+ }
862
+
863
+ function discoverMavenModules(repo, profile = "auto") {
864
+ const rootPom = path.join(repo, "pom.xml");
865
+ if (!pathExists(rootPom)) {
866
+ return [];
867
+ }
868
+ const queue = [rootPom];
869
+ const seen = new Set();
870
+ const modules = {};
871
+ while (queue.length > 0) {
872
+ const pomRaw = queue.shift();
873
+ const pom = resolveLikePython(String(pomRaw));
874
+ if (seen.has(pom) || !pathExists(pom)) {
875
+ continue;
876
+ }
877
+ seen.add(pom);
878
+ const [kind, buildType] = classifyMavenModule(pom);
879
+ const packaging = mavenCoordinates(pom)[3].toLowerCase();
880
+ if (packaging !== "pom" || kind !== "unknown") {
881
+ const moduleId = mavenModuleId(pom);
882
+ modules[moduleId] = createModule(moduleId, path.dirname(pom), kind, "maven", buildType, pom);
883
+ }
884
+ for (const modulePath of mavenModulePaths(pom, profile)) {
885
+ const candidate = path.basename(String(modulePath)).endsWith(".xml") ? modulePath : path.join(modulePath, "pom.xml");
886
+ if (pathExists(candidate)) {
887
+ queue.push(candidate);
888
+ }
889
+ }
890
+ }
891
+ if (Object.keys(modules).length === 0 && mavenHasAndroidPlugin(rootPom)) {
892
+ const [kind, buildType] = classifyMavenModule(rootPom);
893
+ const moduleId = mavenModuleId(rootPom);
894
+ modules[moduleId] = createModule(moduleId, repo, kind, "maven", buildType, rootPom);
895
+ }
896
+ return Object.values(modules).sort((a, b) => (a.module_id < b.module_id ? -1 : a.module_id > b.module_id ? 1 : 0));
897
+ }
898
+
899
+ function mavenDependencies(module, profile = "auto") {
900
+ const pom = module.build_file ?? path.join(module.directory, "pom.xml");
901
+ const root = pomRoot(pom);
902
+ if (root === null) {
903
+ return [];
904
+ }
905
+ const result = [];
906
+
907
+ const collect = (container) => {
908
+ const dependencies = container !== null ? xmlFirst(container, "dependencies") : null;
909
+ for (const dep of xmlChildren(dependencies, "dependency")) {
910
+ const groupId = xmlChildText(dep, "groupId") ?? "";
911
+ const artifactId = xmlChildText(dep, "artifactId") ?? "";
912
+ if (artifactId !== "") {
913
+ result.push([groupId, artifactId]);
914
+ }
915
+ }
916
+ };
917
+
918
+ collect(root);
919
+ if (profile !== "auto") {
920
+ const profiles = xmlFirst(root, "profiles");
921
+ for (const item of xmlChildren(profiles, "profile")) {
922
+ if (xmlChildText(item, "id") === profile) {
923
+ collect(item);
924
+ }
925
+ }
926
+ }
927
+ return result;
928
+ }
929
+
930
+ function buildMavenGraph(modules, profile = "auto") {
931
+ const coordinateMap = {};
932
+ const artifactMap = {};
933
+ for (const module of modules) {
934
+ const [groupId, artifactId] = mavenCoordinates(module.build_file ?? path.join(module.directory, "pom.xml"));
935
+ coordinateMap[JSON.stringify([groupId, artifactId])] = module.module_id;
936
+ if (!(artifactId in artifactMap)) artifactMap[artifactId] = [];
937
+ artifactMap[artifactId].push(module.module_id);
938
+ }
939
+ const graph = {};
940
+ for (const module of modules) {
941
+ const deps = new Set();
942
+ for (const [groupId, artifactId] of mavenDependencies(module, profile)) {
943
+ let target = coordinateMap[JSON.stringify([groupId, artifactId])] ?? null;
944
+ if (target === null && (artifactMap[artifactId] ?? []).length === 1) {
945
+ target = artifactMap[artifactId][0];
946
+ }
947
+ if (target && target !== module.module_id) {
948
+ deps.add(target);
949
+ }
950
+ }
951
+ graph[module.module_id] = [...deps].sort();
952
+ }
953
+ return graph;
954
+ }
955
+
956
+ // ---------------------------------------------------------------------------
957
+ // AOSP / Soong discovery
958
+ // ---------------------------------------------------------------------------
959
+
960
+ function stripBpComments(text) {
961
+ const result = [];
962
+ let i = 0;
963
+ let quote = null;
964
+ while (i < text.length) {
965
+ const char = text[i];
966
+ if (quote) {
967
+ result.push(char);
968
+ if (char === "\\" && i + 1 < text.length) {
969
+ result.push(text[i + 1]);
970
+ i += 2;
971
+ continue;
972
+ }
973
+ if (char === quote) {
974
+ quote = null;
975
+ }
976
+ i += 1;
977
+ continue;
978
+ }
979
+ if (char === "'" || char === '"') {
980
+ quote = char;
981
+ result.push(char);
982
+ i += 1;
983
+ continue;
984
+ }
985
+ if (text.startsWith("//", i)) {
986
+ const end = text.indexOf("\n", i);
987
+ if (end === -1) {
988
+ break;
989
+ }
990
+ result.push("\n");
991
+ i = end + 1;
992
+ continue;
993
+ }
994
+ if (text.startsWith("/*", i)) {
995
+ const end = text.indexOf("*/", i + 2);
996
+ i = end === -1 ? text.length : end + 2;
997
+ continue;
998
+ }
999
+ result.push(char);
1000
+ i += 1;
1001
+ }
1002
+ return result.join("");
1003
+ }
1004
+
1005
+ function findBalancedRegion(text, start, opening, closing) {
1006
+ if (start >= text.length || text[start] !== opening) {
1007
+ return null;
1008
+ }
1009
+ let depth = 0;
1010
+ let quote = null;
1011
+ let escape = false;
1012
+ for (let index = start; index < text.length; index += 1) {
1013
+ const char = text[index];
1014
+ if (escape) {
1015
+ escape = false;
1016
+ continue;
1017
+ }
1018
+ if (char === "\\") {
1019
+ escape = true;
1020
+ continue;
1021
+ }
1022
+ if (quote) {
1023
+ if (char === quote) {
1024
+ quote = null;
1025
+ }
1026
+ continue;
1027
+ }
1028
+ if (char === "'" || char === '"') {
1029
+ quote = char;
1030
+ continue;
1031
+ }
1032
+ if (char === opening) {
1033
+ depth += 1;
1034
+ } else if (char === closing) {
1035
+ depth -= 1;
1036
+ if (depth === 0) {
1037
+ return [text.slice(start + 1, index), index + 1];
1038
+ }
1039
+ }
1040
+ }
1041
+ return null;
1042
+ }
1043
+
1044
+ function extractBpModules(p) {
1045
+ const text = stripBpComments(readText(p));
1046
+ const modules = [];
1047
+ let index = 0;
1048
+ while (index < text.length) {
1049
+ const match = /\b([A-Za-z_][A-Za-z0-9_]*)\s*\{/.exec(text.slice(index));
1050
+ if (!match) {
1051
+ break;
1052
+ }
1053
+ const typeName = match[1];
1054
+ const absoluteStart = index + match.index;
1055
+ const brace = index + match.index + match[0].length - 1;
1056
+ const prefix = text.slice(index, absoluteStart);
1057
+ if ((prefix.match(/\{/g) ?? []).length !== (prefix.match(/\}/g) ?? []).length) {
1058
+ index = brace + 1;
1059
+ continue;
1060
+ }
1061
+ const balanced = findBalancedRegion(text, brace, "{", "}");
1062
+ if (!balanced) {
1063
+ break;
1064
+ }
1065
+ const [body, end] = balanced;
1066
+ const nameMatch = /\bname\s*:\s*['"]([^'"]+)['"]/.exec(body);
1067
+ if (nameMatch) {
1068
+ modules.push({
1069
+ type: typeName,
1070
+ name: nameMatch[1],
1071
+ body,
1072
+ build_file: p,
1073
+ directory: path.dirname(String(p)),
1074
+ });
1075
+ }
1076
+ index = end;
1077
+ }
1078
+ return modules;
1079
+ }
1080
+
1081
+ function bpListProperty(body, name) {
1082
+ const match = new RegExp(`\\b${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*:\\s*\\[`).exec(body);
1083
+ if (!match) {
1084
+ return [];
1085
+ }
1086
+ const start = body.indexOf("[", match.index);
1087
+ const balanced = findBalancedRegion(body, start, "[", "]");
1088
+ if (!balanced) {
1089
+ return [];
1090
+ }
1091
+ return [...balanced[0].matchAll(/['"]([^'"]+)['"]/g)].map((m) => m[1]);
1092
+ }
1093
+
1094
+ function bpStringProperty(body, name) {
1095
+ const match = new RegExp(`\\b${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*:\\s*['"]([^'"]+)['"]`).exec(body);
1096
+ return match ? match[1] : null;
1097
+ }
1098
+
1099
+ function classifyAospType(typeName) {
1100
+ const lowered = typeName.toLowerCase();
1101
+ if (lowered.startsWith("android_app") || ["android_test", "android_test_helper_app"].includes(lowered) || lowered.endsWith("_app")) {
1102
+ return "application";
1103
+ }
1104
+ if (
1105
+ lowered.includes("library")
1106
+ || ["aar_import", "java_sdk_library", "aidl_interface", "filegroup"].includes(lowered)
1107
+ || lowered.endsWith("_defaults")
1108
+ ) {
1109
+ return "library";
1110
+ }
1111
+ return "unknown";
1112
+ }
1113
+
1114
+ function parseAndroidMk(p) {
1115
+ const text = readText(p);
1116
+ const blocks = text.split(/include\s+\$\(CLEAR_VARS\)/);
1117
+ const result = [];
1118
+ for (const block of blocks.slice(1)) {
1119
+ const endMatch = /include\s+\$\((BUILD_[A-Z0-9_]+)\)/.exec(block);
1120
+ if (!endMatch) {
1121
+ continue;
1122
+ }
1123
+ const body = block.slice(0, endMatch.index);
1124
+ const buildType = endMatch[1];
1125
+ const nameMatch = /^\s*LOCAL_(?:PACKAGE_NAME|MODULE)\s*:?=\s*([^\s#]+)/m.exec(body);
1126
+ if (!nameMatch) {
1127
+ continue;
1128
+ }
1129
+ const moduleName = pyStrip(nameMatch[1]);
1130
+ const kind = buildType === "BUILD_PACKAGE"
1131
+ ? "application"
1132
+ : (buildType.includes("LIBRARY") || buildType.includes("AAR") ? "library" : "unknown");
1133
+ result.push({
1134
+ name: moduleName,
1135
+ type: buildType,
1136
+ kind,
1137
+ body,
1138
+ build_file: p,
1139
+ directory: path.dirname(String(p)),
1140
+ });
1141
+ }
1142
+ return result;
1143
+ }
1144
+
1145
+ function findSoongModuleGraph(repo) {
1146
+ const candidate = path.join(repo, "out", "soong", "module-graph.json");
1147
+ return pathExists(candidate) ? candidate : null;
1148
+ }
1149
+
1150
+ function discoverAospFromModuleGraph(repo, graphPath) {
1151
+ let raw;
1152
+ try {
1153
+ raw = parseStrictJson(readText(graphPath));
1154
+ } catch {
1155
+ return [[], {}];
1156
+ }
1157
+ if (!Array.isArray(raw)) {
1158
+ return [[], {}];
1159
+ }
1160
+ const modules = {};
1161
+ const deps = {};
1162
+ for (const entry of raw) {
1163
+ if (entry === null || typeof entry !== "object" || Array.isArray(entry)) {
1164
+ continue;
1165
+ }
1166
+ const name = String(entry.Name ?? "");
1167
+ if (name === "") {
1168
+ continue;
1169
+ }
1170
+ const typeName = String(entry.Type ?? "");
1171
+ const blueprint = String(entry.Blueprint ?? "");
1172
+ const buildFile = blueprint ? resolveLikePython(path.join(repo, blueprint)) : null;
1173
+ const buildFileExists = buildFile !== null && pathExists(buildFile);
1174
+ const directory = buildFile !== null && buildFileExists ? path.dirname(buildFile) : repo;
1175
+ const current = modules[name];
1176
+ const candidate = createModule(name, directory, classifyAospType(typeName), "aosp", typeName, buildFileExists ? buildFile : null);
1177
+ if (current === undefined || (current.directory === String(repo) && candidate.directory !== String(repo))) {
1178
+ modules[name] = candidate;
1179
+ }
1180
+ if (!(name in deps)) deps[name] = new Set();
1181
+ for (const dep of entry.Deps ?? []) {
1182
+ if (dep !== null && typeof dep === "object" && dep.Name) {
1183
+ deps[name].add(String(dep.Name));
1184
+ }
1185
+ }
1186
+ }
1187
+ const graph = {};
1188
+ for (const [name, values] of Object.entries(deps)) {
1189
+ graph[name] = [...values].filter((v) => v !== name).sort();
1190
+ }
1191
+ for (const name of Object.keys(modules)) {
1192
+ if (!(name in graph)) graph[name] = [];
1193
+ }
1194
+ const sorted = Object.values(modules).sort((a, b) => (a.module_id < b.module_id ? -1 : a.module_id > b.module_id ? 1 : 0));
1195
+ return [sorted, graph];
1196
+ }
1197
+
1198
+ function findModuleInfo(repo) {
1199
+ const base = path.join(repo, "out", "target", "product");
1200
+ if (!pathExists(base)) {
1201
+ return null;
1202
+ }
1203
+ const candidates = [];
1204
+ for (const name of fs.readdirSync(base).sort()) {
1205
+ const candidate = path.join(base, name, "module-info.json");
1206
+ if (pathExists(candidate)) {
1207
+ candidates.push(candidate);
1208
+ }
1209
+ }
1210
+ return candidates.length > 0 ? candidates[0] : null;
1211
+ }
1212
+
1213
+ function discoverAospFromModuleInfo(repo, p) {
1214
+ let raw;
1215
+ try {
1216
+ raw = parseStrictJson(readText(p));
1217
+ } catch {
1218
+ return [[], {}];
1219
+ }
1220
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
1221
+ return [[], {}];
1222
+ }
1223
+ const modules = [];
1224
+ const graph = {};
1225
+ for (const [name, info] of Object.entries(raw)) {
1226
+ if (info === null || typeof info !== "object" || Array.isArray(info)) {
1227
+ continue;
1228
+ }
1229
+ const paths = info.path ?? [];
1230
+ const relative = Array.isArray(paths) && paths.length > 0 ? String(paths[0]) : "";
1231
+ const directory = relative ? resolveLikePython(path.join(repo, relative)) : repo;
1232
+ const classes = new Set((info.class ?? []).map((value) => String(value).toUpperCase()));
1233
+ const kind = classes.has("APPS")
1234
+ ? "application"
1235
+ : (["JAVA_LIBRARIES", "SHARED_LIBRARIES", "STATIC_LIBRARIES", "HEADER_LIBRARIES"].some((c) => classes.has(c)) ? "library" : "unknown");
1236
+ const bpPath = path.join(directory, "Android.bp");
1237
+ const mkPath = path.join(directory, "Android.mk");
1238
+ const buildFile = pathExists(bpPath) ? bpPath : (pathExists(mkPath) ? mkPath : null);
1239
+ modules.push(createModule(String(name), directory, kind, "aosp", [...classes].sort().join(","), buildFile));
1240
+ const deps = pyOr(info.dependencies, info.required) ?? [];
1241
+ graph[String(name)] = Array.isArray(deps)
1242
+ ? [...new Set(deps.filter((dep) => dep && String(dep) !== String(name)).map((dep) => String(dep)))].sort()
1243
+ : [];
1244
+ }
1245
+ modules.sort((a, b) => (a.module_id < b.module_id ? -1 : a.module_id > b.module_id ? 1 : 0));
1246
+ return [modules, graph];
1247
+ }
1248
+
1249
+ function discoverAospStatic(repo) {
1250
+ const modules = {};
1251
+ const graph = {};
1252
+ const definitions = {};
1253
+ for (const child of walkAll(repo)) {
1254
+ if (path.basename(String(child)) !== "Android.bp" || pathIsExcluded(child)) {
1255
+ continue;
1256
+ }
1257
+ for (const definition of extractBpModules(child)) {
1258
+ definitions[definition.name] = definition;
1259
+ modules[definition.name] = createModule(
1260
+ definition.name, path.dirname(String(child)), classifyAospType(definition.type), "aosp", definition.type, child,
1261
+ );
1262
+ }
1263
+ }
1264
+ for (const child of walkAll(repo)) {
1265
+ if (path.basename(String(child)) !== "Android.mk" || pathIsExcluded(child)) {
1266
+ continue;
1267
+ }
1268
+ for (const definition of parseAndroidMk(child)) {
1269
+ if (!(definition.name in modules)) {
1270
+ definitions[definition.name] = definition;
1271
+ modules[definition.name] = createModule(
1272
+ definition.name, path.dirname(String(child)), definition.kind, "aosp", definition.type, child,
1273
+ );
1274
+ }
1275
+ }
1276
+ }
1277
+
1278
+ const dependencyProperties = [
1279
+ "static_libs", "libs", "shared_libs", "whole_static_libs", "header_libs",
1280
+ "jni_libs", "required", "defaults",
1281
+ ];
1282
+ for (const [name, definition] of Object.entries(definitions)) {
1283
+ if (!(name in graph)) graph[name] = new Set();
1284
+ if (path.basename(String(definition.build_file)) === "Android.bp") {
1285
+ const body = definition.body;
1286
+ for (const prop of dependencyProperties) {
1287
+ for (const value of bpListProperty(body, prop)) {
1288
+ graph[name].add(value);
1289
+ }
1290
+ }
1291
+ for (const value of bpListProperty(body, "srcs")) {
1292
+ if (value.startsWith(":")) {
1293
+ graph[name].add(value.slice(1).split("{", 1)[0]);
1294
+ }
1295
+ }
1296
+ } else {
1297
+ const body = definition.body;
1298
+ for (const prop of [
1299
+ "LOCAL_STATIC_JAVA_LIBRARIES", "LOCAL_JAVA_LIBRARIES", "LOCAL_SHARED_LIBRARIES",
1300
+ "LOCAL_STATIC_LIBRARIES", "LOCAL_REQUIRED_MODULES",
1301
+ ]) {
1302
+ const match = new RegExp(`^\\s*${prop}\\s*:?=\\s*(.+)$`, "m").exec(body);
1303
+ if (match) {
1304
+ for (const token of pyStrip(match[1]).split(/\s+/)) {
1305
+ if (token && !token.startsWith("$(")) {
1306
+ graph[name].add(token);
1307
+ }
1308
+ }
1309
+ }
1310
+ }
1311
+ }
1312
+ }
1313
+ const known = new Set(Object.keys(modules));
1314
+ const normalized = {};
1315
+ for (const [name, values] of Object.entries(graph)) {
1316
+ const filtered = [...values].filter((v) => known.has(v) && v !== name).sort();
1317
+ normalized[name] = filtered;
1318
+ }
1319
+ for (const name of known) {
1320
+ if (!(name in normalized)) normalized[name] = [];
1321
+ }
1322
+ const sorted = Object.values(modules).sort((a, b) => (a.module_id < b.module_id ? -1 : a.module_id > b.module_id ? 1 : 0));
1323
+ return [sorted, normalized];
1324
+ }
1325
+
1326
+ function discoverAospModules(repo) {
1327
+ const warnings = [];
1328
+ const graphPath = findSoongModuleGraph(repo);
1329
+ if (graphPath) {
1330
+ const [modules, graph] = discoverAospFromModuleGraph(repo, graphPath);
1331
+ if (modules.length > 0) {
1332
+ return [modules, graph, "configured", "authoritative", warnings];
1333
+ }
1334
+ }
1335
+ const moduleInfo = findModuleInfo(repo);
1336
+ if (moduleInfo) {
1337
+ const [modules, graph] = discoverAospFromModuleInfo(repo, moduleInfo);
1338
+ if (modules.length > 0) {
1339
+ warnings.push({
1340
+ code: "aosp_module_info_resolution",
1341
+ message: "AOSP module-info.json was used because a Soong module graph was not available; dependency completeness may be lower.",
1342
+ });
1343
+ return [modules, graph, "configured", "high", warnings];
1344
+ }
1345
+ }
1346
+ const [modules, graph] = discoverAospStatic(repo);
1347
+ if (modules.length > 0) {
1348
+ warnings.push({
1349
+ code: "aosp_static_resolution",
1350
+ message: "AOSP scope was resolved statically from Android.bp/Android.mk; configuration-dependent Soong branches may require semantic review.",
1351
+ });
1352
+ return [modules, graph, "static", "probable", warnings];
1353
+ }
1354
+ return [[], {}, "static", "inferred", warnings];
1355
+ }
1356
+
1357
+ function discoverGenericModules(repo) {
1358
+ const modules = {};
1359
+ for (const manifest of genericManifestCandidates(repo)) {
1360
+ const parent = path.dirname(String(manifest));
1361
+ let directory;
1362
+ if (path.basename(parent) === "main" && path.basename(path.dirname(parent)) === "src") {
1363
+ directory = path.dirname(path.dirname(parent));
1364
+ } else {
1365
+ directory = parent;
1366
+ }
1367
+ let relative = rel(directory, repo);
1368
+ if (relative.startsWith("..")) {
1369
+ relative = path.basename(String(directory));
1370
+ }
1371
+ const moduleId = relative !== "" && relative !== "." ? relative : path.basename(String(directory));
1372
+ modules[directory] = createModule(moduleId, directory, manifestKind(manifest), "generic", "manifest-inferred", null);
1373
+ }
1374
+ return Object.values(modules).sort((a, b) => (a.module_id < b.module_id ? -1 : a.module_id > b.module_id ? 1 : 0));
1375
+ }
1376
+
1377
+ function discoverBuild(repo, buildSystem, configuration) {
1378
+ if (buildSystem === "gradle") {
1379
+ const modules = discoverGradleModules(repo);
1380
+ return [modules, buildGradleGraph(modules), "static", "high", []];
1381
+ }
1382
+ if (buildSystem === "maven") {
1383
+ const modules = discoverMavenModules(repo, configuration);
1384
+ const warnings = [];
1385
+ if (configuration !== "auto") {
1386
+ warnings.push({
1387
+ code: "maven_profile_static_resolution",
1388
+ message: "The requested Maven profile was resolved from POM declarations only; environment-activated profile effects may require review.",
1389
+ profile: configuration,
1390
+ });
1391
+ }
1392
+ return [modules, buildMavenGraph(modules, configuration), "static", "high", warnings];
1393
+ }
1394
+ if (buildSystem === "aosp") {
1395
+ return discoverAospModules(repo);
1396
+ }
1397
+ const modules = discoverGenericModules(repo);
1398
+ const graph = {};
1399
+ for (const module of modules) {
1400
+ graph[module.module_id] = [];
1401
+ }
1402
+ return [modules, graph, "inferred", "inferred", [{
1403
+ code: "generic_android_resolution",
1404
+ message: "No supported build system was authoritatively resolved; Android source scope was inferred from manifests and conventional source layout.",
1405
+ }]];
1406
+ }
1407
+
1408
+ // ---------------------------------------------------------------------------
1409
+ // Module selection
1410
+ // ---------------------------------------------------------------------------
1411
+
1412
+ function moduleAliases(module, repo) {
1413
+ const aliases = new Set([module.module_id, path.basename(String(module.directory))]);
1414
+ const repoResolved = resolveLikePython(repo);
1415
+ const dirResolved = resolveLikePython(String(module.directory));
1416
+ const value = path.relative(repoResolved, dirResolved);
1417
+ if (!value.startsWith("..")) {
1418
+ const relative = value.split(path.sep).join("/");
1419
+ aliases.add(relative);
1420
+ aliases.add(relative.replace(/\//g, ":"));
1421
+ aliases.add(`:${relative.replace(/\//g, ":")}`);
1422
+ }
1423
+ if (module.module_id.startsWith(":")) {
1424
+ aliases.add(module.module_id.replace(/^:+/, ""));
1425
+ }
1426
+ if (module.module_id.includes(":")) {
1427
+ aliases.add(module.module_id.split(":").pop());
1428
+ }
1429
+ return new Set([...aliases].filter((v) => v !== ""));
1430
+ }
1431
+
1432
+ function requestedModuleMatches(modules, requested, repo) {
1433
+ requested = pyStrip(requested);
1434
+ if (requested === "auto") {
1435
+ return [];
1436
+ }
1437
+ const wanted = requested.split(",").map((item) => pyStrip(item)).filter((item) => item !== "");
1438
+ const selected = [];
1439
+ for (const token of wanted) {
1440
+ const exact = modules.filter((module) => moduleAliases(module, repo).has(token));
1441
+ if (exact.length > 1) {
1442
+ const names = exact.map((module) => module.module_id).sort().join(", ");
1443
+ systemExit(`Module selector is ambiguous: ${token}. Candidates: ${names}`);
1444
+ }
1445
+ if (exact.length === 0) {
1446
+ systemExit(`Requested module was not found: ${token}`);
1447
+ }
1448
+ if (!selected.includes(exact[0])) {
1449
+ selected.push(exact[0]);
1450
+ }
1451
+ }
1452
+ return selected;
1453
+ }
1454
+
1455
+ function dependencyClosure(start, modules, graph) {
1456
+ const byId = {};
1457
+ for (const module of modules) {
1458
+ byId[module.module_id] = module;
1459
+ }
1460
+ const queue = start.map((module) => module.module_id);
1461
+ const seen = new Set();
1462
+ while (queue.length > 0) {
1463
+ const current = queue.shift();
1464
+ if (seen.has(current)) {
1465
+ continue;
1466
+ }
1467
+ seen.add(current);
1468
+ for (const dep of graph[current] ?? []) {
1469
+ if (dep in byId && !seen.has(dep)) {
1470
+ queue.push(dep);
1471
+ }
1472
+ }
1473
+ }
1474
+ return [...seen].sort().filter((moduleId) => moduleId in byId).map((moduleId) => byId[moduleId]);
1475
+ }
1476
+
1477
+ function resolveProjectKind(modules, requestedKind, requestedModule, repo) {
1478
+ if (requestedKind === "application" || requestedKind === "library") {
1479
+ return requestedKind;
1480
+ }
1481
+ const explicit = pyStrip(requestedModule) !== "auto" ? requestedModuleMatches(modules, requestedModule, repo) : [];
1482
+ if (explicit.length > 0) {
1483
+ return explicit.every((module) => module.kind !== "application") ? "library" : "application";
1484
+ }
1485
+ return modules.some((module) => module.kind === "application") ? "application" : "library";
1486
+ }
1487
+
1488
+ function selectModules(modules, graph, requested, projectKind, repo, includeDependencyClosure) {
1489
+ const warnings = [];
1490
+ const explicit = pyStrip(requested) !== "auto" ? requestedModuleMatches(modules, requested, repo) : [];
1491
+ let roots;
1492
+ if (projectKind === "application") {
1493
+ if (explicit.length > 0) {
1494
+ roots = explicit;
1495
+ const invalid = roots.filter((module) => !["application", "unknown"].includes(module.kind)).map((module) => module.module_id);
1496
+ if (invalid.length > 0) {
1497
+ systemExit(`Requested module is not an Android application module: ${invalid.join(", ")}`);
1498
+ }
1499
+ } else {
1500
+ roots = modules.filter((module) => module.kind === "application");
1501
+ if (roots.length === 0) {
1502
+ systemExit("No Android application module could be identified.");
1503
+ }
1504
+ if (roots.length > 1) {
1505
+ const names = roots.map((module) => module.module_id).join(", ");
1506
+ systemExit(`Application scope is ambiguous. Specify --app-module. Candidates: ${names}`);
1507
+ }
1508
+ }
1509
+ } else if (explicit.length > 0) {
1510
+ roots = explicit;
1511
+ const invalid = roots.filter((module) => module.kind === "application").map((module) => module.module_id);
1512
+ if (invalid.length > 0) {
1513
+ systemExit(`Requested module is not an Android library module: ${invalid.join(", ")}`);
1514
+ }
1515
+ } else {
1516
+ const candidates = modules.filter((module) => module.kind === "library");
1517
+ const harness = candidates.filter((module) => HARNESS_MODULE_NAME_PATTERN.test(module.module_id));
1518
+ roots = candidates.filter((module) => !harness.includes(module));
1519
+ if (roots.length === 0) {
1520
+ systemExit("No Android library module could be identified. Specify --app-module explicitly.");
1521
+ }
1522
+ if (harness.length > 0) {
1523
+ warnings.push({
1524
+ code: "excluded_harness_library_modules",
1525
+ message: "Library modules that appear to be sample/demo harnesses were excluded from automatic selection.",
1526
+ modules: harness.map((module) => module.module_id).sort(),
1527
+ });
1528
+ }
1529
+ }
1530
+ const selected = includeDependencyClosure ? dependencyClosure(roots, modules, graph) : roots;
1531
+ return [selected, warnings];
1532
+ }
1533
+
1534
+ function rootContainsModule(root, requested, buildSystem, configuration) {
1535
+ if (pyStrip(requested) === "auto") {
1536
+ return true;
1537
+ }
1538
+ const [modules] = discoverBuild(root, buildSystem, configuration);
1539
+ try {
1540
+ return requestedModuleMatches(modules, requested, root).length > 0;
1541
+ } catch {
1542
+ return false;
1543
+ }
1544
+ }
1545
+
1546
+ function resolveEffectiveRepo(inputRepo, requestedModule, requestedBuildSystem, configuration) {
1547
+ const detected = detectBuildSystem(inputRepo, requestedBuildSystem);
1548
+ if (detected) {
1549
+ return [inputRepo, detected];
1550
+ }
1551
+
1552
+ const candidates = [];
1553
+ for (const candidate of candidateAndroidRoots(inputRepo)) {
1554
+ const system = detectBuildSystem(candidate, requestedBuildSystem);
1555
+ if (system) {
1556
+ candidates.push([candidate, system]);
1557
+ }
1558
+ }
1559
+ if (candidates.length === 0) {
1560
+ if ((requestedBuildSystem === "auto" || requestedBuildSystem === "generic") && genericManifestCandidates(inputRepo).length > 0) {
1561
+ return [inputRepo, "generic"];
1562
+ }
1563
+ systemExit("No supported Android project was found under the selected directory.");
1564
+ }
1565
+
1566
+ if (pyStrip(requestedModule) !== "auto") {
1567
+ const matching = candidates.filter(
1568
+ ([candidate, system]) => rootContainsModule(candidate, requestedModule, system, configuration),
1569
+ );
1570
+ if (matching.length === 1) {
1571
+ return matching[0];
1572
+ }
1573
+ if (matching.length > 1) {
1574
+ const formatted = matching.map(([p, system]) => ` - ${p} (${system})`).join("\n");
1575
+ systemExit(`The requested module exists in several Android projects. Select a more specific repository:\n${formatted}`);
1576
+ }
1577
+ }
1578
+
1579
+ const unique = [];
1580
+ const seen = new Set();
1581
+ for (const item of candidates) {
1582
+ if (!seen.has(String(item[0]))) {
1583
+ unique.push(item);
1584
+ seen.add(String(item[0]));
1585
+ }
1586
+ }
1587
+ if (unique.length === 1) {
1588
+ return unique[0];
1589
+ }
1590
+ const formatted = unique.map(([p, system]) => ` - ${p} (${system})`).join("\n");
1591
+ systemExit(`Several Android projects were found. Select a more specific repository or app module:\n${formatted}`);
1592
+ }
1593
+
1594
+ // ---------------------------------------------------------------------------
1595
+ // Source scope resolution
1596
+ // ---------------------------------------------------------------------------
1597
+
1598
+ function splitCamel(value) {
1599
+ return [...value.matchAll(/[A-Z]?[a-z]+|[A-Z]+(?![a-z])|\d+/g)].map((m) => m[0].toLowerCase());
1600
+ }
1601
+
1602
+ function pyStartsWithAny(name, prefixes) {
1603
+ return prefixes.some((prefix) => name.startsWith(prefix));
1604
+ }
1605
+
1606
+ // Directories a Gradle build script declares for the `main` source set, e.g.
1607
+ // sourceSets { main { java.srcDirs = ['src']; res.srcDirs = ['res']
1608
+ // manifest.srcFile 'AndroidManifest.xml' } }
1609
+ // sourceSets.main.java.srcDirs += "src/extra"
1610
+ // Returns absolute paths that exist; [] when nothing is declared.
1611
+ export function gradleMainSourceDirs(buildText, moduleDir) {
1612
+ const text = buildText.replace(/\/\*[\s\S]*?\*\//g, " ").replace(/(^|[^:])\/\/.*$/gm, "$1");
1613
+ const bodies = [];
1614
+ for (const match of text.matchAll(/\bsourceSets\s*\{/g)) {
1615
+ const block = findBalanced(text, match.index + match[0].length - 1, "{", "}");
1616
+ if (!block) continue;
1617
+ for (const main of block[0].matchAll(/(?:^|[\s;{])(?:main|getByName\(\s*["']main["']\s*\)|named\(\s*["']main["']\s*\))\s*\{/g)) {
1618
+ const inner = findBalanced(block[0], main.index + main[0].length - 1, "{", "}");
1619
+ if (inner) bodies.push(inner[0]);
1620
+ }
1621
+ for (const dotted of block[0].matchAll(/\bmain\.[^\n;]+/g)) bodies.push(dotted[0].slice("main.".length));
1622
+ }
1623
+ for (const dotted of text.matchAll(/\bsourceSets\.(?:main|getByName\(\s*["']main["']\s*\))\.([^\n;]+)/g)) {
1624
+ bodies.push(dotted[1]);
1625
+ }
1626
+ const found = new Set();
1627
+ const addAll = (fragment) => {
1628
+ for (const literal of fragment.matchAll(/["']([^"'$]+)["']/g)) {
1629
+ const candidate = path.resolve(moduleDir, literal[1]);
1630
+ if (pathExists(candidate)) found.add(candidate);
1631
+ }
1632
+ };
1633
+ for (const body of bodies) {
1634
+ for (const decl of body.matchAll(/\b(?:java|kotlin|res|resources|assets|aidl|jniLibs|renderscript)\s*(?:\.|\{\s*)(?:setSrcDirs\s*\(|srcDirs?\s*(?:\+?=)?\s*\(?)([^\n}]*)/g)) {
1635
+ addAll(decl[1]);
1636
+ }
1637
+ for (const decl of body.matchAll(/\bmanifest\s*(?:\.|\{\s*)srcFile\s*(?:=\s*)?\(?\s*(?:file\s*\(\s*)?(["'][^"']+["'])/g)) {
1638
+ addAll(decl[1]);
1639
+ }
1640
+ }
1641
+ return [...found].sort();
1642
+ }
1643
+
1644
+ function resolveGradleSourceScopes(module, variant) {
1645
+ const warnings = [];
1646
+ const sourceRoot = path.join(module.directory, "src");
1647
+ const declared = [];
1648
+ for (const name of ["build.gradle", "build.gradle.kts"]) {
1649
+ const buildFile = path.join(module.directory, name);
1650
+ if (isFile(buildFile)) {
1651
+ declared.push(...gradleMainSourceDirs(readText(buildFile), module.directory));
1652
+ }
1653
+ }
1654
+ if (declared.length > 0) {
1655
+ // Non-standard layout: the build script's sourceSets win. Keep any
1656
+ // conventional src/<set> dirs that are not already covered.
1657
+ const covered = (p) => declared.some((d) => p === d || pathIsWithin(p, d));
1658
+ const extra = pathExists(sourceRoot) && !declared.includes(sourceRoot)
1659
+ ? fs.readdirSync(sourceRoot, { withFileTypes: true })
1660
+ .filter((entry) => entry.isDirectory()
1661
+ && !TEST_SOURCE_SETS.has(entry.name)
1662
+ && !pyStartsWithAny(entry.name.toLowerCase(), ["test", "androidtest", "benchmark"]))
1663
+ .map((entry) => path.join(sourceRoot, entry.name))
1664
+ .filter((p) => !covered(p))
1665
+ : [];
1666
+ warnings.push({
1667
+ code: "gradle_declared_source_sets",
1668
+ message: "The module declares sourceSets.main directories in its build script; those were scanned instead of the src/<set> convention.",
1669
+ module: module.module_id,
1670
+ source_dirs: declared.map((p) => relOrAbs(p, module.directory)),
1671
+ });
1672
+ const scopes = [
1673
+ ...declared.map((p) => ({ path: p, label: "main" })),
1674
+ ...extra.map((p) => ({ path: p, label: path.basename(p) })),
1675
+ ].sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
1676
+ return [scopes, warnings];
1677
+ }
1678
+ if (!pathExists(sourceRoot)) {
1679
+ return [[], warnings];
1680
+ }
1681
+ let candidates = fs.readdirSync(sourceRoot, { withFileTypes: true })
1682
+ .filter((entry) => entry.isDirectory())
1683
+ .map((entry) => path.join(sourceRoot, entry.name));
1684
+ candidates = candidates.filter((p) => {
1685
+ const name = path.basename(p);
1686
+ return !TEST_SOURCE_SETS.has(name)
1687
+ && !pyStartsWithAny(name.toLowerCase(), ["test", "androidtest", "benchmark"]);
1688
+ });
1689
+ const byLower = {};
1690
+ for (const p of candidates) {
1691
+ byLower[path.basename(p).toLowerCase()] = p;
1692
+ }
1693
+ if (variant === "auto") {
1694
+ const nonMain = candidates.map((p) => path.basename(p)).filter((name) => name !== "main").sort();
1695
+ if (nonMain.length > 0) {
1696
+ warnings.push({
1697
+ code: "variant_union_scope",
1698
+ message: "Auto variant includes all non-test source sets. Mutually exclusive behavior must remain conditional during semantic review.",
1699
+ module: module.module_id,
1700
+ source_sets: nonMain,
1701
+ });
1702
+ }
1703
+ const sorted = candidates.map((p) => ({ path: p, label: path.basename(p) }))
1704
+ .sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
1705
+ return [sorted, warnings];
1706
+ }
1707
+
1708
+ const requested = variant.toLowerCase();
1709
+ const selectedNames = new Set(["main"]);
1710
+ if (requested in byLower) {
1711
+ selectedNames.add(requested);
1712
+ }
1713
+ const parts = splitCamel(variant);
1714
+ for (const name of Object.keys(byLower)) {
1715
+ if (name === "main") {
1716
+ continue;
1717
+ }
1718
+ if (parts.includes(name) || requested.startsWith(name) || requested.endsWith(name)) {
1719
+ selectedNames.add(name);
1720
+ }
1721
+ }
1722
+ const selected = [...selectedNames].filter((name) => name in byLower).map((name) => byLower[name]);
1723
+ if (!(requested in byLower)) {
1724
+ warnings.push({
1725
+ code: "variant_resolution_inferred",
1726
+ message: "The exact variant source set was absent; source-set components were inferred from directory names.",
1727
+ module: module.module_id,
1728
+ variant,
1729
+ selected_source_sets: selected.map((p) => path.basename(p)).sort(),
1730
+ });
1731
+ }
1732
+ if (selected.length === 1 && path.basename(selected[0]) === "main") {
1733
+ warnings.push({
1734
+ code: "variant_components_not_found",
1735
+ message: "No source-set component of the requested variant was found; only main is in scope.",
1736
+ module: module.module_id,
1737
+ variant,
1738
+ });
1739
+ }
1740
+ const sorted = selected.map((p) => ({ path: p, label: path.basename(p) }))
1741
+ .sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
1742
+ return [sorted, warnings];
1743
+ }
1744
+
1745
+ function mavenBuildSourceDirs(pom, profile) {
1746
+ const root = pomRoot(pom);
1747
+ if (root === null) {
1748
+ return [];
1749
+ }
1750
+ const result = [];
1751
+
1752
+ const collect = (container) => {
1753
+ const build = container !== null ? xmlFirst(container, "build") : null;
1754
+ const sourceDirectory = xmlChildText(build, "sourceDirectory");
1755
+ if (sourceDirectory) {
1756
+ result.push(resolveLikePython(path.join(path.dirname(String(pom)), sourceDirectory)));
1757
+ }
1758
+ const resources = xmlFirst(build, "resources");
1759
+ for (const resource of xmlChildren(resources, "resource")) {
1760
+ const directory = xmlChildText(resource, "directory");
1761
+ if (directory) {
1762
+ result.push(resolveLikePython(path.join(path.dirname(String(pom)), directory)));
1763
+ }
1764
+ }
1765
+ };
1766
+
1767
+ collect(root);
1768
+ if (profile !== "auto") {
1769
+ const profiles = xmlFirst(root, "profiles");
1770
+ for (const item of xmlChildren(profiles, "profile")) {
1771
+ if (xmlChildText(item, "id") === profile) {
1772
+ collect(item);
1773
+ }
1774
+ }
1775
+ }
1776
+ return result;
1777
+ }
1778
+
1779
+ function resolveMavenSourceScopes(module, profile) {
1780
+ const warnings = [];
1781
+ const paths = [];
1782
+ const main = path.join(module.directory, "src", "main");
1783
+ if (pathExists(main)) {
1784
+ paths.push(main);
1785
+ }
1786
+ for (const p of mavenBuildSourceDirs(module.build_file ?? path.join(module.directory, "pom.xml"), profile)) {
1787
+ if (pathExists(p)) {
1788
+ paths.push(p);
1789
+ }
1790
+ }
1791
+ if (paths.length === 0) {
1792
+ for (const name of ["src", "res"]) {
1793
+ const candidate = path.join(module.directory, name);
1794
+ if (pathExists(candidate)) {
1795
+ paths.push(candidate);
1796
+ }
1797
+ }
1798
+ }
1799
+ const unique = [];
1800
+ const seen = new Set();
1801
+ for (const p of paths) {
1802
+ const resolved = resolveLikePython(String(p));
1803
+ if (!seen.has(resolved)) {
1804
+ seen.add(resolved);
1805
+ unique.push(resolved);
1806
+ }
1807
+ }
1808
+ return [unique.map((p) => ({ path: p, label: path.basename(p) })), warnings];
1809
+ }
1810
+
1811
+ function expandAospPath(base, value) {
1812
+ if (value.startsWith(":")) {
1813
+ return [];
1814
+ }
1815
+ value = value.replace("$(LOCAL_PATH)/", "");
1816
+ if (value.includes("$")) {
1817
+ return [];
1818
+ }
1819
+ if (/[*?\[]/.test(value)) {
1820
+ try {
1821
+ return globPattern(String(base), value).filter((p) => pathExists(p));
1822
+ } catch {
1823
+ return [];
1824
+ }
1825
+ }
1826
+ const candidate = resolveLikePython(path.join(base, value));
1827
+ return pathExists(candidate) ? [candidate] : [];
1828
+ }
1829
+
1830
+ function resolveAospSourceScopes(module) {
1831
+ const warnings = [];
1832
+ const paths = [];
1833
+ const buildFile = module.build_file;
1834
+ let explicitSources = false;
1835
+ let explicitResources = false;
1836
+ let unresolvedSources = false;
1837
+ if (buildFile && path.basename(String(buildFile)) === "Android.bp") {
1838
+ const definitions = extractBpModules(buildFile).filter((item) => item.name === module.module_id);
1839
+ if (definitions.length > 0) {
1840
+ const body = definitions[0].body;
1841
+ const manifest = bpStringProperty(body, "manifest");
1842
+ if (manifest) {
1843
+ for (const p of expandAospPath(module.directory, manifest)) {
1844
+ paths.push([p, "@manifest"]);
1845
+ }
1846
+ } else if (module.kind === "application" && pathExists(path.join(module.directory, "AndroidManifest.xml"))) {
1847
+ paths.push([path.join(module.directory, "AndroidManifest.xml"), "@manifest"]);
1848
+ }
1849
+ const srcValues = bpListProperty(body, "srcs");
1850
+ for (const value of srcValues) {
1851
+ const expanded = expandAospPath(module.directory, value);
1852
+ if (expanded.length > 0) {
1853
+ explicitSources = true;
1854
+ }
1855
+ for (const p of expanded) {
1856
+ paths.push([p, "@soong-src"]);
1857
+ }
1858
+ }
1859
+ for (const prop of ["resource_dirs", "asset_dirs"]) {
1860
+ for (const value of bpListProperty(body, prop)) {
1861
+ const expanded = expandAospPath(module.directory, value);
1862
+ if (expanded.length > 0) {
1863
+ explicitResources = true;
1864
+ }
1865
+ for (const p of expanded) {
1866
+ paths.push([p, "@soong-resource"]);
1867
+ }
1868
+ }
1869
+ }
1870
+ unresolvedSources = /\bsrcs\s*:\s*(?!\[)/.test(body) && srcValues.length === 0;
1871
+ if (unresolvedSources) {
1872
+ warnings.push({
1873
+ code: "aosp_source_expression_unresolved",
1874
+ module: module.module_id,
1875
+ message: "A Soong srcs expression could not be statically expanded; conventional source directories were included as a fallback.",
1876
+ });
1877
+ }
1878
+ }
1879
+ } else if (buildFile && path.basename(String(buildFile)) === "Android.mk") {
1880
+ const definitions = parseAndroidMk(buildFile).filter((item) => item.name === module.module_id);
1881
+ if (definitions.length > 0) {
1882
+ const body = definitions[0].body;
1883
+ const manifestMatch = /^\s*LOCAL_MANIFEST_FILE\s*:?=\s*([^\s#]+)/m.exec(body);
1884
+ if (manifestMatch || module.kind === "application") {
1885
+ const manifestValue = manifestMatch ? manifestMatch[1] : "AndroidManifest.xml";
1886
+ for (const p of expandAospPath(module.directory, manifestValue)) {
1887
+ paths.push([p, "@manifest"]);
1888
+ }
1889
+ }
1890
+ const srcMatch = /^\s*LOCAL_SRC_FILES\s*:?=\s*(.+)$/m.exec(body);
1891
+ if (srcMatch) {
1892
+ for (const token of pyStrip(srcMatch[1]).split(/\s+/)) {
1893
+ const expanded = expandAospPath(module.directory, token);
1894
+ if (expanded.length > 0) {
1895
+ explicitSources = true;
1896
+ }
1897
+ for (const p of expanded) {
1898
+ paths.push([p, "@make-src"]);
1899
+ }
1900
+ }
1901
+ }
1902
+ }
1903
+ warnings.push({
1904
+ code: "aosp_make_static_scope",
1905
+ module: module.module_id,
1906
+ message: "Android.mk source expansion is conservative; Make macros may require semantic review.",
1907
+ });
1908
+ }
1909
+
1910
+ if (!explicitSources || unresolvedSources) {
1911
+ for (const name of ["src", "java", "kotlin", "aidl", "jni"]) {
1912
+ const candidate = path.join(module.directory, name);
1913
+ if (pathExists(candidate)) {
1914
+ paths.push([candidate, "@conventional"]);
1915
+ }
1916
+ }
1917
+ }
1918
+ if (!explicitResources) {
1919
+ for (const name of ["res", "assets"]) {
1920
+ const candidate = path.join(module.directory, name);
1921
+ if (pathExists(candidate)) {
1922
+ paths.push([candidate, "@conventional"]);
1923
+ }
1924
+ }
1925
+ }
1926
+ const unique = {};
1927
+ for (const [p, label] of paths) {
1928
+ unique[resolveLikePython(String(p))] = label;
1929
+ }
1930
+ const sorted = Object.entries(unique)
1931
+ .map(([p, label]) => ({ path: p, label }))
1932
+ .sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
1933
+ return [sorted, warnings];
1934
+ }
1935
+
1936
+ function resolveGenericSourceScopes(module) {
1937
+ const main = path.join(module.directory, "src", "main");
1938
+ if (pathExists(main)) {
1939
+ return [[{ path: main, label: "main" }], []];
1940
+ }
1941
+ return [[{ path: module.directory, label: "@inferred" }], [{
1942
+ code: "generic_module_scope_inferred",
1943
+ module: module.module_id,
1944
+ message: "The module source scope was inferred from the manifest directory.",
1945
+ }]];
1946
+ }
1947
+
1948
+ function resolveSourceScopes(module, configuration) {
1949
+ if (module.build_system === "gradle") {
1950
+ return resolveGradleSourceScopes(module, configuration);
1951
+ }
1952
+ if (module.build_system === "maven") {
1953
+ return resolveMavenSourceScopes(module, configuration);
1954
+ }
1955
+ if (module.build_system === "aosp") {
1956
+ return resolveAospSourceScopes(module);
1957
+ }
1958
+ return resolveGenericSourceScopes(module);
1959
+ }
1960
+
1961
+ function pathIsWithin(p, parent) {
1962
+ const value = path.relative(resolveLikePython(parent), resolveLikePython(p));
1963
+ return value !== "" && !value.startsWith("..");
1964
+ }
1965
+
1966
+ function projectBuildFiles(repo, buildSystem) {
1967
+ if (buildSystem === "gradle") {
1968
+ return [
1969
+ "settings.gradle", "settings.gradle.kts", "build.gradle", "build.gradle.kts",
1970
+ "gradle.properties", "gradle/libs.versions.toml",
1971
+ ].map((name) => path.join(repo, name));
1972
+ }
1973
+ if (buildSystem === "maven") {
1974
+ return [path.join(repo, "pom.xml")];
1975
+ }
1976
+ if (buildSystem === "aosp") {
1977
+ return [path.join(repo, "Android.bp"), path.join(repo, "Android.mk")];
1978
+ }
1979
+ return [];
1980
+ }
1981
+
1982
+ function admittedFiles(repo, modules, sourceScopes, artifactsDir, formalDocuments, buildSystem) {
1983
+ const records = {};
1984
+
1985
+ const include = (p, module, sourceSet) => {
1986
+ if (!isFile(p) || (!RELEVANT_EXTENSIONS.has(suffixOf(path.basename(String(p)))) && !NATIVE_BUILD_FILES.has(path.basename(String(p))))) {
1987
+ return;
1988
+ }
1989
+ if (pathIsExcluded(p)) {
1990
+ return;
1991
+ }
1992
+ const resolved = resolveLikePython(String(p));
1993
+ if (pathIsWithin(resolved, artifactsDir) || formalDocuments.has(resolved)) {
1994
+ return;
1995
+ }
1996
+ if (GENERATED_DOCUMENTS.has(path.basename(String(p)))) {
1997
+ return;
1998
+ }
1999
+ let relative;
2000
+ try {
2001
+ relative = rel(p, repo);
2002
+ } catch {
2003
+ return;
2004
+ }
2005
+ if (relative.startsWith("..")) {
2006
+ return;
2007
+ }
2008
+ records[relative] = { path: relative, module, source_set: sourceSet };
2009
+ };
2010
+
2011
+ for (const p of projectBuildFiles(repo, buildSystem)) {
2012
+ include(p, "@project", "@project");
2013
+ }
2014
+
2015
+ for (const module of modules) {
2016
+ if (module.build_file) {
2017
+ include(module.build_file, module.module_id, "@module");
2018
+ }
2019
+ if (module.build_system === "gradle") {
2020
+ for (const name of ["build.gradle", "build.gradle.kts", "gradle.properties"]) {
2021
+ include(path.join(module.directory, name), module.module_id, "@module");
2022
+ }
2023
+ } else if (module.build_system === "maven") {
2024
+ include(path.join(module.directory, "pom.xml"), module.module_id, "@module");
2025
+ }
2026
+ for (const sourceScope of sourceScopes[module.module_id] ?? []) {
2027
+ if (isFile(sourceScope.path)) {
2028
+ include(sourceScope.path, module.module_id, sourceScope.label);
2029
+ } else if (isDir(sourceScope.path)) {
2030
+ for (const child of walkAll(sourceScope.path)) {
2031
+ include(child, module.module_id, sourceScope.label);
2032
+ }
2033
+ }
2034
+ }
2035
+ const schemaDir = path.join(module.directory, "schemas");
2036
+ if (pathExists(schemaDir)) {
2037
+ for (const child of walkAll(schemaDir)) {
2038
+ if (path.basename(String(child)).endsWith(".json")) {
2039
+ include(child, module.module_id, "@room-schema");
2040
+ }
2041
+ }
2042
+ }
2043
+ }
2044
+ return Object.keys(records).sort().map((key) => records[key]);
2045
+ }
2046
+
2047
+ // ---------------------------------------------------------------------------
2048
+ // Surface scanning
2049
+ // ---------------------------------------------------------------------------
2050
+
2051
+ function itemKey(item) {
2052
+ return pyJsonDump(
2053
+ [item.kind ?? null, item.source_path ?? null, item.symbol ?? null, item.module ?? null, item.source_set ?? null],
2054
+ { indent: null, sortKeys: true },
2055
+ );
2056
+ }
2057
+
2058
+ function dedupe(items) {
2059
+ const result = {};
2060
+ for (const item of items) {
2061
+ result[itemKey(item)] = item;
2062
+ }
2063
+ return Object.keys(result).sort().map((key) => result[key]);
2064
+ }
2065
+
2066
+ function normalizeDeclaration(value) {
2067
+ return value.replace(/\s+/g, " ").trim().slice(0, 800);
2068
+ }
2069
+
2070
+ function addSurface(bucket, record, kind, symbol, declaration, confidence = "high", reviewRequired = false) {
2071
+ bucket.push({
2072
+ kind,
2073
+ symbol,
2074
+ source_path: record.path,
2075
+ module: record.module,
2076
+ source_set: record.source_set,
2077
+ declaration: normalizeDeclaration(declaration),
2078
+ confidence,
2079
+ review_required: reviewRequired,
2080
+ });
2081
+ }
2082
+
2083
+ function scanManifest(p, record, result) {
2084
+ let root;
2085
+ try {
2086
+ root = parseXmlFile(p);
2087
+ } catch (exc) {
2088
+ result.warnings.push({ code: "manifest_parse_error", source_path: record.path, message: String(exc && exc.message ? exc.message : exc) });
2089
+ return;
2090
+ }
2091
+ const componentTags = new Set(["activity", "activity-alias", "service", "receiver", "provider"]);
2092
+ for (const element of root.iter()) {
2093
+ const tag = localName(element.tag);
2094
+ if (componentTags.has(tag)) {
2095
+ const name = element.attrib[`${ANDROID_NS}name`] ?? "<unnamed>";
2096
+ const exported = element.attrib[`${ANDROID_NS}exported`];
2097
+ const target = ["activity", "activity-alias"].includes(tag)
2098
+ ? "entry_points"
2099
+ : (tag === "service" ? "background_capabilities" : "system_integrations");
2100
+ const declaration = etToString(element);
2101
+ addSurface(result[target], record, `Manifest${pyTitle(tag)}`, name, declaration);
2102
+ if (exported === "true") {
2103
+ addSurface(result.system_integrations, record, "ExportedComponent", name, declaration);
2104
+ }
2105
+ if (tag === "provider") {
2106
+ const authorities = element.attrib[`${ANDROID_NS}authorities`] ?? "";
2107
+ if (name.endsWith("InitProvider") || authorities.includes("androidx-startup")) {
2108
+ addSurface(result.system_integrations, record, "LibraryAutoInitProvider", name, declaration, "medium", true);
2109
+ }
2110
+ }
2111
+ for (const intentFilter of element.children.filter((child) => localName(child.tag) === "intent-filter")) {
2112
+ const actions = intentFilter.children
2113
+ .filter((child) => localName(child.tag) === "action")
2114
+ .map((child) => child.attrib[`${ANDROID_NS}name`] ?? "");
2115
+ const categories = intentFilter.children
2116
+ .filter((child) => localName(child.tag) === "category")
2117
+ .map((child) => child.attrib[`${ANDROID_NS}name`] ?? "");
2118
+ const dataItems = intentFilter.children
2119
+ .filter((child) => localName(child.tag) === "data")
2120
+ .map((child) => {
2121
+ const item = {};
2122
+ for (const [key, value] of Object.entries(child.attrib)) {
2123
+ item[localName(key)] = value;
2124
+ }
2125
+ return item;
2126
+ });
2127
+ const payload = pyJsonDump(
2128
+ { component: name, actions, categories, data: dataItems },
2129
+ { indent: null, sortKeys: true },
2130
+ );
2131
+ let kind;
2132
+ if (categories.includes("android.intent.category.LAUNCHER")) {
2133
+ kind = "Launcher";
2134
+ } else if (dataItems.length > 0) {
2135
+ kind = "DeepLink";
2136
+ } else {
2137
+ kind = "IntentEntry";
2138
+ }
2139
+ addSurface(result.entry_points, record, kind, name, payload);
2140
+ }
2141
+ } else if (["uses-permission", "permission", "uses-feature", "queries"].includes(tag)) {
2142
+ const name = element.attrib[`${ANDROID_NS}name`] ?? tag;
2143
+ addSurface(result.platform_configurations, record, tag, name, etToString(element));
2144
+ }
2145
+ }
2146
+ }
2147
+
2148
+ function scanNavigation(p, record, result) {
2149
+ let root;
2150
+ try {
2151
+ root = parseXmlFile(p);
2152
+ } catch (exc) {
2153
+ result.warnings.push({ code: "navigation_parse_error", source_path: record.path, message: String(exc && exc.message ? exc.message : exc) });
2154
+ return;
2155
+ }
2156
+ for (const element of root.iter()) {
2157
+ const tag = localName(element.tag);
2158
+ if (["fragment", "activity", "dialog", "navigation", "composable"].includes(tag)) {
2159
+ const symbol = attr(element, "id") ?? attr(element, "name") ?? tag;
2160
+ addSurface(result.entry_points, record, `Navigation${pyTitle(tag)}`, symbol, etToString(element));
2161
+ } else if (tag === "deepLink") {
2162
+ let uri = attr(element, "uri");
2163
+ if (uri === null) {
2164
+ const item = {};
2165
+ for (const [key, value] of Object.entries(element.attrib)) {
2166
+ item[localName(key)] = value;
2167
+ }
2168
+ uri = pyJsonDump(item, { indent: null, sortKeys: true, ensureAscii: true });
2169
+ }
2170
+ addSurface(result.entry_points, record, "DeepLink", uri, etToString(element));
2171
+ }
2172
+ }
2173
+ }
2174
+
2175
+ function scanSourceSurfaces(p, record, result) {
2176
+ const pBasename = path.basename(String(p));
2177
+ const pSuffix = suffixOf(pBasename);
2178
+ if (NATIVE_SUFFIXES.has(pSuffix)) {
2179
+ addSurface(result.system_integrations, record, "NativeSource", pBasename, pBasename, "medium", true);
2180
+ return;
2181
+ }
2182
+ if (NATIVE_BUILD_FILES.has(pBasename)) {
2183
+ addSurface(result.platform_configurations, record, "NativeBuildConfiguration", pBasename, readText(p).slice(0, 800), "medium", true);
2184
+ return;
2185
+ }
2186
+ if (!SOURCE_SUFFIXES.has(pSuffix)) {
2187
+ return;
2188
+ }
2189
+ const text = readText(p);
2190
+ const stem = pBasename.slice(0, pBasename.length - pSuffix.length);
2191
+ const classPattern = /\b(class|object)\s+(\w+)[^\n{]*(?::|extends)\s*([^\n{]+)/g;
2192
+ for (const match of text.matchAll(classPattern)) {
2193
+ const name = match[2];
2194
+ const bases = match[3];
2195
+ for (const [base, [bucket, kind]] of Object.entries(COMPONENT_BASES)) {
2196
+ if (new RegExp(`\\b${base.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`).test(bases)) {
2197
+ addSurface(result[bucket], record, kind, name, match[0]);
2198
+ break;
2199
+ }
2200
+ }
2201
+ }
2202
+
2203
+ for (const match of text.matchAll(/\b(composable|dialog|navigation)\s*\(\s*(['"])(.*?)\2/gs)) {
2204
+ addSurface(result.entry_points, record, `Compose${pyTitle(match[1])}`, match[3], match[0]);
2205
+ }
2206
+ for (const match of text.matchAll(/\b(composable|dialog|navigation)\s*\(([^\n)]*)/g)) {
2207
+ const argument = pyStrip(match[2]);
2208
+ if (argument !== "" && !argument.startsWith("'") && !argument.startsWith('"')) {
2209
+ addSurface(result.dynamic_review_candidates, record, "DynamicComposeRoute", stem, match[0], "medium", true);
2210
+ }
2211
+ }
2212
+
2213
+ for (const [kind, pattern] of Object.entries(BACKGROUND_PATTERNS)) {
2214
+ for (const match of text.matchAll(pattern)) {
2215
+ addSurface(result.background_capabilities, record, kind, `${stem}:${kind}`, match[0], "medium");
2216
+ break;
2217
+ }
2218
+ }
2219
+ for (const [kind, pattern] of Object.entries(SYSTEM_PATTERNS)) {
2220
+ for (const match of text.matchAll(pattern)) {
2221
+ addSurface(result.system_integrations, record, kind, `${stem}:${kind}`, match[0], "medium", kind === "BinderIntegration" || kind === "NativeIntegration");
2222
+ break;
2223
+ }
2224
+ }
2225
+ for (const [kind, pattern] of Object.entries(DYNAMIC_PATTERNS)) {
2226
+ for (const match of text.matchAll(pattern)) {
2227
+ addSurface(result.dynamic_review_candidates, record, kind, `${stem}:${kind}`, match[0], "medium", true);
2228
+ break;
2229
+ }
2230
+ }
2231
+
2232
+ for (const match of text.matchAll(APP_STARTUP_INITIALIZER_PATTERN)) {
2233
+ addSurface(result.system_integrations, record, "AppStartupInitializer", match[1], match[0], "medium", true);
2234
+ }
2235
+ }
2236
+
2237
+ function scanPublicApiSurface(p, record, result) {
2238
+ const pBasename = path.basename(String(p));
2239
+ const pSuffix = suffixOf(pBasename);
2240
+ if (pSuffix === ".aidl") {
2241
+ addSurface(result.public_api_surfaces, record, "AidlInterface", pBasename.slice(0, pBasename.length - 5), pBasename, "medium");
2242
+ return;
2243
+ }
2244
+ if ((pSuffix !== ".kt" && pSuffix !== ".java") || isInternalSourcePath(record.path)) {
2245
+ return;
2246
+ }
2247
+ const text = readText(p);
2248
+ if (pSuffix === ".kt") {
2249
+ for (const match of text.matchAll(PUBLIC_TOP_LEVEL_KOTLIN)) {
2250
+ const keyword = match.groups.keyword;
2251
+ const name = match.groups.name;
2252
+ const kind = keyword === "fun" ? "PublicKotlinFunction" : `PublicKotlin${pyTitle(keyword)}`;
2253
+ addSurface(result.public_api_surfaces, record, kind, name, match[0], "medium");
2254
+ }
2255
+ } else {
2256
+ for (const match of text.matchAll(PUBLIC_TOP_LEVEL_JAVA)) {
2257
+ addSurface(result.public_api_surfaces, record, "PublicJavaType", match[1], match[0], "medium");
2258
+ }
2259
+ }
2260
+ }
2261
+
2262
+ function scanPlatformXml(p, record, result) {
2263
+ const pBasename = path.basename(String(p));
2264
+ const kind = PLATFORM_XML_KINDS[pBasename];
2265
+ if (kind) {
2266
+ addSurface(result.platform_configurations, record, kind, pBasename, readText(p).slice(0, 800));
2267
+ }
2268
+ }
2269
+
2270
+ // ---------------------------------------------------------------------------
2271
+ // SQL / Room / storage parsing
2272
+ // ---------------------------------------------------------------------------
2273
+
2274
+ function stripIdentifier(value) {
2275
+ const trimmed = pyStrip(value).replace(/^[`"'\[]+|[`"'\]]+$/g, "");
2276
+ return trimmed.split(".").pop();
2277
+ }
2278
+
2279
+ function splitTopLevel(value, delimiter = ",") {
2280
+ const parts = [];
2281
+ let start = 0;
2282
+ let depth = 0;
2283
+ let quote = null;
2284
+ let escape = false;
2285
+ for (let index = 0; index < value.length; index += 1) {
2286
+ const char = value[index];
2287
+ if (escape) {
2288
+ escape = false;
2289
+ continue;
2290
+ }
2291
+ if (char === "\\") {
2292
+ escape = true;
2293
+ continue;
2294
+ }
2295
+ if (quote) {
2296
+ if (char === quote) {
2297
+ quote = null;
2298
+ }
2299
+ continue;
2300
+ }
2301
+ if (char === "'" || char === '"' || char === "`") {
2302
+ quote = char;
2303
+ continue;
2304
+ }
2305
+ if (char === "(") {
2306
+ depth += 1;
2307
+ } else if (char === ")") {
2308
+ depth = Math.max(0, depth - 1);
2309
+ } else if (char === delimiter && depth === 0) {
2310
+ parts.push(pyStrip(value.slice(start, index)));
2311
+ start = index + 1;
2312
+ }
2313
+ }
2314
+ const tail = pyStrip(value.slice(start));
2315
+ if (tail !== "") {
2316
+ parts.push(tail);
2317
+ }
2318
+ return parts;
2319
+ }
2320
+
2321
+ function findBalanced(value, start, opening = "(", closing = ")") {
2322
+ if (start >= value.length || value[start] !== opening) {
2323
+ return null;
2324
+ }
2325
+ let depth = 0;
2326
+ let quote = null;
2327
+ let escape = false;
2328
+ for (let index = start; index < value.length; index += 1) {
2329
+ const char = value[index];
2330
+ if (escape) {
2331
+ escape = false;
2332
+ continue;
2333
+ }
2334
+ if (char === "\\") {
2335
+ escape = true;
2336
+ continue;
2337
+ }
2338
+ if (quote) {
2339
+ if (char === quote) {
2340
+ quote = null;
2341
+ }
2342
+ continue;
2343
+ }
2344
+ if (char === "'" || char === '"' || char === "`") {
2345
+ quote = char;
2346
+ continue;
2347
+ }
2348
+ if (char === opening) {
2349
+ depth += 1;
2350
+ } else if (char === closing) {
2351
+ depth -= 1;
2352
+ if (depth === 0) {
2353
+ return [value.slice(start + 1, index), index + 1];
2354
+ }
2355
+ }
2356
+ }
2357
+ return null;
2358
+ }
2359
+
2360
+ function extractCreateTableStatements(text) {
2361
+ const statements = [];
2362
+ const pattern = /CREATE\s+TABLE(?:\s+IF\s+NOT\s+EXISTS)?\s+[^\s(]+\s*\(/gi;
2363
+ for (const match of text.matchAll(pattern)) {
2364
+ const openIndex = text.indexOf("(", match.index);
2365
+ const balanced = findBalanced(text, openIndex);
2366
+ if (balanced) {
2367
+ const end = balanced[1];
2368
+ statements.push(text.slice(match.index, end));
2369
+ }
2370
+ }
2371
+ return statements;
2372
+ }
2373
+
2374
+ function canonicalConstraintTokens(fragment) {
2375
+ const upper = fragment.replace(/\s+/g, " ").trim().toUpperCase();
2376
+ const result = [];
2377
+ if (/\bNOT\s+NULL\b/.test(upper)) {
2378
+ result.push("NOT NULL");
2379
+ }
2380
+ if (/\bAUTOINCREMENT\b/.test(upper)) {
2381
+ result.push("AUTO_INCREMENT");
2382
+ }
2383
+ if (/\bUNIQUE\b/.test(upper)) {
2384
+ result.push("UNIQUE");
2385
+ }
2386
+ const def = /\bDEFAULT\s+((?:\([^)]*\))|(?:'[^']*')|(?:"[^"]*")|[^\s,]+)/i.exec(fragment);
2387
+ if (def) {
2388
+ result.push(`DEFAULT ${def[1].replace(/\s+/g, " ").trim()}`);
2389
+ }
2390
+ const check = /\bCHECK\s*(\([^)]*\))/is.exec(fragment);
2391
+ if (check) {
2392
+ result.push(`CHECK ${check[1].replace(/\s+/g, " ").trim()}`);
2393
+ }
2394
+ const collate = /\bCOLLATE\s+(\w+)/i.exec(fragment);
2395
+ if (collate) {
2396
+ result.push(`COLLATE ${collate[1].toUpperCase()}`);
2397
+ }
2398
+ return result;
2399
+ }
2400
+
2401
+ function parseCreateTable(statement, sourcePath, confidence) {
2402
+ const header = /^CREATE\s+TABLE(?:\s+IF\s+NOT\s+EXISTS)?\s+([^\s(]+)\s*\(/i.exec(statement);
2403
+ if (!header) {
2404
+ return null;
2405
+ }
2406
+ const tableName = stripIdentifier(header[1]);
2407
+ const openIndex = statement.indexOf("(", header.index);
2408
+ const balanced = findBalanced(statement, openIndex);
2409
+ if (!balanced) {
2410
+ return null;
2411
+ }
2412
+ const body = balanced[0];
2413
+ const fragments = splitTopLevel(body);
2414
+ const columns = {};
2415
+ const tableConstraints = [];
2416
+ const pendingPrimary = new Set();
2417
+ const pendingForeign = [];
2418
+
2419
+ for (const fragment of fragments) {
2420
+ let cleaned = pyStrip(fragment.replace(/["']\s*\+\s*["']/g, ""));
2421
+ if (cleaned.length >= 2 && cleaned[0] === cleaned[cleaned.length - 1] && (cleaned[0] === '"' || cleaned[0] === "'")) {
2422
+ cleaned = pyStrip(cleaned.slice(1, -1));
2423
+ }
2424
+ const upper = cleaned.toUpperCase();
2425
+ if ((upper.startsWith("PRIMARY KEY") || upper.startsWith("CONSTRAINT")) && upper.includes("PRIMARY KEY")) {
2426
+ const match = /PRIMARY\s+KEY\s*\(([^)]*)\)/i.exec(cleaned);
2427
+ if (match) {
2428
+ for (const item of splitTopLevel(match[1])) {
2429
+ pendingPrimary.add(stripIdentifier(item));
2430
+ }
2431
+ }
2432
+ continue;
2433
+ }
2434
+ if ((upper.startsWith("FOREIGN KEY") || upper.startsWith("CONSTRAINT")) && upper.includes("FOREIGN KEY")) {
2435
+ const match = /FOREIGN\s+KEY\s*\(([^)]*)\)\s+REFERENCES\s+([^\s(]+)\s*\(([^)]*)\)(.*)/is.exec(cleaned);
2436
+ if (match) {
2437
+ const child = splitTopLevel(match[1]).map(stripIdentifier);
2438
+ const parentTable = stripIdentifier(match[2]);
2439
+ const parent = splitTopLevel(match[3]).map(stripIdentifier);
2440
+ const actions = [];
2441
+ for (const actionName of ["DELETE", "UPDATE"]) {
2442
+ const action = new RegExp(`ON\\s+${actionName}\\s+(CASCADE|RESTRICT|SET\\s+NULL|SET\\s+DEFAULT|NO\\s+ACTION)`, "i").exec(match[4]);
2443
+ if (action) {
2444
+ const normalizedAction = action[1].replace(/\s+/g, " ").toUpperCase();
2445
+ actions.push(`ON ${actionName} ${normalizedAction}`);
2446
+ }
2447
+ }
2448
+ pendingForeign.push([child, parentTable, parent, actions]);
2449
+ }
2450
+ continue;
2451
+ }
2452
+ if (upper.startsWith("UNIQUE") || upper.startsWith("CHECK")) {
2453
+ tableConstraints.push(cleaned.replace(/\s+/g, " "));
2454
+ continue;
2455
+ }
2456
+
2457
+ const tokens = [...cleaned.matchAll(/`[^`]+`|\[[^]]+\]|"[^"]+"|'[^']+'|\S+/g)].map((m) => m[0]);
2458
+ if (tokens.length === 0) {
2459
+ continue;
2460
+ }
2461
+ const name = stripIdentifier(tokens[0]);
2462
+ const typeTokens = [];
2463
+ for (const token of tokens.slice(1)) {
2464
+ if (CONSTRAINT_KEYWORDS.has(token.toUpperCase().replace(/[(,]/g, ""))) {
2465
+ break;
2466
+ }
2467
+ // Python token.strip(","): strip leading/trailing commas only — a
2468
+ // replace-all would corrupt DECIMAL(10,2) into DECIMAL(102).
2469
+ typeTokens.push(token.replace(/^[,]+|[,]+$/g, ""));
2470
+ }
2471
+ const columnType = pyStrip(typeTokens.join(" ")) || "UNKNOWN";
2472
+ let key = /\bPRIMARY\s+KEY\b/i.test(cleaned) ? "PK" : "";
2473
+ const reference = /\bREFERENCES\s+([^\s(]+)\s*\(([^)]*)\)/i.exec(cleaned);
2474
+ if (reference) {
2475
+ const parentTable = stripIdentifier(reference[1]);
2476
+ const parentColumn = stripIdentifier(splitTopLevel(reference[2])[0]);
2477
+ const fk = `FK -> ${parentTable}.${parentColumn}`;
2478
+ key = key === "" ? fk : `${key}, ${fk}`;
2479
+ }
2480
+ const constraints = canonicalConstraintTokens(cleaned);
2481
+ for (const actionName of ["DELETE", "UPDATE"]) {
2482
+ const action = new RegExp(`ON\\s+${actionName}\\s+(CASCADE|RESTRICT|SET\\s+NULL|SET\\s+DEFAULT|NO\\s+ACTION)`, "i").exec(cleaned);
2483
+ if (action) {
2484
+ const normalizedAction = action[1].replace(/\s+/g, " ").toUpperCase();
2485
+ constraints.push(`ON ${actionName} ${normalizedAction}`);
2486
+ }
2487
+ }
2488
+ columns[name] = {
2489
+ field: name,
2490
+ type: columnType,
2491
+ key,
2492
+ constraints: [...new Set(constraints)],
2493
+ source_path: sourcePath,
2494
+ confidence,
2495
+ };
2496
+ }
2497
+
2498
+ for (const name of pendingPrimary) {
2499
+ if (name in columns) {
2500
+ columns[name].key = columns[name].key === "" ? "PK" : columns[name].key;
2501
+ }
2502
+ }
2503
+ for (const [childColumns, parentTable, parentColumns, actions] of pendingForeign) {
2504
+ for (let index = 0; index < childColumns.length; index += 1) {
2505
+ const child = childColumns[index];
2506
+ if (!(child in columns)) {
2507
+ continue;
2508
+ }
2509
+ const parent = index < parentColumns.length ? parentColumns[index] : parentColumns[0];
2510
+ const fk = `FK -> ${parentTable}.${parent}`;
2511
+ columns[child].key = columns[child].key === "" ? fk : `${columns[child].key}, ${fk}`;
2512
+ columns[child].constraints = [...new Set([...columns[child].constraints, ...actions])];
2513
+ }
2514
+ }
2515
+
2516
+ for (const column of Object.values(columns)) {
2517
+ const keyValue = String(column.key ?? "");
2518
+ const components = [...keyValue.matchAll(/PK|FK\s*->\s*[^,]+/gi)].map((m) => m[0]);
2519
+ const uniqueComponents = [];
2520
+ for (const component of components) {
2521
+ const normalized = component.replace(/\s+/g, " ").trim();
2522
+ if (!uniqueComponents.some((value) => value.toUpperCase() === normalized.toUpperCase())) {
2523
+ uniqueComponents.push(normalized);
2524
+ }
2525
+ }
2526
+ column.key = uniqueComponents.join(", ");
2527
+ }
2528
+
2529
+ return {
2530
+ name: tableName,
2531
+ source_path: sourcePath,
2532
+ confidence,
2533
+ columns: Object.values(columns),
2534
+ table_constraints: tableConstraints,
2535
+ };
2536
+ }
2537
+
2538
+ function parseRoomExportedSchema(p, record) {
2539
+ let raw;
2540
+ try {
2541
+ raw = parseStrictJson(fs.readFileSync(p, "utf8"));
2542
+ } catch {
2543
+ return null;
2544
+ }
2545
+ const database = raw !== null && typeof raw === "object" && !Array.isArray(raw) ? raw.database : null;
2546
+ if (database === null || typeof database !== "object" || !Array.isArray(database.entities)) {
2547
+ return null;
2548
+ }
2549
+ let version = database.version;
2550
+ const isInt = (v) => typeof v === "bigint" || (typeof v === "number" && Number.isInteger(v));
2551
+ if (!isInt(version)) {
2552
+ const stem = path.basename(String(p)).replace(/\.[^.]*$/, "");
2553
+ const parsed = Number.parseInt(stem, 10);
2554
+ version = Number.isNaN(parsed) ? 0 : parsed;
2555
+ }
2556
+ const parentName = path.basename(path.dirname(String(p)));
2557
+ const dbName = parentName !== "" ? parentName.split(".").pop() : "RoomDatabase";
2558
+ const tables = [];
2559
+ for (const entity of database.entities) {
2560
+ if (entity === null || typeof entity !== "object" || Array.isArray(entity)) {
2561
+ continue;
2562
+ }
2563
+ const tableName = String(entity.tableName ?? entity.entityName ?? "unknown");
2564
+ const createSql = String(entity.createSql ?? "");
2565
+ let table = createSql ? parseCreateTable(createSql, record.path, "authoritative") : null;
2566
+ if (table) {
2567
+ table.name = tableName;
2568
+ } else {
2569
+ const primary = entity.primaryKey !== null && typeof entity.primaryKey === "object" ? entity.primaryKey : {};
2570
+ const primaryColumns = new Set(primary.columnNames ?? []);
2571
+ const columns = [];
2572
+ for (const field of entity.fields ?? []) {
2573
+ if (field === null || typeof field !== "object" || Array.isArray(field)) {
2574
+ continue;
2575
+ }
2576
+ const columnName = String(field.columnName ?? field.fieldPath ?? "");
2577
+ if (columnName === "") {
2578
+ continue;
2579
+ }
2580
+ const constraints = [];
2581
+ if (field.notNull === true) {
2582
+ constraints.push("NOT NULL");
2583
+ }
2584
+ if (field.defaultValue !== null && field.defaultValue !== undefined) {
2585
+ constraints.push(`DEFAULT ${field.defaultValue}`);
2586
+ }
2587
+ columns.push({
2588
+ field: columnName,
2589
+ type: String(field.affinity ?? "UNKNOWN"),
2590
+ key: primaryColumns.has(columnName) ? "PK" : "",
2591
+ constraints,
2592
+ source_path: record.path,
2593
+ confidence: "authoritative",
2594
+ });
2595
+ }
2596
+ table = {
2597
+ name: tableName,
2598
+ source_path: record.path,
2599
+ confidence: "authoritative",
2600
+ columns,
2601
+ table_constraints: [],
2602
+ };
2603
+ }
2604
+
2605
+ const byField = {};
2606
+ for (const column of table.columns) {
2607
+ byField[column.field] = column;
2608
+ }
2609
+ for (const foreign of entity.foreignKeys ?? []) {
2610
+ if (foreign === null || typeof foreign !== "object" || Array.isArray(foreign)) {
2611
+ continue;
2612
+ }
2613
+ const children = foreign.columnNames ?? foreign.columns ?? [];
2614
+ const parents = foreign.referenceColumnNames ?? foreign.referencedColumns ?? [];
2615
+ const parentTable = String(foreign.referenceTable ?? foreign.table ?? "");
2616
+ for (let index = 0; index < children.length; index += 1) {
2617
+ const child = children[index];
2618
+ if (!(child in byField) || parentTable === "") {
2619
+ continue;
2620
+ }
2621
+ const parent = index < parents.length ? parents[index] : (parents.length > 0 ? parents[0] : "");
2622
+ const fk = parent !== "" ? `FK -> ${parentTable}.${parent}` : `FK -> ${parentTable}`;
2623
+ byField[child].key = byField[child].key === "" ? fk : `${byField[child].key}, ${fk}`;
2624
+ for (const [actionKey, label] of [["onDelete", "ON DELETE"], ["onUpdate", "ON UPDATE"]]) {
2625
+ const action = foreign[actionKey];
2626
+ if (action && String(action).toUpperCase() !== "NO ACTION") {
2627
+ byField[child].constraints.push(`${label} ${String(action).replace(/_/g, " ").toUpperCase()}`);
2628
+ }
2629
+ }
2630
+ }
2631
+ }
2632
+ for (const index of entity.indices ?? []) {
2633
+ if (index === null || typeof index !== "object" || Array.isArray(index) || index.unique !== true) {
2634
+ continue;
2635
+ }
2636
+ const names = index.columnNames ?? index.columns ?? [];
2637
+ const label = names.length === 1 ? "UNIQUE" : `UNIQUE INDEX(${names.map(String).join(", ")})`;
2638
+ for (const name of names) {
2639
+ if (name in byField) {
2640
+ byField[name].constraints.push(label);
2641
+ }
2642
+ }
2643
+ }
2644
+ for (const column of table.columns) {
2645
+ column.constraints = [...new Set(column.constraints)];
2646
+ const components = [...String(column.key ?? "").matchAll(/PK|FK\s*->\s*[^,]+/gi)].map((m) => m[0]);
2647
+ const uniqueComponents = [];
2648
+ for (const component of components) {
2649
+ const normalized = component.replace(/\s+/g, " ").trim();
2650
+ if (!uniqueComponents.some((value) => value.toUpperCase() === normalized.toUpperCase())) {
2651
+ uniqueComponents.push(normalized);
2652
+ }
2653
+ }
2654
+ column.key = uniqueComponents.join(", ");
2655
+ }
2656
+ tables.push(table);
2657
+ }
2658
+ return [dbName, version, tables];
2659
+ }
2660
+
2661
+ function stringArray(value) {
2662
+ return [...value.matchAll(/['"]([^'"]+)['"]/g)].map((m) => m[1]);
2663
+ }
2664
+
2665
+ function constantName(value) {
2666
+ let v = pyStrip(value);
2667
+ v = v.replace(/::class(?:\.java)?/g, "");
2668
+ return v.split(".").pop().trim();
2669
+ }
2670
+
2671
+ function buildRoomEntityDatabaseMap(sourceTexts) {
2672
+ const mapping = {};
2673
+ for (const text of Object.values(sourceTexts)) {
2674
+ for (const match of text.matchAll(/@Database\s*\(/g)) {
2675
+ const balanced = findBalanced(text, text.indexOf("(", match.index));
2676
+ if (!balanced) {
2677
+ continue;
2678
+ }
2679
+ const [params, end] = balanced;
2680
+ const classMatch = /(?:abstract\s+)?class\s+(\w+)/.exec(text.slice(end, end + 800));
2681
+ if (!classMatch) {
2682
+ continue;
2683
+ }
2684
+ const databaseName = classMatch[1];
2685
+ const entitiesMatch = /entities\s*=\s*(?:arrayOf\s*\(|\[)(.*?)(?:\)|\])/s.exec(params);
2686
+ if (!entitiesMatch) {
2687
+ continue;
2688
+ }
2689
+ for (const entity of entitiesMatch[1].matchAll(/(\w+)\s*::\s*class/g)) {
2690
+ mapping[entity[1]] = databaseName;
2691
+ }
2692
+ }
2693
+ }
2694
+ return mapping;
2695
+ }
2696
+
2697
+ function extractAnnotationCalls(value, name) {
2698
+ const result = [];
2699
+ const pattern = new RegExp(`\\b${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*\\(`, "g");
2700
+ for (const match of value.matchAll(pattern)) {
2701
+ const start = value.indexOf("(", match.index);
2702
+ const balanced = findBalanced(value, start);
2703
+ if (balanced) {
2704
+ result.push(balanced[0]);
2705
+ }
2706
+ }
2707
+ return result;
2708
+ }
2709
+
2710
+ function buildRoomEntityTableMap(sourceTexts) {
2711
+ const mapping = {};
2712
+ for (const text of Object.values(sourceTexts)) {
2713
+ for (const match of text.matchAll(/@Entity\b/g)) {
2714
+ let cursor = match.index + match[0].length;
2715
+ while (cursor < text.length && /\s/.test(text[cursor])) {
2716
+ cursor += 1;
2717
+ }
2718
+ let params = "";
2719
+ let annotationEnd = cursor;
2720
+ if (cursor < text.length && text[cursor] === "(") {
2721
+ const balanced = findBalanced(text, cursor);
2722
+ if (!balanced) {
2723
+ continue;
2724
+ }
2725
+ [params, annotationEnd] = balanced;
2726
+ }
2727
+ const classMatch = /(?:data\s+)?class\s+(\w+)/.exec(text.slice(annotationEnd, annotationEnd + 4000));
2728
+ if (!classMatch) {
2729
+ continue;
2730
+ }
2731
+ const className = classMatch[1];
2732
+ const tableMatch = /tableName\s*=\s*['"]([^'"]+)['"]/.exec(params);
2733
+ mapping[className] = tableMatch ? tableMatch[1] : className;
2734
+ }
2735
+ }
2736
+ return mapping;
2737
+ }
2738
+
2739
+ const ROOM_PROPERTY_PATTERN = new RegExp(
2740
+ "((?:@[A-Za-z_][\\w.]*\\s*(?:\\([^)]*\\))?\\s*)*)"
2741
+ + "(?:private\\s+|protected\\s+|public\\s+|internal\\s+)?"
2742
+ + "(?:val|var)\\s+(\\w+)\\s*:\\s*([A-Za-z_][\\w.?<>, ]*)",
2743
+ "gs",
2744
+ );
2745
+
2746
+ function parseRoomSourceEntities(sourceTexts, records) {
2747
+ const databaseMap = buildRoomEntityDatabaseMap(sourceTexts);
2748
+ const entityTableMap = buildRoomEntityTableMap(sourceTexts);
2749
+ const databases = {};
2750
+ for (const [sourcePath, text] of Object.entries(sourceTexts)) {
2751
+ const record = records[sourcePath];
2752
+ for (const match of text.matchAll(/@Entity\b/g)) {
2753
+ let startAfter = match.index + match[0].length;
2754
+ while (startAfter < text.length && /\s/.test(text[startAfter])) {
2755
+ startAfter += 1;
2756
+ }
2757
+ let params = "";
2758
+ let annotationEnd = startAfter;
2759
+ if (startAfter < text.length && text[startAfter] === "(") {
2760
+ const balanced = findBalanced(text, startAfter);
2761
+ if (!balanced) {
2762
+ continue;
2763
+ }
2764
+ [params, annotationEnd] = balanced;
2765
+ }
2766
+ const classMatch = /(?:data\s+)?class\s+(\w+)/.exec(text.slice(annotationEnd, annotationEnd + 4000));
2767
+ if (!classMatch) {
2768
+ continue;
2769
+ }
2770
+ const className = classMatch[1];
2771
+ const classEnd = annotationEnd + classMatch.index + classMatch[0].length;
2772
+ let snippetEnd = Math.min(text.length, classEnd + 12000);
2773
+ let cursor = classEnd;
2774
+ while (cursor < text.length && /\s/.test(text[cursor])) {
2775
+ cursor += 1;
2776
+ }
2777
+ let constructor = "";
2778
+ if (cursor < text.length && text[cursor] === "(") {
2779
+ const constructorBalanced = findBalanced(text, cursor);
2780
+ if (constructorBalanced) {
2781
+ [constructor, cursor] = constructorBalanced;
2782
+ }
2783
+ }
2784
+ while (cursor < text.length && /\s/.test(text[cursor])) {
2785
+ cursor += 1;
2786
+ }
2787
+ let body = "";
2788
+ const brace = text.indexOf("{", cursor);
2789
+ if (brace !== -1 && brace < snippetEnd) {
2790
+ const bodyBalanced = findBalanced(text, brace, "{", "}");
2791
+ if (bodyBalanced) {
2792
+ [body, snippetEnd] = bodyBalanced;
2793
+ }
2794
+ }
2795
+ const snippet = `${constructor}\n${body}`;
2796
+
2797
+ const tableMatch = /tableName\s*=\s*['"]([^'"]+)['"]/.exec(params);
2798
+ const tableName = tableMatch ? tableMatch[1] : className;
2799
+ const primaryKeysMatch = /primaryKeys\s*=\s*(?:arrayOf\s*\(|\[)(.*?)(?:\)|\])/s.exec(params);
2800
+ const primaryKeys = new Set(primaryKeysMatch ? stringArray(primaryKeysMatch[1]) : []);
2801
+
2802
+ const foreignByChild = {};
2803
+ for (const foreignParams of extractAnnotationCalls(params, "ForeignKey")) {
2804
+ const entityMatch = /entity\s*=\s*([^,]+)/.exec(foreignParams);
2805
+ const parentColumnsMatch = /parentColumns\s*=\s*(?:arrayOf\s*\(|\[)(.*?)(?:\)|\])/s.exec(foreignParams);
2806
+ const childColumnsMatch = /childColumns\s*=\s*(?:arrayOf\s*\(|\[)(.*?)(?:\)|\])/s.exec(foreignParams);
2807
+ if (!entityMatch || !parentColumnsMatch || !childColumnsMatch) {
2808
+ continue;
2809
+ }
2810
+ const parentEntity = constantName(entityMatch[1]);
2811
+ const parentTable = entityTableMap[parentEntity] ?? parentEntity;
2812
+ const parentColumns = stringArray(parentColumnsMatch[1]);
2813
+ const childColumns = stringArray(childColumnsMatch[1]);
2814
+ const actions = [];
2815
+ for (const [parameter, label] of [["onDelete", "ON DELETE"], ["onUpdate", "ON UPDATE"]]) {
2816
+ const action = new RegExp(`${parameter}\\s*=\\s*(?:ForeignKey\\.)?(\\w+)`).exec(foreignParams);
2817
+ if (action && action[1].toUpperCase() !== "NO_ACTION") {
2818
+ actions.push(`${label} ${action[1].replace(/_/g, " ").toUpperCase()}`);
2819
+ }
2820
+ }
2821
+ for (let index = 0; index < childColumns.length; index += 1) {
2822
+ const child = childColumns[index];
2823
+ const parent = index < parentColumns.length ? parentColumns[index] : (parentColumns.length > 0 ? parentColumns[0] : "");
2824
+ foreignByChild[child] = [parentTable, parent, actions];
2825
+ }
2826
+ }
2827
+
2828
+ const uniqueColumns = {};
2829
+ for (const indexParams of extractAnnotationCalls(params, "Index")) {
2830
+ const unique = /unique\s*=\s*true/i.test(indexParams);
2831
+ const valuesMatch = /(?:value|columns)\s*=\s*(?:arrayOf\s*\(|\[)(.*?)(?:\)|\])/s.exec(indexParams);
2832
+ if (!unique || !valuesMatch) {
2833
+ continue;
2834
+ }
2835
+ const names = stringArray(valuesMatch[1]);
2836
+ const label = names.length === 1 ? "UNIQUE" : `UNIQUE INDEX(${names.join(", ")})`;
2837
+ for (const name of names) {
2838
+ uniqueColumns[name] = label;
2839
+ }
2840
+ }
2841
+
2842
+ const columns = [];
2843
+ const seenFields = new Set();
2844
+ for (const prop of snippet.matchAll(ROOM_PROPERTY_PATTERN)) {
2845
+ const annotations = prop[1];
2846
+ const fieldName = prop[2];
2847
+ const fieldType = prop[3].replace(/\s+/g, " ").trim().replace(/,+$/, "").replace(/,+$/, "");
2848
+ const columnMatch = /@ColumnInfo\s*\([^)]*name\s*=\s*['"]([^'"]+)['"]/s.exec(annotations);
2849
+ const columnName = columnMatch ? columnMatch[1] : fieldName;
2850
+ if (seenFields.has(columnName)) {
2851
+ continue;
2852
+ }
2853
+ seenFields.add(columnName);
2854
+ const isPrimary = /@PrimaryKey\b/.test(annotations) || primaryKeys.has(columnName) || primaryKeys.has(fieldName);
2855
+ const constraints = [];
2856
+ if (!fieldType.replace(/\s+$/, "").endsWith("?")) {
2857
+ constraints.push("NOT NULL");
2858
+ }
2859
+ const defaultMatch = /@ColumnInfo\s*\([^)]*defaultValue\s*=\s*['"]([^'"]*)['"]/s.exec(annotations);
2860
+ if (defaultMatch) {
2861
+ constraints.push(`DEFAULT ${defaultMatch[1]}`);
2862
+ }
2863
+ if (/@PrimaryKey\s*\([^)]*autoGenerate\s*=\s*true/s.test(annotations)) {
2864
+ constraints.push("AUTO_INCREMENT");
2865
+ }
2866
+ if (columnName in uniqueColumns || fieldName in uniqueColumns) {
2867
+ constraints.push(uniqueColumns[columnName] ?? uniqueColumns[fieldName]);
2868
+ }
2869
+ let key = isPrimary ? "PK" : "";
2870
+ const fk = foreignByChild[columnName] ?? foreignByChild[fieldName];
2871
+ if (fk) {
2872
+ const [parentTable, parentColumn, actions] = fk;
2873
+ const label = parentColumn !== "" ? `FK -> ${parentTable}.${parentColumn}` : `FK -> ${parentTable}`;
2874
+ key = key === "" ? label : `${key}, ${label}`;
2875
+ constraints.push(...actions);
2876
+ }
2877
+ columns.push({
2878
+ field: columnName,
2879
+ type: fieldType,
2880
+ key,
2881
+ constraints: [...new Set(constraints)],
2882
+ source_path: sourcePath,
2883
+ confidence: "probable",
2884
+ });
2885
+ }
2886
+
2887
+ const databaseName = databaseMap[className] ?? "RoomDatabase";
2888
+ if (!(databaseName in databases)) {
2889
+ databases[databaseName] = {
2890
+ name: databaseName,
2891
+ source_kind: "room_annotations",
2892
+ confidence: "probable",
2893
+ sources: [],
2894
+ tables: [],
2895
+ };
2896
+ }
2897
+ const database = databases[databaseName];
2898
+ database.sources.push(sourcePath);
2899
+ database.tables.push({
2900
+ name: tableName,
2901
+ source_path: sourcePath,
2902
+ confidence: "probable",
2903
+ columns,
2904
+ table_constraints: [],
2905
+ });
2906
+ }
2907
+ }
2908
+ for (const database of Object.values(databases)) {
2909
+ database.sources = [...new Set(database.sources)].sort();
2910
+ }
2911
+ return Object.values(databases);
2912
+ }
2913
+
2914
+ // Blank out // and /* */ comments (string literals kept), preserving offsets
2915
+ // and newlines so commented-out DDL or helper code is never read as live.
2916
+ export function stripJvmComments(text) {
2917
+ const out = text.split("");
2918
+ let i = 0;
2919
+ while (i < text.length) {
2920
+ const char = text[i];
2921
+ if (char === '"' || char === "'") {
2922
+ const raw = char === '"' && text.startsWith('"""', i);
2923
+ const close = raw ? '"""' : char;
2924
+ i += close.length;
2925
+ while (i < text.length && !text.startsWith(close, i)) {
2926
+ i += !raw && text[i] === "\\" ? 2 : 1;
2927
+ }
2928
+ i += close.length;
2929
+ continue;
2930
+ }
2931
+ if (char === "/" && (text[i + 1] === "/" || text[i + 1] === "*")) {
2932
+ const end = text[i + 1] === "/"
2933
+ ? (text.indexOf("\n", i) === -1 ? text.length : text.indexOf("\n", i))
2934
+ : (text.indexOf("*/", i + 2) === -1 ? text.length : text.indexOf("*/", i + 2) + 2);
2935
+ for (let k = i; k < end; k += 1) {
2936
+ if (out[k] !== "\n" && out[k] !== "\r") out[k] = " ";
2937
+ }
2938
+ i = end;
2939
+ continue;
2940
+ }
2941
+ i += 1;
2942
+ }
2943
+ return out.join("");
2944
+ }
2945
+
2946
+ // String constants declared in a file: `static final String X = "v"` / `const val X = "v"`.
2947
+ // `strict` drops plain `val` (a local or property, not a constant): project-wide
2948
+ // lookups use strict so an unrelated `val name = "…"` elsewhere is never picked up.
2949
+ function fileStringConstants(text, strict = false) {
2950
+ const constants = {};
2951
+ const pattern = strict
2952
+ ? /\b(?:static\s+final\s+String|final\s+static\s+String|const\s+val)\s+(\w+)\s*(?::\s*String\s*)?=\s*"([^"]*)"/g
2953
+ : /\b(?:static\s+final\s+String|final\s+static\s+String|const\s+val|val)\s+(\w+)\s*(?::\s*String\s*)?=\s*"([^"]*)"/g;
2954
+ for (const match of text.matchAll(pattern)) {
2955
+ if (!(match[1] in constants)) constants[match[1]] = match[2];
2956
+ }
2957
+ return constants;
2958
+ }
2959
+
2960
+ function fileIntConstants(text, strict = false) {
2961
+ const constants = {};
2962
+ const pattern = strict
2963
+ ? /\b(?:static\s+final\s+int|final\s+static\s+int|const\s+val)\s+(\w+)\s*(?::\s*Int\s*)?=\s*(\d+)\b/g
2964
+ : /\b(?:static\s+final\s+int|final\s+static\s+int|const\s+val|val)\s+(\w+)\s*(?::\s*Int\s*)?=\s*(\d+)\b/g;
2965
+ for (const match of text.matchAll(pattern)) {
2966
+ if (!(match[1] in constants)) constants[match[1]] = Number(match[2]);
2967
+ }
2968
+ return constants;
2969
+ }
2970
+
2971
+ // Resolve the database name/version a SQLiteOpenHelper subclass passes to its
2972
+ // super constructor: `super(ctx, NAME, factory, VERSION)` (Java) or
2973
+ // `: SQLiteOpenHelper(ctx, "a.db", null, 6)` (Kotlin). Constants resolve from
2974
+ // the same file first, then from a unique project-wide declaration. An argument
2975
+ // that is one of the helper's own constructor parameters (`super(ctx, name, …)`
2976
+ // passing through what the caller supplied) is left unresolved.
2977
+ function helperConstructorParams(text, className) {
2978
+ const params = new Set();
2979
+ for (const call of text.matchAll(new RegExp(`\\b${className}\\s*\\(`, "g"))) {
2980
+ const balanced = findBalanced(text, call.index + call[0].length - 1);
2981
+ if (!balanced) continue;
2982
+ for (const raw of splitTopLevel(balanced[0])) {
2983
+ const param = pyStrip(raw).replace(/=[\s\S]*$/, "").trim();
2984
+ // Kotlin `[val|var] name: Type`; Java `[final] Type name`.
2985
+ const kotlin = /^(?:(?:private|protected|internal|public)\s+)?(?:va[lr]\s+)?(\w+)\s*:/.exec(param);
2986
+ const java = /(\w+)$/.exec(param);
2987
+ const id = kotlin ? kotlin[1] : java ? java[1] : null;
2988
+ if (id) params.add(id);
2989
+ }
2990
+ }
2991
+ return params;
2992
+ }
2993
+
2994
+ function resolveHelperDatabase(text, projectStrings, projectInts) {
2995
+ const classMatch = /class\s+(\w+)\s*(?:\([^)]*\))?\s*(?::|extends)\s*[^\n{]*SQLiteOpenHelper/.exec(text);
2996
+ if (!classMatch) {
2997
+ return null;
2998
+ }
2999
+ let args = null;
3000
+ for (const pattern of [/SQLiteOpenHelper\s*\(/g, /\bsuper\s*\(/g]) {
3001
+ pattern.lastIndex = classMatch.index;
3002
+ const call = pattern.exec(text);
3003
+ if (call) {
3004
+ const balanced = findBalanced(text, call.index + call[0].length - 1);
3005
+ if (balanced && splitTopLevel(balanced[0]).length >= 4) {
3006
+ args = splitTopLevel(balanced[0]).map((arg) => pyStrip(arg));
3007
+ break;
3008
+ }
3009
+ }
3010
+ }
3011
+ const local = fileStringConstants(text);
3012
+ const localInts = fileIntConstants(text);
3013
+ const ctorParams = helperConstructorParams(text, classMatch[1]);
3014
+ const resolveString = (expr) => {
3015
+ const literal = /^"([^"]*)"$/.exec(expr);
3016
+ if (literal) return literal[1];
3017
+ if (ctorParams.has(expr)) return null;
3018
+ const name = constantName(expr);
3019
+ if (name in local) return local[name];
3020
+ return projectStrings[name] ?? null;
3021
+ };
3022
+ const resolveInt = (expr) => {
3023
+ if (/^\d+$/.test(expr)) return Number(expr);
3024
+ if (ctorParams.has(expr)) return null;
3025
+ const name = constantName(expr);
3026
+ if (name in localInts) return localInts[name];
3027
+ return projectInts[name] ?? null;
3028
+ };
3029
+ const name = args ? resolveString(args[1]) : null;
3030
+ const version = args ? resolveInt(args[3]) : null;
3031
+ return { className: classMatch[1], name, version };
3032
+ }
3033
+
3034
+ // name -> value for string/int constants declared exactly once across the project.
3035
+ function uniqueProjectConstants(sourceTexts, collect) {
3036
+ const seen = {};
3037
+ for (const text of Object.values(sourceTexts)) {
3038
+ for (const [name, value] of Object.entries(collect(text))) {
3039
+ if (!(name in seen)) seen[name] = new Set();
3040
+ seen[name].add(value);
3041
+ }
3042
+ }
3043
+ const unique = {};
3044
+ for (const [name, values] of Object.entries(seen)) {
3045
+ if (values.size === 1) unique[name] = [...values][0];
3046
+ }
3047
+ return unique;
3048
+ }
3049
+
3050
+ function parseSqliteDatabases(sourceTexts) {
3051
+ const databases = {};
3052
+ const liveTexts = {};
3053
+ for (const [sourcePath, text] of Object.entries(sourceTexts)) {
3054
+ liveTexts[sourcePath] = stripJvmComments(text);
3055
+ }
3056
+ const projectStrings = uniqueProjectConstants(liveTexts, (text) => fileStringConstants(text, true));
3057
+ const projectInts = uniqueProjectConstants(liveTexts, (text) => fileIntConstants(text, true));
3058
+ const helpers = {};
3059
+ for (const [sourcePath, text] of Object.entries(liveTexts)) {
3060
+ const helper = resolveHelperDatabase(text, projectStrings, projectInts);
3061
+ if (helper) helpers[sourcePath] = helper;
3062
+ }
3063
+ // DDL kept in a separate constants class is attributed to the one helper
3064
+ // that references that class (e.g. `HighLightTable.CREATE_SQL`).
3065
+ const helperReferencing = (sourcePath) => {
3066
+ const className = path.basename(sourcePath).replace(/\.[^.]*$/, "");
3067
+ const reference = new RegExp(`\\b${className}\\.`);
3068
+ const matches = Object.entries(helpers).filter(([p]) => reference.test(liveTexts[p]));
3069
+ return matches.length === 1 ? matches[0][1] : null;
3070
+ };
3071
+ for (const [sourcePath, text] of Object.entries(liveTexts)) {
3072
+ const statements = extractCreateTableStatements(text);
3073
+ if (statements.length === 0) {
3074
+ continue;
3075
+ }
3076
+ const helper = helpers[sourcePath] ?? helperReferencing(sourcePath);
3077
+ let databaseName = path.basename(sourcePath).replace(/\.[^.]*$/, "");
3078
+ let confidence = "review_required";
3079
+ let nameSource = "file_name";
3080
+ if (helper && helper.name) {
3081
+ databaseName = helper.name;
3082
+ confidence = "probable";
3083
+ nameSource = "helper_constructor";
3084
+ } else if (helper) {
3085
+ databaseName = helper.className;
3086
+ nameSource = "helper_class_name";
3087
+ }
3088
+ if (!(databaseName in databases)) {
3089
+ databases[databaseName] = {
3090
+ name: databaseName,
3091
+ source_kind: "sqlite_ddl",
3092
+ confidence,
3093
+ name_source: nameSource,
3094
+ sources: [],
3095
+ tables: [],
3096
+ };
3097
+ if (helper && helper.version !== null) {
3098
+ databases[databaseName].version = helper.version;
3099
+ }
3100
+ }
3101
+ const database = databases[databaseName];
3102
+ database.sources.push(sourcePath);
3103
+ const tableNames = new Set(database.tables.map((table) => table.name));
3104
+ for (const statement of statements) {
3105
+ const table = parseCreateTable(statement, sourcePath, database.confidence);
3106
+ if (table && !tableNames.has(table.name)) {
3107
+ tableNames.add(table.name);
3108
+ database.tables.push(table);
3109
+ }
3110
+ }
3111
+ }
3112
+ for (const database of Object.values(databases)) {
3113
+ database.sources = [...new Set(database.sources)].sort();
3114
+ }
3115
+ return Object.values(databases);
3116
+ }
3117
+
3118
+ function sourceClassFields(text) {
3119
+ const fields = [];
3120
+ const seen = new Set();
3121
+ const kotlin = /(?:val|var)\s+(\w+)\s*:\s*([A-Za-z_][\w.?<>, ]*)/g;
3122
+ const java = /(?:private|protected|public)?\s*([A-Za-z_][\w.?<>,\[\] ]*)\s+(\w+)\s*(?:=|;)/g;
3123
+ for (const match of text.matchAll(kotlin)) {
3124
+ const name = match[1];
3125
+ const fieldType = match[2].replace(/\s+/g, " ").trim();
3126
+ if (!seen.has(name)) {
3127
+ seen.add(name);
3128
+ fields.push({
3129
+ field: name,
3130
+ type: fieldType,
3131
+ key: "",
3132
+ constraints: fieldType.endsWith("?") ? [] : ["NOT NULL"],
3133
+ });
3134
+ }
3135
+ }
3136
+ for (const match of text.matchAll(java)) {
3137
+ const fieldType = match[1].replace(/\s+/g, " ").trim();
3138
+ const name = match[2];
3139
+ if (!seen.has(name) && name !== "serialVersionUID") {
3140
+ seen.add(name);
3141
+ fields.push({ field: name, type: fieldType, key: "", constraints: [] });
3142
+ }
3143
+ }
3144
+ return fields;
3145
+ }
3146
+
3147
+ function parseLitepal(repo, records) {
3148
+ const databases = [];
3149
+ const warnings = [];
3150
+ const sourceLookup = {};
3151
+ for (const sourcePath of Object.keys(records)) {
3152
+ const p = path.join(repo, sourcePath);
3153
+ const suffix = suffixOf(path.basename(p));
3154
+ if (suffix === ".kt" || suffix === ".java") {
3155
+ sourceLookup[path.basename(p).replace(/\.[^.]*$/, "")] = p;
3156
+ }
3157
+ }
3158
+ for (const [sourcePath, record] of Object.entries(records)) {
3159
+ const p = path.join(repo, sourcePath);
3160
+ if (path.basename(p) !== "litepal.xml") {
3161
+ continue;
3162
+ }
3163
+ let root;
3164
+ try {
3165
+ root = parseXmlFile(p);
3166
+ } catch (exc) {
3167
+ warnings.push({ code: "litepal_parse_error", source_path: sourcePath, message: String(exc && exc.message ? exc.message : exc) });
3168
+ continue;
3169
+ }
3170
+ let databaseName = null;
3171
+ for (const element of root.iter()) {
3172
+ if (localName(element.tag) === "dbname") {
3173
+ databaseName = element.attrib.value ?? null;
3174
+ break;
3175
+ }
3176
+ }
3177
+ databaseName = databaseName ?? "LitePalDatabase";
3178
+ const database = {
3179
+ name: databaseName,
3180
+ source_kind: "litepal",
3181
+ confidence: "probable",
3182
+ sources: [sourcePath],
3183
+ tables: [],
3184
+ };
3185
+ for (const element of root.iter()) {
3186
+ if (localName(element.tag) !== "mapping") {
3187
+ continue;
3188
+ }
3189
+ const qualified = element.attrib.class ?? "";
3190
+ const className = qualified.split(".").pop();
3191
+ const modelPath = sourceLookup[className];
3192
+ const columns = [];
3193
+ let tableSource = sourcePath;
3194
+ if (modelPath) {
3195
+ const modelText = readText(modelPath);
3196
+ tableSource = rel(modelPath, repo);
3197
+ for (const field of sourceClassFields(modelText)) {
3198
+ field.source_path = tableSource;
3199
+ field.confidence = "probable";
3200
+ columns.push(field);
3201
+ }
3202
+ } else {
3203
+ warnings.push({
3204
+ code: "litepal_model_missing",
3205
+ source_path: sourcePath,
3206
+ message: `The LitePal model class could not be located: ${qualified}`,
3207
+ });
3208
+ }
3209
+ if (!columns.some((column) => column.field.toLowerCase() === "id")) {
3210
+ columns.unshift({
3211
+ field: "id",
3212
+ type: "INTEGER",
3213
+ key: "PK",
3214
+ constraints: ["AUTO_INCREMENT"],
3215
+ source_path: sourcePath,
3216
+ confidence: "review_required",
3217
+ });
3218
+ warnings.push({
3219
+ code: "litepal_implicit_id_review",
3220
+ source_path: sourcePath,
3221
+ message: `An implicit LitePal id was added for review: ${className}`,
3222
+ });
3223
+ }
3224
+ database.tables.push({
3225
+ name: className,
3226
+ source_path: tableSource,
3227
+ confidence: "probable",
3228
+ columns,
3229
+ table_constraints: [],
3230
+ });
3231
+ }
3232
+ databases.push(database);
3233
+ }
3234
+ return [databases, warnings];
3235
+ }
3236
+
3237
+ function mergeDatabaseSchemas(databases) {
3238
+ const priority = { authoritative: 3, probable: 2, review_required: 1 };
3239
+ const merged = {};
3240
+ for (const database of databases) {
3241
+ const name = database.name;
3242
+ const current = merged[name];
3243
+ if (current === undefined
3244
+ || (priority[database.confidence ?? "review_required"] ?? 0) > (priority[current.confidence ?? "review_required"] ?? 0)) {
3245
+ merged[name] = database;
3246
+ continue;
3247
+ }
3248
+ if (current.confidence === database.confidence) {
3249
+ const tableNames = new Set((current.tables ?? []).map((table) => table.name));
3250
+ current.sources = [...new Set([...(current.sources ?? []), ...(database.sources ?? [])])].sort();
3251
+ for (const table of database.tables ?? []) {
3252
+ if (!tableNames.has(table.name)) {
3253
+ if (!current.tables) current.tables = [];
3254
+ current.tables.push(table);
3255
+ }
3256
+ }
3257
+ }
3258
+ }
3259
+ for (const database of Object.values(merged)) {
3260
+ database.tables = [...(database.tables ?? [])].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
3261
+ }
3262
+ return Object.keys(merged).sort().map((key) => merged[key]);
3263
+ }
3264
+
3265
+ const NON_PREFERENCE_TYPES = new Set([
3266
+ "JSONObject", "JsonObject", "Bundle", "PersistableBundle", "Intent", "Cursor", "Parcel",
3267
+ "TypedArray", "ContentValues", "Map", "HashMap", "MutableMap", "LinkedHashMap", "Properties",
3268
+ ]);
3269
+ const NON_PREFERENCE_RECEIVERS = /^(?:getIntent\(\)|intent|getArguments\(\)|arguments|requireArguments\(\)|savedInstanceState|outState|extras|bundle|args|json\w*|cursor|typedArray)$/i;
3270
+ const NON_PREFERENCE_SEGMENTS = /(?:^|\.)(?:getExtras\(\)|extras|getIntent\(\)|intent|getArguments\(\)|arguments|optJSONObject\([^)]*\)|getJSONObject\([^)]*\))$/;
3271
+
3272
+ // Declared type of a local/field/parameter `name` in this file, if visible.
3273
+ function declaredTypeOf(text, name) {
3274
+ const escaped = name.replace(/[$]/g, "\\$");
3275
+ const patterns = [
3276
+ new RegExp(`\\b([A-Z]\\w*(?:\\.[A-Z]\\w*)?)(?:<[^>]*>)?\\s+${escaped}\\s*[=;,)]`),
3277
+ new RegExp(`\\b(?:val|var)\\s+${escaped}\\s*:\\s*([A-Z]\\w*(?:\\.[A-Z]\\w*)?)`),
3278
+ new RegExp(`\\b${escaped}\\s*:\\s*([A-Z]\\w*(?:\\.[A-Z]\\w*)?)`),
3279
+ new RegExp(`\\b(?:val|var)?\\s*${escaped}\\s*=\\s*(?:new\\s+)?([A-Z]\\w*)\\s*\\(`),
3280
+ ];
3281
+ for (const pattern of patterns) {
3282
+ const match = pattern.exec(text);
3283
+ if (match) return match[1];
3284
+ }
3285
+ return null;
3286
+ }
3287
+
3288
+ // Classify the receiver of a getXxx/putXxx call at `index`:
3289
+ // "preferences" — provably SharedPreferences / Editor (declared type,
3290
+ // getSharedPreferences(...)/edit() chain, or assigned from one);
3291
+ // "other" — provably a JSON/Bundle/Intent/Cursor-like container;
3292
+ // "unknown" — anything else (bare call, helper method, untyped field).
3293
+ function classifyPreferenceReceiver(text, index) {
3294
+ const before = text.slice(Math.max(0, index - 200), index);
3295
+ const chain = /((?:[A-Za-z_]\w*(?:\([^()]*\))?\s*\.\s*)+)$/.exec(before);
3296
+ if (!chain) {
3297
+ return "unknown";
3298
+ }
3299
+ const expr = chain[1].replace(/\s+/g, "").replace(/\.$/, "");
3300
+ if (/getSharedPreferences\(|getDefaultSharedPreferences\(|\.edit\(\)$|^edit\(\)$/.test(expr)) {
3301
+ return "preferences";
3302
+ }
3303
+ if (NON_PREFERENCE_SEGMENTS.test(expr)) {
3304
+ return "other";
3305
+ }
3306
+ const root = expr.split(".")[0];
3307
+ if (expr === root) {
3308
+ const type = declaredTypeOf(text, root);
3309
+ if (type) {
3310
+ if (/SharedPreferences(?:\.Editor)?$|^Editor$/.test(type)) return "preferences";
3311
+ if (NON_PREFERENCE_TYPES.has(type.split(".").pop())) return "other";
3312
+ }
3313
+ const assigned = new RegExp(`\\b${root.replace(/[$]/g, "\\$")}\\s*=\\s*([^;\\n]+)`).exec(text);
3314
+ if (assigned && /getSharedPreferences\(|getDefaultSharedPreferences\(|\.edit\(\)/.test(assigned[1])) {
3315
+ return "preferences";
3316
+ }
3317
+ if (NON_PREFERENCE_RECEIVERS.test(root)) return "other";
3318
+ }
3319
+ return "unknown";
3320
+ }
3321
+
3322
+ function parsePreferences(sourceTexts, records) {
3323
+ const stores = {};
3324
+
3325
+ const ensureStore = (name, sourcePath, kind, confidence) => {
3326
+ if (!(name in stores)) {
3327
+ stores[name] = { name, kind, confidence, sources: [], keys: [] };
3328
+ }
3329
+ const store = stores[name];
3330
+ store.sources.push(sourcePath);
3331
+ return store;
3332
+ };
3333
+
3334
+ for (const [sourcePath, rawText] of Object.entries(sourceTexts)) {
3335
+ const text = stripJvmComments(rawText);
3336
+ const storeNames = [...text.matchAll(/getSharedPreferences\s*\(\s*['"]([^'"]+)['"]/g)].map((m) => m[1]);
3337
+ if (/PreferenceManager\.getDefaultSharedPreferences/.test(text)) {
3338
+ storeNames.push("defaultSharedPreferences");
3339
+ }
3340
+ const uniqueNames = new Set(storeNames);
3341
+ const literalStore = uniqueNames.size === 1 ? storeNames[0] : null;
3342
+
3343
+ const sharedPattern = /\b(get|put)(StringSet|String|Int|Long|Boolean|Float)\s*\(\s*['"]([^'"]+)['"]\s*(?:,\s*([^)]*))?\)/gs;
3344
+ for (const match of text.matchAll(sharedPattern)) {
3345
+ const receiver = classifyPreferenceReceiver(text, match.index);
3346
+ if (receiver === "other") {
3347
+ // JSONObject/Bundle/Intent/Cursor... share the getString/putInt names.
3348
+ continue;
3349
+ }
3350
+ const operation = match[1];
3351
+ const valueType = match[2];
3352
+ const key = match[3];
3353
+ const second = match[4];
3354
+ const storeName = literalStore ?? `@unresolved:${sourcePath}`;
3355
+ const confidence = literalStore && receiver === "preferences" ? "authoritative" : "review_required";
3356
+ const store = ensureStore(storeName, sourcePath, "SharedPreferences", confidence);
3357
+ let def = "";
3358
+ if (operation === "get" && second !== undefined && second !== "") {
3359
+ def = normalizeDeclaration(second.split(",", 1)[0]);
3360
+ }
3361
+ store.keys.push({
3362
+ key,
3363
+ type: valueType,
3364
+ default: def,
3365
+ source_path: sourcePath,
3366
+ confidence,
3367
+ });
3368
+ }
3369
+
3370
+ const dataStorePattern = /(string|int|long|boolean|float|double|stringSet)PreferencesKey\s*\(\s*['"]([^'"]+)['"]\s*\)/gi;
3371
+ for (const match of text.matchAll(dataStorePattern)) {
3372
+ const store = ensureStore("PreferencesDataStore", sourcePath, "DataStore", "authoritative");
3373
+ store.keys.push({
3374
+ key: match[2],
3375
+ type: match[1],
3376
+ default: "",
3377
+ source_path: sourcePath,
3378
+ confidence: "authoritative",
3379
+ });
3380
+ }
3381
+
3382
+ const mmkvPattern = /\b(?:encode|decodeString|decodeInt|decodeLong|decodeBool|decodeFloat|decodeDouble)\s*\(\s*['"]([^'"]+)['"]/gi;
3383
+ for (const match of text.matchAll(mmkvPattern)) {
3384
+ const call = match[0].split("(", 1)[0];
3385
+ const key = match[1];
3386
+ let inferredType = "String";
3387
+ for (const [suffix, valueType] of [["Int", "Int"], ["Long", "Long"], ["Bool", "Boolean"], ["Float", "Float"], ["Double", "Double"]]) {
3388
+ if (call.toLowerCase().includes(suffix.toLowerCase())) {
3389
+ inferredType = valueType;
3390
+ }
3391
+ }
3392
+ const store = ensureStore("MMKV", sourcePath, "MMKV", "authoritative");
3393
+ store.keys.push({
3394
+ key,
3395
+ type: inferredType,
3396
+ default: "",
3397
+ source_path: sourcePath,
3398
+ confidence: "authoritative",
3399
+ });
3400
+ }
3401
+ }
3402
+
3403
+ for (const store of Object.values(stores)) {
3404
+ const unique = {};
3405
+ for (const item of store.keys) {
3406
+ const current = unique[item.key];
3407
+ if (current === undefined || (!current.default && item.default)) {
3408
+ unique[item.key] = item;
3409
+ }
3410
+ }
3411
+ store.keys = Object.keys(unique).sort().map((key) => unique[key]);
3412
+ store.sources = [...new Set(store.sources)].sort();
3413
+ }
3414
+ return Object.keys(stores).sort().map((key) => stores[key]);
3415
+ }
3416
+
3417
+ // ---------------------------------------------------------------------------
3418
+ // Project inspection
3419
+ // ---------------------------------------------------------------------------
3420
+
3421
+ export function inspectProject(scope) {
3422
+ const repo = resolveLikePython(scope.effective_android_repo);
3423
+ const recordsList = scope.admitted_files ?? [];
3424
+ const records = {};
3425
+ for (const item of recordsList) {
3426
+ records[item.path] = item;
3427
+ }
3428
+ const result = {
3429
+ schema_version: SCHEMA_VERSION,
3430
+ project: {
3431
+ effective_android_repo: String(repo),
3432
+ build_system: scope.build_system ?? "gradle",
3433
+ build_resolution_mode: scope.build_resolution_mode ?? "static",
3434
+ build_confidence: scope.build_confidence ?? "high",
3435
+ selected_modules: scope.selected_modules,
3436
+ requested_variant: scope.requested_variant,
3437
+ build_configuration: scope.build_configuration ?? {},
3438
+ selected_source_sets: scope.selected_source_sets,
3439
+ selected_source_roots: scope.selected_source_roots ?? {},
3440
+ project_kind: scope.project_kind ?? "application",
3441
+ },
3442
+ entry_points: [],
3443
+ background_capabilities: [],
3444
+ system_integrations: [],
3445
+ platform_configurations: [],
3446
+ dynamic_review_candidates: [],
3447
+ public_api_surfaces: [],
3448
+ database_schemas: [],
3449
+ preference_stores: [],
3450
+ storage_presence: {},
3451
+ warnings: [...(scope.warnings ?? [])],
3452
+ };
3453
+ const projectKind = result.project.project_kind;
3454
+ const buildSystem = result.project.build_system;
3455
+
3456
+ const sourceTexts = {};
3457
+ for (const [sourcePath, record] of Object.entries(records)) {
3458
+ const p = path.join(repo, sourcePath);
3459
+ const pBasename = path.basename(p);
3460
+ const pSuffix = suffixOf(pBasename);
3461
+ if (SOURCE_SUFFIXES.has(pSuffix)) {
3462
+ sourceTexts[sourcePath] = readText(p);
3463
+ }
3464
+ if (pBasename === "AndroidManifest.xml") {
3465
+ scanManifest(p, record, result);
3466
+ } else if (pSuffix === ".xml" && `/${sourcePath}`.includes("/res/navigation/")) {
3467
+ scanNavigation(p, record, result);
3468
+ } else if (pSuffix === ".xml") {
3469
+ scanPlatformXml(p, record, result);
3470
+ }
3471
+ const nativeBuild = NATIVE_BUILD_FILES.has(pBasename) && !(buildSystem === "aosp" && pBasename === "Android.mk");
3472
+ if (SOURCE_SUFFIXES.has(pSuffix) || NATIVE_SUFFIXES.has(pSuffix) || nativeBuild) {
3473
+ scanSourceSurfaces(p, record, result);
3474
+ }
3475
+ if (projectKind === "library" && SOURCE_SUFFIXES.has(pSuffix)) {
3476
+ scanPublicApiSurface(p, record, result);
3477
+ }
3478
+ }
3479
+
3480
+ const roomVersions = {};
3481
+ for (const [sourcePath, record] of Object.entries(records)) {
3482
+ const p = path.join(repo, sourcePath);
3483
+ if (suffixOf(path.basename(p)) !== ".json" || record.source_set !== "@room-schema") {
3484
+ continue;
3485
+ }
3486
+ const parsed = parseRoomExportedSchema(p, record);
3487
+ if (!parsed) {
3488
+ continue;
3489
+ }
3490
+ const [databaseName, version, tables] = parsed;
3491
+ const database = {
3492
+ name: databaseName,
3493
+ source_kind: "room_exported_schema",
3494
+ confidence: "authoritative",
3495
+ version,
3496
+ sources: [sourcePath],
3497
+ tables,
3498
+ };
3499
+ const current = roomVersions[databaseName];
3500
+ if (current === undefined || version > current[0]) {
3501
+ roomVersions[databaseName] = [version, database];
3502
+ }
3503
+ }
3504
+
3505
+ const databaseCandidates = Object.values(roomVersions).map((value) => value[1]);
3506
+ const roomSource = parseRoomSourceEntities(sourceTexts, records);
3507
+ const exportedNames = new Set(databaseCandidates.map((database) => database.name));
3508
+ for (const database of roomSource) {
3509
+ if (!exportedNames.has(database.name)) {
3510
+ databaseCandidates.push(database);
3511
+ }
3512
+ }
3513
+ databaseCandidates.push(...parseSqliteDatabases(sourceTexts));
3514
+ const [litepal, litepalWarnings] = parseLitepal(repo, records);
3515
+ databaseCandidates.push(...litepal);
3516
+ result.warnings.push(...litepalWarnings);
3517
+ result.database_schemas = mergeDatabaseSchemas(databaseCandidates);
3518
+ result.preference_stores = parsePreferences(sourceTexts, records);
3519
+
3520
+ for (const key of [
3521
+ "entry_points", "background_capabilities", "system_integrations",
3522
+ "platform_configurations", "dynamic_review_candidates", "public_api_surfaces",
3523
+ ]) {
3524
+ result[key] = dedupe(result[key]);
3525
+ }
3526
+
3527
+ for (const database of result.database_schemas) {
3528
+ for (const table of database.tables ?? []) {
3529
+ const columns = table.columns ?? [];
3530
+ if (columns.length > 0 && !columns.some((column) => String(column.key ?? "").toUpperCase().includes("PK"))) {
3531
+ result.warnings.push({
3532
+ code: "database_primary_key_not_recovered",
3533
+ database: database.name,
3534
+ table: table.name,
3535
+ source_path: table.source_path ?? null,
3536
+ message: "No primary key was recovered. Review HomeGraph or source before completing database_design.md.",
3537
+ });
3538
+ }
3539
+ }
3540
+ }
3541
+
3542
+ result.storage_presence = {
3543
+ database: result.database_schemas.length > 0,
3544
+ preferences: result.preference_stores.length > 0,
3545
+ };
3546
+ result.summary = {
3547
+ entry_points: result.entry_points.length,
3548
+ background_capabilities: result.background_capabilities.length,
3549
+ system_integrations: result.system_integrations.length,
3550
+ platform_configurations: result.platform_configurations.length,
3551
+ dynamic_review_candidates: result.dynamic_review_candidates.length,
3552
+ public_api_surfaces: result.public_api_surfaces.length,
3553
+ databases: result.database_schemas.length,
3554
+ preference_stores: result.preference_stores.length,
3555
+ warnings: result.warnings.length,
3556
+ };
3557
+ return result;
3558
+ }
3559
+
3560
+ function buildConfigurationKind(buildSystem) {
3561
+ return {
3562
+ gradle: "variant",
3563
+ maven: "profile",
3564
+ aosp: "product-or-static-scope",
3565
+ generic: "inferred-source-scope",
3566
+ }[buildSystem] ?? "configuration";
3567
+ }
3568
+
3569
+ function main() {
3570
+ const parser = new ArgParser(path.basename(process.argv[1] || "inspect_android_project.mjs"))
3571
+ .addPositional("android_repo")
3572
+ .addOption("--conversion-mode", { choices: ["logical", "direct"], default: "direct" })
3573
+ .addOption("--layered-architecture", { choices: ["true", "false"], default: "true" })
3574
+ .addOption("--app-module", { default: "auto" })
3575
+ .addOption("--target-project-dir", { required: true });
3576
+ const args = parser.parse(process.argv.slice(2));
3577
+ const requestedModule = pyStrip(args.app_module) || "auto";
3578
+
3579
+ const inputRepo = resolveLikePython(expanduser(args.android_repo));
3580
+ if (!isDir(inputRepo)) {
3581
+ systemExit(`android_repo is not a directory: ${inputRepo}`);
3582
+ }
3583
+
3584
+ // Build-system and variant are always auto-resolved; the module scope
3585
+ // follows --app-module when the caller names one.
3586
+ const [effectiveRepo, buildSystem] = resolveEffectiveRepo(inputRepo, requestedModule, "auto", "auto");
3587
+ const targetProjectDir = resolveLikePython(expanduser(args.target_project_dir));
3588
+ const outputDir = targetProjectDir;
3589
+ const hometransDir = resolveLikePython(path.join(targetProjectDir, ".hometrans"));
3590
+ const artifactsDir = resolveLikePython(path.join(hometransDir, "arch_generate"));
3591
+ if (outputDir === artifactsDir) {
3592
+ systemExit("target_project_dir and artifacts_dir cannot resolve to the same path");
3593
+ }
3594
+ if (artifactsDir.split(path.sep).some((part) => part === "build" || part === "generated")) {
3595
+ systemExit("artifacts_dir must not be placed in a generated build directory");
3596
+ }
3597
+
3598
+ // Formal documents are published under .hometrans/.
3599
+ const formalDocuments = new Set([
3600
+ resolveLikePython(path.join(hometransDir, "project_design.md")),
3601
+ resolveLikePython(path.join(hometransDir, "database_design.md")),
3602
+ resolveLikePython(path.join(hometransDir, "preferences_design.md")),
3603
+ ]);
3604
+
3605
+ const [modules, fullDependencyGraph, resolutionMode, buildConfidence, warnings] = discoverBuild(
3606
+ effectiveRepo,
3607
+ buildSystem,
3608
+ "auto",
3609
+ );
3610
+ if (modules.length === 0) {
3611
+ systemExit(`No Android modules could be identified for build system: ${buildSystem}`);
3612
+ }
3613
+
3614
+ const projectKind = resolveProjectKind(modules, "auto", requestedModule, effectiveRepo);
3615
+ const includeClosure = buildSystem === "gradle" || buildSystem === "maven" || buildSystem === "generic";
3616
+ const [selected, selectionWarnings] = selectModules(
3617
+ modules,
3618
+ fullDependencyGraph,
3619
+ requestedModule,
3620
+ projectKind,
3621
+ effectiveRepo,
3622
+ includeClosure,
3623
+ );
3624
+ warnings.push(...selectionWarnings);
3625
+
3626
+ const moduleDependencyGraph = {};
3627
+ for (const module of selected) {
3628
+ moduleDependencyGraph[module.module_id] = [...(fullDependencyGraph[module.module_id] ?? [])].sort();
3629
+ }
3630
+
3631
+ const sourceScopes = {};
3632
+ for (const module of selected) {
3633
+ const [resolved, moduleWarnings] = resolveSourceScopes(module, "auto");
3634
+ sourceScopes[module.module_id] = resolved;
3635
+ warnings.push(...moduleWarnings);
3636
+ }
3637
+
3638
+ const selectedSourceSets = {};
3639
+ for (const module of selected) {
3640
+ selectedSourceSets[module.module_id] = sourceScopes[module.module_id].map((scope) => scope.label);
3641
+ }
3642
+ const selectedSourceRoots = {};
3643
+ for (const module of selected) {
3644
+ selectedSourceRoots[module.module_id] = sourceScopes[module.module_id].map((scope) => relOrAbs(scope.path, effectiveRepo));
3645
+ }
3646
+
3647
+ const serializedModules = [];
3648
+ for (const module of modules) {
3649
+ const item = {
3650
+ id: module.module_id,
3651
+ directory: relOrAbs(module.directory, effectiveRepo),
3652
+ kind: module.kind,
3653
+ build_system: module.build_system,
3654
+ build_type: module.build_type,
3655
+ };
3656
+ if (module.build_file) {
3657
+ item.build_file = relOrAbs(module.build_file, effectiveRepo);
3658
+ }
3659
+ if (module.build_system === "gradle") {
3660
+ item.gradle_path = module.module_id;
3661
+ }
3662
+ serializedModules.push(item);
3663
+ }
3664
+
3665
+ const scope = {
3666
+ schema_version: SCHEMA_VERSION,
3667
+ input_repository: String(inputRepo),
3668
+ effective_android_repo: String(effectiveRepo),
3669
+ source_kind: "android",
3670
+ build_system: buildSystem,
3671
+ requested_build_system: "auto",
3672
+ build_resolution_mode: resolutionMode,
3673
+ build_confidence: buildConfidence,
3674
+ requested_app_module: requestedModule,
3675
+ project_kind: projectKind,
3676
+ selected_modules: selected.map((module) => module.module_id),
3677
+ associated_dynamic_features: selected.filter((module) => module.kind === "dynamic-feature").map((module) => module.module_id),
3678
+ module_dependency_graph: moduleDependencyGraph,
3679
+ requested_variant: "auto",
3680
+ build_configuration: {
3681
+ kind: buildConfigurationKind(buildSystem),
3682
+ requested: "auto",
3683
+ },
3684
+ // selected_source_sets is retained for compatibility with existing consumers.
3685
+ selected_source_sets: selectedSourceSets,
3686
+ selected_source_roots: selectedSourceRoots,
3687
+ modules: serializedModules,
3688
+ output_dir: String(outputDir),
3689
+ artifacts_dir: String(artifactsDir),
3690
+ target_project_dir: String(targetProjectDir),
3691
+ formal_documents: {
3692
+ project_design: path.join(hometransDir, "project_design.md"),
3693
+ database_design: path.join(hometransDir, "database_design.md"),
3694
+ preferences_design: path.join(hometransDir, "preferences_design.md"),
3695
+ },
3696
+ conversion_mode: args.conversion_mode,
3697
+ packaging_mode: args.layered_architecture === "true" ? "layered" : "single-entry",
3698
+ native_inspection: "automatic",
3699
+ warnings,
3700
+ };
3701
+ scope.admitted_files = admittedFiles(
3702
+ effectiveRepo,
3703
+ selected,
3704
+ sourceScopes,
3705
+ artifactsDir,
3706
+ formalDocuments,
3707
+ buildSystem,
3708
+ );
3709
+ const inspection = inspectProject(scope);
3710
+
3711
+ const scopePath = path.join(artifactsDir, "scope.json");
3712
+ const inspectionPath = path.join(artifactsDir, "inspection.json");
3713
+ atomicWriteJson(scopePath, scope);
3714
+ atomicWriteJson(inspectionPath, inspection);
3715
+ process.stdout.write(`${pyJsonDump({
3716
+ scope: String(scopePath),
3717
+ inspection: String(inspectionPath),
3718
+ effective_android_repo: String(effectiveRepo),
3719
+ source_kind: "android",
3720
+ build_system: buildSystem,
3721
+ build_resolution_mode: resolutionMode,
3722
+ build_confidence: buildConfidence,
3723
+ project_kind: scope.project_kind,
3724
+ selected_modules: scope.selected_modules,
3725
+ selected_source_sets: scope.selected_source_sets,
3726
+ selected_source_roots: scope.selected_source_roots,
3727
+ storage_presence: inspection.storage_presence,
3728
+ conversion_mode: scope.conversion_mode,
3729
+ packaging_mode: scope.packaging_mode,
3730
+ summary: inspection.summary,
3731
+ }, { indent: null })}\n`);
3732
+ return 0;
3733
+ }
3734
+
3735
+ const isMain = process.argv[1]
3736
+ && import.meta.url === pathToFileURL(fs.realpathSync(process.argv[1])).href;
3737
+ if (isMain) {
3738
+ process.exitCode = main();
3739
+ }