guanwei 1.1.1

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 (157) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +202 -0
  3. package/README.md +247 -0
  4. package/dist/assets/index-CsOD5rSo.js +102 -0
  5. package/dist/assets/index-CsOD5rSo.js.map +1 -0
  6. package/dist/assets/index-DQx62TUr.css +1 -0
  7. package/dist/favicon.svg +12 -0
  8. package/dist/index.html +15 -0
  9. package/eslint.config.js +28 -0
  10. package/index.html +25 -0
  11. package/package.json +96 -0
  12. package/postcss.config.js +10 -0
  13. package/public/favicon.svg +12 -0
  14. package/scripts/guanwei +245 -0
  15. package/scripts/install.sh +79 -0
  16. package/scripts/release.sh +42 -0
  17. package/scripts/setup.bat +36 -0
  18. package/scripts/setup.sh +123 -0
  19. package/server/src/data/db.json +12059 -0
  20. package/server/src/data/guanwei.db +0 -0
  21. package/server/src/data/lifeContext.ts +423 -0
  22. package/server/src/data/spreads.ts +255 -0
  23. package/server/src/data/tarotCards.ts +2353 -0
  24. package/server/src/index.ts +71 -0
  25. package/server/src/routes/ai.ts +376 -0
  26. package/server/src/routes/divine.ts +140 -0
  27. package/server/src/routes/hour.ts +40 -0
  28. package/server/src/routes/tarot.ts +129 -0
  29. package/server/src/routes/users.ts +140 -0
  30. package/server/src/services/chartBrief.ts +131 -0
  31. package/server/src/services/divineStore.ts +188 -0
  32. package/server/src/services/hourInference.ts +150 -0
  33. package/server/src/services/llmProvider.ts +181 -0
  34. package/server/src/services/promptBuilder.ts +327 -0
  35. package/server/src/services/relativesCheck.ts +139 -0
  36. package/server/src/services/sixRelatives.ts +70 -0
  37. package/server/src/services/skills.ts +116 -0
  38. package/server/src/types/index.ts +104 -0
  39. package/server/src/utils/semanticAnalyzer.ts +555 -0
  40. package/server/src/utils/tarotEngine.ts +849 -0
  41. package/server/tsconfig.json +18 -0
  42. package/shared/core/data/classics.ts +276 -0
  43. package/shared/core/data/courses.ts +211 -0
  44. package/shared/core/data/duanyu.ts +148 -0
  45. package/shared/core/data/ganzhi.ts +53 -0
  46. package/shared/core/data/gua64.ts +93 -0
  47. package/shared/core/data/liuren.ts +18 -0
  48. package/shared/core/data/liuyao.ts +73 -0
  49. package/shared/core/data/qimen.ts +27 -0
  50. package/shared/core/data/region-full.ts +3 -0
  51. package/shared/core/data/region.ts +310 -0
  52. package/shared/core/data/tarotSpreads.ts +78 -0
  53. package/shared/core/data/xiaoliuren.ts +18 -0
  54. package/shared/core/data/ziwei.ts +97 -0
  55. package/shared/core/data/zodiac.ts +20 -0
  56. package/shared/core/engine/astrology.ts +169 -0
  57. package/shared/core/engine/bazi.ts +306 -0
  58. package/shared/core/engine/calendar.ts +127 -0
  59. package/shared/core/engine/daily.ts +133 -0
  60. package/shared/core/engine/liuren.ts +86 -0
  61. package/shared/core/engine/liuyao.ts +93 -0
  62. package/shared/core/engine/meihua.ts +87 -0
  63. package/shared/core/engine/qimen.ts +78 -0
  64. package/shared/core/engine/questionFit.ts +94 -0
  65. package/shared/core/engine/tarot.ts +69 -0
  66. package/shared/core/engine/trueSolarTime.ts +86 -0
  67. package/shared/core/engine/xiaoliuren.ts +19 -0
  68. package/shared/core/engine/ziwei.ts +217 -0
  69. package/shared/core/engine/ziweiInterpret.ts +161 -0
  70. package/shared/core/types.ts +206 -0
  71. package/src/App.tsx +69 -0
  72. package/src/arts/registry.ts +31 -0
  73. package/src/assets/react.svg +1 -0
  74. package/src/components/Backdrop.tsx +27 -0
  75. package/src/components/BambooArt.tsx +41 -0
  76. package/src/components/CalendarInput.tsx +131 -0
  77. package/src/components/DateInput.tsx +103 -0
  78. package/src/components/Disclaimer.tsx +12 -0
  79. package/src/components/Empty.tsx +8 -0
  80. package/src/components/ErrorBoundary.tsx +38 -0
  81. package/src/components/HomeSideAnchor.tsx +62 -0
  82. package/src/components/InkVein.tsx +10 -0
  83. package/src/components/LifeEventsInput.tsx +47 -0
  84. package/src/components/LocationPicker.tsx +117 -0
  85. package/src/components/Motes.tsx +65 -0
  86. package/src/components/Navigation.tsx +80 -0
  87. package/src/components/ProfileForm.tsx +40 -0
  88. package/src/components/ProfilePicker.tsx +40 -0
  89. package/src/components/QuestionFields.tsx +47 -0
  90. package/src/components/ReportView.tsx +211 -0
  91. package/src/components/ResultCard.tsx +40 -0
  92. package/src/components/SealButton.tsx +18 -0
  93. package/src/components/SiteFooter.tsx +17 -0
  94. package/src/components/SiteNav.tsx +103 -0
  95. package/src/components/SongDialog.tsx +64 -0
  96. package/src/components/SongSearchSelect.tsx +81 -0
  97. package/src/components/SongSelect.tsx +61 -0
  98. package/src/components/StarField.tsx +119 -0
  99. package/src/components/TarotCard.tsx +129 -0
  100. package/src/components/TimeShichenInput.tsx +29 -0
  101. package/src/components/arts/AstrologyArt.tsx +141 -0
  102. package/src/components/arts/BaziArt.tsx +269 -0
  103. package/src/components/arts/LiurenArt.tsx +87 -0
  104. package/src/components/arts/LiuyaoArt.tsx +111 -0
  105. package/src/components/arts/MeihuaArt.tsx +105 -0
  106. package/src/components/arts/QimenArt.tsx +86 -0
  107. package/src/components/arts/TarotArt.tsx +110 -0
  108. package/src/components/arts/XiaoliurenArt.tsx +93 -0
  109. package/src/components/arts/ZiweiArt.tsx +296 -0
  110. package/src/data/arts.ts +84 -0
  111. package/src/data/lifeContext.ts +423 -0
  112. package/src/data/sample-report.json +146 -0
  113. package/src/data/shichen.ts +21 -0
  114. package/src/data/spreads.ts +255 -0
  115. package/src/data/tarotCards.ts +2353 -0
  116. package/src/hooks/useAIInterpret.ts +76 -0
  117. package/src/hooks/useDivine.ts +39 -0
  118. package/src/hooks/useTheme.ts +29 -0
  119. package/src/index.css +190 -0
  120. package/src/lib/utils.ts +6 -0
  121. package/src/main.tsx +12 -0
  122. package/src/pages/AboutPage.tsx +25 -0
  123. package/src/pages/AcademyPage.tsx +128 -0
  124. package/src/pages/AstrologyPage.tsx +33 -0
  125. package/src/pages/AuthPage.tsx +263 -0
  126. package/src/pages/BaZiPage.tsx +33 -0
  127. package/src/pages/ClassicsPage.tsx +120 -0
  128. package/src/pages/DemoPage.tsx +161 -0
  129. package/src/pages/HistoryPage.tsx +133 -0
  130. package/src/pages/Home.tsx +179 -0
  131. package/src/pages/HomePage.tsx +174 -0
  132. package/src/pages/ModulePage.tsx +320 -0
  133. package/src/pages/SpreadEditor.tsx +230 -0
  134. package/src/pages/SpreadEditorPage.tsx +105 -0
  135. package/src/pages/SpreadLibrary.tsx +199 -0
  136. package/src/pages/SpreadLibraryPage.tsx +17 -0
  137. package/src/pages/TarotPage.tsx +738 -0
  138. package/src/pages/ZiWeiPage.tsx +33 -0
  139. package/src/services/api.ts +342 -0
  140. package/src/stores/useDivinationStore.ts +22 -0
  141. package/src/styles/song.css +1066 -0
  142. package/src/styles/tokens.css +60 -0
  143. package/src/types/index.ts +104 -0
  144. package/src/utils/astrologyCalc.ts +61 -0
  145. package/src/utils/comboEngine.ts +134 -0
  146. package/src/utils/dst.ts +24 -0
  147. package/src/utils/panTone.ts +206 -0
  148. package/src/utils/recordStore.ts +60 -0
  149. package/src/utils/semanticAnalyzer.ts +555 -0
  150. package/src/utils/spreadStorage.ts +32 -0
  151. package/src/utils/storage.ts +27 -0
  152. package/src/utils/tarotEngine.ts +849 -0
  153. package/src/utils/userStore.ts +234 -0
  154. package/src/vite-env.d.ts +1 -0
  155. package/tailwind.config.js +52 -0
  156. package/tsconfig.json +40 -0
  157. package/vite.config.ts +34 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 观微(Guanwei)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.en.md ADDED
@@ -0,0 +1,202 @@
1
+ # Guanwei · Ask the Way through Divination
2
+
3
+ <p align="center">
4
+ <img src="docs/assets/guanwei-banner.png" alt="Guanwei · Ask the Way through Divination" width="720">
5
+ </p>
6
+
7
+ <p align="center">
8
+ <a href="https://github.com/RubyCcll/guanwei/actions/workflows/ci.yml"><img src="https://github.com/RubyCcll/guanwei/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI"></a>
9
+ <a href="https://rubyccll.github.io/guanwei/"><img src="https://img.shields.io/badge/demo-GitHub_Pages-4a5442" alt="GitHub Pages"></a>
10
+ <a href="https://github.com/RubyCcll/guanwei/releases"><img src="https://img.shields.io/github/v/release/RubyCcll/guanwei" alt="Release"></a>
11
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-9c4a2f" alt="MIT License"></a>
12
+ <a href="https://github.com/RubyCcll/guanwei"><img src="https://img.shields.io/badge/TypeScript-5.8-3178c6" alt="TypeScript"></a>
13
+ <a href="https://github.com/RubyCcll/guanwei/issues"><img src="https://img.shields.io/badge/tests-181-brightgreen" alt="Tests"></a>
14
+ </p>
15
+
16
+ <p align="center">
17
+ [English](README.en.md) · [简体中文](README.md)
18
+ </p>
19
+
20
+ An open-source Chinese metaphysics application covering **nine arts of divination** — Bazi (Eight Characters), Ziwei Doushu, classical astrology, Qimen Dunjia, Liuyao, Da Liu Ren, Meihua, Xiaoliuren and Tarot — with **AI-powered in-depth interpretation** backed by rigorous chart-fact consistency checks.
21
+
22
+ > All readings are for reflection and entertainment only; never a basis for real decisions.
23
+
24
+ ## ▶️ Try It Now (No Sign-up · No API Key)
25
+
26
+ <p align="center">
27
+ <a href="https://rubyccll.github.io/guanwei/#/demo"><img src="docs/assets/demo.gif" alt="Demo: nine-arts charts → AI report" width="700"></a>
28
+ <br><a href="https://rubyccll.github.io/guanwei/#/demo"><b>▶ Open the Interactive Demo</b></a> — <b>all nine arts computed locally in your browser</b> (zero backend), Bazi includes a full sample AI report.
29
+ </p>
30
+
31
+ ## Screenshots
32
+
33
+ <p align="center">
34
+ <img src="docs/assets/screenshot-home.png" alt="Home page" width="49%">
35
+ <img src="docs/assets/screenshot-bazi.png" alt="Bazi chart" width="49%">
36
+ </p>
37
+
38
+ ## ✨ Features
39
+
40
+ ### Nine Arts of Divination (deterministic calendar computation, single shared engine)
41
+ | Category | Arts |
42
+ |---|---|
43
+ | Natal charts | Bazi (Ziping), Ziwei Doushu, Classical astrology (VSOP87 ecliptic) |
44
+ | Divination | Qimen Dunjia, Meihua, Liuyao, Da Liu Ren, Xiaoliuren, Tarot |
45
+
46
+ - **Gregorian/Lunar dual-calendar** birth input, precise to the minute (east-Asian arts use the two-hour shichen, astrology uses exact time)
47
+ - Location down to **province/city/district → longitude/latitude** (true solar time correction, including 1986–1991 China DST rollback); falls back to Beijing time with a clear notice when location is omitted
48
+ - **Unknown birth hour support**: charts without the hour pillar, plus **hour inference from life events** (year × hour-pillar interaction scoring)
49
+ - **Dynamic chart narration**: personalized summaries generated from the actual chart (day master × season × strength × ten gods × five-element balance × luck cycles)
50
+ - Results computed by the backend and **persisted to SQLite**
51
+
52
+ ### AI Deep Interpretation
53
+ - 9 agents × skill orchestration (e.g. Ziwei: chart structure → star palaces → twelve houses → major cycles → life stages)
54
+ - **Dual schemas**: natal-chart reports (raw reading / character / family / mind / life stages / career / love / wealth / health) and divination reports (situation / trend / timing)
55
+ - **Chart-fact consistency**: the AI must quote chart data verbatim; the backend **verifies six-relations facts** (palace branch, main stars, borrowed stars, four transformations) and patches contradictions
56
+ - **Stable readings**: cached chart-parsing step, low sampling temperature, evidence-anchored claims, de-duplication with word budgets
57
+ - **Life-event calibration**: record known life events; the AI echoes them at the matching years and never contradicts them
58
+ - Question–art **suitability analysis** (e.g. Qimen is not advised for romance questions)
59
+ - Streaming generation + structured report cards; export to Markdown / PDF
60
+
61
+ ### Other
62
+ - Classics pages, academy (history and knowledge of the nine arts)
63
+ - Profile management (primary/sample profiles), divination history with AI reports
64
+
65
+ ## 🏗️ Architecture
66
+
67
+ ```
68
+ Frontend: React 18 + TypeScript + Vite + Tailwind (Song-dynasty aesthetics)
69
+ Backend: Express + tsx (SSE streaming + SQLite)
70
+ Shared: shared/core/engine/* — single source of truth for all chart algorithms
71
+ AI: multi-LLM adapter (OpenAI-compatible & Google formats; DeepSeek / Gemini / Groq / Qwen / custom)
72
+ ```
73
+
74
+ ## 🚀 Quick Start (one-liners)
75
+
76
+ ### ⚡ Recommended: npm one-liner (fast, seconds)
77
+
78
+ ```bash
79
+ npm i -g guanwei
80
+ guanwei setup --key YOUR_API_KEY
81
+ guanwei start
82
+ ```
83
+
84
+ Open http://localhost:5173 . Upgrade: `guanwei update`. Stop: `guanwei stop`.
85
+
86
+ ### ⚡ Docker one-liner (no Node needed, easiest)
87
+
88
+ ```bash
89
+ docker run -d --name guanwei -p 5173:80 -e LLM_DEEPSEEK_KEY=YOUR_API_KEY ghcr.io/rubyccll/guanwei:latest
90
+ ```
91
+
92
+ Open http://localhost:5173 . Stop: `docker stop guanwei`. Other providers: `-e LLM_PROVIDER=gemini -e LLM_GEMINI_KEY=...` (deepseek / gemini / groq / qwen / custom).
93
+
94
+ ### ⚡ Source installer (fallback)
95
+
96
+ ```bash
97
+ curl -fsSL https://raw.githubusercontent.com/RubyCcll/guanwei/main/scripts/install.sh | bash
98
+ guanwei setup --key YOUR_API_KEY
99
+ guanwei start
100
+ ```
101
+
102
+ ### Detailed options (Codespaces / Compose / local Node)
103
+
104
+ **One step: configure your API key** (DeepSeek / Gemini / Groq / Qwen / custom endpoint).
105
+
106
+ #### Option 4: GitHub Codespaces (zero local setup)
107
+
108
+ [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/RubyCcll/guanwei)
109
+
110
+ Click the button → dependencies are installed automatically → run:
111
+
112
+ ```bash
113
+ ./scripts/setup.sh --key YOUR_API_KEY
114
+ ```
115
+
116
+ #### Option 5: Docker Compose
117
+
118
+ Prebuilt images are published to GitHub Container Registry (amd64 + arm64):
119
+
120
+ ```bash
121
+ ./scripts/setup.sh --docker --key YOUR_API_KEY
122
+ # or manually: cp server/.env.example server/.env → docker compose up -d
123
+ ```
124
+
125
+ Open http://localhost:5173 . Stop with `docker compose down`.
126
+
127
+ Images: `ghcr.io/rubyccll/guanwei-guanwei-web` / `guanwei-guanwei-backend`; override ports with `WEB_PORT=5180 API_PORT=3020 docker compose up -d` if needed.
128
+
129
+ #### Option 6: Local Node.js (≥ 22)
130
+
131
+ ```bash
132
+ ./scripts/setup.sh --key YOUR_API_KEY # interactive mode: run ./scripts/setup.sh
133
+ ```
134
+
135
+ The script installs dependencies, writes `server/.env` (key stays local), and starts both servers. Open http://localhost:5173 → register → cast a chart → summon the AI report.
136
+
137
+ ### 🖥️ Guanwei CLI (start / update / self-check)
138
+
139
+ ```bash
140
+ npm link # install globally (or use ./scripts/guanwei directly)
141
+
142
+ guanwei setup --key sk-xxx # configure API key (interactive: guanwei setup)
143
+ guanwei start # start (--docker for containers)
144
+ guanwei doctor # environment self-check (Node/config/ports/deps/version)
145
+ guanwei update # update to latest (git incremental merge; local config preserved)
146
+ guanwei check / status # version check / status
147
+ guanwei stop # stop (docker mode)
148
+ ```
149
+
150
+ > `guanwei update` uses **git incremental merge**: only pulls remote changes, keeps all local config (`.env` etc. are gitignored); uncommitted local edits are auto-stashed and restored.
151
+
152
+ ### 🔑 Getting an API Key (5 providers)
153
+
154
+ | Provider | Portal | Notes |
155
+ |---|---|---|
156
+ | **DeepSeek** (recommended) | https://platform.deepseek.com | Best value, strong Chinese |
157
+ | Groq | https://console.groq.com | Free tier |
158
+ | Gemini | https://aistudio.google.com/apikey | Free tier |
159
+ | Qwen (Alibaba) | https://dashscope.console.aliyun.com/ | China-friendly |
160
+ | Custom endpoint | any OpenAI-compatible API | `--provider custom` |
161
+
162
+ Then run `./scripts/setup.sh --key YOUR_KEY` (Windows: `scripts/setup.bat --key YOUR_KEY`); the UI shows a clear guide when the key is missing.
163
+
164
+ ### Tests
165
+ ```bash
166
+ npm test # 181 tests (engines / rendering / interactions / storage / prompts)
167
+ ```
168
+
169
+ ## 📁 Structure
170
+
171
+ ```
172
+ ├── src/ # Frontend (pages / components / hooks / services)
173
+ ├── server/
174
+ │ ├── src/routes/ # divine / ai / users / hour
175
+ │ └── src/services/ # promptBuilder / llmProvider / divineStore / hourInference / relativesCheck / sixRelatives
176
+ ├── shared/core/ # Shared chart engines (single copy)
177
+ ├── scripts/ # setup.sh / guanwei CLI / release.sh / setup.bat (Windows)
178
+ ├── deploy/ # nginx config (Docker)
179
+ ├── .devcontainer/ # GitHub Codespaces template
180
+ ├── Dockerfile.web / Dockerfile.server / docker-compose.yml
181
+ ├── docs/ # Open-source assets (banner / screenshots / GIF / sample report)
182
+ └── tests/ # Tests (incl. regression set)
183
+ ```
184
+
185
+ ## 🔐 Security
186
+ - Keys live only in local `server/.env` (gitignored); Docker builds exclude `.env` via `.dockerignore`
187
+ - Test data is fully fictional/anonymized — no real personal information in this repository
188
+
189
+ ## 📄 Sample Output
190
+
191
+ - [Sample AI report (PDF)](docs/assets/sample-report.pdf) (fictional profile, generated by the real pipeline)
192
+
193
+ ## 🤝 Contributing
194
+
195
+ See [CONTRIBUTING.md](CONTRIBUTING.md) — including the **zero-privacy policy** (no real user data, keys, or personal info in this repository). Releases follow semantic versioning — see [CHANGELOG.md](CHANGELOG.md).
196
+
197
+ ## 📄 License
198
+ [MIT](LICENSE)
199
+
200
+ ---
201
+
202
+ **Guanwei** · 以术问道,观微知著。 Long-term maintenance — welcome to Star & open Issues.
package/README.md ADDED
@@ -0,0 +1,247 @@
1
+ # 观微 · 以术问道
2
+
3
+ <p align="center">
4
+ <b>Open-source Chinese metaphysics: nine arts of divination with AI interpretation.</b><br>
5
+ <i>简体中文</i> · <a href="README.en.md">English</a>
6
+ </p>
7
+
8
+ <p align="center">
9
+ <img src="docs/assets/guanwei-banner.png" alt="观微 Guanwei · 以术问道,观微知著" width="720">
10
+ </p>
11
+
12
+ <p align="center">
13
+ <a href="https://github.com/RubyCcll/guanwei/actions/workflows/ci.yml"><img src="https://github.com/RubyCcll/guanwei/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI"></a>
14
+ <a href="https://rubyccll.github.io/guanwei/"><img src="https://img.shields.io/badge/demo-GitHub_Pages-4a5442" alt="GitHub Pages"></a>
15
+ <a href="https://github.com/RubyCcll/guanwei/releases"><img src="https://img.shields.io/github/v/release/RubyCcll/guanwei" alt="Release"></a>
16
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-9c4a2f" alt="MIT License"></a>
17
+ <a href="https://github.com/RubyCcll/guanwei"><img src="https://img.shields.io/badge/TypeScript-5.8-3178c6" alt="TypeScript"></a>
18
+ <a href="https://github.com/RubyCcll/guanwei/issues"><img src="https://img.shields.io/badge/tests-181-brightgreen" alt="Tests"></a>
19
+ </p>
20
+
21
+ <p align="center">
22
+ <b>Guanwei</b> — an open-source Chinese metaphysics application: eight-character Bazi, Ziwei Doushu, classical astrology, Qimen Dunjia, Liuyao, Da Liu Ren, Meihua, Xiaoliuren and Tarot — with AI-powered in-depth interpretation.
23
+ <br><i>东玄为主、中西合参的玄学占卜应用:九术排盘、AI 深度解读、古籍引证、学馆修习,一条链路贯通「排盘 → 解读 → 归档 → 回看」。</i>
24
+ </p>
25
+
26
+ > 占问所得,仅供修身养性、怡情遣兴之用,不构成任何决策依据。
27
+
28
+ ## ▶️ 立即体验(无需注册 · 无需配置 · 无需 API Key)
29
+
30
+ <p align="center">
31
+ <a href="https://rubyccll.github.io/guanwei/#/demo"><img src="docs/assets/demo.gif" alt="演示:九术排盘 → AI 报告" width="700"></a><br>
32
+ <a href="https://rubyccll.github.io/guanwei/#/demo"><b>▶ 打开交互演示</b></a> —— <b>九种术数本地排盘</b>(浏览器直接计算,零后端),八字附带完整 AI 解读示例
33
+ </p>
34
+
35
+ > 另有 [GitHub Pages 静态演示站](https://rubyccll.github.io/guanwei/)(首页/九术说明/古籍/学馆)。完整功能(真实排盘 + 实时 AI 解读 + 存档)请本地/云端部署(见下)。
36
+
37
+ ## 🖼️ 界面预览
38
+
39
+ <p align="center">
40
+ <img src="docs/assets/screenshot-home.png" alt="首页" width="49%">
41
+ <img src="docs/assets/screenshot-bazi.png" alt="八字排盘" width="49%">
42
+ </p>
43
+
44
+ ## ✨ 功能
45
+
46
+ ### 九术排盘(确定性历法计算,前后端单一算法副本)
47
+ | 类目 | 术数 |
48
+ |---|---|
49
+ | 命盘类 | 八字(子平)、紫微斗数、古典星盘(VSOP87 回归黄道) |
50
+ | 占问类 | 奇门遁甲、梅花易数、六爻、大六壬、小六壬、塔罗 |
51
+
52
+ - 出生时间支持 **公历/农历双历**、精确到时刻(东玄据此推时辰,星盘直接用时刻)
53
+ - 地点精确到 **省市区县 → 经纬度**(真太阳时校正,含 1986-1991 中国夏令时回拨);未填地点时明示"按北京时间排盘"
54
+ - **时辰未知支持**:不排时柱仅依年月日三柱论命;可**依人生关键事件反推时辰**(流年 × 时柱应象打分引擎)
55
+ - **盘面动态话术**:排盘结果按日主×季节×旺衰×十神×五行旺缺×大运喜忌生成个性化解读,告别千篇一律的模板
56
+ - 起占结果由后端计算并**持久化入库**(SQLite),六爻摇卦、塔罗抽牌等交互结果同样后端定稿
57
+
58
+ ### AI 深度解读
59
+ - 9 个 Agent × Skills 编排(如紫微:命盘结构 → 星曜落宫 → 十二宫 → 大限流年 → 人生阶段)
60
+ - **双轨 Schema**:命盘类(原始解读/性格/原生家庭/心智模式/人生阶段/事业/爱情/财富/健康)、占问类(现状/趋势/时机)
61
+ - **盘面事实一致性约束**:AI 必须逐字引用排盘数据,不得编造;后端**六亲宫位事实校验 + 矛盾定向修正**(宫位地支/主星/借星/生年四化)
62
+ - **解读稳定性**:Step1 盘面解析缓存复用、低温采样、论断锚定(主观程度词必须有盘面依据)、去重与字数预算
63
+ - **人生经历校准**:可录入命主已知人生事件,AI 解读在对应流年处呼应、且不与已知经历矛盾
64
+ - 问题-术数**适配性分析**(如奇门不适于问情爱)
65
+ - 流式生成 + 结构化报告卡片,可导出 Markdown / 存为 PDF
66
+
67
+ ### 其他
68
+ - 古籍页(背景动画、经典原文)、学馆(九术源流与知识)
69
+ - 用户档案管理(主档案/示例档案/编辑/切换)
70
+ - 占卜历史(起占自动归档,可回看排盘与 AI 报告,可删除)
71
+
72
+ ## 🏗️ 技术架构
73
+
74
+ ```
75
+ 前端 React 18 + TS + Vite + Tailwind(宋式美学 UI)
76
+ 后端 Express + tsx(SSE 流式 + SQLite 存储)
77
+ 共享引擎 shared/core/engine/*(lunar-typescript 历法 + astronomy-engine 星历)
78
+ AI 层:多 LLM 适配(OpenAI 兼容 / Google 格式,DeepSeek / Gemini / Groq / 通义 / 自定义端点)
79
+ ```
80
+
81
+ ### 数据流
82
+ ```
83
+ ① 排盘:登录用户 → 前端输入 → POST /api/divine → 后端引擎计算 → SQLite 入库 → 前端渲染
84
+ ② AI:点击解读 → POST /api/ai/interpret/stream(divineId) → 后端读库 → 组装 Prompt → LLM SSE 流式返回
85
+ → 后端 parseReport 结构化匹配(清洗/映射/质量评分/六亲事实校验)→ quality=ok 才入库 → 前端 ReportView
86
+ ③ 历史:GET /api/divine?username= → 档案管理页列表/详情/删除
87
+ ```
88
+
89
+ ## 🚀 快速开始(一行命令)
90
+
91
+ ### ⚡ 方式一:npm 一行安装(推荐,国内几秒装完)
92
+
93
+ ```bash
94
+ npm i -g guanwei
95
+ guanwei setup --key 你的APIKey
96
+ guanwei start
97
+ ```
98
+
99
+ 打开 http://localhost:5173 即用。国内用户自动走 npmmirror 加速;升级:`guanwei update`。停止:`guanwei stop`。
100
+
101
+ ### ⚡ 方式二:Docker 一行启动(免装 Node,最省心)
102
+
103
+ ```bash
104
+ docker run -d --name guanwei -p 5173:80 -e LLM_DEEPSEEK_KEY=你的APIKey ghcr.io/rubyccll/guanwei:latest
105
+ ```
106
+
107
+ 打开 http://localhost:5173 即用。停止:`docker stop guanwei`。其他服务商:`-e LLM_PROVIDER=gemini -e LLM_GEMINI_KEY=你的Key`(deepseek / gemini / groq / qwen / custom 均可)。
108
+
109
+ ### ⚡ 方式三:curl 一键安装(源码方式,备用)
110
+
111
+ ```bash
112
+ curl -fsSL https://raw.githubusercontent.com/RubyCcll/guanwei/main/scripts/install.sh | bash
113
+ guanwei setup --key 你的APIKey
114
+ guanwei start
115
+ ```
116
+
117
+ ### 详细方式(Codespaces / Compose / 本地 Node)
118
+
119
+ **只需一步:配置你的 API Key**([5 家服务商任选](#-获取-api-key5-家服务商任选),DeepSeek 性价比最高)。
120
+
121
+ #### 方式四:GitHub Codespaces(零本地安装,云端一键)
122
+
123
+ [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/RubyCcll/guanwei)
124
+
125
+ 点击按钮 → 云端环境自动装好依赖 → 终端执行:
126
+
127
+ ```bash
128
+ ./scripts/setup.sh --key 你的APIKey
129
+ ```
130
+
131
+ #### 方式五:Docker Compose(多容器)
132
+
133
+ 预构建镜像已发布到 GitHub Container Registry(amd64 + arm64 双平台):
134
+
135
+ ```bash
136
+ ./scripts/setup.sh --docker --key 你的APIKey # 自动配置 + 拉取镜像 + 启动
137
+ # 或手动:
138
+ # cp server/.env.example server/.env (填入 Key)
139
+ # docker compose up -d (自动拉取 GHCR 镜像)
140
+ ```
141
+
142
+ 打开 http://localhost:5173 。停止:`docker compose down`。
143
+
144
+ 镜像:`ghcr.io/rubyccll/guanwei-guanwei-web` / `guanwei-guanwei-backend`;端口冲突时 `WEB_PORT=5180 API_PORT=3020 docker compose up -d` 覆盖。也可直接 `docker pull ghcr.io/rubyccll/guanwei-guanwei-web:latest`。
145
+
146
+ #### 方式六:本地 Node.js(≥ 22)
147
+
148
+ ```bash
149
+ ./scripts/setup.sh --key 你的APIKey # 交互式可直接运行 ./scripts/setup.sh
150
+ ```
151
+
152
+ 脚本自动:安装依赖 → 写入 `server/.env`(Key 仅存本地)→ 启动前后端。打开 http://localhost:5173 → 缘起页注册 → 九术页起占 → 召 AI 成报告。
153
+
154
+ ### 🖥️ 观微 CLI(启动 / 更新 / 自检一条命令)
155
+
156
+ ```bash
157
+ # ① 在【项目根目录】执行一次(全局安装 guanwei 命令,之后任意目录可用):
158
+ npm link
159
+ # ② 不想全局安装?直接使用:./scripts/guanwei <命令>
160
+
161
+ guanwei setup --key sk-xxx # 配置 API Key(交互式:guanwei setup)
162
+ guanwei start # 启动(--docker 用容器)
163
+ guanwei doctor # 环境自检(Node/配置/占位密钥/端口/依赖/版本)
164
+ guanwei update # 更新到最新版(git 增量合并,.env 等本地配置不覆盖)
165
+ guanwei check / status # 版本检查 / 状态
166
+ guanwei stop # 停止(docker 模式)
167
+ ```
168
+
169
+ > `guanwei update` 采用 **git 增量合并**:只拉取远程变更、保留本地所有配置(`.env` 等已 gitignore 文件不受影响);检测到本地未提交修改会先提示并自动 stash 保护,更新完成后恢复。
170
+
171
+ ### 🔑 获取 API Key(5 家服务商任选)
172
+
173
+ | 服务商 | 官方入口 | 说明 |
174
+ |---|---|---|
175
+ | **DeepSeek**(推荐) | https://platform.deepseek.com | 性价比最高,中文好 |
176
+ | Groq | https://console.groq.com | 有免费额度 |
177
+ | Gemini | https://aistudio.google.com/apikey | 有免费额度 |
178
+ | 通义千问 | https://dashscope.console.aliyun.com/ | 国内直连 |
179
+ | 自定义端点 | 任意 OpenAI 兼容接口 | `--provider custom` |
180
+
181
+ 注册后在对应平台创建 Key → 运行 `./scripts/setup.sh --key 你的Key`(Windows 用 `scripts/setup.bat --key 你的Key`)即完成配置;未配置时页面会有明确引导。
182
+
183
+ ### 测试
184
+ ```bash
185
+ npm test # 181 项测试(核心引擎/渲染/交互/存储/流程/提示词)
186
+ cd server && npx tsx scripts/divineStoreSmoke.ts # SQLite 存储冒烟
187
+ ```
188
+
189
+ ## 📁 目录结构
190
+
191
+ ```
192
+ ├── src/ # 前端(页面/组件/hooks/服务)
193
+ ├── server/
194
+ │ ├── src/
195
+ │ │ ├── routes/ # divine(排盘)/ ai(解读)/ users / hour(时辰反推)
196
+ │ │ └── services/ # promptBuilder / llmProvider / divineStore / hourInference / relativesCheck / sixRelatives
197
+ │ ├── data/ # SQLite 与用户数据(gitignore)
198
+ │ └── .env.example
199
+ ├── shared/core/ # 前后端共用引擎(排盘算法/数据,单一副本)
200
+ ├── scripts/ # setup.sh(一键配置)/ guanwei(CLI)/ release.sh(发版)/ setup.bat(Windows)
201
+ ├── deploy/ # nginx 配置(Docker 部署)
202
+ ├── .devcontainer/ # GitHub Codespaces 模板
203
+ ├── Dockerfile.web / Dockerfile.server / docker-compose.yml
204
+ ├── docs/ # 开源素材(banner/截图/GIF/示例报告)
205
+ └── tests/ # 测试(含回归集)
206
+ ```
207
+
208
+ ## 🔐 安全说明
209
+ - 所有密钥仅存于本地 `server/.env`(已 gitignore),仓库只提供 `.env.example` 模板;Docker 镜像构建已排除 `.env`(.dockerignore)
210
+ - AI 报告质量门槛:结构评分不达标不入库,自动留档供改进提示词
211
+ - 测试数据全部虚构/匿名化,不含真实用户隐私;真实案例仅存本地(git 忽略)
212
+
213
+ ## 📄 示例输出
214
+
215
+ - [示例 AI 报告 PDF](docs/assets/sample-report.pdf)(虚构档案,真实管线生成)
216
+
217
+ ## 🗺️ 迭代计划
218
+
219
+ 已完成(v1.1.x):
220
+ - ✅ **排盘精度**:八字(藏干十神/旺衰拆解/用神喜忌/大运流年/神煞/胎元命宫身宫/时辰未知)、紫微(辅曜安星/生年四化/庙旺落陷/格局识别)、星盘(宫位/行星入宫/庙旺逆行)、六爻纳甲(六亲六神世应/月破旬空)、奇门(值使/暗干/八神)、六壬(贵人/十二天将)、梅花(体用旺衰)
221
+ - ✅ **AI 解读**:两步管线(盘面解析 → 深度报告)、盘面事实注入、画像级 Schema、多 LLM 适配、解读稳定化与去重、六亲事实校验修正、人生经历校准
222
+ - ✅ **时辰反推**:依人生关键事件推演时辰(流年 × 时柱应象打分引擎)
223
+ - ✅ **盘面动态话术**:排盘结果按盘面数据生成个性化解读
224
+ - ✅ **部署套件**:一键配置脚本、Docker Compose(GHCR 预构建镜像)、Codespaces、guanwei CLI(启动/更新/自检)、Windows 支持
225
+ - ✅ **演示页**:九术本地排盘(纯浏览器引擎)+ 八字示例报告,GitHub Pages 直接体验
226
+ - ✅ **评测闭环**:接入 MingLi-Bench(160 题)建立 AI 解读评测基线,评测驱动 prompt 迭代
227
+
228
+ 计划方向:
229
+ - **开放分发**:MCP Server / Agent Skill / REST API(复用 shared/core 单一算法副本)
230
+ - **体验**:移动端适配深化、性能优化、演示页输入表单
231
+ - **持续演进**:更细致的解读和更精确的个人化设计
232
+
233
+ ## 🤝 如何参与
234
+
235
+ - 🐛 遇到问题 → 提 [Bug 报告](https://github.com/RubyCcll/guanwei/issues/new?template=bug_report.yml)
236
+ - 💡 有想法 → 提 [功能建议](https://github.com/RubyCcll/guanwei/issues/new?template=feature_request.yml)
237
+ - 🧑‍💻 想写代码 → 见 [CONTRIBUTING.md](CONTRIBUTING.md)(含「我想做什么 → 推荐起点」导航)
238
+ - 🌱 新手友好 → [good first issue](https://github.com/RubyCcll/guanwei/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)
239
+ - ⭐ 觉得不错 → 点个 Star,就是最大的支持
240
+ - 📦 发版节奏:语义化版本,见 [CHANGELOG.md](CHANGELOG.md);发版一条命令 `./scripts/release.sh <版本号>`
241
+
242
+ ## 📄 License
243
+ [MIT](LICENSE)
244
+
245
+ ---
246
+
247
+ **观微** · 以术问道,观微知著。本仓库将持续迭代,欢迎 Star 与 Issue。