@buaa_smat/hometrans 0.1.17 → 0.1.20

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 (227) hide show
  1. package/README.md +138 -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 +35 -376
  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 +19 -146
  35. package/dist/cli/config.js +6 -8
  36. package/dist/cli/env-vars.js +1 -3
  37. package/dist/cli/index.js +0 -11
  38. package/dist/cli/init.js +147 -235
  39. package/dist/cli/uninstall.js +5 -129
  40. package/dist/utils/regex.js +8 -0
  41. package/env-requirements.json +57 -55
  42. package/package.json +6 -8
  43. package/resource/convert_pipeline_process.svg +103 -0
  44. package/resource/project_architecture.svg +122 -0
  45. package/resource/title_dark.png +0 -0
  46. package/skills/hmos-batch-ui-align/SKILL.md +345 -43
  47. package/skills/hmos-batch-ui-align/references/conversion-procedure.md +661 -180
  48. package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +2533 -2533
  49. package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +555 -555
  50. package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +117 -117
  51. 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
  52. 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
  53. 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
  54. 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
  55. 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
  56. 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
  57. 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
  58. 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
  59. 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
  60. 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
  61. package/skills/hmos-batch-ui-align/references/mvvm/MVVM/346/250/241/345/274/217/357/274/210V1/357/274/211.md +911 -911
  62. 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
  63. 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
  64. 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
  65. 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
  66. 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
  67. 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
  68. 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
  69. 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
  70. 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
  71. 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
  72. 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
  73. 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
  74. 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
  75. 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
  76. 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
  77. 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
  78. 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
  79. 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
  80. package/skills/hmos-batch-ui-align/scripts/android_parse_fast.ts +1798 -0
  81. package/skills/hmos-batch-ui-align/scripts/arkts_static_check.ts +1592 -0
  82. package/skills/hmos-batch-ui-align/scripts/measure_pack.ts +752 -0
  83. package/skills/hmos-convert-pipeline/SKILL.md +188 -131
  84. package/skills/hmos-fix-build-errors/SKILL.md +87 -67
  85. package/skills/hmos-fix-build-errors/references/arkts-strict-patterns.md +219 -219
  86. package/skills/hmos-fix-build-errors/references/known-patterns.md +157 -157
  87. package/skills/hmos-fix-build-errors/references/rdb-entity-pattern.md +131 -131
  88. package/skills/hmos-incremental-ui-align/README.md +57 -40
  89. package/skills/hmos-incremental-ui-align/SKILL.md +180 -24
  90. package/skills/hmos-incremental-ui-align/diff_analysis.md +52 -52
  91. package/skills/hmos-incremental-ui-align/page_align.md +62 -62
  92. package/skills/hmos-incremental-ui-align/references/Comparison_Template.md +38 -2
  93. 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
  94. 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
  95. 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
  96. 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
  97. 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
  98. 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
  99. 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
  100. 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
  101. 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
  102. 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
  103. 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
  104. 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
  105. 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
  106. 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
  107. 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
  108. 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
  109. 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
  110. 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
  111. 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
  112. 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
  113. 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
  114. 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
  115. 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
  116. 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
  117. 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
  118. 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
  119. 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
  120. 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
  121. package/skills/hmos-incremental-ui-align/references/State_Model_Template.md +74 -0
  122. package/skills/hmos-incremental-ui-align/references/UI_Analysis_Template.md +34 -4
  123. package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +2533 -2533
  124. package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-interaction-mapping-reference.md +555 -555
  125. package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-layout-mapping-reference.md +117 -117
  126. package/skills/hmos-incremental-ui-align/scripts/app_feature_verify.ts +937 -0
  127. package/skills/hmos-incremental-ui-align/scripts/extract_checklist.ts +343 -0
  128. package/skills/hmos-incremental-ui-align/scripts/navigation-capure.md +44 -5
  129. package/skills/hmos-incremental-ui-align/scripts/page_capture.ts +977 -0
  130. package/skills/hmos-incremental-ui-align/scripts/page_capture_burst.ts +188 -0
  131. package/skills/hmos-integration-test/README.md +111 -79
  132. package/skills/hmos-integration-test/SKILL.md +216 -132
  133. package/skills/hmos-integration-test/scripts/report-tool.ts +791 -0
  134. package/skills/hmos-integration-test/scripts/resolve-metadata-tool.ts +125 -0
  135. package/skills/hmos-integration-test/scripts/self-test-runner.ts +756 -0
  136. package/skills/hmos-integration-test/scripts/testcases-tool.ts +239 -0
  137. package/skills/hmos-resources-convert/SKILL.md +334 -66
  138. package/skills/hmos-resources-convert/references/code-vector-icon-rules.md +335 -0
  139. package/skills/hmos-resources-convert/references/conversion-rules.md +676 -663
  140. package/skills/hmos-resources-convert/references/dependency-analysis-rules.md +410 -388
  141. package/skills/hmos-resources-convert/references/lottie-conversion-rules.md +219 -0
  142. package/skills/hmos-resources-convert/references/resource-mapping-rules.md +482 -457
  143. package/skills/hmos-resources-convert/references/xml-drawable-to-svg-rules.md +592 -513
  144. package/skills/hmos-resources-convert/scripts/a2h_resource_convert.ts +2163 -0
  145. package/skills/hmos-resources-convert/scripts/code_vector_icons.ts +591 -0
  146. package/skills/hmos-resources-convert/scripts/svg_fidelity_check.ts +632 -0
  147. package/skills/hmos-spec-generate/SKILL.md +293 -214
  148. package/skills/hmos-spec-generate/scripts/parse_requirements.ts +515 -0
  149. package/skills/hmos-spec-generate/template/REQ.txt +22 -0
  150. package/skills/hmos-spec-generate/template/REQ.xlsx +0 -0
  151. package/skills/hmos-test-case-generation/README.md +241 -0
  152. package/skills/hmos-test-case-generation/SKILL.md +324 -0
  153. package/skills/hmos-test-case-generation/references/contract.md +315 -0
  154. package/skills/hmos-test-case-generation/references/review-notes-template.md +84 -0
  155. package/skills/hmos-test-case-generation/references/ui-elements-schema.md +142 -0
  156. package/skills/hmos-test-case-generation/tools/convert_to_ui_elements.ts +550 -0
  157. package/skills/hmos-test-case-generation/tools/validate.ts +1312 -0
  158. package/tools/bfs-crawl/README.md +73 -0
  159. package/tools/bfs-crawl/android_viewtree_bfs_crawler.ts +1662 -0
  160. package/agents/build-fixer.md +0 -385
  161. package/agents/logic-coder/scripts/platform_context_query.py +0 -568
  162. package/agents/review-fixer.md +0 -405
  163. package/agents/spec-generator.md +0 -541
  164. package/dist/cli/mcp-setup.js +0 -258
  165. package/dist/cli/mcp.js +0 -94
  166. package/dist/context/index.js +0 -694
  167. package/resource/migration_process.svg +0 -94
  168. package/resource/migration_process_transparent.svg +0 -93
  169. package/skills/hmos-batch-ui-align/scripts/android_parse_fast.py +0 -1606
  170. package/skills/hmos-incremental-ui-align/scripts/__pycache__/app_feature_verify.cpython-314.pyc +0 -0
  171. package/skills/hmos-incremental-ui-align/scripts/app_feature_verify.py +0 -542
  172. package/skills/hmos-incremental-ui-align/scripts/page_capture.py +0 -597
  173. package/skills/hmos-resources-convert/evals/evals.json +0 -171
  174. package/skills/hmos-resources-convert/template/AppScope/app.json5 +0 -10
  175. package/skills/hmos-resources-convert/template/AppScope/resources/base/element/string.json +0 -8
  176. package/skills/hmos-resources-convert/template/AppScope/resources/base/media/background.png +0 -0
  177. package/skills/hmos-resources-convert/template/AppScope/resources/base/media/foreground.png +0 -0
  178. package/skills/hmos-resources-convert/template/AppScope/resources/base/media/layered_image.json +0 -7
  179. package/skills/hmos-resources-convert/template/build-profile.json5 +0 -42
  180. package/skills/hmos-resources-convert/template/code-linter.json5 +0 -32
  181. package/skills/hmos-resources-convert/template/entry/build-profile.json5 +0 -33
  182. package/skills/hmos-resources-convert/template/entry/hvigorfile.ts +0 -6
  183. package/skills/hmos-resources-convert/template/entry/obfuscation-rules.txt +0 -23
  184. package/skills/hmos-resources-convert/template/entry/oh-package.json5 +0 -10
  185. package/skills/hmos-resources-convert/template/entry/src/main/ets/entryability/EntryAbility.ets +0 -48
  186. package/skills/hmos-resources-convert/template/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +0 -16
  187. package/skills/hmos-resources-convert/template/entry/src/main/ets/pages/Index.ets +0 -23
  188. package/skills/hmos-resources-convert/template/entry/src/main/module.json5 +0 -55
  189. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/element/color.json +0 -8
  190. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/element/float.json +0 -8
  191. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/element/string.json +0 -16
  192. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/media/background.png +0 -0
  193. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/media/foreground.png +0 -0
  194. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/media/layered_image.json +0 -7
  195. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/media/startIcon.png +0 -0
  196. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/profile/backup_config.json +0 -3
  197. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/profile/main_pages.json +0 -5
  198. package/skills/hmos-resources-convert/template/entry/src/main/resources/dark/element/color.json +0 -8
  199. package/skills/hmos-resources-convert/template/entry/src/mock/mock-config.json5 +0 -2
  200. package/skills/hmos-resources-convert/template/entry/src/ohosTest/ets/test/Ability.test.ets +0 -35
  201. package/skills/hmos-resources-convert/template/entry/src/ohosTest/ets/test/List.test.ets +0 -5
  202. package/skills/hmos-resources-convert/template/entry/src/ohosTest/module.json5 +0 -16
  203. package/skills/hmos-resources-convert/template/entry/src/test/List.test.ets +0 -5
  204. package/skills/hmos-resources-convert/template/entry/src/test/LocalUnit.test.ets +0 -33
  205. package/skills/hmos-resources-convert/template/hvigor/hvigor-config.json5 +0 -23
  206. package/skills/hmos-resources-convert/template/hvigorfile.ts +0 -6
  207. package/skills/hmos-resources-convert/template/oh-package-lock.json5 +0 -28
  208. package/skills/hmos-resources-convert/template/oh-package.json5 +0 -10
  209. package/skills/hmos-resources-convert/tools/apktool_3.0.1.jar +0 -0
  210. package/skills/hmos-spec-generate/references/android-platform-tokens.md +0 -105
  211. package/skills/hmos-spec-generate/references/spec-sample-1.md +0 -78
  212. package/skills/hmos-spec-generate/references/spec-sample-2.md +0 -58
  213. package/skills/hmos-spec-generate/references/spec-sample-3.md +0 -116
  214. package/skills/hmos-spec-generate/references/step4-report-template.md +0 -33
  215. package/tools/test-tools/autotest/README.md +0 -238
  216. package/tools/test-tools/autotest/pyproject.toml +0 -26
  217. package/tools/test-tools/autotest/report_tool.py +0 -759
  218. package/tools/test-tools/autotest/self_test_runner.py +0 -895
  219. package/tools/test-tools/autotest/testcases_schema.md +0 -143
  220. package/tools/test-tools/autotest/testcases_tool.py +0 -215
  221. package/tools/test-tools/autotest/uv.lock +0 -3156
  222. package/tools/test-tools/harmony_autotest-0.1.0-py3-none-any.whl +0 -0
  223. package/tools/test-tools/hypium-6.1.0.210-py3-none-any.whl +0 -0
  224. package/tools/test-tools/hypium_mcp-0.6.5-py3-none-any.whl +0 -0
  225. package/tools/test-tools/xdevice-6.1.0.210-py3-none-any.whl +0 -0
  226. package/tools/test-tools/xdevice_devicetest-6.1.0.210-py3-none-any.whl +0 -0
  227. package/tools/test-tools/xdevice_ohos-6.1.0.210-py3-none-any.whl +0 -0
@@ -0,0 +1,626 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { copyFile, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const DEFAULT_API_LEVEL = 22;
8
+ const ALLOWED_STAGES = new Set(['planner', 'coder']);
9
+ const DEFAULT_QUERY_TYPES_BY_STAGE = {
10
+ planner: ['api', 'pattern'],
11
+ coder: ['api', 'pattern'],
12
+ };
13
+ const DEEPWIKI_URL = 'https://mcp.deepwiki.com/mcp';
14
+ const READ_TIMEOUT_MS = 120000;
15
+ const MAX_RESPONSE_CHARS = 2400;
16
+ const MAX_RETRIES = 2;
17
+ const RETRY_BASE_MS = 2000;
18
+ const DEEPWIKI_REPO = 'jjjzzz666/dev_kb_repo';
19
+ const PROVIDER_FAILURE_PATTERNS = [
20
+ 'Error processing question',
21
+ 'Query failed',
22
+ 'Error while executing query',
23
+ ];
24
+ const PLANNER_SLOTS = [
25
+ 'feasibility',
26
+ 'owner_boundary',
27
+ 'forbidden_path',
28
+ 'version_gate',
29
+ 'protocol_variant',
30
+ 'fallback_gap',
31
+ 'blocking_unknown',
32
+ 'completion_evidence',
33
+ 'implementation_implication',
34
+ ];
35
+ const CODER_SLOTS = [
36
+ 'exact_api',
37
+ 'exact_import',
38
+ 'return_error',
39
+ 'context_permission',
40
+ 'lifecycle_threading',
41
+ 'local_forbidden',
42
+ 'local_validation',
43
+ 'planned_fallback',
44
+ 'blocking_unknown',
45
+ ];
46
+ const ALLOWED_STRUCTURED_SLOTS = new Set([...PLANNER_SLOTS, ...CODER_SLOTS]);
47
+ const PREFACE_PATTERNS = [
48
+ 'you are asking',
49
+ 'the user is asking',
50
+ "you're asking",
51
+ 'i understand',
52
+ 'based on',
53
+ 'summary:',
54
+ 'here are',
55
+ ];
56
+ const DEEPWIKI_FOOTER_PREFIX = 'view this search on deepwiki:';
57
+ const STRUCTURED_LINE_RE = /^[-*]\s*(?:\*\*)?(?<slot>extra:[a-z0-9_-]+|[a-z][a-z0-9_]*)(?:\*\*)?\s*:\s*(?<fact>.+)$/i;
58
+ const OUTPUT_CONTRACT = 'OUTPUT CONTRACT: Total response must be at most 1800 characters and 8 lines. Every line must start with a hyphen and space, followed by a plain slot name, colon, and fact. Do not use Markdown around slot names. Return no other text. If over budget, keep blocking_unknown, conflicts, and decision-changing facts; silently omit lower-priority facts.';
59
+
60
+ function parseArgs(argv) {
61
+ const args = {
62
+ request: '',
63
+ outDir: '',
64
+ apiLevel: null,
65
+ dryRun: false,
66
+ };
67
+ for (let index = 0; index < argv.length; index += 1) {
68
+ const token = argv[index];
69
+ if (token === '--request' && argv[index + 1]) {
70
+ args.request = argv[++index];
71
+ continue;
72
+ }
73
+ if (token === '--out-dir' && argv[index + 1]) {
74
+ args.outDir = argv[++index];
75
+ continue;
76
+ }
77
+ if (token === '--api-level' && argv[index + 1]) {
78
+ args.apiLevel = parseInteger(argv[++index], '--api-level');
79
+ continue;
80
+ }
81
+ if (token === '--dry-run') {
82
+ args.dryRun = true;
83
+ continue;
84
+ }
85
+ throw new Error(`unknown argument: ${token}`);
86
+ }
87
+ if (!args.request || !args.outDir) {
88
+ throw new Error('--request and --out-dir are required');
89
+ }
90
+ return args;
91
+ }
92
+
93
+ function parseInteger(value, name) {
94
+ const text = String(value).trim();
95
+ if (!/^\d+$/.test(text)) throw new Error(`${name} must be an integer`);
96
+ const parsed = Number(text);
97
+ if (!Number.isSafeInteger(parsed)) throw new Error(`${name} must be an integer`);
98
+ return parsed;
99
+ }
100
+
101
+ async function loadJson(filePath) {
102
+ const parsed = JSON.parse(await readFile(filePath, 'utf8'));
103
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
104
+ throw new Error('request must be a JSON object');
105
+ }
106
+ return parsed;
107
+ }
108
+
109
+ async function writeJson(filePath, data) {
110
+ await mkdir(path.dirname(filePath), { recursive: true });
111
+ await writeFile(filePath, `${JSON.stringify(data, null, 2)}\n`, 'utf8');
112
+ }
113
+
114
+ function normalize(value) {
115
+ return String(value ?? '').replace(/\s+/g, ' ').trim();
116
+ }
117
+
118
+ function requiredText(value, name) {
119
+ if (typeof value !== 'string') throw new Error(`${name} must be a non-empty string`);
120
+ const text = normalize(value);
121
+ if (!text) throw new Error(`${name} must be a non-empty string`);
122
+ return text;
123
+ }
124
+
125
+ function normalizeList(value, name, warnings = []) {
126
+ if (value == null) return [];
127
+ const isArray = Array.isArray(value);
128
+ const items = isArray ? value : [value];
129
+ if (!isArray) warnings.push(`${name} was normalized to a one-item list`);
130
+ return items.map((item) => {
131
+ if (typeof item === 'string') return normalize(item);
132
+ if (item && typeof item === 'object' && !Array.isArray(item)) {
133
+ return normalize(JSON.stringify(item));
134
+ }
135
+ throw new Error(`${name} must contain only strings or objects`);
136
+ }).filter(Boolean);
137
+ }
138
+
139
+ function canonicalizeRequest(request, warnings = []) {
140
+ const canonical = { ...request };
141
+ const aliases = {
142
+ platform_surfaces: ['platformSurfaces'],
143
+ extra_constraints: ['extraConstraints', 'extra_contraints'],
144
+ };
145
+ for (const [name, candidates] of Object.entries(aliases)) {
146
+ if (canonical[name] != null) continue;
147
+ const alias = candidates.find((candidate) => canonical[candidate] != null);
148
+ if (!alias) continue;
149
+ canonical[name] = canonical[alias];
150
+ warnings.push(`${alias} was normalized to ${name}`);
151
+ }
152
+ return canonical;
153
+ }
154
+
155
+ function resolveApiLevel(request, cliApiLevel) {
156
+ if (cliApiLevel != null) return { apiLevel: cliApiLevel, source: 'cli' };
157
+ const raw = request.api_level ?? request.api_version;
158
+ if (raw != null) {
159
+ return { apiLevel: parseInteger(raw, 'api_level'), source: 'request' };
160
+ }
161
+ return { apiLevel: DEFAULT_API_LEVEL, source: 'default' };
162
+ }
163
+
164
+ function validateRequest(request, apiLevel, warnings = []) {
165
+ const stage = normalize(request.stage);
166
+ if (!ALLOWED_STAGES.has(stage)) throw new Error("stage must be 'planner' or 'coder'");
167
+ const focusPoint = requiredText(request.focus_point, 'focus_point');
168
+ const taskExcerpt = requiredText(request.task_excerpt ?? request.spec_excerpt, 'task_excerpt');
169
+ let projectEvidence = 'none';
170
+ if (request.project_evidence != null) {
171
+ if (typeof request.project_evidence !== 'string') throw new Error('project_evidence must be a string');
172
+ projectEvidence = normalize(request.project_evidence);
173
+ if (!projectEvidence) {
174
+ projectEvidence = 'none';
175
+ warnings.push('project_evidence was normalized to none');
176
+ }
177
+ }
178
+ let queryTypes;
179
+ if (request.query_types == null) {
180
+ queryTypes = [...DEFAULT_QUERY_TYPES_BY_STAGE[stage]];
181
+ } else if (typeof request.query_types === 'string') {
182
+ queryTypes = [normalize(request.query_types).toLowerCase()].filter(Boolean);
183
+ warnings.push('query_types was normalized to a one-item list');
184
+ } else if (Array.isArray(request.query_types)) {
185
+ queryTypes = request.query_types.map((item) => {
186
+ if (typeof item !== 'string') throw new Error('query_types must contain only strings');
187
+ return normalize(item).toLowerCase();
188
+ }).filter(Boolean);
189
+ } else {
190
+ throw new Error('query_types must be a list or one string');
191
+ }
192
+ if (!queryTypes.length && !Array.isArray(request.query_types)) {
193
+ queryTypes = [...DEFAULT_QUERY_TYPES_BY_STAGE[stage]];
194
+ warnings.push('empty query_types was replaced with stage defaults');
195
+ }
196
+ for (const queryType of queryTypes) {
197
+ if (!['api', 'pattern', 'migration'].includes(queryType)) {
198
+ throw new Error(`unsupported query_type: ${queryType}`);
199
+ }
200
+ }
201
+ return {
202
+ stage,
203
+ api_level: apiLevel,
204
+ focus_point: focusPoint,
205
+ task_excerpt: taskExcerpt,
206
+ project_evidence: projectEvidence,
207
+ platform_surfaces: normalizeList(request.platform_surfaces, 'platform_surfaces', warnings),
208
+ extra_constraints: normalizeList(request.extra_constraints, 'extra_constraints', warnings),
209
+ query_types: [...new Set(queryTypes)],
210
+ };
211
+ }
212
+
213
+ function shortModuleName(stage, focusPoint) {
214
+ const base = focusPoint.replace(/[^a-zA-Z0-9]+/g, '_').replace(/^_+|_+$/g, '').toLowerCase() || 'platform_context';
215
+ return `${stage}_${base.slice(0, 72).replace(/_+$/g, '')}`;
216
+ }
217
+
218
+ function joinItems(items) {
219
+ return items.length ? items.join('; ') : 'none';
220
+ }
221
+
222
+ function defaultExtraConstraints(stage) {
223
+ if (stage === 'planner') {
224
+ return [
225
+ 'Return only decision-changing platform facts: feasibility, exact surface/owner/lifecycle/version gates, forbidden paths, fallback or blocking unknown, and code-observable completion evidence.',
226
+ 'Check unasked platform pitfalls in initial state, mutation/event, identity/key, lifecycle/async, permission/context, persistence, and return/error/null/default/conflict semantics.',
227
+ 'Anchor on the named surfaces; do not silently substitute them. Include at most two adjacent APIs, protocols, or pitfalls only when they invalidate, constrain, or materially improve the requested path; label each extra:alternative_surface or extra:pitfall and state why. If direct evidence is unavailable or conflicts, return blocking_unknown.',
228
+ ];
229
+ }
230
+ return [
231
+ 'Return only edit-relevant platform facts: exact API/import/type/signature, version/permission/context/lifecycle gates, return/error/null/default/conflict, forbidden use, fallback, and validation.',
232
+ 'Check unasked platform pitfalls in initial state, mutation/event, identity/key, lifecycle/async, permission/context, persistence, and return/error/null/default/conflict semantics.',
233
+ 'Anchor on the named surfaces; do not silently substitute them. Include at most two adjacent APIs, protocols, or pitfalls only when they invalidate, constrain, or materially improve the requested path; label each extra:alternative_surface or extra:pitfall and state why. If direct evidence is unavailable or conflicts, return blocking_unknown.',
234
+ ];
235
+ }
236
+
237
+ function buildStageChecks(stage, queryType) {
238
+ if (stage === 'planner') {
239
+ if (queryType === 'api') {
240
+ return 'path feasibility at this API level; required owner/context/lifecycle/capability gate; API family traps that can invalidate the plan; fallback or blocking gap; code-observable completion evidence affected by this fact';
241
+ }
242
+ if (queryType === 'migration') {
243
+ return 'cross-platform assumptions that would make the plan invalid; HarmonyOS primary path; forbidden migration paths; owner/lifecycle/permission differences; fallback or blocking gap';
244
+ }
245
+ return 'forbidden paths and false friends; negative space that looks valid but should not be used; valid high-level pattern only if it changes the plan; hidden owner/lifecycle/state pitfalls; fallback or blocking gap; the smallest evidence a planner can require to know the path is complete';
246
+ }
247
+ if (queryType === 'api') {
248
+ return 'exact import/module/type/member/signature and minimal call shape; API-level availability for this call; required permission/config/context; return/error/null/default/conflict semantics; call-site lifecycle/threading constraints; compile/runtime failure traps';
249
+ }
250
+ if (queryType === 'migration') {
251
+ return 'old-platform assumptions that would break this local edit; exact HarmonyOS replacement API or local pattern; incompatible parameters/return semantics; permission/lifecycle differences at this call site';
252
+ }
253
+ return 'minimal valid local usage pattern; local forbidden usage that would fail compile/runtime; lifecycle/permission/state pitfalls at this call site; whether the planned fallback is valid; minimal validation checks for this edit; do not redesign the architecture';
254
+ }
255
+
256
+ function stageQualityBar(stage) {
257
+ if (stage === 'planner') {
258
+ return 'Quality bar: a planner can write a short contract from the answer: main path, forbidden path, fallback/gap, owner/lifecycle boundary, blocking unknown if unresolved, and observable completion evidence. ';
259
+ }
260
+ return 'Quality bar: a coder can write or check the local code from the answer: exact import/module/type/member/signature, minimal call shape, context/permission/config, lifecycle/threading, return/error/null/default/conflict semantics, forbidden local usage, and validation check. ';
261
+ }
262
+
263
+ function buildQuery(request, queryType) {
264
+ const stageGoal = request.stage === 'planner'
265
+ ? 'choose a valid implementation path before coding'
266
+ : 'verify exact local API usage while implementing';
267
+ const slots = request.stage === 'planner' ? PLANNER_SLOTS.join(', ') : CODER_SLOTS.join(', ');
268
+ const constraints = [...defaultExtraConstraints(request.stage), ...request.extra_constraints];
269
+ return [
270
+ OUTPUT_CONTRACT,
271
+ `HarmonyOS ArkTS/ArkUI platform fact check. API level: ${request.api_level}.`,
272
+ `Stage goal: ${stageGoal}. Focus: ${request.focus_point}.`,
273
+ `Task constraint: ${request.task_excerpt}.`,
274
+ `Project evidence: ${request.project_evidence}.`,
275
+ `Platform surfaces: ${joinItems(request.platform_surfaces)}.`,
276
+ `Extra constraints: ${joinItems(constraints)}.`,
277
+ `Check only: ${buildStageChecks(request.stage, queryType)}.`,
278
+ stageQualityBar(request.stage),
279
+ 'Return concise evidence bullets only.',
280
+ `Use these slots when applicable: ${slots}.`,
281
+ 'For critical slots, write `slot: none` when the fact is not applicable or not known.',
282
+ 'If sources disagree or the fact is unavailable, state the conflict or unknown explicitly; do not smooth it over.',
283
+ 'You may add extra:<name> if a critical fact does not fit.',
284
+ 'Do not invent missing facts.',
285
+ 'No preface, headings, restatement, examples, tutorials, or steps.',
286
+ OUTPUT_CONTRACT,
287
+ ].join(' ');
288
+ }
289
+
290
+ function cleanEvidenceResponse(text) {
291
+ const structuredLines = [];
292
+ const fallbackLines = [];
293
+ let hasTruncated = false;
294
+ for (const rawLine of String(text).split('\n')) {
295
+ const line = rawLine.trim();
296
+ if (!line) continue;
297
+ const lowered = line.toLowerCase().replace(/^[#*\-0-9.\s]+/, '');
298
+ if (line.startsWith('#') || lowered.startsWith(DEEPWIKI_FOOTER_PREFIX) || PREFACE_PATTERNS.some((pattern) => lowered.startsWith(pattern))) {
299
+ continue;
300
+ }
301
+ const match = STRUCTURED_LINE_RE.exec(line);
302
+ if (match?.groups) {
303
+ let { slot } = match.groups;
304
+ const fact = match.groups.fact.trim();
305
+ if (!fact) continue;
306
+ slot = slot.toLowerCase();
307
+ if (!ALLOWED_STRUCTURED_SLOTS.has(slot) && !slot.startsWith('extra:')) {
308
+ slot = `extra:${slot}`;
309
+ }
310
+ structuredLines.push(`- ${slot}: ${fact}`);
311
+ continue;
312
+ }
313
+ if (line === '[truncated]') hasTruncated = true;
314
+ fallbackLines.push(line);
315
+ }
316
+ if (structuredLines.length) {
317
+ const extraLines = fallbackLines.map((line) => `- extra:unstructured: ${line}`);
318
+ const complete = !hasTruncated;
319
+ return { cleaned: [...structuredLines, ...extraLines].join('\n'), structured: complete };
320
+ }
321
+ const cleaned = fallbackLines.join('\n').trim();
322
+ return { cleaned: cleaned || String(text), structured: false };
323
+ }
324
+
325
+ function buildQueries(request) {
326
+ const moduleName = shortModuleName(request.stage, request.focus_point);
327
+ return request.query_types.map((queryType) => ({
328
+ module: moduleName,
329
+ type: queryType,
330
+ query: buildQuery(request, queryType),
331
+ }));
332
+ }
333
+
334
+ function parseSseResponse(content) {
335
+ let result = '';
336
+ for (const rawLine of content.split('\n')) {
337
+ const line = rawLine.trim();
338
+ if (!line.startsWith('data: ')) continue;
339
+ try {
340
+ const data = JSON.parse(line.slice(6));
341
+ if (data.error) return `[provider_error] ${data.error}`;
342
+ for (const item of data.result?.content ?? []) {
343
+ if (item?.type === 'text') result += item.text ?? '';
344
+ }
345
+ } catch {
346
+ continue;
347
+ }
348
+ }
349
+ return result.trim();
350
+ }
351
+
352
+ function truncateResponse(text) {
353
+ if (text.length <= MAX_RESPONSE_CHARS) return text;
354
+ const cut = text.lastIndexOf('\n', MAX_RESPONSE_CHARS);
355
+ if (cut <= 0) return '[truncated]';
356
+ return `${text.slice(0, cut).trimEnd()}\n[truncated]`;
357
+ }
358
+
359
+ function providerTextFailure(text) {
360
+ return PROVIDER_FAILURE_PATTERNS.some((pattern) => text.includes(pattern));
361
+ }
362
+
363
+ function retryWaitMillis(attempt) {
364
+ const base = RETRY_BASE_MS * (2 ** attempt);
365
+ return Math.round(base * (0.8 + (0.4 * Math.random())));
366
+ }
367
+
368
+ async function askDeepwikiOnce(repo, question) {
369
+ const controller = new AbortController();
370
+ const timer = setTimeout(() => controller.abort(), READ_TIMEOUT_MS);
371
+ try {
372
+ const response = await fetch(DEEPWIKI_URL, {
373
+ method: 'POST',
374
+ headers: {
375
+ 'Content-Type': 'application/json',
376
+ Accept: 'application/json, text/event-stream',
377
+ 'User-Agent': 'platform-context-query/0.1',
378
+ },
379
+ body: JSON.stringify({
380
+ jsonrpc: '2.0',
381
+ method: 'tools/call',
382
+ id: 1,
383
+ params: {
384
+ name: 'ask_question',
385
+ arguments: {
386
+ repoName: repo,
387
+ question,
388
+ },
389
+ },
390
+ }),
391
+ signal: controller.signal,
392
+ });
393
+ const text = await response.text();
394
+ if (!response.ok) {
395
+ return {
396
+ ok: false,
397
+ response: `[http_error] ${response.status} ${response.statusText}`,
398
+ retryable: [429, 500, 502, 503, 504].includes(response.status),
399
+ };
400
+ }
401
+ const answer = parseSseResponse(text);
402
+ if (!answer) return { ok: false, response: '[provider_error] empty response', retryable: true };
403
+ if (answer.startsWith('[provider_error]')) return { ok: false, response: answer, retryable: true };
404
+ if (answer.includes('429 Too Many Requests') || answer.includes("Client error '429")) {
405
+ return { ok: false, response: answer, retryable: true };
406
+ }
407
+ if (providerTextFailure(answer)) return { ok: false, response: `[provider_error] ${answer}`, retryable: true };
408
+ return { ok: true, response: truncateResponse(answer), retryable: false };
409
+ } catch (error) {
410
+ if (error?.name === 'AbortError') return { ok: false, response: '[timeout]', retryable: true };
411
+ return {
412
+ ok: false,
413
+ response: `[provider_exception] ${error?.name ?? 'Error'}: ${error?.message ?? String(error)}`,
414
+ retryable: error instanceof TypeError && error.message === 'fetch failed',
415
+ };
416
+ } finally {
417
+ clearTimeout(timer);
418
+ }
419
+ }
420
+
421
+ async function askDeepwiki(repo, question) {
422
+ let lastResponse = '';
423
+ for (let attempt = 0; attempt <= MAX_RETRIES; attempt += 1) {
424
+ const result = await askDeepwikiOnce(repo, question);
425
+ if (result.ok) return { ok: true, response: result.response };
426
+ lastResponse = result.response;
427
+ if (!result.retryable || attempt >= MAX_RETRIES) break;
428
+ await new Promise((resolve) => setTimeout(resolve, retryWaitMillis(attempt)));
429
+ }
430
+ return { ok: false, response: lastResponse };
431
+ }
432
+
433
+ async function queryOne(query) {
434
+ const { ok, response } = await askDeepwiki(DEEPWIKI_REPO, query.query);
435
+ return {
436
+ ok,
437
+ entry: {
438
+ ts: new Date().toISOString(),
439
+ provider: 'deepwiki',
440
+ repo: DEEPWIKI_REPO,
441
+ module: query.module ?? '',
442
+ type: query.type ?? 'pattern',
443
+ query: query.query ?? '',
444
+ response,
445
+ quality: ok ? 'verified' : 'query_failed',
446
+ },
447
+ };
448
+ }
449
+
450
+ async function runDeepwikiProvider(queries, cachePath) {
451
+ const results = await Promise.all(queries.map((query) => queryOne(query)));
452
+ const sortedEntries = results.map((result) => result.entry).sort((left, right) => String(left.type).localeCompare(String(right.type)));
453
+ const stderrLines = [];
454
+ let okCount = 0;
455
+ for (const { ok, entry } of results) {
456
+ if (ok) {
457
+ okCount += 1;
458
+ continue;
459
+ }
460
+ stderrLines.push(`${entry.module}/${entry.type}: ${entry.response}`);
461
+ }
462
+ await writeFile(cachePath, `${sortedEntries.map((entry) => JSON.stringify(entry)).join('\n')}${sortedEntries.length ? '\n' : ''}`, 'utf8');
463
+ return {
464
+ stdout: `Queried: ${okCount}, Failed: ${queries.length - okCount}, Total: ${queries.length}`,
465
+ stderr: stderrLines.join('\n'),
466
+ };
467
+ }
468
+
469
+ async function readCacheEntries(cachePath) {
470
+ try {
471
+ const content = await readFile(cachePath, 'utf8');
472
+ return content
473
+ .split('\n')
474
+ .map((line) => line.trim())
475
+ .filter(Boolean)
476
+ .map((line) => {
477
+ try {
478
+ return JSON.parse(line);
479
+ } catch {
480
+ return null;
481
+ }
482
+ })
483
+ .filter((entry) => entry && typeof entry === 'object');
484
+ } catch {
485
+ return [];
486
+ }
487
+ }
488
+
489
+ async function main(argv = process.argv.slice(2)) {
490
+ const started = Date.now();
491
+ const args = parseArgs(argv);
492
+ const requestPath = path.resolve(args.request);
493
+ const outDir = path.resolve(args.outDir);
494
+ const providerDir = path.join(outDir, 'provider');
495
+ const resultPath = path.join(outDir, 'platform-context-result.json');
496
+ const tracePath = path.join(outDir, 'platform-context-trace.json');
497
+ const queriesPath = path.join(providerDir, 'provider-queries.json');
498
+ const cachePath = path.join(providerDir, 'provider-cache.jsonl');
499
+
500
+ const rawRequest = await loadJson(requestPath);
501
+ const normalizationWarnings = [];
502
+ const canonicalRequest = canonicalizeRequest(rawRequest, normalizationWarnings);
503
+ const { apiLevel, source: apiLevelSource } = resolveApiLevel(canonicalRequest, args.apiLevel);
504
+ const request = validateRequest(canonicalRequest, apiLevel, normalizationWarnings);
505
+ const queries = buildQueries(request);
506
+
507
+ await mkdir(providerDir, { recursive: true });
508
+ await rm(cachePath, { force: true, recursive: true });
509
+ await copyFile(requestPath, path.join(outDir, 'platform-context-request.json'));
510
+ await writeJson(queriesPath, queries);
511
+
512
+ let status = args.dryRun ? 'dry_run' : 'ok';
513
+ let providerStdout = '';
514
+ let providerStderr = '';
515
+ let exitCode = 0;
516
+
517
+ if (!args.dryRun) {
518
+ const providerResult = await runDeepwikiProvider(queries, cachePath);
519
+ providerStdout = providerResult.stdout;
520
+ providerStderr = providerResult.stderr;
521
+ }
522
+
523
+ const evidence = await readCacheEntries(cachePath);
524
+ const verifiedCount = evidence.filter((entry) => entry.quality === 'verified').length;
525
+ const failedCount = evidence.length - verifiedCount;
526
+ let structuredMissingCount = 0;
527
+ if (!args.dryRun) {
528
+ if (verifiedCount === 0) {
529
+ status = 'provider_failed';
530
+ exitCode = 1;
531
+ } else if (failedCount > 0) {
532
+ status = 'partial_ok';
533
+ }
534
+ }
535
+
536
+ const evidenceList = [];
537
+ const structuredEvidenceList = [];
538
+ for (const item of evidence) {
539
+ const rawResponse = String(item.response ?? '');
540
+ const { cleaned, structured } = cleanEvidenceResponse(rawResponse);
541
+ if (item.quality === 'verified' && !structured) structuredMissingCount += 1;
542
+ evidenceList.push({
543
+ type: item.type ?? '',
544
+ quality: item.quality ?? '',
545
+ query: item.query ?? '',
546
+ response: rawResponse,
547
+ });
548
+ structuredEvidenceList.push({
549
+ type: item.type ?? '',
550
+ quality: item.quality ?? '',
551
+ structured,
552
+ response: cleaned,
553
+ });
554
+ }
555
+
556
+ const result = {
557
+ status,
558
+ stage: request.stage,
559
+ api_level: apiLevel,
560
+ api_level_source: apiLevelSource,
561
+ focus_point: request.focus_point,
562
+ platform_surfaces: request.platform_surfaces,
563
+ evidence_count: evidence.length,
564
+ verified_evidence_count: verifiedCount,
565
+ failed_evidence_count: failedCount,
566
+ evidence: evidenceList,
567
+ structured_evidence: structuredEvidenceList,
568
+ structured_missing_count: structuredMissingCount,
569
+ llm_usage: [
570
+ 'Use evidence only if it changes or confirms the platform contract, local API usage, forbidden path, fallback, blocking unknown, or validation condition.',
571
+ 'If API facts and pattern facts disagree, do not merge them silently. Prefer the stricter lifecycle / permission / forbidden-path constraint; if the implementation path still depends on the disagreement, record blocking Unknown or platform_drift.',
572
+ 'Do not paste raw evidence into plan.md or commit-info.md.',
573
+ 'If status is not ok and the platform fact blocks the task, record blocking Unknown or platform_drift.',
574
+ ],
575
+ };
576
+ const trace = {
577
+ status,
578
+ provider: 'deepwiki',
579
+ api_level: apiLevel,
580
+ api_level_source: apiLevelSource,
581
+ query_count: queries.length,
582
+ evidence_count: evidence.length,
583
+ verified_evidence_count: verifiedCount,
584
+ failed_evidence_count: failedCount,
585
+ structured_missing_count: structuredMissingCount,
586
+ normalization_warnings: normalizationWarnings,
587
+ elapsed_ms: Date.now() - started,
588
+ dry_run: args.dryRun,
589
+ provider_stdout: providerStdout,
590
+ provider_stderr: providerStderr,
591
+ internal_files: {
592
+ queries: queriesPath,
593
+ cache: cachePath,
594
+ },
595
+ };
596
+
597
+ await writeJson(resultPath, result);
598
+ await writeJson(tracePath, trace);
599
+ process.stdout.write(`${resultPath}\n`);
600
+ return exitCode;
601
+ }
602
+
603
+ export const __test__ = Object.freeze({
604
+ askDeepwikiOnce,
605
+ buildQueries,
606
+ canonicalizeRequest,
607
+ cleanEvidenceResponse,
608
+ normalizeList,
609
+ parseArgs,
610
+ parseSseResponse,
611
+ truncateResponse,
612
+ validateRequest,
613
+ });
614
+ export { main };
615
+
616
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
617
+ main().then(
618
+ (code) => {
619
+ process.exitCode = code;
620
+ },
621
+ (error) => {
622
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
623
+ process.exitCode = 1;
624
+ },
625
+ );
626
+ }