cnhkmcp 2.1.3__py3-none-any.whl → 2.1.5__py3-none-any.whl

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 (194) hide show
  1. cnhkmcp/__init__.py +126 -0
  2. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/README.md +38 -0
  3. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/ace.log +0 -0
  4. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/config.json +6 -0
  5. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/get_knowledgeBase_tool/ace_lib.py +1514 -0
  6. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/get_knowledgeBase_tool/fetch_all_datasets.py +157 -0
  7. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/get_knowledgeBase_tool/fetch_all_documentation.py +132 -0
  8. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/get_knowledgeBase_tool/fetch_all_operators.py +99 -0
  9. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/get_knowledgeBase_tool/helpful_functions.py +180 -0
  10. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/icon.ico +0 -0
  11. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/icon.png +0 -0
  12. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/001_10_Steps_to_Start_on_BRAIN_documentation.json +14 -0
  13. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/001_Intermediate_Pack_-_Improve_your_Alpha_2_2_documentation.json +174 -0
  14. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/001_Intermediate_Pack_-_Understand_Results_1_2_documentation.json +167 -0
  15. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/001_Introduction_to_Alphas_documentation.json +145 -0
  16. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/001_Introduction_to_BRAIN_Expression_Language_documentation.json +107 -0
  17. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/001_WorldQuant_Challenge_documentation.json +56 -0
  18. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/001__Read_this_First_-_Starter_Pack_documentation.json +404 -0
  19. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/002_How_to_choose_the_Simulation_Settings_documentation.json +268 -0
  20. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/002_Simulate_your_first_Alpha_documentation.json +88 -0
  21. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/002__Alpha_Examples_for_Beginners_documentation.json +254 -0
  22. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/002__Alpha_Examples_for_Bronze_Users_documentation.json +114 -0
  23. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/002__Alpha_Examples_for_Silver_Users_documentation.json +79 -0
  24. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/002__How_BRAIN_works_documentation.json +184 -0
  25. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/003_Clear_these_tests_before_submitting_an_Alpha_documentation.json +388 -0
  26. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/003_Parameters_in_the_Simulation_results_documentation.json +243 -0
  27. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/004_Group_Data_Fields_documentation.json +69 -0
  28. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/004_How_to_use_the_Data_Explorer_documentation.json +142 -0
  29. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/004_Model77_dataset_documentation.json +14 -0
  30. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/004_Sentiment1_dataset_documentation.json +14 -0
  31. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/004_Understanding_Data_in_BRAIN_Key_Concepts_and_Tips_documentation.json +182 -0
  32. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/004_Vector_Data_Fields_documentation.json +30 -0
  33. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/005_Crowding_Risk-Neutralized_Alphas_documentation.json +64 -0
  34. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/005_D0_documentation.json +66 -0
  35. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/005_Double_Neutralization_documentation.json +53 -0
  36. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/005_Fast_D1_Documentation_documentation.json +304 -0
  37. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/005_Investability_Constrained_Metrics_documentation.json +129 -0
  38. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/005_Must-read_posts_How_to_improve_your_Alphas_documentation.json +14 -0
  39. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/005_Neutralization_documentation.json +29 -0
  40. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/005_RAM_Risk-Neutralized_Alphas_documentation.json +64 -0
  41. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/005_Risk_Neutralization_Default_setting_documentation.json +75 -0
  42. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/005_Risk_Neutralized_Alphas_documentation.json +171 -0
  43. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/005_Statistical_Risk-Neutralized_Alphas_documentation.json +51 -0
  44. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/006_EUR_TOP2500_Universe_documentation.json +35 -0
  45. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/006_GLB_TOPDIV3000_Universe_documentation.json +48 -0
  46. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/006_Getting_Started_China_Research_for_Consultants_Gold_documentation.json +142 -0
  47. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/006_Getting_started_on_Illiquid_Universes_Gold_documentation.json +46 -0
  48. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/006_Getting_started_with_USA_TOPSP500_universe_Gold_documentation.json +62 -0
  49. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/006_Global_Alphas_Gold_documentation.json +66 -0
  50. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/006_India_Alphas_documentation.json +35 -0
  51. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/007_Consultant_Dos_and_Don_ts_documentation.json +35 -0
  52. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/007_Consultant_Features_documentation.json +239 -0
  53. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/007_Consultant_Simulation_Features_documentation.json +149 -0
  54. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/007_Consultant_Submission_Tests_documentation.json +363 -0
  55. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/007_Finding_Consultant_Alphas_documentation.json +333 -0
  56. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/007_Power_Pool_Alphas_documentation.json +14 -0
  57. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/007_Research_Advisory_Program_documentation.json +35 -0
  58. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/007_Starting_Guide_for_Research_Consultants_documentation.json +14 -0
  59. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/007_Visualization_Tool_documentation.json +99 -0
  60. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/007_Your_Advisor_-_Kunqi_Jiang_documentation.json +53 -0
  61. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/007__Brain_Genius_documentation.json +288 -0
  62. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/007__Single_Dataset_Alphas_documentation.json +41 -0
  63. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/008_Advisory_Theme_Calendar_documentation.json +14 -0
  64. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/008_Multiplier_Rules_documentation.json +14 -0
  65. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/008_Overview_of_Themes_documentation.json +14 -0
  66. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/008_Theme_Calendar_documentation.json +14 -0
  67. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/009_Combo_Expression_documentation.json +272 -0
  68. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/009_Global_SuperAlphas_documentation.json +14 -0
  69. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/009_Helpful_Tips_documentation.json +58 -0
  70. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/009_Selection_Expression_documentation.json +1546 -0
  71. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/009_SuperAlpha_Operators_documentation.json +890 -0
  72. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/009_SuperAlpha_Results_documentation.json +83 -0
  73. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/009_What_is_a_SuperAlpha_documentation.json +261 -0
  74. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/010_BRAIN_API_documentation.json +515 -0
  75. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/010_Documentation_for_ACE_API_Library_Gold_documentation.json +27 -0
  76. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/010__Understanding_simulation_limits_documentation.json +210 -0
  77. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/arithmetic_operators.json +209 -0
  78. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/cross_sectional_operators.json +98 -0
  79. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/group_operators.json +121 -0
  80. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/logical_operators.json +145 -0
  81. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/reduce_operators.json +156 -0
  82. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/special_operators.json +35 -0
  83. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/test.txt +1 -0
  84. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/time_series_operators.json +386 -0
  85. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/transformational_operators.json +61 -0
  86. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/vector_operators.json +38 -0
  87. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/main.py +576 -0
  88. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/process_knowledge_base.py +281 -0
  89. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/rag_engine.py +408 -0
  90. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/requirements.txt +7 -0
  91. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/run.bat +3 -0
  92. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/vector_db/_manifest.json +302 -0
  93. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/vector_db/_meta.json +1 -0
  94. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/vector_db/chroma.sqlite3 +0 -0
  95. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242//321/211/320/266/320/246/321/206/320/274/320/261/321/210/342/224/220/320/240/321/210/320/261/320/234/321/206/320/231/320/243/321/205/342/225/235/320/220/321/206/320/230/320/241.py +265 -0
  96. cnhkmcp/untracked/APP/.gitignore +32 -0
  97. cnhkmcp/untracked/APP/MODULAR_STRUCTURE.md +112 -0
  98. cnhkmcp/untracked/APP/README.md +309 -0
  99. cnhkmcp/untracked/APP/Tranformer/Transformer.py +4989 -0
  100. cnhkmcp/untracked/APP/Tranformer/ace.log +0 -0
  101. cnhkmcp/untracked/APP/Tranformer/ace_lib.py +1514 -0
  102. cnhkmcp/untracked/APP/Tranformer/helpful_functions.py +180 -0
  103. cnhkmcp/untracked/APP/Tranformer/output/Alpha_candidates.json +7187 -0
  104. cnhkmcp/untracked/APP/Tranformer/output/Alpha_candidates_/321/207/320/264/342/225/221/321/204/342/225/233/320/233.json +654 -0
  105. cnhkmcp/untracked/APP/Tranformer/output/Alpha_generated_expressions_error.json +1 -0
  106. cnhkmcp/untracked/APP/Tranformer/output/Alpha_generated_expressions_success.json +47312 -0
  107. cnhkmcp/untracked/APP/Tranformer/output/Alpha_generated_expressions_/321/207/320/264/342/225/221/321/204/342/225/233/320/233/321/205/320/237/320/277/321/207/320/253/342/224/244/321/206/320/236/320/265/321/210/342/225/234/342/225/234/321/205/320/225/320/265Machine_lib.json +22 -0
  108. cnhkmcp/untracked/APP/Tranformer/parsetab.py +60 -0
  109. cnhkmcp/untracked/APP/Tranformer/template_summary.txt +3182 -0
  110. cnhkmcp/untracked/APP/Tranformer/transformer_config.json +7 -0
  111. cnhkmcp/untracked/APP/Tranformer/validator.py +889 -0
  112. cnhkmcp/untracked/APP/ace.log +69 -0
  113. cnhkmcp/untracked/APP/ace_lib.py +1514 -0
  114. cnhkmcp/untracked/APP/blueprints/__init__.py +6 -0
  115. cnhkmcp/untracked/APP/blueprints/feature_engineering.py +347 -0
  116. cnhkmcp/untracked/APP/blueprints/idea_house.py +221 -0
  117. cnhkmcp/untracked/APP/blueprints/inspiration_house.py +432 -0
  118. cnhkmcp/untracked/APP/blueprints/paper_analysis.py +570 -0
  119. cnhkmcp/untracked/APP/custom_templates/templates.json +1257 -0
  120. cnhkmcp/untracked/APP/give_me_idea/BRAIN_Alpha_Template_Expert_SystemPrompt.md +400 -0
  121. cnhkmcp/untracked/APP/give_me_idea/ace_lib.py +1514 -0
  122. cnhkmcp/untracked/APP/give_me_idea/alpha_data_specific_template_master.py +252 -0
  123. cnhkmcp/untracked/APP/give_me_idea/fetch_all_datasets.py +157 -0
  124. cnhkmcp/untracked/APP/give_me_idea/fetch_all_operators.py +99 -0
  125. cnhkmcp/untracked/APP/give_me_idea/helpful_functions.py +180 -0
  126. cnhkmcp/untracked/APP/give_me_idea/what_is_Alpha_template.md +11 -0
  127. cnhkmcp/untracked/APP/helpful_functions.py +180 -0
  128. cnhkmcp/untracked/APP/hkSimulator/ace_lib.py +1501 -0
  129. cnhkmcp/untracked/APP/hkSimulator/autosimulator.py +447 -0
  130. cnhkmcp/untracked/APP/hkSimulator/helpful_functions.py +180 -0
  131. cnhkmcp/untracked/APP/mirror_config.txt +20 -0
  132. cnhkmcp/untracked/APP/operaters.csv +129 -0
  133. cnhkmcp/untracked/APP/requirements.txt +53 -0
  134. cnhkmcp/untracked/APP/run_app.bat +28 -0
  135. cnhkmcp/untracked/APP/run_app.sh +34 -0
  136. cnhkmcp/untracked/APP/setup_tsinghua.bat +39 -0
  137. cnhkmcp/untracked/APP/setup_tsinghua.sh +43 -0
  138. cnhkmcp/untracked/APP/simulator/alpha_submitter.py +404 -0
  139. cnhkmcp/untracked/APP/simulator/simulator_wqb.py +618 -0
  140. cnhkmcp/untracked/APP/ssrn-3332513.pdf +109188 -19
  141. cnhkmcp/untracked/APP/static/brain.js +589 -0
  142. cnhkmcp/untracked/APP/static/decoder.js +1540 -0
  143. cnhkmcp/untracked/APP/static/feature_engineering.js +1729 -0
  144. cnhkmcp/untracked/APP/static/idea_house.js +937 -0
  145. cnhkmcp/untracked/APP/static/inspiration.js +465 -0
  146. cnhkmcp/untracked/APP/static/inspiration_house.js +868 -0
  147. cnhkmcp/untracked/APP/static/paper_analysis.js +390 -0
  148. cnhkmcp/untracked/APP/static/script.js +3082 -0
  149. cnhkmcp/untracked/APP/static/simulator.js +597 -0
  150. cnhkmcp/untracked/APP/static/styles.css +3127 -0
  151. cnhkmcp/untracked/APP/static/usage_widget.js +508 -0
  152. cnhkmcp/untracked/APP/templates/alpha_inspector.html +511 -0
  153. cnhkmcp/untracked/APP/templates/feature_engineering.html +960 -0
  154. cnhkmcp/untracked/APP/templates/idea_house.html +564 -0
  155. cnhkmcp/untracked/APP/templates/index.html +932 -0
  156. cnhkmcp/untracked/APP/templates/inspiration_house.html +861 -0
  157. cnhkmcp/untracked/APP/templates/paper_analysis.html +91 -0
  158. cnhkmcp/untracked/APP/templates/simulator.html +343 -0
  159. cnhkmcp/untracked/APP/templates/transformer_web.html +580 -0
  160. cnhkmcp/untracked/APP/usage.md +351 -0
  161. cnhkmcp/untracked/APP//321/207/342/225/235/320/250/321/205/320/230/320/226/321/204/342/225/225/320/220/321/211/320/221/320/243/321/206/320/261/320/265/ace_lib.py +1514 -0
  162. cnhkmcp/untracked/APP//321/207/342/225/235/320/250/321/205/320/230/320/226/321/204/342/225/225/320/220/321/211/320/221/320/243/321/206/320/261/320/265/brain_alpha_inspector.py +712 -0
  163. cnhkmcp/untracked/APP//321/207/342/225/235/320/250/321/205/320/230/320/226/321/204/342/225/225/320/220/321/211/320/221/320/243/321/206/320/261/320/265/helpful_functions.py +180 -0
  164. cnhkmcp/untracked/APP//321/210/342/224/220/320/240/321/210/320/261/320/234/321/206/320/231/320/243/321/205/342/225/235/320/220/321/206/320/230/320/241.py +2460 -0
  165. cnhkmcp/untracked/__init__.py +0 -0
  166. cnhkmcp/untracked/arXiv_API_Tool_Manual.md +490 -0
  167. cnhkmcp/untracked/arxiv_api.py +229 -0
  168. cnhkmcp/untracked/back_up/forum_functions.py +998 -0
  169. cnhkmcp/untracked/back_up/platform_functions.py +2886 -0
  170. cnhkmcp/untracked/brain-consultant.md +31 -0
  171. cnhkmcp/untracked/forum_functions.py +407 -0
  172. cnhkmcp/untracked/mcp/321/206/320/246/320/227/321/204/342/225/227/342/225/242/321/210/320/276/342/225/221/321/205/320/255/320/253/321/207/320/231/320/2302_/321/205/320/266/320/222/321/206/320/256/320/254/321/205/320/236/320/257/321/207/320/231/320/230/321/205/320/240/320/277/321/205/320/232/320/270/321/204/342/225/225/320/235/321/204/342/225/221/320/226/321/206/342/225/241/320/237/321/210/320/267/320/230/321/205/320/251/320/270/321/205/342/226/221/342/226/222/321/210/320/277/320/245/321/210/342/224/220/320/251/321/204/342/225/225/320/272/forum_functions.py +407 -0
  173. cnhkmcp/untracked/mcp/321/206/320/246/320/227/321/204/342/225/227/342/225/242/321/210/320/276/342/225/221/321/205/320/255/320/253/321/207/320/231/320/2302_/321/205/320/266/320/222/321/206/320/256/320/254/321/205/320/236/320/257/321/207/320/231/320/230/321/205/320/240/320/277/321/205/320/232/320/270/321/204/342/225/225/320/235/321/204/342/225/221/320/226/321/206/342/225/241/320/237/321/210/320/267/320/230/321/205/320/251/320/270/321/205/342/226/221/342/226/222/321/210/320/277/320/245/321/210/342/224/220/320/251/321/204/342/225/225/320/272/platform_functions.py +2601 -0
  174. cnhkmcp/untracked/mcp/321/206/320/246/320/227/321/204/342/225/227/342/225/242/321/210/320/276/342/225/221/321/205/320/255/320/253/321/207/320/231/320/2302_/321/205/320/266/320/222/321/206/320/256/320/254/321/205/320/236/320/257/321/207/320/231/320/230/321/205/320/240/320/277/321/205/320/232/320/270/321/204/342/225/225/320/235/321/204/342/225/221/320/226/321/206/342/225/241/320/237/321/210/320/267/320/230/321/205/320/251/320/270/321/205/342/226/221/342/226/222/321/210/320/277/320/245/321/210/342/224/220/320/251/321/204/342/225/225/320/272/user_config.json +31 -0
  175. cnhkmcp/untracked/mcp/321/206/320/246/320/227/321/204/342/225/227/342/225/242/321/210/320/276/342/225/221/321/205/320/255/320/253/321/207/320/231/320/2302_/321/205/320/266/320/222/321/206/320/256/320/254/321/205/320/236/320/257/321/207/320/231/320/230/321/205/320/240/320/277/321/205/320/232/320/270/321/204/342/225/225/320/235/321/204/342/225/221/320/226/321/206/342/225/241/320/237/321/210/320/267/320/230/321/205/320/251/320/270/321/205/342/226/221/342/226/222/321/210/320/277/320/245/321/210/342/224/220/320/251/321/204/342/225/225/320/272//321/210/320/276/320/271AI/321/210/320/277/342/225/227/321/210/342/224/220/320/251/321/204/342/225/225/320/272/321/206/320/246/320/227/321/206/320/261/320/263/321/206/320/255/320/265/321/205/320/275/320/266/321/204/342/225/235/320/252/321/204/342/225/225/320/233/321/210/342/225/234/342/225/234/321/206/342/225/241/320/237/321/210/320/267/320/230/321/205/320/251/320/270.md +101 -0
  176. cnhkmcp/untracked/mcp/321/206/320/246/320/227/321/204/342/225/227/342/225/242/321/210/320/276/342/225/221/321/205/320/255/320/253/321/207/320/231/320/2302_/321/205/320/266/320/222/321/206/320/256/320/254/321/205/320/236/320/257/321/207/320/231/320/230/321/205/320/240/320/277/321/205/320/232/320/270/321/204/342/225/225/320/235/321/204/342/225/221/320/226/321/206/342/225/241/320/237/321/210/320/267/320/230/321/205/320/251/320/270/321/205/342/226/221/342/226/222/321/210/320/277/320/245/321/210/342/224/220/320/251/321/204/342/225/225/320/272//321/211/320/225/320/235/321/207/342/225/234/320/276/321/205/320/231/320/235/321/210/342/224/220/320/240/321/210/320/261/320/234/321/206/320/230/320/241_/321/205/320/276/320/231/321/210/320/263/320/225/321/205/342/224/220/320/225/321/210/320/266/320/221/321/204/342/225/233/320/255/321/210/342/225/241/320/246/321/205/320/234/320/225.py +190 -0
  177. cnhkmcp/untracked/platform_functions.py +2601 -0
  178. cnhkmcp/untracked/sample_mcp_config.json +11 -0
  179. cnhkmcp/untracked/user_config.json +31 -0
  180. cnhkmcp/untracked//321/207/320/264/342/225/221/321/204/342/225/233/320/233/321/205/320/237/320/222/321/210/320/220/320/223/321/206/320/246/320/227/321/206/320/261/320/263_BRAIN_Alpha_Test_Requirements_and_Tips.md +202 -0
  181. cnhkmcp/untracked//321/207/320/264/342/225/221/321/204/342/225/233/320/233/321/205/342/225/226/320/265/321/204/342/225/234/320/254/321/206/342/225/241/320/221_Alpha_explaination_workflow.md +56 -0
  182. cnhkmcp/untracked//321/207/320/264/342/225/221/321/204/342/225/233/320/233/321/205/342/225/226/320/265/321/204/342/225/234/320/254/321/206/342/225/241/320/221_BRAIN_6_Tips_Datafield_Exploration_Guide.md +194 -0
  183. cnhkmcp/untracked//321/207/320/264/342/225/221/321/204/342/225/233/320/233/321/205/342/225/226/320/265/321/204/342/225/234/320/254/321/206/342/225/241/320/221_BRAIN_Alpha_Improvement_Workflow.md +101 -0
  184. cnhkmcp/untracked//321/207/320/264/342/225/221/321/204/342/225/233/320/233/321/205/342/225/226/320/265/321/204/342/225/234/320/254/321/206/342/225/241/320/221_Dataset_Exploration_Expert_Manual.md +436 -0
  185. cnhkmcp/untracked//321/207/320/264/342/225/221/321/204/342/225/233/320/233/321/205/342/225/226/320/265/321/204/342/225/234/320/254/321/206/342/225/241/320/221_daily_report_workflow.md +128 -0
  186. cnhkmcp/untracked//321/211/320/225/320/235/321/207/342/225/234/320/276/321/205/320/231/320/235/321/210/342/224/220/320/240/321/210/320/261/320/234/321/206/320/230/320/241_/321/205/320/276/320/231/321/210/320/263/320/225/321/205/342/224/220/320/225/321/210/320/266/320/221/321/204/342/225/233/320/255/321/210/342/225/241/320/246/321/205/320/234/320/225.py +192 -0
  187. {cnhkmcp-2.1.3.dist-info → cnhkmcp-2.1.5.dist-info}/METADATA +1 -1
  188. cnhkmcp-2.1.5.dist-info/RECORD +192 -0
  189. cnhkmcp-2.1.5.dist-info/top_level.txt +1 -0
  190. cnhkmcp-2.1.3.dist-info/RECORD +0 -6
  191. cnhkmcp-2.1.3.dist-info/top_level.txt +0 -1
  192. {cnhkmcp-2.1.3.dist-info → cnhkmcp-2.1.5.dist-info}/WHEEL +0 -0
  193. {cnhkmcp-2.1.3.dist-info → cnhkmcp-2.1.5.dist-info}/entry_points.txt +0 -0
  194. {cnhkmcp-2.1.3.dist-info → cnhkmcp-2.1.5.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,407 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ WorldQuant BRAIN Forum Functions - Python Version
4
+ Comprehensive forum functionality including glossary, search, and post viewing using Playwright.
5
+ """
6
+
7
+ import asyncio
8
+ import re
9
+ import sys
10
+ import time
11
+ from datetime import datetime
12
+ from typing import Dict, Any, List, Optional
13
+
14
+ from bs4 import BeautifulSoup
15
+ from playwright.async_api import async_playwright
16
+ import requests
17
+ import os
18
+
19
+ def log(message: str, level: str = "INFO"):
20
+ """Log message with timestamp."""
21
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
22
+ print(f"[{timestamp}] [{level}] {message}", file=sys.stderr)
23
+
24
+ # --- Parsing Helper Functions (from playwright_forum_test.py) ---
25
+
26
+ def _is_navigation_or_metadata(line: str) -> bool:
27
+ """Check if a line is navigation or metadata."""
28
+ navigation_patterns = [
29
+ r'^\d+ days? ago$',
30
+ r'~\d+ minute read',
31
+ r'^Follow',
32
+ r'^Not yet followed',
33
+ r'^Updated$',
34
+ r'^AS\d+$',
35
+ r'^[A-Z] - [A-Z] - [A-Z]', # Letter navigation
36
+ r'^A$',
37
+ r'^B$',
38
+ r'^[A-Z]$' # Single letters
39
+ ]
40
+ return any(re.match(pattern, line.strip()) for pattern in navigation_patterns)
41
+
42
+ def _looks_like_term(line: str) -> bool:
43
+ """Check if a line looks like a glossary term."""
44
+ if len(line) > 100:
45
+ return False
46
+ if _is_navigation_or_metadata(line):
47
+ return False
48
+ definition_starters = ['the', 'a', 'an', 'this', 'that', 'it', 'is', 'are', 'was', 'were', 'for', 'to', 'in', 'on', 'at', 'by', 'with']
49
+ first_word = line.lower().split(' ')[0] if line else ''
50
+ if first_word and first_word in definition_starters:
51
+ return False
52
+ is_short = len(line) <= 80
53
+ starts_with_capital = bool(re.match(r'^[A-Z]', line))
54
+ has_all_caps = bool(re.match(r'^[A-Z\s\-\/\(\)]+$', line))
55
+ has_reasonable_length = len(line) >= 2
56
+ return is_short and has_reasonable_length and (starts_with_capital or has_all_caps)
57
+
58
+ def _parse_glossary_terms(content: str) -> List[Dict[str, str]]:
59
+ """Parse glossary terms from HTML content."""
60
+ soup = BeautifulSoup(content, 'html.parser')
61
+ # Get text from the article body, which is more reliable than splitting the whole HTML
62
+ article_body = soup.select_one('.article-body')
63
+ if not article_body:
64
+ return []
65
+
66
+ # Use .get_text with a separator to preserve line breaks, which is key for the logic below
67
+ lines = article_body.get_text(separator='\n').split('\n')
68
+
69
+ terms = []
70
+ current_term = None
71
+ current_definition = []
72
+
73
+ for line in lines:
74
+ line = line.strip()
75
+ if not line:
76
+ continue
77
+
78
+ if _looks_like_term(line):
79
+ if current_term:
80
+ # Save the previous term
81
+ terms.append({
82
+ "term": current_term,
83
+ "definition": " ".join(current_definition).strip()
84
+ })
85
+ # Start a new term
86
+ current_term = line
87
+ current_definition = []
88
+ elif current_term:
89
+ # Add to the current definition
90
+ current_definition.append(line)
91
+
92
+ # Add the last term
93
+ if current_term:
94
+ terms.append({
95
+ "term": current_term,
96
+ "definition": " ".join(current_definition).strip()
97
+ })
98
+
99
+ # Filter out invalid terms and improve quality
100
+ return [term for term in terms if
101
+ len(term["term"]) > 0 and
102
+ len(term["definition"]) > 10 and
103
+ not _is_navigation_or_metadata(term["term"]) and
104
+ "ago" not in term["definition"] and
105
+ "minute read" not in term["definition"]]
106
+
107
+ class ForumClient:
108
+ """Forum client for WorldQuant BRAIN support site, using Playwright."""
109
+
110
+ def __init__(self):
111
+ self.base_url = "https://support.worldquantbrain.com"
112
+ # The session is mainly used for the initial authentication via brain_client
113
+ self.session = requests.Session()
114
+ self.session.headers.update({
115
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36'
116
+ })
117
+
118
+ async def _get_browser_context(self, p: async_playwright, email: str, password: str):
119
+ """Authenticate and return a browser context with the session."""
120
+ # Import brain_client here to avoid circular dependency
121
+ from platform_functions import brain_client
122
+
123
+ log("Authenticating with BRAIN platform...", "INFO")
124
+ auth_result = await brain_client.authenticate(email, password)
125
+ if auth_result.get('status') != 'authenticated':
126
+ raise Exception("BRAIN platform authentication failed.")
127
+ log("Successfully authenticated with BRAIN platform.", "SUCCESS")
128
+
129
+ browser = await p.chromium.launch(channel="chrome", headless=True, args=['--no-sandbox'])
130
+ context = await browser.new_context(user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36')
131
+
132
+ log("Transferring authentication session to browser...", "INFO")
133
+ cookies = brain_client.session.cookies
134
+ playwright_cookies = []
135
+ for cookie in cookies:
136
+ cookie_dict = {
137
+ 'name': cookie.name,
138
+ 'value': cookie.value,
139
+ 'domain': cookie.domain,
140
+ 'path': cookie.path,
141
+ 'secure': cookie.secure,
142
+ 'httpOnly': 'HttpOnly' in cookie._rest,
143
+ 'sameSite': 'Lax'
144
+ }
145
+ if cookie.expires:
146
+ cookie_dict['expires'] = cookie.expires
147
+ playwright_cookies.append(cookie_dict)
148
+
149
+ await context.add_cookies(playwright_cookies)
150
+ log("Session transferred.", "SUCCESS")
151
+
152
+ return browser, context
153
+
154
+ async def get_glossary_terms(self, email: str, password: str) -> List[Dict[str, str]]:
155
+ """Extract glossary terms from the forum using Playwright."""
156
+ async with async_playwright() as p:
157
+ browser = None
158
+ try:
159
+ log("Starting glossary extraction process with Playwright", "INFO")
160
+ browser, context = await self._get_browser_context(p, email, password)
161
+
162
+ page = await context.new_page()
163
+ log("Navigating to BRAIN support forum glossary...", "INFO")
164
+ await page.goto("https://support.worldquantbrain.com/hc/en-us/articles/4902349883927-Click-here-for-a-list-of-terms-and-their-definitions")
165
+
166
+ log("Extracting glossary content...", "INFO")
167
+ content = await page.content()
168
+
169
+ terms = _parse_glossary_terms(content)
170
+
171
+ log(f"Extracted {len(terms)} glossary terms", "SUCCESS")
172
+ return terms
173
+
174
+ except Exception as e:
175
+ log(f"Glossary extraction failed: {str(e)}", "ERROR")
176
+ # Re-raise to be handled by the MCP server wrapper
177
+ raise
178
+ finally:
179
+ if browser:
180
+ await browser.close()
181
+ log("Browser closed.", "INFO")
182
+
183
+ async def search_forum_posts(self, email: str, password: str, search_query: str, max_results: int = 50, locale: str = "zh-cn") -> Dict[str, Any]:
184
+ """Search for posts on the forum using Playwright, with pagination."""
185
+ async with async_playwright() as p:
186
+ browser = None
187
+ try:
188
+ log(f"Starting forum search for '{search_query}'", "INFO")
189
+ browser, context = await self._get_browser_context(p, email, password)
190
+
191
+ page = await context.new_page()
192
+
193
+ search_results = []
194
+ page_num = 1
195
+
196
+ while len(search_results) < max_results:
197
+ search_url = f"{self.base_url}/hc/{locale}/search?page={page_num}&query={search_query}#results"
198
+ log(f"Navigating to search page: {search_url}", "INFO")
199
+
200
+ try:
201
+ response = await page.goto(search_url)
202
+ if response.status == 404:
203
+ log(f"Page {page_num} not found. End of results.", "INFO")
204
+ break
205
+ await page.wait_for_selector('ul.search-results-list', timeout=15000)
206
+ except Exception as e:
207
+ log(f"Could not load search results on page {page_num}: {e}", "INFO")
208
+ break
209
+
210
+ content = await page.content()
211
+ soup = BeautifulSoup(content, 'html.parser')
212
+
213
+ results_on_page = soup.select('li.search-result-list-item')
214
+ if not results_on_page:
215
+ log("No more search results found.", "INFO")
216
+ break
217
+
218
+ for result in results_on_page:
219
+ title_element = result.select_one('h2.search-result-title a')
220
+ snippet_element = result.select_one('.search-results-description')
221
+
222
+ if title_element:
223
+ title = title_element.get_text(strip=True)
224
+ link = title_element.get('href')
225
+
226
+ votes_element = result.select_one('.search-result-votes span[aria-hidden="true"]')
227
+ votes_text = votes_element.get_text(strip=True) if votes_element else '0'
228
+ votes_match = re.search(r'\d+', votes_text)
229
+ votes = int(votes_match.group()) if votes_match else 0
230
+
231
+ comments_element = result.select_one('.search-result-meta-count span[aria-hidden="true"]')
232
+ comments_text = comments_element.get_text(strip=True) if comments_element else '0'
233
+ comments_match = re.search(r'\d+', comments_text)
234
+ comments = int(comments_match.group()) if comments_match else 0
235
+
236
+ breadcrumbs_elements = result.select('ol.search-result-breadcrumbs li')
237
+ breadcrumbs = [bc.get_text(strip=True) for bc in breadcrumbs_elements]
238
+
239
+ meta_group = result.select_one('ul.meta-group')
240
+ author = 'Unknown'
241
+ post_date = 'Unknown'
242
+ if meta_group:
243
+ meta_data_elements = meta_group.select('li.meta-data')
244
+ if len(meta_data_elements) > 0:
245
+ author = meta_data_elements[0].get_text(strip=True)
246
+ if len(meta_data_elements) > 1:
247
+ time_element = meta_data_elements[1].select_one('time')
248
+ if time_element:
249
+ post_date = time_element.get('datetime', time_element.get_text(strip=True))
250
+
251
+ snippet = snippet_element.get_text(strip=True) if snippet_element else ''
252
+
253
+ full_link = ''
254
+ if link:
255
+ if link.startswith('http'):
256
+ full_link = link
257
+ else:
258
+ full_link = f"{self.base_url}{link}"
259
+
260
+ search_results.append({
261
+ 'title': title,
262
+ 'link': full_link,
263
+ 'snippet': snippet,
264
+ 'votes': votes,
265
+ 'comments': comments,
266
+ 'author': author,
267
+ 'date': post_date,
268
+ 'breadcrumbs': breadcrumbs
269
+ })
270
+
271
+ if len(search_results) >= max_results:
272
+ break
273
+
274
+ if len(search_results) >= max_results:
275
+ break
276
+
277
+ page_num += 1
278
+
279
+ log(f"Found {len(search_results)} results for '{search_query}'", "SUCCESS")
280
+
281
+ return {
282
+ "success": True,
283
+ "results": search_results,
284
+ "total_found": len(search_results)
285
+ }
286
+
287
+ except Exception as e:
288
+ log(f"Forum search failed: {str(e)}", "ERROR")
289
+ raise
290
+ finally:
291
+ if browser:
292
+ await browser.close()
293
+
294
+ async def read_full_forum_post(self, email: str, password: str, post_url_or_id: str, include_comments: bool = True) -> Dict[str, Any]:
295
+ """Read a complete forum post and all its comments using Playwright."""
296
+ async with async_playwright() as p:
297
+ browser = None
298
+ try:
299
+ log("Starting forum post reading process with Playwright", "INFO")
300
+
301
+ if post_url_or_id.startswith('http'):
302
+ initial_url = post_url_or_id
303
+ else:
304
+ initial_url = f"https://support.worldquantbrain.com/hc/zh-cn/community/posts/{post_url_or_id}"
305
+
306
+ browser, context = await self._get_browser_context(p, email, password)
307
+ page = await context.new_page()
308
+
309
+ # --- Get Main Post Content and Final URL ---
310
+ log(f"Navigating to initial URL: {initial_url}", "INFO")
311
+ await page.goto(initial_url)
312
+ await page.wait_for_selector('.post-body, .article-body', timeout=15000)
313
+
314
+ # Get the final URL after any redirects
315
+ base_url = re.sub(r'(\?|&)page=\d+', '', page.url).split('#')[0]
316
+ log(f"Resolved to Base URL: {base_url}", "INFO")
317
+ await page.wait_for_selector('.post-body, .article-body', timeout=15000)
318
+ content = await page.content()
319
+ soup = BeautifulSoup(content, 'html.parser')
320
+
321
+ post_data = {}
322
+ title_element = soup.select_one('.post-title, h1.article-title, .article__title')
323
+ post_data['title'] = title_element.get_text(strip=True) if title_element else 'Unknown Title'
324
+
325
+ author_span = soup.select_one('.post-author span[title]')
326
+ post_data['author'] = author_span['title'] if author_span else 'Unknown Author'
327
+
328
+ body_element = soup.select_one('.post-body, .article-body')
329
+ post_data['body'] = body_element.get_text(strip=True) if body_element else 'Body not found'
330
+
331
+ votes_element = soup.select_one('.vote-sum')
332
+ date_element = soup.select_one('.post-meta .meta-data')
333
+ post_data['details'] = {
334
+ 'votes': votes_element.get_text(strip=True) if votes_element else '0',
335
+ 'date': date_element.get_text(strip=True) if date_element else 'Unknown Date'
336
+ }
337
+
338
+ # --- Get Comments with Pagination ---
339
+ comments = []
340
+ if include_comments:
341
+ log("Starting comment extraction...", "INFO")
342
+ page_num = 1
343
+ while True:
344
+ comment_url = f"{base_url}?page={page_num}#comments"
345
+ log(f"Navigating to comment page: {comment_url}", "INFO")
346
+
347
+ try:
348
+ response = await page.goto(comment_url)
349
+ if response.status == 404:
350
+ log(f"Page {page_num} returned 404. End of comments.", "INFO")
351
+ break
352
+ await page.wait_for_selector('.comment-list', timeout=10000)
353
+ except Exception as e:
354
+ log(f"Could not load page {page_num}: {e}. Assuming end of comments.", "INFO")
355
+ break
356
+
357
+ comment_soup = BeautifulSoup(await page.content(), 'html.parser')
358
+ comment_elements = comment_soup.select('.comment')
359
+
360
+ if not comment_elements:
361
+ log(f"No comments found on page {page_num}. Ending extraction.", "INFO")
362
+ break
363
+
364
+ log(f"Found {len(comment_elements)} comments on page {page_num}.", "INFO")
365
+
366
+ new_comments_found_on_page = 0
367
+ for comment_element in comment_elements:
368
+ author_span = comment_element.select_one('.comment-author span[title]')
369
+ author_id = author_span['title'] if author_span else 'Unknown'
370
+
371
+ body_element = comment_element.select_one('.comment-body')
372
+ date_element = comment_element.select_one('.comment-meta .meta-data')
373
+
374
+ comment_data = {
375
+ 'author': author_id,
376
+ 'body': body_element.get_text(strip=True) if body_element else '',
377
+ 'date': date_element.get_text(strip=True) if date_element else 'Unknown Date'
378
+ }
379
+
380
+ if comment_data not in comments:
381
+ comments.append(comment_data)
382
+ new_comments_found_on_page += 1
383
+
384
+ if new_comments_found_on_page == 0 and page_num > 1:
385
+ log(f"No new comments detected on page {page_num}. Ending extraction.", "INFO")
386
+ break
387
+
388
+ page_num += 1
389
+
390
+ log(f"Extracted {len(comments)} comments in total.", "SUCCESS")
391
+ return {
392
+ "success": True, "post": post_data, "comments": comments, "total_comments": len(comments)
393
+ }
394
+
395
+ except Exception as e:
396
+ log(f"Failed to read forum post: {str(e)}", "ERROR")
397
+ raise
398
+ finally:
399
+ if browser:
400
+ await browser.close()
401
+
402
+ # Initialize forum client
403
+ forum_client = ForumClient()
404
+
405
+ # The main block is for testing and won't be run by the MCP server.
406
+ if __name__ == "__main__":
407
+ print("📚 WorldQuant BRAIN Forum Functions - This script provides the ForumClient class.", file=sys.stderr)