histrategy 0.2.1__tar.gz

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 (339) hide show
  1. histrategy-0.2.1/.agent/skills/CONTRIBUTING.md +66 -0
  2. histrategy-0.2.1/.agent/skills/SKILL.md +75 -0
  3. histrategy-0.2.1/.coverage +0 -0
  4. histrategy-0.2.1/.dockerignore +54 -0
  5. histrategy-0.2.1/.env.example +46 -0
  6. histrategy-0.2.1/.gitignore +29 -0
  7. histrategy-0.2.1/.pre-commit-config.yaml +17 -0
  8. histrategy-0.2.1/CLAUDE.md +90 -0
  9. histrategy-0.2.1/CONTRIBUTING.md +309 -0
  10. histrategy-0.2.1/Dockerfile +29 -0
  11. histrategy-0.2.1/LICENSE +21 -0
  12. histrategy-0.2.1/PKG-INFO +20 -0
  13. histrategy-0.2.1/README-zh.md +132 -0
  14. histrategy-0.2.1/README.md +113 -0
  15. histrategy-0.2.1/demo/show-hn-v2-draft.md +25 -0
  16. histrategy-0.2.1/demo/show-hn-v2-final.md +31 -0
  17. histrategy-0.2.1/demo/v2-shu-10t.mp4 +0 -0
  18. histrategy-0.2.1/demo/v2-shu-gameplay.mp4 +0 -0
  19. histrategy-0.2.1/demo/zhihu-v2-draft.md +51 -0
  20. histrategy-0.2.1/demo/zhihu-v2-final.md +107 -0
  21. histrategy-0.2.1/docs/.gitkeep +0 -0
  22. histrategy-0.2.1/docs/OPERATIONS.md +232 -0
  23. histrategy-0.2.1/docs/ROADMAP.md +257 -0
  24. histrategy-0.2.1/docs/architecture/decision-cli-db-direct-mode.md +257 -0
  25. histrategy-0.2.1/docs/architecture/frontend-persistence.md +182 -0
  26. histrategy-0.2.1/docs/architecture-philosophy.md +154 -0
  27. histrategy-0.2.1/docs/archive/PRD-openclaw.md +326 -0
  28. histrategy-0.2.1/docs/archive/PRD.md +163 -0
  29. histrategy-0.2.1/docs/archive/asymmetric-loop-design.md +141 -0
  30. histrategy-0.2.1/docs/archive/design-p5-web-recording.md +237 -0
  31. histrategy-0.2.1/docs/archive/design-v2-implementation-plan.md +515 -0
  32. histrategy-0.2.1/docs/archive/design-v2-physics-engine.md +641 -0
  33. histrategy-0.2.1/docs/archive/design-v2-technical-spec.md +1243 -0
  34. histrategy-0.2.1/docs/archive/npc-ai-implementation-plan.md +63 -0
  35. histrategy-0.2.1/docs/archive/simply-v1-framework.md +312 -0
  36. histrategy-0.2.1/docs/archive/simply-v2-pluggable-framework.md +397 -0
  37. histrategy-0.2.1/docs/archive/tasks-v2-execution.md +160 -0
  38. histrategy-0.2.1/docs/archive/tasks-web-deployment.md +926 -0
  39. histrategy-0.2.1/docs/archive/tech-design-agent-clients.md +708 -0
  40. histrategy-0.2.1/docs/archive/tech-design-openclaw.md +683 -0
  41. histrategy-0.2.1/docs/archive/tech-design.md +338 -0
  42. histrategy-0.2.1/docs/decisions/h15m-shanhe-dingge-repo-decision.md +126 -0
  43. histrategy-0.2.1/docs/decisions/h15n-sdk-reload-vs-http-server.md +193 -0
  44. histrategy-0.2.1/docs/deployment-railway.md +27 -0
  45. histrategy-0.2.1/docs/design/engine-refactor-tech-design.md +310 -0
  46. histrategy-0.2.1/docs/design/macro-engine-market-analysis.md +161 -0
  47. histrategy-0.2.1/docs/design/macro-engine-prd.md +276 -0
  48. histrategy-0.2.1/docs/design/macro-engine-tech-design.md +457 -0
  49. histrategy-0.2.1/docs/design/multi-scenario-architecture.md +277 -0
  50. histrategy-0.2.1/docs/design/package-naming-and-pypi-strategy.md +144 -0
  51. histrategy-0.2.1/docs/design/refactor-engine-unification.md +401 -0
  52. histrategy-0.2.1/docs/design/state-complexity-vs-llm-hallucination.md +416 -0
  53. histrategy-0.2.1/docs/design/symmetric-multiplayer-engine.md +943 -0
  54. histrategy-0.2.1/docs/design/v1-v3-engine-design.md +223 -0
  55. histrategy-0.2.1/docs/design-h15g-core-vs-extensible-state.md +265 -0
  56. histrategy-0.2.1/docs/design-iterations.md +127 -0
  57. histrategy-0.2.1/docs/design-v3-llm-simulation.md +356 -0
  58. histrategy-0.2.1/docs/governance-engine-design.md +247 -0
  59. histrategy-0.2.1/docs/guide-custom-scenarios.md +183 -0
  60. histrategy-0.2.1/docs/macbook-local-setup.md +107 -0
  61. histrategy-0.2.1/docs/research-h15k-koei-numerical-systems.md +139 -0
  62. histrategy-0.2.1/histrategy/__init__.py +3 -0
  63. histrategy-0.2.1/histrategy/__main__.py +7 -0
  64. histrategy-0.2.1/histrategy/cli/__init__.py +1 -0
  65. histrategy-0.2.1/histrategy/cli/app.py +993 -0
  66. histrategy-0.2.1/histrategy/cli/dev_cli.py +437 -0
  67. histrategy-0.2.1/histrategy/cli/headless_cli.py +449 -0
  68. histrategy-0.2.1/histrategy/cli/record.py +686 -0
  69. histrategy-0.2.1/histrategy/cli/simulator.py +218 -0
  70. histrategy-0.2.1/histrategy/db/__init__.py +33 -0
  71. histrategy-0.2.1/histrategy/db/connection.py +465 -0
  72. histrategy-0.2.1/histrategy/db/file_backup.py +150 -0
  73. histrategy-0.2.1/histrategy/db/models.py +613 -0
  74. histrategy-0.2.1/histrategy/db/schema.sql +164 -0
  75. histrategy-0.2.1/histrategy/engine/__init__.py +9 -0
  76. histrategy-0.2.1/histrategy/engine/black_swan.py +152 -0
  77. histrategy-0.2.1/histrategy/engine/debug_logger.py +128 -0
  78. histrategy-0.2.1/histrategy/engine/decision_bus.py +324 -0
  79. histrategy-0.2.1/histrategy/engine/engine_switch.py +50 -0
  80. histrategy-0.2.1/histrategy/engine/faction_slot.py +167 -0
  81. histrategy-0.2.1/histrategy/engine/game.py +2722 -0
  82. histrategy-0.2.1/histrategy/engine/game_room.py +244 -0
  83. histrategy-0.2.1/histrategy/engine/guardrail.py +215 -0
  84. histrategy-0.2.1/histrategy/engine/knowledge_layer.py +143 -0
  85. histrategy-0.2.1/histrategy/engine/loader.py +614 -0
  86. histrategy-0.2.1/histrategy/engine/log_exporter.py +174 -0
  87. histrategy-0.2.1/histrategy/engine/macro_policy_engine.py +343 -0
  88. histrategy-0.2.1/histrategy/engine/narrative_director.py +172 -0
  89. histrategy-0.2.1/histrategy/engine/npc_events.py +100 -0
  90. histrategy-0.2.1/histrategy/engine/offline_sim.py +1029 -0
  91. histrategy-0.2.1/histrategy/engine/offline_sim_engine.py +139 -0
  92. histrategy-0.2.1/histrategy/engine/policy_evaluator.py +271 -0
  93. histrategy-0.2.1/histrategy/engine/quarterly_engine.py +284 -0
  94. histrategy-0.2.1/histrategy/engine/quarterly_resolver.py +482 -0
  95. histrategy-0.2.1/histrategy/engine/resilient_sim_engine.py +73 -0
  96. histrategy-0.2.1/histrategy/engine/scenario_loader.py +619 -0
  97. histrategy-0.2.1/histrategy/engine/state_applier.py +283 -0
  98. histrategy-0.2.1/histrategy/engine/v1_simulator.py +620 -0
  99. histrategy-0.2.1/histrategy/engine/world.py +348 -0
  100. histrategy-0.2.1/histrategy/engine/world_sim_interface.py +137 -0
  101. histrategy-0.2.1/histrategy/knowledge/__init__.py +1 -0
  102. histrategy-0.2.1/histrategy/knowledge/data/README.md +114 -0
  103. histrategy-0.2.1/histrategy/knowledge/data/arc_goals.json +82 -0
  104. histrategy-0.2.1/histrategy/knowledge/data/characters.json +242 -0
  105. histrategy-0.2.1/histrategy/knowledge/data/events.json +57 -0
  106. histrategy-0.2.1/histrategy/knowledge/data/factions.json +93 -0
  107. histrategy-0.2.1/histrategy/knowledge/data/regions.json +192 -0
  108. histrategy-0.2.1/histrategy/knowledge/data/schema.json +202 -0
  109. histrategy-0.2.1/histrategy/knowledge/data/schema.md +150 -0
  110. histrategy-0.2.1/histrategy/knowledge/scripts/validate_data.py +355 -0
  111. histrategy-0.2.1/histrategy/llm/__init__.py +1 -0
  112. histrategy-0.2.1/histrategy/llm/adapter.py +722 -0
  113. histrategy-0.2.1/histrategy/llm/advisor.py +309 -0
  114. histrategy-0.2.1/histrategy/llm/alignment.py +294 -0
  115. histrategy-0.2.1/histrategy/llm/endgame_summary.py +61 -0
  116. histrategy-0.2.1/histrategy/llm/game_master.py +574 -0
  117. histrategy-0.2.1/histrategy/llm/llm_sim_engine.py +65 -0
  118. histrategy-0.2.1/histrategy/llm/narrative.py +807 -0
  119. histrategy-0.2.1/histrategy/llm/npc_decision_engine.py +475 -0
  120. histrategy-0.2.1/histrategy/llm/npc_interpreter.py +177 -0
  121. histrategy-0.2.1/histrategy/llm/prompt_loader.py +60 -0
  122. histrategy-0.2.1/histrategy/llm/prompts/advisor.md +28 -0
  123. histrategy-0.2.1/histrategy/llm/prompts/alignment.md +38 -0
  124. histrategy-0.2.1/histrategy/llm/prompts/gamemaster_command.md +70 -0
  125. histrategy-0.2.1/histrategy/llm/prompts/gamemaster_command_en.md +70 -0
  126. histrategy-0.2.1/histrategy/llm/prompts/gamemaster_intro.md +41 -0
  127. histrategy-0.2.1/histrategy/llm/prompts/gamemaster_intro_en.md +41 -0
  128. histrategy-0.2.1/histrategy/llm/prompts/gamemaster_plan.md +40 -0
  129. histrategy-0.2.1/histrategy/llm/prompts/gamemaster_plan_en.md +40 -0
  130. histrategy-0.2.1/histrategy/llm/prompts/global_narrative.md +41 -0
  131. histrategy-0.2.1/histrategy/llm/prompts/global_narrative_en.md +43 -0
  132. histrategy-0.2.1/histrategy/llm/prompts/intent_parse.md +189 -0
  133. histrategy-0.2.1/histrategy/llm/prompts/macro_simulator.md +55 -0
  134. histrategy-0.2.1/histrategy/llm/prompts/narrative.md +43 -0
  135. histrategy-0.2.1/histrategy/llm/prompts/narrative_en.md +34 -0
  136. histrategy-0.2.1/histrategy/llm/prompts/npc_decision.md +113 -0
  137. histrategy-0.2.1/histrategy/llm/prompts/npc_decision_en.md +113 -0
  138. histrategy-0.2.1/histrategy/llm/prompts/npc_interpreter.md +32 -0
  139. histrategy-0.2.1/histrategy/llm/prompts/plan_suggestions.md +22 -0
  140. histrategy-0.2.1/histrategy/llm/prompts/policy_parse.md +36 -0
  141. histrategy-0.2.1/histrategy/llm/prompts/v1_simulator.md +118 -0
  142. histrategy-0.2.1/histrategy/llm/prompts/v1_simulator_en.md +102 -0
  143. histrategy-0.2.1/histrategy/llm/prompts/world_simulator.md +130 -0
  144. histrategy-0.2.1/histrategy/llm/world_simulator.py +288 -0
  145. histrategy-0.2.1/histrategy/parser/__init__.py +11 -0
  146. histrategy-0.2.1/histrategy/parser/intent.py +529 -0
  147. histrategy-0.2.1/histrategy/parser/validator.py +231 -0
  148. histrategy-0.2.1/histrategy/plugins/__init__.py +25 -0
  149. histrategy-0.2.1/histrategy/plugins/interface.py +206 -0
  150. histrategy-0.2.1/histrategy/plugins/registry.py +65 -0
  151. histrategy-0.2.1/histrategy/policy/__init__.py +13 -0
  152. histrategy-0.2.1/histrategy/policy/policy_parser.py +437 -0
  153. histrategy-0.2.1/histrategy/policy/policy_types.py +98 -0
  154. histrategy-0.2.1/histrategy/policy/policy_validator.py +74 -0
  155. histrategy-0.2.1/histrategy/server/__init__.py +1 -0
  156. histrategy-0.2.1/histrategy/server/api.py +1487 -0
  157. histrategy-0.2.1/histrategy/server/auth.py +52 -0
  158. histrategy-0.2.1/histrategy/server/persistence.py +130 -0
  159. histrategy-0.2.1/histrategy/server/persistence_adapter.py +323 -0
  160. histrategy-0.2.1/histrategy/server/room_manager.py +1483 -0
  161. histrategy-0.2.1/histrategy/server/single_player.py +406 -0
  162. histrategy-0.2.1/histrategy/state/__init__.py +5 -0
  163. histrategy-0.2.1/histrategy/state/npc_state.py +166 -0
  164. histrategy-0.2.1/histrategy/state/world_state.py +437 -0
  165. histrategy-0.2.1/histrategy/web/css/main.css +604 -0
  166. histrategy-0.2.1/histrategy/web/images/avatar_cao.png +0 -0
  167. histrategy-0.2.1/histrategy/web/images/avatar_shu.png +0 -0
  168. histrategy-0.2.1/histrategy/web/images/avatar_wu.png +0 -0
  169. histrategy-0.2.1/histrategy/web/images/histrategy-logo-scroll.png +0 -0
  170. histrategy-0.2.1/histrategy/web/images/histrategy-logo-scroll.svg +81 -0
  171. histrategy-0.2.1/histrategy/web/images/histrategy-logo.png +0 -0
  172. histrategy-0.2.1/histrategy/web/images/histrategy-logo.svg +100 -0
  173. histrategy-0.2.1/histrategy/web/index.html +40 -0
  174. histrategy-0.2.1/histrategy/web/js/api.js +53 -0
  175. histrategy-0.2.1/histrategy/web/js/game.js +262 -0
  176. histrategy-0.2.1/histrategy/web/js/ui.js +169 -0
  177. histrategy-0.2.1/histrategy/web/manual.html +297 -0
  178. histrategy-0.2.1/histrategy/web/mp.html +557 -0
  179. histrategy-0.2.1/histrategy-agent/pyproject.toml +22 -0
  180. histrategy-0.2.1/histrategy-agent/skills/hermes/SKILL.md +164 -0
  181. histrategy-0.2.1/histrategy-agent/skills/hermes/scripts/__init__.py +1 -0
  182. histrategy-0.2.1/histrategy-agent/skills/hermes/scripts/commands.py +209 -0
  183. histrategy-0.2.1/histrategy-agent/skills/hermes/scripts/entry.py +147 -0
  184. histrategy-0.2.1/histrategy-agent/skills/hermes/scripts/session_manager.py +66 -0
  185. histrategy-0.2.1/histrategy-agent/skills/histrategy-sdk/SKILL.md +265 -0
  186. histrategy-0.2.1/histrategy-agent/skills/openclaw/SKILL.md +220 -0
  187. histrategy-0.2.1/histrategy-agent/skills/openclaw/scripts/entry.py +158 -0
  188. histrategy-0.2.1/histrategy-agent/skills/rule-contribution/SKILL.md +101 -0
  189. histrategy-0.2.1/histrategy-agent/src/histrategy_agent/__init__.py +25 -0
  190. histrategy-0.2.1/histrategy-agent/src/histrategy_agent/format_engine.py +258 -0
  191. histrategy-0.2.1/histrategy-agent/src/histrategy_agent/im_adapters/__init__.py +6 -0
  192. histrategy-0.2.1/histrategy-agent/src/histrategy_agent/im_adapters/base.py +42 -0
  193. histrategy-0.2.1/histrategy-agent/src/histrategy_agent/im_adapters/feishu.py +445 -0
  194. histrategy-0.2.1/histrategy-agent/src/histrategy_agent/llm_adapter.py +188 -0
  195. histrategy-0.2.1/histrategy-agent/src/histrategy_agent/multiplayer.py +262 -0
  196. histrategy-0.2.1/histrategy-agent/src/histrategy_agent/session.py +418 -0
  197. histrategy-0.2.1/histrategy-agent/src/histrategy_agent/state_bridge.py +611 -0
  198. histrategy-0.2.1/histrategy-agent/src/histrategy_agent/turn_processor.py +549 -0
  199. histrategy-0.2.1/histrategy-agent/tests/__init__.py +0 -0
  200. histrategy-0.2.1/histrategy-agent/tests/conftest.py +18 -0
  201. histrategy-0.2.1/histrategy-agent/tests/test_feishu_adapter.py +235 -0
  202. histrategy-0.2.1/histrategy-agent/tests/test_format_engine.py +285 -0
  203. histrategy-0.2.1/histrategy-agent/tests/test_multiplayer.py +302 -0
  204. histrategy-0.2.1/histrategy-agent/tests/test_session.py +196 -0
  205. histrategy-0.2.1/histrategy-agent/tests/test_state_bridge.py +187 -0
  206. histrategy-0.2.1/histrategy-agent/tests/test_turn_processor.py +236 -0
  207. histrategy-0.2.1/histrategy-engine/pyproject.toml +48 -0
  208. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/__init__.py +71 -0
  209. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/ai/__init__.py +348 -0
  210. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/ai/fog_of_war.py +354 -0
  211. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/ai/npc_planner.py +358 -0
  212. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/ai/recon.py +84 -0
  213. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/character/__init__.py +227 -0
  214. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/character/loyalty.py +10 -0
  215. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/domestic/__init__.py +504 -0
  216. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/domestic/grain.py +8 -0
  217. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/governance/__init__.py +0 -0
  218. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/governance/legitimacy.py +21 -0
  219. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/history/__init__.py +503 -0
  220. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/history/rag.py +145 -0
  221. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/map/__init__.py +244 -0
  222. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/military/__init__.py +470 -0
  223. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/military/sabotage.py +235 -0
  224. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/rules/__init__.py +1 -0
  225. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/rules/economy.yaml +61 -0
  226. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/rules/historical_events.yaml +27 -0
  227. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/rules/interpreter.py +143 -0
  228. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/turn/__init__.py +604 -0
  229. histrategy-0.2.1/histrategy-engine/src/histrategy_engine/world/__init__.py +534 -0
  230. histrategy-0.2.1/histrategy-engine/tests/test_balance_and_legitimacy.py +251 -0
  231. histrategy-0.2.1/histrategy-engine/tests/test_character_loyalty.py +20 -0
  232. histrategy-0.2.1/histrategy-engine/tests/test_domestic_grain.py +16 -0
  233. histrategy-0.2.1/histrategy-engine/tests/test_e2e_headless.py +3624 -0
  234. histrategy-0.2.1/histrategy-engine/tests/test_engines.py +580 -0
  235. histrategy-0.2.1/histrategy-engine/tests/test_fog_of_war.py +364 -0
  236. histrategy-0.2.1/histrategy-engine/tests/test_governance_legitimacy.py +23 -0
  237. histrategy-0.2.1/histrategy-engine/tests/test_military_sabotage.py +251 -0
  238. histrategy-0.2.1/histrategy-engine/tests/test_npc_fow.py +359 -0
  239. histrategy-0.2.1/histrategy-engine/tests/test_npc_planner.py +214 -0
  240. histrategy-0.2.1/histrategy-engine/tests/test_p2.py +1449 -0
  241. histrategy-0.2.1/histrategy-engine/tests/test_p3.py +934 -0
  242. histrategy-0.2.1/histrategy-engine/tests/test_p4.py +769 -0
  243. histrategy-0.2.1/histrategy-engine/tests/test_recon.py +54 -0
  244. histrategy-0.2.1/histrategy-engine/tests/test_rules_interpreter.py +303 -0
  245. histrategy-0.2.1/histrategy-knowledge/characters/207_roster.json +282 -0
  246. histrategy-0.2.1/histrategy-knowledge/geography/territories.json +166 -0
  247. histrategy-0.2.1/histrategy-knowledge/scenarios/207_liubei.json +279 -0
  248. histrategy-0.2.1/histrategy-knowledge/scenarios/207_reference.md +131 -0
  249. histrategy-0.2.1/histrategy-knowledge/schema/event.schema.json +20 -0
  250. histrategy-0.2.1/histrategy-knowledge/timeline/207-223.json +483 -0
  251. histrategy-0.2.1/histrategy-sdk/README.md +113 -0
  252. histrategy-0.2.1/histrategy-sdk/pyproject.toml +36 -0
  253. histrategy-0.2.1/histrategy-sdk/src/histrategy_sdk/__init__.py +112 -0
  254. histrategy-0.2.1/histrategy-sdk/src/histrategy_sdk/_client.py +346 -0
  255. histrategy-0.2.1/histrategy-sdk/src/histrategy_sdk/_engine.py +287 -0
  256. histrategy-0.2.1/histrategy-sdk/src/histrategy_sdk/_mp_room.py +265 -0
  257. histrategy-0.2.1/histrategy-sdk/src/histrategy_sdk/_room.py +270 -0
  258. histrategy-0.2.1/histrategy-sdk/src/histrategy_sdk/exceptions.py +33 -0
  259. histrategy-0.2.1/histrategy-sdk/src/histrategy_sdk/types.py +124 -0
  260. histrategy-0.2.1/histrategy-sdk/tests/__init__.py +0 -0
  261. histrategy-0.2.1/histrategy-sdk/tests/conftest.py +110 -0
  262. histrategy-0.2.1/histrategy-sdk/tests/test_mp_integration.py +305 -0
  263. histrategy-0.2.1/pyproject.toml +61 -0
  264. histrategy-0.2.1/references/2024-nottingham-llms-and-games.md +110 -0
  265. histrategy-0.2.1/references/2026-jenova-ai-narrative-game.md +246 -0
  266. histrategy-0.2.1/rooms/test_room_alpha/world_v2.json +143 -0
  267. histrategy-0.2.1/scenarios/rome-triumvirate/knowledge/arc_goals.json +127 -0
  268. histrategy-0.2.1/scenarios/rome-triumvirate/knowledge/characters.json +300 -0
  269. histrategy-0.2.1/scenarios/rome-triumvirate/knowledge/events.json +211 -0
  270. histrategy-0.2.1/scenarios/rome-triumvirate/knowledge/factions.json +97 -0
  271. histrategy-0.2.1/scenarios/rome-triumvirate/knowledge/initial_state.json +350 -0
  272. histrategy-0.2.1/scenarios/rome-triumvirate/knowledge/regions.json +202 -0
  273. histrategy-0.2.1/scenarios/rome-triumvirate/knowledge/roster.json +30 -0
  274. histrategy-0.2.1/scenarios/rome-triumvirate/knowledge/schema.json +4 -0
  275. histrategy-0.2.1/scenarios/rome-triumvirate/knowledge/territories.json +188 -0
  276. histrategy-0.2.1/scenarios/rome-triumvirate/knowledge/timeline.json +184 -0
  277. histrategy-0.2.1/scenarios/rome-triumvirate/npc_decisions_q0.json +305 -0
  278. histrategy-0.2.1/scenarios/rome-triumvirate/prompts/macro_simulator_en.md +21 -0
  279. histrategy-0.2.1/scenarios/rome-triumvirate/prompts/macro_simulator_zh-CN.md +20 -0
  280. histrategy-0.2.1/scenarios/rome-triumvirate/prompts/narrative_en.md +18 -0
  281. histrategy-0.2.1/scenarios/rome-triumvirate/prompts/npc_decision_en.md +36 -0
  282. histrategy-0.2.1/scenarios/rome-triumvirate/prompts/npc_decision_zh-CN.md +36 -0
  283. histrategy-0.2.1/scenarios/rome-triumvirate/prompts/system.md +56 -0
  284. histrategy-0.2.1/scenarios/rome-triumvirate/prompts/system.zh-CN.md +56 -0
  285. histrategy-0.2.1/scenarios/rome-triumvirate/prompts/v1_simulator_en.md +58 -0
  286. histrategy-0.2.1/scenarios/rome-triumvirate/rules/naval.yaml +63 -0
  287. histrategy-0.2.1/scenarios/rome-triumvirate/scenario.toml +58 -0
  288. histrategy-0.2.1/scenarios/shanhe-dingge/scenario.toml +55 -0
  289. histrategy-0.2.1/scenarios/three-kingdoms/knowledge/arc_goals.json +82 -0
  290. histrategy-0.2.1/scenarios/three-kingdoms/knowledge/characters.json +242 -0
  291. histrategy-0.2.1/scenarios/three-kingdoms/knowledge/events.json +57 -0
  292. histrategy-0.2.1/scenarios/three-kingdoms/knowledge/factions.json +98 -0
  293. histrategy-0.2.1/scenarios/three-kingdoms/knowledge/initial_state.json +284 -0
  294. histrategy-0.2.1/scenarios/three-kingdoms/knowledge/regions.json +192 -0
  295. histrategy-0.2.1/scenarios/three-kingdoms/knowledge/roster.json +282 -0
  296. histrategy-0.2.1/scenarios/three-kingdoms/knowledge/schema.json +202 -0
  297. histrategy-0.2.1/scenarios/three-kingdoms/knowledge/territories.json +289 -0
  298. histrategy-0.2.1/scenarios/three-kingdoms/knowledge/timeline.json +483 -0
  299. histrategy-0.2.1/scenarios/three-kingdoms/npc_decisions_q0.json +260 -0
  300. histrategy-0.2.1/scenarios/three-kingdoms/scenario.toml +61 -0
  301. histrategy-0.2.1/scripts/demo_instructions.py +61 -0
  302. histrategy-0.2.1/scripts/e2e_experience.py +72 -0
  303. histrategy-0.2.1/scripts/e2e_macro_caocao.py +88 -0
  304. histrategy-0.2.1/scripts/e2e_macro_liubei.py +89 -0
  305. histrategy-0.2.1/scripts/e2e_macro_sunquan.py +88 -0
  306. histrategy-0.2.1/scripts/e2e_multiplayer.py +151 -0
  307. histrategy-0.2.1/scripts/e2e_rome_octavian.py +120 -0
  308. histrategy-0.2.1/scripts/e2e_symmetric.py +320 -0
  309. histrategy-0.2.1/scripts/feishu_bridge.py +139 -0
  310. histrategy-0.2.1/scripts/feishu_bridge_v2.py +229 -0
  311. histrategy-0.2.1/scripts/feishu_bridge_v3.py +218 -0
  312. histrategy-0.2.1/scripts/install_hooks.sh +17 -0
  313. histrategy-0.2.1/scripts/prebake_npc_decisions.py +129 -0
  314. histrategy-0.2.1/scripts/record_12rounds.py +115 -0
  315. histrategy-0.2.1/scripts/record_asciinema.py +104 -0
  316. histrategy-0.2.1/scripts/record_demo.py +177 -0
  317. histrategy-0.2.1/scripts/record_playtest.py +105 -0
  318. histrategy-0.2.1/scripts/script2svg.py +107 -0
  319. histrategy-0.2.1/scripts/verify_sdk_multipayer.py +267 -0
  320. histrategy-0.2.1/sprints/2026-05-23-ai-native-historical-strategy-design.md +346 -0
  321. histrategy-0.2.1/sprints/2026-05-23-llm-game-master-redesign.md +83 -0
  322. histrategy-0.2.1/tests/test_advisor.py +137 -0
  323. histrategy-0.2.1/tests/test_alignment.py +196 -0
  324. histrategy-0.2.1/tests/test_cli_room.py +44 -0
  325. histrategy-0.2.1/tests/test_cli_simulator.py +62 -0
  326. histrategy-0.2.1/tests/test_e2e.py +209 -0
  327. histrategy-0.2.1/tests/test_e2e_liubiao_llm.py +206 -0
  328. histrategy-0.2.1/tests/test_endgame_summary.py +32 -0
  329. histrategy-0.2.1/tests/test_engine.py +698 -0
  330. histrategy-0.2.1/tests/test_intent_parser.py +252 -0
  331. histrategy-0.2.1/tests/test_llm_context.py +153 -0
  332. histrategy-0.2.1/tests/test_macro_engine.py +596 -0
  333. histrategy-0.2.1/tests/test_narrative_context.py +141 -0
  334. histrategy-0.2.1/tests/test_orchestrator_integration.py +210 -0
  335. histrategy-0.2.1/tests/test_record.py +56 -0
  336. histrategy-0.2.1/tests/test_server.py +436 -0
  337. histrategy-0.2.1/tests/test_symmetric_engine.py +702 -0
  338. histrategy-0.2.1/tests/test_v3_modules.py +590 -0
  339. histrategy-0.2.1/uv.lock +478 -0
@@ -0,0 +1,66 @@
1
+ # Agent Contribution Guide — 三國志略
2
+
3
+ Short-form guide for AI coding agents (Hermes, Claude Code, etc.) working on this project. See root `CONTRIBUTING.md` for the human version.
4
+
5
+ ## Quick-Start for Agents
6
+
7
+ ```bash
8
+ # Install
9
+ pip install -e .
10
+
11
+ # Run tests (must pass before submitting)
12
+ pytest tests/ -v
13
+
14
+ # Play-test dev mode
15
+ histrategy --dev
16
+ ```
17
+
18
+ ## What Goes Where
19
+
20
+ | Concern | Location |
21
+ |---|---|
22
+ | LLM integration (prompts, API calls, Game Master) | `histrategy/llm/` |
23
+ | Game engine (turn logic, Plan/Command modes) | `histrategy/engine/` |
24
+ | State management (WorldState, persistence) | `histrategy/state/` |
25
+ | Terminal UI (Rich TUI, dev CLI) | `histrategy/cli/` |
26
+ | Historical knowledge (characters, factions, events) | `histrategy/knowledge/data/` |
27
+ | Tests | `tests/` |
28
+
29
+ ## Code Conventions
30
+
31
+ - Python 3.10+, type hints on all public functions
32
+ - Google-style docstrings on public API only
33
+ - No comments unless the WHY is non-obvious
34
+ - Imports: stdlib → third-party → first-party, blank line between groups
35
+ - Use `ruff` for linting
36
+ - Use `dict[str, int]` not `Dict[str, int]`
37
+
38
+ ## Architecture Constraints
39
+
40
+ **DO NOT:**
41
+ - Write Python string templates for advisor speeches, suggestions, consequences, or NPC actions — those come from the LLM
42
+ - Hardcode game data in Python — it lives in `histrategy/knowledge/data/*.json`
43
+ - Skip tests — `pytest tests/` must pass before every commit
44
+
45
+ **DO:**
46
+ - Use `WorldState` dataclass for all state, with `to_dict()` / `from_dict()` for persistence
47
+ - Keep Plan Mode (council/what-to-do) and Command Mode (execution/how-it-goes) separate
48
+ - Reference `schema.json` before editing any data file
49
+ - Validate data changes: `python histrategy/knowledge/scripts/validate_data.py`
50
+
51
+ ## Data File Editing
52
+
53
+ When adding to `histrategy/knowledge/data/`:
54
+
55
+ 1. Read `histrategy/knowledge/data/schema.json` first — it defines required fields, types, and allowed values
56
+ 2. Use snake_case IDs (e.g. `cao_cao`, `guan_yu`)
57
+ 3. Ensure cross-file references are consistent: `characters.faction` → `factions.id`, `factions.ruler_id` → `characters.id`, `regions.neighbors` → `regions.id`
58
+
59
+ ## Key Files to Read Before Starting
60
+
61
+ - `CLAUDE.md` — project context and architecture requirements
62
+ - `docs/PRD.md` — product vision
63
+ - `docs/tech-design.md` — architecture and data flow
64
+ - `histrategy/llm/game_master.py` — LLM-powered Game Master
65
+ - `histrategy/state/world_state.py` — state data structures
66
+ - `README.md` — overview and quick-start
@@ -0,0 +1,75 @@
1
+ # SKILL.md — Agent Instructions for 三國志略
2
+
3
+ Instructions for AI coding agents (Claude Code, Hermes, Cursor, etc.) contributing to this project.
4
+
5
+ ## Project Identity
6
+
7
+ **三國志略 (Histrategy)** — An open-source, AI-powered text-based Three Kingdoms strategy game. The LLM is the game engine, not a narrator over pre-computed results.
8
+
9
+ ## Agent Workflow
10
+
11
+ ### Before Writing Code
12
+
13
+ 1. Read `CLAUDE.md` for critical architecture context and current priorities
14
+ 2. Read `docs/PRD.md` and `docs/tech-design.md` for product vision and architecture
15
+ 3. Understand the Plan/Command two-tier architecture before touching engine code
16
+ 4. Check `histrategy/knowledge/data/schema.json` before editing any JSON data file
17
+
18
+ ### While Writing Code
19
+
20
+ - **Test-first**: Write or update tests alongside code changes
21
+ - **LLM-first**: All advisor speeches, suggestions, consequences, and NPC actions come from the LLM layer — never write Python string templates for game content
22
+ - **State-first**: Use `WorldState` dataclasses. All state is serializable via `to_dict()` / `from_dict()`
23
+ - **Minimal changes**: Don't refactor or add abstractions beyond what the task requires. No half-finished implementations.
24
+
25
+ ### Before Submitting
26
+
27
+ ```bash
28
+ # 1. Run full test suite
29
+ pytest tests/ -v
30
+
31
+ # 2. Validate knowledge base (if data files changed)
32
+ python histrategy/knowledge/scripts/validate_data.py
33
+
34
+ # 3. Smoke test dev mode
35
+ histrategy --dev --new
36
+ ```
37
+
38
+ ## What to Avoid
39
+
40
+ - **DO NOT** write hardcoded template functions (`_generate_*`, `_format_*`, `_compute_*`) for game narrative
41
+ - **DO NOT** add comments explaining what code does — well-named identifiers do that
42
+ - **DO NOT** add error handling for scenarios that can't happen — trust internal code and framework guarantees
43
+ - **DO NOT** create documentation files unless explicitly requested
44
+ - **DO NOT** use backwards-compatibility shims or keep unused code — delete it
45
+
46
+ ## Project Layout (Quick Reference)
47
+
48
+ ```
49
+ histrategy/engine/ # Game engine (game.py, advisors.py, command.py)
50
+ histrategy/llm/ # LLM layer (game_master.py, adapter.py, prompts.py)
51
+ histrategy/state/ # Game state (world_state.py)
52
+ histrategy/cli/ # Terminal UI (app.py for Rich TUI, dev_cli.py for --dev)
53
+ histrategy/knowledge/ # Historical data (data/*.json, scripts/validate_data.py)
54
+ docs/ # Design docs (PRD.md, tech-design.md)
55
+ tests/ # Pytest suite (test_engine.py, test_e2e.py)
56
+ ```
57
+
58
+ ## Module Purposes
59
+
60
+ | Module | Purpose |
61
+ |---|---|
62
+ | `engine/game.py` | Game orchestrator — turn loop, Plan/Command mode dispatch |
63
+ | `engine/advisors.py` | Plan Mode: advisor generation, 4 strategic suggestions |
64
+ | `engine/command.py` | Command Mode: bureaucracy execution, seed system |
65
+ | `engine/offline_sim.py` | Rule-based fallback when no LLM API key |
66
+ | `llm/game_master.py` | LLM-powered Game Master — generates plan mode, command mode, NPC moves |
67
+ | `llm/adapter.py` | Multi-provider LLM client (DeepSeek, OpenAI, Tongyi, OpenRouter) |
68
+ | `llm/prompts.py` | System prompt templates for LLM calls |
69
+ | `state/world_state.py` | `WorldState` / `FactionState` dataclasses with JSON persistence |
70
+ | `cli/app.py` | Rich terminal UI (colors, panels, layout) |
71
+ | `cli/dev_cli.py` | Plain-text dev mode for testing (--dev flag) |
72
+
73
+ ## Commit Style
74
+
75
+ Follow the existing commit convention: short Chinese + English prefix describing the change (e.g. `H24a: Rich TUI refactor — unified LLM GameMaster display`). Commits are co-authored with the AI agent that produced them.
Binary file
@@ -0,0 +1,54 @@
1
+ # Python cache
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ .venv/
8
+ venv/
9
+
10
+ # IDE
11
+ .vscode/
12
+ .idea/
13
+ *.swp
14
+
15
+ # OS
16
+ .DS_Store
17
+ Thumbs.db
18
+
19
+ # Game saves
20
+ .histrategy/
21
+ .histrategy-playtest/
22
+
23
+ # Environment
24
+ .env
25
+ .env.local
26
+
27
+ # Logs and temp
28
+ logs/
29
+ scratch/
30
+ *.log
31
+
32
+ # Tests (not needed in production)
33
+ .pytest_cache/
34
+ tests/
35
+ histrategy-engine/tests/
36
+ **/test_*.py
37
+
38
+ # Git
39
+ .git/
40
+ .gitignore
41
+
42
+ # Misc
43
+ rooms/
44
+ references/
45
+ publications/
46
+ sprints/
47
+ scripts/
48
+ docs/
49
+ CLAUDE.md
50
+ CONTRIBUTING.md
51
+ README.md
52
+ LICENSE
53
+ .pre-commit-config.yaml
54
+ .ruff_cache/
@@ -0,0 +1,46 @@
1
+ # ─── LLM Provider Configuration ───────────────────────────────
2
+ # Three-path design — pick ONE of the following approaches:
3
+ #
4
+ # Path 1 (zero-config): Set a provider-specific API key.
5
+ # The URL and model are auto-configured for you.
6
+ # Pick ONE:
7
+ DEEPSEEK_API_KEY='sk-...'
8
+ # OPENAI_API_KEY='sk-...'
9
+ # TONGYI_API_KEY='sk-...'
10
+ # OPENROUTER_API_KEY='sk-...'
11
+ #
12
+ # Optionally override auto-detected settings:
13
+ # LLM_MODEL='deepseek-v4-pro'
14
+ # OPENAI_API_BASE='https://api.deepseek.com' # override a provider's base URL
15
+ #
16
+ # Path 2 (full control): Set a generic OpenAI-compatible endpoint.
17
+ # No provider auto-detection — you supply everything.
18
+ # LLM_API_BASE='https://api.openai.com/v1'
19
+ # LLM_API_KEY='sk-...'
20
+ # LLM_MODEL='gpt-4o-mini'
21
+ #
22
+ # Path 3 (legacy): OPENAI_API_BASE + OPENAI_API_KEY
23
+ # Still supported but Path 2 (LLM_API_BASE + LLM_API_KEY) is preferred.
24
+
25
+ # ─── Engine Version ────────────────────────────────────────────
26
+ # v1 = original (legacy), v3 = new hybrid engine (recommended)
27
+ HISTRATEGY_ENGINE=v3
28
+
29
+ # ─── Scenario ──────────────────────────────────────────────────
30
+ # Default scenario ID. Available scenarios:
31
+ # three-kingdoms — 三國志略 (AD 207, Cao/Shu/Wu/LiuBiao)
32
+ # caesar-44bc — 凯撒余烬 Ashes of Caesar (44 BC, Octavian/Antony/Cleopatra/Senate)
33
+ # shanhe-dingge — 山河鼎革 (AD 1644, Ming/Qing transition)
34
+ # HISTRATEGY_SCENARIO=caesar-44bc
35
+
36
+ # ─── Data Directory ────────────────────────────────────────────
37
+ # Game saves and state (default: ~/.histrategy/)
38
+ # HISTRATEGY_DATA_DIR=~/.histrategy
39
+
40
+ # ─── Server ────────────────────────────────────────────────────
41
+ # Start the Web UI multiplayer server:
42
+ # python3 -c "from histrategy.server.api import run_server; run_server(host='0.0.0.0', port=8080)"
43
+ # Then open: http://localhost:8080/mp?scenario=caesar-44bc
44
+ # Or use the CLI:
45
+ # histrategy
46
+ # histrategy --dev --faction 2 --new
@@ -0,0 +1,29 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ .venv/
8
+ venv/
9
+
10
+ # IDE
11
+ .vscode/
12
+ .idea/
13
+ *.swp
14
+
15
+ # OS
16
+ .DS_Store
17
+ Thumbs.db
18
+
19
+ # Game saves
20
+ .histrategy/
21
+ .histrategy-playtest/
22
+
23
+ # Environment
24
+ .env
25
+ .env.local
26
+ logs
27
+ scratch
28
+ publications
29
+ histrategy.db
@@ -0,0 +1,17 @@
1
+ repos:
2
+ - repo: https://github.com/astral-sh/ruff-pre-commit
3
+ rev: v0.15.14
4
+ hooks:
5
+ - id: ruff
6
+ args: [--fix]
7
+ - id: ruff-format
8
+ - repo: local
9
+ hooks:
10
+ - id: pytest
11
+ name: pytest (unit tests)
12
+ entry: python -m pytest tests/ -q --tb=short
13
+ language: system
14
+ pass_filenames: false
15
+ always_run: true
16
+ stages: [pre-push]
17
+ minimum_pre_commit_version: 3.0.0
@@ -0,0 +1,90 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ 三國志略 (Histrategy) is an AI-powered Three Kingdoms strategy game where the LLM acts as the game engine — generating advisor speeches, strategic suggestions, consequences, and NPC actions based on actual world state. Offline/fallback mode uses a rule-based simulation.
8
+
9
+ ## Commands
10
+
11
+ ```bash
12
+ # Install in dev mode
13
+ pip install -e .
14
+
15
+ # Run the game (auto-detects API key, falls back to offline mode)
16
+ histrategy
17
+ histrategy --dev # plain-text dev mode
18
+ histrategy --dev --faction 2 --new # skip faction select, force new game
19
+
20
+ # Run all tests
21
+ pytest tests/ -v
22
+
23
+ # Run a specific test file or class
24
+ pytest tests/test_engine.py -v
25
+ pytest tests/test_engine.py::TestSimulation -v
26
+
27
+ # Lint and format (ruff)
28
+ ruff check .
29
+ ruff format .
30
+
31
+ # Validate knowledge base JSON data
32
+ python histrategy/knowledge/scripts/validate_data.py
33
+
34
+ # Pre-push hooks (ruff lint+format, then pytest unit tests)
35
+ pre-commit run --hook-stage pre-push
36
+ ```
37
+
38
+ ## Architecture
39
+
40
+ ### Game Flow (Plan/Command two-phase)
41
+
42
+ ```
43
+ Plan Mode (LLM) → Player decision (free text) → Command Mode (LLM)
44
+ ```
45
+
46
+ - **Plan Mode** — `GameMaster.generate_plan_mode()` generates advisor court + 4 strategic suggestions from LLM
47
+ - **Player** types free-text decision (or `plan` to re-enter plan, `state` to view world, `exit` to quit)
48
+ - **Command Mode** — `GameMaster.generate_command_mode()` generates bureaucracy execution, consequences, NPC reactions, updated world state
49
+
50
+ ### Key Layers
51
+
52
+ | Layer | Key Files | Responsibility |
53
+ |-------|-----------|----------------|
54
+ | **CLI** | `cli/app.py`, `cli/dev_cli.py` | Rich TUI / plain-text I/O, orchestrates game loop |
55
+ | **Engine** | `engine/game.py`, `engine/offline_sim.py` | GameEngine orchestrator, offline fallback simulation |
56
+ | **LLM** | `llm/game_master.py`, `llm/adapter.py` | GameMaster (Intro/Plan/Command), multi-provider API client |
57
+ | **State** | `state/world_state.py` | `WorldState` dataclass with JSON persistence |
58
+ | **Knowledge** | `knowledge/data/*.json` | Characters, factions, regions, events as structured JSON |
59
+
60
+ ### Two Game Engines
61
+
62
+ - **`GameEngine`** (in `engine/game.py`) — the primary orchestrator. Uses `GameMaster` (LLM) when an API key is available, otherwise falls back to `offline_sim`.
63
+ - **`GameWorld`** (in `engine/world.py`) — legacy class used only by `offline_sim`. Not used in LLM mode.
64
+
65
+ ### LLM Integration
66
+
67
+ - **`GameMaster`** (in `llm/game_master.py`) — current unified implementation with game intro, Plan Mode, and Command Mode. Used by `cli/app.py` and `cli/dev_cli.py`.
68
+
69
+ ### LLM Provider Detection
70
+
71
+ `LLMAdapter` in `llm/adapter.py` auto-detects the best available provider via a three-path design:
72
+
73
+ 1. **Provider-specific key** — Set ONE of `DEEPSEEK_API_KEY`, `OPENAI_API_KEY`, `TONGYI_API_KEY`, or `OPENROUTER_API_KEY`. URL and model are auto-configured.
74
+ 2. **Generic endpoint** — Set `LLM_API_BASE` + `LLM_API_KEY`. Use `LLM_MODEL` to override the model.
75
+ 3. **No key** → offline (rule-based) mode.
76
+
77
+ ### State Persistence
78
+
79
+ `WorldState` dataclasses save to `~/.histrategy/` (or `$HISTRATEGY_DATA_DIR`) as JSON. Multiple files track world state, player memory, faction relationships, event history, and character profiles.
80
+
81
+ ### Key Design Rules
82
+
83
+ - **LLM is the game engine** — advisor speeches, suggestions, consequences, NPC actions come from LLM, not Python templates. Templates only as offline fallback.
84
+ - **State is serializable** — `WorldState` with `to_dict()`/`from_dict()` for persistence and LLM context building.
85
+ - **Plan/Command separation** — Plan = council meeting (what to do). Command = execution (how it goes).
86
+ - **Knowledge lives in JSON** — characters, factions, regions, events are data, not code.
87
+ - **Tests use isolated save dirs** — `HISTRATEGY_DATA_DIR` is monkeypatched to `tmp_path` in tests.
88
+ - **Rules-as-Data (rules in YAML)** — Formula configuration is externalized in YAML templates, parsed by the rules interpreter (supporting diverse era settings).
89
+ - **Asymmetric NPC AI (Fog of War)** — NPCs evaluate threats and plan strategies using projected LocalWorldStates, Heuristics, and LLM Monarch Planners.
90
+ - **AI Playtesting** — Automated multi-agent headless simulations verify game balance and tuning statistics.