kaabalah 5.1.1 → 5.2.0

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.
package/dist/cli.mjs CHANGED
@@ -158,6 +158,28 @@ var COMMANDS = [
158
158
  "kaabalah astrology 1990-01-15 --lat=40.7128 --lon=-74.006 --json"
159
159
  ]
160
160
  },
161
+ {
162
+ name: "astrology:synastry",
163
+ description: "Calculate synastry (cross-chart aspects) between two birth charts",
164
+ args: [],
165
+ flags: [
166
+ { name: "house-system", type: "string", default: "placidus", description: "House system for both charts" }
167
+ ],
168
+ examples: [
169
+ `kaabalah astrology:synastry --input-json='{"chartA":{"date":"1990-01-15","time":"14:30","lat":40.71,"lon":-74},"chartB":{"date":"1992-06-20","time":"09:00","lat":51.5,"lon":-0.12}}' --json --compact`
170
+ ]
171
+ },
172
+ {
173
+ name: "astrology:composite",
174
+ description: "Calculate midpoint composite chart from two birth charts",
175
+ args: [],
176
+ flags: [
177
+ { name: "house-system", type: "string", default: "placidus", description: "House system for both charts" }
178
+ ],
179
+ examples: [
180
+ `kaabalah astrology:composite --input-json='{"chartA":{"date":"1990-01-15","time":"14:30","lat":40.71,"lon":-74},"chartB":{"date":"1992-06-20","time":"09:00","lat":51.5,"lon":-0.12}}' --json --compact`
181
+ ]
182
+ },
161
183
  {
162
184
  name: "help",
163
185
  description: "Show help message",
@@ -902,6 +924,187 @@ Node types (${Object.keys(counts).length}):
902
924
  }
903
925
  console.log();
904
926
  }
927
+ function parseChartInput(input, label, flags) {
928
+ const dateStr = input.date;
929
+ if (!dateStr) {
930
+ exitWithError("MISSING_ARGUMENT", `${label}: "date" is required (YYYY-MM-DD).`, flags);
931
+ }
932
+ parseDate(dateStr, flags);
933
+ const timeStr = input.time ?? "12:00";
934
+ const timeMatch = timeStr.match(/^(\d{1,2}):(\d{2})$/);
935
+ if (!timeMatch) {
936
+ exitWithError("INVALID_ARGUMENT", `${label}: Invalid time format "${timeStr}". Use HH:MM.`, flags);
937
+ }
938
+ const hour = parseInt(timeMatch[1], 10);
939
+ const minute = parseInt(timeMatch[2], 10);
940
+ if (hour < 0 || hour > 23 || minute < 0 || minute > 59) {
941
+ exitWithError("INVALID_ARGUMENT", `${label}: Invalid time "${timeStr}". Hours 0-23, minutes 0-59.`, flags);
942
+ }
943
+ const latitude = input.lat != null ? Number(input.lat) : void 0;
944
+ const longitude = input.lon != null ? Number(input.lon) : void 0;
945
+ if (latitude == null || longitude == null) {
946
+ exitWithError("MISSING_ARGUMENT", `${label}: "lat" and "lon" are required.`, flags);
947
+ }
948
+ if (latitude < -90 || latitude > 90) {
949
+ exitWithError("INVALID_ARGUMENT", `${label}: Latitude must be between -90 and 90, got ${latitude}.`, flags);
950
+ }
951
+ if (longitude < -180 || longitude > 180) {
952
+ exitWithError("INVALID_ARGUMENT", `${label}: Longitude must be between -180 and 180, got ${longitude}.`, flags);
953
+ }
954
+ const houseSystem = input.houseSystem ?? "placidus";
955
+ const houseSystemCode = HOUSE_SYSTEM_MAP[houseSystem.toLowerCase()];
956
+ if (!houseSystemCode) {
957
+ exitWithError("INVALID_ARGUMENT", `${label}: Unknown house system "${houseSystem}". Valid: ${Object.keys(HOUSE_SYSTEM_MAP).join(", ")}`, flags);
958
+ }
959
+ const timezoneStr = input.timezone;
960
+ const timeZoneSettings = {};
961
+ if (timezoneStr) {
962
+ timeZoneSettings.timeZone = timezoneStr;
963
+ } else {
964
+ timeZoneSettings.autoTimeZone = true;
965
+ }
966
+ const dateParts = dateStr.match(/^(\d{4})-(\d{2})-(\d{2})$/);
967
+ const birthDate = new Date(
968
+ parseInt(dateParts[1], 10),
969
+ parseInt(dateParts[2], 10) - 1,
970
+ parseInt(dateParts[3], 10),
971
+ hour,
972
+ minute,
973
+ 0
974
+ );
975
+ return { birthDate, latitude, longitude, houseSystem, houseSystemCode, timeZoneSettings, dateStr, timeStr };
976
+ }
977
+ async function initWasm() {
978
+ const path = __require("path");
979
+ const wasmPath = path.resolve(__dirname, "../wasm/build/swisseph.node.wasm");
980
+ const ephePath = path.resolve(__dirname, "../ephe");
981
+ const { getSwissEph } = await import('./astrology/index.mjs');
982
+ await getSwissEph({ wasmPath, ephePath });
983
+ }
984
+ async function cmdAstrologySynastry(flags, inputPayload) {
985
+ if (!inputPayload?.chartA || !inputPayload?.chartB) {
986
+ exitWithError("MISSING_ARGUMENT", `Usage: kaabalah astrology:synastry --input-json='{"chartA":{...},"chartB":{...}}'`, flags);
987
+ }
988
+ const chartAInput = parseChartInput(inputPayload.chartA, "chartA", flags);
989
+ const chartBInput = parseChartInput(inputPayload.chartB, "chartB", flags);
990
+ const { getSynastryChart, closeSwissEph, HouseSystem } = await import('./astrology/index.mjs');
991
+ try {
992
+ await initWasm();
993
+ } catch (err) {
994
+ exitWithError("WASM_INIT_ERROR", `Failed to initialize Swiss Ephemeris: ${err instanceof Error ? err.message : String(err)}`, flags);
995
+ }
996
+ try {
997
+ const result = await getSynastryChart({
998
+ chartA: {
999
+ date: chartAInput.birthDate,
1000
+ latitude: chartAInput.latitude,
1001
+ longitude: chartAInput.longitude,
1002
+ houseSystem: chartAInput.houseSystemCode,
1003
+ timeZoneSettings: chartAInput.timeZoneSettings
1004
+ },
1005
+ chartB: {
1006
+ date: chartBInput.birthDate,
1007
+ latitude: chartBInput.latitude,
1008
+ longitude: chartBInput.longitude,
1009
+ houseSystem: chartBInput.houseSystemCode,
1010
+ timeZoneSettings: chartBInput.timeZoneSettings
1011
+ },
1012
+ aspectSpecs: inputPayload.aspectSpecs
1013
+ });
1014
+ if (isJsonMode(flags)) {
1015
+ outputJson({
1016
+ ...result,
1017
+ input: {
1018
+ chartA: { date: chartAInput.dateStr, time: chartAInput.timeStr, lat: chartAInput.latitude, lon: chartAInput.longitude, houseSystem: chartAInput.houseSystem },
1019
+ chartB: { date: chartBInput.dateStr, time: chartBInput.timeStr, lat: chartBInput.latitude, lon: chartBInput.longitude, houseSystem: chartBInput.houseSystem }
1020
+ }
1021
+ }, flags);
1022
+ } else {
1023
+ console.log(`
1024
+ Synastry Chart
1025
+ `);
1026
+ console.log(` Chart A: ${chartAInput.dateStr} ${chartAInput.timeStr} (${chartAInput.latitude}, ${chartAInput.longitude})`);
1027
+ console.log(` Chart B: ${chartBInput.dateStr} ${chartBInput.timeStr} (${chartBInput.latitude}, ${chartBInput.longitude})`);
1028
+ console.log(`
1029
+ Cross-chart Aspects (${result.aspects.length}):
1030
+ `);
1031
+ for (const a of result.aspects) {
1032
+ console.log(` ${a.planetA.padEnd(14)} ${a.aspect.padEnd(12)} ${a.planetB.padEnd(14)} orb ${a.orb.toFixed(2)}\xB0`);
1033
+ }
1034
+ console.log();
1035
+ }
1036
+ } finally {
1037
+ closeSwissEph();
1038
+ }
1039
+ }
1040
+ async function cmdAstrologyComposite(flags, inputPayload) {
1041
+ if (!inputPayload?.chartA || !inputPayload?.chartB) {
1042
+ exitWithError("MISSING_ARGUMENT", `Usage: kaabalah astrology:composite --input-json='{"chartA":{...},"chartB":{...}}'`, flags);
1043
+ }
1044
+ const chartAInput = parseChartInput(inputPayload.chartA, "chartA", flags);
1045
+ const chartBInput = parseChartInput(inputPayload.chartB, "chartB", flags);
1046
+ const { getCompositeChart, closeSwissEph, HouseSystem } = await import('./astrology/index.mjs');
1047
+ try {
1048
+ await initWasm();
1049
+ } catch (err) {
1050
+ exitWithError("WASM_INIT_ERROR", `Failed to initialize Swiss Ephemeris: ${err instanceof Error ? err.message : String(err)}`, flags);
1051
+ }
1052
+ try {
1053
+ const result = await getCompositeChart({
1054
+ chartA: {
1055
+ date: chartAInput.birthDate,
1056
+ latitude: chartAInput.latitude,
1057
+ longitude: chartAInput.longitude,
1058
+ houseSystem: chartAInput.houseSystemCode,
1059
+ timeZoneSettings: chartAInput.timeZoneSettings
1060
+ },
1061
+ chartB: {
1062
+ date: chartBInput.birthDate,
1063
+ latitude: chartBInput.latitude,
1064
+ longitude: chartBInput.longitude,
1065
+ houseSystem: chartBInput.houseSystemCode,
1066
+ timeZoneSettings: chartBInput.timeZoneSettings
1067
+ },
1068
+ aspectSpecs: inputPayload.aspectSpecs
1069
+ });
1070
+ if (isJsonMode(flags)) {
1071
+ outputJson({
1072
+ ...result,
1073
+ input: {
1074
+ chartA: { date: chartAInput.dateStr, time: chartAInput.timeStr, lat: chartAInput.latitude, lon: chartAInput.longitude, houseSystem: chartAInput.houseSystem },
1075
+ chartB: { date: chartBInput.dateStr, time: chartBInput.timeStr, lat: chartBInput.latitude, lon: chartBInput.longitude, houseSystem: chartBInput.houseSystem }
1076
+ }
1077
+ }, flags);
1078
+ } else {
1079
+ console.log(`
1080
+ Composite Chart (Midpoint Method)
1081
+ `);
1082
+ console.log(` Chart A: ${chartAInput.dateStr} ${chartAInput.timeStr} (${chartAInput.latitude}, ${chartAInput.longitude})`);
1083
+ console.log(` Chart B: ${chartBInput.dateStr} ${chartBInput.timeStr} (${chartBInput.latitude}, ${chartBInput.longitude})`);
1084
+ console.log(`
1085
+ Composite Planets:`);
1086
+ for (const [name, planet] of Object.entries(result.compositePlanets)) {
1087
+ const zp = planet.zodiacPosition;
1088
+ console.log(` ${name.padEnd(14)} ${zp.sign.padEnd(12)} ${zp.traditionalFormat.padEnd(8)} House ${zp.house}`);
1089
+ }
1090
+ console.log(`
1091
+ Composite House Cusps:`);
1092
+ for (let i = 0; i < result.compositeHouses.length; i++) {
1093
+ const h = result.compositeHouses[i];
1094
+ console.log(` House ${String(i + 1).padStart(2)}: ${h.sign.padEnd(12)} ${h.traditionalFormat}`);
1095
+ }
1096
+ console.log(`
1097
+ Composite Aspects (${result.aspects.length}):
1098
+ `);
1099
+ for (const a of result.aspects) {
1100
+ console.log(` ${a.planetA.padEnd(14)} ${a.aspect.padEnd(12)} ${a.planetB.padEnd(14)} orb ${a.orb.toFixed(2)}\xB0`);
1101
+ }
1102
+ console.log();
1103
+ }
1104
+ } finally {
1105
+ closeSwissEph();
1106
+ }
1107
+ }
905
1108
  async function cmdAstrology(args, flags, inputPayload) {
906
1109
  const dateStr = inputPayload?.date ?? args[0];
907
1110
  if (!dateStr) {
@@ -1150,6 +1353,12 @@ async function main() {
1150
1353
  case "astrology":
1151
1354
  await cmdAstrology(args.slice(1), flags, inputPayload);
1152
1355
  break;
1356
+ case "astrology:synastry":
1357
+ await cmdAstrologySynastry(flags, inputPayload);
1358
+ break;
1359
+ case "astrology:composite":
1360
+ await cmdAstrologyComposite(flags, inputPayload);
1361
+ break;
1153
1362
  case "--version":
1154
1363
  if (isJsonMode(flags)) {
1155
1364
  outputJson({ version: VERSION }, flags);