Chinese traditional divination based on the Nine-Palace hand technique (九宫掌诀). Generates three-pass (三传) predictions with multi-layer analysis, then provides AI-powered interpretation grounded in traditional methodology.
Workflow
- Determine input mode (numbers / datetime / Chinese chars / current time).
- Run
scripts/xiaoliu.py --format jsonto compute the prediction (now returns a rich analytical JSON — see "JSON Schema" below). - Check if
config.yamlexists and has amodelfield:- No config (default): Display
ℹ️ 当前使用 Claude Code 内置模型解读。如需使用第三方模型,请创建 config.yaml. Then perform the built-in LLM analysis following the "Seven-Step Interpretation Framework" below. - Has config + API key: Display
ℹ️ 当前使用 <model> 解读. Pipe the prediction JSON intoscripts/interpret.py:uv run scripts/xiaoliu.py --now --question "问题" --format json | \ uv run scripts/interpret.py --question "问题" - Has config, missing API key: Display
⚠️ 请在 .env 中设置 <ENV_KEY>. Fall back to built-in LLM analysis.
- No config (default): Display
- Format the final report using
assets/template.md, filling all placeholders with the prediction JSON and the LLM analysis.
Quick Start
# By three numbers
uv run scripts/xiaoliu.py --numbers 1,2,3 --question "今日运势" --format json
# By date/time (auto-converted to lunar month / day / hour-branch)
uv run scripts/xiaoliu.py --datetime "2025-07-15 10:30" --question "面试能成功吗" --format json
# By Chinese characters (uses stroke count)
uv run scripts/xiaoliu.py --chars "天地人" --question "感情运势" --format json
# By current time
uv run scripts/xiaoliu.py --now --question "今天适合出行吗" --format json
Use --format json for LLM analysis. Use --format text for direct human-readable display (already includes the analytical sections).
Input Mode Selection
| User says | Mode | Example |
|---|---|---|
| gives 3 numbers | --numbers |
--numbers 3,5,7 |
| mentions a date/time | --datetime |
--datetime "2025-01-31 14:30" |
| gives Chinese characters | --chars |
--chars "天地人" |
| "use the current time" / "now" | --now |
--now |
| no specific input | --now |
default to current time |
JSON Schema (key analytical fields)
The script now outputs a structured JSON with these top-level fields:
| Field | Purpose |
|---|---|
input |
Input mode metadata (mode, raw, lunar/hour for datetime modes, stroke_counts for chars) |
input_numbers |
The three step numbers used for 三传 computation |
passes |
The three passes; each has position, role (体/枢/用), symbol with auspice/auspice_level/question_lens |
relations |
Pairwise five-element relations between adjacent passes, with meaning |
subject_object |
体用关系: subject (initial) vs object (final) — relation + interpretation |
flow |
Overall five-element flow pattern (连珠相生 / 连珠相克 / 三同比和 / 始克终生 / ... ) with explanation |
patterns |
overall_pattern (三吉/二吉一凶/...), grade (上上格..下下格), trend (渐入佳境/苦尽甘来/...), auspice_score |
combinations |
Detected special combinations (双符 / 三符格局) with valence |
timing_guidance |
Season, months, hours, directions (based on末传 element + 三传 auspice-sorted directions), favorable deities |
question |
Echo of the user's question |
Key field for question-aware interpretation: passes[i].symbol.question_lens provides each symbol's auspice level (-2..+2) for each of 8 question categories (财运/情感/事业/健康/学业/家庭/官非/出行). Always prefer the lens value over the base auspice_level when the user's question category is identifiable.
Seven-Step Interpretation Framework
When performing the built-in LLM analysis (Claude Code's own model, no third-party config), follow this rigorous seven-step traditional framework. (scripts/interpret.py embeds the same framework in its system prompt for third-party models.)
Step 1: Identify Question Category (识别问题类别)
Map the user's question to one of 8 categories — this determines which question_lens index to use:
| Category | Keywords |
|---|---|
| Wealth | money, wealth, business, investment, raise, bonus, buying and selling |
| Romance | dating, feelings, marriage, partner, reconciliation, breakup |
| Career | work, project, promotion, job change, offer, interview |
| Health | illness, surgery, recovery, examination, physical checkup |
| Studies | exam, further education, studying abroad, thesis, study |
| Family | family members, parents, children, spouse, family matters |
| Legal disputes | lawsuit, litigation, dispute, law |
| Travel | business trip, travel, moving house, long journey, transfer |
If no clear question or "综合运势": fall back to base auspice_level.
Step 2: 体用定位 (Subject-Object Positioning)
- 初传 = 体 (cause of the problem / the questioner themselves)
- 末传 = 用 (the matter asked about / the final outcome)
- 中传 = 枢 (process pivot)
Use subject_object.interpretation from the JSON.
Step 3: 三传时序分析 (Sequential Analysis with Question Lens)
For each pass, answer:
- In this question category, what does this symbol mean? — Use
question_lens[category]from each pass's symbol. - Five-element relation with the adjacent pass — Use
relations[i].meaning. - Direction and deity — what energy does this position channel?
Critical: the same symbol means different things across categories. Examples:
- 桃花 → Romance +2 great fortune, Career -1 minor misfortune
- 大安 → Health +2 great fortune, Travel -1 minor misfortune (favors stillness over activity)
- 速喜 → Wealth +2 great fortune, Health -1 minor misfortune (sudden illness)
Step 4: 五行整体流转 (Overall Five-Element Flow)
Use flow.pattern + flow.explanation + patterns.trend:
- 连珠相生 → fortune flows continuously, the most auspicious flow
- 连珠相克 → each level is constrained, the most inauspicious flow
- 始克终生 → bitterness first, sweetness later
- 始生终克 → prosperity at its peak gives way to decline
- 三同比和 → power is concentrated, hard to change suddenly
- etc.
Step 5: Special Combination Detection (Detect Combinations)
Use combinations list:
- Three-token pattern → defines the entire cast.
- Two-token combination: valence "+" reinforces auspicious signs / "-" warns of danger / "0" depends on actions
- If empty: skip; rely on basic analysis.
See references/combinations_reference.md for detailed combination meanings.
Step 6: Timing & Direction (Timing & Direction)
Use timing_guidance:
- Timing: season, months, hours (based on the element of the final transmission)
- Auspicious direction:
favorable_directions_from_passes - Directions to avoid:
avoid_directions_from_passes - Spiritual beings that can be invoked:
favorable_deities
Step 7: Synthesis & Advice (Synthesis & Advice)
Tie everything back to the user's specific question. Give a clear answer (能成 / 不能成 / 部分成 / 需某条件).
Built-in LLM Output Structure
Generate analysis in this exact section order (matches assets/template.md placeholders):
- 🎯 Hexagram Overview (
ai_overview) — one paragraph: overall pattern + five-element flow + trend (1-2 sentences to set the tone) - ⏳ Timeline (
ai_timeline) — three sections: initial transmission / middle transmission / final transmission, each 2-4 sentences with a question lens - ⚖️ Body/Function and Five Elements (
ai_subject_object_flow) — explain "why the situation is heading this way": body-function relationship × five-element flow - 🌟 Key Combinations (
ai_combinations) — 1-2 most relevant combinations, or note that none formed - 🧭 Timing and Direction (
ai_timing_direction) — when / where / which deity to invoke - 💡 Action Advice (
ai_advice) — 3-5 concrete actionable bullets - 🔮 Conclusion (
ai_conclusion) — 1-2 sentences: direct answer to the question
Style Guidelines
- Always stay tightly focused on the user's question—never speak in generalities.
- The final transmission is the most important (final pass = primary indicator).
- Avoid extreme assertions—use "宜" "忌" "可" "需" etc. to leave room.
- Elegant, philosophical Chinese, but accessible.
- Total length: 700-1100 Chinese characters for the LLM analysis portion.
Report Output
After generating the prediction JSON and the LLM analysis, format using assets/template.md. Replace all {{placeholder}} variables with values from the script output and the LLM analysis.
Key template variables
From xiaoliu.py JSON output:
{{timestamp}},{{input_mode}},{{input_data}},{{input_numbers}},{{question}}{{overall_pattern}},{{grade}},{{auspice_score}},{{trend}},{{trend_explanation_short}}{{flow_pattern}},{{element_sequence}},{{flow_explanation}}- Per pass:
{{first_name}},{{first_element}},{{first_auspice}},{{first_level}},{{first_description}},{{first_interpretation}},{{first_direction}},{{first_deity}},{{first_lens_value}}(andsecond_*,third_*analogously) {{relation_1_2}},{{relation_2_3}},{{relation_1_2_meaning}},{{relation_2_3_meaning}}{{subject_object_relation}},{{subject_object_interpretation}},{{subject_object_summary}},{{subject_object_relation_short}}{{primary_element}},{{element_spirit}},{{season}},{{favorable_months}},{{favorable_hours}},{{element_directions}},{{favorable_directions_from_passes}},{{avoid_directions_from_passes}},{{favorable_deities}},{{favorable_colors}}{{#combinations}}...{{/combinations}}block: iterates over thecombinationsarray, each item has{{combo_name}},{{combo_type}},{{combo_symbols}},{{combo_meaning}}. If empty, replace the whole loop with the note "本卦三传无形成传统特殊组合,回归基础卦象分析。"
From LLM analysis (you generate these strings):
{{ai_overview}},{{ai_timeline}},{{ai_subject_object_flow}},{{ai_combinations}},{{ai_timing_direction}},{{ai_advice}},{{ai_conclusion}}- For question-lens explanations:
{{first_lens_explanation}},{{second_lens_explanation}},{{third_lens_explanation}}(brief 1-line explanation tying the lens value to the user's question)
Third-Party Model Configuration (Optional)
By default, the skill uses Claude Code's built-in LLM for interpretation. To use a third-party model:
Step 1: Create config.yaml
# 格式: provider:model_name
model: deepseek:deepseek-chat
Step 2: Set API Key in .env
DEEPSEEK_API_KEY=sk-...
Supported Providers
| Provider prefix | API Key env var | Notes |
|---|---|---|
openai |
OPENAI_API_KEY |
GPT series |
anthropic |
ANTHROPIC_API_KEY |
Claude series |
google-gla |
GEMINI_API_KEY |
Gemini series |
deepseek |
DEEPSEEK_API_KEY |
DeepSeek |
kimi |
MOONSHOT_API_KEY |
Moonshot Kimi |
qwen |
DASHSCOPE_API_KEY |
Alibaba Qwen |
glm |
ZHIPU_API_KEY |
Zhipu ChatGLM |
interpret.py embeds the same seven-step framework as a system prompt, so third-party models produce comparably structured output. To switch back to the built-in LLM, delete config.yaml.
References
references/symbols_reference.md— Detailed explanation of the nine-palace symbols (differentiated by 8 types of questions)references/interpretation_framework.md— Seven-step interpretation framework methodologyreferences/combinations_reference.md— Two-token / three-token special combination spectrumexamples/— Examples of three input methods