@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,961 @@
1
+ /**
2
+ * Self-Test Runner — launches HarmonyOS on-device self-tests via the Node.js
3
+ * `@autotest/agent` engine (batch_runner), then reports status from output files.
4
+ *
5
+ * run — prepare env (npm install + hdc install), spawn batch detached, return PID.
6
+ * status — report state from output files (summary.json / task_results.jsonl) + native liveness.
7
+ * kill — terminate the background batch.
8
+ *
9
+ * STDOUT carries strict JSON parsed by the caller; all logging goes to stderr /
10
+ * the log file. JSON shapes + exit codes are a frozen contract (see agents/self-tester.md).
11
+ */
12
+ import crypto from 'node:crypto';
13
+ import { execFileSync, spawn, spawnSync } from 'node:child_process';
14
+ import fs from 'node:fs';
15
+ import path from 'node:path';
16
+ import { fileURLToPath } from 'node:url';
17
+ import { Command } from 'commander';
18
+ import { loadAutotestConfig, type AutotestConfigBlock } from '../config.ts';
19
+ import { createLogger, type Logger } from '../runner/logger.ts';
20
+ import { killProcessTree, pidAlive } from '../runner/process-utils.ts';
21
+ import {
22
+ type CheckResult,
23
+ checkHap,
24
+ checkInputs,
25
+ checkPre,
26
+ checkConfig,
27
+ resolveDir,
28
+ } from '../validate.ts';
29
+
30
+ const HAP_INSTALL_WAIT = 3; // post-install settle, in seconds (reduced from the original 10s).
31
+ const INSTALL_TIMEOUT = 120;
32
+ const DEFAULT_CATEGORY = 'self_test';
33
+
34
+ let logger: Logger = createLogger(null, 'INFO');
35
+
36
+ function timestampForFile(d: Date): string {
37
+ const pad = (n: number) => String(n).padStart(2, '0');
38
+ return (
39
+ `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}_` +
40
+ `${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())}`
41
+ );
42
+ }
43
+
44
+ /** Synchronous sleep (PowerShell on Windows, `sleep` on POSIX). Best-effort. */
45
+ function sleep(sec: number): void {
46
+ if (sec <= 0) return;
47
+ const ms = sec * 1000;
48
+ try {
49
+ if (process.platform === 'win32') {
50
+ spawnSync('powershell.exe', ['-NoProfile', '-Command', `Start-Sleep -Seconds ${sec}`], {
51
+ stdio: 'ignore',
52
+ timeout: ms + 5000,
53
+ windowsHide: true,
54
+ });
55
+ } else {
56
+ spawnSync('sleep', [String(sec)], { stdio: 'ignore', timeout: ms + 5000 });
57
+ }
58
+ } catch {
59
+ // best effort
60
+ }
61
+ }
62
+
63
+ function setupLogging(outputDir: string): void {
64
+ const logPath = path.join(outputDir, `self_test_${timestampForFile(new Date())}.log`);
65
+ fs.mkdirSync(path.dirname(logPath), { recursive: true });
66
+ logger = createLogger(fs.createWriteStream(logPath, { encoding: 'utf-8' }), 'DEBUG');
67
+ logger.info(`日志文件: ${logPath}`);
68
+ }
69
+
70
+ // ---- external tool discovery ----------------------------------------------
71
+
72
+ /** Find `name` on PATH via `where` (Windows) or `which` (POSIX). Null on failure. */
73
+ function findOnPath(name: string): string | null {
74
+ const finder = process.platform === 'win32' ? 'where' : 'which';
75
+ try {
76
+ const out = execFileSync(finder, [name], {
77
+ encoding: 'utf-8',
78
+ windowsHide: true,
79
+ timeout: 5000,
80
+ });
81
+ const first = out.split(/\r?\n/).find((l) => l.trim());
82
+ return first ? first.trim() : null;
83
+ } catch {
84
+ return null;
85
+ }
86
+ }
87
+
88
+ function getHdc(): string {
89
+ const found = findOnPath('hdc');
90
+ if (!found) {
91
+ logger.error('hdc 未找到');
92
+ process.exit(1);
93
+ }
94
+ return found;
95
+ }
96
+
97
+ /**
98
+ * Absolute path to the compiled `batch-launcher.js` — the detached background
99
+ * process that drives `new AutoTestAgent({...})` programmatically. Sits next to
100
+ * this module under `tools/test-tools/autotest/engine/`.
101
+ */
102
+ function batchLauncherPath(): string {
103
+ const here = path.dirname(fileURLToPath(import.meta.url));
104
+ const p = path.join(here, 'batch-launcher.ts');
105
+ if (!fs.existsSync(p)) {
106
+ logger.error(
107
+ `未找到 batch-launcher: ${p}\n` +
108
+ '请先在 HomeTrans 根目录执行 `npm run build` 重新构建 dist/。',
109
+ );
110
+ process.exit(1);
111
+ }
112
+ return p;
113
+ }
114
+
115
+ /**
116
+ * Bridge HomeTrans's autotest config block (resolved from
117
+ * `~/.hometrans/config.json` + HOMETRANS_MODEL_* env overlay) into the
118
+ * `AUTOTEST_*` env vars the batch launcher reads — these become the
119
+ * `new AutoTestAgent({ apiKey, modelName, … })` constructor args, so the user
120
+ * sets API_KEY / model / device once (via `ht init` or env) and they flow
121
+ * straight into the agent constructor with no config.yaml file.
122
+ */
123
+ function agentEnvFromConfig(block: AutotestConfigBlock, base: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
124
+ const env: NodeJS.ProcessEnv = { ...base };
125
+ const um = block.unified_model;
126
+ if (um) {
127
+ if (um.api_key) env.AUTOTEST_API_KEY = um.api_key;
128
+ if (um.name) env.AUTOTEST_MODEL = um.name;
129
+ if (um.base_url) env.AUTOTEST_BASE_URL = um.base_url;
130
+ if (um.provider) env.AUTOTEST_PROVIDER = um.provider;
131
+ }
132
+ const dev = block.device as Record<string, unknown> | undefined;
133
+ if (dev) {
134
+ if (dev.device_sn != null) env.AUTOTEST_DEVICE_SN = String(dev.device_sn);
135
+ if (dev.ip != null) env.AUTOTEST_IP = String(dev.ip);
136
+ if (dev.port != null) env.AUTOTEST_PORT = String(dev.port);
137
+ }
138
+ if (block.agent_mode) env.AUTOTEST_MODE = block.agent_mode;
139
+ return env;
140
+ }
141
+
142
+ // ---- sync subprocess runner ------------------------------------------------
143
+
144
+ interface RunCmdResult {
145
+ returncode: number;
146
+ stdout: string;
147
+ stderr: string;
148
+ }
149
+
150
+ /**
151
+ * Synchronous subprocess runner with logging. On non-zero exit logs
152
+ * stdout/stderr; if `check` (default true), exits with the failing code.
153
+ */
154
+ function runCmd(
155
+ cmd: string[],
156
+ opts: { cwd?: string; check?: boolean; timeout?: number; env?: NodeJS.ProcessEnv } = {},
157
+ ): RunCmdResult {
158
+ const { cwd, check = true, timeout, env } = opts;
159
+ const cmdStr = cmd.join(' ');
160
+ logger.info(`>>> ${cmdStr}`);
161
+ const result = spawnSync(cmd[0], cmd.slice(1), {
162
+ cwd,
163
+ env,
164
+ encoding: 'utf-8',
165
+ timeout: timeout ? timeout * 1000 : undefined,
166
+ maxBuffer: 1024 * 1024 * 1024,
167
+ windowsHide: true,
168
+ stdio: ['ignore', 'pipe', 'pipe'],
169
+ });
170
+ if (result.error) {
171
+ logger.error(`命令异常: ${result.error.message}`);
172
+ throw result.error;
173
+ }
174
+ const status = result.status ?? 0;
175
+ const stdout = result.stdout ?? '';
176
+ const stderr = result.stderr ?? '';
177
+ if (status !== 0) {
178
+ logger.warning(`退出码=${status}: ${cmdStr}`);
179
+ if (stdout) logger.warning(` stdout: ${stdout.trim()}`);
180
+ if (stderr) logger.warning(` stderr: ${stderr.trim()}`);
181
+ if (check) process.exit(status);
182
+ } else {
183
+ logger.debug(`成功 (rc=0): ${cmdStr}`);
184
+ }
185
+ return { returncode: status, stdout, stderr };
186
+ }
187
+
188
+ // ---- testcases JSONL normalizer -------------------------------------------
189
+
190
+ /**
191
+ * Normalize `--testcases` into a JSONL path. A JSON array (legacy
192
+ * `testcases.json`) is converted to JSONL at `<taskSubdir>/testcases.jsonl`,
193
+ * filling missing `uuid` (md5 of case_name or `case_<idx>`, first 8 hex) and
194
+ * `spec` (""). Already-JSONL input is validated line-by-line and passed through.
195
+ */
196
+ export function prepareTestcasesJsonl(inputPath: string, taskSubdir: string): string {
197
+ if (!fs.existsSync(inputPath)) {
198
+ logger.error(`测试用例文件不存在: ${inputPath}`);
199
+ process.exit(1);
200
+ }
201
+ let text = fs.readFileSync(inputPath, 'utf-8');
202
+ if (text.charCodeAt(0) === 0xfeff) text = text.slice(1); // strip BOM
203
+ const stripped = text.trimStart();
204
+ if (!stripped) {
205
+ logger.error(`测试用例文件为空: ${inputPath}`);
206
+ process.exit(1);
207
+ }
208
+
209
+ if (stripped[0] === '[') {
210
+ let arr: unknown;
211
+ try {
212
+ arr = JSON.parse(text);
213
+ } catch (e) {
214
+ logger.error(`测试用例 JSON 数组解析失败 ${inputPath}: ${e instanceof Error ? e.message : e}`);
215
+ process.exit(1);
216
+ }
217
+ if (!Array.isArray(arr)) {
218
+ logger.error(`测试用例文件根不是数组: ${inputPath}`);
219
+ process.exit(1);
220
+ }
221
+ const outPath = path.join(taskSubdir, 'testcases.jsonl');
222
+ const lines = arr.map((entry, idx) => {
223
+ const i = idx + 1;
224
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
225
+ logger.error(`用例 #${i} 不是 JSON 对象: ${JSON.stringify(entry)}`);
226
+ process.exit(1);
227
+ }
228
+ const c = entry as Record<string, unknown>;
229
+ if (!c.uuid) {
230
+ const seed = typeof c.case_name === 'string' && c.case_name ? c.case_name : `case_${i}`;
231
+ c.uuid = crypto.createHash('md5').update(seed, 'utf-8').digest('hex').slice(0, 8);
232
+ }
233
+ if (!('spec' in c)) c.spec = '';
234
+ return JSON.stringify(c);
235
+ });
236
+ fs.writeFileSync(outPath, lines.join('\n') + '\n', 'utf-8');
237
+ logger.info(`已将 JSON 数组转换为 JSONL: ${outPath}(${arr.length} 条用例)`);
238
+ return outPath;
239
+ }
240
+
241
+ const lines = text.split(/\r?\n/).filter((l) => l.trim());
242
+ lines.forEach((line, i) => {
243
+ try {
244
+ JSON.parse(line);
245
+ } catch (e) {
246
+ logger.error(`JSONL 第 ${i + 1} 行解析失败 ${inputPath}: ${e instanceof Error ? e.message : e}`);
247
+ process.exit(1);
248
+ }
249
+ });
250
+ logger.info(`测试用例文件已为 JSONL,原样透传: ${inputPath}(${lines.length} 条用例)`);
251
+ return inputPath;
252
+ }
253
+
254
+ // ---- HAP install -----------------------------------------------------------
255
+
256
+ /**
257
+ * Install every `.hap`/`.hsp` from a comma-separated `--hap` arg (each entry a
258
+ * file or a directory) in one `hdc install -r` transaction. Real apps ship an
259
+ * entry HAP plus HSPs, so at least one `.hap` is required. Success is judged by
260
+ * hdc's stdout heuristic — hdc can return 0 on failure.
261
+ */
262
+ function installHaps(hapArg: string, hdc: string): void {
263
+ const entries = hapArg
264
+ .split(',')
265
+ .map((s) => s.trim())
266
+ .filter((s) => s);
267
+ if (entries.length === 0) {
268
+ logger.error('hap-path 为空');
269
+ process.exit(1);
270
+ }
271
+ const pkgs: string[] = [];
272
+ for (const e of entries) {
273
+ if (!fs.existsSync(e)) {
274
+ logger.error(`hap 路径不存在: ${e}`);
275
+ process.exit(1);
276
+ }
277
+ const stat = fs.statSync(e);
278
+ const lower = e.toLowerCase();
279
+ if (stat.isDirectory()) {
280
+ const found = fs
281
+ .readdirSync(e)
282
+ .filter((f) => f.toLowerCase().endsWith('.hap') || f.toLowerCase().endsWith('.hsp'))
283
+ .sort()
284
+ .map((f) => path.join(e, f));
285
+ if (found.length === 0) {
286
+ logger.error(`目录内无 .hap/.hsp 包: ${e}`);
287
+ process.exit(1);
288
+ }
289
+ pkgs.push(...found);
290
+ } else if (stat.isFile() && (lower.endsWith('.hap') || lower.endsWith('.hsp'))) {
291
+ pkgs.push(e);
292
+ } else {
293
+ logger.error(`既不是目录也不是 .hap/.hsp 文件: ${e}`);
294
+ process.exit(1);
295
+ }
296
+ }
297
+ // Resolve to native absolute paths (backslashes on Windows) AND dedup in one
298
+ // pass. Resolving is required, not cosmetic: hdc on Windows mis-parses a
299
+ // forward-slash *drive-absolute* path (e.g. `C:/a/b.hap`) as relative and
300
+ // prepends its own cwd (`C:\cwd\C:/a/b.hap` → invalid), silently skipping the
301
+ // install after Step 2a already uninstalled the app. `path.resolve` yields the
302
+ // native `C:\a\b.hap` form hdc accepts. On POSIX it's a harmless no-op for
303
+ // already-absolute inputs. Callers assemble --hap from multiple sources
304
+ // (package-set dir, comma-list, the rebuild step's hsp/ copy) that can overlap, so
305
+ // dedup on the same resolved key.
306
+ const seen = new Set<string>();
307
+ const deduped: string[] = [];
308
+ for (const p of pkgs) {
309
+ const resolved = path.resolve(p);
310
+ if (seen.has(resolved)) continue;
311
+ seen.add(resolved);
312
+ deduped.push(resolved);
313
+ }
314
+ if (!deduped.some((p) => p.toLowerCase().endsWith('.hap'))) {
315
+ logger.error(`缺少 entry HAP(至少需要一个 .hap): ${hapArg}`);
316
+ process.exit(1);
317
+ }
318
+
319
+ // hdc install -r accepts multiple package paths in one transaction.
320
+ logger.info(`安装 ${deduped.length} 个包: ${deduped.map((p) => path.basename(p)).join(', ')}`);
321
+ const result = runCmd([hdc, 'install', '-r', ...deduped], {
322
+ timeout: INSTALL_TIMEOUT,
323
+ check: false,
324
+ });
325
+ const combined = `${(result.stdout || '').trim()}\n${(result.stderr || '').trim()}`;
326
+ const combinedLower = combined.toLowerCase();
327
+ // msg:error is case-sensitive; the rest match on lowercased output.
328
+ const hasError =
329
+ combined.includes('msg:error') ||
330
+ combinedLower.includes('failed to install') ||
331
+ (combined.includes('code:') && combinedLower.includes('error:'));
332
+ const hasSuccess = combinedLower.includes('successfully');
333
+ if (result.returncode === 0 && !hasError && hasSuccess) {
334
+ logger.info('安装成功');
335
+ sleep(HAP_INSTALL_WAIT);
336
+ } else if (result.returncode === 0 && !hasError) {
337
+ logger.warning(`安装结果不确定(rc=0 但无 success 消息): ${combined}`);
338
+ sleep(HAP_INSTALL_WAIT);
339
+ } else {
340
+ logger.error(`安装失败: rc=${result.returncode}, output=${combined}`);
341
+ process.exit(1);
342
+ }
343
+ }
344
+
345
+ // ---- run subcommand --------------------------------------------------------
346
+
347
+ export interface RunArgs {
348
+ testcases: string;
349
+ hap: string;
350
+ bundleName: string;
351
+ taskDir: string;
352
+ outputDir?: string;
353
+ category: string;
354
+ config?: string;
355
+ timeout?: number | 'auto';
356
+ }
357
+
358
+ // Per-case outer poll budget when `--timeout auto` is used: mirrors the
359
+ // batch-launcher hard cap CASE_TIMEOUT_MS=10min + 20% margin = 720s/case. The
360
+ // CLI already parses `--testcases`, so it derives the total itself instead of
361
+ // making the caller compute `caseCount * 720` in a (shell-specific) wrapper.
362
+ const PER_CASE_TIMEOUT_SEC = 720;
363
+
364
+ export interface SpawnBatchOpts {
365
+ cmd: string[];
366
+ cwd: string;
367
+ env: NodeJS.ProcessEnv;
368
+ stdoutLog: string;
369
+ pidFile: string;
370
+ taskDir: string;
371
+ taskSubdir: string;
372
+ }
373
+
374
+ /**
375
+ * Spawn the batch-launcher detached and write pidFile. Resolves with the PID
376
+ * on the spawn event, rejects with an Error on the spawn-error event (ENOENT,
377
+ * EACCES, …). Caller is responsible for emitting JSON (RUNNING or FAILED) —
378
+ * this function is silent on stdout so the same code path can serve both the
379
+ * backward-compat "emit RUNNING immediately" mode and the `--timeout`
380
+ * "suppress RUNNING, poll until terminal" mode. `spawnFn` is injectable for tests.
381
+ */
382
+ export function spawnBatch(opts: SpawnBatchOpts, spawnFn: typeof spawn = spawn): Promise<number> {
383
+ return new Promise((resolve, reject) => {
384
+ const { cmd, cwd, env, stdoutLog, pidFile, taskDir, taskSubdir } = opts;
385
+ const logFd = fs.openSync(stdoutLog, 'w');
386
+ let settled = false;
387
+ const fail = (error: string): void => {
388
+ if (settled) return;
389
+ settled = true;
390
+ try { fs.closeSync(logFd); } catch { /* ignore */ }
391
+ try { fs.rmSync(pidFile, { force: true }); } catch { /* ignore */ }
392
+ logger.error(`后台 batch 进程启动失败: ${error}`);
393
+ reject(new Error(error));
394
+ };
395
+ const proc = spawnFn(cmd[0], cmd.slice(1), {
396
+ cwd,
397
+ stdio: ['ignore', logFd, logFd],
398
+ env,
399
+ detached: true,
400
+ windowsHide: true,
401
+ });
402
+ // spawn() reports failure asynchronously via the 'error' event and success
403
+ // via the 'spawn' event. proc.pid is set synchronously even for some
404
+ // failures, so emitting RUNNING off the pid could hand the caller a
405
+ // live-looking but dead PID. Gate both outcomes on the events (with a
406
+ // `settled` latch) so exactly one of resolve/reject fires.
407
+ proc.on('error', (e: Error) => fail(e.message));
408
+ proc.on('spawn', () => {
409
+ if (settled) return;
410
+ settled = true;
411
+ fs.writeFileSync(pidFile, String(proc.pid), 'utf-8');
412
+ proc.unref();
413
+ logger.info(`后台进程 PID=${proc.pid}`);
414
+ resolve(proc.pid);
415
+ });
416
+ });
417
+ }
418
+
419
+ /**
420
+ * Poll `probeStatus` every 60 seconds until a terminal status is reached
421
+ * (COMPLETED / CRASHED / NOT_STARTED) or `timeoutSec` elapses. On timeout,
422
+ * auto-kill the batch tree via `killProcessTree` and return a `TIMEOUT`
423
+ * result with exit code 5 (new). The first probe happens immediately (no
424
+ * leading sleep) so a fast-finished batch is detected without a 60s delay.
425
+ *
426
+ * Returns `{ json, exitCode }` — caller emits `JSON.stringify(json)` to stdout
427
+ * and `process.exit(exitCode)`.
428
+ *
429
+ * Exit codes: COMPLETED=0, CRASHED=3, NOT_STARTED=4, TIMEOUT=5.
430
+ */
431
+ export function pollUntilTerminal(
432
+ taskDir: string,
433
+ outputDir: string,
434
+ timeoutSec: number,
435
+ ): { json: Record<string, unknown>; exitCode: number } {
436
+ const start = Date.now();
437
+
438
+ while (true) {
439
+ const r = probeStatus(taskDir, outputDir);
440
+
441
+ if (r.status === 'COMPLETED') {
442
+ return {
443
+ json: {
444
+ status: 'COMPLETED',
445
+ pid: r.pid,
446
+ task_subdir: r.taskSubdir,
447
+ cases_done: r.casesDone,
448
+ pass_count: r.passCount ?? 0,
449
+ fail_count: r.failCount ?? 0,
450
+ unknown_count: r.unknownCount ?? 0,
451
+ pass_rate: r.passRate ?? 0,
452
+ log_tail: r.logTail,
453
+ },
454
+ exitCode: 0,
455
+ };
456
+ }
457
+
458
+ if (r.status === 'CRASHED') {
459
+ return {
460
+ json: {
461
+ status: 'CRASHED',
462
+ pid: r.pid,
463
+ task_subdir: r.taskSubdir,
464
+ cases_done: r.casesDone,
465
+ last_case: r.lastCase,
466
+ log_tail: r.logTail,
467
+ },
468
+ exitCode: 3,
469
+ };
470
+ }
471
+
472
+ if (r.status === 'NOT_STARTED') {
473
+ return {
474
+ json: { status: 'NOT_STARTED' },
475
+ exitCode: 4,
476
+ };
477
+ }
478
+
479
+ // r.status === 'RUNNING' — check timeout before sleeping
480
+ const elapsed = (Date.now() - start) / 1000;
481
+ if (elapsed >= timeoutSec) {
482
+ // Auto-kill the batch tree, then return TIMEOUT.
483
+ if (r.pid != null) {
484
+ try {
485
+ killProcessTree(r.pid);
486
+ sleep(2);
487
+ } catch {
488
+ // best effort
489
+ }
490
+ }
491
+ return {
492
+ json: {
493
+ status: 'TIMEOUT',
494
+ pid: r.pid,
495
+ task_subdir: r.taskSubdir,
496
+ cases_done: r.casesDone,
497
+ last_case: r.lastCase,
498
+ log_tail: r.logTail,
499
+ },
500
+ exitCode: 5,
501
+ };
502
+ }
503
+
504
+ // Still RUNNING and within budget — sleep 60s then probe again.
505
+ sleep(60);
506
+ }
507
+ }
508
+
509
+ /** `run` subcommand: prepare environment, then spawn the batch-launcher detached. */
510
+ export async function cmdRun(args: RunArgs): Promise<void> {
511
+ let taskDir: string;
512
+ let outputDir: string;
513
+ let taskSubdir: string;
514
+ let pidFile: string;
515
+ let stdoutLog: string;
516
+ let batchEnv: NodeJS.ProcessEnv;
517
+ let cmd: string[];
518
+ let effectiveTimeout: number | undefined;
519
+ try {
520
+ taskDir = path.resolve(args.taskDir);
521
+ fs.mkdirSync(taskDir, { recursive: true });
522
+ outputDir = args.outputDir ? path.resolve(args.outputDir) : taskDir;
523
+ fs.mkdirSync(outputDir, { recursive: true });
524
+
525
+ setupLogging(outputDir);
526
+ logger.info(`Node: ${process.execPath}`);
527
+ logger.info(
528
+ `参数: testcases=${args.testcases}, hap=${args.hap}, bundle=${args.bundleName}, ` +
529
+ `task_dir=${taskDir}, category=${args.category}, config=${args.config ?? ''}` +
530
+ (args.timeout === 'auto' ? `, timeout=auto` : args.timeout ? `, timeout=${args.timeout}s` : ''),
531
+ );
532
+
533
+ // Per-run task subdir; status subcommand globs `task_*` to find the latest.
534
+ taskSubdir = path.join(taskDir, `task_${timestampForFile(new Date())}`);
535
+ fs.mkdirSync(taskSubdir, { recursive: true });
536
+
537
+ pidFile = path.join(taskDir, 'batch.pid');
538
+ stdoutLog = path.join(taskDir, 'batch_stdout.log');
539
+
540
+ // Kill any previous run's batch still recorded alive in the pid file.
541
+ if (fs.existsSync(pidFile)) {
542
+ try {
543
+ const oldPid = parseInt(fs.readFileSync(pidFile, 'utf-8').trim(), 10);
544
+ if (Number.isFinite(oldPid) && pidAlive(oldPid)) {
545
+ logger.warning(`杀掉上次残留进程 PID=${oldPid}`);
546
+ killProcessTree(oldPid);
547
+ sleep(2);
548
+ }
549
+ } catch {
550
+ // best effort
551
+ }
552
+ }
553
+
554
+ // Resolve the autotest config block once (env-overlay applied) — its
555
+ // api_key / model / device fields are forwarded to the batch launcher as
556
+ // AUTOTEST_* env vars, which become `new AutoTestAgent({...})` constructor
557
+ // args. No config.yaml is materialized.
558
+ const configBlock = loadAutotestConfig(args.config);
559
+ logger.info('已加载 autotest 配置(api_key/model/device 将通过 new AutoTestAgent 构造器传入)');
560
+
561
+ const hdc = getHdc();
562
+
563
+ logger.info(`=== Step 2a: uninstall ${args.bundleName} ===`);
564
+ runCmd([hdc, 'uninstall', args.bundleName], { timeout: INSTALL_TIMEOUT, check: false });
565
+
566
+ logger.info(`=== Step 2b: install ${args.hap} ===`);
567
+ installHaps(args.hap, hdc);
568
+
569
+ const testcasesJsonl = prepareTestcasesJsonl(path.resolve(args.testcases), taskSubdir);
570
+
571
+ // Resolve `--timeout auto` now that the testcases are parsed: total budget =
572
+ // caseCount × 720s (min 1 case). A numeric --timeout passes through; omitted
573
+ // stays undefined → backward-compat immediate-RUNNING mode below.
574
+ if (args.timeout === 'auto') {
575
+ const caseCount = fs.readFileSync(testcasesJsonl, 'utf-8').split(/\r?\n/).filter((l) => l.trim()).length;
576
+ effectiveTimeout = Math.max(caseCount, 1) * PER_CASE_TIMEOUT_SEC;
577
+ logger.info(`--timeout auto: ${caseCount} 条用例 × ${PER_CASE_TIMEOUT_SEC}s = ${effectiveTimeout}s`);
578
+ } else {
579
+ effectiveTimeout = args.timeout;
580
+ }
581
+
582
+ // Node engine: `node <batch-launcher.js>` constructs `new AutoTestAgent(...)`
583
+ // from AUTOTEST_* env and runs the testcases batch in-process. cwd=taskSubdir
584
+ // keeps the per-case report dirs and task_results.jsonl inside the subdir.
585
+ cmd = [
586
+ process.execPath, batchLauncherPath(),
587
+ '--task-dir', taskSubdir,
588
+ '--testcases', testcasesJsonl,
589
+ '--category', args.category,
590
+ ];
591
+ batchEnv = agentEnvFromConfig(configBlock, process.env);
592
+ } catch (e) {
593
+ const error = e instanceof Error ? e.message : String(e);
594
+ logger.error(`异常:\n${e instanceof Error ? e.stack ?? error : String(e)}`);
595
+ console.log(JSON.stringify({ status: 'FAILED', error }));
596
+ process.exit(1);
597
+ }
598
+
599
+ logger.info('=== Step 3: 后台启动 AutoTest (Node @autotest/agent, new AutoTestAgent) ===');
600
+
601
+ // No --timeout: backward-compat mode — emit RUNNING JSON immediately on successful spawn.
602
+ try {
603
+ // ponytail: the non-null assertions are safe because the prep try/catch above
604
+ // either assigned all these locals or process.exit(1) — no path reaches here
605
+ // with an unassigned variable. If the catch ever stops exiting, drop the `!`.
606
+ const pid = await spawnBatch({ cmd: cmd!, cwd: taskSubdir!, env: batchEnv!, stdoutLog, pidFile, taskDir: taskDir!, taskSubdir: taskSubdir! });
607
+ if (effectiveTimeout) {
608
+ const r = pollUntilTerminal(taskDir!, outputDir!, effectiveTimeout);
609
+ console.log(JSON.stringify(r.json));
610
+ process.exit(r.exitCode);
611
+ } else {
612
+ console.log(
613
+ JSON.stringify({
614
+ status: 'RUNNING',
615
+ pid,
616
+ pid_file: pidFile,
617
+ stdout_log: stdoutLog,
618
+ task_dir: taskDir,
619
+ task_subdir: taskSubdir,
620
+ }),
621
+ );
622
+ }
623
+ } catch (e) {
624
+ const error = e instanceof Error ? e.message : String(e);
625
+ console.log(JSON.stringify({ status: 'FAILED', error }));
626
+ process.exit(1);
627
+ }
628
+ }
629
+
630
+ export interface ProbeResult {
631
+ status: 'NOT_STARTED' | 'COMPLETED' | 'RUNNING' | 'CRASHED';
632
+ pid: number | null;
633
+ taskSubdir: string | null;
634
+ casesDone: number;
635
+ lastCase: string;
636
+ logTail: string;
637
+ // COMPLETED-only (undefined for other statuses):
638
+ passCount?: number;
639
+ failCount?: number;
640
+ unknownCount?: number;
641
+ passRate?: string | number;
642
+ }
643
+
644
+ /**
645
+ * Read batch state from on-disk artifacts (no JSON emission, no exit).
646
+ * Same logic as `cmdStatus` but returns a structured `ProbeResult` so callers
647
+ * (`cmdStatus` for one-shot, `pollUntilTerminal` for the `run --timeout` loop)
648
+ * can share one source of truth.
649
+ */
650
+ export function probeStatus(taskDir: string, outputDir: string): ProbeResult {
651
+ const pidFile = path.join(taskDir, 'batch.pid');
652
+ if (!fs.existsSync(pidFile)) {
653
+ return {
654
+ status: 'NOT_STARTED',
655
+ pid: null,
656
+ taskSubdir: null,
657
+ casesDone: 0,
658
+ lastCase: '',
659
+ logTail: '',
660
+ };
661
+ }
662
+
663
+ const pid = parseInt(fs.readFileSync(pidFile, 'utf-8').trim(), 10);
664
+ const taskSubdir = findTaskSubdir(taskDir);
665
+
666
+ let casesDone = 0;
667
+ let lastCase = '';
668
+ const jsonlFile = taskSubdir ? path.join(taskSubdir, 'task_results.jsonl') : null;
669
+ if (jsonlFile && fs.existsSync(jsonlFile)) {
670
+ const text = fs.readFileSync(jsonlFile, 'utf-8').trim();
671
+ const lines = text ? text.split(/\r?\n/) : [];
672
+ casesDone = lines.length;
673
+ if (lines.length) {
674
+ try {
675
+ const last = JSON.parse(lines[lines.length - 1]) as { case_name?: string };
676
+ if (typeof last.case_name === 'string') lastCase = last.case_name;
677
+ } catch {
678
+ // ignore
679
+ }
680
+ }
681
+ }
682
+
683
+ let logTail = '';
684
+ const logFile = findLatestLog(outputDir);
685
+ if (logFile && fs.existsSync(logFile)) {
686
+ const text = fs.readFileSync(logFile, 'utf-8').trim();
687
+ logTail = (text ? text.split(/\r?\n/) : []).slice(-5).join('\n');
688
+ }
689
+
690
+ const summaryFile = taskSubdir ? path.join(taskSubdir, 'summary.json') : null;
691
+ if (summaryFile && fs.existsSync(summaryFile)) {
692
+ let summary: Record<string, unknown> = {};
693
+ try {
694
+ summary = JSON.parse(fs.readFileSync(summaryFile, 'utf-8'));
695
+ } catch {
696
+ // ignore
697
+ }
698
+ const num = (v: unknown, fallback: number) => (typeof v === 'number' ? v : fallback);
699
+ // ponytail: cast `pass_rate` (unknown from JSON) to the documented schema
700
+ // (string like "30.00%" or absent). `num(...)` would zero a string rate, so
701
+ // we keep the `?? 0` fallback verbatim from the original cmdStatus.
702
+ return {
703
+ status: 'COMPLETED',
704
+ pid,
705
+ taskSubdir,
706
+ casesDone: num(summary.total_cases, casesDone),
707
+ lastCase,
708
+ passCount: num(summary.pass_count, num(summary.success_count, 0)),
709
+ failCount: num(summary.fail_count, 0),
710
+ unknownCount: num(summary.unknown_count, 0),
711
+ passRate: (summary.pass_rate as string | number | undefined) ?? 0,
712
+ logTail,
713
+ };
714
+ }
715
+
716
+ const alive = pidAlive(pid);
717
+ return {
718
+ status: alive ? 'RUNNING' : 'CRASHED',
719
+ pid,
720
+ taskSubdir,
721
+ casesDone,
722
+ lastCase,
723
+ logTail,
724
+ };
725
+ }
726
+
727
+ // ---- status subcommand -----------------------------------------------------
728
+
729
+ export interface StatusArgs {
730
+ taskDir: string;
731
+ outputDir?: string;
732
+ }
733
+
734
+ /** Latest `task_*` subdir in `taskDir` (name-sorted desc), or null. */
735
+ export function findTaskSubdir(taskDir: string): string | null {
736
+ if (!fs.existsSync(taskDir)) return null;
737
+ let entries: fs.Dirent[];
738
+ try {
739
+ entries = fs.readdirSync(taskDir, { withFileTypes: true });
740
+ } catch {
741
+ return null;
742
+ }
743
+ const candidates = entries
744
+ .filter((e) => e.isDirectory() && e.name.startsWith('task_'))
745
+ .map((e) => e.name)
746
+ .sort()
747
+ .reverse();
748
+ return candidates.length ? path.join(taskDir, candidates[0]) : null;
749
+ }
750
+
751
+ /** Latest `self_test_*.log` (desc), falling back to `batch_stdout.log`, or null. */
752
+ export function findLatestLog(outputDir: string): string | null {
753
+ if (!fs.existsSync(outputDir)) return null;
754
+ let entries: fs.Dirent[];
755
+ try {
756
+ entries = fs.readdirSync(outputDir, { withFileTypes: true });
757
+ } catch {
758
+ return null;
759
+ }
760
+ const selfTest = entries
761
+ .filter((e) => e.isFile() && e.name.startsWith('self_test_') && e.name.endsWith('.log'))
762
+ .map((e) => e.name)
763
+ .sort()
764
+ .reverse();
765
+ const batchLog = entries
766
+ .filter((e) => e.isFile() && e.name === 'batch_stdout.log')
767
+ .map((e) => e.name);
768
+ const ordered = [...selfTest, ...batchLog];
769
+ return ordered.length ? path.join(outputDir, ordered[0]) : null;
770
+ }
771
+
772
+ /**
773
+ * `status` subcommand: report state from output files.
774
+ * summary.json present → COMPLETED (exit 0)
775
+ * else pid alive → RUNNING (exit 2)
776
+ * else → CRASHED (exit 3)
777
+ * No pid file at all → NOT_STARTED (exit 4).
778
+ */
779
+ export function cmdStatus(args: StatusArgs): void {
780
+ const taskDir = path.resolve(args.taskDir);
781
+ const outputDir = args.outputDir ? path.resolve(args.outputDir) : taskDir;
782
+
783
+ const r = probeStatus(taskDir, outputDir);
784
+
785
+ if (r.status === 'NOT_STARTED') {
786
+ console.log(JSON.stringify({ status: 'NOT_STARTED' }));
787
+ process.exit(4);
788
+ }
789
+
790
+ if (r.status === 'COMPLETED') {
791
+ console.log(
792
+ JSON.stringify({
793
+ status: 'COMPLETED',
794
+ pid: r.pid,
795
+ task_subdir: r.taskSubdir,
796
+ cases_done: r.casesDone,
797
+ pass_count: r.passCount ?? 0,
798
+ fail_count: r.failCount ?? 0,
799
+ unknown_count: r.unknownCount ?? 0,
800
+ pass_rate: r.passRate ?? 0,
801
+ log_tail: r.logTail,
802
+ }),
803
+ );
804
+ process.exit(0);
805
+ }
806
+
807
+ // RUNNING or CRASHED
808
+ console.log(
809
+ JSON.stringify({
810
+ status: r.status,
811
+ pid: r.pid,
812
+ cases_done: r.casesDone,
813
+ last_case: r.lastCase,
814
+ task_subdir: r.taskSubdir,
815
+ log_tail: r.logTail,
816
+ }),
817
+ );
818
+ process.exit(r.status === 'RUNNING' ? 2 : 3);
819
+ }
820
+
821
+ // ---- kill subcommand -------------------------------------------------------
822
+
823
+ export interface KillArgs {
824
+ taskDir: string;
825
+ }
826
+
827
+ /** `kill` subcommand: terminate the batch-launcher background process by pid. */
828
+ export function cmdKill(args: KillArgs): void {
829
+ const taskDir = path.resolve(args.taskDir);
830
+ const pidFile = path.join(taskDir, 'batch.pid');
831
+ if (!fs.existsSync(pidFile)) {
832
+ console.log(JSON.stringify({ status: 'NO_PID_FILE', killed: false }));
833
+ return;
834
+ }
835
+ let pid: number;
836
+ try {
837
+ pid = parseInt(fs.readFileSync(pidFile, 'utf-8').trim(), 10);
838
+ } catch {
839
+ console.log(JSON.stringify({ status: 'NO_PID_FILE', killed: false }));
840
+ return;
841
+ }
842
+ if (!pidAlive(pid)) {
843
+ console.log(JSON.stringify({ status: 'ALREADY_DEAD', pid, killed: false }));
844
+ return;
845
+ }
846
+ killProcessTree(pid);
847
+ console.log(JSON.stringify({ status: 'KILLED', pid, killed: true }));
848
+ }
849
+
850
+ // ---- CLI entry -------------------------------------------------------------
851
+
852
+ /** Wire up `run` / `status` / `kill` subcommands via commander. */
853
+ export function main(): void {
854
+ const program = new Command();
855
+ program.name('self-test-runner').description('自测执行器 - 统一的进程管理和测试执行');
856
+
857
+ program
858
+ .command('run')
859
+ .description('准备环境并执行用例')
860
+ .requiredOption('--testcases <path>', '测试用例文件,JSON 数组或 JSONL')
861
+ .requiredOption('--hap <path>', '签名包:单个 .hap/.hsp 文件、目录,或逗号分隔的多个文件/目录')
862
+ .requiredOption('--bundle-name <name>', '包名')
863
+ .option('--task-dir <dir>', '任务目录(内部会创建 task_<timestamp> 子目录)', 'task')
864
+ .option('--output-dir <dir>', '日志目录')
865
+ .option('--category <name>', '测试分类名称,传给 batch-launcher', DEFAULT_CATEGORY)
866
+ .option('--config <path>', 'HomeTrans 配置文件路径')
867
+ .option('--timeout <sec>', '阻塞直到终态或超时(秒),或 `auto` = 按用例数 × 720s 自动推导。不传则立即返回 RUNNING JSON。超时后自动 kill batch 并返回 TIMEOUT JSON(exit 5)', v => {
868
+ if (v === 'auto') return 'auto';
869
+ const n = Number(v);
870
+ if (!Number.isInteger(n) || n <= 0) {
871
+ throw new Error(`--timeout 必须是正整数或 'auto',收到: ${v}`);
872
+ }
873
+ return n;
874
+ })
875
+ .action(async (opts: RunArgs) => {
876
+ await cmdRun({
877
+ testcases: opts.testcases,
878
+ hap: opts.hap,
879
+ bundleName: opts.bundleName,
880
+ taskDir: opts.taskDir,
881
+ outputDir: opts.outputDir,
882
+ category: opts.category,
883
+ config: opts.config,
884
+ timeout: opts.timeout,
885
+ });
886
+ });
887
+
888
+ program
889
+ .command('status')
890
+ .description('查询执行状态')
891
+ .requiredOption('--task-dir <dir>')
892
+ .option('--output-dir <dir>')
893
+ .action((opts: StatusArgs) => {
894
+ cmdStatus({ taskDir: opts.taskDir, outputDir: opts.outputDir });
895
+ });
896
+
897
+ program
898
+ .command('kill')
899
+ .description('终止进程')
900
+ .requiredOption('--task-dir <dir>')
901
+ .action((opts: KillArgs) => {
902
+ cmdKill({ taskDir: opts.taskDir });
903
+ });
904
+
905
+ // ---- Validation gates (replace the self-tester.md `uv run python -c` lines) --
906
+ // Each prints its message to stdout on pass, or stderr + exit(1) on fail —
907
+ // matching the prompt's `… && echo OK` expectation. These are NOT part of the
908
+ // run/status/kill stdout-JSON contract; they are plain pass/fail checks.
909
+ const gate = (fn: () => CheckResult): void => {
910
+ const r = fn();
911
+ if (r.ok) {
912
+ console.log(r.message);
913
+ } else {
914
+ console.error(r.message);
915
+ process.exit(1);
916
+ }
917
+ };
918
+
919
+ program
920
+ .command('check-hap')
921
+ .description('校验 hap_path:各项存在且至少含一个入口 .hap')
922
+ .requiredOption('--hap <path>', '签名包:文件、目录,或逗号分隔的多个文件/目录')
923
+ .action((opts: { hap: string }) => gate(() => checkHap(opts.hap)));
924
+
925
+ program
926
+ .command('check-inputs')
927
+ .description('校验 testcases.json(非空数组)与 app-metadata.json(必需字段)可解析')
928
+ .requiredOption('--testcases <path>')
929
+ .requiredOption('--metadata <path>')
930
+ .action((opts: { testcases: string; metadata: string }) =>
931
+ gate(() => checkInputs(opts.testcases, opts.metadata)),
932
+ );
933
+
934
+ program
935
+ .command('check-pre')
936
+ .description('校验 testcases.json 中 [PRE] 用例从索引 0 起连续')
937
+ .requiredOption('--testcases <path>')
938
+ .action((opts: { testcases: string }) => gate(() => checkPre(opts.testcases)));
939
+
940
+ program
941
+ .command('check-config')
942
+ .description('校验多模态模型 api_key 可解析(env 或 ~/.hometrans/config.json)')
943
+ .action(() => gate(() => checkConfig()));
944
+
945
+ program
946
+ .command('resolve-dir')
947
+ .description('解析并打印 test-tools/autotest 目录')
948
+ .option('--from <dir>', '解析失败时从该目录(通常 output_path)向上回退查找')
949
+ .action((opts: { from?: string }) => gate(() => resolveDir(opts.from)));
950
+
951
+ program.parseAsync(process.argv).catch((err) => {
952
+ console.error(err instanceof Error ? err.message : err);
953
+ process.exit(1);
954
+ });
955
+ }
956
+
957
+ const __filename = fileURLToPath(import.meta.url);
958
+ const isMainEntry = !!process.argv[1] && fs.realpathSync(process.argv[1]) === __filename;
959
+ if (isMainEntry) {
960
+ main();
961
+ }