@cyanheads/astronomy-mcp-server 0.5.0 → 0.5.2

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.
Files changed (58) hide show
  1. package/AGENTS.md +16 -14
  2. package/CLAUDE.md +16 -14
  3. package/README.md +19 -13
  4. package/changelog/0.5.x/0.5.1.md +35 -0
  5. package/changelog/0.5.x/0.5.2.md +30 -0
  6. package/changelog/template.md +20 -11
  7. package/dist/mcp-server/prompts/definitions/stargazing-plan.prompt.d.ts +4 -2
  8. package/dist/mcp-server/prompts/definitions/stargazing-plan.prompt.d.ts.map +1 -1
  9. package/dist/mcp-server/prompts/definitions/stargazing-plan.prompt.js +8 -5
  10. package/dist/mcp-server/prompts/definitions/stargazing-plan.prompt.js.map +1 -1
  11. package/dist/mcp-server/tools/definitions/find-events.tool.d.ts +43 -9
  12. package/dist/mcp-server/tools/definitions/find-events.tool.d.ts.map +1 -1
  13. package/dist/mcp-server/tools/definitions/find-events.tool.js +134 -23
  14. package/dist/mcp-server/tools/definitions/find-events.tool.js.map +1 -1
  15. package/dist/mcp-server/tools/definitions/get-ephemeris.tool.d.ts +19 -0
  16. package/dist/mcp-server/tools/definitions/get-ephemeris.tool.d.ts.map +1 -1
  17. package/dist/mcp-server/tools/definitions/get-ephemeris.tool.js +73 -37
  18. package/dist/mcp-server/tools/definitions/get-ephemeris.tool.js.map +1 -1
  19. package/dist/mcp-server/tools/definitions/get-rise-set.tool.d.ts +27 -8
  20. package/dist/mcp-server/tools/definitions/get-rise-set.tool.d.ts.map +1 -1
  21. package/dist/mcp-server/tools/definitions/get-rise-set.tool.js +67 -14
  22. package/dist/mcp-server/tools/definitions/get-rise-set.tool.js.map +1 -1
  23. package/dist/mcp-server/tools/definitions/get-sky-position.tool.d.ts.map +1 -1
  24. package/dist/mcp-server/tools/definitions/get-sky-position.tool.js +3 -1
  25. package/dist/mcp-server/tools/definitions/get-sky-position.tool.js.map +1 -1
  26. package/dist/mcp-server/tools/definitions/list-visible.tool.d.ts +2 -4
  27. package/dist/mcp-server/tools/definitions/list-visible.tool.d.ts.map +1 -1
  28. package/dist/mcp-server/tools/definitions/list-visible.tool.js +15 -14
  29. package/dist/mcp-server/tools/definitions/list-visible.tool.js.map +1 -1
  30. package/dist/services/ephemeris/ephemeris-service.d.ts +34 -18
  31. package/dist/services/ephemeris/ephemeris-service.d.ts.map +1 -1
  32. package/dist/services/ephemeris/ephemeris-service.js +221 -126
  33. package/dist/services/ephemeris/ephemeris-service.js.map +1 -1
  34. package/dist/services/ephemeris/meteor-showers.d.ts +49 -0
  35. package/dist/services/ephemeris/meteor-showers.d.ts.map +1 -0
  36. package/dist/services/ephemeris/meteor-showers.js +122 -0
  37. package/dist/services/ephemeris/meteor-showers.js.map +1 -0
  38. package/dist/services/ephemeris/rise-set-horizon.d.ts +11 -0
  39. package/dist/services/ephemeris/rise-set-horizon.d.ts.map +1 -0
  40. package/dist/services/ephemeris/rise-set-horizon.js +116 -0
  41. package/dist/services/ephemeris/rise-set-horizon.js.map +1 -0
  42. package/dist/services/ephemeris/star-catalog.d.ts +6 -8
  43. package/dist/services/ephemeris/star-catalog.d.ts.map +1 -1
  44. package/dist/services/ephemeris/star-catalog.js +7 -4
  45. package/dist/services/ephemeris/star-catalog.js.map +1 -1
  46. package/dist/services/ephemeris/types.d.ts +50 -4
  47. package/dist/services/ephemeris/types.d.ts.map +1 -1
  48. package/dist/services/ephemeris/types.js +2 -1
  49. package/dist/services/ephemeris/types.js.map +1 -1
  50. package/dist/services/horizons/horizons-service.d.ts +10 -5
  51. package/dist/services/horizons/horizons-service.d.ts.map +1 -1
  52. package/dist/services/horizons/horizons-service.js +46 -15
  53. package/dist/services/horizons/horizons-service.js.map +1 -1
  54. package/dist/services/horizons/types.d.ts +16 -3
  55. package/dist/services/horizons/types.d.ts.map +1 -1
  56. package/package.json +10 -9
  57. package/server.json +3 -3
  58. package/skills/astronomy-guide/SKILL.md +16 -8
@@ -9,10 +9,12 @@
9
9
  * @module services/ephemeris/ephemeris-service
10
10
  */
11
11
  import { invalidParams, notFound } from '@cyanheads/mcp-ts-core/errors';
12
- import { AngleBetween, AngleFromSun, ApsisKind, Atmosphere, Body, Constellation, DefineStar, Ecliptic, Equator, GeoVector, Horizon, Illumination, MakeTime, MoonPhase, NextGlobalSolarEclipse, NextLocalSolarEclipse, NextLunarApsis, NextLunarEclipse, NextMoonQuarter, NextPlanetApsis, Observer, PairLongitude, Search, SearchAltitude, SearchGlobalSolarEclipse, SearchHourAngle, SearchLocalSolarEclipse, SearchLunarApsis, SearchLunarEclipse, SearchMaxElongation, SearchMoonPhase, SearchMoonQuarter, SearchPlanetApsis, SearchRelativeLongitude, SearchRiseSet, Seasons, } from 'astronomy-engine';
12
+ import { AngleBetween, AngleFromSun, ApsisKind, Body, Constellation, DefineStar, Ecliptic, Equator, EquatorFromVector, GeoVector, HelioVector, Horizon, Illumination, MakeTime, MoonPhase, NextGlobalSolarEclipse, NextLocalSolarEclipse, NextLunarApsis, NextLunarEclipse, NextMoonQuarter, NextPlanetApsis, Observer, PairLongitude, RotateVector, Rotation_EQJ_ECL, Rotation_EQJ_EQD, Search, SearchAltitude, SearchGlobalSolarEclipse, SearchHourAngle, SearchLocalSolarEclipse, SearchLunarApsis, SearchLunarEclipse, SearchMaxElongation, SearchMoonPhase, SearchMoonQuarter, SearchPlanetApsis, SearchRelativeLongitude, Seasons, Spherical, VectorFromSphere, } from 'astronomy-engine';
13
13
  import { BODY_META } from './body-data.js';
14
14
  import { parseIsoInstant } from './iso-time.js';
15
- import { CONSTELLATION_GENITIVES, GREEK_LETTER_NAMES, STAR_CATALOG } from './star-catalog.js';
15
+ import { findShower, METEOR_SHOWERS } from './meteor-showers.js';
16
+ import { riseSetHorizon } from './rise-set-horizon.js';
17
+ import { CONSTELLATION_GENITIVES, GREEK_LETTERS, STAR_CATALOG } from './star-catalog.js';
16
18
  /**
17
19
  * astronomy-engine's high-accuracy span, as inclusive UTC calendar years. `resolveTime()`
18
20
  * rejects an instant outside it, and every event search stops at its end.
@@ -323,24 +325,31 @@ export class EphemerisService {
323
325
  return pos;
324
326
  }
325
327
  // ---- Rise / set / transit + twilight ------------------------------------
326
- /** Rise/set/transit cycles for a body, searching forward from `start` — the cycles alone. */
327
- riseSet(body, observer, start, count, timezone) {
328
- return this.riseSetSearch(body, observer, start, count, timezone).events;
328
+ /** Rise/set/transit cycles for a body or catalog star from `start` — the cycles alone. */
329
+ riseSet(target, observer, start, count, timezone) {
330
+ return this.riseSetSearch(target, observer, start, count, timezone).events;
329
331
  }
330
332
  /**
331
- * Rise/set/transit cycles for a body, searching forward from `start`, plus where the search
332
- * stopped and — for the Sun when `start` falls at night — the night already under way.
333
+ * Rise/set/transit cycles for a body or catalog star, searching forward from `start`, plus
334
+ * where the search stopped and — for the Sun when `start` falls at night — the night already
335
+ * under way.
333
336
  *
334
337
  * A cycle is one of the body's days: a culmination with the rise before it and the set after
335
338
  * it. A day with neither — the Sun's polar night or midnight sun, a day the Moon spends wholly
336
339
  * below or above the horizon — is a cycle of its own, never folded into a neighbour, so
337
340
  * consecutive cycles cover consecutive days. A Sun cycle also carries the night after its day,
338
341
  * which ends where the next cycle's day begins, so each night falls in exactly one cycle.
342
+ *
343
+ * A star runs the same loop on its DefineStar slot, a point at the horizon like a planet. The
344
+ * eight slots are module state that any later definition overwrites, so resolve the star with
345
+ * `resolveStarTarget()` in the same synchronous call that searches it, never ahead of it.
339
346
  */
340
- riseSetSearch(body, observer, start, count, timezone) {
347
+ riseSetSearch(target, observer, start, count, timezone) {
341
348
  const obs = this.toObserver(observer);
342
- const target = BODY_ENUM[body];
343
- const isSun = body === 'sun';
349
+ const engineBody = target.kind === 'body' ? BODY_ENUM[target.body] : target.star.slot;
350
+ const heightAboveHorizon = observer.heightAboveHorizon ?? 0;
351
+ const horizon = riseSetHorizon(engineBody, obs, heightAboveHorizon);
352
+ const isSun = target.kind === 'body' && target.body === 'sun';
344
353
  /**
345
354
  * The next rise from a cursor, searched once per cursor: a Sun cycle that closes with a set
346
355
  * looks ahead for the following sunrise to place its resume point, and the cycle resumed
@@ -350,15 +359,13 @@ export class EphemerisService {
350
359
  const riseFrom = (cursor) => {
351
360
  const key = cursor.getTime();
352
361
  if (!rises.has(key)) {
353
- rises.set(key, this.horizonCrossing(target, obs, +1, cursor, RISE_SET_WINDOW_DAYS));
362
+ rises.set(key, horizon.crossing(+1, cursor, RISE_SET_WINDOW_DAYS));
354
363
  }
355
364
  return rises.get(key) ?? null;
356
365
  };
357
- const cycleAt = (cursor, crossings = this.crossingsFrom(target, obs, cursor, riseFrom)) => this.dayCycle(target, obs, cursor, crossings, isSun, riseFrom);
358
- const opening = this.crossingsFrom(target, obs, start, riseFrom);
359
- const sunsetBefore = isSun && !opening.alreadyUp
360
- ? this.horizonCrossing(Body.Sun, obs, -1, start, -RISE_SET_WINDOW_DAYS)
361
- : null;
366
+ const cycleAt = (cursor, crossings = this.crossingsFrom(engineBody, obs, cursor, riseFrom, horizon)) => this.dayCycle(engineBody, obs, cursor, crossings, isSun, riseFrom);
367
+ const opening = this.crossingsFrom(engineBody, obs, start, riseFrom, horizon);
368
+ const sunsetBefore = isSun && !opening.alreadyUp ? horizon.crossing(-1, start, -RISE_SET_WINDOW_DAYS) : null;
362
369
  let cycle = (isSun ? this.restOfDarkDay(obs, start, opening, sunsetBefore) : undefined) ??
363
370
  cycleAt(start, opening);
364
371
  const opener = cycle;
@@ -391,8 +398,11 @@ export class EphemerisService {
391
398
  if (c.note)
392
399
  event.note = c.note;
393
400
  const nightEnd = nightEnds[i];
394
- if (nightEnd)
395
- event.twilight = this.twilight(obs, c.nightFrom, nightEnd, timezone);
401
+ if (nightEnd) {
402
+ // At a dipped horizon, geometric twilight can begin before the Sun has set.
403
+ const nightStart = heightAboveHorizon > 0 && c.set ? c.set.date : c.nightFrom;
404
+ event.twilight = this.twilight(obs, nightStart, nightEnd, timezone);
405
+ }
396
406
  if (timezone) {
397
407
  if (c.rise)
398
408
  event.riseLocal = this.formatLocal(c.rise.date, timezone);
@@ -403,7 +413,11 @@ export class EphemerisService {
403
413
  }
404
414
  return event;
405
415
  });
406
- const search = { events, resumeAt };
416
+ const search = {
417
+ body: target.kind === 'body' ? target.body : target.star.meta.name,
418
+ events,
419
+ resumeAt,
420
+ };
407
421
  /**
408
422
  * The opener owns the night after its day. If that day begins after `start`, the preceding
409
423
  * night has no cycle in this result and is reported separately. A sunset after the previous
@@ -411,7 +425,7 @@ export class EphemerisService {
411
425
  * An opener beginning before `start` already owns the night, including a rest-of-dark-day
412
426
  * opener, so it must not also appear here.
413
427
  */
414
- if (isSun && this.horizonResidual(Body.Sun, obs, start) < 0 && opener.nightFrom > start) {
428
+ if (isSun && horizon.residual(start) < 0 && opener.nightFrom > start) {
415
429
  const noonBefore = SearchHourAngle(Body.Sun, obs, 0, start, -1).time.date;
416
430
  const anchor = sunsetBefore && sunsetBefore.date > noonBefore ? sunsetBefore.date : noonBefore;
417
431
  search.nightInProgress = this.twilight(obs, anchor, opener.nightFrom, timezone);
@@ -419,9 +433,10 @@ export class EphemerisService {
419
433
  return search;
420
434
  }
421
435
  /** The next rise, set, and culmination searched forward from one cursor. */
422
- crossingsFrom(target, obs, cursor, riseFrom) {
436
+ crossingsFrom(target, obs, cursor, riseFrom, horizon) {
423
437
  const rise = riseFrom(cursor);
424
- const set = this.horizonCrossing(target, obs, -1, cursor, RISE_SET_WINDOW_DAYS);
438
+ const set = horizon.crossing(-1, cursor, RISE_SET_WINDOW_DAYS);
439
+ const culmination = SearchHourAngle(target, obs, 0, cursor, +1);
425
440
  return {
426
441
  rise,
427
442
  set,
@@ -435,83 +450,9 @@ export class EphemerisService {
435
450
  * drop tonight's set, which is the event a caller asking during the day most needs.
436
451
  */
437
452
  alreadyUp: set !== null && (rise === null || set.date < rise.date),
438
- culmination: SearchHourAngle(target, obs, 0, cursor, +1),
439
- };
440
- }
441
- /**
442
- * Certify the engine's upper-limb crossing before it participates in a cycle. A shallow
443
- * quadratic estimate can have the wrong direction; retain ordinary estimates unchanged,
444
- * and recover an invalid estimate with directed bisection in the original search window.
445
- */
446
- horizonCrossing(target, obs, direction, start, limitDays) {
447
- const candidate = SearchRiseSet(target, obs, direction, start, limitDays);
448
- if (!candidate)
449
- return null;
450
- const residual = (ms) => direction * this.horizonResidual(target, obs, new Date(ms));
451
- const estimate = candidate.date.getTime();
452
- const end = start.getTime() + limitDays * 86_400_000;
453
- const low = Math.min(start.getTime(), end);
454
- const high = Math.max(start.getTime(), end);
455
- if (estimate >= low &&
456
- estimate <= high &&
457
- residual(estimate - 100) < 0 &&
458
- residual(estimate + 100) >= 0)
459
- return candidate;
460
- /**
461
- * Envelope of the engine's body-specific altitude slope bounds, in degrees/ms.
462
- * It bounds the round trip from either same-sign endpoint to a hidden short interval.
463
- */
464
- const latitude = (obs.latitude * Math.PI) / 180;
465
- const slope = (370 * Math.abs(Math.cos(latitude)) + 9 * Math.abs(Math.sin(latitude))) / 86_400_000;
466
- const backwards = limitDays < 0;
467
- const bracket = (a, b, fa, fb) => {
468
- if (fa < 0 && fb >= 0) {
469
- while (b - a > 10) {
470
- const middle = Math.floor((a + b) / 2);
471
- const fm = residual(middle);
472
- if (fm < 0)
473
- a = middle;
474
- else
475
- b = middle;
476
- }
477
- return MakeTime(new Date((a + b) / 2));
478
- }
479
- if (b - a <= 50 || Math.min(Math.abs(fa), Math.abs(fb)) > (slope * (b - a)) / 2)
480
- return null;
481
- const middle = Math.floor((a + b) / 2);
482
- const fm = residual(middle);
483
- return backwards
484
- ? (bracket(middle, b, fm, fb) ?? bracket(a, middle, fa, fm))
485
- : (bracket(a, middle, fa, fm) ?? bracket(middle, b, fm, fb));
453
+ culmination,
454
+ aboveAtCulmination: horizon.aboveAtCulmination(culmination),
486
455
  };
487
- let cursor = start.getTime();
488
- let value = residual(cursor);
489
- while (backwards ? cursor > end : cursor < end) {
490
- const next = backwards
491
- ? Math.max(end, cursor - 0.42 * 86_400_000)
492
- : Math.min(end, cursor + 0.42 * 86_400_000);
493
- const nextValue = residual(next);
494
- const found = backwards
495
- ? bracket(next, cursor, nextValue, value)
496
- : bracket(cursor, next, value, nextValue);
497
- if (found)
498
- return found;
499
- cursor = next;
500
- value = nextValue;
501
- }
502
- return null;
503
- }
504
- /** Apparent upper-limb height using SearchRiseSet's ground-level horizon convention. */
505
- horizonResidual(target, obs, date) {
506
- /**
507
- * metersAboveGround defaults to zero: no horizon dip, even at a high ground elevation.
508
- * Only Sun and Moon have a radius in the engine's rise/set model (constants in km).
509
- */
510
- const radiusAu = (target === Body.Sun ? 695700 : target === Body.Moon ? 1738.1 : 0) / KM_PER_AU;
511
- const equator = Equator(target, date, obs, true, true);
512
- return (Horizon(date, obs, equator.ra, equator.dec).altitude +
513
- (180 / Math.PI) * Math.asin(radiusAu / equator.dist) +
514
- (34 / 60) * Atmosphere(obs.height).density);
515
456
  }
516
457
  /**
517
458
  * The cycle that opens at `cursor`: the day of the next culmination, or — when the body is
@@ -533,7 +474,7 @@ export class EphemerisService {
533
474
  rise: null,
534
475
  set: null,
535
476
  transit: culmination,
536
- note: culmination.hor.altitude > 0
477
+ note: crossings.aboveAtCulmination
537
478
  ? 'Circumpolar — never sets at this latitude/date.'
538
479
  : 'Never rises above the horizon at this latitude/date.',
539
480
  nightFrom: noon.date,
@@ -576,7 +517,7 @@ export class EphemerisService {
576
517
  */
577
518
  restOfDarkDay(obs, start, crossings, sunsetBefore) {
578
519
  const { alreadyUp, rise, culmination } = crossings;
579
- if (alreadyUp || (rise === null && culmination.hor.altitude > 0))
520
+ if (alreadyUp || (rise === null && crossings.aboveAtCulmination))
580
521
  return;
581
522
  const midnight = SearchHourAngle(Body.Sun, obs, 12, start, +1).time;
582
523
  // A lower culmination before the next culmination means `start` is past this day's.
@@ -716,8 +657,10 @@ export class EphemerisService {
716
657
  * Search forward for the next `count` occurrences of an event class. Every search stops
717
658
  * at the end of the supported span, which is the only reason fewer than `count` come back.
718
659
  * An observer adds local circumstances to either eclipse class, and for solar eclipses it
719
- * switches the search from global to observer-local. `body2` turns a conjunction with
720
- * the Sun into a conjunction of two bodies, and is rejected on every other class.
660
+ * switches the search from global to observer-local; on a meteor shower it adds the
661
+ * radiant's and the Sun's altitude at each maximum. `body2` turns a conjunction with the
662
+ * Sun into a conjunction of two bodies, and is rejected on every other class. `shower`
663
+ * narrows a meteor-shower search to one shower, and every other class ignores it.
721
664
  */
722
665
  findEvents(event, opts) {
723
666
  if (opts.body2 !== undefined && event !== 'conjunction') {
@@ -743,6 +686,8 @@ export class EphemerisService {
743
686
  return this.maxElongationEvents(resolveBody(event, opts.body), opts.start, opts.count, opts.timezone);
744
687
  case 'perigee_apogee':
745
688
  return this.apsisEvents(resolveBody(event, opts.body), opts.start, opts.count, opts.timezone);
689
+ case 'meteor_shower':
690
+ return this.meteorShowerEvents(opts.start, opts.count, opts.shower, opts.observer, opts.timezone);
746
691
  }
747
692
  }
748
693
  seasonEvents(event, start, count, timezone) {
@@ -828,8 +773,10 @@ export class EphemerisService {
828
773
  ]))
829
774
  : {}),
830
775
  };
831
- if (timezone)
776
+ if (timezone) {
832
777
  rec.timeLocal = this.formatLocal(peak.date, timezone);
778
+ rec.contactsLocal = this.localContactTimes(contacts, timezone);
779
+ }
833
780
  out.push(rec);
834
781
  ecl = NextLunarEclipse(peak);
835
782
  }
@@ -858,16 +805,22 @@ export class EphemerisService {
858
805
  ['total_end', ecl.total_end],
859
806
  ['partial_end', ecl.partial_end],
860
807
  ];
808
+ const times = contacts.map(([phase, contact]) => [
809
+ phase,
810
+ contact?.time,
811
+ ]);
861
812
  const rec = {
862
813
  event: 'solar_eclipse',
863
814
  timeUtc: peakTime.toString(),
864
815
  kind: ecl.kind,
865
816
  obscuration: ecl.obscuration,
866
- contacts: contactTimes(contacts.map(([phase, contact]) => [phase, contact?.time])),
817
+ contacts: contactTimes(times),
867
818
  ...localCircumstances(contacts.map(([phase, contact]) => [phase, contact?.altitude])),
868
819
  };
869
- if (timezone)
820
+ if (timezone) {
870
821
  rec.timeLocal = this.formatLocal(peakTime.date, timezone);
822
+ rec.contactsLocal = this.localContactTimes(times, timezone);
823
+ }
871
824
  out.push(rec);
872
825
  ecl = NextLocalSolarEclipse(peakTime, obs);
873
826
  }
@@ -877,26 +830,41 @@ export class EphemerisService {
877
830
  while (ecl.peak.date < start)
878
831
  ecl = NextGlobalSolarEclipse(ecl.peak);
879
832
  for (let i = 0; i < count && withinSpan(ecl.peak.date); i++) {
833
+ // A global eclipse has no observer to time the partial or total phases for.
834
+ const times = [['peak', ecl.peak]];
880
835
  const rec = {
881
836
  event: 'solar_eclipse',
882
837
  timeUtc: ecl.peak.toString(),
883
838
  kind: ecl.kind,
884
839
  obscuration: ecl.obscuration ?? null,
885
- contacts: { peak_utc: ecl.peak.toString() },
840
+ contacts: contactTimes(times),
886
841
  };
887
842
  // The engine leaves both undefined for a partial eclipse, whose axis misses Earth.
888
843
  if (ecl.latitude !== undefined && ecl.longitude !== undefined) {
889
844
  rec.peakLatitudeDegrees = ecl.latitude;
890
845
  rec.peakLongitudeDegrees = ecl.longitude;
891
846
  }
892
- if (timezone)
847
+ if (timezone) {
893
848
  rec.timeLocal = this.formatLocal(ecl.peak.date, timezone);
849
+ rec.contactsLocal = this.localContactTimes(times, timezone);
850
+ }
894
851
  out.push(rec);
895
852
  ecl = NextGlobalSolarEclipse(ecl.peak);
896
853
  }
897
854
  }
898
855
  return out;
899
856
  }
857
+ /**
858
+ * `contactTimes()` on the observer's clock: keyed `<phase>_local`, null for a phase that
859
+ * does not occur, each instant formatted as `timeLocal` is — whole seconds, and the zone's
860
+ * offset at that contact's own instant.
861
+ */
862
+ localContactTimes(contacts, timezone) {
863
+ return Object.fromEntries(contacts.map(([phase, time]) => [
864
+ `${phase}_local`,
865
+ time ? this.formatLocal(time.date, timezone) : null,
866
+ ]));
867
+ }
900
868
  relativeLongitudeEvents(event, body, start, count, timezone) {
901
869
  // SearchRelativeLongitude takes the body's ecliptic longitude relative to Earth's
902
870
  // as seen from the Sun: 0 puts them on the same side (opposition for a superior
@@ -946,10 +914,7 @@ export class EphemerisService {
946
914
  const [b1, b2] = [BODY_ENUM[body], BODY_ENUM[body2]];
947
915
  const maxRate = MAX_LONGITUDE_RATE_DEG_PER_DAY[body] + MAX_LONGITUDE_RATE_DEG_PER_DAY[body2];
948
916
  /** `body`'s longitude minus `body2`'s in (−180°, 180°]: 0 at conjunction, ±180 opposite. */
949
- const offset = (t) => {
950
- const d = PairLongitude(b1, b2, t);
951
- return d > 180 ? d - 360 : d;
952
- };
917
+ const offset = (t) => toSignedTurn(PairLongitude(b1, b2, t));
953
918
  const end = MakeTime(SPAN_END);
954
919
  const out = [];
955
920
  let t1 = MakeTime(start);
@@ -1032,8 +997,55 @@ export class EphemerisService {
1032
997
  }
1033
998
  return out;
1034
999
  }
1000
+ /**
1001
+ * Meteor shower maxima from the bundled IMO table, merged in time order: each the instant
1002
+ * λ⊙ reaches the shower's peak value, kept when it falls at or after `start`. `shower`
1003
+ * narrows the search to one shower, and a name the table does not hold throws
1004
+ * `shower_not_found`. An observer adds the radiant's and the Sun's altitude at each maximum.
1005
+ */
1006
+ meteorShowerEvents(start, count, shower, observer, timezone) {
1007
+ const showers = shower === undefined ? METEOR_SHOWERS : [lookupShower(shower)];
1008
+ const obs = observer ? this.toObserver(observer) : undefined;
1009
+ const from = MakeTime(start);
1010
+ // Each shower's next maximum; the earliest is served, then replaced by that shower's next.
1011
+ const pending = showers.map((s) => ({
1012
+ shower: s,
1013
+ peak: nextSolarLongitude(s.peakSolarLongitudeDegrees, from),
1014
+ }));
1015
+ const out = [];
1016
+ while (out.length < count) {
1017
+ const next = pending.reduce((earliest, p) => (p.peak.ut < earliest.peak.ut ? p : earliest));
1018
+ if (!withinSpan(next.peak.date))
1019
+ break;
1020
+ out.push(this.meteorShowerRecord(next.shower, next.peak, obs, timezone));
1021
+ next.peak = nextSolarLongitude(next.shower.peakSolarLongitudeDegrees, next.peak.AddDays(1));
1022
+ }
1023
+ return out;
1024
+ }
1025
+ /** One meteor shower maximum: the bundled parameters, the dates bounding its activity, and the Moon. */
1026
+ meteorShowerRecord(shower, peak, obs, timezone) {
1027
+ const rec = {
1028
+ event: 'meteor_shower',
1029
+ timeUtc: peak.toString(),
1030
+ shower: shower.name,
1031
+ showerCode: shower.code,
1032
+ zhr: shower.zhr,
1033
+ radiantRaHours: shower.radiantRaDegrees / 15,
1034
+ radiantDecDegrees: shower.radiantDecDegrees,
1035
+ activityStartDate: activityDate(shower.activity2026.start, shower, peak),
1036
+ activityEndDate: activityDate(shower.activity2026.end, shower, peak),
1037
+ moonIlluminatedFraction: Illumination(Body.Moon, peak).phase_fraction,
1038
+ };
1039
+ if (obs) {
1040
+ rec.radiantAltitudeDegrees = radiantAltitudeDegrees(shower, obs, peak);
1041
+ rec.sunAltitudeDegrees = this.altitudeDegrees(Body.Sun, obs, peak);
1042
+ }
1043
+ if (timezone)
1044
+ rec.timeLocal = this.formatLocal(peak.date, timezone);
1045
+ return rec;
1046
+ }
1035
1047
  // ---- list_visible --------------------------------------------------------
1036
- /** Iterate naked-eye bodies (+ optional catalog stars), filter above-horizon, rank. */
1048
+ /** Filter naked-eye bodies and optional catalog stars by altitude, then rank them. */
1037
1049
  listVisible(observer, date, opts) {
1038
1050
  const obs = this.toObserver(observer);
1039
1051
  const time = MakeTime(date);
@@ -1065,9 +1077,11 @@ export class EphemerisService {
1065
1077
  candidates.push(pos);
1066
1078
  }
1067
1079
  }
1068
- // Rank brightest-and-highest first: sort by magnitude ascending (brighter = lower),
1069
- // breaking ties by altitude descending. Null magnitudes sort last.
1080
+ // Bodies above the horizon come first. Within each group, rank by magnitude
1081
+ // ascending and break ties by altitude descending. Null magnitudes sort last.
1070
1082
  candidates.sort((a, b) => {
1083
+ if (a.horizontal.aboveHorizon !== b.horizontal.aboveHorizon)
1084
+ return a.horizontal.aboveHorizon ? -1 : 1;
1071
1085
  const am = a.magnitude ?? 99;
1072
1086
  const bm = b.magnitude ?? 99;
1073
1087
  if (am !== bm)
@@ -1081,7 +1095,7 @@ export class EphemerisService {
1081
1095
  }));
1082
1096
  return { bodies, skyCondition, sunAltitudeDegrees: sunAlt };
1083
1097
  }
1084
- /** Resolve a single named star into a DefineStar slot for get_sky_position. */
1098
+ /** Resolve a single named star into a DefineStar slot for get_sky_position and get_rise_set. */
1085
1099
  resolveStarTarget(name) {
1086
1100
  return this.defineStarTarget(this.lookupStar(name), 0);
1087
1101
  }
@@ -1105,8 +1119,13 @@ function angularDiameterArcsec(radiusKm, distanceAu) {
1105
1119
  const radians = 2 * Math.atan(radiusKm / distanceKm);
1106
1120
  return radians * (180 / Math.PI) * 3600;
1107
1121
  }
1108
- /** Lower-cased Greek letter symbol → spelled-out name, e.g. `α` → `alpha`. */
1109
- const GREEK_LETTERS = new Map(Object.entries(GREEK_LETTER_NAMES).map(([symbol, spelled]) => [symbol, spelled.toLowerCase()]));
1122
+ /** Degrees folded into [0, 360). */
1123
+ const toTurn = (degrees) => ((degrees % 360) + 360) % 360;
1124
+ /** Degrees folded into (−180, 180]. */
1125
+ const toSignedTurn = (degrees) => {
1126
+ const d = toTurn(degrees);
1127
+ return d > 180 ? d - 360 : d;
1128
+ };
1110
1129
  /** Lower-cased IAU abbreviation → lower-cased genitive, e.g. `cma` → `canis majoris`. */
1111
1130
  const GENITIVES = new Map(Object.entries(CONSTELLATION_GENITIVES).map(([abbr, genitive]) => [
1112
1131
  abbr.toLowerCase(),
@@ -1137,7 +1156,7 @@ function quarterName(index) {
1137
1156
  }
1138
1157
  /** Human phase name from the Moon–Sun longitude difference (0=new, 90=first, 180=full, 270=last). */
1139
1158
  function phaseNameFromLongitude(longitude) {
1140
- const a = ((longitude % 360) + 360) % 360;
1159
+ const a = toTurn(longitude);
1141
1160
  if (a < 22.5 || a >= 337.5)
1142
1161
  return 'New Moon';
1143
1162
  if (a < 67.5)
@@ -1173,7 +1192,7 @@ function skyConditionFromSunAltitude(sunAlt) {
1173
1192
  /** Compass octant label from an azimuth in degrees (0=N, 90=E, 180=S, 270=W). */
1174
1193
  function compassOctant(azimuth) {
1175
1194
  const dirs = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'];
1176
- const normalized = (((azimuth % 360) + 360) % 360) / 45;
1195
+ const normalized = toTurn(azimuth) / 45;
1177
1196
  const idx = Math.round(normalized) % 8;
1178
1197
  return dirs[idx] ?? 'N';
1179
1198
  }
@@ -1193,8 +1212,8 @@ function brightnessAdjective(mag) {
1193
1212
  }
1194
1213
  /**
1195
1214
  * Deterministic, server-computed visibility headline — real values only. The brightness
1196
- * adjective describes a body against a dark sky, so a condition that hides the body replaces
1197
- * it: daylight, or sitting within `GLARE_ELONGATION_DEG` of the Sun. A civil-twilight sky dims
1215
+ * adjective describes a body against a dark sky. Horizon obstruction takes precedence over
1216
+ * sky conditions. Above the horizon, daylight and solar glare can hide a body. Civil twilight dims
1198
1217
  * the view without hiding a bright body, so it follows the adjective as a caveat. The Sun is
1199
1218
  * exempt from all of it. The Moon and a negative-magnitude Venus are naked-eye objects in a
1200
1219
  * blue sky, so they skip the sky-condition caveats — but not glare, since beside the Sun's
@@ -1208,6 +1227,11 @@ function visibilityNote(pos, sky) {
1208
1227
  ? `${Math.abs(alt).toFixed(0)}° below the ${octant} horizon`
1209
1228
  : `${alt.toFixed(0)}° above the ${octant} horizon`;
1210
1229
  const name = pos.body.charAt(0).toUpperCase() + pos.body.slice(1);
1230
+ if (!pos.horizontal.aboveHorizon) {
1231
+ const obstruction = alt === 0 ? 'at the horizon' : 'below the horizon';
1232
+ const position = alt === 0 ? `at the ${octant} horizon` : altPhrase;
1233
+ return `${name}, ${magPart}${position} — ${obstruction}, not visible`;
1234
+ }
1211
1235
  const headline = `${name}, ${magPart}${altPhrase}`;
1212
1236
  const isSun = pos.body === 'sun';
1213
1237
  const seenInDaylight = isSun ||
@@ -1239,6 +1263,76 @@ function localCircumstances(altitudes) {
1239
1263
  localVisible: altitudes.some(([, altitude]) => altitude !== undefined && altitude > 0),
1240
1264
  };
1241
1265
  }
1266
+ /** The rotation from the J2000 equator to the J2000 mean ecliptic — fixed, so built once. */
1267
+ const EQJ_TO_ECL = Rotation_EQJ_ECL();
1268
+ /** The Earth's mean sidereal motion in degrees per day: how fast λ⊙ advances on average. */
1269
+ const SOLAR_LONGITUDE_RATE_DEG_PER_DAY = 360 / 365.256363;
1270
+ /**
1271
+ * Half-width in days of the window a λ⊙ crossing is refined in around an estimate made at
1272
+ * the mean rate. The orbit's eccentricity puts the true crossing up to 3.9 days from that
1273
+ * estimate however far ahead it reaches, and λ⊙ returns to any value only once a year, so
1274
+ * the window holds exactly the one crossing sought.
1275
+ */
1276
+ const SOLAR_LONGITUDE_WINDOW_DAYS = 6;
1277
+ /**
1278
+ * IMO's solar longitude λ⊙ in degrees: the Earth's heliocentric longitude plus 180° in the
1279
+ * J2000 mean ecliptic, geometric — no aberration. Not the Sun's apparent longitude of date
1280
+ * that `SearchSunLongitude` tracks, which drifts from it with precession (about 0.37° in
1281
+ * 2026, nine hours of the Sun's motion), so the meteor-shower calendar's maxima need this one.
1282
+ */
1283
+ function solarLongitude(time) {
1284
+ const v = RotateVector(EQJ_TO_ECL, HelioVector(Body.Earth, time));
1285
+ return toTurn((Math.atan2(v.y, v.x) * 180) / Math.PI + 180);
1286
+ }
1287
+ /** The instant λ⊙ reaches `target` degrees within `SOLAR_LONGITUDE_WINDOW_DAYS` of `estimate`. */
1288
+ function solarLongitudeCrossing(target, estimate) {
1289
+ const time = Search((t) => toSignedTurn(solarLongitude(t) - target), estimate.AddDays(-SOLAR_LONGITUDE_WINDOW_DAYS), estimate.AddDays(SOLAR_LONGITUDE_WINDOW_DAYS), { dt_tolerance_seconds: 0.01 });
1290
+ if (!time)
1291
+ throw new Error(`No crossing of solar longitude ${target}° near ${estimate}.`);
1292
+ return time;
1293
+ }
1294
+ /** The first instant at or after `from` that λ⊙ reaches `target` degrees. */
1295
+ function nextSolarLongitude(target, from) {
1296
+ const ahead = toTurn(target - solarLongitude(from));
1297
+ return solarLongitudeCrossing(target, from.AddDays(ahead / SOLAR_LONGITUDE_RATE_DEG_PER_DAY));
1298
+ }
1299
+ /**
1300
+ * The UTC date (YYYY-MM-DD), near a maximum at `peak`, on which the Sun reaches the λ⊙ it
1301
+ * held at 12:00 UT on `calendarDate` — one of the 2026 calendar's activity bounds. Kept in
1302
+ * λ⊙ rather than as a date, the window moves with the maximum across the span, as the
1303
+ * maximum's own date does, and needs no year-boundary case: the Quadrantids' opens in the
1304
+ * previous calendar year.
1305
+ */
1306
+ function activityDate(calendarDate, shower, peak) {
1307
+ const bound = solarLongitude(MakeTime(new Date(`${calendarDate}T12:00:00Z`)));
1308
+ const fromPeak = toSignedTurn(bound - shower.peakSolarLongitudeDegrees);
1309
+ const crossing = solarLongitudeCrossing(bound, peak.AddDays(fromPeak / SOLAR_LONGITUDE_RATE_DEG_PER_DAY));
1310
+ return crossing.date.toISOString().slice(0, 10);
1311
+ }
1312
+ /** Refracted altitude in degrees of a shower's J2000 radiant at `time`, precessed to the date. */
1313
+ function radiantAltitudeDegrees(shower, obs, time) {
1314
+ const j2000 = VectorFromSphere(new Spherical(shower.radiantDecDegrees, shower.radiantRaDegrees, 1), time);
1315
+ const ofDate = EquatorFromVector(RotateVector(Rotation_EQJ_EQD(time), j2000));
1316
+ return Horizon(time, obs, ofDate.ra, ofDate.dec, 'normal').altitude;
1317
+ }
1318
+ /**
1319
+ * Resolve a shower's IMO code or name (case-insensitive, a Greek letter spelled out or as a
1320
+ * symbol). A miss throws `shower_not_found` listing the table, in the message and as
1321
+ * `catalog_showers`.
1322
+ */
1323
+ function lookupShower(name) {
1324
+ const hit = findShower(name);
1325
+ if (hit)
1326
+ return hit;
1327
+ const listed = METEOR_SHOWERS.map((s) => `${s.name} (${s.code})`);
1328
+ throw notFound(`Meteor shower "${name}" is not in the bundled table. It holds these ${listed.length} showers: ${listed.join(', ')}.`, {
1329
+ reason: 'shower_not_found',
1330
+ recovery: {
1331
+ hint: 'Pick a shower from the table this error lists, by its IMO code or name (e.g. "GEM", "Geminids", "eta Aquariids"). A shower outside the table cannot be searched.',
1332
+ },
1333
+ catalog_showers: METEOR_SHOWERS.map(({ code, name }) => ({ code, name })),
1334
+ });
1335
+ }
1242
1336
  /**
1243
1337
  * Which bodies each body-relative event class is defined for, and the hint that
1244
1338
  * names the alternatives. Gating here keeps astronomy-engine from being handed a
@@ -1279,12 +1373,13 @@ function resolveBody(event, body) {
1279
1373
  }
1280
1374
  return body;
1281
1375
  }
1282
- /** A body-relative event searched without its target body — the `body_required` reason. */
1376
+ /**
1377
+ * A body-relative event searched without its target body — the `body_required` reason. It
1378
+ * carries no hint: one written here would override the recovery astronomy_find_events
1379
+ * declares for the same reason, so the framework fills that declared recovery instead.
1380
+ */
1283
1381
  function bodyRequired(event) {
1284
- return invalidParams(`The "${event}" event requires a target body.`, {
1285
- reason: 'body_required',
1286
- recovery: { hint: 'Add the target body (e.g. "mars" or "jupiter") and retry.' },
1287
- });
1382
+ return invalidParams(`The "${event}" event requires a target body.`, { reason: 'body_required' });
1288
1383
  }
1289
1384
  /**
1290
1385
  * A `body2` the search cannot pair — the `invalid_body_pair` reason. The hint is written