@buaa_smat/hometrans 0.1.17 → 0.1.19

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 (234) hide show
  1. package/README.md +120 -56
  2. package/agents/code-reviewer.md +321 -65
  3. package/agents/logic-coder.md +113 -88
  4. package/agents/logic-context-builder.md +47 -29
  5. package/agents/scripts/hmos-precheck/backends/arkts.mjs +567 -0
  6. package/agents/scripts/hmos-precheck/backends/arkts_diff.mjs +159 -0
  7. package/agents/scripts/hmos-precheck/backends/arkts_project_rules.mjs +398 -0
  8. package/agents/scripts/hmos-precheck/backends/codelinter.mjs +250 -0
  9. package/agents/scripts/hmos-precheck/backends/project_integrity.mjs +321 -0
  10. package/agents/scripts/hmos-precheck/backends/static_precheck.mjs +247 -0
  11. package/agents/scripts/hmos-precheck/core/config.mjs +184 -0
  12. package/agents/scripts/hmos-precheck/core/diagnostic_scope.mjs +20 -0
  13. package/agents/scripts/hmos-precheck/core/process_adapter.mjs +47 -0
  14. package/agents/scripts/hmos-precheck/core/project_catalog.mjs +50 -0
  15. package/agents/scripts/hmos-precheck/core/result_projection.mjs +147 -0
  16. package/agents/scripts/hmos-precheck/core/scope_plan.mjs +131 -0
  17. package/agents/scripts/hmos-precheck/core/sdk_context.mjs +67 -0
  18. package/agents/scripts/hmos-precheck/docs/architecture.md +37 -0
  19. package/agents/scripts/hmos-precheck/docs/performance-optimization.md +28 -0
  20. package/agents/scripts/hmos-precheck/docs/upstream-reference.json +19 -0
  21. package/agents/scripts/hmos-precheck/docs/validation.md +50 -0
  22. package/agents/scripts/hmos-precheck/index.mjs +17 -0
  23. package/agents/scripts/hmos-precheck/invocation.mjs +231 -0
  24. package/agents/scripts/hmos-precheck/rules/rule_case_matrix.csv +32 -0
  25. package/agents/scripts/hmos-precheck/rules/rule_inventory.csv +64 -0
  26. package/agents/scripts/hmos-precheck/rules/rule_inventory.mjs +59 -0
  27. package/agents/scripts/hmos-precheck/rules/rule_policy.mjs +54 -0
  28. package/agents/scripts/platform_query.mjs +626 -0
  29. package/agents/scripts/platform_query.test.mjs +422 -0
  30. package/agents/self-test-fixer.md +36 -34
  31. package/agents/self-tester.md +123 -143
  32. package/agents/test-case-generation-generator.md +317 -0
  33. package/agents/test-case-generation-validator.md +231 -0
  34. package/dist/cli/config-store.js +16 -63
  35. package/dist/cli/env-vars.js +1 -3
  36. package/dist/cli/index.js +0 -11
  37. package/dist/cli/init.js +123 -204
  38. package/dist/cli/uninstall.js +3 -127
  39. package/dist/utils/regex.js +8 -0
  40. package/env-requirements.json +55 -54
  41. package/package.json +6 -6
  42. package/resource/convert_pipeline_process.svg +103 -0
  43. package/resource/project_architecture.svg +122 -0
  44. package/resource/title_dark.png +0 -0
  45. package/skills/hmos-batch-ui-align/SKILL.md +345 -43
  46. package/skills/hmos-batch-ui-align/references/conversion-procedure.md +661 -180
  47. package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +2533 -2533
  48. package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +555 -555
  49. package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +117 -117
  50. package/skills/hmos-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 +648 -648
  51. package/skills/hmos-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 +2088 -2088
  52. package/skills/hmos-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 +1033 -1033
  53. package/skills/hmos-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 +1183 -1183
  54. package/skills/hmos-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 +576 -576
  55. package/skills/hmos-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 +297 -297
  56. package/skills/hmos-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 +395 -395
  57. package/skills/hmos-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 +902 -902
  58. package/skills/hmos-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 +106 -106
  59. package/skills/hmos-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 +1178 -1178
  60. package/skills/hmos-batch-ui-align/references/mvvm/MVVM/346/250/241/345/274/217/357/274/210V1/357/274/211.md +911 -911
  61. package/skills/hmos-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 +354 -354
  62. package/skills/hmos-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 +11 -11
  63. package/skills/hmos-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 +206 -0
  64. package/skills/hmos-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 +373 -0
  65. package/skills/hmos-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 +158 -0
  66. package/skills/hmos-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 +750 -0
  67. package/skills/hmos-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 +1704 -0
  68. package/skills/hmos-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 +1012 -0
  69. package/skills/hmos-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 +164 -0
  70. package/skills/hmos-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 +840 -0
  71. package/skills/hmos-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 +856 -0
  72. package/skills/hmos-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 +83 -0
  73. package/skills/hmos-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 +294 -0
  74. package/skills/hmos-batch-ui-align/references/mvvm-v2/MVVM/346/250/241/345/274/217/357/274/210V2/357/274/211.md +1407 -0
  75. package/skills/hmos-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 +1220 -0
  76. package/skills/hmos-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 +47 -0
  77. package/skills/hmos-batch-ui-align/references/mvvm-v2/_/350/243/205/351/245/260/345/231/250/351/200/237/346/237/245.md +133 -0
  78. package/skills/hmos-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 +840 -0
  79. package/skills/hmos-batch-ui-align/scripts/android_parse_fast.ts +1798 -0
  80. package/skills/hmos-batch-ui-align/scripts/arkts_static_check.ts +1592 -0
  81. package/skills/hmos-batch-ui-align/scripts/measure_pack.ts +752 -0
  82. package/skills/hmos-convert-pipeline/SKILL.md +168 -121
  83. package/skills/hmos-fix-build-errors/SKILL.md +87 -67
  84. package/skills/hmos-fix-build-errors/references/arkts-strict-patterns.md +219 -219
  85. package/skills/hmos-fix-build-errors/references/known-patterns.md +157 -157
  86. package/skills/hmos-fix-build-errors/references/rdb-entity-pattern.md +131 -131
  87. package/skills/hmos-incremental-ui-align/README.md +53 -36
  88. package/skills/hmos-incremental-ui-align/SKILL.md +179 -23
  89. package/skills/hmos-incremental-ui-align/diff_analysis.md +52 -52
  90. package/skills/hmos-incremental-ui-align/page_align.md +62 -62
  91. package/skills/hmos-incremental-ui-align/references/Comparison_Template.md +38 -2
  92. 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 +648 -648
  93. 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 +2088 -2088
  94. 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 +1033 -1033
  95. 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 +1183 -1183
  96. 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 +576 -576
  97. 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 +297 -297
  98. 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 +395 -395
  99. 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 +902 -902
  100. 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 +106 -106
  101. 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 +1178 -1178
  102. 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 +911 -911
  103. 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 +354 -354
  104. 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 +11 -11
  105. 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 +206 -0
  106. 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 +373 -0
  107. 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 +158 -0
  108. 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 +750 -0
  109. 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 +1704 -0
  110. 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 +1012 -0
  111. 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 +164 -0
  112. 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 +840 -0
  113. 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 +856 -0
  114. 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 +83 -0
  115. 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 +294 -0
  116. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/MVVM/346/250/241/345/274/217/357/274/210V2/357/274/211.md +1407 -0
  117. 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 +1220 -0
  118. 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 +47 -0
  119. 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 +840 -0
  120. package/skills/hmos-incremental-ui-align/references/State_Model_Template.md +74 -0
  121. package/skills/hmos-incremental-ui-align/references/UI_Analysis_Template.md +34 -4
  122. package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +2533 -2533
  123. package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-interaction-mapping-reference.md +555 -555
  124. package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-layout-mapping-reference.md +117 -117
  125. package/skills/hmos-incremental-ui-align/scripts/app_feature_verify.ts +937 -0
  126. package/skills/hmos-incremental-ui-align/scripts/extract_checklist.ts +343 -0
  127. package/skills/hmos-incremental-ui-align/scripts/navigation-capure.md +44 -5
  128. package/skills/hmos-incremental-ui-align/scripts/page_capture.ts +977 -0
  129. package/skills/hmos-incremental-ui-align/scripts/page_capture_burst.ts +188 -0
  130. package/skills/hmos-integration-test/README.md +61 -70
  131. package/skills/hmos-integration-test/SKILL.md +128 -111
  132. package/skills/hmos-resources-convert/SKILL.md +334 -66
  133. package/skills/hmos-resources-convert/references/code-vector-icon-rules.md +335 -0
  134. package/skills/hmos-resources-convert/references/conversion-rules.md +676 -663
  135. package/skills/hmos-resources-convert/references/dependency-analysis-rules.md +410 -388
  136. package/skills/hmos-resources-convert/references/lottie-conversion-rules.md +219 -0
  137. package/skills/hmos-resources-convert/references/resource-mapping-rules.md +482 -457
  138. package/skills/hmos-resources-convert/references/xml-drawable-to-svg-rules.md +592 -513
  139. package/skills/hmos-resources-convert/scripts/a2h_resource_convert.ts +2163 -0
  140. package/skills/hmos-resources-convert/scripts/code_vector_icons.ts +591 -0
  141. package/skills/hmos-resources-convert/scripts/svg_fidelity_check.ts +632 -0
  142. package/skills/hmos-spec-generate/SKILL.md +293 -214
  143. package/skills/hmos-spec-generate/scripts/parse_requirements.ts +515 -0
  144. package/skills/hmos-spec-generate/template/REQ.txt +22 -0
  145. package/skills/hmos-spec-generate/template/REQ.xlsx +0 -0
  146. package/skills/hmos-test-case-generation/README.md +241 -0
  147. package/skills/hmos-test-case-generation/SKILL.md +324 -0
  148. package/skills/hmos-test-case-generation/references/contract.md +315 -0
  149. package/skills/hmos-test-case-generation/references/review-notes-template.md +84 -0
  150. package/skills/hmos-test-case-generation/references/ui-elements-schema.md +142 -0
  151. package/skills/hmos-test-case-generation/tools/convert_to_ui_elements.ts +550 -0
  152. package/skills/hmos-test-case-generation/tools/validate.ts +1312 -0
  153. package/tools/bfs-crawl/README.md +73 -0
  154. package/tools/bfs-crawl/android_viewtree_bfs_crawler.ts +1662 -0
  155. package/tools/test-tools/autotest/config.ts +175 -0
  156. package/tools/test-tools/autotest/deps/autotest-agent-0.1.1.tgz +0 -0
  157. package/tools/test-tools/autotest/docs/README.md +266 -0
  158. package/tools/test-tools/autotest/{testcases_schema.md → docs/testcases_schema.md} +1 -1
  159. package/tools/test-tools/autotest/engine/batch-launcher.ts +327 -0
  160. package/tools/test-tools/autotest/engine/report-tool.ts +773 -0
  161. package/tools/test-tools/autotest/engine/self-test-runner.ts +961 -0
  162. package/tools/test-tools/autotest/engine/testcases-tool.ts +246 -0
  163. package/tools/test-tools/autotest/paths.ts +41 -0
  164. package/tools/test-tools/autotest/resolve-metadata-tool.ts +143 -0
  165. package/tools/test-tools/autotest/runner/logger.ts +45 -0
  166. package/tools/test-tools/autotest/runner/process-utils.ts +41 -0
  167. package/tools/test-tools/autotest/validate.ts +167 -0
  168. package/agents/build-fixer.md +0 -385
  169. package/agents/logic-coder/scripts/platform_context_query.py +0 -568
  170. package/agents/review-fixer.md +0 -405
  171. package/agents/spec-generator.md +0 -541
  172. package/dist/cli/mcp-setup.js +0 -258
  173. package/dist/cli/mcp.js +0 -94
  174. package/dist/context/index.js +0 -694
  175. package/resource/migration_process.svg +0 -94
  176. package/resource/migration_process_transparent.svg +0 -93
  177. package/skills/hmos-batch-ui-align/scripts/android_parse_fast.py +0 -1606
  178. package/skills/hmos-incremental-ui-align/scripts/__pycache__/app_feature_verify.cpython-314.pyc +0 -0
  179. package/skills/hmos-incremental-ui-align/scripts/app_feature_verify.py +0 -542
  180. package/skills/hmos-incremental-ui-align/scripts/page_capture.py +0 -597
  181. package/skills/hmos-resources-convert/evals/evals.json +0 -171
  182. package/skills/hmos-resources-convert/template/AppScope/app.json5 +0 -10
  183. package/skills/hmos-resources-convert/template/AppScope/resources/base/element/string.json +0 -8
  184. package/skills/hmos-resources-convert/template/AppScope/resources/base/media/background.png +0 -0
  185. package/skills/hmos-resources-convert/template/AppScope/resources/base/media/foreground.png +0 -0
  186. package/skills/hmos-resources-convert/template/AppScope/resources/base/media/layered_image.json +0 -7
  187. package/skills/hmos-resources-convert/template/build-profile.json5 +0 -42
  188. package/skills/hmos-resources-convert/template/code-linter.json5 +0 -32
  189. package/skills/hmos-resources-convert/template/entry/build-profile.json5 +0 -33
  190. package/skills/hmos-resources-convert/template/entry/hvigorfile.ts +0 -6
  191. package/skills/hmos-resources-convert/template/entry/obfuscation-rules.txt +0 -23
  192. package/skills/hmos-resources-convert/template/entry/oh-package.json5 +0 -10
  193. package/skills/hmos-resources-convert/template/entry/src/main/ets/entryability/EntryAbility.ets +0 -48
  194. package/skills/hmos-resources-convert/template/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +0 -16
  195. package/skills/hmos-resources-convert/template/entry/src/main/ets/pages/Index.ets +0 -23
  196. package/skills/hmos-resources-convert/template/entry/src/main/module.json5 +0 -55
  197. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/element/color.json +0 -8
  198. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/element/float.json +0 -8
  199. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/element/string.json +0 -16
  200. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/media/background.png +0 -0
  201. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/media/foreground.png +0 -0
  202. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/media/layered_image.json +0 -7
  203. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/media/startIcon.png +0 -0
  204. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/profile/backup_config.json +0 -3
  205. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/profile/main_pages.json +0 -5
  206. package/skills/hmos-resources-convert/template/entry/src/main/resources/dark/element/color.json +0 -8
  207. package/skills/hmos-resources-convert/template/entry/src/mock/mock-config.json5 +0 -2
  208. package/skills/hmos-resources-convert/template/entry/src/ohosTest/ets/test/Ability.test.ets +0 -35
  209. package/skills/hmos-resources-convert/template/entry/src/ohosTest/ets/test/List.test.ets +0 -5
  210. package/skills/hmos-resources-convert/template/entry/src/ohosTest/module.json5 +0 -16
  211. package/skills/hmos-resources-convert/template/entry/src/test/List.test.ets +0 -5
  212. package/skills/hmos-resources-convert/template/entry/src/test/LocalUnit.test.ets +0 -33
  213. package/skills/hmos-resources-convert/template/hvigor/hvigor-config.json5 +0 -23
  214. package/skills/hmos-resources-convert/template/hvigorfile.ts +0 -6
  215. package/skills/hmos-resources-convert/template/oh-package-lock.json5 +0 -28
  216. package/skills/hmos-resources-convert/template/oh-package.json5 +0 -10
  217. package/skills/hmos-resources-convert/tools/apktool_3.0.1.jar +0 -0
  218. package/skills/hmos-spec-generate/references/android-platform-tokens.md +0 -105
  219. package/skills/hmos-spec-generate/references/spec-sample-1.md +0 -78
  220. package/skills/hmos-spec-generate/references/spec-sample-2.md +0 -58
  221. package/skills/hmos-spec-generate/references/spec-sample-3.md +0 -116
  222. package/skills/hmos-spec-generate/references/step4-report-template.md +0 -33
  223. package/tools/test-tools/autotest/README.md +0 -238
  224. package/tools/test-tools/autotest/pyproject.toml +0 -26
  225. package/tools/test-tools/autotest/report_tool.py +0 -759
  226. package/tools/test-tools/autotest/self_test_runner.py +0 -895
  227. package/tools/test-tools/autotest/testcases_tool.py +0 -215
  228. package/tools/test-tools/autotest/uv.lock +0 -3156
  229. package/tools/test-tools/harmony_autotest-0.1.0-py3-none-any.whl +0 -0
  230. package/tools/test-tools/hypium-6.1.0.210-py3-none-any.whl +0 -0
  231. package/tools/test-tools/hypium_mcp-0.6.5-py3-none-any.whl +0 -0
  232. package/tools/test-tools/xdevice-6.1.0.210-py3-none-any.whl +0 -0
  233. package/tools/test-tools/xdevice_devicetest-6.1.0.210-py3-none-any.whl +0 -0
  234. package/tools/test-tools/xdevice_ohos-6.1.0.210-py3-none-any.whl +0 -0
@@ -0,0 +1,246 @@
1
+ /**
2
+ * Generate or validate testcases.json for the Self-Testing Agent.
3
+ *
4
+ * TS port of `tools/test-tools/autotest/testcases_tool.py`.
5
+ *
6
+ * Subcommands:
7
+ * generate <input-json> <output-json> [--validate]
8
+ * Rewrite app_name → bundle_name and compose `test_steps` strictly
9
+ * ("动作:..." / "预期结果:..."). Optionally re-validate the output.
10
+ *
11
+ * validate <testcases-json>
12
+ * Check a `testcases.json` (array of cases) against the schema in
13
+ * `testcases_schema.md`. Exit 0 = PASSED, exit 1 = FAILED.
14
+ *
15
+ * The forbidden-strings and section-header rules live in this file as the
16
+ * single source of truth — generate enforces them at write time, validate
17
+ * re-checks them on existing files.
18
+ */
19
+ import fs from 'node:fs';
20
+ import path from 'node:path';
21
+ import { fileURLToPath } from 'node:url';
22
+ import { Command } from 'commander';
23
+
24
+ const FORBIDDEN_STRINGS = [
25
+ '前置条件',
26
+ 'Spec:',
27
+ 'Scenario:',
28
+ 'ability_name:',
29
+ 'module_name:',
30
+ ] as const;
31
+
32
+ const SECTION_HEADER_RE = /【(.+?)】/;
33
+
34
+ const REQUIRED_LINES = ['动作:', '预期结果:'] as const;
35
+
36
+ const TEST_STEPS_TEMPLATE = '动作:{actions}\n预期结果:{expected_results}';
37
+
38
+ /** Input case shape from the extractor. */
39
+ interface InputCase {
40
+ case_name: string;
41
+ actions: string;
42
+ expected_results: string;
43
+ }
44
+
45
+ /** Input document: extractor output consumed by `generate`. */
46
+ interface InputData {
47
+ bundle_name: string;
48
+ app_name: string;
49
+ cases: InputCase[];
50
+ }
51
+
52
+ /** Output case shape: what we write to testcases.json. */
53
+ interface OutputCase {
54
+ case_name: string;
55
+ bundle_name: string;
56
+ app_name: string;
57
+ test_steps: string;
58
+ }
59
+
60
+ /** Safety net: replace remaining app_name references with bundle_name. */
61
+ function rewriteAppName(text: string, appName: string, bundleName: string): string {
62
+ if (appName && text.includes(appName)) {
63
+ return text.replaceAll(appName, bundleName);
64
+ }
65
+ return text;
66
+ }
67
+
68
+ /** Compose a compliant test_steps string with only 动作 and 预期结果. */
69
+ function composeTestSteps(
70
+ appName: string,
71
+ bundleName: string,
72
+ actions: string,
73
+ expectedResults: string,
74
+ ): string {
75
+ const rewrittenActions = rewriteAppName(actions, appName, bundleName);
76
+ const rewrittenExpected = rewriteAppName(expectedResults, appName, bundleName);
77
+ // Use function replacements so '$' sequences ($&, $$, $1, ...) in the action /
78
+ // expected text are inserted literally — String.replace with a STRING argument
79
+ // would interpret them, diverging from Python str.format().
80
+ let testSteps = TEST_STEPS_TEMPLATE.replace('{actions}', () => rewrittenActions).replace(
81
+ '{expected_results}',
82
+ () => rewrittenExpected,
83
+ );
84
+ // Final safety: rewrite once more in case app_name only became visible after composition.
85
+ testSteps = rewriteAppName(testSteps, appName, bundleName);
86
+
87
+ for (const forbidden of FORBIDDEN_STRINGS) {
88
+ if (testSteps.includes(forbidden)) {
89
+ throw new Error(
90
+ `FATAL: forbidden string '${forbidden}' found in generated test_steps. ` +
91
+ `This is a bug in testcases-tool.`,
92
+ );
93
+ }
94
+ }
95
+ const sectionMatch = SECTION_HEADER_RE.exec(testSteps);
96
+ if (sectionMatch) {
97
+ throw new Error(
98
+ `FATAL: unexpected section header 【${sectionMatch[1]}】 in generated test_steps. ` +
99
+ `test_steps should only contain 动作 and 预期结果.`,
100
+ );
101
+ }
102
+ return testSteps;
103
+ }
104
+
105
+ /** Generate compliant testcases array from input data. */
106
+ export function generate(inputData: InputData): OutputCase[] {
107
+ const { bundle_name: bundleName, app_name: appName, cases } = inputData;
108
+ // Fail loudly on malformed extractor input instead of silently writing
109
+ // `undefined`/dropped keys (Python indexed with [] and raised KeyError).
110
+ const missingTop = (['bundle_name', 'app_name', 'cases'] as const).filter(
111
+ (k) => inputData[k] === undefined,
112
+ );
113
+ if (missingTop.length > 0) {
114
+ throw new Error(`FATAL: input is missing required key(s): ${missingTop.join(', ')}.`);
115
+ }
116
+ const result: OutputCase[] = [];
117
+ for (const [i, c] of cases.entries()) {
118
+ const missingCase = (['case_name', 'actions', 'expected_results'] as const).filter(
119
+ (k) => c[k] === undefined,
120
+ );
121
+ if (missingCase.length > 0) {
122
+ throw new Error(
123
+ `FATAL: case ${i} (${c.case_name ?? '<no case_name>'}) is missing required key(s): ` +
124
+ `${missingCase.join(', ')}.`,
125
+ );
126
+ }
127
+ const testSteps = composeTestSteps(appName, bundleName, c.actions, c.expected_results);
128
+ result.push({
129
+ case_name: c.case_name,
130
+ bundle_name: bundleName,
131
+ app_name: appName,
132
+ test_steps: testSteps,
133
+ });
134
+ }
135
+ return result;
136
+ }
137
+
138
+ /** Return a list of validation error messages. Empty list means PASSED. */
139
+ export function validateTestcases(filepath: string): string[] {
140
+ const raw = fs.readFileSync(filepath, 'utf-8');
141
+ const cases: unknown = JSON.parse(raw);
142
+
143
+ if (!Array.isArray(cases)) return ['Root element is not a JSON array'];
144
+
145
+ const errors: string[] = [];
146
+ const globalSectionRe = new RegExp(SECTION_HEADER_RE.source, 'g');
147
+ cases.forEach((c: any, i: number) => {
148
+ const ts: string = c?.test_steps ?? '';
149
+ const name: string = c?.case_name ?? `case_${i}`;
150
+ const appName: string = c?.app_name ?? '';
151
+ const bundleName: string = c?.bundle_name ?? '';
152
+ const prefix = `Case ${i + 1} [${name}]`;
153
+
154
+ for (const required of REQUIRED_LINES) {
155
+ if (!ts.includes(required)) errors.push(`${prefix}: MISSING ${required} line`);
156
+ }
157
+
158
+ for (const forbidden of FORBIDDEN_STRINGS) {
159
+ if (ts.includes(forbidden)) {
160
+ errors.push(`${prefix}: CONTAINS ${forbidden} (must be excluded)`);
161
+ }
162
+ }
163
+
164
+ let m: RegExpExecArray | null;
165
+ while ((m = globalSectionRe.exec(ts)) !== null) {
166
+ errors.push(
167
+ `${prefix}: CONTAINS unexpected section header 【${m[1]}】 ` +
168
+ `(test_steps should only contain 动作 and 预期结果)`,
169
+ );
170
+ }
171
+
172
+ if (appName && bundleName && appName !== bundleName && ts.includes(appName)) {
173
+ errors.push(
174
+ `${prefix}: test_steps contains app_name '${appName}' instead of bundle_name ` +
175
+ `'${bundleName}'. All app name references in test_steps must use bundle_name.`,
176
+ );
177
+ }
178
+ });
179
+ return errors;
180
+ }
181
+
182
+ function cmdGenerate(input: string, output: string, doValidate: boolean): void {
183
+ const inputData = JSON.parse(fs.readFileSync(input, 'utf-8')) as InputData;
184
+ const testcases = generate(inputData);
185
+ fs.writeFileSync(output, JSON.stringify(testcases, null, 2), 'utf-8');
186
+ console.log(`Generated ${testcases.length} test cases -> ${output}`);
187
+
188
+ if (doValidate) {
189
+ const errors = validateTestcases(output);
190
+ if (errors.length > 0) {
191
+ console.log('VALIDATION FAILED:');
192
+ for (const e of errors) console.log(` [FAIL] ${e}`);
193
+ process.exit(1);
194
+ }
195
+ console.log(`VALIDATION PASSED: all ${testcases.length} cases conform to the schema`);
196
+ }
197
+ }
198
+
199
+ function cmdValidate(filepath: string): void {
200
+ const errors = validateTestcases(filepath);
201
+ if (errors.length > 0) {
202
+ console.log('VALIDATION FAILED:');
203
+ for (const e of errors) console.log(` [FAIL] ${e}`);
204
+ process.exit(1);
205
+ }
206
+ const cases = JSON.parse(fs.readFileSync(filepath, 'utf-8')) as unknown[];
207
+ console.log(`VALIDATION PASSED: all ${cases.length} cases have correct test_steps format`);
208
+ }
209
+
210
+ /** CLI entry — wires up commander with `generate` and `validate` subcommands. */
211
+ export function main(): void {
212
+ const program = new Command();
213
+ program.description(
214
+ 'Generate or validate testcases.json for the Self-Testing Agent.',
215
+ );
216
+
217
+ program
218
+ .command('generate')
219
+ .description('Generate compliant testcases.json from an extracted input')
220
+ .argument('<input>', 'Path to the extracted input JSON')
221
+ .argument('<output>', 'Path to write the compliant testcases.json')
222
+ .option('--validate', 'After writing, re-validate the output against the schema')
223
+ .action((input: string, output: string, opts: { validate?: boolean }) => {
224
+ cmdGenerate(input, output, !!opts.validate);
225
+ });
226
+
227
+ program
228
+ .command('validate')
229
+ .description('Validate an existing testcases.json against the schema')
230
+ .argument('<path>', 'Path to the testcases.json to validate')
231
+ .action((filepath: string) => {
232
+ cmdValidate(filepath);
233
+ });
234
+
235
+ program.parseAsync(process.argv).catch((err) => {
236
+ console.error(err instanceof Error ? err.message : err);
237
+ process.exit(1);
238
+ });
239
+ }
240
+
241
+ const __filename = fileURLToPath(import.meta.url);
242
+ const isMainEntry =
243
+ !!process.argv[1] && fs.realpathSync(process.argv[1]) === __filename;
244
+ if (isMainEntry) {
245
+ main();
246
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Shared path resolution for the AutoTest CLI tools
3
+ * (testcases-tool / report-tool / self-test-runner TS ports).
4
+ *
5
+ * Replaces Python's `SCRIPT_DIR = Path(__file__).resolve().parent` and the
6
+ * `~/.hometrans/config.json` + `HOMETRANS_TOOL_PATH` autotest-dir resolution
7
+ * chain that lived at the top of `self_test_runner.py`.
8
+ */
9
+ import fs from 'node:fs';
10
+ import os from 'node:os';
11
+ import path from 'node:path';
12
+ import { fileURLToPath } from 'node:url';
13
+
14
+ /**
15
+ * Directory of the running JS file. Mirrors Python's `Path(__file__).parent`.
16
+ * Resolves to the autotest source dir `tools/test-tools/autotest/` at runtime.
17
+ *
18
+ * Resolution order: source-tree walk-up → `HOMETRANS_TOOL_PATH` →
19
+ * `~/.hometrans/tools`. `HOMETRANS_TOOL_PATH` is the single tools-dir env var;
20
+ * there is deliberately no autotest-specific override.
21
+ */
22
+ export function autotestDir(): string {
23
+ // Prefer the source-tree / npm package directory — always current after
24
+ // `npm update`, no need for the user to re-run `ht init` to sync.
25
+ // Walk up from this module's location until we find `tools/test-tools/autotest`.
26
+ const here = path.dirname(fileURLToPath(import.meta.url));
27
+ let dir = here;
28
+ for (let i = 0; i < 10 && dir; i++) {
29
+ const probe = path.join(dir, 'tools', 'test-tools', 'autotest');
30
+ if (fs.existsSync(probe)) return probe;
31
+ const parent = path.dirname(dir);
32
+ if (parent === dir) break;
33
+ dir = parent;
34
+ }
35
+
36
+ // Fallback: `HOMETRANS_TOOL_PATH` (persisted by `ht init`) → ~/.hometrans/tools.
37
+ const toolPath =
38
+ process.env.HOMETRANS_TOOL_PATH || path.join(os.homedir(), '.hometrans', 'tools');
39
+ const candidate = path.join(toolPath, 'test-tools', 'autotest');
40
+ return candidate; // return the canonical path even if absent; caller will error clearly
41
+ }
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Resolve App Metadata — discover `bundle_name` / `app_name` from a HarmonyOS
3
+ * project and write `app-metadata.json`.
4
+ *
5
+ * Subcommand:
6
+ * resolve-metadata --project-dir <dir> --output <path>
7
+ * Reads `<project-dir>/AppScope/app.json5` (JSON5 via jsonc-parser),
8
+ * extracts `app.bundleName` and `app.label` (resolving `$string:xxx`
9
+ * references from the base-qualifier string.json), writes
10
+ * `{bundle_name, app_name, project_root}` to `--output`, and emits the
11
+ * same JSON to stdout.
12
+ *
13
+ * Exit codes: 0 = success (JSON emitted + file written), 1 = any failure
14
+ * (invalid project root, JSON5 parse failure, missing bundleName, write
15
+ * failure). Errors go to stderr; stdout carries exactly one JSON line on
16
+ * success. This is the deterministic replacement for the LLM-driven discovery
17
+ * that previously lived in the self-tester agent prompt (S2/S3).
18
+ */
19
+ import fs from 'node:fs';
20
+ import path from 'node:path';
21
+ import { fileURLToPath } from 'node:url';
22
+ import { Command } from 'commander';
23
+ import { parse as parseJsonc, printParseErrorCode, type ParseError } from 'jsonc-parser';
24
+
25
+ /**
26
+ * Resolve a `$string:<key>` reference from `AppScope/resources/base/element/string.json`
27
+ * (the HarmonyOS base-qualifier string resource file). Returns the value, or null
28
+ * when the file is missing / unparseable / the key is absent. The caller falls back
29
+ * to the literal `$string:xxx` text on null — app_name is a display name, not
30
+ * load-bearing, so a missing resource must not fail the run.
31
+ */
32
+ function resolveStringResource(projectRoot: string, key: string): string | null {
33
+ const stringJson = path.join(
34
+ projectRoot, 'AppScope', 'resources', 'base', 'element', 'string.json',
35
+ );
36
+ if (!fs.existsSync(stringJson)) return null;
37
+ let doc: unknown;
38
+ try {
39
+ doc = parseJsonc(fs.readFileSync(stringJson, 'utf-8'));
40
+ } catch {
41
+ return null;
42
+ }
43
+ const arr = (doc as { string?: unknown })?.string;
44
+ if (!Array.isArray(arr)) return null;
45
+ const entry = arr.find((e) => (e as { name?: unknown })?.name === key);
46
+ const value = (entry as { value?: unknown } | undefined)?.value;
47
+ return typeof value === 'string' && value ? value : null;
48
+ }
49
+
50
+ export interface ResolveMetadataArgs {
51
+ projectDir: string;
52
+ output: string;
53
+ }
54
+
55
+ export function cmdResolveMetadata(args: ResolveMetadataArgs): void {
56
+ const projectRoot = path.resolve(args.projectDir);
57
+
58
+ const appJson5 = path.join(projectRoot, 'AppScope', 'app.json5');
59
+ if (!fs.existsSync(appJson5)) {
60
+ console.error(`not a HarmonyOS project root (no AppScope/app.json5): ${projectRoot}`);
61
+ process.exit(1);
62
+ }
63
+
64
+ let doc: unknown;
65
+ const errs: ParseError[] = [];
66
+ try {
67
+ doc = parseJsonc(fs.readFileSync(appJson5, 'utf-8'), errs, { allowTrailingComma: true });
68
+ } catch (e) {
69
+ console.error(`failed to parse ${appJson5}: ${e instanceof Error ? e.message : String(e)}`);
70
+ process.exit(1);
71
+ }
72
+ if (errs.length > 0) {
73
+ console.error(
74
+ `failed to parse ${appJson5}: ${errs.map((e) => printParseErrorCode(e.error)).join('; ')}`,
75
+ );
76
+ process.exit(1);
77
+ }
78
+
79
+ const app = (doc as { app?: Record<string, unknown> })?.app;
80
+ const bundleName = app?.bundleName;
81
+ if (typeof bundleName !== 'string' || !bundleName) {
82
+ console.error(`missing app.bundleName (string) in ${appJson5}`);
83
+ process.exit(1);
84
+ }
85
+
86
+ const label = app?.label;
87
+ let appName: string;
88
+ if (typeof label === 'string' && label.startsWith('$string:')) {
89
+ const key = label.slice('$string:'.length);
90
+ const resolved = resolveStringResource(projectRoot, key);
91
+ if (resolved) {
92
+ appName = resolved;
93
+ } else {
94
+ console.error(
95
+ `warning: string resource '${key}' not found in AppScope/resources/base/element/string.json — ` +
96
+ `using literal '${label}' as app_name`,
97
+ );
98
+ appName = label;
99
+ }
100
+ } else if (typeof label === 'string' && label) {
101
+ appName = label;
102
+ } else {
103
+ // ponytail: label missing/empty — bundleName is a valid non-empty string, reuse it.
104
+ // app_name is display-only; failing the whole run over it would be over-strict.
105
+ console.error(`warning: missing app.label in ${appJson5} — using bundleName as app_name`);
106
+ appName = bundleName;
107
+ }
108
+
109
+ const meta = { bundle_name: bundleName, app_name: appName, project_root: projectRoot };
110
+
111
+ try {
112
+ fs.mkdirSync(path.dirname(path.resolve(args.output)), { recursive: true });
113
+ fs.writeFileSync(path.resolve(args.output), JSON.stringify(meta) + '\n', 'utf-8');
114
+ } catch (e) {
115
+ console.error(`failed to write ${args.output}: ${e instanceof Error ? e.message : String(e)}`);
116
+ process.exit(1);
117
+ }
118
+
119
+ console.log(JSON.stringify(meta));
120
+ }
121
+
122
+ /** CLI entry — wires up the `resolve-metadata` subcommand. */
123
+ export function main(): void {
124
+ const program = new Command();
125
+ program
126
+ .description('从 HarmonyOS 工程解析 bundle_name/app_name 并写 app-metadata.json')
127
+ .requiredOption('--project-dir <dir>', 'HarmonyOS 工程根目录(含 AppScope/app.json5)')
128
+ .requiredOption('--output <path>', 'app-metadata.json 输出路径')
129
+ .action((opts: ResolveMetadataArgs) => {
130
+ cmdResolveMetadata({ projectDir: opts.projectDir, output: opts.output });
131
+ });
132
+
133
+ program.parseAsync(process.argv).catch((err) => {
134
+ console.error(err instanceof Error ? err.message : err);
135
+ process.exit(1);
136
+ });
137
+ }
138
+
139
+ const __filename = fileURLToPath(import.meta.url);
140
+ const isMainEntry = !!process.argv[1] && fs.realpathSync(process.argv[1]) === __filename;
141
+ if (isMainEntry) {
142
+ main();
143
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Minimal logger for the self-test runner. Writes `[timestamp] LEVEL msg` to an
3
+ * optional file stream and to stderr — never stdout, which carries the strict
4
+ * JSON the orchestrator parses.
5
+ */
6
+ import fs from 'node:fs';
7
+
8
+ /** Format a Date as `YYYY-MM-DD HH:MM:SS`. Shared with self-test-runner's status log. */
9
+ export function formatLogTimestamp(d: Date): string {
10
+ const pad = (n: number) => String(n).padStart(2, '0');
11
+ return (
12
+ `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ` +
13
+ `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
14
+ );
15
+ }
16
+
17
+ export interface Logger {
18
+ info(msg: string): void;
19
+ warning(msg: string): void;
20
+ error(msg: string): void;
21
+ debug(msg: string): void;
22
+ }
23
+
24
+ type Level = 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR';
25
+ const LEVEL_RANK: Record<Level, number> = { DEBUG: 0, INFO: 1, WARNING: 2, ERROR: 3 };
26
+
27
+ /** Logger writing to `stream` (if non-null) and stderr; drops messages below `minLevel`. */
28
+ export function createLogger(
29
+ stream: fs.WriteStream | null,
30
+ minLevel: 'DEBUG' | 'INFO' = 'DEBUG',
31
+ ): Logger {
32
+ const rank = LEVEL_RANK[minLevel];
33
+ const write = (level: Level, msg: string): void => {
34
+ if (LEVEL_RANK[level] < rank) return;
35
+ const line = `[${formatLogTimestamp(new Date())}] ${level} ${msg}`;
36
+ if (stream) stream.write(line + '\n');
37
+ process.stderr.write(line + '\n');
38
+ };
39
+ return {
40
+ info: (m) => write('INFO', m),
41
+ warning: (m) => write('WARNING', m),
42
+ error: (m) => write('ERROR', m),
43
+ debug: (m) => write('DEBUG', m),
44
+ };
45
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Process helpers for the self-test runner: native liveness + tree-kill.
3
+ */
4
+ import { execFileSync } from 'node:child_process';
5
+
6
+ const IS_WIN = process.platform === 'win32';
7
+
8
+ /** Whether `pid` is alive, via `kill(pid, 0)`: ESRCH = dead, EPERM = alive. */
9
+ export function pidAlive(pid: number): boolean {
10
+ try {
11
+ process.kill(pid, 0);
12
+ return true;
13
+ } catch (e) {
14
+ return (e as NodeJS.ErrnoException).code === 'EPERM';
15
+ }
16
+ }
17
+
18
+ /** Kill `pid` + descendants. Windows: `taskkill /F /T`; POSIX: SIGKILL the group then the pid. Best-effort. */
19
+ export function killProcessTree(pid: number): void {
20
+ if (IS_WIN) {
21
+ try {
22
+ execFileSync('taskkill', ['/F', '/T', '/PID', String(pid)], {
23
+ timeout: 10000,
24
+ windowsHide: true,
25
+ stdio: 'ignore',
26
+ });
27
+ } catch {
28
+ // best effort
29
+ }
30
+ return;
31
+ }
32
+ try {
33
+ process.kill(-pid, 'SIGKILL');
34
+ } catch {
35
+ try {
36
+ process.kill(pid, 'SIGKILL');
37
+ } catch {
38
+ // best effort
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Self-test input validation gates — TS ports of the `uv run python -c "..."`
3
+ * one-liners that previously lived inline in `agents/self-tester.md`.
4
+ *
5
+ * Folding them here removes a cold Python+uv start per check (5 per run) and
6
+ * gives the logic a single, typed, testable home. Each function is pure and
7
+ * returns `{ ok, message }`; the CLI layer prints `message` to stdout on
8
+ * success or stderr+exit(1) on failure, matching the prompt's `… && echo OK`
9
+ * expectation. No stdout-JSON contract applies to these gates (unlike
10
+ * run/status/kill) — they are simple human-readable pass/fail checks.
11
+ */
12
+ import fs from 'node:fs';
13
+ import path from 'node:path';
14
+ import { autotestDir } from './paths.ts';
15
+ import { loadAutotestConfig, AutotestConfigError } from './config.ts';
16
+
17
+ export interface CheckResult {
18
+ ok: boolean;
19
+ message: string;
20
+ }
21
+
22
+ /**
23
+ * `hap_path` is a comma-separated list of files/dirs — each entry a
24
+ * `.hap`/`.hsp` file or a directory. Every entry must exist and, across all
25
+ * entries, at least one `.hap` (the entry package) must be present.
26
+ * (Replaces self-tester.md T1's hap validation one-liner.)
27
+ */
28
+ export function checkHap(hapArg: string): CheckResult {
29
+ const parts = hapArg
30
+ .split(',')
31
+ .map((s) => s.trim())
32
+ .filter(Boolean);
33
+ if (parts.length === 0) return { ok: false, message: 'hap_path empty' };
34
+
35
+ for (const p of parts) {
36
+ if (!fs.existsSync(p)) return { ok: false, message: `path not found: ${p}` };
37
+ }
38
+
39
+ const haps: string[] = [];
40
+ for (const p of parts) {
41
+ const names = fs.statSync(p).isDirectory() ? fs.readdirSync(p) : [path.basename(p)];
42
+ for (const n of names) {
43
+ if (n.toLowerCase().endsWith('.hap')) haps.push(n);
44
+ }
45
+ }
46
+ if (haps.length === 0) {
47
+ return { ok: false, message: 'no entry .hap found across hap_path entries' };
48
+ }
49
+ return { ok: true, message: 'OK' };
50
+ }
51
+
52
+ /**
53
+ * `setup=false` precondition: both JSONs must parse, `testcases.json` must be a
54
+ * non-empty array, and `app-metadata.json` must carry the required keys.
55
+ * (Replaces self-tester.md T1's setup=false JSON check one-liner.)
56
+ */
57
+ export function checkInputs(testcasesPath: string, metadataPath: string): CheckResult {
58
+ let t: unknown;
59
+ try {
60
+ t = JSON.parse(fs.readFileSync(testcasesPath, 'utf-8'));
61
+ } catch (e) {
62
+ return { ok: false, message: `testcases.json failed to parse: ${(e as Error).message}` };
63
+ }
64
+ if (!Array.isArray(t) || t.length === 0) {
65
+ return { ok: false, message: 'testcases.json empty or not a list' };
66
+ }
67
+
68
+ let m: unknown;
69
+ try {
70
+ m = JSON.parse(fs.readFileSync(metadataPath, 'utf-8'));
71
+ } catch (e) {
72
+ return { ok: false, message: `app-metadata.json failed to parse: ${(e as Error).message}` };
73
+ }
74
+ // A JSON primitive/array has no keys → treat as missing fields (avoids the
75
+ // `in` operator throwing a TypeError on a non-object).
76
+ if (typeof m !== 'object' || m === null || Array.isArray(m)) {
77
+ return { ok: false, message: 'app-metadata.json missing required fields' };
78
+ }
79
+ const mo = m as Record<string, unknown>;
80
+ for (const k of ['bundle_name', 'app_name', 'project_root']) {
81
+ if (!(k in mo)) return { ok: false, message: 'app-metadata.json missing required fields' };
82
+ }
83
+ return { ok: true, message: 'OK' };
84
+ }
85
+
86
+ /**
87
+ * `[PRE]` cases must occupy a contiguous block starting at index 0 in
88
+ * `testcases.json`. Run only when pre-cases were extracted.
89
+ * (Replaces self-tester.md S5's `[PRE]` ordering one-liner.)
90
+ */
91
+ export function checkPre(testcasesPath: string): CheckResult {
92
+ let d: unknown;
93
+ try {
94
+ d = JSON.parse(fs.readFileSync(testcasesPath, 'utf-8'));
95
+ } catch (e) {
96
+ return { ok: false, message: `testcases.json failed to parse: ${(e as Error).message}` };
97
+ }
98
+ if (!Array.isArray(d)) return { ok: false, message: 'testcases.json not a list' };
99
+
100
+ const pre: number[] = [];
101
+ for (let i = 0; i < d.length; i++) {
102
+ const name = (d[i] as { case_name?: unknown })?.case_name;
103
+ // Parity with the original: a case lacking a string `case_name` is a
104
+ // malformed testcases.json and must fail hard (Python raised KeyError).
105
+ if (typeof name !== 'string') {
106
+ return { ok: false, message: `testcases.json entry at index ${i} missing string case_name` };
107
+ }
108
+ if (name.startsWith('[PRE] ')) pre.push(i);
109
+ }
110
+ const contiguous = pre.every((v, idx) => v === idx);
111
+ if (!contiguous) {
112
+ return {
113
+ ok: false,
114
+ message: `[PRE] entries must be contiguous from index 0, got ${JSON.stringify(pre)}`,
115
+ };
116
+ }
117
+ return { ok: true, message: `OK: ${pre.length} [PRE] entries at front` };
118
+ }
119
+
120
+ /**
121
+ * The multimodal model api_key must be resolvable along the standard chain
122
+ * (env `HOMETRANS_MODEL_API_KEY` → `~/.hometrans/config.json` autotest block).
123
+ * Delegates entirely to `loadAutotestConfig`, which applies the same env overlay
124
+ * + placeholder validation the runner uses at run time.
125
+ * (Replaces self-tester.md T4's api_key config one-liner.)
126
+ */
127
+ export function checkConfig(): CheckResult {
128
+ try {
129
+ loadAutotestConfig();
130
+ return { ok: true, message: 'OK' };
131
+ } catch (e) {
132
+ const msg = e instanceof AutotestConfigError ? e.message : (e as Error).message;
133
+ return { ok: false, message: msg };
134
+ }
135
+ }
136
+
137
+ /**
138
+ * Resolve the `test-tools/autotest` directory via the canonical `autotestDir()`
139
+ * chain (env `HOMETRANS_TOOL_PATH` → config.json → tools dir → source-tree
140
+ * walk-up). If that path does not exist, optionally walk up from `fromDir`
141
+ * (the sub-agent's `<output_path>`) for a sibling `test-tools/autotest` (or the
142
+ * legacy `agents/test-tools/autotest`). Prints the resolved dir on success.
143
+ * (Replaces self-tester.md's AutoTest Directory Locator bash tiers.)
144
+ */
145
+ export function resolveDir(fromDir?: string): CheckResult {
146
+ const dir = autotestDir();
147
+ if (fs.existsSync(dir)) return { ok: true, message: dir };
148
+
149
+ if (fromDir) {
150
+ let d = path.resolve(fromDir);
151
+ for (let i = 0; i < 20 && d; i++) {
152
+ for (const probe of [
153
+ path.join(d, 'test-tools', 'autotest'),
154
+ path.join(d, 'agents', 'test-tools', 'autotest'),
155
+ ]) {
156
+ if (fs.existsSync(probe)) return { ok: true, message: probe };
157
+ }
158
+ const parent = path.dirname(d);
159
+ if (parent === d) break;
160
+ d = parent;
161
+ }
162
+ }
163
+ return {
164
+ ok: false,
165
+ message: `AutoTest directory not found from HOMETRANS_TOOL_PATH env var or output_path (resolved ${dir})`,
166
+ };
167
+ }