kaabalah 4.9.1 → 5.0.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 ADDED
@@ -0,0 +1,993 @@
1
+ import { calculateOdu } from './chunk-YTZCZRJG.mjs';
2
+ import { calculateFibonacciCycle, calculateChallenges, calculatePersonalCycles, calculateCycles, calculateKaabalisticLifePath, calculateStraightAcrossReductionLifePath, getDateEnergies, calculatePersonalYear } from './chunk-KSKAKQTM.mjs';
3
+ import { reverseGematria, calculateGematria } from './chunk-X2SPWMUA.mjs';
4
+ import { createTree, SYSTEM } from './chunk-JBMCNKO4.mjs';
5
+ import { ARKANNUS, shuffleTarotDeck } from './chunk-M7XQFDS4.mjs';
6
+ import { __require } from './chunk-WY6NIR2V.mjs';
7
+ import 'dotenv/config';
8
+
9
+ var VERSION = "4.9.1";
10
+ var GLOBAL_FLAGS = [
11
+ { name: "json", type: "boolean", default: false, description: "Output as JSON (auto-enabled when stdout is not a TTY)" },
12
+ { name: "no-json", type: "boolean", default: false, description: "Force human-readable output even when piped" },
13
+ { name: "compact", type: "boolean", default: false, description: "Minified JSON output (no indentation)" },
14
+ { name: "fields", type: "string", description: "Comma-separated dot-paths to filter JSON output (e.g. --fields=a.b,c.d)" },
15
+ { name: "input-json", type: "string", description: "JSON string with command parameters (alternative to positional args)" }
16
+ ];
17
+ var COMMANDS = [
18
+ {
19
+ name: "gematria",
20
+ description: "Calculate gematria for a word/phrase",
21
+ args: [{ name: "text", type: "string", required: true, description: "Text to calculate gematria for" }],
22
+ flags: [
23
+ { name: "missing", type: "boolean", default: false, description: "Show missing gematria values" },
24
+ { name: "percentages", type: "boolean", default: false, description: "Show letter percentages" }
25
+ ],
26
+ examples: ['kaabalah gematria "Mat Moura"', 'kaabalah gematria "Mat Moura" --json']
27
+ },
28
+ {
29
+ name: "gematria:reverse",
30
+ description: "Find letter combos matching a gematria value",
31
+ args: [{ name: "target", type: "number", required: true, description: "Target synthesis number" }],
32
+ flags: [
33
+ { name: "max-results", type: "number", default: 20, description: "Maximum results to return (max 10000)" },
34
+ { name: "min-length", type: "number", default: 2, description: "Minimum letters per combination" },
35
+ { name: "max-length", type: "number", default: 6, description: "Maximum letters per combination" },
36
+ { name: "include-digraphs", type: "boolean", default: false, description: "Include digraphs like PH, SH" }
37
+ ],
38
+ examples: ["kaabalah gematria:reverse 22", "kaabalah gematria:reverse 22 --max-results=50 --json"]
39
+ },
40
+ {
41
+ name: "numerology",
42
+ description: "Full numerological profile for a birth date",
43
+ args: [{ name: "date", type: "date", required: true, description: "Birth date in YYYY-MM-DD format" }],
44
+ flags: [],
45
+ examples: ["kaabalah numerology 1990-01-15", "kaabalah numerology 1990-01-15 --json --fields=kaabalistic.lifePath.reducedValue"]
46
+ },
47
+ {
48
+ name: "numerology:lifepath",
49
+ description: "Life path number (kaabalistic method)",
50
+ args: [{ name: "date", type: "date", required: true, description: "Birth date in YYYY-MM-DD format" }],
51
+ flags: [],
52
+ examples: ["kaabalah numerology:lifepath 1990-01-15"]
53
+ },
54
+ {
55
+ name: "numerology:cycles",
56
+ description: "Personal cycles (year, month, periods)",
57
+ args: [
58
+ { name: "date", type: "date", required: true, description: "Birth date in YYYY-MM-DD format" },
59
+ { name: "firstName", type: "string", required: false, description: "First name for personal cycles" }
60
+ ],
61
+ flags: [],
62
+ examples: ["kaabalah numerology:cycles 1990-01-15", "kaabalah numerology:cycles 1990-01-15 Mateus"]
63
+ },
64
+ {
65
+ name: "numerology:challenges",
66
+ description: "Challenges from birth date",
67
+ args: [{ name: "date", type: "date", required: true, description: "Birth date in YYYY-MM-DD format" }],
68
+ flags: [],
69
+ examples: ["kaabalah numerology:challenges 1990-01-15"]
70
+ },
71
+ {
72
+ name: "numerology:fibonacci",
73
+ description: "Fibonacci cycle for current age",
74
+ args: [{ name: "date", type: "date", required: true, description: "Birth date in YYYY-MM-DD format" }],
75
+ flags: [],
76
+ examples: ["kaabalah numerology:fibonacci 1990-01-15"]
77
+ },
78
+ {
79
+ name: "tarot",
80
+ description: "Draw tarot cards (default: 3)",
81
+ args: [{ name: "count", type: "number", required: false, description: "Number of cards to draw (1-78, default: 3)" }],
82
+ flags: [
83
+ { name: "inverted", type: "boolean", default: false, description: "Include inverted cards" },
84
+ { name: "shuffle-count", type: "number", default: 7, description: "Number of times to shuffle the deck" }
85
+ ],
86
+ examples: ["kaabalah tarot 5 --inverted", "kaabalah tarot --json"]
87
+ },
88
+ {
89
+ name: "tarot:card",
90
+ description: "Look up a specific card (1-78)",
91
+ args: [{ name: "number", type: "number", required: true, description: "Card number (1-78)" }],
92
+ flags: [],
93
+ examples: ["kaabalah tarot:card 7", "kaabalah tarot:card 22 --json"]
94
+ },
95
+ {
96
+ name: "ifa",
97
+ description: "Calculate Odu from a date",
98
+ args: [{ name: "date", type: "date", required: true, description: "Date in YYYY-MM-DD format" }],
99
+ flags: [],
100
+ examples: ["kaabalah ifa 1990-01-15"]
101
+ },
102
+ {
103
+ name: "tree",
104
+ description: "Show Tree of Life structure",
105
+ args: [],
106
+ flags: [],
107
+ examples: ["kaabalah tree", "kaabalah tree --json"]
108
+ },
109
+ {
110
+ name: "astrology",
111
+ description: "Calculate birth chart using Swiss Ephemeris",
112
+ args: [
113
+ { name: "date", type: "date", required: true, description: "Birth date in YYYY-MM-DD format" },
114
+ { name: "time", type: "string", required: false, description: "Birth time in HH:MM format (default: 12:00)" }
115
+ ],
116
+ flags: [
117
+ { name: "lat", type: "number", description: "Latitude (-90 to 90)" },
118
+ { name: "lon", type: "number", description: "Longitude (-180 to 180)" },
119
+ { name: "location", type: "string", description: "Location string for geocoding (requires GOOGLE_MAPS_API_KEY env var)" },
120
+ { name: "house-system", type: "string", default: "placidus", description: "House system: placidus, koch, porphyrius, regiomontanus, campanus, equal, whole-sign, meridian, morinus, krusinski, alcabitius" },
121
+ { name: "timezone", type: "string", description: "IANA timezone string (e.g. America/New_York). Auto-resolved from coordinates if omitted" }
122
+ ],
123
+ examples: [
124
+ "kaabalah astrology 1990-01-15 14:30 --lat=-23.5505 --lon=-46.6333",
125
+ 'kaabalah astrology 1990-01-15 14:30 --location="S\xE3o Paulo, Brazil"',
126
+ "kaabalah astrology 1990-01-15 --lat=40.7128 --lon=-74.006 --json"
127
+ ]
128
+ },
129
+ {
130
+ name: "help",
131
+ description: "Show help message",
132
+ args: [{ name: "command", type: "string", required: false, description: "Command to show help for" }],
133
+ flags: [],
134
+ examples: ["kaabalah help", "kaabalah help --json", "kaabalah help astrology --json"]
135
+ }
136
+ ];
137
+ function parseArgs(argv) {
138
+ const args = [];
139
+ const flags = {};
140
+ for (const arg of argv.slice(2)) {
141
+ if (arg.startsWith("--")) {
142
+ const eqIdx = arg.indexOf("=");
143
+ if (eqIdx !== -1) {
144
+ flags[arg.slice(2, eqIdx)] = arg.slice(eqIdx + 1);
145
+ } else {
146
+ flags[arg.slice(2)] = true;
147
+ }
148
+ } else {
149
+ args.push(arg);
150
+ }
151
+ }
152
+ if (!process.stdout.isTTY && flags["no-json"] !== true) {
153
+ flags.json = true;
154
+ }
155
+ return { args, flags };
156
+ }
157
+ function getFlagString(flags, name) {
158
+ const v = flags[name];
159
+ return typeof v === "string" ? v : void 0;
160
+ }
161
+ function getFlagNumber(flags, name) {
162
+ const v = flags[name];
163
+ if (typeof v === "string") {
164
+ const n = Number(v);
165
+ return isNaN(n) ? void 0 : n;
166
+ }
167
+ return void 0;
168
+ }
169
+ function getFlagBool(flags, name) {
170
+ return flags[name] === true;
171
+ }
172
+ function isJsonMode(flags) {
173
+ return flags.json === true || typeof flags.json === "string";
174
+ }
175
+ function parseInputJson(flags) {
176
+ const raw = getFlagString(flags, "input-json");
177
+ if (!raw) return null;
178
+ try {
179
+ const parsed = JSON.parse(raw);
180
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
181
+ exitWithError("INVALID_JSON", "--input-json must be a JSON object", flags);
182
+ }
183
+ return parsed;
184
+ } catch {
185
+ exitWithError("INVALID_JSON", `Invalid JSON in --input-json: ${raw}`, flags);
186
+ }
187
+ }
188
+ function sanitizeInput(str) {
189
+ return str.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, "");
190
+ }
191
+ function validateDateRange(dateStr, flags) {
192
+ const match = dateStr.match(/^(\d{4})-(\d{2})-(\d{2})$/);
193
+ if (!match) {
194
+ exitWithError("INVALID_DATE", `Invalid date: "${dateStr}". Use YYYY-MM-DD format.`, flags);
195
+ }
196
+ const year = parseInt(match[1], 10);
197
+ if (year < 1 || year > 9999) {
198
+ exitWithError("INVALID_DATE", `Year must be between 0001 and 9999, got ${year}.`, flags);
199
+ }
200
+ }
201
+ function capNumber(value, max) {
202
+ if (value > max) return max;
203
+ if (value < 0) return 0;
204
+ return value;
205
+ }
206
+ var MAX_TEXT_LENGTH = 1e3;
207
+ var MAX_RESULTS_CAP = 1e4;
208
+ function exitWithError(code, message, flags) {
209
+ if (isJsonMode(flags)) {
210
+ const out = JSON.stringify({ error: true, code, message });
211
+ process.stdout.write(out + "\n");
212
+ } else {
213
+ process.stderr.write(message + "\n");
214
+ }
215
+ process.exit(1);
216
+ }
217
+ function pickFields(obj, paths) {
218
+ if (typeof obj !== "object" || obj === null) return obj;
219
+ const result = {};
220
+ for (const path of paths) {
221
+ const parts = path.split(".");
222
+ let current = obj;
223
+ for (const part of parts) {
224
+ if (current === null || current === void 0 || typeof current !== "object") {
225
+ current = void 0;
226
+ break;
227
+ }
228
+ current = current[part];
229
+ }
230
+ if (current !== void 0) {
231
+ let target = result;
232
+ for (let i = 0; i < parts.length - 1; i++) {
233
+ if (!(parts[i] in target) || typeof target[parts[i]] !== "object") {
234
+ target[parts[i]] = {};
235
+ }
236
+ target = target[parts[i]];
237
+ }
238
+ target[parts[parts.length - 1]] = current;
239
+ }
240
+ }
241
+ return result;
242
+ }
243
+ function outputJson(data, flags) {
244
+ let output = data;
245
+ const fieldsStr = getFlagString(flags, "fields");
246
+ if (fieldsStr) {
247
+ const paths = fieldsStr.split(",").map((s) => s.trim()).filter(Boolean);
248
+ if (paths.length > 0) {
249
+ output = pickFields(output, paths);
250
+ }
251
+ }
252
+ const indent = getFlagBool(flags, "compact") ? void 0 : 2;
253
+ console.log(JSON.stringify(output, null, indent));
254
+ }
255
+ function parseDate(str, flags) {
256
+ validateDateRange(str, flags);
257
+ const d = /* @__PURE__ */ new Date(str + "T12:00:00Z");
258
+ if (isNaN(d.getTime())) {
259
+ exitWithError("INVALID_DATE", `Invalid date: "${str}". Use YYYY-MM-DD format.`, flags);
260
+ }
261
+ return d;
262
+ }
263
+ function generateHelp() {
264
+ const lines = [];
265
+ lines.push("");
266
+ lines.push("kaabalah - CLI for esoteric calculations");
267
+ lines.push("");
268
+ lines.push("USAGE");
269
+ lines.push(" kaabalah <command> [options]");
270
+ lines.push("");
271
+ lines.push("COMMANDS");
272
+ for (const cmd of COMMANDS) {
273
+ const argsStr = cmd.args.map((a) => a.required ? `<${a.name}>` : `[${a.name}]`).join(" ");
274
+ const line = ` ${cmd.name} ${argsStr}`.padEnd(42) + cmd.description;
275
+ lines.push(line);
276
+ }
277
+ lines.push("");
278
+ lines.push("GLOBAL OPTIONS");
279
+ for (const f of GLOBAL_FLAGS) {
280
+ const def = f.default !== void 0 ? ` (default: ${f.default})` : "";
281
+ const line = ` --${f.name}`.padEnd(30) + f.description + def;
282
+ lines.push(line);
283
+ }
284
+ lines.push("");
285
+ lines.push("EXAMPLES");
286
+ lines.push(' kaabalah gematria "Mat Moura"');
287
+ lines.push(" kaabalah numerology 1990-01-15");
288
+ lines.push(" kaabalah numerology:cycles 1990-01-15 Mateus");
289
+ lines.push(" kaabalah tarot 5 --inverted");
290
+ lines.push(" kaabalah tarot:card 7");
291
+ lines.push(" kaabalah gematria:reverse 22");
292
+ lines.push(" kaabalah ifa 1990-01-15");
293
+ lines.push(" kaabalah astrology 1990-01-15 14:30 --lat=-23.5505 --lon=-46.6333");
294
+ lines.push(' kaabalah astrology 1990-01-15 14:30 --location="S\xE3o Paulo, Brazil"');
295
+ lines.push(" kaabalah help --json");
296
+ lines.push("");
297
+ return lines.join("\n");
298
+ }
299
+ function cmdHelp(args, flags) {
300
+ const subcommand = args[0];
301
+ if (isJsonMode(flags)) {
302
+ if (subcommand) {
303
+ const cmd = COMMANDS.find((c) => c.name === subcommand);
304
+ if (!cmd) {
305
+ exitWithError("UNKNOWN_COMMAND", `Unknown command: "${subcommand}".`, flags);
306
+ }
307
+ outputJson({ version: VERSION, command: cmd, globalFlags: GLOBAL_FLAGS }, flags);
308
+ } else {
309
+ outputJson({ version: VERSION, commands: COMMANDS, globalFlags: GLOBAL_FLAGS }, flags);
310
+ }
311
+ return;
312
+ }
313
+ if (subcommand) {
314
+ const cmd = COMMANDS.find((c) => c.name === subcommand);
315
+ if (!cmd) {
316
+ exitWithError("UNKNOWN_COMMAND", `Unknown command: "${subcommand}".`, flags);
317
+ }
318
+ console.log(`
319
+ ${cmd.name} - ${cmd.description}
320
+ `);
321
+ console.log("USAGE");
322
+ const argsStr = cmd.args.map((a) => a.required ? `<${a.name}>` : `[${a.name}]`).join(" ");
323
+ console.log(` kaabalah ${cmd.name} ${argsStr}
324
+ `);
325
+ if (cmd.args.length > 0) {
326
+ console.log("ARGUMENTS");
327
+ for (const a of cmd.args) {
328
+ const req = a.required ? "(required)" : "(optional)";
329
+ console.log(` ${a.name.padEnd(20)} ${a.type.padEnd(10)} ${req} ${a.description}`);
330
+ }
331
+ console.log();
332
+ }
333
+ if (cmd.flags.length > 0) {
334
+ console.log("FLAGS");
335
+ for (const f of cmd.flags) {
336
+ const def = f.default !== void 0 ? ` (default: ${f.default})` : "";
337
+ console.log(` --${f.name.padEnd(24)} ${f.description}${def}`);
338
+ }
339
+ console.log();
340
+ }
341
+ if (cmd.examples.length > 0) {
342
+ console.log("EXAMPLES");
343
+ for (const e of cmd.examples) {
344
+ console.log(` ${e}`);
345
+ }
346
+ console.log();
347
+ }
348
+ } else {
349
+ console.log(generateHelp());
350
+ }
351
+ }
352
+ async function geocodeLocation(location, flags) {
353
+ const apiKey = process.env.GOOGLE_MAPS_API_KEY;
354
+ if (!apiKey) {
355
+ exitWithError(
356
+ "GEOCODE_ERROR",
357
+ "GOOGLE_MAPS_API_KEY environment variable is required for --location. Set it or use --lat/--lon directly.",
358
+ flags
359
+ );
360
+ }
361
+ const url = "https://places.googleapis.com/v1/places:searchText";
362
+ let response;
363
+ try {
364
+ response = await fetch(url, {
365
+ method: "POST",
366
+ headers: {
367
+ "Content-Type": "application/json",
368
+ "X-Goog-Api-Key": apiKey,
369
+ "X-Goog-FieldMask": "places.displayName,places.formattedAddress,places.location"
370
+ },
371
+ body: JSON.stringify({ textQuery: location, maxResultCount: 1 })
372
+ });
373
+ } catch (err) {
374
+ exitWithError("GEOCODE_ERROR", `Geocoding request failed: ${err instanceof Error ? err.message : String(err)}`, flags);
375
+ }
376
+ const data = await response.json();
377
+ if (data.error) {
378
+ exitWithError(
379
+ "GEOCODE_ERROR",
380
+ `Geocoding failed for "${location}": ${data.error.message}`,
381
+ flags
382
+ );
383
+ }
384
+ if (!data.places || data.places.length === 0 || !data.places[0].location) {
385
+ exitWithError(
386
+ "GEOCODE_ERROR",
387
+ `No results found for "${location}".`,
388
+ flags
389
+ );
390
+ }
391
+ const place = data.places[0];
392
+ return {
393
+ latitude: place.location.latitude,
394
+ longitude: place.location.longitude,
395
+ formattedAddress: place.formattedAddress ?? place.displayName?.text ?? location
396
+ };
397
+ }
398
+ var HOUSE_SYSTEM_MAP = {
399
+ placidus: "P",
400
+ koch: "K",
401
+ porphyrius: "O",
402
+ regiomontanus: "R",
403
+ campanus: "C",
404
+ equal: "E",
405
+ "whole-sign": "W",
406
+ meridian: "X",
407
+ morinus: "M",
408
+ krusinski: "U",
409
+ alcabitius: "B"
410
+ };
411
+ function cmdGematria(text, flags) {
412
+ if (text.length > MAX_TEXT_LENGTH) {
413
+ exitWithError("INVALID_ARGUMENT", `Text exceeds maximum length of ${MAX_TEXT_LENGTH} characters.`, flags);
414
+ }
415
+ const sanitized = sanitizeInput(text);
416
+ const result = calculateGematria(sanitized, {
417
+ missing: getFlagBool(flags, "missing"),
418
+ percentages: getFlagBool(flags, "percentages")
419
+ });
420
+ if (isJsonMode(flags)) {
421
+ outputJson(result, flags);
422
+ return;
423
+ }
424
+ console.log(`
425
+ Gematria: "${sanitized}"
426
+ `);
427
+ console.log(` Vowels: ${result.vowels.originalSum} -> [${result.vowels.reductionSteps.join(", ")}] = ${result.vowels.finalValue}`);
428
+ console.log(` Consonants: ${result.consonants.originalSum} -> [${result.consonants.reductionSteps.join(", ")}] = ${result.consonants.finalValue}`);
429
+ console.log(` Synthesis: ${result.synthesis.originalSum} -> [${result.synthesis.reductionSteps.join(", ")}] = ${result.synthesis.finalValue}`);
430
+ if (result.includedLetters.length > 0) {
431
+ console.log(`
432
+ Letters:`);
433
+ for (const l of result.includedLetters) {
434
+ const vowelTag = l.isVowel ? " (vowel)" : "";
435
+ console.log(` ${l.hebrewCharacter} value=${l.value}${vowelTag}`);
436
+ }
437
+ }
438
+ if (result.missingGematriaValues && result.missingGematriaValues.length > 0) {
439
+ console.log(`
440
+ Missing values: ${result.missingGematriaValues.map((m) => m.value).join(", ")}`);
441
+ }
442
+ if (result.letterPercentages) {
443
+ console.log(`
444
+ Vowel %: ${result.letterPercentages.percentageOfVowels.toFixed(1)}%`);
445
+ console.log(` Consonant %: ${result.letterPercentages.percentageOfConsonants.toFixed(1)}%`);
446
+ }
447
+ console.log();
448
+ }
449
+ function cmdReverseGematria(target, flags, inputPayload) {
450
+ const targetNum = inputPayload?.targetSynthesis != null ? Number(inputPayload.targetSynthesis) : parseInt(target, 10);
451
+ if (isNaN(targetNum)) {
452
+ exitWithError("INVALID_ARGUMENT", `Invalid target number: "${target}"`, flags);
453
+ }
454
+ let maxResults = inputPayload?.maxResults != null ? Number(inputPayload.maxResults) : getFlagNumber(flags, "max-results") ?? 20;
455
+ maxResults = capNumber(maxResults, MAX_RESULTS_CAP);
456
+ let minLength = inputPayload?.minLength != null ? Number(inputPayload.minLength) : getFlagNumber(flags, "min-length") ?? 2;
457
+ let maxLength = inputPayload?.maxLength != null ? Number(inputPayload.maxLength) : getFlagNumber(flags, "max-length") ?? 6;
458
+ const includeDigraphs = inputPayload?.includeDigraphs != null ? Boolean(inputPayload.includeDigraphs) : getFlagBool(flags, "include-digraphs");
459
+ const result = reverseGematria({
460
+ targetSynthesis: targetNum,
461
+ maxResults,
462
+ minLength,
463
+ maxLength,
464
+ includeDigraphs
465
+ });
466
+ if (isJsonMode(flags)) {
467
+ outputJson(result, flags);
468
+ return;
469
+ }
470
+ console.log(`
471
+ Reverse Gematria: target synthesis = ${targetNum}
472
+ `);
473
+ console.log(` Found: ${result.totalFound} combinations${result.hasMore ? ` (showing first ${maxResults})` : ""}
474
+ `);
475
+ for (const r of result.results) {
476
+ console.log(` ${r.letters.padEnd(12)} vowels=${r.vowelsSum} consonants=${r.consonantsSum} synthesis=${r.synthesisSum}`);
477
+ }
478
+ console.log();
479
+ }
480
+ function cmdNumerology(dateStr, flags) {
481
+ const date = parseDate(dateStr, flags);
482
+ const kaabalistic = calculateKaabalisticLifePath(date);
483
+ const straight = calculateStraightAcrossReductionLifePath(date);
484
+ const challenges = calculateChallenges(date);
485
+ const energies = getDateEnergies(date);
486
+ const personalYear = calculatePersonalYear(date);
487
+ const fibonacci = calculateFibonacciCycle(date, /* @__PURE__ */ new Date());
488
+ if (isJsonMode(flags)) {
489
+ outputJson({ kaabalistic, straight, challenges, energies, personalYear, fibonacci }, flags);
490
+ return;
491
+ }
492
+ console.log(`
493
+ Numerology Profile: ${dateStr}
494
+ `);
495
+ console.log(` Kaabalistic Life Path: ${kaabalistic.lifePath.reducedValue}`);
496
+ console.log(` Steps: [${kaabalistic.lifePath.reductionSteps.join(", ")}]`);
497
+ console.log(` Personal Mythology: [${kaabalistic.personalMythologyNumbers.join(", ")}]`);
498
+ console.log(`
499
+ Straight Across Life Path: ${straight.lifePath.reducedValue}`);
500
+ console.log(` Day energy: ${straight.dayEnergy.reducedValue}`);
501
+ console.log(` Month energy: ${straight.monthEnergy.reducedValue}`);
502
+ console.log(` Year energy: ${straight.yearEnergy.reducedValue}`);
503
+ console.log(`
504
+ Challenges:`);
505
+ console.log(` Main: ${challenges.mainChallenge}`);
506
+ console.log(` Sub 1: ${challenges.subChallenge1}`);
507
+ console.log(` Sub 2: ${challenges.subChallenge2}`);
508
+ console.log(`
509
+ Date Energies:`);
510
+ console.log(` Day: ${energies.dayEnergy.reducedValue}`);
511
+ console.log(` Month: ${energies.monthEnergy.reducedValue}`);
512
+ console.log(` Year: ${energies.yearEnergy.reducedValue}`);
513
+ console.log(`
514
+ Personal Year: ${personalYear.reducedValue}`);
515
+ console.log(`
516
+ Fibonacci Cycle (age ${fibonacci.currentAge}):`);
517
+ for (let i = 1; i <= 7; i++) {
518
+ const cycle = fibonacci[`cycle${i}`];
519
+ console.log(` Cycle ${i}: ${cycle.reducedValue}`);
520
+ }
521
+ console.log();
522
+ }
523
+ function cmdLifePath(dateStr, flags) {
524
+ const date = parseDate(dateStr, flags);
525
+ const result = calculateKaabalisticLifePath(date);
526
+ if (isJsonMode(flags)) {
527
+ outputJson(result, flags);
528
+ return;
529
+ }
530
+ console.log(`
531
+ Kaabalistic Life Path: ${dateStr}
532
+ `);
533
+ console.log(` Life Path: ${result.lifePath.reducedValue}`);
534
+ console.log(` Steps: [${result.lifePath.reductionSteps.join(", ")}]`);
535
+ console.log(` Personal Mythology: [${result.personalMythologyNumbers.join(", ")}]`);
536
+ console.log(` Parts: day=${result.reducedParts.reducedDay} month=${result.reducedParts.reducedMonth} year1=${result.reducedParts.reducedYear1} year2=${result.reducedParts.reducedYear2}`);
537
+ console.log();
538
+ }
539
+ function cmdCycles(dateStr, firstName, flags) {
540
+ const date = parseDate(dateStr, flags);
541
+ const today = /* @__PURE__ */ new Date();
542
+ if (firstName) {
543
+ const result = calculatePersonalCycles(date, today, firstName);
544
+ if (isJsonMode(flags)) {
545
+ outputJson(result, flags);
546
+ return;
547
+ }
548
+ console.log(`
549
+ Personal Cycles: ${dateStr} (${firstName})
550
+ `);
551
+ console.log(` Age: ${result.currentAge}`);
552
+ console.log(` Life Path: ${result.lifePath.reducedValue}`);
553
+ console.log(` Soul Number: ${result.soulNumber?.reducedValue}`);
554
+ console.log(` Personal Year: ${result.personalYear.reducedValue}`);
555
+ console.log(` Current Period: ${result.currentPersonalPeriod + 1}/3`);
556
+ console.log(` Current Month: ${result.currentPersonalMonth + 1}/12`);
557
+ console.log(`
558
+ Periods:`);
559
+ for (let i = 0; i < result.personalPeriods.length; i++) {
560
+ const p = result.personalPeriods[i];
561
+ const active = i === result.currentPersonalPeriod ? " <--" : "";
562
+ console.log(` Period ${i + 1} (months ${p.startMonth}-${p.endMonth}): ${p.value.reducedValue}${active}`);
563
+ }
564
+ console.log(`
565
+ Monthly energies:`);
566
+ for (let i = 0; i < result.personalMonths.length; i++) {
567
+ const m = result.personalMonths[i];
568
+ const active = i === result.currentPersonalMonth ? " <--" : "";
569
+ console.log(` Month ${m.month}: ${m.value.reducedValue}${active}`);
570
+ }
571
+ } else {
572
+ const result = calculateCycles(date, today);
573
+ if (isJsonMode(flags)) {
574
+ outputJson(result, flags);
575
+ return;
576
+ }
577
+ console.log(`
578
+ Heptad Cycles: ${dateStr}
579
+ `);
580
+ console.log(` Total days since last birthday: ${result.totalDays}`);
581
+ if (result.currentAgeCycle) {
582
+ console.log(`
583
+ Age Cycles (current: ${result.currentAgeCycle}):`);
584
+ for (const c of result.ageCycles) {
585
+ const active = c.isActive ? " <--" : "";
586
+ console.log(` Cycle ${c.number}: ${c.description}${active}`);
587
+ }
588
+ }
589
+ if (result.currentYearlyCycle) {
590
+ console.log(`
591
+ Yearly Cycles (current: ${result.currentYearlyCycle}):`);
592
+ for (const c of result.yearlyCycles) {
593
+ const active = c.isActive ? " <--" : "";
594
+ console.log(` Cycle ${c.number}: ${c.description}${active}`);
595
+ }
596
+ }
597
+ console.log(`
598
+ Monthly Cycles (current: ${result.currentMonthlyCycle}, day ${result.daysInMonthlyCycle}):`);
599
+ for (const c of result.monthlyCycles) {
600
+ const active = c.isActive ? " <--" : "";
601
+ console.log(` Cycle ${c.number}: ${c.description}${active}`);
602
+ }
603
+ }
604
+ console.log();
605
+ }
606
+ function cmdChallenges(dateStr, flags) {
607
+ const date = parseDate(dateStr, flags);
608
+ const result = calculateChallenges(date);
609
+ if (isJsonMode(flags)) {
610
+ outputJson(result, flags);
611
+ return;
612
+ }
613
+ console.log(`
614
+ Challenges: ${dateStr}
615
+ `);
616
+ console.log(` Day: ${result.day}`);
617
+ console.log(` Month: ${result.month}`);
618
+ console.log(` Year: ${result.year}`);
619
+ console.log(` Main: ${result.mainChallenge}`);
620
+ console.log(` Sub 1: ${result.subChallenge1}`);
621
+ console.log(` Sub 2: ${result.subChallenge2}`);
622
+ console.log();
623
+ }
624
+ function cmdFibonacci(dateStr, flags) {
625
+ const date = parseDate(dateStr, flags);
626
+ const result = calculateFibonacciCycle(date, /* @__PURE__ */ new Date());
627
+ if (isJsonMode(flags)) {
628
+ outputJson(result, flags);
629
+ return;
630
+ }
631
+ console.log(`
632
+ Fibonacci Cycle: ${dateStr} (age ${result.currentAge})
633
+ `);
634
+ for (let i = 1; i <= 7; i++) {
635
+ const cycle = result[`cycle${i}`];
636
+ console.log(` Cycle ${i}: ${cycle.reducedValue} [${cycle.reductionSteps.join(", ")}]`);
637
+ }
638
+ console.log();
639
+ }
640
+ async function cmdTarot(countStr, flags) {
641
+ const count = countStr ? parseInt(countStr, 10) : 3;
642
+ if (isNaN(count) || count < 1 || count > 78) {
643
+ exitWithError("INVALID_ARGUMENT", "Card count must be between 1 and 78.", flags);
644
+ }
645
+ const shuffleCount = getFlagNumber(flags, "shuffle-count") ?? 7;
646
+ const deck = await shuffleTarotDeck(ARKANNUS, getFlagBool(flags, "inverted"), shuffleCount);
647
+ const drawn = deck.slice(0, count);
648
+ if (isJsonMode(flags)) {
649
+ outputJson(drawn, flags);
650
+ return;
651
+ }
652
+ console.log(`
653
+ Tarot Draw: ${count} card${count > 1 ? "s" : ""}
654
+ `);
655
+ for (const card of drawn) {
656
+ const inverted = card.isInverted ? " (INVERTED)" : "";
657
+ console.log(` #${String(card.number).padStart(2, "0")} ${card.tarotCard}${inverted}`);
658
+ console.log(` ${card.meaning}`);
659
+ if (card.egyptianCardName) {
660
+ console.log(` Egyptian: ${card.egyptianCardName}`);
661
+ }
662
+ if (card.papusMeaning) {
663
+ console.log(` Papus: ${card.papusMeaning}`);
664
+ }
665
+ console.log();
666
+ }
667
+ }
668
+ function cmdTarotCard(numberStr, flags) {
669
+ const num = parseInt(numberStr, 10);
670
+ const card = ARKANNUS.find((c) => c.number === num);
671
+ if (!card) {
672
+ exitWithError("CARD_NOT_FOUND", `Card #${num} not found. Valid range: 1-78.`, flags);
673
+ }
674
+ if (isJsonMode(flags)) {
675
+ outputJson(card, flags);
676
+ return;
677
+ }
678
+ console.log(`
679
+ #${String(card.number).padStart(2, "0")} ${card.tarotCard}`);
680
+ console.log(` Type: ${card.type} | Suit: ${card.suit ?? "major"} | Deck: ${card.deck}`);
681
+ console.log(` Meaning: ${card.meaning}`);
682
+ if (card.egyptianCardName) console.log(` Egyptian: ${card.egyptianCardName}`);
683
+ if (card.papusMeaning) console.log(` Papus: ${card.papusMeaning}`);
684
+ console.log();
685
+ }
686
+ function cmdIfa(dateStr, flags) {
687
+ const date = parseDate(dateStr, flags);
688
+ const result = calculateOdu(date);
689
+ if (isJsonMode(flags)) {
690
+ outputJson(result, flags);
691
+ return;
692
+ }
693
+ console.log(`
694
+ Odu: ${dateStr}
695
+ `);
696
+ console.log(` Left: [${result.leftNumbers.join(", ")}]`);
697
+ console.log(` Right: [${result.rightNumbers.join(", ")}]`);
698
+ console.log(` North: ${result.north}`);
699
+ console.log(` South: ${result.south}`);
700
+ console.log(` East: ${result.east}`);
701
+ console.log(` West: ${result.west}`);
702
+ console.log(` Center: ${result.center}`);
703
+ console.log();
704
+ }
705
+ function cmdTree(flags) {
706
+ const tree = createTree({ system: SYSTEM, parts: ["westernAstrology", "tarot"] });
707
+ const allNodes = tree.getNodes();
708
+ if (isJsonMode(flags)) {
709
+ outputJson(allNodes.map((n) => ({ id: n.id, type: n.type, name: n.data && "name" in n.data ? n.data?.name : void 0 })), flags);
710
+ return;
711
+ }
712
+ console.log(`
713
+ Tree of Life (${SYSTEM})
714
+ `);
715
+ console.log(` Total nodes: ${allNodes.length}`);
716
+ const byType = /* @__PURE__ */ new Map();
717
+ for (const node of allNodes) {
718
+ const t = node.type;
719
+ if (!byType.has(t)) byType.set(t, []);
720
+ byType.get(t).push(node);
721
+ }
722
+ for (const [type, nodes] of byType) {
723
+ console.log(`
724
+ ${type} (${nodes.length}):`);
725
+ for (const n of nodes.slice(0, 15)) {
726
+ const d = n.data;
727
+ const name = d?.name ?? d?.character ?? "";
728
+ console.log(` ${n.id}${name ? ` \u2014 ${name}` : ""}`);
729
+ }
730
+ if (nodes.length > 15) {
731
+ console.log(` ... and ${nodes.length - 15} more`);
732
+ }
733
+ }
734
+ console.log();
735
+ }
736
+ async function cmdAstrology(args, flags, inputPayload) {
737
+ const dateStr = inputPayload?.date ?? args[0];
738
+ if (!dateStr) {
739
+ exitWithError("MISSING_ARGUMENT", "Usage: kaabalah astrology <YYYY-MM-DD> [HH:MM] --lat=<N> --lon=<N>", flags);
740
+ }
741
+ parseDate(dateStr, flags);
742
+ const timeStr = inputPayload?.time ?? args[1] ?? "12:00";
743
+ const timeMatch = timeStr.match(/^(\d{1,2}):(\d{2})$/);
744
+ if (!timeMatch) {
745
+ exitWithError("INVALID_ARGUMENT", `Invalid time format: "${timeStr}". Use HH:MM format.`, flags);
746
+ }
747
+ const hour = parseInt(timeMatch[1], 10);
748
+ const minute = parseInt(timeMatch[2], 10);
749
+ if (hour < 0 || hour > 23 || minute < 0 || minute > 59) {
750
+ exitWithError("INVALID_ARGUMENT", `Invalid time: "${timeStr}". Hours 0-23, minutes 0-59.`, flags);
751
+ }
752
+ let latitude;
753
+ let longitude;
754
+ let resolvedLocation;
755
+ const locationStr = inputPayload?.location ?? getFlagString(flags, "location");
756
+ const latFlag = inputPayload?.lat != null ? Number(inputPayload.lat) : getFlagNumber(flags, "lat");
757
+ const lonFlag = inputPayload?.lon != null ? Number(inputPayload.lon) : getFlagNumber(flags, "lon");
758
+ if (latFlag != null && lonFlag != null) {
759
+ latitude = latFlag;
760
+ longitude = lonFlag;
761
+ } else if (locationStr) {
762
+ const geo = await geocodeLocation(locationStr, flags);
763
+ latitude = geo.latitude;
764
+ longitude = geo.longitude;
765
+ resolvedLocation = geo.formattedAddress;
766
+ } else {
767
+ exitWithError(
768
+ "MISSING_ARGUMENT",
769
+ 'Location is required. Use --lat=<N> --lon=<N> or --location="City, Country" (requires GOOGLE_MAPS_API_KEY).',
770
+ flags
771
+ );
772
+ }
773
+ if (latitude < -90 || latitude > 90) {
774
+ exitWithError("INVALID_ARGUMENT", `Latitude must be between -90 and 90, got ${latitude}.`, flags);
775
+ }
776
+ if (longitude < -180 || longitude > 180) {
777
+ exitWithError("INVALID_ARGUMENT", `Longitude must be between -180 and 180, got ${longitude}.`, flags);
778
+ }
779
+ const houseSystemStr = inputPayload?.houseSystem ?? getFlagString(flags, "house-system") ?? "placidus";
780
+ const houseSystemCode = HOUSE_SYSTEM_MAP[houseSystemStr.toLowerCase()];
781
+ if (!houseSystemCode) {
782
+ exitWithError(
783
+ "INVALID_ARGUMENT",
784
+ `Unknown house system: "${houseSystemStr}". Valid: ${Object.keys(HOUSE_SYSTEM_MAP).join(", ")}`,
785
+ flags
786
+ );
787
+ }
788
+ const timezoneStr = inputPayload?.timezone ?? getFlagString(flags, "timezone");
789
+ const dateParts = dateStr.match(/^(\d{4})-(\d{2})-(\d{2})$/);
790
+ const birthDate = new Date(
791
+ parseInt(dateParts[1], 10),
792
+ parseInt(dateParts[2], 10) - 1,
793
+ parseInt(dateParts[3], 10),
794
+ hour,
795
+ minute,
796
+ 0
797
+ );
798
+ const path = __require("path");
799
+ const { getSwissEph, closeSwissEph, getBirthChart, HouseSystem } = await import('./astrology/index.mjs');
800
+ const wasmPath = path.resolve(__dirname, "../wasm/build/swisseph.node.wasm");
801
+ const ephePath = path.resolve(__dirname, "../ephe");
802
+ try {
803
+ await getSwissEph({ wasmPath, ephePath });
804
+ } catch (err) {
805
+ exitWithError("WASM_INIT_ERROR", `Failed to initialize Swiss Ephemeris: ${err instanceof Error ? err.message : String(err)}`, flags);
806
+ }
807
+ try {
808
+ const timeZoneSettings = {};
809
+ if (timezoneStr) {
810
+ timeZoneSettings.timeZone = timezoneStr;
811
+ } else {
812
+ timeZoneSettings.autoTimeZone = true;
813
+ }
814
+ const chart = await getBirthChart({
815
+ date: birthDate,
816
+ latitude,
817
+ longitude,
818
+ houseSystem: houseSystemCode,
819
+ timeZoneSettings
820
+ });
821
+ if (isJsonMode(flags)) {
822
+ const result = { ...chart };
823
+ if (resolvedLocation) {
824
+ result.resolvedLocation = resolvedLocation;
825
+ }
826
+ result.input = {
827
+ date: dateStr,
828
+ time: timeStr,
829
+ latitude,
830
+ longitude,
831
+ houseSystem: houseSystemStr,
832
+ timezone: timezoneStr ?? "auto"
833
+ };
834
+ outputJson(result, flags);
835
+ } else {
836
+ console.log(`
837
+ Birth Chart: ${dateStr} ${timeStr}
838
+ `);
839
+ if (resolvedLocation) {
840
+ console.log(` Location: ${resolvedLocation}`);
841
+ }
842
+ console.log(` Coordinates: ${latitude.toFixed(4)}, ${longitude.toFixed(4)}`);
843
+ console.log(` House System: ${houseSystemStr}`);
844
+ console.log(` UTC Date: ${chart.dateUtc.toISOString()}`);
845
+ console.log(`
846
+ Planets:`);
847
+ for (const [name, planet] of Object.entries(chart.planets)) {
848
+ const zp = planet.zodiacPosition;
849
+ console.log(` ${name.padEnd(14)} ${zp.sign.padEnd(12)} ${zp.traditionalFormat.padEnd(8)} House ${zp.house}`);
850
+ }
851
+ console.log(`
852
+ Houses:`);
853
+ console.log(` Ascendant: ${chart.houses.ascendant.sign} ${chart.houses.ascendant.traditionalFormat}`);
854
+ console.log(` Midheaven: ${chart.houses.mc.sign} ${chart.houses.mc.traditionalFormat}`);
855
+ console.log(` Descendant: ${chart.houses.dc.sign} ${chart.houses.dc.traditionalFormat}`);
856
+ console.log(` IC: ${chart.houses.ic.sign} ${chart.houses.ic.traditionalFormat}`);
857
+ console.log(`
858
+ House Cusps:`);
859
+ for (let i = 0; i < chart.houses.houses.length; i++) {
860
+ const h = chart.houses.houses[i];
861
+ console.log(` House ${String(i + 1).padStart(2)}: ${h.sign.padEnd(12)} ${h.traditionalFormat}`);
862
+ }
863
+ if (chart.nodes && Object.keys(chart.nodes).length > 0) {
864
+ console.log(`
865
+ Nodes:`);
866
+ for (const [, node] of Object.entries(chart.nodes)) {
867
+ console.log(` ${node.name.padEnd(18)} ${node.sign.padEnd(12)} ${node.traditionalFormat.padEnd(8)} House ${node.house}`);
868
+ }
869
+ }
870
+ console.log();
871
+ }
872
+ } finally {
873
+ closeSwissEph();
874
+ }
875
+ }
876
+ async function main() {
877
+ const { args, flags } = parseArgs(process.argv);
878
+ if (getFlagBool(flags, "version")) {
879
+ if (isJsonMode(flags)) {
880
+ outputJson({ version: VERSION }, flags);
881
+ } else {
882
+ console.log(`kaabalah v${VERSION}`);
883
+ }
884
+ process.exit(0);
885
+ }
886
+ if (args.length === 0) {
887
+ cmdHelp([], flags);
888
+ process.exit(0);
889
+ }
890
+ const command = args[0];
891
+ if (getFlagBool(flags, "help") && command !== "help") {
892
+ cmdHelp([command], flags);
893
+ process.exit(0);
894
+ }
895
+ const inputPayload = parseInputJson(flags);
896
+ switch (command) {
897
+ case "help":
898
+ cmdHelp(args.slice(1), flags);
899
+ break;
900
+ case "gematria":
901
+ if (!args[1] && !inputPayload?.text) {
902
+ exitWithError("MISSING_ARGUMENT", "Usage: kaabalah gematria <text>", flags);
903
+ }
904
+ cmdGematria(inputPayload?.text ?? args.slice(1).join(" "), flags);
905
+ break;
906
+ case "gematria:reverse":
907
+ if (!args[1] && inputPayload?.targetSynthesis == null) {
908
+ exitWithError("MISSING_ARGUMENT", "Usage: kaabalah gematria:reverse <target-number>", flags);
909
+ }
910
+ cmdReverseGematria(args[1] ?? String(inputPayload?.targetSynthesis ?? ""), flags, inputPayload);
911
+ break;
912
+ case "numerology":
913
+ if (!args[1] && !inputPayload?.date) {
914
+ exitWithError("MISSING_ARGUMENT", "Usage: kaabalah numerology <YYYY-MM-DD>", flags);
915
+ }
916
+ cmdNumerology(inputPayload?.date ?? args[1], flags);
917
+ break;
918
+ case "numerology:lifepath":
919
+ if (!args[1] && !inputPayload?.date) {
920
+ exitWithError("MISSING_ARGUMENT", "Usage: kaabalah numerology:lifepath <YYYY-MM-DD>", flags);
921
+ }
922
+ cmdLifePath(inputPayload?.date ?? args[1], flags);
923
+ break;
924
+ case "numerology:cycles":
925
+ if (!args[1] && !inputPayload?.date) {
926
+ exitWithError("MISSING_ARGUMENT", "Usage: kaabalah numerology:cycles <YYYY-MM-DD> [firstName]", flags);
927
+ }
928
+ cmdCycles(
929
+ inputPayload?.date ?? args[1],
930
+ inputPayload?.firstName ?? args[2],
931
+ flags
932
+ );
933
+ break;
934
+ case "numerology:challenges":
935
+ if (!args[1] && !inputPayload?.date) {
936
+ exitWithError("MISSING_ARGUMENT", "Usage: kaabalah numerology:challenges <YYYY-MM-DD>", flags);
937
+ }
938
+ cmdChallenges(inputPayload?.date ?? args[1], flags);
939
+ break;
940
+ case "numerology:fibonacci":
941
+ if (!args[1] && !inputPayload?.date) {
942
+ exitWithError("MISSING_ARGUMENT", "Usage: kaabalah numerology:fibonacci <YYYY-MM-DD>", flags);
943
+ }
944
+ cmdFibonacci(inputPayload?.date ?? args[1], flags);
945
+ break;
946
+ case "tarot":
947
+ await cmdTarot(inputPayload?.count ?? args[1], flags);
948
+ break;
949
+ case "tarot:card":
950
+ if (!args[1] && inputPayload?.number == null) {
951
+ exitWithError("MISSING_ARGUMENT", "Usage: kaabalah tarot:card <number>", flags);
952
+ }
953
+ cmdTarotCard((inputPayload?.number != null ? String(inputPayload.number) : void 0) ?? args[1], flags);
954
+ break;
955
+ case "ifa":
956
+ if (!args[1] && !inputPayload?.date) {
957
+ exitWithError("MISSING_ARGUMENT", "Usage: kaabalah ifa <YYYY-MM-DD>", flags);
958
+ }
959
+ cmdIfa(inputPayload?.date ?? args[1], flags);
960
+ break;
961
+ case "tree":
962
+ cmdTree(flags);
963
+ break;
964
+ case "astrology":
965
+ await cmdAstrology(args.slice(1), flags, inputPayload);
966
+ break;
967
+ case "--version":
968
+ if (isJsonMode(flags)) {
969
+ outputJson({ version: VERSION }, flags);
970
+ } else {
971
+ console.log(`kaabalah v${VERSION}`);
972
+ }
973
+ break;
974
+ default:
975
+ exitWithError("UNKNOWN_COMMAND", `Unknown command: "${command}". Run "kaabalah help" for usage.`, flags);
976
+ }
977
+ }
978
+ main().catch((err) => {
979
+ const hasJson = process.argv.some((a) => a === "--json") || !process.stdout.isTTY;
980
+ if (hasJson) {
981
+ const out = JSON.stringify({
982
+ error: true,
983
+ code: "INTERNAL_ERROR",
984
+ message: err instanceof Error ? err.message : String(err)
985
+ });
986
+ process.stdout.write(out + "\n");
987
+ } else {
988
+ console.error(err instanceof Error ? err.message : err);
989
+ }
990
+ process.exit(1);
991
+ });
992
+ //# sourceMappingURL=cli.mjs.map
993
+ //# sourceMappingURL=cli.mjs.map