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,219 @@
1
+ import { entityId } from '../core/graph.js';
2
+ import { clamp, median } from '../core/stats.js';
3
+ import { signalId } from '../core/text.js';
4
+ import { aircraftInfo, byHex, byRegistration, hexForRegistration, isHex, military, openskyState, } from '../sources/aircraft.js';
5
+ import { airportLabel, airports, nearestAirport } from '../sources/airports.js';
6
+ /** Ground traffic counts as "at" an airport within 8 km; low traffic "near" within 40 km; otherwise "over" within 150 km. */
7
+ export function locate(list, s) {
8
+ if (s.lat === null || s.lon === null)
9
+ return null;
10
+ const low = s.onGround || (s.altFt !== null && s.altFt < 5000);
11
+ const n = nearestAirport(list, s.lat, s.lon);
12
+ if (!n)
13
+ return null;
14
+ if (s.onGround && n.km <= 8)
15
+ return { airport: airportLabel(n.airport), ident: n.airport.ident, km: Math.round(n.km), relation: 'at' };
16
+ if (low && n.km <= 40)
17
+ return { airport: airportLabel(n.airport), ident: n.airport.ident, km: Math.round(n.km), relation: 'near' };
18
+ if (n.km <= 150)
19
+ return { airport: airportLabel(n.airport), ident: n.airport.ident, km: Math.round(n.km), relation: 'over' };
20
+ return null;
21
+ }
22
+ export function describeChange(prev, status, place) {
23
+ if (!prev)
24
+ return null;
25
+ const prevIdent = prev.place?.relation !== 'over' ? prev.place?.ident : undefined;
26
+ const nowIdent = place?.relation !== 'over' ? place?.ident : undefined;
27
+ if (status !== 'AIRBORNE' && prev.status !== 'AIRBORNE' && prevIdent && nowIdent && prevIdent !== nowIdent) {
28
+ return `moved from ${prev.place.airport} to ${place.airport}`;
29
+ }
30
+ if (status === 'AIRBORNE' && prev.status !== 'AIRBORNE')
31
+ return `took off${prev.place ? ` (last seen ${prev.place.relation} ${prev.place.airport})` : ''}`;
32
+ if (status !== 'AIRBORNE' && prev.status === 'AIRBORNE' && place && place.relation !== 'over')
33
+ return `landed ${place.relation} ${place.airport}`;
34
+ return null;
35
+ }
36
+ export async function track(ctx, queryInput) {
37
+ const query = queryInput.trim();
38
+ const provenance = [];
39
+ const nowIso = ctx.now().toISOString();
40
+ let hex = isHex(query) ? query.toLowerCase() : null;
41
+ let state = null;
42
+ if (!hex) {
43
+ const h = await hexForRegistration(ctx, query);
44
+ provenance.push(h.prov);
45
+ hex = h.data;
46
+ if (!hex) {
47
+ const byReg = await byRegistration(ctx, query);
48
+ provenance.push(byReg.prov);
49
+ state = byReg.data?.[0] ?? null;
50
+ hex = state?.hex ?? null;
51
+ }
52
+ }
53
+ const [info, live, list] = await Promise.all([
54
+ hex ? aircraftInfo(ctx, hex) : Promise.resolve(null),
55
+ hex && !state ? byHex(ctx, hex) : Promise.resolve(null),
56
+ airports(ctx),
57
+ ]);
58
+ if (info)
59
+ provenance.push(info.prov);
60
+ if (live)
61
+ provenance.push(live.prov);
62
+ provenance.push(list.prov);
63
+ state ??= live?.data?.[0] ?? null;
64
+ if (hex && !state) {
65
+ const os = await openskyState(ctx, hex);
66
+ provenance.push(os.prov);
67
+ state = os.data;
68
+ }
69
+ const status = !state || state.lat === null ? 'NOT_SEEN' : state.onGround ? 'ON_GROUND' : 'AIRBORNE';
70
+ const place = state && list.data ? locate(list.data, state) : null;
71
+ let previous = null;
72
+ let change = null;
73
+ const signals = [];
74
+ const infoData = info?.data ?? null;
75
+ if (hex) {
76
+ const name = infoData?.registration ?? state?.registration ?? hex;
77
+ const id = ctx.graph.upsert('aircraft', hex, {
78
+ registration: name,
79
+ ...(infoData?.type ? { type: infoData.type } : {}),
80
+ ...(infoData?.owner ? { owner: infoData.owner } : {}),
81
+ });
82
+ if (infoData?.owner)
83
+ ctx.graph.link(id, ctx.graph.upsert('company', infoData.owner), 'registered_to', 'hexdb');
84
+ const last = ctx.store.db
85
+ .prepare("SELECT payload, observed_at FROM observations WHERE entity_id = ? AND kind = 'position' ORDER BY observed_at DESC LIMIT 1")
86
+ .get(id);
87
+ if (last) {
88
+ const p = JSON.parse(last.payload);
89
+ previous = { status: p.status, place: p.place, at: new Date(last.observed_at).toISOString() };
90
+ }
91
+ change = describeChange(previous, status, place);
92
+ ctx.graph.observe(id, 'falcon', 'position', state?.altFt ?? null, state?.source ?? 'none', { status, place, lat: state?.lat, lon: state?.lon });
93
+ if (change) {
94
+ signals.push({
95
+ id: signalId('falcon', hex, change, nowIso.slice(0, 13)),
96
+ module: 'falcon',
97
+ title: `${name}${infoData?.owner ? ` (${infoData.owner})` : ''} ${change}`,
98
+ score: change.startsWith('moved') ? 70 : change.startsWith('landed') ? 60 : 50,
99
+ entity: id,
100
+ evidence: [
101
+ { source: state?.source ?? 'adsb', text: `${status}${place ? `, ${place.relation} ${place.airport} (${place.km} km)` : ''}` },
102
+ ...(previous ? [{ source: 'oculon-history', text: `previously ${previous.status}${previous.place ? ` ${previous.place.relation} ${previous.place.airport}` : ''} at ${previous.at}` }] : []),
103
+ ],
104
+ createdAt: nowIso,
105
+ });
106
+ signals.forEach((s) => ctx.graph.saveSignal(s));
107
+ }
108
+ }
109
+ return {
110
+ module: 'falcon',
111
+ input: query,
112
+ generatedAt: nowIso,
113
+ result: { query, hex, info: info?.data ?? null, state, status, place, previous, change },
114
+ signals,
115
+ provenance,
116
+ };
117
+ }
118
+ /** ICAO type designators with a role worth calling out. Airlifters are tracked but not treated as notable. */
119
+ export const ROLES = {
120
+ K35R: 'tanker',
121
+ K35E: 'tanker',
122
+ KC46: 'tanker',
123
+ A330: 'tanker/transport',
124
+ E3TF: 'AWACS',
125
+ E3CF: 'AWACS',
126
+ E737: 'AWACS',
127
+ E6: 'TACAMO',
128
+ R135: 'ISR',
129
+ E8: 'ISR',
130
+ U2: 'ISR',
131
+ Q4: 'ISR drone',
132
+ Q9: 'drone',
133
+ P8: 'maritime patrol',
134
+ P3: 'maritime patrol',
135
+ B52: 'bomber',
136
+ B1: 'bomber',
137
+ B2: 'bomber',
138
+ C17: 'airlifter',
139
+ C5M: 'airlifter',
140
+ C30J: 'airlifter',
141
+ A400: 'airlifter',
142
+ };
143
+ /** Countries large enough that one bucket would hide where activity is. */
144
+ const SPLIT_BY_REGION = new Set(['US', 'CA', 'AU', 'RU', 'CN', 'BR', 'IN']);
145
+ export async function mil(ctx) {
146
+ const provenance = [];
147
+ const nowIso = ctx.now().toISOString();
148
+ const nowMs = ctx.now().getTime();
149
+ const [ac, list] = await Promise.all([military(ctx), airports(ctx)]);
150
+ provenance.push(ac.prov, list.prov);
151
+ const large = list.data?.filter((a) => a.type === 'large_airport') ?? [];
152
+ const groups = new Map();
153
+ const positioned = (ac.data ?? []).filter((a) => a.lat !== null && a.lon !== null);
154
+ for (const a of positioned) {
155
+ const n = large.length ? nearestAirport(large, a.lat, a.lon) : null;
156
+ const key = n && n.km <= 500 ? (SPLIT_BY_REGION.has(n.airport.country) && n.airport.region ? n.airport.region : n.airport.country) : 'OCEAN';
157
+ const label = n && n.km <= 500 ? `${n.airport.city || n.airport.name}, ${n.airport.country}` : n ? `open water, ~${Math.round(n.km)} km from ${n.airport.city || n.airport.name}` : 'unknown';
158
+ const g = groups.get(key) ?? { label: new Map(), items: [] };
159
+ g.items.push(a);
160
+ g.label.set(label, (g.label.get(label) ?? 0) + 1);
161
+ groups.set(key, g);
162
+ }
163
+ let firstRuns = false;
164
+ const regions = [...groups].map(([key, g]) => {
165
+ const id = ctx.graph.upsert('event', `mil-region:${key}`);
166
+ // Ignore observations from the last 20 minutes so a quick re-run does not become its own baseline.
167
+ const hist = ctx.graph
168
+ .history(id, 'mil_count', 200)
169
+ .filter((h) => nowMs - h.observedAt > 20 * 60_000)
170
+ .map((h) => h.value ?? 0);
171
+ if (hist.length < 3)
172
+ firstRuns = true;
173
+ ctx.graph.observe(id, 'falcon', 'mil_count', g.items.length, 'adsb.lol');
174
+ const base = hist.length >= 3 ? median(hist) : null;
175
+ const notable = g.items
176
+ .filter((a) => a.type && ROLES[a.type] && ROLES[a.type] !== 'airlifter')
177
+ .map((a) => ({ role: ROLES[a.type], type: a.type, registration: a.registration, callsign: a.callsign, hex: a.hex }));
178
+ const label = [...g.label].sort((x, y) => y[1] - x[1])[0]?.[0] ?? key;
179
+ return { key, label, count: g.items.length, notable, baselineMedian: base, ratio: base ? g.items.length / Math.max(1, base) : null };
180
+ });
181
+ regions.sort((a, b) => b.notable.length - a.notable.length || b.count - a.count);
182
+ const signals = [];
183
+ for (const r of regions) {
184
+ if (r.baselineMedian !== null && r.count >= Math.max(5, 2 * r.baselineMedian)) {
185
+ signals.push({
186
+ id: signalId('falcon', 'mil-surge', r.key, nowIso.slice(0, 13)),
187
+ module: 'falcon',
188
+ title: `Military air traffic surge near ${r.label}: ${r.count} aircraft (usual ~${Math.round(r.baselineMedian)})`,
189
+ score: clamp(Math.round(55 + 10 * Math.log2(r.ratio)), 0, 90),
190
+ entity: entityId('event', `mil-region:${r.key}`),
191
+ evidence: [{ source: 'adsb.lol', text: `${r.count} military-flagged aircraft vs median ${r.baselineMedian} over previous scans`, value: r.count }],
192
+ createdAt: nowIso,
193
+ });
194
+ }
195
+ if (r.notable.length >= 2) {
196
+ const byRole = new Map();
197
+ r.notable.forEach((n) => byRole.set(n.role, (byRole.get(n.role) ?? 0) + 1));
198
+ signals.push({
199
+ id: signalId('falcon', 'mil-notable', r.key, nowIso.slice(0, 13)),
200
+ module: 'falcon',
201
+ title: `${[...byRole].map(([role, n]) => `${n}x ${role}`).join(', ')} active near ${r.label}`,
202
+ score: clamp(40 + r.notable.length * 8 + (byRole.size - 1) * 5, 0, 85),
203
+ entity: entityId('event', `mil-region:${r.key}`),
204
+ evidence: r.notable.map((n) => ({ source: 'adsb.lol', text: `${n.type} (${n.role}) ${n.registration ?? ''} ${n.callsign ?? ''}`.replace(/\s+/g, ' ').trim(), url: `https://globe.adsb.lol/?icao=${n.hex}` })),
205
+ createdAt: nowIso,
206
+ });
207
+ }
208
+ }
209
+ signals.sort((a, b) => b.score - a.score);
210
+ signals.forEach((s) => ctx.graph.saveSignal(s));
211
+ return {
212
+ module: 'falcon',
213
+ input: 'mil',
214
+ generatedAt: nowIso,
215
+ result: { total: ac.data?.length ?? 0, withPosition: positioned.length, regions, firstRuns },
216
+ signals,
217
+ provenance,
218
+ };
219
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Feedback: alerts carry "Useful" / "Noise" buttons. Votes are stored per signal, and each module's alert bar
3
+ * moves with them: a module people keep calling noise needs a higher score to alert, a useful one a lower score.
4
+ * The shift only starts after 3 votes and is capped, so a couple of clicks cannot silence a module.
5
+ */
6
+ import type { Ctx } from '../core/context.js';
7
+ export type Verdict = 'useful' | 'noise';
8
+ export declare function ensureFeedback(ctx: Ctx): void;
9
+ export declare function recordFeedback(ctx: Ctx, signalId: string, verdict: Verdict, voter: string): {
10
+ module: string;
11
+ title: string;
12
+ } | null;
13
+ export interface ModuleFeedback {
14
+ module: string;
15
+ useful: number;
16
+ noise: number;
17
+ /** Points added to (or taken from) the alert bar for this module. */
18
+ shift: number;
19
+ }
20
+ /** +3 per net noise vote, -2 per net useful vote, from the third vote on, capped to [-10, +20]. */
21
+ export declare function shiftFor(useful: number, noise: number): number;
22
+ export declare function feedbackStats(ctx: Ctx): ModuleFeedback[];
23
+ /** Alert bar for a module given the base bar. */
24
+ export declare function alertBar(ctx: Ctx, module: string, base: number): number;
@@ -0,0 +1,37 @@
1
+ export function ensureFeedback(ctx) {
2
+ ctx.store.db.exec(`CREATE TABLE IF NOT EXISTS feedback (
3
+ signal_id TEXT NOT NULL,
4
+ voter TEXT NOT NULL,
5
+ module TEXT NOT NULL,
6
+ verdict TEXT NOT NULL,
7
+ created_at INTEGER NOT NULL,
8
+ PRIMARY KEY (signal_id, voter)
9
+ )`);
10
+ }
11
+ export function recordFeedback(ctx, signalId, verdict, voter) {
12
+ ensureFeedback(ctx);
13
+ const s = ctx.store.db.prepare('SELECT module, title FROM signals WHERE id = ?').get(signalId);
14
+ if (!s)
15
+ return null;
16
+ ctx.store.db
17
+ .prepare('INSERT INTO feedback (signal_id, voter, module, verdict, created_at) VALUES (?, ?, ?, ?, ?) ON CONFLICT(signal_id, voter) DO UPDATE SET verdict = excluded.verdict, created_at = excluded.created_at')
18
+ .run(signalId, voter, s.module, verdict, ctx.now().getTime());
19
+ return s;
20
+ }
21
+ /** +3 per net noise vote, -2 per net useful vote, from the third vote on, capped to [-10, +20]. */
22
+ export function shiftFor(useful, noise) {
23
+ if (useful + noise < 3)
24
+ return 0;
25
+ const net = noise - useful;
26
+ return Math.max(-10, Math.min(20, net > 0 ? net * 3 : net * 2));
27
+ }
28
+ export function feedbackStats(ctx) {
29
+ ensureFeedback(ctx);
30
+ const rows = ctx.store.db.prepare("SELECT module, SUM(verdict = 'useful') AS useful, SUM(verdict = 'noise') AS noise FROM feedback GROUP BY module ORDER BY module").all();
31
+ return rows.map((r) => ({ module: r.module, useful: Number(r.useful), noise: Number(r.noise), shift: shiftFor(Number(r.useful), Number(r.noise)) }));
32
+ }
33
+ /** Alert bar for a module given the base bar. */
34
+ export function alertBar(ctx, module, base) {
35
+ const m = feedbackStats(ctx).find((x) => x.module === module);
36
+ return base + (m?.shift ?? 0);
37
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Geofences: named boxes on the map. Each check looks inside every fence for military aircraft, military
3
+ * vessels, earthquakes and natural events, and reports only what is NEW since the previous check.
4
+ * The first check of a fence records a baseline.
5
+ */
6
+ import type { Ctx } from '../core/context.js';
7
+ import type { Provenance, Signal } from '../core/types.js';
8
+ export declare const FENCE_KINDS: readonly ['air', 'sea', 'quake', 'events'];
9
+ export type FenceKind = (typeof FENCE_KINDS)[number];
10
+ export interface Fence {
11
+ id: number;
12
+ name: string;
13
+ south: number;
14
+ west: number;
15
+ north: number;
16
+ east: number;
17
+ kinds: FenceKind[];
18
+ createdAt: string;
19
+ lastRun: string | null;
20
+ lastState: FenceState | null;
21
+ }
22
+ export interface FenceState {
23
+ milAircraft: Record<string, string>;
24
+ milVessels: Record<string, string>;
25
+ quakes: Record<string, string>;
26
+ events: Record<string, string>;
27
+ }
28
+ export declare function validBox(s: number, w: number, n: number, e: number): boolean;
29
+ export declare function addFence(ctx: Ctx, name: string, box: [number, number, number, number], kinds?: string[]): Fence;
30
+ /** Box of `radiusKm` around a geocoded place. */
31
+ export declare function boxAround(ctx: Ctx, place: string, radiusKm?: number): Promise<[number, number, number, number]>;
32
+ export declare function listFences(ctx: Ctx): Fence[];
33
+ export declare function removeFence(ctx: Ctx, id: number): boolean;
34
+ export interface FenceCheck {
35
+ fence: Fence;
36
+ baseline: boolean;
37
+ changes: string[];
38
+ counts: {
39
+ milAircraft: number;
40
+ milVessels: number;
41
+ quakes: number;
42
+ events: number;
43
+ };
44
+ }
45
+ /** Check every fence once. Quakes and natural events are fetched once and shared across fences. */
46
+ export declare function checkFences(ctx: Ctx, opts?: {
47
+ aisSeconds?: number;
48
+ }): Promise<{
49
+ checks: FenceCheck[];
50
+ signals: Signal[];
51
+ provenance: Provenance[];
52
+ }>;
@@ -0,0 +1,128 @@
1
+ import { signalId } from '../core/text.js';
2
+ import { collect, shipType } from '../sources/ais.js';
3
+ import { aroundPoint } from '../sources/aircraft.js';
4
+ import { eonetEvents, geocode } from '../sources/earth.js';
5
+ import { recentQuakes } from '../sources/usgs.js';
6
+ import { ROLES } from './falcon.js';
7
+ export const FENCE_KINDS = ['air', 'sea', 'quake', 'events'];
8
+ const toFence = (r) => ({
9
+ id: r.id,
10
+ name: r.name,
11
+ south: r.south,
12
+ west: r.west,
13
+ north: r.north,
14
+ east: r.east,
15
+ kinds: JSON.parse(r.kinds),
16
+ createdAt: new Date(r.created_at).toISOString(),
17
+ lastRun: r.last_run ? new Date(r.last_run).toISOString() : null,
18
+ lastState: r.last_state ? JSON.parse(r.last_state) : null,
19
+ });
20
+ export function validBox(s, w, n, e) {
21
+ return [s, w, n, e].every(Number.isFinite) && s >= -90 && n <= 90 && s < n && w >= -180 && e <= 180 && w < e && n - s <= 30 && e - w <= 30;
22
+ }
23
+ export function addFence(ctx, name, box, kinds = [...FENCE_KINDS]) {
24
+ const [s, w, n, e] = box;
25
+ if (!validBox(s, w, n, e))
26
+ throw new Error('invalid box: need south<north, west<east, at most 30 degrees per side');
27
+ const k = kinds.filter((x) => FENCE_KINDS.includes(x));
28
+ if (!k.length)
29
+ throw new Error(`kinds must include one of: ${FENCE_KINDS.join(', ')}`);
30
+ const clean = name.trim().slice(0, 60) || 'fence';
31
+ const id = Number(ctx.store.db.prepare('INSERT INTO fences (name, south, west, north, east, kinds, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)').run(clean, s, w, n, e, JSON.stringify(k), ctx.now().getTime()).lastInsertRowid);
32
+ return listFences(ctx).find((f) => f.id === id);
33
+ }
34
+ /** Box of `radiusKm` around a geocoded place. */
35
+ export async function boxAround(ctx, place, radiusKm = 100) {
36
+ const g = await geocode(ctx, place);
37
+ const p = g.data?.[0];
38
+ if (!p)
39
+ throw new Error(`place not found: ${place}`);
40
+ const dLat = radiusKm / 111;
41
+ const dLon = radiusKm / (111 * Math.max(0.2, Math.cos((p.lat * Math.PI) / 180)));
42
+ return [p.lat - dLat, p.lon - dLon, p.lat + dLat, p.lon + dLon].map((v) => Math.round(v * 1000) / 1000);
43
+ }
44
+ export function listFences(ctx) {
45
+ return ctx.store.db.prepare('SELECT * FROM fences ORDER BY id').all().map(toFence);
46
+ }
47
+ export function removeFence(ctx, id) {
48
+ return ctx.store.db.prepare('DELETE FROM fences WHERE id = ?').run(id).changes > 0;
49
+ }
50
+ const inside = (f, lat, lon) => lat != null && lon != null && lat >= f.south && lat <= f.north && lon >= f.west && lon <= f.east;
51
+ /** Check every fence once. Quakes and natural events are fetched once and shared across fences. */
52
+ export async function checkFences(ctx, opts = {}) {
53
+ const fences = listFences(ctx);
54
+ const provenance = [];
55
+ if (!fences.length)
56
+ return { checks: [], signals: [], provenance };
57
+ const needQuake = fences.some((f) => f.kinds.includes('quake'));
58
+ const needEvents = fences.some((f) => f.kinds.includes('events'));
59
+ const [quakes, events] = await Promise.all([needQuake ? recentQuakes(ctx) : Promise.resolve(null), needEvents ? eonetEvents(ctx, 7) : Promise.resolve(null)]);
60
+ if (quakes)
61
+ provenance.push(quakes.prov);
62
+ if (events)
63
+ provenance.push(events.prov);
64
+ const checks = [];
65
+ const signals = [];
66
+ const nowIso = ctx.now().toISOString();
67
+ for (const f of fences) {
68
+ const prev = f.lastState;
69
+ const state = { milAircraft: {}, milVessels: {}, quakes: {}, events: {} };
70
+ if (f.kinds.includes('air')) {
71
+ const lat = (f.south + f.north) / 2;
72
+ const lon = (f.west + f.east) / 2;
73
+ const halfDiagKm = Math.hypot((f.north - f.south) * 111, (f.east - f.west) * 111 * Math.cos((lat * Math.PI) / 180)) / 2;
74
+ const r = await aroundPoint(ctx, lat, lon, halfDiagKm / 1.852);
75
+ provenance.push(r.prov);
76
+ for (const a of r.data ?? [])
77
+ if (a.military && inside(f, a.lat, a.lon))
78
+ state.milAircraft[a.hex] = `${a.type ?? '?'}${a.type && ROLES[a.type] ? ` (${ROLES[a.type]})` : ''} ${a.callsign ?? a.registration ?? a.hex}`.trim();
79
+ }
80
+ if (f.kinds.includes('sea')) {
81
+ const c = await collect([
82
+ [
83
+ [f.south, f.west],
84
+ [f.north, f.east],
85
+ ],
86
+ ], opts.aisSeconds ?? 20);
87
+ provenance.push(c.prov);
88
+ for (const v of c.vessels)
89
+ if (shipType(v.typeCode) === 'military')
90
+ state.milVessels[String(v.mmsi)] = v.name ?? String(v.mmsi);
91
+ }
92
+ if (f.kinds.includes('quake'))
93
+ for (const q of (quakes?.data ?? []).filter((x) => inside(f, x.lat, x.lon)))
94
+ state.quakes[q.id] = `M${q.mag.toFixed(1)} ${q.place}`;
95
+ if (f.kinds.includes('events'))
96
+ for (const e of (events?.data ?? []).filter((x) => inside(f, x.lat, x.lon)))
97
+ state.events[e.id] = e.title;
98
+ const changes = [];
99
+ if (prev) {
100
+ const fresh = (now, before) => Object.entries(now).filter(([k]) => !(k in before)).map(([, v]) => v);
101
+ for (const v of fresh(state.milAircraft, prev.milAircraft))
102
+ changes.push(`military aircraft entered: ${v}`);
103
+ for (const v of fresh(state.milVessels, prev.milVessels))
104
+ changes.push(`military vessel appeared: ${v}`);
105
+ for (const v of fresh(state.quakes, prev.quakes))
106
+ changes.push(`earthquake: ${v}`);
107
+ for (const v of fresh(state.events, prev.events))
108
+ changes.push(`natural event: ${v}`);
109
+ }
110
+ // Aircraft come and go; keep a 6-hour memory so a plane circling in and out is not reported every check.
111
+ const keep = prev && f.lastRun && Date.now() - Date.parse(f.lastRun) < 6 * 3_600_000 ? { ...prev.milAircraft, ...state.milAircraft } : state.milAircraft;
112
+ const stored = { ...state, milAircraft: keep, milVessels: { ...(prev?.milVessels ?? {}), ...state.milVessels } };
113
+ ctx.store.db.prepare('UPDATE fences SET last_run = ?, last_state = ? WHERE id = ?').run(ctx.now().getTime(), JSON.stringify(stored), f.id);
114
+ checks.push({ fence: f, baseline: !prev, changes, counts: { milAircraft: Object.keys(state.milAircraft).length, milVessels: Object.keys(state.milVessels).length, quakes: Object.keys(state.quakes).length, events: Object.keys(state.events).length } });
115
+ if (changes.length) {
116
+ signals.push({
117
+ id: signalId('fence', String(f.id), changes.join('|')),
118
+ module: 'fence',
119
+ title: `Fence ${f.name}: ${changes[0]}${changes.length > 1 ? ` (+${changes.length - 1} more)` : ''}`,
120
+ score: Math.min(90, (changes.some((c) => /military/.test(c)) ? 65 : 55) + (changes.length - 1) * 5),
121
+ evidence: changes.map((c) => ({ source: `fence:${f.name}`, text: c })),
122
+ createdAt: nowIso,
123
+ });
124
+ }
125
+ }
126
+ signals.forEach((s) => ctx.graph.saveSignal(s));
127
+ return { checks, signals, provenance };
128
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Ferret: finds footprints of things that are not announced yet.
3
+ * New hostnames in Certificate Transparency logs, pages that only recently appeared in the
4
+ * Wayback Machine, hosts seen in urlscan.io scans, freshly created public GitHub repos, and Google Safe Browsing
5
+ * verdicts on everything new.
6
+ */
7
+ import { type Ctx } from '../core/context.js';
8
+ import type { ModuleResult } from '../core/types.js';
9
+ import { type CertEntry } from '../sources/certs.js';
10
+ export type FindingKind = 'subdomain' | 'page' | 'repo';
11
+ export interface Finding {
12
+ kind: FindingKind;
13
+ value: string;
14
+ firstSeen: string;
15
+ source: string;
16
+ url: string;
17
+ score: number;
18
+ reasons: string[];
19
+ /** True only when a previous scan of this domain exists and did not contain this item. */
20
+ newSinceLastScan: boolean;
21
+ }
22
+ export interface FerretResult {
23
+ domain: string;
24
+ /** URLs Google Safe Browsing flags among the domain and new findings. */
25
+ flagged: {
26
+ url: string;
27
+ threat: string;
28
+ }[];
29
+ windowDays: number;
30
+ firstScan: boolean;
31
+ findings: Finding[];
32
+ counts: Record<FindingKind, number>;
33
+ }
34
+ export interface FerretOptions {
35
+ days?: number;
36
+ /** GitHub org/user to check. Defaults to the domain's first label (openai.com -> openai). */
37
+ org?: string | false;
38
+ limit?: number;
39
+ }
40
+ export declare function scoreName(kind: FindingKind, value: string, firstSeenMs: number, nowMs: number, windowDays: number): {
41
+ score: number;
42
+ reasons: string[];
43
+ };
44
+ export declare function isNoiseHost(host: string): boolean;
45
+ /** First time each hostname under `domain` appeared on any certificate. */
46
+ export declare function firstSeenHosts(entries: CertEntry[], domain: string): Map<string, number>;
47
+ export declare function ferret(ctx: Ctx, domainInput: string, opts?: FerretOptions): Promise<ModuleResult<FerretResult>>;