← Back to Skills Marketplace
youhan2021

Fortune Telling Bazi

by youhan2021 · GitHub ↗ · v1.0.2 · MIT-0
cross-platform ✓ Security Clean
105
Downloads
0
Stars
0
Active Installs
3
Versions
Install in OpenClaw
/install fortune-telling-bazi
Description
八字算命 skill — 支持多人八字存储+联合分析,首次询问生日,后续对话自动附带八字信息。说"停止算命"退出。
README (SKILL.md)

fortune-telling-bazi 八字算命

核心流程

首次启用

  1. 用户说「开始算命」→ 调用 python3 scripts/main.py status
  2. 无用户 → 询问生日(姓名/年份/月份/日期/时间/性别)
  3. 调用 python3 scripts/main.py add \x3Cname> \x3C年> \x3C月> \x3C日> \x3C时> \x3C性别>(分可省略)
  4. 本地计算八字(scripts/calc.py)→ 保存到 data/users.json → 显示摘要
  5. 调用 python3 scripts/main.py active \x3Cname> 激活
  6. 标记 is_active = true,此后每条回复注入八字摘要

非首次启用

  1. 用户说「开始算命」→ python3 scripts/main.py status
  2. 有记录 → 显示所有已保存用户列表,询问「用哪个/哪几个」
  3. 用户选一个或多个人 → python3 scripts/main.py active \x3Cname1,name2,...>
  4. 标记 is_active = true,注入对应八字摘要

退出

  • 用户说「停止算命」→ is_active = false

数据文件

data/
├── users.json     # 所有用户的生日+八字(JSON格式)
└── active.json    # 当前激活的用户列表

命令一览

命令 功能
python3 scripts/main.py add \x3Cname> \x3Cyear> \x3Cmonth> \x3Cday> \x3Ctime> \x3Cgender> 添加新用户(time格式:16 / 16:30 / 下午4 / 晚8
python3 scripts/main.py update \x3Cname> \x3Cyear> \x3Cmonth> \x3Cday> \x3Ctime> \x3Cgender> 更新已有用户
python3 scripts/main.py list 列出所有已保存用户
python3 scripts/main.py view [name] 查看某人八字详情(默认当前激活)
python3 scripts/main.py remove \x3Cname> 删除某人八字
python3 scripts/main.py active [name1,name2,...] 设置激活用户,多人用逗号分隔
python3 scripts/main.py status 检查激活状态
python3 scripts/main.py joint [name1,name2] 联合分析(默认当前激活用户)

八字摘要格式(单人被注入到 context)

━━━ 八字信息 ━━━
姓名:{name} | {gender} | 农历{lunar_str}
八字:{year_ganzhi} {month_ganzhi} {day_ganzhi} {hour_ganzhi}
生肖:{shengxiao} | 日主:{me}({yinyang})
五行:{wuxing} | {mingge} | 旺衰:{wangshuai}
喜用:{xiyong}
神煞:{shensha}
大运:{current_dayun}({start_age}-{end_age}岁)
━━━ 八字信息 ━━━

联合分析格式(多人被注入到 context)

━━━ 联合分析 ━━━
【{name1}】{gender} | {bazi_str} | {mingge}
【{name2}】{gender} | {bazi_str} | {mingge}
━━━ 合冲刑害 ━━━
年支关系:{analysis}
日支关系:{analysis}(夫妻/伴侣位)
月支关系:{analysis}
━━━ 五行契合 ━━━
{analysis}
━━━ 婚配分析 ━━━
{analysis}(仅两人时)
━━━ 八字信息 ━━━

触发关键词

关键词 动作
开始算命算命看看八字我的八字 激活算命流程
停止算命不算了退出算命 退出算命模式
联合分析合盘双人八字 触发联合分析
添加八字加个人录入八字 添加新用户
查看用户都有谁八字体检 列出所有已保存用户

联合分析内容

地支关系分析:

  • 年支 vs 年支(双方祖辈/原生家庭/根基是否相合)
  • 日支 vs 日支(夫妻/伴侣位合冲刑害)
  • 月支 vs 月支(父母/环境/外环境关系)

五行契合分析:

  • 喜用五行是否相生(你生我或我生你为吉)
  • 五行是否互补

婚配分析(仅两人时):

  • 日支合冲刑害婚姻判断
  • 桃花重叠警告
  • 天乙贵人重叠吉兆

技术实现

  • 八字计算:完全本地,不依赖任何远程API

  • 依赖库scripts/lunar_core.py 自包含单文件,提供本地农历换算和四柱计算。

    • 计算范围覆盖 1899-2060 年。
    • 无远程 API、无第三方运行时依赖。
  • lunar_core.py 调试经验(2026-04-26 已修复)

    • jd_greg() 反算公历年时曾少减 4800,导致 Solar.toYmd() 出现 67870114 这类错误年份;现已修正 JD → Gregorian 转换。
    • _from_solar() 现在按月首 JD 反推真实农历年,避免 11/12 月重复数据和立春年混用;立春年柱判断放在 _compute() 中按 solar year 查询 LICHUN_JD/LICHUN_YMD
    • 日期比较统一使用 int(s.toYmd()) / int(LICHUN_YMD[year]),exact 年柱用含时分秒的 Julian Day 比较。
    • 三个测试案例:1987/3/14 16:30→丁卯/癸卯/壬戌/戊申;1998/1/19 16:00→丁丑/癸丑/丙寅/丙申;2000/2/1 00:30→己卯/丁丑/己丑/甲子
  • 农历计算:完全自包含的 lunar_core.py,基于 LY_DATA V6B 天文表,覆盖 1899-2060 年。

  • 命格算法(已验证 12/12 测试全过):直接用 TEN_GOD[日干][月干] → 格局映射,一行代码

    def calc_mingge(day_stem, month_stem):
        return TEN_GOD_TO_GE[TEN_GOD[day_stem][month_stem]]
    
    • 9个普通格:正官→正官格,偏官→偏官格,七杀→七杀格,正印→正印格,偏印→偏印格,食神→食神格,伤官→伤官格,正财→正财格,偏财→偏财格
    • 特殊格:比肩→比肩格,劫财→阳刃格
    • 不需要藏干强度表,不需要透干逻辑
    • "财才格" = "正财格" 的别名(2024/2/10 案例验证)
  • 喜用神算法

    • 天干强度表(10天干 × 12月令地支)
    • 地支藏干强度表(12地支藏干 × 12月令地支)
    • 同类总分(日主五行 + 生我五行)vs 异类总分(克我 + 我克 + 泄我)
    • 身强 → 宜泄(取异类);身弱 → 宜扶(取同类)
  • calc.py TEN_GOD table bug(2026-04-26 已修复)

    • 100 个条目全部写错 — 用的是缩写(比/劫/食/伤)而非全称(比肩/劫财/食神/伤官)
    • 修复:替换为完整的十神表(全称版本),重新验证 12 个案例
  • 代码位置:所有 Python 文件统一放在 scripts/ 下,数据文件放在 data/ 下。

  • 代码架构(6个文件)

    scripts/
    ├── main.py    # CLI 入口,命令路由,时间解析
    ├── calc.py    # 八字计算核心(常量和计算逻辑)
    ├── report.py  # 输出格式化(单人详情 / 联合分析)
    ├── store.py   # 数据存储(users.json / active.json)
    ├── lunar_core.py # 自包含农历/八字底层换算
    └── test_lunar_core.py # 单元测试(12 个固定样例 + 128 个随机日期)
    
  • 测试命令python3 -m unittest scripts/test_lunar_core.py

  • 已实现功能

    • 四柱天干地支(含藏干)
    • 五行纳音
    • 十神(以日干为中心)
    • 地支阴阳
    • 旬空
    • 胎元、胎息、命宫、身宫
    • 大运排盘(10步大运)
    • 神煞:桃花、天乙贵人、驿马、将星、劫煞
    • 旺衰判断(量化算法:月令强度 × 天干 + 藏干权重)
    • 喜用判断
    • 联合分析:合冲刑害、五行相生、婚配

注意事项

  • python3 scripts/main.py joint 支持2-N人联合分析,默认用当前激活用户
  • 激活多个用户时,所有人的摘要都注入 context
  • 若只激活一人,格式同单人摘要
  • 注入摘要时放在回复最前面,然后回答问题
  • 大运排盘需要性别参数(第7个参数:男=1,女=0)

架构可复用性

本 skill 的多人+联合分析架构可复用到其他领域:

  • 任何「alias + 结构化数据 + 联合分析」场景都适用
  • 核心数据结构:users.json(key=alias)、active.json(当前激活列表)
  • scripts/main.py(入口)+ scripts/calc.py(计算)+ scripts/report.py(展示)+ scripts/store.py(存储)+ scripts/lunar_core.py(农历换算)
  • 联合分析的维度(合冲刑害/五行/喜用等)可根据不同领域替换
Usage Guidance
This skill appears to do what it says: all calculation is local and there are no network calls or requested credentials. Before installing, consider: (1) privacy — the skill stores names and full birth data in data/users.json and will prepend BaZi summaries to replies for any activated users; avoid saving other people’s sensitive info unless you trust the environment. (2) To stop automatic inclusion of a person's summary, run the active command with 'none' or delete/clear data/active.json or say the provided trigger (e.g., '停止算命'). (3) The files live in the skill directory — delete that directory to remove persisted data, and consider restricting file permissions if others share the machine. (4) If you want extra assurance, review the provided scripts locally or run the unit tests (python3 -m unittest scripts/test_lunar_core.py). (5) If you need remote logging or integration, note this skill currently has no such capability — you would need to inspect/modify code to add it. Overall: functionally coherent and low-risk for code‑level misdirection, but handle persisted birth data as sensitive.
Capability Analysis
Type: OpenClaw Skill Name: fortune-telling-bazi Version: 1.0.2 The skill provides a local BaZi (Chinese astrology) calculation engine and management system. It features a self-contained lunar calendar conversion module (lunar_core.py) and stores user data locally in JSON format (data/users.json). Analysis of the Python scripts (main.py, calc.py, store.py) shows no evidence of data exfiltration, network requests, or unauthorized command execution. The instructions in SKILL.md correctly guide the agent to manage user state and provide astrological context without attempting to subvert the agent's safety boundaries.
Capability Assessment
Purpose & Capability
Name/description match the included files and runtime instructions: all calculation code (lunar_core.py, calc.py, report.py) is present and the CLI (scripts/main.py) implements add/list/view/active/joint as described. No unrelated binaries, cloud credentials, or secrets are requested.
Instruction Scope
SKILL.md instructs the agent to ask for name/birth/gender, run the local Python CLI, save results under data/users.json and data/active.json, and to inject an 八字摘要 into each reply while a user is active. This behavior is coherent with the skill purpose but means collected personal birth data (PII) will be persisted and automatically included in future responses while active — a privacy consideration the user should be aware of.
Install Mechanism
No install script or remote download; this is instruction + local Python source shipped with the skill. No external packages or URLs are fetched during install. Execution is limited to the provided Python files.
Credentials
The skill requires no environment variables or external credentials (correct for a local computation tool). It does persist sensitive personal data (birthdates, names, gender) in data/users.json and active state in data/active.json — these are local files but should be treated as sensitive and protected accordingly.
Persistence & Privilege
always:false and no system-wide changes are requested. The skill writes only to its own data/ directory (users.json, active.json). It marks activation state which causes automatic injection of summaries into responses; this is expected functionality but is persistent until deactivated or data is removed.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install fortune-telling-bazi
  3. After installation, invoke the skill by name or use /fortune-telling-bazi
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.2
- 完全重构,八字农历与四柱计算迁移为本地自包含核心,无需远程API。 - 增加 lunar_core.py:本地农历换算、四柱干支、生肖等算法覆盖1899-2060年。 - 修正干支推算、命格与喜用算法,所有常量及十神表已覆核并纠正。 - 拆分原脚本,新增主入口、报告输出、存储模块和单元测试,提高可维护性和复用性。 - 更新命令行交互、关键词触发和格式注入,支持多人八字联合分析与数据持久化。 - 丰富输出摘要内容,明确神煞、大运、旺衰等字段,并统一格式。
v1.0.1
Version 1.0.1 — 支持多人八字存储和联合分析 - 支持录入、保存和切换多个用户八字资料,实现多人管理 - 新增八字联合分析(合盘),可分析多人的八字关系与匹配度 - 用户可主动选择或切换参与分析的人员 - 新增用户管理命令,如添加、更新、移除、查看和激活用户 - 所有相关触发关键词和摘要格式已更新,方便多用户和合盘操作
v1.0.0
Initial release of the 八字算命 (Bazi Fortune-Telling) skill. - Guides users to input their birth date on first run, fetches and saves Bazi info. - Subsequent conversations automatically include Bazi summary if active. - Users can reactivate, update, or exit Bazi mode with specified keywords. - Status and activation managed via internal `is_active` flag and `user.json`. - Supports commands: status check, fetch, view summary, and clear data on exit.
Metadata
Slug fortune-telling-bazi
Version 1.0.2
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 3
Frequently Asked Questions

What is Fortune Telling Bazi?

八字算命 skill — 支持多人八字存储+联合分析,首次询问生日,后续对话自动附带八字信息。说"停止算命"退出。 It is an AI Agent Skill for Claude Code / OpenClaw, with 105 downloads so far.

How do I install Fortune Telling Bazi?

Run "/install fortune-telling-bazi" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is Fortune Telling Bazi free?

Yes, Fortune Telling Bazi is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does Fortune Telling Bazi support?

Fortune Telling Bazi is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created Fortune Telling Bazi?

It is built and maintained by youhan2021 (@youhan2021); the current version is v1.0.2.

💬 Comments