willfate
# WillFate
[]([https://github.com/gro83j/willfate/actions/workflows/ci.yml](https://github.com/gro83j/willfate/actions/workflows/ci.yml))
[](pyproject.toml)
[](agent/external/taibu-runtime/package.json)
[](#22-个统一-mcp-工具一览)
[](LICENSE)
> [English README](README.en.md) · [更新日志 CHANGELOG](CHANGELOG.md) · [可选网页工作台分支 (`web-ui`)](#可选分支本地网页与图谱记忆工作台-web-ui)
**WillFate** 是一套**本地优先**的中国传统术数排盘、经典书证检索、个人长期记忆与现实成长陪伴框架。装好后,你可以直接用 **Claude Code、Codex、Antigravity、WorkBuddy、Cursor、DSH** 等任意本地 AI 助手为你排盘、解盘、复盘校准与规划现实行动。

---
## 为什么做 WillFate?(解决普通 AI 算命的三大硬伤)
1. **告别大模型“心算排盘幻觉”**:大模型心算万年历、节气换柱、真太阳时、紫微安星和星盘宫位极易出错。WillFate 内置 **16 个确定性术数计算工具**(八字、大运、紫微、运限、飞星、西占、推运/返照、奇门、六爻、梅花、大小六壬、太乙、黄历、塔罗),所有盘面符号 100% 由本地确定性算法产出并自动缓存。
2. **从 0 开始、越用越懂你的本地长期记忆**:每位使用者的数据完全独立保存在自己电脑的 `~/.willfate/`(可通过 `WILLFATE_HOME` 覆盖),仓库**零预置私人数据**。首次对话自动引导建档,后续会话一键“温启动”加载你的个人简报、沟通偏好、已排本命盘与未决问题。
3. **事实与推算严格分家 + 四段式证据链**:
- **只把客观现实写进档案**:你亲口说的现状、经历与偏好进入 `personal_memory.db` 与事实台账;AI 推算的运势判断只写进 `~/.willfate/readings/` 待事后现实校准,绝不污染事实库。
- **反宿命论与可验证推演**:每个结论强制走「盘面信号 → 时间触发 → 领域归属 → 最窄可支持结论」,区分强/中/弱证据并设置高风险安全降级,同时提供「算命解盘线」与「现实能力提升线」双轨切换。
---
## 三分钟快速上手
环境要求:**Python ≥ 3.10** + **Node.js ≥ 20**。
### 第 1 步:克隆并初始化本地私密目录与排盘引擎
```bash
git clone https://github.com/gro83j/willfate.git
cd willfate
# 安装最小核心依赖(仅 lunar-python,SQLite FTS5 / 稀疏向量 / MCP 均使用标准库)
pip install -r requirements.txt
# 初始化 ~/.willfate 空数据库与目录,并安装 16 工具排盘运行时依赖
python willfate_cli.py init --install-runtime
# 环境自检
python willfate_cli.py doctor
```
### 第 2 步:一键安装全宿主 Skill 并挂载 22 工具 MCP
```bash
# 自动探测本机已安装的 AI 助手并写入 Skill(也可指定 --host claude,codex,antigravity,workbuddy,cursor,dsh 或 all)
python willfate_cli.py setup --host auto
```
按终端打印的配置把 MCP Server 挂进你的 AI 助手(任选其一;即使不挂 MCP,能访问本地文件/终端的 AI 助手也能通过 `~/.willfate/bin/willfate_run.py` 直接驱动全部能力):
- **Claude Code(一行命令)**:
```bash
claude mcp add willfate -- python /绝对路径/willfate/willfate_cli.py mcp
```
- **Cursor / Antigravity / WorkBuddy / DSH(MCP JSON)**:
```json
{
"mcpServers": {
"willfate": {
"command": "python",
"args": ["/绝对路径/willfate/willfate_cli.py", "mcp"]
}
}
}
```
- **Codex(`~/.codex/config.toml`)**:
```toml
[mcp_servers.willfate]
command = "python"
args = ["/绝对路径/willfate/willfate_cli.py", "mcp"]
```
### 第 3 步:在你的 AI 助手里直接开聊
- **首次使用(冷启动从 0 建档)**:
> `willfate`
> (AI 会引导你提供称呼、性别、公历出生年月日时分与出生城市,自动排好本命八字/紫微/星盘缓存到本地 `~/.willfate/charts/` 并建立你的专属档案。)
- **日常看盘 / 起卦(算命解盘线)**:
> `willfate 结合我的八字和紫微看看明年事业变动窗口,再起一局奇门看眼下这个机会能不能成。`
- **日常复盘 / 抗拖延(能力提升陪伴线)**:
> `最近推进副业总是拖延内耗,帮我拆解一下这周可执行的动作和复盘指标。`
---
## 22 个统一 MCP 工具一览
### A. 本地长期记忆、温启动与校准工具(6 个)
| 工具名 | 作用 |
| --- | --- |
| `willfate_doctor` | 检查 Python、16 工具排盘引擎版本与 `~/.willfate` 本地记忆/书库状态 |
| `willfate_warmstart` | 生成会话温启动简报(当下干支锚点、事实台账、偏好画像、缓存盘面、最近解读;首次使用标记冷启动) |
| `willfate_profile_get` | 读取本人(`primary`)或第三方(`other:*`)结构化档案、事实台账与沟通偏好 |
| `willfate_profile_ingest` | 将用户直述的客观现实事实写入 SQLite 向量记忆库与 Markdown 事实台账(禁写测算结论) |
| `willfate_memory_search` | 在个人长期记忆库(`personal_memory.db`)与自备古籍书库(`books.db`)中执行 FTS5 + 稀疏向量混合检索 |
| `willfate_reading_log` | 创建正式解读归档(`create`)、列出历史记录(`list`)或追加事后现实校准(`calibrate`) |
### B. 确定性术数排盘工具(16 个,全部支持 `saveAs` 自动落盘缓存)
| 类别 | 工具名 | 核心输出 |
| --- | --- | --- |
| **四柱子平** | `bazi` · `bazi_dayun` · `bazi_pillars_resolve` | 真太阳时换算、四柱藏干十神、神煞、交运节气、大运流年流月、四柱反推公历 |
| **紫微斗数** | `ziwei` · `ziwei_horoscope` · `ziwei_flying_star` | 十二宫安星、庙旺利陷、五行局、大限/流年/流月/流日四化叠盘、宫干飞星转宫 |
| **西方占星** | `astrology` · `astrology_advanced` | 本命行星落宫与相位、流运触发、次限推运(`secondary_progression`)、太阳返照(`solar_return`) |
| **三式与周易** | `qimen` · `liuyao` · `meihua` · `daliuren` · `xiaoliuren` · `taiyi` | 时家转盘奇门九宫门星神、六爻纳甲六亲月建日辰、梅花体用、大小六壬四课三传、太乙 |
| **历法与符号** | `almanac` · `tarot` | 万年历择日干支宜忌、塔罗牌阵抽取 |
---
## CLI 常用命令
```bash
python willfate_cli.py doctor # 环境与记忆库状态自检
python willfate_cli.py warmstart # 生成 ~/.willfate/warmstart/briefing.md
python willfate_cli.py chart --list # 查看 16 个排盘工具及必填参数
python willfate_cli.py chart --tool bazi --args-file args.json --out-name primary_bazi
python willfate_cli.py profile show # 查看当前个人档案状态
python willfate_cli.py profile ingest --facts examples/facts_ingest.example.json --dry-run
python willfate_cli.py search --query "伤官见官" --scope books # 检索自备古籍书库
python willfate_cli.py ingest-books # 导入 ~/.willfate/books 下的自备书籍
python willfate_cli.py calibrate --list # 查看历史解读与事后校准记录
```
---
## 本地数据目录与自备古籍书库
本仓库不包含任何受版权保护的书籍文件或任何个人数据。运行 `init` 后,你的所有私人数据均保存在本地 `~/.willfate/`(可用环境变量 `WILLFATE_HOME` 指定其他盘符目录):
```text
~/.willfate/
├── memory_store/
│ ├── personal_memory.db # 个人长期记忆与结构化档案 SQLite(FTS5 + 稀疏向量)
│ ├── books.db # 自备古籍分块与检索索引 SQLite
│ └── profiles/ # 事实台账 primary_profile_facts.md 与沟通画像
├── books/ # 放入你自备的 .txt / .md / .pdf / .epub / .docx 典籍后运行 ingest-books
├── charts/ # 本命盘与起局 JSON/MD 本地缓存(免重复排盘)
├── readings/ # 每次正式解读的归档与事后现实校准记录
└── warmstart/briefing.md # 供本地 AI 助手一键读取的会话温启动简报
```
- **可选高级能力**:
- PDF/EPUB/图片排盘 OCR:`pip install -r agent/requirements-optional.txt`
- 本地离线 BGE ONNX 重排:`pip install -r agent/requirements-book-rerank.txt`
- Neo4j 图谱记忆旁路层(默认 fail-open,不装也不影响主流程):`pip install -r agent/requirements-graph.txt`,参考 `agent/graph/README.md`。
---
## 可选分支:本地网页与图谱记忆工作台 (`web-ui`)
如果你除了在本地 AI 助手里对话之外,还想要一个**本地浏览器可视化界面**(包含图谱记忆节点可视化浏览、日常心情日记、随手笔记与历史解读归档台),可以切换到可选的 `web-ui` 分支:
```bash
git fetch origin web-ui
git checkout web-ui
# 启动本地 Web 工作台(默认监听 127.0.0.1:8765,首次启动自动在本地生成随机口令)
python bridge/server.py
```
日常只用 Claude Code / Codex / Antigravity / Cursor / DSH 对话的用户,留在默认的 `main` 分支即可,更加轻量纯粹。
---
## 开发测试与免责声明
```bash
# 在隔离空环境下运行全量单元测试与排盘运行时集成测试(635+ 用例)
cd agent
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 WILLFATE_CHART_RUNTIME_INTEGRATION=1 python -m pytest -q
```
**文化与安全边界声明**:
1. 本项目定位为传统文化术数研究、符号自省与个人成长复盘工具,严禁用于宿命论恐吓或迷信敛财。
2. 任何排盘推演结论均属于条件性视角参考,**不能替代执业医师的医疗诊断、执业律师的法律意见、心理咨询/危机干预或持牌机构的金融投资决策**。
## License
[MIT License](LICENSE) · 第三方开源组件说明见 [NOTICE](NOTICE)。
TDQS
Scored across 22 tools
Each divination system (bazi, ziwei, qimen, liuyao, meihua, daliuren, xiaoliuren, taiyi, tarot, astrology) is a clearly separate tool with a distinct method, and the sub-tools (astrology_advanced, bazi_dayun, ziwei_horoscope) are scoped to distinct chart layers. The only mild overlaps are willfate_doctor vs willfate_warmstart (both environment/init concerns) and willfate_profile_get vs willfate_memory_search (both read local personal data), but descriptions distinguish them adequately.
All names are lowercase snake_case and follow a recognizable {system}_{subfunction} pattern, which is readable. However, the willfate_ prefix is applied to only a subset of tools (doctor, warmstart, profile_*, memory_search, reading_log) while core chart tools are bare, and some suffixes are adjectives (astrology_advanced) rather than actions, so the convention is mixed.
22 tools is on the heavy side, but the server covers roughly ten distinct divination systems plus profile/memory management, so each system getting 1-3 tools is justified rather than redundant. No obvious filler tools are present.
Chart casting is well covered across many traditions, plus a reading log, memory search, and diagnostics. However, the long-term memory/profile surface is write-and-read only: there is no way to correct, update, or delete stored facts, profile entries, or reading-log records, which is a notable gap for a persistent memory system.