ziwei-cli 1.1.2 → 1.1.3

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.
@@ -16,28 +16,13 @@ function buildQueryDate(year, month = 1, day = 1) {
16
16
  }
17
17
 
18
18
  /**
19
- * 获取指定层级的宫位及三方四正
19
+ * 获取指定层级的宫位及三方四正(统一走 horoscope 接口)
20
20
  */
21
- function getScopedPalaceAndSurrounded(astrolabe, palaceName, scope, queryDate) {
22
- if (scope === 'origin') {
23
- // 本命层直接从 astrolabe 获取
24
- const targetPalace = astrolabe.palace(palaceName);
25
- const surroundedPalaces = astrolabe.surroundedPalaces(palaceName);
26
- return { targetPalace, surroundedPalaces, scopeData: {} };
27
- } else {
28
- // 运限层从 horoscope 获取
29
- const horoscope = astrolabe.horoscope(queryDate);
30
- const scopeData = horoscope[scope];
31
-
32
- if (!scopeData) {
33
- throw new Error(`无效的运限范围: ${scope}`);
34
- }
35
-
36
- const targetPalace = horoscope.palace(palaceName, scope);
37
- const surroundedPalaces = horoscope.surroundPalaces(palaceName, scope);
38
-
39
- return { targetPalace, surroundedPalaces, scopeData };
40
- }
21
+ function getScopedPalaceAndSurrounded(horoscope, palaceName, scope) {
22
+ const scopeData = horoscope[scope] || {};
23
+ const targetPalace = horoscope.palace(palaceName, scope);
24
+ const surroundedPalaces = horoscope.surroundPalaces(palaceName, scope);
25
+ return { targetPalace, surroundedPalaces, scopeData };
41
26
  }
42
27
 
43
28
  /**
@@ -87,18 +72,20 @@ export async function executePalace(options) {
87
72
  is_leap: leap || false
88
73
  });
89
74
 
90
- // 获取目标宫位名称
91
- // origin 模式需要带"宫"字,horoscope 模式不需要
92
- const palaceNameWithSuffix = palace.replace(/宫$/, '') + '';
93
- const palaceNameWithoutSuffix = palace.replace(/宫$/, '');
94
- const targetPalaceName = scope === 'origin' ? palaceNameWithSuffix : palaceNameWithoutSuffix;
75
+ // 归一化宫位名称:iztro 内部除"命宫"外均不带"宫"字
76
+ const base = palace.replace(/宫$/, '');
77
+ const targetPalaceName = base === '' ? '命宫' : base;
78
+
79
+ // 构建查询日期(origin 用今天的日期,不影响本命数据)
80
+ const queryDate = scope !== 'origin'
81
+ ? buildQueryDate(year, month || 1, day || 1)
82
+ : new Date().toISOString().slice(0, 10);
95
83
 
96
- // 构建查询日期
97
- const queryDate = scope !== 'origin' ? buildQueryDate(year, month || 1, day || 1) : null;
84
+ // 统一通过 horoscope 接口查询所有层级
85
+ const horoscope = astrolabe.horoscope(queryDate);
98
86
 
99
- // 获取目标宫位和三方四正
100
87
  const { targetPalace, surroundedPalaces, scopeData } = getScopedPalaceAndSurrounded(
101
- astrolabe, targetPalaceName, scope, queryDate
88
+ horoscope, targetPalaceName, scope
102
89
  );
103
90
 
104
91
  if (!targetPalace) {
@@ -109,13 +96,7 @@ export async function executePalace(options) {
109
96
  }
110
97
 
111
98
  // 检测格局
112
- let patterns;
113
- if (scope === 'origin') {
114
- patterns = detectPatterns(astrolabe);
115
- } else {
116
- const horoscope = astrolabe.horoscope(queryDate);
117
- patterns = detectPatterns(horoscope, scope);
118
- }
99
+ const patterns = detectPatterns(horoscope, scope);
119
100
 
120
101
  // 构建结果
121
102
  const result = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ziwei-cli",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "紫微斗数 + 八字命理分析 CLI 工具 - Claude Code / OpenClaw Skill",
5
5
  "type": "module",
6
6
  "main": "bin/ziwei.js",