oculon 0.0.0-stage → 0.1.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.
Files changed (255) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +344 -2
  3. package/dist/agent.d.ts +47 -0
  4. package/dist/agent.js +104 -0
  5. package/dist/cases.d.ts +68 -0
  6. package/dist/cases.js +158 -0
  7. package/dist/cli/main.d.ts +12 -0
  8. package/dist/cli/main.js +1999 -0
  9. package/dist/cli.d.ts +2 -0
  10. package/dist/cli.js +15 -0
  11. package/dist/core/context.d.ts +19 -0
  12. package/dist/core/context.js +19 -0
  13. package/dist/core/features.d.ts +22 -0
  14. package/dist/core/features.js +28 -0
  15. package/dist/core/graph.d.ts +38 -0
  16. package/dist/core/graph.js +81 -0
  17. package/dist/core/http.d.ts +42 -0
  18. package/dist/core/http.js +266 -0
  19. package/dist/core/keys.d.ts +8 -0
  20. package/dist/core/keys.js +22 -0
  21. package/dist/core/llm.d.ts +93 -0
  22. package/dist/core/llm.js +180 -0
  23. package/dist/core/merkle.d.ts +15 -0
  24. package/dist/core/merkle.js +46 -0
  25. package/dist/core/paths.d.ts +2 -0
  26. package/dist/core/paths.js +6 -0
  27. package/dist/core/png.d.ts +17 -0
  28. package/dist/core/png.js +101 -0
  29. package/dist/core/quota.d.ts +15 -0
  30. package/dist/core/quota.js +90 -0
  31. package/dist/core/stats.d.ts +24 -0
  32. package/dist/core/stats.js +67 -0
  33. package/dist/core/store.d.ts +20 -0
  34. package/dist/core/store.js +213 -0
  35. package/dist/core/text.d.ts +9 -0
  36. package/dist/core/text.js +30 -0
  37. package/dist/core/types.d.ts +38 -0
  38. package/dist/core/types.js +1 -0
  39. package/dist/index.d.ts +342 -0
  40. package/dist/index.js +495 -0
  41. package/dist/live.d.ts +53 -0
  42. package/dist/live.js +236 -0
  43. package/dist/mcp.d.ts +43 -0
  44. package/dist/mcp.js +651 -0
  45. package/dist/modules/airport.d.ts +60 -0
  46. package/dist/modules/airport.js +111 -0
  47. package/dist/modules/audit.d.ts +73 -0
  48. package/dist/modules/audit.js +211 -0
  49. package/dist/modules/bgp.d.ts +147 -0
  50. package/dist/modules/bgp.js +206 -0
  51. package/dist/modules/blackout.d.ts +41 -0
  52. package/dist/modules/blackout.js +98 -0
  53. package/dist/modules/brief.d.ts +26 -0
  54. package/dist/modules/brief.js +99 -0
  55. package/dist/modules/calendar.d.ts +27 -0
  56. package/dist/modules/calendar.js +145 -0
  57. package/dist/modules/calibrate.d.ts +46 -0
  58. package/dist/modules/calibrate.js +92 -0
  59. package/dist/modules/cloud.d.ts +32 -0
  60. package/dist/modules/cloud.js +94 -0
  61. package/dist/modules/condor.d.ts +66 -0
  62. package/dist/modules/condor.js +214 -0
  63. package/dist/modules/connect.d.ts +47 -0
  64. package/dist/modules/connect.js +114 -0
  65. package/dist/modules/contradictions.d.ts +27 -0
  66. package/dist/modules/contradictions.js +76 -0
  67. package/dist/modules/country.d.ts +82 -0
  68. package/dist/modules/country.js +136 -0
  69. package/dist/modules/cricket.d.ts +34 -0
  70. package/dist/modules/cricket.js +166 -0
  71. package/dist/modules/darkships.d.ts +219 -0
  72. package/dist/modules/darkships.js +400 -0
  73. package/dist/modules/defi.d.ts +237 -0
  74. package/dist/modules/defi.js +512 -0
  75. package/dist/modules/emailsec.d.ts +47 -0
  76. package/dist/modules/emailsec.js +146 -0
  77. package/dist/modules/exposure.d.ts +43 -0
  78. package/dist/modules/exposure.js +89 -0
  79. package/dist/modules/factcheck.d.ts +39 -0
  80. package/dist/modules/factcheck.js +127 -0
  81. package/dist/modules/falcon.d.ts +58 -0
  82. package/dist/modules/falcon.js +219 -0
  83. package/dist/modules/feedback.d.ts +24 -0
  84. package/dist/modules/feedback.js +37 -0
  85. package/dist/modules/fence.d.ts +52 -0
  86. package/dist/modules/fence.js +128 -0
  87. package/dist/modules/ferret.d.ts +47 -0
  88. package/dist/modules/ferret.js +220 -0
  89. package/dist/modules/filings.d.ts +86 -0
  90. package/dist/modules/filings.js +166 -0
  91. package/dist/modules/fires.d.ts +56 -0
  92. package/dist/modules/fires.js +150 -0
  93. package/dist/modules/hazards.d.ts +37 -0
  94. package/dist/modules/hazards.js +83 -0
  95. package/dist/modules/health.d.ts +24 -0
  96. package/dist/modules/health.js +82 -0
  97. package/dist/modules/heron.d.ts +68 -0
  98. package/dist/modules/heron.js +184 -0
  99. package/dist/modules/hound.d.ts +100 -0
  100. package/dist/modules/hound.js +301 -0
  101. package/dist/modules/impact.d.ts +39 -0
  102. package/dist/modules/impact.js +63 -0
  103. package/dist/modules/launches.d.ts +24 -0
  104. package/dist/modules/launches.js +61 -0
  105. package/dist/modules/listen.d.ts +48 -0
  106. package/dist/modules/listen.js +125 -0
  107. package/dist/modules/lynx.d.ts +43 -0
  108. package/dist/modules/lynx.js +127 -0
  109. package/dist/modules/magpie.d.ts +70 -0
  110. package/dist/modules/magpie.js +174 -0
  111. package/dist/modules/meerkat.d.ts +42 -0
  112. package/dist/modules/meerkat.js +293 -0
  113. package/dist/modules/monitor.d.ts +27 -0
  114. package/dist/modules/monitor.js +105 -0
  115. package/dist/modules/narratives.d.ts +33 -0
  116. package/dist/modules/narratives.js +136 -0
  117. package/dist/modules/owl.d.ts +71 -0
  118. package/dist/modules/owl.js +290 -0
  119. package/dist/modules/papers.d.ts +46 -0
  120. package/dist/modules/papers.js +135 -0
  121. package/dist/modules/personal.d.ts +54 -0
  122. package/dist/modules/personal.js +153 -0
  123. package/dist/modules/pulse.d.ts +19 -0
  124. package/dist/modules/pulse.js +59 -0
  125. package/dist/modules/raven.d.ts +80 -0
  126. package/dist/modules/raven.js +147 -0
  127. package/dist/modules/recall.d.ts +44 -0
  128. package/dist/modules/recall.js +123 -0
  129. package/dist/modules/regs.d.ts +88 -0
  130. package/dist/modules/regs.js +142 -0
  131. package/dist/modules/rewind.d.ts +22 -0
  132. package/dist/modules/rewind.js +68 -0
  133. package/dist/modules/sanctions.d.ts +62 -0
  134. package/dist/modules/sanctions.js +173 -0
  135. package/dist/modules/scam.d.ts +43 -0
  136. package/dist/modules/scam.js +111 -0
  137. package/dist/modules/scoop.d.ts +31 -0
  138. package/dist/modules/scoop.js +74 -0
  139. package/dist/modules/ships.d.ts +33 -0
  140. package/dist/modules/ships.js +113 -0
  141. package/dist/modules/sky.d.ts +47 -0
  142. package/dist/modules/sky.js +183 -0
  143. package/dist/modules/squawk.d.ts +46 -0
  144. package/dist/modules/squawk.js +106 -0
  145. package/dist/modules/tortoise.d.ts +40 -0
  146. package/dist/modules/tortoise.js +104 -0
  147. package/dist/modules/travel.d.ts +94 -0
  148. package/dist/modules/travel.js +241 -0
  149. package/dist/modules/urlcheck.d.ts +63 -0
  150. package/dist/modules/urlcheck.js +223 -0
  151. package/dist/modules/vulns.d.ts +142 -0
  152. package/dist/modules/vulns.js +276 -0
  153. package/dist/plugins.d.ts +41 -0
  154. package/dist/plugins.js +70 -0
  155. package/dist/report.d.ts +12 -0
  156. package/dist/report.js +90 -0
  157. package/dist/scheduler.d.ts +22 -0
  158. package/dist/scheduler.js +139 -0
  159. package/dist/sources/aircraft.d.ts +76 -0
  160. package/dist/sources/aircraft.js +107 -0
  161. package/dist/sources/airports.d.ts +28 -0
  162. package/dist/sources/airports.js +100 -0
  163. package/dist/sources/ais.d.ts +32 -0
  164. package/dist/sources/ais.js +111 -0
  165. package/dist/sources/apify.d.ts +28 -0
  166. package/dist/sources/apify.js +80 -0
  167. package/dist/sources/arxiv.d.ts +13 -0
  168. package/dist/sources/arxiv.js +27 -0
  169. package/dist/sources/certs.d.ts +12 -0
  170. package/dist/sources/certs.js +23 -0
  171. package/dist/sources/corp.d.ts +46 -0
  172. package/dist/sources/corp.js +60 -0
  173. package/dist/sources/earth.d.ts +39 -0
  174. package/dist/sources/earth.js +76 -0
  175. package/dist/sources/fda.d.ts +77 -0
  176. package/dist/sources/fda.js +121 -0
  177. package/dist/sources/finance.d.ts +181 -0
  178. package/dist/sources/finance.js +270 -0
  179. package/dist/sources/gdelt.d.ts +19 -0
  180. package/dist/sources/gdelt.js +33 -0
  181. package/dist/sources/github.d.ts +17 -0
  182. package/dist/sources/github.js +33 -0
  183. package/dist/sources/hackernews.d.ts +20 -0
  184. package/dist/sources/hackernews.js +37 -0
  185. package/dist/sources/labels.d.ts +21 -0
  186. package/dist/sources/labels.js +87 -0
  187. package/dist/sources/launch.d.ts +16 -0
  188. package/dist/sources/launch.js +41 -0
  189. package/dist/sources/ofac.d.ts +29 -0
  190. package/dist/sources/ofac.js +86 -0
  191. package/dist/sources/onchain.d.ts +77 -0
  192. package/dist/sources/onchain.js +189 -0
  193. package/dist/sources/opentimestamps.d.ts +44 -0
  194. package/dist/sources/opentimestamps.js +131 -0
  195. package/dist/sources/polymarket.d.ts +36 -0
  196. package/dist/sources/polymarket.js +70 -0
  197. package/dist/sources/predict.d.ts +18 -0
  198. package/dist/sources/predict.js +59 -0
  199. package/dist/sources/press.d.ts +30 -0
  200. package/dist/sources/press.js +111 -0
  201. package/dist/sources/resend.d.ts +14 -0
  202. package/dist/sources/resend.js +29 -0
  203. package/dist/sources/robinhood.d.ts +109 -0
  204. package/dist/sources/robinhood.js +129 -0
  205. package/dist/sources/sec.d.ts +67 -0
  206. package/dist/sources/sec.js +129 -0
  207. package/dist/sources/sentinel.d.ts +13 -0
  208. package/dist/sources/sentinel.js +63 -0
  209. package/dist/sources/signatures.d.ts +14 -0
  210. package/dist/sources/signatures.js +103 -0
  211. package/dist/sources/social.d.ts +22 -0
  212. package/dist/sources/social.js +56 -0
  213. package/dist/sources/space.d.ts +160 -0
  214. package/dist/sources/space.js +230 -0
  215. package/dist/sources/usgs.d.ts +17 -0
  216. package/dist/sources/usgs.js +24 -0
  217. package/dist/sources/wayback.d.ts +10 -0
  218. package/dist/sources/wayback.js +28 -0
  219. package/dist/sources/websec.d.ts +19 -0
  220. package/dist/sources/websec.js +40 -0
  221. package/dist/sources/wikidata.d.ts +11 -0
  222. package/dist/sources/wikidata.js +30 -0
  223. package/dist/sources/wikimedia.d.ts +28 -0
  224. package/dist/sources/wikimedia.js +52 -0
  225. package/dist/telegram.d.ts +104 -0
  226. package/dist/telegram.js +927 -0
  227. package/dist/web/assets/favicon-32.png +0 -0
  228. package/dist/web/assets/fx.js +178 -0
  229. package/dist/web/assets/icon-192.png +0 -0
  230. package/dist/web/assets/icon-512.png +0 -0
  231. package/dist/web/assets/icon-maskable-512.png +0 -0
  232. package/dist/web/assets/night-americas.jpg +0 -0
  233. package/dist/web/assets/night-emea.jpg +0 -0
  234. package/dist/web/assets/og.png +0 -0
  235. package/dist/web/assets/redsea-bm.jpg +0 -0
  236. package/dist/web/docs.html +263 -0
  237. package/dist/web/index.html +1828 -0
  238. package/dist/web/insights.d.ts +100 -0
  239. package/dist/web/insights.js +134 -0
  240. package/dist/web/landing.html +1143 -0
  241. package/dist/web/legal.html +176 -0
  242. package/dist/web/manifest.webmanifest +20 -0
  243. package/dist/web/mcp.html +104 -0
  244. package/dist/web/mcphttp.d.ts +10 -0
  245. package/dist/web/mcphttp.js +67 -0
  246. package/dist/web/openapi.d.ts +1 -0
  247. package/dist/web/openapi.js +51 -0
  248. package/dist/web/public.d.ts +45 -0
  249. package/dist/web/public.js +135 -0
  250. package/dist/web/server.d.ts +69 -0
  251. package/dist/web/server.js +750 -0
  252. package/dist/web/share.d.ts +35 -0
  253. package/dist/web/share.js +132 -0
  254. package/dist/web/sw.js +28 -0
  255. package/package.json +60 -4
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Airport status: is this airport running normally right now?
3
+ * aviationweather.gov (NOAA, no key, worldwide): the latest METAR (flight category, wind, visibility, ceiling)
4
+ * and the TAF forecast.
5
+ * FAA NAS status (no key, US airports): ground stops, ground delay programs, arrival and departure delays,
6
+ * closures.
7
+ * adsb.lol: aircraft squawking an emergency code within 150 km.
8
+ * The airport is found by IATA or ICAO code, or by name, in OurAirports.
9
+ */
10
+ import type { Ctx } from '../core/context.js';
11
+ import type { ModuleResult } from '../core/types.js';
12
+ import { type Airport } from '../sources/airports.js';
13
+ export type AirportVerdict = 'normal' | 'weather watch' | 'delays' | 'disrupted';
14
+ export interface AirportStatus {
15
+ airport: {
16
+ ident: string;
17
+ iata: string | null;
18
+ name: string;
19
+ city: string;
20
+ country: string;
21
+ lat: number;
22
+ lon: number;
23
+ };
24
+ verdict: AirportVerdict;
25
+ points: string[];
26
+ metar: {
27
+ raw: string;
28
+ time: string;
29
+ category: string | null;
30
+ windKt: number | null;
31
+ gustKt: number | null;
32
+ visibility: string | null;
33
+ ceilingFt: number | null;
34
+ tempC: number | null;
35
+ weather: string | null;
36
+ } | null;
37
+ taf: {
38
+ raw: string;
39
+ issued: string;
40
+ } | null;
41
+ faa: {
42
+ delays: {
43
+ type: string;
44
+ reason: string;
45
+ detail: string;
46
+ }[];
47
+ checked: boolean;
48
+ };
49
+ emergencies: {
50
+ callsign: string | null;
51
+ code: string;
52
+ meaning: string;
53
+ km: number;
54
+ }[];
55
+ }
56
+ /** Finds an airport by IATA ("JFK"), ICAO ("KJFK") or words of its name or city. */
57
+ export declare function findAirport(list: Airport[], q: string): Airport | null;
58
+ /** FAA NAS status XML → delays and closures for one airport (IATA code without the K). */
59
+ export declare function parseFaaStatus(xml: string, iata: string): AirportStatus['faa']['delays'];
60
+ export declare function airportStatus(ctx: Ctx, query: string): Promise<ModuleResult<AirportStatus>>;
@@ -0,0 +1,111 @@
1
+ import { signalId } from '../core/text.js';
2
+ import { airportLabel, airports, haversineKm } from '../sources/airports.js';
3
+ import { squawks } from './squawk.js';
4
+ /** Finds an airport by IATA ("JFK"), ICAO ("KJFK") or words of its name or city. */
5
+ export function findAirport(list, q) {
6
+ const s = q.trim().toUpperCase();
7
+ if (/^[A-Z]{3}$/.test(s))
8
+ return list.find((a) => a.iata === s) ?? null;
9
+ if (/^[A-Z0-9]{4}$/.test(s)) {
10
+ const a = list.find((x) => x.ident === s);
11
+ if (a)
12
+ return a;
13
+ }
14
+ const words = q.toLowerCase().split(/\s+/).filter(Boolean);
15
+ const hits = list.filter((a) => words.every((w) => `${a.name} ${a.city}`.toLowerCase().includes(w)));
16
+ return hits.sort((a, b) => Number(b.type === 'large_airport') - Number(a.type === 'large_airport'))[0] ?? null;
17
+ }
18
+ async function metar(ctx, icao) {
19
+ const r = await ctx.http.get(`https://aviationweather.gov/api/data/metar?ids=${icao}&format=json`, { source: 'aviationweather', ttlSec: 600 });
20
+ const m = r.data?.[0];
21
+ if (!m?.rawOb)
22
+ return { data: null, prov: r.prov };
23
+ const ceiling = (m.clouds ?? []).filter((c) => /BKN|OVC|OVX/.test(c.cover) && c.base != null).map((c) => c.base).sort((a, b) => a - b)[0] ?? null;
24
+ return { data: { raw: m.rawOb, time: m.reportTime ?? '', category: m.fltCat ?? null, windKt: typeof m.wspd === 'number' ? m.wspd : null, gustKt: m.wgst ?? null, visibility: m.visib != null ? `${m.visib} SM` : null, ceilingFt: ceiling, tempC: m.temp ?? null, weather: m.wxString ?? null }, prov: r.prov };
25
+ }
26
+ async function taf(ctx, icao) {
27
+ const r = await ctx.http.get(`https://aviationweather.gov/api/data/taf?ids=${icao}&format=json`, { source: 'aviationweather', ttlSec: 1800 });
28
+ const t = r.data?.[0];
29
+ return { data: t?.rawTAF ? { raw: t.rawTAF, issued: t.issueTime ?? '' } : null, prov: r.prov };
30
+ }
31
+ const text = (xml, tag) => new RegExp(`<${tag}>([\\s\\S]*?)</${tag}>`).exec(xml)?.[1]?.trim() ?? '';
32
+ /** FAA NAS status XML → delays and closures for one airport (IATA code without the K). */
33
+ export function parseFaaStatus(xml, iata) {
34
+ const out = [];
35
+ for (const block of xml.split('<Delay_type>').slice(1)) {
36
+ const type = text(block, 'Name');
37
+ const items = block.split(/<(?:Ground_Stop|Program|Delay|Airport)>/).slice(1);
38
+ for (const it of items) {
39
+ const arpt = text(it, 'ARPT');
40
+ if (arpt !== iata)
41
+ continue;
42
+ const reason = text(it, 'Reason').replace(/^!\S+\s+\S+\s+/, '');
43
+ const detail = [text(it, 'Avg') && `average ${text(it, 'Avg')}`, text(it, 'Max') && `max ${text(it, 'Max')}`, text(it, 'End_Time') && `until ${text(it, 'End_Time')}`, text(it, 'Min') && text(it, 'Trend') && `${text(it, 'Min')}-${text(it, 'Max')} ${text(it, 'Trend')}`, text(it, 'Reopen') && `reopens ${text(it, 'Reopen')}`].filter(Boolean).join(', ');
44
+ out.push({ type, reason: reason.slice(0, 200), detail });
45
+ }
46
+ }
47
+ return out;
48
+ }
49
+ const MEANING = { '7500': 'hijack', '7600': 'radio failure', '7700': 'general emergency' };
50
+ export async function airportStatus(ctx, query) {
51
+ const provenance = [];
52
+ const list = await airports(ctx);
53
+ provenance.push(list.prov);
54
+ const a = findAirport(list.data ?? [], query);
55
+ if (!a)
56
+ throw new Error(`airport not found: ${query} (try an IATA code like JFK or an ICAO code like EGLL)`);
57
+ const isUs = a.country === 'US';
58
+ const [m, t, faaXml, sq] = await Promise.all([
59
+ metar(ctx, a.ident),
60
+ taf(ctx, a.ident),
61
+ isUs ? ctx.http.get('https://nasstatus.faa.gov/api/airport-status-information', { source: 'faa-nas', as: 'text', ttlSec: 300 }) : Promise.resolve(null),
62
+ squawks(ctx, { lookup: false }).catch(() => null),
63
+ ]);
64
+ provenance.push(m.prov, t.prov);
65
+ if (faaXml)
66
+ provenance.push(faaXml.prov);
67
+ if (sq)
68
+ provenance.push(...sq.provenance);
69
+ // FAA ground-stop and closure lists also carry routine NOTAM closures for general aviation; keep real disruptions.
70
+ const delays = faaXml?.data && a.iata ? parseFaaStatus(faaXml.data, a.iata).filter((d) => !/NON SKED TRANSIENT GA|PPR/.test(d.reason)) : [];
71
+ const emergencies = (sq?.result.aircraft ?? [])
72
+ .filter((x) => x.lat != null && x.lon != null)
73
+ .map((x) => ({ callsign: x.callsign ?? null, code: x.code, meaning: x.meaning || MEANING[x.code] || 'emergency', km: Math.round(haversineKm(a.lat, a.lon, x.lat, x.lon)) }))
74
+ .filter((x) => x.km <= 150);
75
+ const points = [];
76
+ let verdict = 'normal';
77
+ for (const d of delays)
78
+ points.push(`FAA ${d.type.toLowerCase()}: ${d.reason}${d.detail ? ` (${d.detail})` : ''}`);
79
+ if (delays.some((d) => /ground stop|closure/i.test(d.type)))
80
+ verdict = 'disrupted';
81
+ else if (delays.length)
82
+ verdict = 'delays';
83
+ const w = m.data;
84
+ if (w) {
85
+ const bad = w.category === 'LIFR' || w.category === 'IFR' || (w.gustKt ?? 0) >= 35 || /TS|FZ|\+SN|\+RA|GR/.test(w.weather ?? '');
86
+ if (bad && verdict === 'normal')
87
+ verdict = 'weather watch';
88
+ points.push(`Weather ${w.category ?? 'n/a'}${w.weather ? `, ${w.weather}` : ''}: wind ${w.windKt ?? '?'} kt${w.gustKt ? ` gusting ${w.gustKt}` : ''}, visibility ${w.visibility ?? '?'}${w.ceilingFt != null ? `, ceiling ${w.ceilingFt} ft` : ''}${w.tempC != null ? `, ${w.tempC}°C` : ''}`);
89
+ }
90
+ else
91
+ points.push('No current METAR from this airport');
92
+ for (const e of emergencies)
93
+ points.push(`Aircraft ${e.callsign ?? 'unknown'} squawking ${e.code} (${e.meaning}) ${e.km} km away`);
94
+ if (isUs && !delays.length)
95
+ points.push('No FAA delays or ground stops reported');
96
+ const nowIso = ctx.now().toISOString();
97
+ const signals = [];
98
+ if (verdict === 'disrupted') {
99
+ const s = { id: signalId('airport', a.ident, nowIso.slice(0, 13)), module: 'airport', title: `${a.iata ?? a.ident} disrupted: ${points[0]}`.slice(0, 160), score: 65, evidence: points.slice(0, 3).map((x) => ({ source: 'faa-nas', text: x })), createdAt: nowIso };
100
+ ctx.graph.saveSignal(s);
101
+ signals.push(s);
102
+ }
103
+ return {
104
+ module: 'airport',
105
+ input: query,
106
+ generatedAt: nowIso,
107
+ result: { airport: { ident: a.ident, iata: a.iata, name: airportLabel(a), city: a.city, country: a.country, lat: a.lat, lon: a.lon }, verdict, points, metar: w, taf: t.data, faa: { delays, checked: Boolean(faaXml?.data) }, emergencies },
108
+ signals,
109
+ provenance,
110
+ };
111
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Dependency audit: health and supply-chain risk of every package in a manifest.
3
+ * deps.dev (Google Open Source Insights, no key): versions, release dates, deprecation, licenses,
4
+ * known advisories (OSV / GitHub), and the source project with its OpenSSF Scorecard and stars.
5
+ * Accepts package.json (npm), requirements.txt (PyPI), or a list such as "npm:express@4.17.1 pypi:requests".
6
+ * Every flag is plain: vulnerable, deprecated, no release in 2 years, behind the latest major, weak or
7
+ * unmaintained per Scorecard, missing or strong-copyleft license.
8
+ */
9
+ import type { Ctx } from '../core/context.js';
10
+ import type { ModuleResult } from '../core/types.js';
11
+ export type Ecosystem = 'npm' | 'pypi' | 'go' | 'cargo' | 'maven' | 'nuget';
12
+ export interface Dependency {
13
+ ecosystem: Ecosystem;
14
+ name: string;
15
+ spec: string | null;
16
+ dev: boolean;
17
+ }
18
+ export interface PackageAudit {
19
+ ecosystem: Ecosystem;
20
+ name: string;
21
+ spec: string | null;
22
+ version: string | null;
23
+ latest: string | null;
24
+ latestReleased: string | null;
25
+ dev: boolean;
26
+ licenses: string[];
27
+ deprecated: string | null;
28
+ advisories: {
29
+ id: string;
30
+ title: string;
31
+ cvss: number | null;
32
+ aliases: string[];
33
+ url: string;
34
+ }[];
35
+ /** All known advisories for this version (details are fetched for the first 8). */
36
+ advisoryCount: number;
37
+ project: {
38
+ id: string;
39
+ stars: number | null;
40
+ scorecard: number | null;
41
+ maintained: number | null;
42
+ url: string;
43
+ } | null;
44
+ flags: string[];
45
+ /** 0 (fine) to 100 (fix now). */
46
+ risk: number;
47
+ }
48
+ export interface AuditResult {
49
+ manifest: string;
50
+ packages: PackageAudit[];
51
+ summary: {
52
+ total: number;
53
+ checked: number;
54
+ vulnerable: number;
55
+ advisories: number;
56
+ deprecated: number;
57
+ stale: number;
58
+ weakScorecard: number;
59
+ risky: number;
60
+ };
61
+ skipped: string[];
62
+ }
63
+ /** Parses package.json, requirements.txt or "eco:name@version" lists into dependencies. */
64
+ export declare function parseManifest(text: string): {
65
+ kind: string;
66
+ deps: Dependency[];
67
+ };
68
+ /** The version a spec most likely installs: an exact pin, else the highest release in the same major (or the default). */
69
+ export declare function resolveVersion(spec: string | null, versions: string[], fallback: string | null): string | null;
70
+ /** Audits up to `max` packages from a manifest (package.json, requirements.txt, or "npm:name@ver" items). */
71
+ export declare function audit(ctx: Ctx, manifestText: string, opts?: {
72
+ max?: number;
73
+ }): Promise<ModuleResult<AuditResult>>;
@@ -0,0 +1,211 @@
1
+ import { clamp } from '../core/stats.js';
2
+ import { signalId } from '../core/text.js';
3
+ const DD = 'https://api.deps.dev/v3';
4
+ const DAY = 86_400_000;
5
+ const SOURCE = 'deps.dev';
6
+ const SYSTEM = { npm: 'NPM', pypi: 'PYPI', go: 'GO', cargo: 'CARGO', maven: 'MAVEN', nuget: 'NUGET' };
7
+ /** Parses package.json, requirements.txt or "eco:name@version" lists into dependencies. */
8
+ export function parseManifest(text) {
9
+ const t = text.trim();
10
+ if (t.startsWith('{')) {
11
+ const j = JSON.parse(t);
12
+ const deps = [];
13
+ for (const [name, spec] of Object.entries({ ...j.dependencies, ...j.optionalDependencies }))
14
+ deps.push({ ecosystem: 'npm', name, spec: String(spec), dev: false });
15
+ for (const [name, spec] of Object.entries(j.devDependencies ?? {}))
16
+ if (!deps.some((d) => d.name === name))
17
+ deps.push({ ecosystem: 'npm', name, spec: String(spec), dev: true });
18
+ return { kind: 'package.json', deps };
19
+ }
20
+ const tokens = t.split(/[\s,]+/).filter(Boolean);
21
+ if (tokens.length && tokens.every((x) => /^(npm|pypi|go|cargo|maven|nuget):/i.test(x))) {
22
+ return {
23
+ kind: 'list',
24
+ deps: tokens.map((x) => {
25
+ const [eco, rest] = [x.slice(0, x.indexOf(':')).toLowerCase(), x.slice(x.indexOf(':') + 1)];
26
+ // "requests==2.19.0" (pip style) or "express@4.17.1"; a leading "@" is an npm scope, not a version.
27
+ const pin = /^(.+?)(==|~=|>=)(.+)$/.exec(rest);
28
+ if (pin)
29
+ return { ecosystem: eco, name: eco === 'pypi' ? pin[1].toLowerCase() : pin[1], spec: `${pin[2]}${pin[3]}`, dev: false };
30
+ const at = rest.lastIndexOf('@');
31
+ return at > 0 ? { ecosystem: eco, name: rest.slice(0, at), spec: rest.slice(at + 1), dev: false } : { ecosystem: eco, name: eco === 'pypi' ? rest.toLowerCase() : rest, spec: null, dev: false };
32
+ }),
33
+ };
34
+ }
35
+ // requirements.txt: "name==1.2.3", "name>=1.0", "name[extra]~=2.0", comments and options ignored.
36
+ const deps = [];
37
+ for (const raw of t.split(/\r?\n/)) {
38
+ const line = raw.replace(/#.*/, '').trim();
39
+ if (!line || line.startsWith('-'))
40
+ continue;
41
+ const m = /^([A-Za-z0-9][A-Za-z0-9._-]*)(\[[^\]]*\])?\s*(?:(==|===|~=|>=|<=|>|<|!=)\s*([^;,\s]+))?/.exec(line);
42
+ if (m)
43
+ deps.push({ ecosystem: 'pypi', name: m[1].toLowerCase(), spec: m[4] ? `${m[3]}${m[4]}` : null, dev: false });
44
+ }
45
+ if (!deps.length)
46
+ throw new Error('could not read the manifest: expected package.json, requirements.txt or "npm:name@version" items');
47
+ return { kind: 'requirements.txt', deps };
48
+ }
49
+ const cmp = (a, b) => {
50
+ const pa = a.split(/[.+-]/).map((x) => (/^\d+$/.test(x) ? Number(x) : x));
51
+ const pb = b.split(/[.+-]/).map((x) => (/^\d+$/.test(x) ? Number(x) : x));
52
+ for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
53
+ const x = pa[i] ?? 0, y = pb[i] ?? 0;
54
+ if (x === y)
55
+ continue;
56
+ if (typeof x === 'number' && typeof y === 'number')
57
+ return x - y;
58
+ return String(x).localeCompare(String(y));
59
+ }
60
+ return 0;
61
+ };
62
+ const major = (v) => Number(/^\D*(\d+)/.exec(v)?.[1] ?? NaN);
63
+ const isPre = (v) => /-|a\d|b\d|rc|dev|alpha|beta/i.test(v);
64
+ /** The version a spec most likely installs: an exact pin, else the highest release in the same major (or the default). */
65
+ export function resolveVersion(spec, versions, fallback) {
66
+ if (!spec)
67
+ return fallback;
68
+ const s = spec.trim();
69
+ const exact = s.replace(/^(==|===|v)/, '');
70
+ if (versions.includes(exact))
71
+ return exact;
72
+ const base = /(\d+(?:\.\d+){0,2})/.exec(s)?.[1];
73
+ if (!base)
74
+ return fallback;
75
+ const releases = versions.filter((v) => !isPre(v));
76
+ if (/^\^|^~=|^~|^>=|^>/.test(s)) {
77
+ const sameMajor = releases.filter((v) => major(v) === major(base) && cmp(v, base) >= 0).sort(cmp);
78
+ if (s.startsWith('>'))
79
+ return releases.filter((v) => cmp(v, base) >= 0).sort(cmp).at(-1) ?? fallback;
80
+ return sameMajor.at(-1) ?? fallback;
81
+ }
82
+ return releases.filter((v) => cmp(v, base) <= 0).sort(cmp).at(-1) ?? fallback;
83
+ }
84
+ const COPYLEFT = /^(A?GPL|SSPL|EUPL|OSL)/i;
85
+ async function auditOne(ctx, d, prov) {
86
+ const sys = SYSTEM[d.ecosystem];
87
+ const pkgPath = `${DD}/systems/${sys}/packages/${encodeURIComponent(d.name)}`;
88
+ const pkg = await ctx.http.get(pkgPath, { source: SOURCE, ttlSec: 12 * 3600, keep: (x) => (x.versions ?? []).map((v) => ({ versionKey: { version: v.versionKey.version }, publishedAt: v.publishedAt, isDefault: v.isDefault, isDeprecated: v.isDeprecated, deprecatedReason: v.deprecatedReason })) });
89
+ prov.push(pkg.prov);
90
+ if (!pkg.data?.length)
91
+ return `${d.ecosystem}:${d.name} (not found on deps.dev)`;
92
+ const all = pkg.data;
93
+ const def = all.find((v) => v.isDefault) ?? [...all].sort((a, b) => cmp(a.versionKey.version, b.versionKey.version)).at(-1);
94
+ const latest = def.versionKey.version;
95
+ const version = resolveVersion(d.spec, all.map((v) => v.versionKey.version), latest);
96
+ const vr = version
97
+ ? await ctx.http.get(`${pkgPath}/versions/${encodeURIComponent(version)}`, { source: SOURCE, ttlSec: 12 * 3600 })
98
+ : null;
99
+ if (vr)
100
+ prov.push(vr.prov);
101
+ const v = vr?.data ?? null;
102
+ const advisories = [];
103
+ for (const a of (v?.advisoryKeys ?? []).slice(0, 8)) {
104
+ const ar = await ctx.http.get(`${DD}/advisories/${encodeURIComponent(a.id)}`, { source: SOURCE, ttlSec: 24 * 3600 });
105
+ prov.push(ar.prov);
106
+ advisories.push({ id: a.id, title: ar.data?.title ?? a.id, cvss: ar.data?.cvss3Score ?? null, aliases: ar.data?.aliases ?? [], url: ar.data?.url ?? `https://osv.dev/vulnerability/${a.id}` });
107
+ }
108
+ const extraAdvisories = Math.max(0, (v?.advisoryKeys?.length ?? 0) - advisories.length);
109
+ const projId = v?.relatedProjects?.find((p) => p.relationType === 'SOURCE_REPO')?.projectKey.id ?? v?.relatedProjects?.[0]?.projectKey.id;
110
+ let project = null;
111
+ if (projId) {
112
+ const pr = await ctx.http.get(`${DD}/projects/${encodeURIComponent(projId)}`, {
113
+ source: SOURCE,
114
+ ttlSec: 24 * 3600,
115
+ keep: (x) => ({ starsCount: x.starsCount, scorecard: x.scorecard ? { overallScore: x.scorecard.overallScore, checks: (x.scorecard.checks ?? []).map((c) => ({ name: c.name, score: c.score })) } : undefined }),
116
+ });
117
+ prov.push(pr.prov);
118
+ if (pr.data)
119
+ project = { id: projId, stars: pr.data.starsCount ?? null, scorecard: pr.data.scorecard?.overallScore ?? null, maintained: pr.data.scorecard?.checks?.find((c) => c.name === 'Maintained')?.score ?? null, url: `https://${projId}` };
120
+ }
121
+ const flags = [];
122
+ let risk = 0;
123
+ if (advisories.length) {
124
+ const worst = Math.max(0, ...advisories.map((a) => a.cvss ?? 0));
125
+ risk += worst >= 9 ? 70 : worst >= 7 ? 55 : 40;
126
+ flags.push(`${advisories.length + extraAdvisories} known vulnerabilit${advisories.length + extraAdvisories === 1 ? 'y' : 'ies'}${worst ? ` (worst CVSS ${worst})` : ''}`);
127
+ }
128
+ const deprecated = v?.isDeprecated ? v.deprecatedReason || 'deprecated' : def.isDeprecated ? def.deprecatedReason || 'deprecated' : null;
129
+ if (deprecated) {
130
+ risk += 30;
131
+ flags.push(`deprecated: ${deprecated.slice(0, 120)}`);
132
+ }
133
+ const lastRelease = def.publishedAt ?? null;
134
+ const ageDays = lastRelease ? (ctx.now().getTime() - Date.parse(lastRelease)) / DAY : null;
135
+ if (ageDays != null && ageDays > 730) {
136
+ risk += 20;
137
+ flags.push(`no release in ${Math.floor(ageDays / 365)} years`);
138
+ }
139
+ if (version && latest && major(version) < major(latest)) {
140
+ risk += 10;
141
+ flags.push(`${major(latest) - major(version)} major version${major(latest) - major(version) === 1 ? '' : 's'} behind (latest ${latest})`);
142
+ }
143
+ if (project?.scorecard != null && project.scorecard < 4) {
144
+ risk += 15;
145
+ flags.push(`weak OpenSSF Scorecard (${project.scorecard}/10)`);
146
+ }
147
+ if (project?.maintained === 0) {
148
+ risk += 15;
149
+ flags.push('Scorecard says not actively maintained');
150
+ }
151
+ const licenses = v?.licenses ?? [];
152
+ if (!licenses.length || licenses.every((l) => /^non-standard$/i.test(l))) {
153
+ risk += 5;
154
+ flags.push('no declared license');
155
+ }
156
+ else if (licenses.some((l) => COPYLEFT.test(l)))
157
+ flags.push(`strong copyleft license (${licenses.join(', ')})`);
158
+ if (d.dev)
159
+ risk = Math.round(risk * 0.6);
160
+ return { ecosystem: d.ecosystem, name: d.name, spec: d.spec, version, latest, latestReleased: lastRelease, dev: d.dev, licenses, deprecated, advisories, advisoryCount: advisories.length + extraAdvisories, project, flags, risk: clamp(risk, 0, 100) };
161
+ }
162
+ /** Audits up to `max` packages from a manifest (package.json, requirements.txt, or "npm:name@ver" items). */
163
+ export async function audit(ctx, manifestText, opts = {}) {
164
+ const { kind, deps } = parseManifest(manifestText);
165
+ const max = Math.max(1, Math.min(opts.max ?? 60, 150));
166
+ const todo = deps.slice(0, max);
167
+ const provenance = [];
168
+ const packages = [];
169
+ const skipped = deps.slice(max).map((d) => `${d.ecosystem}:${d.name} (over the ${max}-package limit)`);
170
+ // A small pool keeps deps.dev happy and still finishes a typical manifest in seconds.
171
+ let next = 0;
172
+ await Promise.all(Array.from({ length: Math.min(6, todo.length) }, async () => {
173
+ while (next < todo.length) {
174
+ const d = todo[next++];
175
+ try {
176
+ const r = await auditOne(ctx, d, provenance);
177
+ if (typeof r === 'string')
178
+ skipped.push(r);
179
+ else
180
+ packages.push(r);
181
+ }
182
+ catch (e) {
183
+ skipped.push(`${d.ecosystem}:${d.name} (${e.message})`);
184
+ }
185
+ }
186
+ }));
187
+ packages.sort((a, b) => b.risk - a.risk || a.name.localeCompare(b.name));
188
+ const summary = {
189
+ total: deps.length,
190
+ checked: packages.length,
191
+ vulnerable: packages.filter((p) => p.advisories.length).length,
192
+ advisories: packages.reduce((n, p) => n + p.advisoryCount, 0),
193
+ deprecated: packages.filter((p) => p.deprecated).length,
194
+ stale: packages.filter((p) => p.flags.some((f) => f.startsWith('no release'))).length,
195
+ weakScorecard: packages.filter((p) => p.project?.scorecard != null && p.project.scorecard < 4).length,
196
+ risky: packages.filter((p) => p.risk >= 40).length,
197
+ };
198
+ const nowIso = ctx.now().toISOString();
199
+ const signals = packages
200
+ .filter((p) => p.advisories.some((a) => (a.cvss ?? 0) >= 9))
201
+ .slice(0, 5)
202
+ .map((p) => ({
203
+ id: signalId('audit', p.ecosystem, p.name, p.version ?? '', nowIso.slice(0, 10)),
204
+ module: 'audit',
205
+ title: `Critical vulnerability in ${p.name}@${p.version}`,
206
+ score: clamp(p.risk, 60, 90),
207
+ evidence: p.advisories.slice(0, 3).map((a) => ({ source: 'deps.dev', text: `${a.aliases[0] ?? a.id}: ${a.title}${a.cvss ? ` (CVSS ${a.cvss})` : ''}`, url: a.url })),
208
+ createdAt: nowIso,
209
+ }));
210
+ return { module: 'audit', input: kind, generatedAt: nowIso, result: { manifest: kind, packages, summary, skipped }, signals, provenance };
211
+ }
@@ -0,0 +1,147 @@
1
+ /**
2
+ * BGP routing: who can reach what on the internet, and who is announcing address space that is not theirs.
3
+ * RIPEstat (no key): country prefix visibility, AS visibility and neighbours, and for an IP address the
4
+ * announcing network, RPKI validity, abuse contact and location.
5
+ * Cloudflare Radar (token): detected BGP origin hijacks and route leaks, plus the countries most targeted
6
+ * by DDoS attacks. A high-confidence hijack is how traffic gets rerouted to steal crypto or spy on it.
7
+ * A country-wide shutdown or a cut cable shows up as announced prefixes disappearing, which is independent
8
+ * evidence next to traffic-based outage detection.
9
+ */
10
+ import type { Ctx } from '../core/context.js';
11
+ import type { ModuleResult, Provenance, Signal } from '../core/types.js';
12
+ export interface CountryRouting {
13
+ country: string;
14
+ /** Visible IPv4 prefixes per hour over the window. */
15
+ series: {
16
+ time: string;
17
+ v4: number;
18
+ v6: number;
19
+ asns: number;
20
+ }[];
21
+ latest: {
22
+ v4: number;
23
+ v6: number;
24
+ asns: number;
25
+ } | null;
26
+ baseline: {
27
+ v4: number;
28
+ v6: number;
29
+ asns: number;
30
+ } | null;
31
+ /** Latest versus baseline median, e.g. -0.35 = 35% fewer prefixes visible. */
32
+ v4Change: number | null;
33
+ }
34
+ export interface AsnRouting {
35
+ asn: string;
36
+ name: string | null;
37
+ visibilityV4: number | null;
38
+ visibilityV6: number | null;
39
+ prefixesV4: number;
40
+ prefixesV6: number;
41
+ neighbours: number;
42
+ }
43
+ export interface IpRouting {
44
+ ip: string;
45
+ prefix: string | null;
46
+ announced: boolean;
47
+ origins: {
48
+ asn: string;
49
+ name: string;
50
+ }[];
51
+ /** RPKI validity of the announcement: valid, invalid (possible hijack or misconfiguration), unknown. */
52
+ rpki: string | null;
53
+ abuse: string[];
54
+ country: string | null;
55
+ city: string | null;
56
+ registry: string | null;
57
+ }
58
+ export interface Hijack {
59
+ id: number;
60
+ hijacker: string;
61
+ hijackerCountry: string | null;
62
+ victims: string[];
63
+ victimCountries: string[];
64
+ prefixes: string[];
65
+ confidence: number;
66
+ peers: number;
67
+ start: string;
68
+ end: string;
69
+ durationSec: number;
70
+ ongoing: boolean;
71
+ tags: string[];
72
+ /** Hijacker and every victim belong to the same organisation (sister AS numbers): almost never a real hijack. */
73
+ sameOrg: boolean;
74
+ url: string;
75
+ }
76
+ export interface RouteLeak {
77
+ id: number;
78
+ leaker: string;
79
+ countries: string[];
80
+ path: string[];
81
+ prefixes: number;
82
+ origins: number;
83
+ announcements: number;
84
+ start: string;
85
+ end: string;
86
+ finished: boolean;
87
+ url: string;
88
+ }
89
+ export interface BgpIncidents {
90
+ hijacks: Hijack[];
91
+ leaks: RouteLeak[];
92
+ /** Share of DDoS attack traffic by target country, last 24h (Cloudflare's network). */
93
+ attacks: {
94
+ layer7: {
95
+ country: string;
96
+ name: string;
97
+ share: number;
98
+ }[];
99
+ layer3: {
100
+ country: string;
101
+ name: string;
102
+ share: number;
103
+ }[];
104
+ } | null;
105
+ }
106
+ /** Repairs UTF-8 names that arrive double-encoded (mojibake) and drops soft hyphens and doubled spaces. */
107
+ export declare function cleanOrgName(name: string): string;
108
+ export declare function countryRouting(ctx: Ctx, cc: string, hours?: number): Promise<{
109
+ data: CountryRouting | null;
110
+ prov: Provenance;
111
+ }>;
112
+ export declare function asnRouting(ctx: Ctx, asnInput: string): Promise<{
113
+ data: AsnRouting | null;
114
+ prov: Provenance[];
115
+ }>;
116
+ export declare const isIp: (s: string) => boolean;
117
+ /** Who announces an IP address, whether RPKI says they may, who to report abuse to, and where it is. */
118
+ export declare function ipRouting(ctx: Ctx, ip: string): Promise<{
119
+ data: IpRouting | null;
120
+ prov: Provenance[];
121
+ }>;
122
+ /** Cloudflare Radar BGP hijacks and route leaks, optionally for one AS or country, plus DDoS target countries. */
123
+ export declare function bgpIncidents(ctx: Ctx, opts?: {
124
+ days?: number;
125
+ asn?: string;
126
+ country?: string;
127
+ minConfidence?: number;
128
+ }): Promise<{
129
+ data: BgpIncidents | null;
130
+ prov: Provenance[];
131
+ }>;
132
+ /**
133
+ * Only hijacks that are very likely real: Radar confidence 9+ and either seen by many peers, lasting an hour,
134
+ * or covering many prefixes. Most single-peer events are misconfigurations seen by one vantage point.
135
+ */
136
+ export declare function incidentSignals(inc: BgpIncidents, now: Date): Signal[];
137
+ export interface BgpResult {
138
+ country: CountryRouting | null;
139
+ asn: AsnRouting | null;
140
+ ip?: IpRouting | null;
141
+ incidents?: BgpIncidents | null;
142
+ }
143
+ /**
144
+ * `bgp('PK')` country routing, `bgp('AS15169')` a network, `bgp('8.8.8.8')` an address,
145
+ * `bgp('world')` (or empty) global hijacks, leaks and DDoS targets. Countries and networks include incidents involving them.
146
+ */
147
+ export declare function bgp(ctx: Ctx, resource: string, days?: number): Promise<ModuleResult<BgpResult>>;