@ohos-cpf/3rdloop 0.0.2 → 0.0.4

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 (393) hide show
  1. package/README.md +290 -244
  2. package/bin/3rdloop.mjs +46 -46
  3. package/lib/cli.js +781 -781
  4. package/lib/config-cmd.js +451 -451
  5. package/lib/config.js +318 -318
  6. package/lib/doctor.js +113 -113
  7. package/lib/exit-codes.js +30 -30
  8. package/lib/opencode.js +155 -155
  9. package/lib/orch.js +426 -426
  10. package/lib/queries.js +263 -263
  11. package/lib/step.js +325 -325
  12. package/lib/ui.js +222 -222
  13. package/lib/update.js +279 -279
  14. package/lib/workflow.js +308 -308
  15. package/lib/workflows.js +131 -131
  16. package/package.json +50 -50
  17. package/vendor/Server/Agent/SkillSelector/README.md +343 -343
  18. package/vendor/Server/Agent/SkillSelector/core/Agent.js +207 -207
  19. package/vendor/Server/Agent/SkillSelector/index.js +14 -14
  20. package/vendor/Server/Agent/SkillSelector/llm/llmClient.js +313 -313
  21. package/vendor/Server/Agent/SkillSelector/llm/prompts.js +161 -161
  22. package/vendor/Server/Agent/SkillSelector/llm/reactSteps.js +144 -144
  23. package/vendor/Server/Agent/SkillSelector/matcher/fuzzyMatcher.js +433 -433
  24. package/vendor/Server/Agent/SkillSelector/scanner/skillScanner.js +382 -382
  25. package/vendor/Server/Agent/SkillSelector/utils/actionWords.js +59 -59
  26. package/vendor/Server/Brain/AnalysisStrategies.js +422 -422
  27. package/vendor/Server/Brain/Brain.js +686 -686
  28. package/vendor/Server/Brain/DecompositionStrategies.js +621 -621
  29. package/vendor/Server/Brain/PlanPersistence.js +196 -196
  30. package/vendor/Server/Brain/SkillExecutor.js +251 -251
  31. package/vendor/Server/Brain/index.js +11 -11
  32. package/vendor/Server/CLI/cli.js +275 -275
  33. package/vendor/Server/CLI/deveco-code/index.js +71 -71
  34. package/vendor/Server/CLI/deveco-code.js +5 -5
  35. package/vendor/Server/CLI/opencode/index.js +817 -818
  36. package/vendor/Server/CLI/opencode.js +5 -5
  37. package/vendor/Server/DbUse/MessageArchive.js +61 -61
  38. package/vendor/Server/DbUse/StorageManager.js +107 -107
  39. package/vendor/Server/DbUse/adapters/BaseAdapter.js +94 -94
  40. package/vendor/Server/DbUse/adapters/FileAdapter.js +138 -138
  41. package/vendor/Server/DbUse/adapters/JsonAdapter.js +138 -138
  42. package/vendor/Server/DbUse/adapters/JsonlAdapter.js +114 -114
  43. package/vendor/Server/DbUse/adapters/SqliteAdapter.js +157 -157
  44. package/vendor/Server/DbUse/index.js +160 -160
  45. package/vendor/Server/DbUse/stores/SessionStore.js +279 -279
  46. package/vendor/Server/DbUse/stores/TaskExecutionStore.js +133 -133
  47. package/vendor/Server/DbUse/stores/TaskRegistryStore.js +262 -262
  48. package/vendor/Server/DbUse/stores/TaskStepStore.js +279 -279
  49. package/vendor/Server/FlexRunner/FlexRunner.js +1759 -1759
  50. package/vendor/Server/FlexRunner/index.js +12 -12
  51. package/vendor/Server/Knowledge/KnowledgeImporter.js +523 -523
  52. package/vendor/Server/Knowledge/KnowledgeManager.js +341 -341
  53. package/vendor/Server/Knowledge/index.js +33 -33
  54. package/vendor/Server/LoopEngine/LoopEngine.js +1133 -1133
  55. package/vendor/Server/LoopEngine/index.js +11 -11
  56. package/vendor/Server/Orchestrator/Orchestrator.js +0 -3
  57. package/vendor/Server/Orchestrator/StepNode.js +312 -312
  58. package/vendor/Server/Orchestrator/index.js +13 -13
  59. package/vendor/Server/Routes/controllers/BrainController.js +241 -241
  60. package/vendor/Server/Routes/controllers/FlexRunnerController.js +1125 -1125
  61. package/vendor/Server/Routes/controllers/HealthController.js +44 -44
  62. package/vendor/Server/Routes/controllers/KnowledgeImportController.js +355 -355
  63. package/vendor/Server/Routes/controllers/LoopEngineController.js +788 -788
  64. package/vendor/Server/Routes/controllers/StatsController.js +57 -57
  65. package/vendor/Server/Routes/controllers/StreamController.js +67 -67
  66. package/vendor/Server/Routes/library/logger.js +179 -179
  67. package/vendor/Server/Routes/library/zipArchive.js +172 -172
  68. package/vendor/Server/Routes/router/Router.js +204 -204
  69. package/vendor/Server/Routes/routes/brain.js +47 -47
  70. package/vendor/Server/Routes/routes/flexrunner.js +72 -72
  71. package/vendor/Server/Routes/routes/health.js +28 -28
  72. package/vendor/Server/Routes/routes/index.js +57 -57
  73. package/vendor/Server/Routes/routes/knowledge.js +55 -55
  74. package/vendor/Server/Routes/routes/loopengine.js +58 -58
  75. package/vendor/Server/Routes/routes/orchestrator.js +61 -61
  76. package/vendor/Server/Routes/routes/registry.js +97 -97
  77. package/vendor/Server/Routes/routes/stats.js +23 -23
  78. package/vendor/Server/Routes/routes/stream.js +30 -30
  79. package/vendor/Server/Routes/server.js +203 -203
  80. package/vendor/Server/Routes/sse/SseHub.js +308 -308
  81. package/vendor/Server/Skills/acceptance-check/SKILL.md +191 -191
  82. package/vendor/Server/Skills/acceptance-check/references/PHASE1_ARTIFACT_COLLECTION.md +52 -52
  83. package/vendor/Server/Skills/acceptance-check/references/PHASE2_CRITERIA_EVALUATION.md +77 -77
  84. package/vendor/Server/Skills/acceptance-check/references/PHASE2_EVIDENCE_VERIFICATION.md +70 -70
  85. package/vendor/Server/Skills/arkts-code-check/SKILL.md +320 -320
  86. package/vendor/Server/Skills/arkts-code-check/references/CODE_CHECK_GUIDE.md +210 -210
  87. package/vendor/Server/Skills/arkts-code-check/references/FILE_TYPE_GUIDE.md +28 -28
  88. package/vendor/Server/Skills/arkts-code-check/references/PHASE1_INFO_COLLECTION.md +233 -233
  89. package/vendor/Server/Skills/arkts-code-check/references/REPORT_TEMPLATE.md +219 -219
  90. package/vendor/Server/Skills/arkts-library-compile-validate/SKILL.md +328 -328
  91. package/vendor/Server/Skills/arkts-library-compile-validate/scripts/build.ps1 +93 -93
  92. package/vendor/Server/Skills/arkts-library-compile-validate/scripts/code-linter.cjs +432 -432
  93. package/vendor/Server/Skills/arkts-library-compile-validate/scripts/migrate.cjs +851 -851
  94. package/vendor/Server/Skills/arkts-library-compile-validate/scripts/ohpm-switch.cjs +788 -788
  95. package/vendor/Server/Skills/arkts-library-demo-code/SKILL.md +291 -291
  96. package/vendor/Server/Skills/arkts-library-demo-code/references/API_SIGNATURE_CHECKS.md +68 -68
  97. package/vendor/Server/Skills/arkts-library-demo-code/references/BUILD_VALIDATION.md +184 -184
  98. package/vendor/Server/Skills/arkts-library-demo-code/references/CODE_STANDARDS.md +337 -337
  99. package/vendor/Server/Skills/arkts-library-demo-code/references/EXAMPLES.md +400 -400
  100. package/vendor/Server/Skills/arkts-library-demo-code/references/SYSTEM_API_LOOKUP.md +98 -98
  101. package/vendor/Server/Skills/arkts-library-demo-code/references/TEMPLATE.md +544 -544
  102. package/vendor/Server/Skills/arkts-library-demo-code/scripts/build.ps1 +93 -93
  103. package/vendor/Server/Skills/arkts-library-demo-code/scripts/code-linter.cjs +432 -432
  104. package/vendor/Server/Skills/arkts-library-demo-code/scripts/migrate.cjs +851 -851
  105. package/vendor/Server/Skills/arkts-library-demo-code/scripts/ohpm-switch.cjs +788 -788
  106. package/vendor/Server/Skills/arkts-library-demo-coverage/SKILL.md +174 -174
  107. package/vendor/Server/Skills/arkts-library-demo-scenario/SKILL.md +321 -321
  108. package/vendor/Server/Skills/arkts-library-demo-scenario/references/EXAMPLES.md +100 -100
  109. package/vendor/Server/Skills/arkts-library-demo-scenario/references/TEMPLATE.md +185 -185
  110. package/vendor/Server/Skills/arkts-library-documentation-quality-check/SKILL.md +233 -233
  111. package/vendor/Server/Skills/arkts-library-documentation-quality-check/assets/REPORT_TEMPLATE.md +102 -102
  112. package/vendor/Server/Skills/arkts-library-documentation-quality-check/references/CHECK_DIMENSIONS.md +89 -89
  113. package/vendor/Server/Skills/arkts-library-documentation-quality-check/references/COMPLIANCE_CHECKLIST.md +62 -62
  114. package/vendor/Server/Skills/arkts-library-documentation-quality-check/references/KB_QUERY_GUIDE.md +107 -107
  115. package/vendor/Server/Skills/arkts-library-documentation-quality-check/references/MCP_TOOL_DISCOVERY.md +124 -124
  116. package/vendor/Server/Skills/arkts-library-documentation-quality-check/references/REPORT_TEMPLATE.md +90 -90
  117. package/vendor/Server/Skills/arkts-library-documentation-quality-check/references/SCORING_FORMULA.md +57 -57
  118. package/vendor/Server/Skills/arkts-library-documentation-quality-check/scripts/validate-skill.cjs +259 -259
  119. package/vendor/Server/Skills/arkts-library-interface-spec/SKILL.md +97 -97
  120. package/vendor/Server/Skills/arkts-library-memory-leak-check/SKILL.md +391 -391
  121. package/vendor/Server/Skills/arkts-library-source-clone/SKILL.md +113 -113
  122. package/vendor/Server/Skills/arkts-library-stability-check/SKILL.md +312 -312
  123. package/vendor/Server/Skills/arkts-library-stability-check/assets/REPORT_TEMPLATE.md +154 -154
  124. package/vendor/Server/Skills/arkts-library-stability-check/references/CHECKLIST.md +165 -165
  125. package/vendor/Server/Skills/arkts-library-stability-check/references/CODE_EXAMPLES.md +308 -308
  126. package/vendor/Server/Skills/arkts-library-stability-check/references/SCORING_RULES.md +90 -90
  127. package/vendor/Server/Skills/arkts-library-stability-check/scripts/validate-skill.cjs +282 -282
  128. package/vendor/Server/Skills/arkts-library-test-coverage-check/SKILL.md +360 -360
  129. package/vendor/Server/Skills/arkts-library-test-coverage-check/assets/REPORT_TEMPLATE.md +145 -145
  130. package/vendor/Server/Skills/arkts-library-test-coverage-check/references/CHECKLIST.md +252 -252
  131. package/vendor/Server/Skills/arkts-library-test-coverage-check/references/MCP_TOOL_USAGE.md +114 -114
  132. package/vendor/Server/Skills/arkts-library-test-coverage-check/scripts/validate-skill.cjs +262 -262
  133. package/vendor/Server/Skills/arkts-library-xts-code/SKILL.md +455 -455
  134. package/vendor/Server/Skills/arkts-library-xts-code/assets/report-template.md +60 -60
  135. package/vendor/Server/Skills/arkts-library-xts-code/references/ACCESS_MODIFIER_PRECHECK.md +76 -76
  136. package/vendor/Server/Skills/arkts-library-xts-code/references/BUILD_VERIFICATION.md +200 -200
  137. package/vendor/Server/Skills/arkts-library-xts-code/references/CODE_STANDARDS.md +518 -518
  138. package/vendor/Server/Skills/arkts-library-xts-code/references/SUBAGENT_PROMPT_TEMPLATE.md +276 -276
  139. package/vendor/Server/Skills/arkts-library-xts-code/references/SYSTEM_API_LOOKUP.md +92 -92
  140. package/vendor/Server/Skills/arkts-library-xts-code/references/XTS_TEMPLATE.md +767 -767
  141. package/vendor/Server/Skills/arkts-library-xts-code/scripts/build.ps1 +93 -93
  142. package/vendor/Server/Skills/arkts-library-xts-code/scripts/code-linter.cjs +432 -432
  143. package/vendor/Server/Skills/arkts-library-xts-code/scripts/migrate.cjs +851 -851
  144. package/vendor/Server/Skills/arkts-library-xts-code/scripts/ohpm-switch.cjs +788 -788
  145. package/vendor/Server/Skills/arkts-library-xts-code/scripts/precheck-access-modifiers.cjs +221 -221
  146. package/vendor/Server/Skills/arkts-library-xts-code-fix/SKILL.md +228 -228
  147. package/vendor/Server/Skills/arkts-library-xts-coverage/SKILL.md +97 -97
  148. package/vendor/Server/Skills/arkts-library-xts-doc/SKILL.md +194 -194
  149. package/vendor/Server/Skills/arkts-library-xts-doc/references/EXAMPLES.md +575 -575
  150. package/vendor/Server/Skills/arkts-library-xts-doc/references/TEMPLATE.md +574 -574
  151. package/vendor/Server/Skills/arkts-library-xts-doc/references/TESTABILITY_GUIDE.md +182 -182
  152. package/vendor/Server/Skills/arkts-library-xts-execution/SKILL.md +490 -490
  153. package/vendor/Server/Skills/arkts-library-xts-execution/references/error-fixing-examples.md +217 -217
  154. package/vendor/Server/Skills/arkts-library-xts-execution/scripts/build.ps1 +93 -93
  155. package/vendor/Server/Skills/arkts-library-xts-execution/scripts/code-linter.cjs +432 -432
  156. package/vendor/Server/Skills/arkts-library-xts-execution/scripts/migrate.cjs +851 -851
  157. package/vendor/Server/Skills/arkts-library-xts-execution/scripts/ohpm-switch.cjs +788 -788
  158. package/vendor/Server/Skills/flutter-code-check/SKILL.md +299 -299
  159. package/vendor/Server/Skills/flutter-code-check/assets/OUTPUT_TEMPLATE.md +311 -311
  160. package/vendor/Server/Skills/flutter-code-check/references/CHECKLIST.md +190 -190
  161. package/vendor/Server/Skills/flutter-code-check/references/PLATFORMS.md +133 -133
  162. package/vendor/Server/Skills/flutter-code-check/scripts/validate-skill.cjs +259 -259
  163. package/vendor/Server/Skills/flutter-interface/README.md +75 -75
  164. package/vendor/Server/Skills/flutter-interface/SKILL.md +291 -291
  165. package/vendor/Server/Skills/flutter-interface/references/EXAMPLES.md +336 -336
  166. package/vendor/Server/Skills/flutter-interface/references/GIT_CLONE_GUIDE.md +190 -190
  167. package/vendor/Server/Skills/flutter-interface/references/SCRIPT_REFERENCE.md +258 -258
  168. package/vendor/Server/Skills/flutter-interface/references/TEMPLATE.md +254 -254
  169. package/vendor/Server/Skills/flutter-library-consistency-check/SKILL.md +517 -517
  170. package/vendor/Server/Skills/flutter-library-consistency-check/references/CHECKLIST.md +381 -381
  171. package/vendor/Server/Skills/flutter-library-consistency-check/references/FUNCTION_COMPARISON_GUIDE.md +341 -341
  172. package/vendor/Server/Skills/flutter-library-consistency-check/references/PLATFORM_LIMITATION_GUIDE.md +71 -71
  173. package/vendor/Server/Skills/flutter-library-documentation-quality-check/SKILL.md +518 -518
  174. package/vendor/Server/Skills/flutter-library-documentation-quality-check/references/CHECKLIST.md +406 -406
  175. package/vendor/Server/Skills/flutter-library-memory-leak-check/SKILL.md +652 -652
  176. package/vendor/Server/Skills/flutter-library-memory-leak-check/references/CHECKLIST.md +396 -396
  177. package/vendor/Server/Skills/flutter-library-stability-check/SKILL.md +744 -744
  178. package/vendor/Server/Skills/flutter-library-stability-check/references/CHECKLIST.md +720 -720
  179. package/vendor/Server/Skills/flutter-library-test-coverage-check/SKILL.md +414 -414
  180. package/vendor/Server/Skills/flutter-library-test-coverage-check/assets/REPORT_TEMPLATE.md +150 -150
  181. package/vendor/Server/Skills/flutter-library-test-coverage-check/references/CHECKLIST.md +304 -304
  182. package/vendor/Server/Skills/flutter-library-test-coverage-check/references/SCORING_RULES.md +265 -265
  183. package/vendor/Server/Skills/flutter-library-test-coverage-check/references/SCRIPT_USAGE.md +286 -286
  184. package/vendor/Server/Skills/knowledge-import/SKILL.md +383 -383
  185. package/vendor/Server/Skills/knowledge-import/references/MCP_TOOL_USAGE.md +165 -165
  186. package/vendor/Server/Skills/knowledge-import/references/SKILL_LOCATOR_GUIDE.md +91 -91
  187. package/vendor/Server/Skills/knowledge-import/references/SKILL_OPTIMIZATION_GUIDE.md +127 -127
  188. package/vendor/Server/Skills/ohos-lib-pr-push/SKILL.md +453 -301
  189. package/vendor/Server/Skills/ohos-lib-pr-push/assets/PR_CHECKLIST.md +151 -0
  190. package/vendor/Server/Skills/ohos-lib-pr-push/assets/PR_ISSUE_TEMPLATE.md +257 -105
  191. package/vendor/Server/Skills/ohos-lib-pr-push/references/GITCODE_API.md +191 -127
  192. package/vendor/Server/Skills/ohos-lib-pr-push/scripts/gitcode-api.cjs +317 -208
  193. package/vendor/Server/Skills/rn-code-check/SKILL.md +320 -320
  194. package/vendor/Server/Skills/rn-code-check/references/API-GUIDE.md +234 -234
  195. package/vendor/Server/Skills/rn-code-check/references/CHECKLIST.md +188 -188
  196. package/vendor/Server/Skills/rn-code-check/references/REPORT-TEMPLATE.md +246 -246
  197. package/vendor/Server/Skills/rn-lib-add-example/SKILL.md +198 -198
  198. package/vendor/Server/Skills/rn-lib-add-example/references/APP_RENAME_GUIDE.md +40 -40
  199. package/vendor/Server/Skills/rn-lib-add-example/references/SHELL_ADAPTATION_CHECKLIST.md +78 -78
  200. package/vendor/Server/Skills/rn-lib-add-example/references/TEMPLATE_REPO_GUIDE.md +70 -70
  201. package/vendor/Server/Skills/rn-lib-add-example/references/VERIFICATION_GUIDE.md +47 -47
  202. package/vendor/Server/Skills/rn-lib-add-example/scripts/create-example.cjs +252 -252
  203. package/vendor/Server/Skills/rn-lib-update-doc/SKILL.md +176 -176
  204. package/vendor/Server/Skills/rn-lib-update-doc/config.json +5 -5
  205. package/vendor/Server/Skills/rn-lib-update-doc/references/changelog-template.md +35 -35
  206. package/vendor/Server/Skills/rn-lib-update-doc/references/format-diff.md +137 -137
  207. package/vendor/Server/Skills/rn-lib-update-doc/references/link-registry.json +33 -33
  208. package/vendor/Server/Skills/rn-lib-update-doc/references/model-0.4.2-overview.md +40 -40
  209. package/vendor/Server/Skills/rn-lib-update-doc/references/model-0.4.2.md +429 -429
  210. package/vendor/Server/Skills/rn-lib-update-doc/scripts/detect-readme-format.cjs +105 -105
  211. package/vendor/Server/Skills/rn-lib-update-doc/scripts/find-usage-doc.cjs +90 -90
  212. package/vendor/Server/Skills/rn-lib-update-doc/scripts/link-verify.cjs +213 -213
  213. package/vendor/Server/Skills/rn-lib-update-doc/scripts/normalize-changelog.cjs +73 -73
  214. package/vendor/Server/Skills/rn-lib-update-doc/scripts/normalize-package-meta.cjs +258 -258
  215. package/vendor/Server/Skills/rn-lib-update-doc/scripts/normalize-readme-links.cjs +341 -341
  216. package/vendor/Server/Skills/rn-lib-update-doc/scripts/resolve-usage-docs.cjs +67 -67
  217. package/vendor/Server/Skills/rn-library-consistency-check/SKILL.md +299 -299
  218. package/vendor/Server/Skills/rn-library-consistency-check/assets/REPORT_TEMPLATE.md +293 -293
  219. package/vendor/Server/Skills/rn-library-consistency-check/references/ARKTS_COMPONENT_CHECK_GUIDE.md +857 -857
  220. package/vendor/Server/Skills/rn-library-consistency-check/references/ARKTS_TURBOMODULE_CHECK_GUIDE.md +856 -856
  221. package/vendor/Server/Skills/rn-library-consistency-check/references/CHECKLIST.md +157 -157
  222. package/vendor/Server/Skills/rn-library-consistency-check/references/CPP_COMPONENT_CHECK_GUIDE.md +801 -801
  223. package/vendor/Server/Skills/rn-library-consistency-check/references/CPP_TURBOMODULE_CHECK_GUIDE.md +683 -683
  224. package/vendor/Server/Skills/rn-library-consistency-check/references/FUNCTION_COMPARISON_GUIDE.md +233 -233
  225. package/vendor/Server/Skills/rn-library-consistency-check/references/NATIVE_COMPONENT_IDENTIFICATION.md +1373 -1373
  226. package/vendor/Server/Skills/rn-library-consistency-check/references/SCORING_STANDARD.md +220 -220
  227. package/vendor/Server/Skills/rn-library-consistency-check/scripts/validate-skill.py +245 -245
  228. package/vendor/Server/Skills/rn-library-documentation-quality-check/SKILL.md +263 -263
  229. package/vendor/Server/Skills/rn-library-documentation-quality-check/assets/MODEL.md +414 -414
  230. package/vendor/Server/Skills/rn-library-documentation-quality-check/assets/MODEL_en.md +413 -413
  231. package/vendor/Server/Skills/rn-library-documentation-quality-check/assets/REPORT_TEMPLATE.md +311 -311
  232. package/vendor/Server/Skills/rn-library-documentation-quality-check/references/CHECK_CHECKLIST.md +355 -355
  233. package/vendor/Server/Skills/rn-library-documentation-quality-check/references/CROSS_VALIDATION_GUIDE.md +115 -115
  234. package/vendor/Server/Skills/rn-library-documentation-quality-check/references/DOC_COLLECTION_GUIDE.md +139 -139
  235. package/vendor/Server/Skills/rn-library-documentation-quality-check/references/EXAMPLES.md +586 -586
  236. package/vendor/Server/Skills/rn-library-documentation-quality-check/references/GOTCHAS.md +57 -57
  237. package/vendor/Server/Skills/rn-library-documentation-quality-check/scripts/validate-skill.py +259 -259
  238. package/vendor/Server/Skills/rn-library-interface-analyzer/SKILL.md +301 -301
  239. package/vendor/Server/Skills/rn-library-interface-analyzer/assets/REPORT_TEMPLATE.md +148 -148
  240. package/vendor/Server/Skills/rn-library-interface-analyzer/references/DOC_ANNOTATION_GUIDE.md +118 -118
  241. package/vendor/Server/Skills/rn-library-interface-analyzer/references/SCRIPT_USAGE_GUIDE.md +168 -168
  242. package/vendor/Server/Skills/rn-library-interface-analyzer/references/URL_PARSING_RULES.md +176 -176
  243. package/vendor/Server/Skills/rn-library-issue-generalizer/SKILL.md +274 -274
  244. package/vendor/Server/Skills/rn-library-issue-generalizer/assets/case-template.md +45 -45
  245. package/vendor/Server/Skills/rn-library-issue-generalizer/assets/rule-template.md +25 -25
  246. package/vendor/Server/Skills/rn-library-issue-generalizer/references/PR_FETCH_GUIDE.md +61 -61
  247. package/vendor/Server/Skills/rn-library-issue-generalizer/references/RULE_TEMPLATE_GUIDE.md +165 -165
  248. package/vendor/Server/Skills/rn-library-issue-generalizer/scripts/fetch-pr-info.py +239 -239
  249. package/vendor/Server/Skills/rn-library-known-issue-check/SKILL.md +263 -263
  250. package/vendor/Server/Skills/rn-library-known-issue-check/assets/REPORT_TEMPLATE.md +96 -96
  251. package/vendor/Server/Skills/rn-library-known-issue-check/references/COMPLIANCE_CHECKLIST.md +57 -57
  252. package/vendor/Server/Skills/rn-library-known-issue-check/references/INSPECTION_GUIDE.md +99 -99
  253. package/vendor/Server/Skills/rn-library-known-issue-check/references/PRESCREEN_GUIDE.md +64 -64
  254. package/vendor/Server/Skills/rn-library-known-issue-check/references/SOURCE_PREP_GUIDE.md +74 -74
  255. package/vendor/Server/Skills/rn-library-known-issue-check/scripts/validate-known-issue-report.py +164 -164
  256. package/vendor/Server/Skills/rn-library-memory-leak-check/SKILL.md +356 -339
  257. package/vendor/Server/Skills/rn-library-memory-leak-check/assets/REPORT_TEMPLATE.md +85 -83
  258. package/vendor/Server/Skills/rn-library-memory-leak-check/references/CHECKLIST.md +905 -859
  259. package/vendor/Server/Skills/rn-library-memory-leak-check/references/HARMONY_CODE_PATTERNS.md +124 -122
  260. package/vendor/Server/Skills/rn-library-memory-leak-check/scripts/scan_harmony_code.py +287 -279
  261. package/vendor/Server/Skills/rn-library-stability-check/SKILL.md +273 -273
  262. package/vendor/Server/Skills/rn-library-stability-check/assets/REPORT_TEMPLATE.md +129 -129
  263. package/vendor/Server/Skills/rn-library-stability-check/references/CHECKLIST.md +581 -581
  264. package/vendor/Server/Skills/rn-library-stability-check/references/SCORING_RULES.md +138 -138
  265. package/vendor/Server/Skills/rn-library-stability-check/scripts/scan-harmony-code.py +168 -168
  266. package/vendor/Server/Skills/rn-library-test-coverage-check/SKILL.md +526 -506
  267. package/vendor/Server/Skills/rn-library-test-coverage-check/references/CHECKLIST.md +321 -280
  268. package/vendor/Server/Skills/rn-library-test-coverage-check/references/DEMO_LOCATION.md +221 -221
  269. package/vendor/Server/Skills/rn-library-test-coverage-check/references/REPORT_TEMPLATE.md +220 -209
  270. package/vendor/Server/Skills/rn-library-test-coverage-check/references/SCRIPT_USAGE.md +325 -325
  271. package/vendor/Server/Skills/rn-ohos-xts-generator/SKILL.md +279 -279
  272. package/vendor/Server/Skills/rn-ohos-xts-generator/assets/TEST_FILE_TEMPLATES.md +404 -404
  273. package/vendor/Server/Skills/rn-ohos-xts-generator/references/BUILD_TROUBLESHOOTING.md +185 -185
  274. package/vendor/Server/Skills/rn-ohos-xts-generator/references/BUILD_WORKFLOW.md +265 -265
  275. package/vendor/Server/Skills/rn-ohos-xts-generator/references/COMMON_CONFIG.md +189 -189
  276. package/vendor/Server/Skills/rn-ohos-xts-generator/references/CONFIG_GUIDE.md +203 -203
  277. package/vendor/Server/Skills/rn-ohos-xts-generator/references/COVERAGE_ANALYZER.md +147 -147
  278. package/vendor/Server/Skills/rn-ohos-xts-generator/references/DESIGN_DOC_GUIDE.md +148 -148
  279. package/vendor/Server/Skills/rn-ohos-xts-generator/references/GENERATION_FLOW.md +165 -165
  280. package/vendor/Server/Skills/rn-ohos-xts-generator/references/GENERATION_STRATEGY.md +195 -195
  281. package/vendor/Server/Skills/rn-ohos-xts-generator/references/HARMONY_SCANNER.md +249 -249
  282. package/vendor/Server/Skills/rn-ohos-xts-generator/references/JEST_FRAMEWORK.md +235 -235
  283. package/vendor/Server/Skills/rn-ohos-xts-generator/references/PLATFORM_COMPAT.md +161 -161
  284. package/vendor/Server/Skills/rn-ohos-xts-generator/references/RN_TEST_PATTERNS.md +413 -413
  285. package/vendor/Server/Skills/rn-ohos-xts-generator/references/SOURCE_PARSER.md +235 -235
  286. package/vendor/Server/Skills/rn-ohos-xts-generator/references/TEST_CONVENTIONS.md +245 -245
  287. package/vendor/Server/Skills/rn-ohos-xts-generator/references/TROUBLESHOOTING.md +282 -282
  288. package/vendor/Server/Skills/rn-ohos-xts-generator/references/USAGE_GUIDE.md +251 -251
  289. package/vendor/Server/Skills/rnoh-cptf-api-test/SKILL.md +469 -469
  290. package/vendor/Server/Skills/rnoh-cptf-api-test/assets/CPTF_TEST_TEMPLATE.md +310 -310
  291. package/vendor/Server/Skills/rnoh-cptf-api-test/assets/DEMO_PAGE_TEMPLATE.md +303 -303
  292. package/vendor/Server/Skills/rnoh-cptf-api-test/references/CPTF_TEST_GENERATION_GUIDE.md +421 -421
  293. package/vendor/Server/Skills/rnoh-cptf-api-test/references/DEMO_GENERATION_GUIDE.md +358 -358
  294. package/vendor/Server/Skills/rnoh-cptf-api-test/references/QUALITY_CHECKLIST.md +114 -114
  295. package/vendor/Server/Skills/rnoh-cptf-api-test/references/SPEC_PARSING_GUIDE.md +274 -274
  296. package/vendor/Server/Skills/rnoh-cptf-api-test/scripts/validate-rnoh-cptf-api-test.sh +185 -185
  297. package/vendor/Server/Skills/rnoh-cptf-demo-test/SKILL.md +191 -191
  298. package/vendor/Server/Skills/rnoh-cptf-demo-test/assets/TEST_TEMPLATE.md +216 -216
  299. package/vendor/Server/Skills/rnoh-cptf-demo-test/references/CPTF_SETUP.md +107 -107
  300. package/vendor/Server/Skills/rnoh-cptf-demo-test/references/DEMO_ANALYSIS.md +120 -120
  301. package/vendor/Server/Skills/rnoh-cptf-demo-test/scripts/validate-rnoh-cptf-test.sh +108 -108
  302. package/vendor/Server/Skills/rnoh-cptf-test-run/SKILL.md +237 -237
  303. package/vendor/Server/Skills/rnoh-cptf-test-run/references/DEBUG_PLAYBOOK.md +261 -261
  304. package/vendor/Server/Skills/rnoh-cptf-test-run/scripts/validate-run-env.sh +112 -112
  305. package/vendor/Server/Skills/rnoh-lib-code-adapt/SKILL.md +497 -497
  306. package/vendor/Server/Skills/rnoh-lib-code-adapt/references/adapt-checklist.md +270 -270
  307. package/vendor/Server/Skills/rnoh-lib-code-adapt/references/api-migration-checklist.md +164 -164
  308. package/vendor/Server/Skills/rnoh-lib-code-adapt/references/common-compile-errors.md +556 -556
  309. package/vendor/Server/Skills/rnoh-lib-code-adapt/references/deveco-cli-tools.md +459 -459
  310. package/vendor/Server/Skills/rnoh-lib-code-adapt/references/edge-cases.md +65 -65
  311. package/vendor/Server/Skills/rnoh-lib-code-adapt/references/har-tgz-build.md +512 -512
  312. package/vendor/Server/Skills/rnoh-lib-code-adapt/references/version-compat-matrix.md +132 -132
  313. package/vendor/Server/Skills/rnoh-lib-code-adapt/scripts/auto-integrate.sh +424 -424
  314. package/vendor/Server/Skills/rnoh-lib-demo-coverage/SKILL.md +137 -137
  315. package/vendor/Server/Skills/rnoh-lib-demo-create/SKILL.md +306 -306
  316. package/vendor/Server/Skills/rnoh-lib-demo-create/assets/DEMO_PAGE_TEMPLATE.md +485 -485
  317. package/vendor/Server/Skills/rnoh-lib-demo-create/assets/INDEX_TEMPLATE.md +172 -172
  318. package/vendor/Server/Skills/rnoh-lib-demo-create/references/DEMO_CODE_RULES.md +422 -422
  319. package/vendor/Server/Skills/rnoh-lib-demo-create/references/QUALITY_CHECKLIST.md +95 -95
  320. package/vendor/Server/Skills/rnoh-lib-demo-create/references/SOURCE_EXPLORATION.md +169 -169
  321. package/vendor/Server/Skills/rnoh-lib-demo-doc/SKILL.md +554 -554
  322. package/vendor/Server/Skills/rnoh-lib-demo-doc/assets/DEMO_DOC_TEMPLATE.md +106 -106
  323. package/vendor/Server/Skills/rnoh-lib-demo-doc/references/COVERAGE_INCREMENTAL.md +216 -216
  324. package/vendor/Server/Skills/rnoh-lib-demo-doc/references/DEMO_DESIGN_RULES.md +413 -413
  325. package/vendor/Server/Skills/rnoh-lib-demo-doc/references/OUTPUT_FORMAT.md +269 -269
  326. package/vendor/Server/Skills/rnoh-lib-demo-doc/references/QUALITY_CHECKLIST.md +98 -98
  327. package/vendor/Server/Skills/rnoh-lib-func-test/SKILL.md +337 -337
  328. package/vendor/Server/Skills/rnoh-lib-rnt-search/SKILL.md +722 -722
  329. package/vendor/Server/Skills/rnoh-lib-rnt-search/assets/PORT_REPORT_TEMPLATE.md +219 -219
  330. package/vendor/Server/Skills/rnoh-lib-rnt-search/references/DEMO_PORTING_GUIDE.md +345 -345
  331. package/vendor/Server/Skills/rnoh-lib-rnt-search/references/PORT_VERIFICATION.md +269 -269
  332. package/vendor/Server/Skills/rnoh-lib-rnt-search/references/RNT_PROJECT_STRUCTURE.md +173 -173
  333. package/vendor/Server/Skills/rnoh-lib-rnt-search/scripts/analyze-demo-deps.cjs +267 -267
  334. package/vendor/Server/Skills/rnoh-lib-rnt-search/scripts/detect-rnoh-version.cjs +174 -174
  335. package/vendor/Server/Skills/rnoh-lib-rnt-search/scripts/find-rnt-demo.sh +111 -111
  336. package/vendor/Server/Skills/rnoh-lib-rnt-search/scripts/port-demo.sh +186 -186
  337. package/vendor/Server/Skills/rnoh-lib-rnt-search/scripts/read-lib-meta.cjs +150 -150
  338. package/vendor/Server/Skills/rnoh-lib-test-align/SKILL.md +296 -296
  339. package/vendor/Server/Skills/rnoh-lib-test-align/references/jest-troubleshooting.md +371 -371
  340. package/vendor/Server/Skills/rnoh-lib-test-align/references/port-test-demo-guide.md +212 -212
  341. package/vendor/Server/Skills/rnoh-lib-test-align/references/runtime-troubleshooting.md +345 -345
  342. package/vendor/Server/Skills/rnoh-lib-test-align/references/unit-test-template.md +223 -223
  343. package/vendor/Server/Skills/rnoh-lib-test-align/scripts/port-test-demo.sh +1053 -1053
  344. package/vendor/Server/Skills/rnoh-lib-version-diff/SKILL.md +295 -255
  345. package/vendor/Server/Skills/rnoh-lib-version-diff/references/OHOS_ADAPTATION.md +82 -77
  346. package/vendor/Server/Skills/rnoh-lib-version-diff/references/OHOS_API_LOOKUP.md +224 -224
  347. package/vendor/Server/Skills/rnoh-lib-version-diff/references/script-reference.md +175 -174
  348. package/vendor/Server/Skills/rnoh-lib-version-diff/scripts/detect-upstream-version.js +967 -967
  349. package/vendor/Server/Skills/rnoh-lib-version-diff/scripts/generate-diff.js +1798 -1798
  350. package/vendor/Server/Skills/rnoh-lib-version-diff/scripts/package.json +5 -5
  351. package/vendor/Server/Skills/rnoh-lib-version-diff/templates/report-template.md +180 -137
  352. package/vendor/Server/Skills/rnoh-lib-xts-coverage/SKILL.md +145 -145
  353. package/vendor/Server/Skills/skill-generator/SKILL.md +365 -365
  354. package/vendor/Server/Skills/skill-generator/assets/SKILL_TEMPLATE.md +183 -183
  355. package/vendor/Server/Skills/skill-generator/references/COMPLIANCE_CHECKLIST.md +82 -82
  356. package/vendor/Server/Skills/skill-generator/references/KB_QUERY_GUIDE.md +110 -110
  357. package/vendor/Server/Skills/skill-generator/references/MCP_TOOL_DISCOVERY.md +122 -122
  358. package/vendor/Server/Skills/skill-generator/references/SKILL_SPEC.md +121 -121
  359. package/vendor/Server/Skills/skill-generator/scripts/validate-skill.cjs +259 -259
  360. package/vendor/Server/Skills/task-analysis/SKILL.md +234 -234
  361. package/vendor/Server/Skills/task-analysis/assets/OUTPUT_EXAMPLES.md +160 -160
  362. package/vendor/Server/Skills/task-analysis/references/ACCEPTANCE_CRITERIA_GUIDE.md +190 -190
  363. package/vendor/Server/Skills/task-analysis/references/ANALYSIS_SCHEMA.md +224 -224
  364. package/vendor/Server/Skills/task-analysis/references/INTEGRATION_CONTEXT.md +162 -162
  365. package/vendor/Server/Skills/task-analysis/references/LESSONS_LEARNED.md +55 -55
  366. package/vendor/Server/Skills/task-analysis/references/REPLAN_CONTEXT_GUIDE.md +126 -126
  367. package/vendor/Server/Skills/task-analysis/scripts/validate-analysis-output.sh +256 -256
  368. package/vendor/Server/Skills/task-decomposition/SKILL.md +528 -528
  369. package/vendor/Server/Skills/task-decomposition/assets/OUTPUT_EXAMPLES.md +451 -451
  370. package/vendor/Server/Skills/task-decomposition/references/ACCEPTANCE_CRITERIA_GUIDE.md +179 -179
  371. package/vendor/Server/Skills/task-decomposition/references/DEPENDENCY_GRAPH_GUIDE.md +152 -152
  372. package/vendor/Server/Skills/task-decomposition/references/INTEGRATION_CONTEXT.md +175 -175
  373. package/vendor/Server/Skills/task-decomposition/references/REPLAN_CONTEXT_GUIDE.md +195 -195
  374. package/vendor/Server/Skills/task-decomposition/references/TASK_DECOMPOSITION_TEMPLATES.md +226 -226
  375. package/vendor/Server/Skills/task-decomposition/scripts/list-available-skills.cjs +263 -263
  376. package/vendor/Server/Skills/task-decomposition/scripts/skill-blacklist.json +29 -29
  377. package/vendor/Server/Skills/task-decomposition/scripts/validate-decomposition-output.cjs +376 -376
  378. package/vendor/Server/Skills/task-decomposition/scripts/validate-param-consistency.cjs +259 -259
  379. package/vendor/Server/Skills/task-decomposition/scripts/validate-specified-skills.cjs +216 -216
  380. package/vendor/Server/Skills/task-decomposition/scripts/validate-step-graph.cjs +424 -424
  381. package/vendor/Server/Skills/tpc-cpp-check/SKILL.md +427 -427
  382. package/vendor/Server/Skills/tpc-cpp-check/references/CHECKLIST.md +214 -214
  383. package/vendor/Server/Skills/tpc-cpp-check/references/HPKBUILD_GUIDE.md +235 -235
  384. package/vendor/Server/Skills/tpc-cpp-check/references/REPORT_TEMPLATE.md +250 -250
  385. package/vendor/Server/TestCheck/TestCheck.js +775 -775
  386. package/vendor/Server/TestCheck/index.js +11 -11
  387. package/vendor/Server/library/McpToolGuide.js +280 -280
  388. package/vendor/Server/library/StatsService.js +126 -126
  389. package/vendor/Server/library/cstTime.js +16 -16
  390. package/vendor/VERSION +3 -3
  391. package/workflows/pr-check.mjs +105 -105
  392. package/workflows/pr-push.mjs +192 -192
  393. package/vendor/Server/Agent/SkillSelector/types.js +0 -63
@@ -1,775 +1,775 @@
1
- /**
2
- * TestCheck —— 任务准出校验引擎
3
- *
4
- * 职责:
5
- * - 在 Orchestrator 所有步骤执行完成后,对最终产物进行验收审核
6
- * - 通过 Agent 选择合适的 SKILL,执行准出检查
7
- * - 对比 Brain 生成的任务级验收标准,判断是否满足准出条件
8
- * - 产出结构化的审核结论(通过/未通过 + 逐条标准评估 + 改进建议)
9
- * - 支持审核结果持久化,供 LoopEngine 决定是否触发大循环
10
- *
11
- * 架构角色(Loop Engineering 大循环):
12
- * Brain(拆解/重规划)→ Orchestrator(编排)→ FlexRunner(执行)→ TestCheck(准出审核)
13
- * │
14
- * 未通过 ──→ 回到 Brain 重新生成目标
15
- *
16
- * 设计原则:
17
- * - 高内聚:所有准出审核逻辑集中于此,不感知 HTTP 层和编排细节
18
- * - 低耦合:依赖注入 LLMClient / SkillSelector / CLIController / Storage
19
- * - 可扩展:审核策略通过 Skill 调用实现,新增审核能力只需新增 Skill
20
- * - 复用 FlexRunner 的执行模式(matchSkill → invokeSkill → checkResult)
21
- */
22
-
23
- import path from 'node:path';
24
- import { fileURLToPath } from 'node:url';
25
- import fs from 'node:fs/promises';
26
-
27
- import { LLMClient } from '../Agent/SkillSelector/llm/llmClient.js';
28
- import { nowCST } from '../library/cstTime.js';
29
- import { createStorage } from '../DbUse/index.js';
30
-
31
- // 惰性加载 FlexRunner 的依赖(CLIController / SkillSelectorAgent),
32
- // 与 FlexRunner 同样的惰性加载策略,避免测试时拉入重依赖。
33
- let _CLIController = null;
34
- let _SkillSelectorAgent = null;
35
-
36
- async function _loadCLIController() {
37
- if (!_CLIController) {
38
- const mod = await import('../CLI/cli.js');
39
- _CLIController = mod.CLIController;
40
- }
41
- return _CLIController;
42
- }
43
-
44
- async function _loadSkillSelectorAgent() {
45
- if (!_SkillSelectorAgent) {
46
- const mod = await import('../Agent/SkillSelector/index.js');
47
- _SkillSelectorAgent = mod.Agent;
48
- }
49
- return _SkillSelectorAgent;
50
- }
51
-
52
- // ─── 常量 ────────────────────────────────────────────────────────────────────
53
-
54
- /** TestCheck 审核状态 */
55
- export const CheckStatus = Object.freeze({
56
- IDLE: 'idle',
57
- MATCHING: 'matching', // 正在匹配审核 Skill
58
- EXECUTING: 'executing', // 正在执行审核
59
- EVALUATING: 'evaluating', // 正在评估准出条件
60
- PASSED: 'passed', // 准出通过
61
- FAILED: 'failed', // 准出未通过
62
- ERROR: 'error' // 审核过程出错
63
- });
64
-
65
- /** SSE 事件类型 */
66
- const SSE_EVENT = Object.freeze({
67
- CHECK_START: 'testcheck:start',
68
- CHECK_MATCH: 'testcheck:match',
69
- CHECK_EXECUTE: 'testcheck:execute',
70
- CHECK_EVALUATE: 'testcheck:evaluate',
71
- CHECK_RESULT: 'testcheck:result',
72
- CHECK_ERROR: 'testcheck:error'
73
- });
74
-
75
- /** 轮询间隔(ms),等待审核 Skill 执行完成 */
76
- const POLL_INTERVAL_MS = 3000;
77
-
78
- /** 轮询超时(ms),审核最多等待 30 分钟 */
79
- const POLL_TIMEOUT_MS = 30 * 60 * 1000;
80
-
81
- // ─── TestCheck 类 ────────────────────────────────────────────────────────────
82
-
83
- /**
84
- * TestCheck —— 准出审核引擎
85
- */
86
- class TestCheck {
87
- /**
88
- * @param {object} [deps] - 依赖注入
89
- * @param {LLMClient} [deps.llm] - LLM 客户端(复用 SkillSelector 的 LLMClient)
90
- * @param {object} [deps.storage] - 存储门面(createStorage() 返回值)
91
- * @param {object} [deps.sseHub] - SseHub 实例(可选,用于推送审核进度)
92
- * @param {object} [deps.cli] - CLIController 实例(可选,用于执行 Skill)
93
- * @param {object} [deps.skillSelector] - SkillSelectorAgent 实例(可选,用于匹配 Skill)
94
- * @param {string} [deps.skillDirectory] - SKILL 目录路径(默认 Server/Skills)
95
- */
96
- constructor(deps = {}) {
97
- this.llm = deps.llm || new LLMClient();
98
- this.storage = deps.storage || createStorage();
99
- this.sseHub = deps.sseHub || null;
100
- this.cli = deps.cli || null;
101
- this.skillSelector = deps.skillSelector || null;
102
-
103
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
104
- this.skillDirectory = deps.skillDirectory ||
105
- path.resolve(__dirname, '..', 'Skills');
106
-
107
- /** @type {CheckStatus} */
108
- this._status = CheckStatus.IDLE;
109
- }
110
-
111
- // ─── 属性访问 ──────────────────────────────────────────────────────
112
-
113
- /** @returns {CheckStatus} */
114
- get status() {
115
- return this._status;
116
- }
117
-
118
- // ─── SSE 推送辅助 ──────────────────────────────────────────────────
119
-
120
- /**
121
- * 推送审核进度事件。
122
- * @param {string} channel - SSE 频道(通常为 taskId)
123
- * @param {string} eventType - 事件类型
124
- * @param {object} data - 事件数据
125
- * @private
126
- */
127
- _emit(channel, eventType, data) {
128
- if (this.sseHub) {
129
- this.sseHub.emit(channel, eventType, data);
130
- }
131
- }
132
-
133
- // ─── 惰性加载依赖 ──────────────────────────────────────────────────
134
-
135
- /**
136
- * 获取 CLIController 实例(懒加载)。
137
- * @returns {Promise<object>}
138
- * @private
139
- */
140
- async _getCli() {
141
- if (!this.cli) {
142
- const CLIController = await _loadCLIController();
143
- this.cli = new CLIController();
144
- }
145
- return this.cli;
146
- }
147
-
148
- /**
149
- * 获取 SkillSelectorAgent 实例(懒加载)。
150
- * @returns {Promise<object>}
151
- * @private
152
- */
153
- async _getSkillSelector() {
154
- if (!this.skillSelector) {
155
- const SkillSelectorAgent = await _loadSkillSelectorAgent();
156
- this.skillSelector = new SkillSelectorAgent();
157
- }
158
- return this.skillSelector;
159
- }
160
-
161
- // ─── 核心方法 ──────────────────────────────────────────────────────
162
-
163
- /**
164
- * 执行准出审核 — 对任务最终产物进行验收检查。
165
- *
166
- * 流程:
167
- * 1. MATCHING — 基于"准出审核"语义匹配最佳审核 Skill
168
- * 2. EXECUTING — 通过 CLI 执行审核 Skill,生成审核报告文件
169
- * 3. EVALUATING — LLM 评估审核报告,逐条判断验收标准是否满足
170
- * 4. 产出 CheckResult(通过/未通过 + 逐条评估 + 改进建议)
171
- *
172
- * @param {object} params - 审核参数
173
- * @param {string} params.taskId - 任务 ID(必填)
174
- * @param {string} params.taskDir - 工作目录
175
- * @param {string} [params.taskDescription] - 原始任务描述
176
- * @param {Array} [params.acceptanceCriteria] - 任务级验收标准(Brain 生成)
177
- * @param {object} [params.orchestratorResult] - Orchestrator 执行结果摘要
178
- * @param {number} [params.loopCount=0] - 当前大循环次数
179
- * @param {string} [params.skillDirectory] - 覆盖 SKILL 目录
180
- * @param {() => boolean} [params.isAborted] - 终止信号回调(返回 true 时审核轮询抛终止退出)
181
- * @param {(sessionId: string) => void} [params.onSessionCreated] - Session 创建回调(供上层登记远程中止)
182
- * @returns {Promise<CheckResult>}
183
- */
184
- async runCheck(params = {}) {
185
- const {
186
- taskId,
187
- taskDir,
188
- taskDescription = '',
189
- acceptanceCriteria = [],
190
- orchestratorResult = null,
191
- loopCount = 0,
192
- isAborted = null,
193
- onSessionCreated = null
194
- } = params;
195
-
196
- // 终止信号:审核过程中各环节检查,置位时抛终止退出
197
- const abortSignal = {
198
- isAborted: typeof isAborted === 'function' ? isAborted : null,
199
- onSessionCreated: typeof onSessionCreated === 'function' ? onSessionCreated : null
200
- };
201
-
202
- if (!taskId) {
203
- throw new Error('TestCheck.runCheck: taskId 为必填项');
204
- }
205
-
206
- const skillDir = params.skillDirectory || this.skillDirectory;
207
- const workDir = taskDir || path.resolve(this.storage.manager.rootDir, 'task', taskId);
208
-
209
- const channel = taskId;
210
- const checkId = _generateCheckId(taskId, loopCount);
211
- const startTime = nowCST();
212
-
213
- this._status = CheckStatus.MATCHING;
214
- this._emit(channel, SSE_EVENT.CHECK_START, {
215
- checkId, taskId, loopCount, startTime,
216
- acceptanceCriteriaCount: acceptanceCriteria.length
217
- });
218
-
219
- /** @type {CheckResult} */
220
- const result = {
221
- checkId,
222
- taskId,
223
- loopCount,
224
- taskDescription,
225
- acceptanceCriteria,
226
- orchestratorResult,
227
- startTime,
228
- endTime: null,
229
- status: CheckStatus.IDLE,
230
- passed: false,
231
- matchedSkillDir: '',
232
- checkReportPath: '',
233
- sessionId: '',
234
- criteriaResults: [],
235
- summary: '',
236
- improvementSuggestions: [],
237
- error: null
238
- };
239
-
240
- try {
241
- // ─── 步骤 1:匹配审核 Skill ───
242
- const checkTaskDescription = this._buildCheckTaskDescription(
243
- taskDescription, acceptanceCriteria, orchestratorResult
244
- );
245
-
246
- this._status = CheckStatus.MATCHING;
247
- const matchedSkillDir = await this._matchSkill(checkTaskDescription, skillDir);
248
- result.matchedSkillDir = matchedSkillDir;
249
- this._emit(channel, SSE_EVENT.CHECK_MATCH, { checkId, matchedSkillDir });
250
-
251
- // ─── 步骤 2:执行审核 Skill ───
252
- this._status = CheckStatus.EXECUTING;
253
- const reportPath = path.join(workDir, `testcheck_loop${loopCount}_result.md`);
254
- const summaryPath = path.join(workDir, `testcheck_loop${loopCount}_Summary.md`);
255
-
256
- const { sessionId, executed } = await this._invokeSkill({
257
- taskDescription: checkTaskDescription,
258
- skillDir: matchedSkillDir,
259
- reportPath,
260
- summaryPath,
261
- workDir,
262
- loopCount,
263
- abortSignal
264
- });
265
-
266
- result.sessionId = sessionId;
267
- result.checkReportPath = reportPath;
268
- this._emit(channel, SSE_EVENT.CHECK_EXECUTE, { checkId, sessionId, reportPath, executed });
269
-
270
- if (!executed) {
271
- throw new Error('审核 Skill 执行失败,未生成审核报告');
272
- }
273
-
274
- // ─── 步骤 3:评估准出条件 ───
275
- this._status = CheckStatus.EVALUATING;
276
- const evaluation = await this._evaluateAcceptance({
277
- reportPath,
278
- acceptanceCriteria,
279
- taskDescription,
280
- orchestratorResult,
281
- loopCount
282
- });
283
-
284
- result.criteriaResults = evaluation.criteriaResults;
285
- result.passed = evaluation.passed;
286
- result.summary = evaluation.summary;
287
- result.improvementSuggestions = evaluation.improvementSuggestions;
288
- result.status = evaluation.passed ? CheckStatus.PASSED : CheckStatus.FAILED;
289
-
290
- this._emit(channel, SSE_EVENT.CHECK_EVALUATE, {
291
- checkId,
292
- passed: result.passed,
293
- criteriaResults: result.criteriaResults
294
- });
295
-
296
- } catch (err) {
297
- result.status = CheckStatus.ERROR;
298
- result.error = err.message;
299
- this._status = CheckStatus.ERROR;
300
- this._emit(channel, SSE_EVENT.CHECK_ERROR, { checkId, error: err.message });
301
- this._log('error', `审核异常: ${err.message}`);
302
- }
303
-
304
- result.endTime = nowCST();
305
- this._status = result.status;
306
-
307
- // ─── 持久化审核结果 ───
308
- await this._persistCheckResult(taskId, result);
309
-
310
- this._emit(channel, SSE_EVENT.CHECK_RESULT, {
311
- checkId,
312
- passed: result.passed,
313
- status: result.status,
314
- summary: result.summary
315
- });
316
-
317
- this._log('info', `── 准出审核结束: passed=${result.passed}, loop=${loopCount} ──`);
318
- return result;
319
- }
320
-
321
- // ─── 内部:Skill 匹配 ──────────────────────────────────────────────
322
-
323
- /**
324
- * 匹配审核 Skill — 基于准出审核语义选择最佳 Skill。
325
- *
326
- * @param {string} checkTaskDescription - 审核任务描述
327
- * @param {string} skillDirectory - SKILL 目录
328
- * @returns {Promise<string>} 匹配到的 SKILL 目录绝对路径
329
- * @private
330
- */
331
- async _matchSkill(checkTaskDescription, skillDirectory) {
332
- if (!checkTaskDescription) {
333
- throw new Error('TestCheck._matchSkill: 审核任务描述不能为空');
334
- }
335
- if (!skillDirectory) {
336
- throw new Error('TestCheck._matchSkill: skillDirectory 不能为空');
337
- }
338
-
339
- this._log('info', `matchSkill 开始 — 审核任务: "${checkTaskDescription.slice(0, 80)}…"`);
340
-
341
- const selector = await this._getSkillSelector();
342
- const selection = await selector.selectSkill(checkTaskDescription, skillDirectory);
343
-
344
- if (!selection || !selection.best) {
345
- throw new Error('TestCheck._matchSkill: 未匹配到任何合适的审核 Skill');
346
- }
347
-
348
- const bestDir = selection.skillPath || selection.best.skillPath;
349
- if (!bestDir) {
350
- throw new Error('TestCheck._matchSkill: 匹配结果缺少 Skill 目录路径');
351
- }
352
-
353
- this._log('info', `matchSkill 完成 — 最佳审核 Skill: ${selection.best.name} (${bestDir})`);
354
- return bestDir;
355
- }
356
-
357
- /**
358
- * 构建准出审核的任务描述 — 供 Skill 匹配器使用。
359
- *
360
- * @param {string} taskDescription - 原始任务描述
361
- * @param {Array} acceptanceCriteria - 验收标准
362
- * @param {object} orchestratorResult - 编排结果
363
- * @returns {string}
364
- * @private
365
- */
366
- _buildCheckTaskDescription(taskDescription, acceptanceCriteria, orchestratorResult) {
367
- const parts = [
368
- '对任务执行结果进行准出审核(验收测试)',
369
- `原始任务: ${taskDescription}`
370
- ];
371
-
372
- if (acceptanceCriteria && acceptanceCriteria.length > 0) {
373
- const criteriaText = acceptanceCriteria
374
- .map(c => `- [${c.id}] (${c.type}) ${c.criterion}`)
375
- .join('\n');
376
- parts.push(`验收标准:\n${criteriaText}`);
377
- }
378
-
379
- if (orchestratorResult) {
380
- parts.push(`编排状态: ${orchestratorResult.status || 'unknown'}`);
381
- if (orchestratorResult.stats) {
382
- parts.push(`步骤统计: ${JSON.stringify(orchestratorResult.stats)}`);
383
- }
384
- }
385
-
386
- parts.push('检查任务产物是否满足所有验收标准,生成准出审核报告');
387
- return parts.join('\n');
388
- }
389
-
390
- // ─── 内部:Skill 执行 ──────────────────────────────────────────────
391
-
392
- /**
393
- * 调用 CLI 执行审核 Skill。
394
- *
395
- * 流程:
396
- * 1. 健康检查
397
- * 2. 构建 prompt(任务描述 + 验收标准 + 产物路径 + 报告路径)
398
- * 3. 创建 Session 并发送 prompt
399
- * 4. 轮询等待完成
400
- *
401
- * @param {object} opts
402
- * @param {string} opts.taskDescription
403
- * @param {string} opts.skillDir
404
- * @param {string} opts.reportPath
405
- * @param {string} opts.summaryPath
406
- * @param {string} opts.workDir
407
- * @param {number} opts.loopCount
408
- * @param {object} [opts.abortSignal] - 终止信号 { isAborted, onSessionCreated }(LoopEngine 注入)
409
- * @returns {Promise<{sessionId: string, executed: boolean}>}
410
- * @private
411
- */
412
- async _invokeSkill({ taskDescription, skillDir, reportPath, summaryPath, workDir, loopCount, abortSignal }) {
413
- const cli = await this._getCli();
414
-
415
- this._log('info', `invokeSkill 开始 — skillDir: ${skillDir}`);
416
-
417
- // 健康检查
418
- const health = await cli.checkHealth();
419
- if (health.status !== 'ok') {
420
- this._log('error', `CLI(${cli.getType()}) 服务不可用: ${health.message}`);
421
- return { sessionId: '', executed: false };
422
- }
423
-
424
- // 构建 prompt
425
- const title = `testcheck|task=${workDir.split('/').pop()}|loop=${loopCount}`;
426
- const prompt = this._buildPrompt(taskDescription, skillDir, reportPath, summaryPath, workDir);
427
-
428
- // 创建 Session(指定工作目录为 workDir,确保 opencode session 的文件操作在任务目录下执行)
429
- // const { sessionId } = await cli.startSession(title, prompt, { cwd: workDir });
430
- const { sessionId } = await cli.startSession(title, prompt);
431
- this._log('info', `审核 Session 已创建: ${sessionId}`);
432
-
433
- // 通知上层登记 sessionId(abortLoop 可据此远程中止)
434
- if (abortSignal && typeof abortSignal.onSessionCreated === 'function') {
435
- try {
436
- abortSignal.onSessionCreated(sessionId);
437
- } catch { /* 回调异常不影响主流程 */ }
438
- }
439
-
440
- // Session 创建后终止标志已置位 → 立即中止并退出
441
- if (abortSignal && typeof abortSignal.isAborted === 'function' && abortSignal.isAborted()) {
442
- try {
443
- await cli.abortSession(sessionId);
444
- } catch { /* 已自然结束 */ }
445
- throw new Error('审核被终止(Session 创建后即中止)');
446
- }
447
-
448
- // 轮询等待完成
449
- const completed = await this._pollSession(cli, sessionId, abortSignal);
450
- if (!completed) {
451
- this._log('warn', `审核 Session ${sessionId} 未在超时时间内完成`);
452
- }
453
-
454
- this._log('info', `invokeSkill 完成 — sessionId: ${sessionId}, completed: ${completed}`);
455
- return { sessionId, executed: completed };
456
- }
457
-
458
- /**
459
- * 构建审核 prompt。
460
- *
461
- * @param {string} taskDescription
462
- * @param {string} skillDir
463
- * @param {string} reportPath
464
- * @param {string} summaryPath
465
- * @param {string} workDir
466
- * @returns {string}
467
- * @private
468
- */
469
- _buildPrompt(taskDescription, skillDir, reportPath, summaryPath, workDir) {
470
- const parts = [
471
- `## 审核任务描述\n${taskDescription}`,
472
- `## SKILL 目录\n${skillDir}`,
473
- `## 工作目录\n${workDir}`,
474
- `## 审核报告输出路径\n${reportPath}`,
475
- `## 审核摘要输出路径\n${summaryPath}`,
476
- '请按照 SKILL 中的指令执行准出审核任务。',
477
- '审核完成后,请将审核结果写入上述"审核报告输出路径",并在"审核摘要输出路径"写入摘要。',
478
- '审核报告需包含 `## 准出结论` 字段(值为 `通过` 或 `未通过`),用于判断审核结果。',
479
- '审核报告需逐条列出每个验收标准的评估结论(满足/未满足)及证据。'
480
- ];
481
- return parts.join('\n\n');
482
- }
483
-
484
- /**
485
- * 轮询 Session 状态直到完成或超时。
486
- *
487
- * @param {object} cli - CLIController 实例
488
- * @param {string} sessionId - 会话 ID
489
- * @param {object} [abortSignal] - 终止信号 { isAborted: () => boolean };
490
- * 置位时在下一轮询周期远程中止 session 并抛终止退出
491
- * @returns {Promise<boolean>}
492
- * @private
493
- */
494
- async _pollSession(cli, sessionId, abortSignal = null) {
495
- const deadline = Date.now() + POLL_TIMEOUT_MS;
496
-
497
- while (Date.now() < deadline) {
498
- // 终止检查:比超时检查优先,确保终止请求即时生效
499
- if (abortSignal && typeof abortSignal.isAborted === 'function' && abortSignal.isAborted()) {
500
- try {
501
- await cli.abortSession(sessionId);
502
- } catch { /* 已自然结束 */ }
503
- this._log('warn', `审核 Session ${sessionId} 被终止`);
504
- throw new Error('审核被终止');
505
- }
506
-
507
- await this._sleep(POLL_INTERVAL_MS);
508
- try {
509
- const { status } = await cli.checkSessionStatus(sessionId);
510
- if (status === 'completed') {
511
- return true;
512
- }
513
- } catch (err) {
514
- this._log('warn', `轮询审核 Session 状态失败: ${err.message}`);
515
- }
516
- }
517
- return false;
518
- }
519
-
520
- // ─── 内部:准出评估 ────────────────────────────────────────────────
521
-
522
- /**
523
- * 评估准出条件 — LLM 审核报告对照验收标准逐条判断。
524
- *
525
- * 读取审核报告文件,调用 LLM 对照任务级验收标准进行结构化评估:
526
- * - 逐条判断每个验收标准是否满足
527
- * - 汇总结论(全部满足=通过,任一未满足=未通过)
528
- * - 生成改进建议(未通过时)
529
- *
530
- * @param {object} opts
531
- * @param {string} opts.reportPath - 审核报告文件路径
532
- * @param {Array} opts.acceptanceCriteria - 任务级验收标准
533
- * @param {string} opts.taskDescription - 原始任务描述
534
- * @param {object} opts.orchestratorResult - 编排结果
535
- * @param {number} opts.loopCount - 当前循环次数
536
- * @returns {Promise<{passed: boolean, criteriaResults: Array, summary: string, improvementSuggestions: Array}>}
537
- * @private
538
- */
539
- async _evaluateAcceptance({ reportPath, acceptanceCriteria, taskDescription, loopCount }) {
540
- // 读取审核报告
541
- let reportContent = '';
542
- try {
543
- reportContent = await fs.readFile(reportPath, 'utf-8');
544
- } catch (err) {
545
- this._log('warn', `读取审核报告失败: ${reportPath} — ${err.message}`);
546
- // 报告不存在时,仍尝试基于验收标准做基本评估
547
- }
548
-
549
- // 快速检查:报告中是否包含明确的准出结论
550
- const quickMatch = reportContent.match(/##\s*准出结论\s*\n\s*(通过|未通过)/i);
551
- if (quickMatch) {
552
- const quickPassed = quickMatch[1] === '通过';
553
- this._log('info', `快速判断准出结论: ${quickMatch[1]}`);
554
- // 仍调用 LLM 做详细评估,但快速结论作为 fallback
555
- const fallback = {
556
- passed: quickPassed,
557
- criteriaResults: acceptanceCriteria.map(c => ({
558
- id: c.id,
559
- criterion: c.criterion,
560
- satisfied: quickPassed,
561
- evidence: '基于审核报告准出结论',
562
- note: quickPassed ? '满足' : '未满足'
563
- })),
564
- summary: quickPassed ? '所有验收标准已满足' : '存在未满足的验收标准',
565
- improvementSuggestions: quickPassed ? [] : ['请根据审核报告中的问题进行修复']
566
- };
567
-
568
- // 尝试 LLM 详细评估,失败则用 fallback
569
- try {
570
- return await this._llmEvaluate(reportContent, acceptanceCriteria, taskDescription, loopCount);
571
- } catch (err) {
572
- this._log('warn', `LLM 评估失败,使用快速判断 fallback: ${err.message}`);
573
- return fallback;
574
- }
575
- }
576
-
577
- // 无快速结论时,直接调用 LLM 评估
578
- return await this._llmEvaluate(reportContent, acceptanceCriteria, taskDescription, loopCount);
579
- }
580
-
581
- /**
582
- * 调用 LLM 进行结构化准出评估。
583
- *
584
- * @param {string} reportContent - 审核报告内容
585
- * @param {Array} acceptanceCriteria - 验收标准
586
- * @param {string} taskDescription - 任务描述
587
- * @param {number} loopCount - 循环次数
588
- * @returns {Promise<{passed: boolean, criteriaResults: Array, summary: string, improvementSuggestions: Array}>}
589
- * @private
590
- */
591
- async _llmEvaluate(reportContent, acceptanceCriteria, taskDescription, loopCount) {
592
- const criteriaText = (acceptanceCriteria || [])
593
- .map(c => `- [${c.id}] (${c.type}) ${c.criterion}\n 验证方式: ${c.verification}`)
594
- .join('\n');
595
-
596
- const prompt = `你是一个准出审核专家。请根据审核报告内容,逐条评估任务级验收标准是否满足。
597
-
598
- ## 原始任务描述
599
- ${taskDescription || '(未提供)'}
600
-
601
- ## 任务级验收标准
602
- ${criteriaText || '(未提供验收标准,请根据审核报告整体判断)'}
603
-
604
- ## 审核报告内容
605
- ${reportContent || '(审核报告为空,无法判断)'}
606
-
607
- ## 当前循环次数
608
- 第 ${loopCount + 1} 次循环
609
-
610
- ## 输出要求
611
- 请以 JSON 格式返回,包含以下字段:
612
- {
613
- "passed": true/false,
614
- "criteriaResults": [
615
- {
616
- "id": "ac1",
617
- "criterion": "验收标准描述",
618
- "satisfied": true/false,
619
- "evidence": "审核报告中支持该结论的证据或分析",
620
- "note": "补充说明"
621
- }
622
- ],
623
- "summary": "整体审核结论摘要(一段话)",
624
- "improvementSuggestions": [
625
- "针对未满足标准的改进建议(仅在未通过时提供)"
626
- ]
627
- }
628
-
629
- ### 评估规则
630
- 1. 如果审核报告为空或无法获取有效信息,passed 应为 false
631
- 2. criteriaResults 必须覆盖所有任务级验收标准
632
- 3. 每条标准的 satisfied 字段必须基于审核报告中的证据
633
- 4. 如果所有标准都 satisfied=true,则 passed=true
634
- 5. 如果任一标准 satisfied=false,则 passed=false
635
- 6. improvementSuggestions 仅在 passed=false 时提供,针对未满足的标准给出具体改进建议
636
- 7. summary 应概括整体审核结论,包括通过/未通过的原因
637
-
638
- 注意:只返回 JSON,不要包含其他文字。`;
639
-
640
- const result = await this.llm.chatJSON(prompt, { maxTokens: 4096 });
641
-
642
- return {
643
- passed: Boolean(result.passed),
644
- criteriaResults: Array.isArray(result.criteriaResults)
645
- ? result.criteriaResults.map((c, idx) => ({
646
- id: c.id || (acceptanceCriteria[idx] ? acceptanceCriteria[idx].id : `ac${idx + 1}`),
647
- criterion: c.criterion || (acceptanceCriteria[idx] ? acceptanceCriteria[idx].criterion : ''),
648
- satisfied: Boolean(c.satisfied),
649
- evidence: c.evidence || '',
650
- note: c.note || ''
651
- }))
652
- : [],
653
- summary: result.summary || (result.passed ? '审核通过' : '审核未通过'),
654
- improvementSuggestions: Array.isArray(result.improvementSuggestions)
655
- ? result.improvementSuggestions
656
- : []
657
- };
658
- }
659
-
660
- // ─── 内部:持久化 ──────────────────────────────────────────────────
661
-
662
- /**
663
- * 持久化审核结果到文件系统。
664
- *
665
- * 文件路径:db/task/{taskId}/testcheck_loop{loopCount}.json
666
- *
667
- * 与 Brain / Orchestrator 的持久化目录结构保持一致:
668
- * db/task/{taskId}/
669
- * ├── brain.json ← Brain 拆解计划(最新快照)
670
- * ├── brain_loop0.json ← 各轮 Brain 计划
671
- * ├── orchestration.json ← Orchestrator 编排状态(最新快照)
672
- * ├── orchestration_loop0.json ← 各轮编排状态
673
- * ├── stepid_1_loop0.json ← 各轮步骤执行记录
674
- * ├── testcheck_loop0.json ← 第 0 次循环准出审核(本方法写入)
675
- * ├── testcheck_loop1.json ← 第 1 次循环准出审核
676
- * └── ...
677
- *
678
- * @param {string} taskId
679
- * @param {CheckResult} result
680
- * @private
681
- */
682
- async _persistCheckResult(taskId, result) {
683
- try {
684
- const json = this.storage.json('task');
685
- await json.write(`${taskId}/testcheck_loop${result.loopCount}`, result);
686
- this._log('info', `审核结果已持久化: db/task/${taskId}/testcheck_loop${result.loopCount}.json`);
687
- } catch (err) {
688
- this._log('warn', `持久化审核结果失败: ${err.message}`);
689
- }
690
- }
691
-
692
- /**
693
- * 从文件系统加载历史审核结果。
694
- *
695
- * @param {string} taskId
696
- * @param {number} loopCount
697
- * @returns {Promise<CheckResult|null>}
698
- */
699
- async loadCheckResult(taskId, loopCount) {
700
- try {
701
- const json = this.storage.json('task');
702
- return await json.read(`${taskId}/testcheck_loop${loopCount}`);
703
- } catch {
704
- return null;
705
- }
706
- }
707
-
708
- /**
709
- * 列出某个 Task 下所有审核结果。
710
- *
711
- * @param {string} taskId
712
- * @returns {Promise<Array>}
713
- */
714
- async listCheckResults(taskId) {
715
- try {
716
- const json = this.storage.json('task');
717
- const entries = await json.list(`${taskId}/testcheck_loop`);
718
- return entries
719
- .filter(e => e && e.data)
720
- .map(e => e.data)
721
- .sort((a, b) => (a.loopCount || 0) - (b.loopCount || 0));
722
- } catch {
723
- return [];
724
- }
725
- }
726
-
727
- // ─── 内部工具 ──────────────────────────────────────────────────────
728
-
729
- /**
730
- * Promise 版 sleep。
731
- * @param {number} ms
732
- * @returns {Promise<void>}
733
- * @private
734
- */
735
- _sleep(ms) {
736
- return new Promise((resolve) => setTimeout(resolve, ms));
737
- }
738
-
739
- /**
740
- * 统一日志输出。
741
- * @param {'info'|'warn'|'error'} level
742
- * @param {string} message
743
- * @private
744
- */
745
- _log(level, message) {
746
- const prefix = '[TestCheck]';
747
- const ts = nowCST();
748
- switch (level) {
749
- case 'error':
750
- console.error(`${ts} ${prefix} ❌ ${message}`);
751
- break;
752
- case 'warn':
753
- console.warn(`${ts} ${prefix} ⚠ ${message}`);
754
- break;
755
- default:
756
- console.info(`${ts} ${prefix} ℹ ${message}`);
757
- }
758
- }
759
- }
760
-
761
- // ─── 辅助函数 ──────────────────────────────────────────────────────────────
762
-
763
- /**
764
- * 生成 checkId。
765
- * @param {string} taskId
766
- * @param {number} loopCount
767
- * @returns {string}
768
- */
769
- function _generateCheckId(taskId, loopCount) {
770
- const ts = Date.now().toString(36);
771
- return `check_${taskId}_loop${loopCount}_${ts}`;
772
- }
773
-
774
- export { TestCheck };
775
- export default TestCheck;
1
+ /**
2
+ * TestCheck —— 任务准出校验引擎
3
+ *
4
+ * 职责:
5
+ * - 在 Orchestrator 所有步骤执行完成后,对最终产物进行验收审核
6
+ * - 通过 Agent 选择合适的 SKILL,执行准出检查
7
+ * - 对比 Brain 生成的任务级验收标准,判断是否满足准出条件
8
+ * - 产出结构化的审核结论(通过/未通过 + 逐条标准评估 + 改进建议)
9
+ * - 支持审核结果持久化,供 LoopEngine 决定是否触发大循环
10
+ *
11
+ * 架构角色(Loop Engineering 大循环):
12
+ * Brain(拆解/重规划)→ Orchestrator(编排)→ FlexRunner(执行)→ TestCheck(准出审核)
13
+ * │
14
+ * 未通过 ──→ 回到 Brain 重新生成目标
15
+ *
16
+ * 设计原则:
17
+ * - 高内聚:所有准出审核逻辑集中于此,不感知 HTTP 层和编排细节
18
+ * - 低耦合:依赖注入 LLMClient / SkillSelector / CLIController / Storage
19
+ * - 可扩展:审核策略通过 Skill 调用实现,新增审核能力只需新增 Skill
20
+ * - 复用 FlexRunner 的执行模式(matchSkill → invokeSkill → checkResult)
21
+ */
22
+
23
+ import path from 'node:path';
24
+ import { fileURLToPath } from 'node:url';
25
+ import fs from 'node:fs/promises';
26
+
27
+ import { LLMClient } from '../Agent/SkillSelector/llm/llmClient.js';
28
+ import { nowCST } from '../library/cstTime.js';
29
+ import { createStorage } from '../DbUse/index.js';
30
+
31
+ // 惰性加载 FlexRunner 的依赖(CLIController / SkillSelectorAgent),
32
+ // 与 FlexRunner 同样的惰性加载策略,避免测试时拉入重依赖。
33
+ let _CLIController = null;
34
+ let _SkillSelectorAgent = null;
35
+
36
+ async function _loadCLIController() {
37
+ if (!_CLIController) {
38
+ const mod = await import('../CLI/cli.js');
39
+ _CLIController = mod.CLIController;
40
+ }
41
+ return _CLIController;
42
+ }
43
+
44
+ async function _loadSkillSelectorAgent() {
45
+ if (!_SkillSelectorAgent) {
46
+ const mod = await import('../Agent/SkillSelector/index.js');
47
+ _SkillSelectorAgent = mod.Agent;
48
+ }
49
+ return _SkillSelectorAgent;
50
+ }
51
+
52
+ // ─── 常量 ────────────────────────────────────────────────────────────────────
53
+
54
+ /** TestCheck 审核状态 */
55
+ export const CheckStatus = Object.freeze({
56
+ IDLE: 'idle',
57
+ MATCHING: 'matching', // 正在匹配审核 Skill
58
+ EXECUTING: 'executing', // 正在执行审核
59
+ EVALUATING: 'evaluating', // 正在评估准出条件
60
+ PASSED: 'passed', // 准出通过
61
+ FAILED: 'failed', // 准出未通过
62
+ ERROR: 'error' // 审核过程出错
63
+ });
64
+
65
+ /** SSE 事件类型 */
66
+ const SSE_EVENT = Object.freeze({
67
+ CHECK_START: 'testcheck:start',
68
+ CHECK_MATCH: 'testcheck:match',
69
+ CHECK_EXECUTE: 'testcheck:execute',
70
+ CHECK_EVALUATE: 'testcheck:evaluate',
71
+ CHECK_RESULT: 'testcheck:result',
72
+ CHECK_ERROR: 'testcheck:error'
73
+ });
74
+
75
+ /** 轮询间隔(ms),等待审核 Skill 执行完成 */
76
+ const POLL_INTERVAL_MS = 3000;
77
+
78
+ /** 轮询超时(ms),审核最多等待 30 分钟 */
79
+ const POLL_TIMEOUT_MS = 30 * 60 * 1000;
80
+
81
+ // ─── TestCheck 类 ────────────────────────────────────────────────────────────
82
+
83
+ /**
84
+ * TestCheck —— 准出审核引擎
85
+ */
86
+ class TestCheck {
87
+ /**
88
+ * @param {object} [deps] - 依赖注入
89
+ * @param {LLMClient} [deps.llm] - LLM 客户端(复用 SkillSelector 的 LLMClient)
90
+ * @param {object} [deps.storage] - 存储门面(createStorage() 返回值)
91
+ * @param {object} [deps.sseHub] - SseHub 实例(可选,用于推送审核进度)
92
+ * @param {object} [deps.cli] - CLIController 实例(可选,用于执行 Skill)
93
+ * @param {object} [deps.skillSelector] - SkillSelectorAgent 实例(可选,用于匹配 Skill)
94
+ * @param {string} [deps.skillDirectory] - SKILL 目录路径(默认 Server/Skills)
95
+ */
96
+ constructor(deps = {}) {
97
+ this.llm = deps.llm || new LLMClient();
98
+ this.storage = deps.storage || createStorage();
99
+ this.sseHub = deps.sseHub || null;
100
+ this.cli = deps.cli || null;
101
+ this.skillSelector = deps.skillSelector || null;
102
+
103
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
104
+ this.skillDirectory = deps.skillDirectory ||
105
+ path.resolve(__dirname, '..', 'Skills');
106
+
107
+ /** @type {CheckStatus} */
108
+ this._status = CheckStatus.IDLE;
109
+ }
110
+
111
+ // ─── 属性访问 ──────────────────────────────────────────────────────
112
+
113
+ /** @returns {CheckStatus} */
114
+ get status() {
115
+ return this._status;
116
+ }
117
+
118
+ // ─── SSE 推送辅助 ──────────────────────────────────────────────────
119
+
120
+ /**
121
+ * 推送审核进度事件。
122
+ * @param {string} channel - SSE 频道(通常为 taskId)
123
+ * @param {string} eventType - 事件类型
124
+ * @param {object} data - 事件数据
125
+ * @private
126
+ */
127
+ _emit(channel, eventType, data) {
128
+ if (this.sseHub) {
129
+ this.sseHub.emit(channel, eventType, data);
130
+ }
131
+ }
132
+
133
+ // ─── 惰性加载依赖 ──────────────────────────────────────────────────
134
+
135
+ /**
136
+ * 获取 CLIController 实例(懒加载)。
137
+ * @returns {Promise<object>}
138
+ * @private
139
+ */
140
+ async _getCli() {
141
+ if (!this.cli) {
142
+ const CLIController = await _loadCLIController();
143
+ this.cli = new CLIController();
144
+ }
145
+ return this.cli;
146
+ }
147
+
148
+ /**
149
+ * 获取 SkillSelectorAgent 实例(懒加载)。
150
+ * @returns {Promise<object>}
151
+ * @private
152
+ */
153
+ async _getSkillSelector() {
154
+ if (!this.skillSelector) {
155
+ const SkillSelectorAgent = await _loadSkillSelectorAgent();
156
+ this.skillSelector = new SkillSelectorAgent();
157
+ }
158
+ return this.skillSelector;
159
+ }
160
+
161
+ // ─── 核心方法 ──────────────────────────────────────────────────────
162
+
163
+ /**
164
+ * 执行准出审核 — 对任务最终产物进行验收检查。
165
+ *
166
+ * 流程:
167
+ * 1. MATCHING — 基于"准出审核"语义匹配最佳审核 Skill
168
+ * 2. EXECUTING — 通过 CLI 执行审核 Skill,生成审核报告文件
169
+ * 3. EVALUATING — LLM 评估审核报告,逐条判断验收标准是否满足
170
+ * 4. 产出 CheckResult(通过/未通过 + 逐条评估 + 改进建议)
171
+ *
172
+ * @param {object} params - 审核参数
173
+ * @param {string} params.taskId - 任务 ID(必填)
174
+ * @param {string} params.taskDir - 工作目录
175
+ * @param {string} [params.taskDescription] - 原始任务描述
176
+ * @param {Array} [params.acceptanceCriteria] - 任务级验收标准(Brain 生成)
177
+ * @param {object} [params.orchestratorResult] - Orchestrator 执行结果摘要
178
+ * @param {number} [params.loopCount=0] - 当前大循环次数
179
+ * @param {string} [params.skillDirectory] - 覆盖 SKILL 目录
180
+ * @param {() => boolean} [params.isAborted] - 终止信号回调(返回 true 时审核轮询抛终止退出)
181
+ * @param {(sessionId: string) => void} [params.onSessionCreated] - Session 创建回调(供上层登记远程中止)
182
+ * @returns {Promise<CheckResult>}
183
+ */
184
+ async runCheck(params = {}) {
185
+ const {
186
+ taskId,
187
+ taskDir,
188
+ taskDescription = '',
189
+ acceptanceCriteria = [],
190
+ orchestratorResult = null,
191
+ loopCount = 0,
192
+ isAborted = null,
193
+ onSessionCreated = null
194
+ } = params;
195
+
196
+ // 终止信号:审核过程中各环节检查,置位时抛终止退出
197
+ const abortSignal = {
198
+ isAborted: typeof isAborted === 'function' ? isAborted : null,
199
+ onSessionCreated: typeof onSessionCreated === 'function' ? onSessionCreated : null
200
+ };
201
+
202
+ if (!taskId) {
203
+ throw new Error('TestCheck.runCheck: taskId 为必填项');
204
+ }
205
+
206
+ const skillDir = params.skillDirectory || this.skillDirectory;
207
+ const workDir = taskDir || path.resolve(this.storage.manager.rootDir, 'task', taskId);
208
+
209
+ const channel = taskId;
210
+ const checkId = _generateCheckId(taskId, loopCount);
211
+ const startTime = nowCST();
212
+
213
+ this._status = CheckStatus.MATCHING;
214
+ this._emit(channel, SSE_EVENT.CHECK_START, {
215
+ checkId, taskId, loopCount, startTime,
216
+ acceptanceCriteriaCount: acceptanceCriteria.length
217
+ });
218
+
219
+ /** @type {CheckResult} */
220
+ const result = {
221
+ checkId,
222
+ taskId,
223
+ loopCount,
224
+ taskDescription,
225
+ acceptanceCriteria,
226
+ orchestratorResult,
227
+ startTime,
228
+ endTime: null,
229
+ status: CheckStatus.IDLE,
230
+ passed: false,
231
+ matchedSkillDir: '',
232
+ checkReportPath: '',
233
+ sessionId: '',
234
+ criteriaResults: [],
235
+ summary: '',
236
+ improvementSuggestions: [],
237
+ error: null
238
+ };
239
+
240
+ try {
241
+ // ─── 步骤 1:匹配审核 Skill ───
242
+ const checkTaskDescription = this._buildCheckTaskDescription(
243
+ taskDescription, acceptanceCriteria, orchestratorResult
244
+ );
245
+
246
+ this._status = CheckStatus.MATCHING;
247
+ const matchedSkillDir = await this._matchSkill(checkTaskDescription, skillDir);
248
+ result.matchedSkillDir = matchedSkillDir;
249
+ this._emit(channel, SSE_EVENT.CHECK_MATCH, { checkId, matchedSkillDir });
250
+
251
+ // ─── 步骤 2:执行审核 Skill ───
252
+ this._status = CheckStatus.EXECUTING;
253
+ const reportPath = path.join(workDir, `testcheck_loop${loopCount}_result.md`);
254
+ const summaryPath = path.join(workDir, `testcheck_loop${loopCount}_Summary.md`);
255
+
256
+ const { sessionId, executed } = await this._invokeSkill({
257
+ taskDescription: checkTaskDescription,
258
+ skillDir: matchedSkillDir,
259
+ reportPath,
260
+ summaryPath,
261
+ workDir,
262
+ loopCount,
263
+ abortSignal
264
+ });
265
+
266
+ result.sessionId = sessionId;
267
+ result.checkReportPath = reportPath;
268
+ this._emit(channel, SSE_EVENT.CHECK_EXECUTE, { checkId, sessionId, reportPath, executed });
269
+
270
+ if (!executed) {
271
+ throw new Error('审核 Skill 执行失败,未生成审核报告');
272
+ }
273
+
274
+ // ─── 步骤 3:评估准出条件 ───
275
+ this._status = CheckStatus.EVALUATING;
276
+ const evaluation = await this._evaluateAcceptance({
277
+ reportPath,
278
+ acceptanceCriteria,
279
+ taskDescription,
280
+ orchestratorResult,
281
+ loopCount
282
+ });
283
+
284
+ result.criteriaResults = evaluation.criteriaResults;
285
+ result.passed = evaluation.passed;
286
+ result.summary = evaluation.summary;
287
+ result.improvementSuggestions = evaluation.improvementSuggestions;
288
+ result.status = evaluation.passed ? CheckStatus.PASSED : CheckStatus.FAILED;
289
+
290
+ this._emit(channel, SSE_EVENT.CHECK_EVALUATE, {
291
+ checkId,
292
+ passed: result.passed,
293
+ criteriaResults: result.criteriaResults
294
+ });
295
+
296
+ } catch (err) {
297
+ result.status = CheckStatus.ERROR;
298
+ result.error = err.message;
299
+ this._status = CheckStatus.ERROR;
300
+ this._emit(channel, SSE_EVENT.CHECK_ERROR, { checkId, error: err.message });
301
+ this._log('error', `审核异常: ${err.message}`);
302
+ }
303
+
304
+ result.endTime = nowCST();
305
+ this._status = result.status;
306
+
307
+ // ─── 持久化审核结果 ───
308
+ await this._persistCheckResult(taskId, result);
309
+
310
+ this._emit(channel, SSE_EVENT.CHECK_RESULT, {
311
+ checkId,
312
+ passed: result.passed,
313
+ status: result.status,
314
+ summary: result.summary
315
+ });
316
+
317
+ this._log('info', `── 准出审核结束: passed=${result.passed}, loop=${loopCount} ──`);
318
+ return result;
319
+ }
320
+
321
+ // ─── 内部:Skill 匹配 ──────────────────────────────────────────────
322
+
323
+ /**
324
+ * 匹配审核 Skill — 基于准出审核语义选择最佳 Skill。
325
+ *
326
+ * @param {string} checkTaskDescription - 审核任务描述
327
+ * @param {string} skillDirectory - SKILL 目录
328
+ * @returns {Promise<string>} 匹配到的 SKILL 目录绝对路径
329
+ * @private
330
+ */
331
+ async _matchSkill(checkTaskDescription, skillDirectory) {
332
+ if (!checkTaskDescription) {
333
+ throw new Error('TestCheck._matchSkill: 审核任务描述不能为空');
334
+ }
335
+ if (!skillDirectory) {
336
+ throw new Error('TestCheck._matchSkill: skillDirectory 不能为空');
337
+ }
338
+
339
+ this._log('info', `matchSkill 开始 — 审核任务: "${checkTaskDescription.slice(0, 80)}…"`);
340
+
341
+ const selector = await this._getSkillSelector();
342
+ const selection = await selector.selectSkill(checkTaskDescription, skillDirectory);
343
+
344
+ if (!selection || !selection.best) {
345
+ throw new Error('TestCheck._matchSkill: 未匹配到任何合适的审核 Skill');
346
+ }
347
+
348
+ const bestDir = selection.skillPath || selection.best.skillPath;
349
+ if (!bestDir) {
350
+ throw new Error('TestCheck._matchSkill: 匹配结果缺少 Skill 目录路径');
351
+ }
352
+
353
+ this._log('info', `matchSkill 完成 — 最佳审核 Skill: ${selection.best.name} (${bestDir})`);
354
+ return bestDir;
355
+ }
356
+
357
+ /**
358
+ * 构建准出审核的任务描述 — 供 Skill 匹配器使用。
359
+ *
360
+ * @param {string} taskDescription - 原始任务描述
361
+ * @param {Array} acceptanceCriteria - 验收标准
362
+ * @param {object} orchestratorResult - 编排结果
363
+ * @returns {string}
364
+ * @private
365
+ */
366
+ _buildCheckTaskDescription(taskDescription, acceptanceCriteria, orchestratorResult) {
367
+ const parts = [
368
+ '对任务执行结果进行准出审核(验收测试)',
369
+ `原始任务: ${taskDescription}`
370
+ ];
371
+
372
+ if (acceptanceCriteria && acceptanceCriteria.length > 0) {
373
+ const criteriaText = acceptanceCriteria
374
+ .map(c => `- [${c.id}] (${c.type}) ${c.criterion}`)
375
+ .join('\n');
376
+ parts.push(`验收标准:\n${criteriaText}`);
377
+ }
378
+
379
+ if (orchestratorResult) {
380
+ parts.push(`编排状态: ${orchestratorResult.status || 'unknown'}`);
381
+ if (orchestratorResult.stats) {
382
+ parts.push(`步骤统计: ${JSON.stringify(orchestratorResult.stats)}`);
383
+ }
384
+ }
385
+
386
+ parts.push('检查任务产物是否满足所有验收标准,生成准出审核报告');
387
+ return parts.join('\n');
388
+ }
389
+
390
+ // ─── 内部:Skill 执行 ──────────────────────────────────────────────
391
+
392
+ /**
393
+ * 调用 CLI 执行审核 Skill。
394
+ *
395
+ * 流程:
396
+ * 1. 健康检查
397
+ * 2. 构建 prompt(任务描述 + 验收标准 + 产物路径 + 报告路径)
398
+ * 3. 创建 Session 并发送 prompt
399
+ * 4. 轮询等待完成
400
+ *
401
+ * @param {object} opts
402
+ * @param {string} opts.taskDescription
403
+ * @param {string} opts.skillDir
404
+ * @param {string} opts.reportPath
405
+ * @param {string} opts.summaryPath
406
+ * @param {string} opts.workDir
407
+ * @param {number} opts.loopCount
408
+ * @param {object} [opts.abortSignal] - 终止信号 { isAborted, onSessionCreated }(LoopEngine 注入)
409
+ * @returns {Promise<{sessionId: string, executed: boolean}>}
410
+ * @private
411
+ */
412
+ async _invokeSkill({ taskDescription, skillDir, reportPath, summaryPath, workDir, loopCount, abortSignal }) {
413
+ const cli = await this._getCli();
414
+
415
+ this._log('info', `invokeSkill 开始 — skillDir: ${skillDir}`);
416
+
417
+ // 健康检查
418
+ const health = await cli.checkHealth();
419
+ if (health.status !== 'ok') {
420
+ this._log('error', `CLI(${cli.getType()}) 服务不可用: ${health.message}`);
421
+ return { sessionId: '', executed: false };
422
+ }
423
+
424
+ // 构建 prompt
425
+ const title = `testcheck|task=${workDir.split('/').pop()}|loop=${loopCount}`;
426
+ const prompt = this._buildPrompt(taskDescription, skillDir, reportPath, summaryPath, workDir);
427
+
428
+ // 创建 Session(指定工作目录为 workDir,确保 opencode session 的文件操作在任务目录下执行)
429
+ // const { sessionId } = await cli.startSession(title, prompt, { cwd: workDir });
430
+ const { sessionId } = await cli.startSession(title, prompt);
431
+ this._log('info', `审核 Session 已创建: ${sessionId}`);
432
+
433
+ // 通知上层登记 sessionId(abortLoop 可据此远程中止)
434
+ if (abortSignal && typeof abortSignal.onSessionCreated === 'function') {
435
+ try {
436
+ abortSignal.onSessionCreated(sessionId);
437
+ } catch { /* 回调异常不影响主流程 */ }
438
+ }
439
+
440
+ // Session 创建后终止标志已置位 → 立即中止并退出
441
+ if (abortSignal && typeof abortSignal.isAborted === 'function' && abortSignal.isAborted()) {
442
+ try {
443
+ await cli.abortSession(sessionId);
444
+ } catch { /* 已自然结束 */ }
445
+ throw new Error('审核被终止(Session 创建后即中止)');
446
+ }
447
+
448
+ // 轮询等待完成
449
+ const completed = await this._pollSession(cli, sessionId, abortSignal);
450
+ if (!completed) {
451
+ this._log('warn', `审核 Session ${sessionId} 未在超时时间内完成`);
452
+ }
453
+
454
+ this._log('info', `invokeSkill 完成 — sessionId: ${sessionId}, completed: ${completed}`);
455
+ return { sessionId, executed: completed };
456
+ }
457
+
458
+ /**
459
+ * 构建审核 prompt。
460
+ *
461
+ * @param {string} taskDescription
462
+ * @param {string} skillDir
463
+ * @param {string} reportPath
464
+ * @param {string} summaryPath
465
+ * @param {string} workDir
466
+ * @returns {string}
467
+ * @private
468
+ */
469
+ _buildPrompt(taskDescription, skillDir, reportPath, summaryPath, workDir) {
470
+ const parts = [
471
+ `## 审核任务描述\n${taskDescription}`,
472
+ `## SKILL 目录\n${skillDir}`,
473
+ `## 工作目录\n${workDir}`,
474
+ `## 审核报告输出路径\n${reportPath}`,
475
+ `## 审核摘要输出路径\n${summaryPath}`,
476
+ '请按照 SKILL 中的指令执行准出审核任务。',
477
+ '审核完成后,请将审核结果写入上述"审核报告输出路径",并在"审核摘要输出路径"写入摘要。',
478
+ '审核报告需包含 `## 准出结论` 字段(值为 `通过` 或 `未通过`),用于判断审核结果。',
479
+ '审核报告需逐条列出每个验收标准的评估结论(满足/未满足)及证据。'
480
+ ];
481
+ return parts.join('\n\n');
482
+ }
483
+
484
+ /**
485
+ * 轮询 Session 状态直到完成或超时。
486
+ *
487
+ * @param {object} cli - CLIController 实例
488
+ * @param {string} sessionId - 会话 ID
489
+ * @param {object} [abortSignal] - 终止信号 { isAborted: () => boolean };
490
+ * 置位时在下一轮询周期远程中止 session 并抛终止退出
491
+ * @returns {Promise<boolean>}
492
+ * @private
493
+ */
494
+ async _pollSession(cli, sessionId, abortSignal = null) {
495
+ const deadline = Date.now() + POLL_TIMEOUT_MS;
496
+
497
+ while (Date.now() < deadline) {
498
+ // 终止检查:比超时检查优先,确保终止请求即时生效
499
+ if (abortSignal && typeof abortSignal.isAborted === 'function' && abortSignal.isAborted()) {
500
+ try {
501
+ await cli.abortSession(sessionId);
502
+ } catch { /* 已自然结束 */ }
503
+ this._log('warn', `审核 Session ${sessionId} 被终止`);
504
+ throw new Error('审核被终止');
505
+ }
506
+
507
+ await this._sleep(POLL_INTERVAL_MS);
508
+ try {
509
+ const { status } = await cli.checkSessionStatus(sessionId);
510
+ if (status === 'completed') {
511
+ return true;
512
+ }
513
+ } catch (err) {
514
+ this._log('warn', `轮询审核 Session 状态失败: ${err.message}`);
515
+ }
516
+ }
517
+ return false;
518
+ }
519
+
520
+ // ─── 内部:准出评估 ────────────────────────────────────────────────
521
+
522
+ /**
523
+ * 评估准出条件 — LLM 审核报告对照验收标准逐条判断。
524
+ *
525
+ * 读取审核报告文件,调用 LLM 对照任务级验收标准进行结构化评估:
526
+ * - 逐条判断每个验收标准是否满足
527
+ * - 汇总结论(全部满足=通过,任一未满足=未通过)
528
+ * - 生成改进建议(未通过时)
529
+ *
530
+ * @param {object} opts
531
+ * @param {string} opts.reportPath - 审核报告文件路径
532
+ * @param {Array} opts.acceptanceCriteria - 任务级验收标准
533
+ * @param {string} opts.taskDescription - 原始任务描述
534
+ * @param {object} opts.orchestratorResult - 编排结果
535
+ * @param {number} opts.loopCount - 当前循环次数
536
+ * @returns {Promise<{passed: boolean, criteriaResults: Array, summary: string, improvementSuggestions: Array}>}
537
+ * @private
538
+ */
539
+ async _evaluateAcceptance({ reportPath, acceptanceCriteria, taskDescription, loopCount }) {
540
+ // 读取审核报告
541
+ let reportContent = '';
542
+ try {
543
+ reportContent = await fs.readFile(reportPath, 'utf-8');
544
+ } catch (err) {
545
+ this._log('warn', `读取审核报告失败: ${reportPath} — ${err.message}`);
546
+ // 报告不存在时,仍尝试基于验收标准做基本评估
547
+ }
548
+
549
+ // 快速检查:报告中是否包含明确的准出结论
550
+ const quickMatch = reportContent.match(/##\s*准出结论\s*\n\s*(通过|未通过)/i);
551
+ if (quickMatch) {
552
+ const quickPassed = quickMatch[1] === '通过';
553
+ this._log('info', `快速判断准出结论: ${quickMatch[1]}`);
554
+ // 仍调用 LLM 做详细评估,但快速结论作为 fallback
555
+ const fallback = {
556
+ passed: quickPassed,
557
+ criteriaResults: acceptanceCriteria.map(c => ({
558
+ id: c.id,
559
+ criterion: c.criterion,
560
+ satisfied: quickPassed,
561
+ evidence: '基于审核报告准出结论',
562
+ note: quickPassed ? '满足' : '未满足'
563
+ })),
564
+ summary: quickPassed ? '所有验收标准已满足' : '存在未满足的验收标准',
565
+ improvementSuggestions: quickPassed ? [] : ['请根据审核报告中的问题进行修复']
566
+ };
567
+
568
+ // 尝试 LLM 详细评估,失败则用 fallback
569
+ try {
570
+ return await this._llmEvaluate(reportContent, acceptanceCriteria, taskDescription, loopCount);
571
+ } catch (err) {
572
+ this._log('warn', `LLM 评估失败,使用快速判断 fallback: ${err.message}`);
573
+ return fallback;
574
+ }
575
+ }
576
+
577
+ // 无快速结论时,直接调用 LLM 评估
578
+ return await this._llmEvaluate(reportContent, acceptanceCriteria, taskDescription, loopCount);
579
+ }
580
+
581
+ /**
582
+ * 调用 LLM 进行结构化准出评估。
583
+ *
584
+ * @param {string} reportContent - 审核报告内容
585
+ * @param {Array} acceptanceCriteria - 验收标准
586
+ * @param {string} taskDescription - 任务描述
587
+ * @param {number} loopCount - 循环次数
588
+ * @returns {Promise<{passed: boolean, criteriaResults: Array, summary: string, improvementSuggestions: Array}>}
589
+ * @private
590
+ */
591
+ async _llmEvaluate(reportContent, acceptanceCriteria, taskDescription, loopCount) {
592
+ const criteriaText = (acceptanceCriteria || [])
593
+ .map(c => `- [${c.id}] (${c.type}) ${c.criterion}\n 验证方式: ${c.verification}`)
594
+ .join('\n');
595
+
596
+ const prompt = `你是一个准出审核专家。请根据审核报告内容,逐条评估任务级验收标准是否满足。
597
+
598
+ ## 原始任务描述
599
+ ${taskDescription || '(未提供)'}
600
+
601
+ ## 任务级验收标准
602
+ ${criteriaText || '(未提供验收标准,请根据审核报告整体判断)'}
603
+
604
+ ## 审核报告内容
605
+ ${reportContent || '(审核报告为空,无法判断)'}
606
+
607
+ ## 当前循环次数
608
+ 第 ${loopCount + 1} 次循环
609
+
610
+ ## 输出要求
611
+ 请以 JSON 格式返回,包含以下字段:
612
+ {
613
+ "passed": true/false,
614
+ "criteriaResults": [
615
+ {
616
+ "id": "ac1",
617
+ "criterion": "验收标准描述",
618
+ "satisfied": true/false,
619
+ "evidence": "审核报告中支持该结论的证据或分析",
620
+ "note": "补充说明"
621
+ }
622
+ ],
623
+ "summary": "整体审核结论摘要(一段话)",
624
+ "improvementSuggestions": [
625
+ "针对未满足标准的改进建议(仅在未通过时提供)"
626
+ ]
627
+ }
628
+
629
+ ### 评估规则
630
+ 1. 如果审核报告为空或无法获取有效信息,passed 应为 false
631
+ 2. criteriaResults 必须覆盖所有任务级验收标准
632
+ 3. 每条标准的 satisfied 字段必须基于审核报告中的证据
633
+ 4. 如果所有标准都 satisfied=true,则 passed=true
634
+ 5. 如果任一标准 satisfied=false,则 passed=false
635
+ 6. improvementSuggestions 仅在 passed=false 时提供,针对未满足的标准给出具体改进建议
636
+ 7. summary 应概括整体审核结论,包括通过/未通过的原因
637
+
638
+ 注意:只返回 JSON,不要包含其他文字。`;
639
+
640
+ const result = await this.llm.chatJSON(prompt, { maxTokens: 4096 });
641
+
642
+ return {
643
+ passed: Boolean(result.passed),
644
+ criteriaResults: Array.isArray(result.criteriaResults)
645
+ ? result.criteriaResults.map((c, idx) => ({
646
+ id: c.id || (acceptanceCriteria[idx] ? acceptanceCriteria[idx].id : `ac${idx + 1}`),
647
+ criterion: c.criterion || (acceptanceCriteria[idx] ? acceptanceCriteria[idx].criterion : ''),
648
+ satisfied: Boolean(c.satisfied),
649
+ evidence: c.evidence || '',
650
+ note: c.note || ''
651
+ }))
652
+ : [],
653
+ summary: result.summary || (result.passed ? '审核通过' : '审核未通过'),
654
+ improvementSuggestions: Array.isArray(result.improvementSuggestions)
655
+ ? result.improvementSuggestions
656
+ : []
657
+ };
658
+ }
659
+
660
+ // ─── 内部:持久化 ──────────────────────────────────────────────────
661
+
662
+ /**
663
+ * 持久化审核结果到文件系统。
664
+ *
665
+ * 文件路径:db/task/{taskId}/testcheck_loop{loopCount}.json
666
+ *
667
+ * 与 Brain / Orchestrator 的持久化目录结构保持一致:
668
+ * db/task/{taskId}/
669
+ * ├── brain.json ← Brain 拆解计划(最新快照)
670
+ * ├── brain_loop0.json ← 各轮 Brain 计划
671
+ * ├── orchestration.json ← Orchestrator 编排状态(最新快照)
672
+ * ├── orchestration_loop0.json ← 各轮编排状态
673
+ * ├── stepid_1_loop0.json ← 各轮步骤执行记录
674
+ * ├── testcheck_loop0.json ← 第 0 次循环准出审核(本方法写入)
675
+ * ├── testcheck_loop1.json ← 第 1 次循环准出审核
676
+ * └── ...
677
+ *
678
+ * @param {string} taskId
679
+ * @param {CheckResult} result
680
+ * @private
681
+ */
682
+ async _persistCheckResult(taskId, result) {
683
+ try {
684
+ const json = this.storage.json('task');
685
+ await json.write(`${taskId}/testcheck_loop${result.loopCount}`, result);
686
+ this._log('info', `审核结果已持久化: db/task/${taskId}/testcheck_loop${result.loopCount}.json`);
687
+ } catch (err) {
688
+ this._log('warn', `持久化审核结果失败: ${err.message}`);
689
+ }
690
+ }
691
+
692
+ /**
693
+ * 从文件系统加载历史审核结果。
694
+ *
695
+ * @param {string} taskId
696
+ * @param {number} loopCount
697
+ * @returns {Promise<CheckResult|null>}
698
+ */
699
+ async loadCheckResult(taskId, loopCount) {
700
+ try {
701
+ const json = this.storage.json('task');
702
+ return await json.read(`${taskId}/testcheck_loop${loopCount}`);
703
+ } catch {
704
+ return null;
705
+ }
706
+ }
707
+
708
+ /**
709
+ * 列出某个 Task 下所有审核结果。
710
+ *
711
+ * @param {string} taskId
712
+ * @returns {Promise<Array>}
713
+ */
714
+ async listCheckResults(taskId) {
715
+ try {
716
+ const json = this.storage.json('task');
717
+ const entries = await json.list(`${taskId}/testcheck_loop`);
718
+ return entries
719
+ .filter(e => e && e.data)
720
+ .map(e => e.data)
721
+ .sort((a, b) => (a.loopCount || 0) - (b.loopCount || 0));
722
+ } catch {
723
+ return [];
724
+ }
725
+ }
726
+
727
+ // ─── 内部工具 ──────────────────────────────────────────────────────
728
+
729
+ /**
730
+ * Promise 版 sleep。
731
+ * @param {number} ms
732
+ * @returns {Promise<void>}
733
+ * @private
734
+ */
735
+ _sleep(ms) {
736
+ return new Promise((resolve) => setTimeout(resolve, ms));
737
+ }
738
+
739
+ /**
740
+ * 统一日志输出。
741
+ * @param {'info'|'warn'|'error'} level
742
+ * @param {string} message
743
+ * @private
744
+ */
745
+ _log(level, message) {
746
+ const prefix = '[TestCheck]';
747
+ const ts = nowCST();
748
+ switch (level) {
749
+ case 'error':
750
+ console.error(`${ts} ${prefix} ❌ ${message}`);
751
+ break;
752
+ case 'warn':
753
+ console.warn(`${ts} ${prefix} ⚠ ${message}`);
754
+ break;
755
+ default:
756
+ console.info(`${ts} ${prefix} ℹ ${message}`);
757
+ }
758
+ }
759
+ }
760
+
761
+ // ─── 辅助函数 ──────────────────────────────────────────────────────────────
762
+
763
+ /**
764
+ * 生成 checkId。
765
+ * @param {string} taskId
766
+ * @param {number} loopCount
767
+ * @returns {string}
768
+ */
769
+ function _generateCheckId(taskId, loopCount) {
770
+ const ts = Date.now().toString(36);
771
+ return `check_${taskId}_loop${loopCount}_${ts}`;
772
+ }
773
+
774
+ export { TestCheck };
775
+ export default TestCheck;