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.
- package/LICENSE +21 -0
- package/README.md +344 -2
- package/dist/agent.d.ts +47 -0
- package/dist/agent.js +104 -0
- package/dist/cases.d.ts +68 -0
- package/dist/cases.js +158 -0
- package/dist/cli/main.d.ts +12 -0
- package/dist/cli/main.js +1999 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +15 -0
- package/dist/core/context.d.ts +19 -0
- package/dist/core/context.js +19 -0
- package/dist/core/features.d.ts +22 -0
- package/dist/core/features.js +28 -0
- package/dist/core/graph.d.ts +38 -0
- package/dist/core/graph.js +81 -0
- package/dist/core/http.d.ts +42 -0
- package/dist/core/http.js +266 -0
- package/dist/core/keys.d.ts +8 -0
- package/dist/core/keys.js +22 -0
- package/dist/core/llm.d.ts +93 -0
- package/dist/core/llm.js +180 -0
- package/dist/core/merkle.d.ts +15 -0
- package/dist/core/merkle.js +46 -0
- package/dist/core/paths.d.ts +2 -0
- package/dist/core/paths.js +6 -0
- package/dist/core/png.d.ts +17 -0
- package/dist/core/png.js +101 -0
- package/dist/core/quota.d.ts +15 -0
- package/dist/core/quota.js +90 -0
- package/dist/core/stats.d.ts +24 -0
- package/dist/core/stats.js +67 -0
- package/dist/core/store.d.ts +20 -0
- package/dist/core/store.js +213 -0
- package/dist/core/text.d.ts +9 -0
- package/dist/core/text.js +30 -0
- package/dist/core/types.d.ts +38 -0
- package/dist/core/types.js +1 -0
- package/dist/index.d.ts +342 -0
- package/dist/index.js +495 -0
- package/dist/live.d.ts +53 -0
- package/dist/live.js +236 -0
- package/dist/mcp.d.ts +43 -0
- package/dist/mcp.js +651 -0
- package/dist/modules/airport.d.ts +60 -0
- package/dist/modules/airport.js +111 -0
- package/dist/modules/audit.d.ts +73 -0
- package/dist/modules/audit.js +211 -0
- package/dist/modules/bgp.d.ts +147 -0
- package/dist/modules/bgp.js +206 -0
- package/dist/modules/blackout.d.ts +41 -0
- package/dist/modules/blackout.js +98 -0
- package/dist/modules/brief.d.ts +26 -0
- package/dist/modules/brief.js +99 -0
- package/dist/modules/calendar.d.ts +27 -0
- package/dist/modules/calendar.js +145 -0
- package/dist/modules/calibrate.d.ts +46 -0
- package/dist/modules/calibrate.js +92 -0
- package/dist/modules/cloud.d.ts +32 -0
- package/dist/modules/cloud.js +94 -0
- package/dist/modules/condor.d.ts +66 -0
- package/dist/modules/condor.js +214 -0
- package/dist/modules/connect.d.ts +47 -0
- package/dist/modules/connect.js +114 -0
- package/dist/modules/contradictions.d.ts +27 -0
- package/dist/modules/contradictions.js +76 -0
- package/dist/modules/country.d.ts +82 -0
- package/dist/modules/country.js +136 -0
- package/dist/modules/cricket.d.ts +34 -0
- package/dist/modules/cricket.js +166 -0
- package/dist/modules/darkships.d.ts +219 -0
- package/dist/modules/darkships.js +400 -0
- package/dist/modules/defi.d.ts +237 -0
- package/dist/modules/defi.js +512 -0
- package/dist/modules/emailsec.d.ts +47 -0
- package/dist/modules/emailsec.js +146 -0
- package/dist/modules/exposure.d.ts +43 -0
- package/dist/modules/exposure.js +89 -0
- package/dist/modules/factcheck.d.ts +39 -0
- package/dist/modules/factcheck.js +127 -0
- package/dist/modules/falcon.d.ts +58 -0
- package/dist/modules/falcon.js +219 -0
- package/dist/modules/feedback.d.ts +24 -0
- package/dist/modules/feedback.js +37 -0
- package/dist/modules/fence.d.ts +52 -0
- package/dist/modules/fence.js +128 -0
- package/dist/modules/ferret.d.ts +47 -0
- package/dist/modules/ferret.js +220 -0
- package/dist/modules/filings.d.ts +86 -0
- package/dist/modules/filings.js +166 -0
- package/dist/modules/fires.d.ts +56 -0
- package/dist/modules/fires.js +150 -0
- package/dist/modules/hazards.d.ts +37 -0
- package/dist/modules/hazards.js +83 -0
- package/dist/modules/health.d.ts +24 -0
- package/dist/modules/health.js +82 -0
- package/dist/modules/heron.d.ts +68 -0
- package/dist/modules/heron.js +184 -0
- package/dist/modules/hound.d.ts +100 -0
- package/dist/modules/hound.js +301 -0
- package/dist/modules/impact.d.ts +39 -0
- package/dist/modules/impact.js +63 -0
- package/dist/modules/launches.d.ts +24 -0
- package/dist/modules/launches.js +61 -0
- package/dist/modules/listen.d.ts +48 -0
- package/dist/modules/listen.js +125 -0
- package/dist/modules/lynx.d.ts +43 -0
- package/dist/modules/lynx.js +127 -0
- package/dist/modules/magpie.d.ts +70 -0
- package/dist/modules/magpie.js +174 -0
- package/dist/modules/meerkat.d.ts +42 -0
- package/dist/modules/meerkat.js +293 -0
- package/dist/modules/monitor.d.ts +27 -0
- package/dist/modules/monitor.js +105 -0
- package/dist/modules/narratives.d.ts +33 -0
- package/dist/modules/narratives.js +136 -0
- package/dist/modules/owl.d.ts +71 -0
- package/dist/modules/owl.js +290 -0
- package/dist/modules/papers.d.ts +46 -0
- package/dist/modules/papers.js +135 -0
- package/dist/modules/personal.d.ts +54 -0
- package/dist/modules/personal.js +153 -0
- package/dist/modules/pulse.d.ts +19 -0
- package/dist/modules/pulse.js +59 -0
- package/dist/modules/raven.d.ts +80 -0
- package/dist/modules/raven.js +147 -0
- package/dist/modules/recall.d.ts +44 -0
- package/dist/modules/recall.js +123 -0
- package/dist/modules/regs.d.ts +88 -0
- package/dist/modules/regs.js +142 -0
- package/dist/modules/rewind.d.ts +22 -0
- package/dist/modules/rewind.js +68 -0
- package/dist/modules/sanctions.d.ts +62 -0
- package/dist/modules/sanctions.js +173 -0
- package/dist/modules/scam.d.ts +43 -0
- package/dist/modules/scam.js +111 -0
- package/dist/modules/scoop.d.ts +31 -0
- package/dist/modules/scoop.js +74 -0
- package/dist/modules/ships.d.ts +33 -0
- package/dist/modules/ships.js +113 -0
- package/dist/modules/sky.d.ts +47 -0
- package/dist/modules/sky.js +183 -0
- package/dist/modules/squawk.d.ts +46 -0
- package/dist/modules/squawk.js +106 -0
- package/dist/modules/tortoise.d.ts +40 -0
- package/dist/modules/tortoise.js +104 -0
- package/dist/modules/travel.d.ts +94 -0
- package/dist/modules/travel.js +241 -0
- package/dist/modules/urlcheck.d.ts +63 -0
- package/dist/modules/urlcheck.js +223 -0
- package/dist/modules/vulns.d.ts +142 -0
- package/dist/modules/vulns.js +276 -0
- package/dist/plugins.d.ts +41 -0
- package/dist/plugins.js +70 -0
- package/dist/report.d.ts +12 -0
- package/dist/report.js +90 -0
- package/dist/scheduler.d.ts +22 -0
- package/dist/scheduler.js +139 -0
- package/dist/sources/aircraft.d.ts +76 -0
- package/dist/sources/aircraft.js +107 -0
- package/dist/sources/airports.d.ts +28 -0
- package/dist/sources/airports.js +100 -0
- package/dist/sources/ais.d.ts +32 -0
- package/dist/sources/ais.js +111 -0
- package/dist/sources/apify.d.ts +28 -0
- package/dist/sources/apify.js +80 -0
- package/dist/sources/arxiv.d.ts +13 -0
- package/dist/sources/arxiv.js +27 -0
- package/dist/sources/certs.d.ts +12 -0
- package/dist/sources/certs.js +23 -0
- package/dist/sources/corp.d.ts +46 -0
- package/dist/sources/corp.js +60 -0
- package/dist/sources/earth.d.ts +39 -0
- package/dist/sources/earth.js +76 -0
- package/dist/sources/fda.d.ts +77 -0
- package/dist/sources/fda.js +121 -0
- package/dist/sources/finance.d.ts +181 -0
- package/dist/sources/finance.js +270 -0
- package/dist/sources/gdelt.d.ts +19 -0
- package/dist/sources/gdelt.js +33 -0
- package/dist/sources/github.d.ts +17 -0
- package/dist/sources/github.js +33 -0
- package/dist/sources/hackernews.d.ts +20 -0
- package/dist/sources/hackernews.js +37 -0
- package/dist/sources/labels.d.ts +21 -0
- package/dist/sources/labels.js +87 -0
- package/dist/sources/launch.d.ts +16 -0
- package/dist/sources/launch.js +41 -0
- package/dist/sources/ofac.d.ts +29 -0
- package/dist/sources/ofac.js +86 -0
- package/dist/sources/onchain.d.ts +77 -0
- package/dist/sources/onchain.js +189 -0
- package/dist/sources/opentimestamps.d.ts +44 -0
- package/dist/sources/opentimestamps.js +131 -0
- package/dist/sources/polymarket.d.ts +36 -0
- package/dist/sources/polymarket.js +70 -0
- package/dist/sources/predict.d.ts +18 -0
- package/dist/sources/predict.js +59 -0
- package/dist/sources/press.d.ts +30 -0
- package/dist/sources/press.js +111 -0
- package/dist/sources/resend.d.ts +14 -0
- package/dist/sources/resend.js +29 -0
- package/dist/sources/robinhood.d.ts +109 -0
- package/dist/sources/robinhood.js +129 -0
- package/dist/sources/sec.d.ts +67 -0
- package/dist/sources/sec.js +129 -0
- package/dist/sources/sentinel.d.ts +13 -0
- package/dist/sources/sentinel.js +63 -0
- package/dist/sources/signatures.d.ts +14 -0
- package/dist/sources/signatures.js +103 -0
- package/dist/sources/social.d.ts +22 -0
- package/dist/sources/social.js +56 -0
- package/dist/sources/space.d.ts +160 -0
- package/dist/sources/space.js +230 -0
- package/dist/sources/usgs.d.ts +17 -0
- package/dist/sources/usgs.js +24 -0
- package/dist/sources/wayback.d.ts +10 -0
- package/dist/sources/wayback.js +28 -0
- package/dist/sources/websec.d.ts +19 -0
- package/dist/sources/websec.js +40 -0
- package/dist/sources/wikidata.d.ts +11 -0
- package/dist/sources/wikidata.js +30 -0
- package/dist/sources/wikimedia.d.ts +28 -0
- package/dist/sources/wikimedia.js +52 -0
- package/dist/telegram.d.ts +104 -0
- package/dist/telegram.js +927 -0
- package/dist/web/assets/favicon-32.png +0 -0
- package/dist/web/assets/fx.js +178 -0
- package/dist/web/assets/icon-192.png +0 -0
- package/dist/web/assets/icon-512.png +0 -0
- package/dist/web/assets/icon-maskable-512.png +0 -0
- package/dist/web/assets/night-americas.jpg +0 -0
- package/dist/web/assets/night-emea.jpg +0 -0
- package/dist/web/assets/og.png +0 -0
- package/dist/web/assets/redsea-bm.jpg +0 -0
- package/dist/web/docs.html +263 -0
- package/dist/web/index.html +1828 -0
- package/dist/web/insights.d.ts +100 -0
- package/dist/web/insights.js +134 -0
- package/dist/web/landing.html +1143 -0
- package/dist/web/legal.html +176 -0
- package/dist/web/manifest.webmanifest +20 -0
- package/dist/web/mcp.html +104 -0
- package/dist/web/mcphttp.d.ts +10 -0
- package/dist/web/mcphttp.js +67 -0
- package/dist/web/openapi.d.ts +1 -0
- package/dist/web/openapi.js +51 -0
- package/dist/web/public.d.ts +45 -0
- package/dist/web/public.js +135 -0
- package/dist/web/server.d.ts +69 -0
- package/dist/web/server.js +750 -0
- package/dist/web/share.d.ts +35 -0
- package/dist/web/share.js +132 -0
- package/dist/web/sw.js +28 -0
- package/package.json +60 -4
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hound: builds a dossier on one entity (company, person, project) from every public trail Oculon can reach,
|
|
3
|
+
* merges it into one timeline, links it into the entity graph, and raises signals when several trails move at once.
|
|
4
|
+
*
|
|
5
|
+
* Trails: Wikipedia, Hacker News, GDELT, GNews, The Guardian, NYT, web search (Tavily/Exa), Polymarket, GitHub,
|
|
6
|
+
* SEC EDGAR (filings, decoded 8-K items), Finnhub (quote, profile, insiders, company news, analyst recommendations,
|
|
7
|
+
* insider sentiment, peers, key metrics, earnings surprises; with deep: lobbying, federal contracts, visa filings,
|
|
8
|
+
* patents), openFDA recalls and ClinicalTrials.gov (health and food companies only), Adzuna (hiring), CourtListener (federal dockets),
|
|
9
|
+
* Companies House (UK registry), Brandfetch, YouTube, Bluesky. Sources without a key are skipped and labeled.
|
|
10
|
+
*/
|
|
11
|
+
import { type Ctx } from '../core/context.js';
|
|
12
|
+
import type { ModuleResult } from '../core/types.js';
|
|
13
|
+
import { type Brand, type CourtCase, type Hiring, type UkCompany } from '../sources/corp.js';
|
|
14
|
+
import { type FirmRecalls, type SponsorTrials } from '../sources/fda.js';
|
|
15
|
+
import { type CompanyProfile, type EarningsSurprise, type GovContracts, type Insider, type InsiderSentimentMonth, type KeyMetrics, type Lobbying, type NewsItem, type Patents, type Quote, type Recommendation, type VisaFilings } from '../sources/finance.js';
|
|
16
|
+
import { type CorporateEvent } from './filings.js';
|
|
17
|
+
import { type Repo } from '../sources/github.js';
|
|
18
|
+
import { type HnStory } from '../sources/hackernews.js';
|
|
19
|
+
import { type Market } from '../sources/polymarket.js';
|
|
20
|
+
import { type WebResult } from '../sources/press.js';
|
|
21
|
+
import { type Company, type Filing } from '../sources/sec.js';
|
|
22
|
+
import { type Post, type Video } from '../sources/social.js';
|
|
23
|
+
import { type Summary } from '../sources/wikimedia.js';
|
|
24
|
+
export interface TimelineItem {
|
|
25
|
+
date: string;
|
|
26
|
+
source: string;
|
|
27
|
+
text: string;
|
|
28
|
+
url?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface Dossier {
|
|
31
|
+
query: string;
|
|
32
|
+
wikipedia: (Summary & {
|
|
33
|
+
lastDayViews: number | null;
|
|
34
|
+
spike: number | null;
|
|
35
|
+
}) | null;
|
|
36
|
+
stock: {
|
|
37
|
+
symbol: string;
|
|
38
|
+
quote: Quote | null;
|
|
39
|
+
profile: CompanyProfile | null;
|
|
40
|
+
insiders: Insider[];
|
|
41
|
+
} | null;
|
|
42
|
+
sec: {
|
|
43
|
+
company: Company;
|
|
44
|
+
filings: Filing[];
|
|
45
|
+
} | null;
|
|
46
|
+
/** 8-Ks in the window with item codes decoded (from the same SEC submissions feed). */
|
|
47
|
+
events?: CorporateEvent[];
|
|
48
|
+
/** Finnhub free-tier extras; present only when the ticker matched the query. */
|
|
49
|
+
recommendations?: Recommendation[];
|
|
50
|
+
insiderSentiment?: InsiderSentimentMonth[];
|
|
51
|
+
peers?: string[];
|
|
52
|
+
metrics?: KeyMetrics;
|
|
53
|
+
earnings?: EarningsSurprise[];
|
|
54
|
+
/** Only with HoundOptions.deep. */
|
|
55
|
+
lobbying?: Lobbying;
|
|
56
|
+
govContracts?: GovContracts;
|
|
57
|
+
visa?: VisaFilings;
|
|
58
|
+
patents?: Patents;
|
|
59
|
+
/** openFDA recalls; only for health, pharma, device or food companies with at least one recall. */
|
|
60
|
+
fda?: FirmRecalls;
|
|
61
|
+
/** ClinicalTrials.gov; only for health or pharma companies with registered trials. */
|
|
62
|
+
trials?: SponsorTrials;
|
|
63
|
+
uk: UkCompany | null;
|
|
64
|
+
brand: Brand | null;
|
|
65
|
+
hiring: (Hiring[] & {
|
|
66
|
+
change?: number | null;
|
|
67
|
+
}) | null;
|
|
68
|
+
/** Same as hiring.change, kept as its own field because JSON drops properties attached to an array. */
|
|
69
|
+
hiringChange: number | null;
|
|
70
|
+
court: {
|
|
71
|
+
total: number;
|
|
72
|
+
cases: CourtCase[];
|
|
73
|
+
} | null;
|
|
74
|
+
github: {
|
|
75
|
+
owner: string;
|
|
76
|
+
repos: Repo[];
|
|
77
|
+
} | null;
|
|
78
|
+
/** News from GDELT, GNews, Guardian, NYT and company news, deduplicated by title. */
|
|
79
|
+
news: NewsItem[];
|
|
80
|
+
web: WebResult[];
|
|
81
|
+
stories: HnStory[];
|
|
82
|
+
markets: Market[];
|
|
83
|
+
videos: Video[];
|
|
84
|
+
posts: Post[];
|
|
85
|
+
timeline: TimelineItem[];
|
|
86
|
+
}
|
|
87
|
+
export interface HoundOptions {
|
|
88
|
+
/** GitHub org/user; defaults to the query with spaces removed. false to skip. */
|
|
89
|
+
github?: string | false;
|
|
90
|
+
days?: number;
|
|
91
|
+
/** Also fetch lobbying, federal contracts, visa filings and patents (four more Finnhub calls). */
|
|
92
|
+
deep?: boolean;
|
|
93
|
+
}
|
|
94
|
+
/** "Examplecorp Holdings, Inc." -> "Examplecorp" (for registry searches). */
|
|
95
|
+
export declare const coreName: (name: string) => string;
|
|
96
|
+
/** Keep only items that actually mention the entity, so a common word does not drag in noise. */
|
|
97
|
+
export declare function mentions(text: string, query: string): boolean;
|
|
98
|
+
/** Merge news lists, newest first, dropping near-duplicate headlines. */
|
|
99
|
+
export declare function mergeNews(lists: NewsItem[][]): NewsItem[];
|
|
100
|
+
export declare function hound(ctx: Ctx, queryInput: string, opts?: HoundOptions): Promise<ModuleResult<Dossier>>;
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hound: builds a dossier on one entity (company, person, project) from every public trail Oculon can reach,
|
|
3
|
+
* merges it into one timeline, links it into the entity graph, and raises signals when several trails move at once.
|
|
4
|
+
*
|
|
5
|
+
* Trails: Wikipedia, Hacker News, GDELT, GNews, The Guardian, NYT, web search (Tavily/Exa), Polymarket, GitHub,
|
|
6
|
+
* SEC EDGAR (filings, decoded 8-K items), Finnhub (quote, profile, insiders, company news, analyst recommendations,
|
|
7
|
+
* insider sentiment, peers, key metrics, earnings surprises; with deep: lobbying, federal contracts, visa filings,
|
|
8
|
+
* patents), openFDA recalls and ClinicalTrials.gov (health and food companies only), Adzuna (hiring), CourtListener (federal dockets),
|
|
9
|
+
* Companies House (UK registry), Brandfetch, YouTube, Bluesky. Sources without a key are skipped and labeled.
|
|
10
|
+
*/
|
|
11
|
+
import { DAY_MS } from '../core/context.js';
|
|
12
|
+
import { clamp, spikeRatio } from '../core/stats.js';
|
|
13
|
+
import { keywords, signalId } from '../core/text.js';
|
|
14
|
+
import { brand, courtCases, hiring, ukCompany } from '../sources/corp.js';
|
|
15
|
+
import { recalls, sponsorTrials, isPhase3 } from '../sources/fda.js';
|
|
16
|
+
import { bullishShare, companyNews, earningsSurprises, findSymbol, govContracts, insiderSentiment, insiders, lobbying, metrics, patents, peers, profile, quote, recommendations, visaApplications, } from '../sources/finance.js';
|
|
17
|
+
import { decodeEvents, eventEvidence } from './filings.js';
|
|
18
|
+
import { latestArticles } from '../sources/gdelt.js';
|
|
19
|
+
import { recentRepos } from '../sources/github.js';
|
|
20
|
+
import { hnItemUrl, recentMentions } from '../sources/hackernews.js';
|
|
21
|
+
import { searchMarkets } from '../sources/polymarket.js';
|
|
22
|
+
import { gnews, guardian, nytSearch, webSearch } from '../sources/press.js';
|
|
23
|
+
import { companies, matchCompany, recentFilings } from '../sources/sec.js';
|
|
24
|
+
import { bluesky, youtube } from '../sources/social.js';
|
|
25
|
+
import { dailyViews, resolveTitle, summary } from '../sources/wikimedia.js';
|
|
26
|
+
/** Industries (Finnhub) or descriptions (Wikipedia) where FDA recalls and clinical trials are relevant. */
|
|
27
|
+
const FDA_RELEVANT = /pharma|biotech|bio-?pharm|health ?care|medical|life sciences|drug|diagnostic|food|beverage|tobacco|cosmetic|nutrition|vaccine/i;
|
|
28
|
+
const TRIALS_RELEVANT = /pharma|biotech|bio-?pharm|health ?care|medical|life sciences|drug|diagnostic|vaccine|therapeutic/i;
|
|
29
|
+
/** "Examplecorp Holdings, Inc." -> "Examplecorp" (for registry searches). */
|
|
30
|
+
export const coreName = (name) => name
|
|
31
|
+
.replace(/[,.]/g, ' ')
|
|
32
|
+
.replace(/\b(inc|incorporated|corp|corporation|co|company|ltd|limited|plc|llc|lp|sa|ag|nv|se|group|holdings?|the)\b/gi, ' ')
|
|
33
|
+
.replace(/\s+/g, ' ')
|
|
34
|
+
.trim() || name.trim();
|
|
35
|
+
/** Keep only items that actually mention the entity, so a common word does not drag in noise. */
|
|
36
|
+
export function mentions(text, query) {
|
|
37
|
+
const q = [...keywords(query)];
|
|
38
|
+
if (!q.length)
|
|
39
|
+
return text.toLowerCase().includes(query.toLowerCase());
|
|
40
|
+
const k = keywords(text);
|
|
41
|
+
return q.every((w) => k.has(w)) || text.toLowerCase().includes(query.toLowerCase());
|
|
42
|
+
}
|
|
43
|
+
const gdeltDate = (s) => (/^\d{8}T\d{6}Z$/.test(s) ? `${s.slice(0, 4)}-${s.slice(4, 6)}-${s.slice(6, 8)}T${s.slice(9, 11)}:${s.slice(11, 13)}:00Z` : s);
|
|
44
|
+
/** Merge news lists, newest first, dropping near-duplicate headlines. */
|
|
45
|
+
export function mergeNews(lists) {
|
|
46
|
+
const seen = new Set();
|
|
47
|
+
const out = [];
|
|
48
|
+
for (const n of lists.flat().sort((a, b) => b.date.localeCompare(a.date))) {
|
|
49
|
+
const k = n.title.toLowerCase().replace(/[^a-z0-9 ]/g, '').split(' ').filter(Boolean).slice(0, 8).join(' ');
|
|
50
|
+
if (!k || seen.has(k))
|
|
51
|
+
continue;
|
|
52
|
+
seen.add(k);
|
|
53
|
+
out.push(n);
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
const INSIDER_SELL_CODES = new Set(['S']);
|
|
58
|
+
export async function hound(ctx, queryInput, opts = {}) {
|
|
59
|
+
const query = queryInput.trim();
|
|
60
|
+
const days = opts.days ?? 14;
|
|
61
|
+
const nowMs = ctx.now().getTime();
|
|
62
|
+
const nowIso = new Date(nowMs).toISOString();
|
|
63
|
+
const provenance = [];
|
|
64
|
+
const owner = opts.github === false ? null : (opts.github ?? query.toLowerCase().replace(/[^a-z0-9-]/g, ''));
|
|
65
|
+
const [title, hn, gd, markets, comps, repos, sym, gn, gu, ny, web, jobs, court, uk, vids, posts] = await Promise.all([
|
|
66
|
+
resolveTitle(ctx, query),
|
|
67
|
+
recentMentions(ctx, query, days, 30),
|
|
68
|
+
latestArticles(ctx, query, 15),
|
|
69
|
+
searchMarkets(ctx, query, 10),
|
|
70
|
+
companies(ctx),
|
|
71
|
+
owner ? recentRepos(ctx, owner) : Promise.resolve(null),
|
|
72
|
+
findSymbol(ctx, query),
|
|
73
|
+
gnews(ctx, query, 10),
|
|
74
|
+
guardian(ctx, query, days, 10),
|
|
75
|
+
nytSearch(ctx, query, days),
|
|
76
|
+
webSearch(ctx, `${query} latest news`, 6, true),
|
|
77
|
+
hiring(ctx, query),
|
|
78
|
+
courtCases(ctx, query, 8),
|
|
79
|
+
ukCompany(ctx, query),
|
|
80
|
+
youtube(ctx, query, 7, 8),
|
|
81
|
+
bluesky(ctx, query, 25),
|
|
82
|
+
]);
|
|
83
|
+
provenance.push(title.prov, hn.prov, gd.prov, markets.prov, comps.prov, sym.prov, gn.prov, gu.prov, ny.prov, web.prov, jobs.prov, court.prov, uk.prov, vids.prov, posts.prov);
|
|
84
|
+
if (repos)
|
|
85
|
+
provenance.push(repos.prov);
|
|
86
|
+
// Second wave: things that depend on the first (Wikipedia title, ticker, website).
|
|
87
|
+
const [sumR, viewsR, q, prof, ins, cnews] = await Promise.all([
|
|
88
|
+
title.data ? summary(ctx, title.data) : Promise.resolve(null),
|
|
89
|
+
title.data ? dailyViews(ctx, title.data, 30) : Promise.resolve(null),
|
|
90
|
+
sym.data ? quote(ctx, sym.data) : Promise.resolve(null),
|
|
91
|
+
sym.data ? profile(ctx, sym.data) : Promise.resolve(null),
|
|
92
|
+
sym.data ? insiders(ctx, sym.data, 30) : Promise.resolve(null),
|
|
93
|
+
sym.data ? companyNews(ctx, sym.data, 7) : Promise.resolve(null),
|
|
94
|
+
]);
|
|
95
|
+
for (const r of [sumR, viewsR, q, prof, ins, cnews])
|
|
96
|
+
if (r)
|
|
97
|
+
provenance.push(r.prov);
|
|
98
|
+
let wikipedia = null;
|
|
99
|
+
if (sumR?.data) {
|
|
100
|
+
const vals = viewsR?.data?.map((v) => v.views) ?? [];
|
|
101
|
+
const last = vals.length ? vals[vals.length - 1] : null;
|
|
102
|
+
wikipedia = { ...sumR.data, lastDayViews: last, spike: last !== null && vals.length > 7 ? spikeRatio(last, vals.slice(0, -3)) : null };
|
|
103
|
+
}
|
|
104
|
+
// Only trust the ticker when the company profile actually matches the query.
|
|
105
|
+
const stockOk = Boolean(sym.data && prof?.data && (mentions(prof.data.name, query) || sym.data.toLowerCase() === query.toLowerCase()));
|
|
106
|
+
const stock = stockOk ? { symbol: sym.data, quote: q?.data ?? null, profile: prof?.data ?? null, insiders: ins?.data ?? [] } : null;
|
|
107
|
+
const website = stock?.profile?.weburl ? (() => { try {
|
|
108
|
+
return new URL(stock.profile.weburl).hostname.replace(/^www\./, '');
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return null;
|
|
112
|
+
} })() : null;
|
|
113
|
+
let sec = null;
|
|
114
|
+
const company = comps.data ? matchCompany(comps.data, stock?.symbol ?? query) : null;
|
|
115
|
+
const sector = `${stock?.profile?.industry ?? ''} ${wikipedia?.description ?? ''}`;
|
|
116
|
+
const firm = stock?.profile ? coreName(stock.profile.name) : query;
|
|
117
|
+
const S = stockOk ? sym.data : null;
|
|
118
|
+
const none = Promise.resolve(null);
|
|
119
|
+
// Third wave: everything that needs the ticker, website, CIK or sector, in parallel.
|
|
120
|
+
const [br, f, recR, isR, peerR, metR, earnR, lobR, govR, visaR, patR, fdaR, ctR] = await Promise.all([
|
|
121
|
+
website ? brand(ctx, website) : none,
|
|
122
|
+
company ? recentFilings(ctx, company.cik, 40) : none,
|
|
123
|
+
S ? recommendations(ctx, S) : none,
|
|
124
|
+
S ? insiderSentiment(ctx, S, 12) : none,
|
|
125
|
+
S ? peers(ctx, S) : none,
|
|
126
|
+
S ? metrics(ctx, S) : none,
|
|
127
|
+
S ? earningsSurprises(ctx, S) : none,
|
|
128
|
+
S && opts.deep ? lobbying(ctx, S) : none,
|
|
129
|
+
S && opts.deep ? govContracts(ctx, S) : none,
|
|
130
|
+
S && opts.deep ? visaApplications(ctx, S) : none,
|
|
131
|
+
S && opts.deep ? patents(ctx, S) : none,
|
|
132
|
+
FDA_RELEVANT.test(sector) ? recalls(ctx, firm, { days: 90 }) : none,
|
|
133
|
+
TRIALS_RELEVANT.test(sector) ? sponsorTrials(ctx, firm, 180) : none,
|
|
134
|
+
]);
|
|
135
|
+
for (const r of [br, f, recR, isR, peerR, metR, earnR, lobR, govR, visaR, patR])
|
|
136
|
+
if (r)
|
|
137
|
+
provenance.push(r.prov);
|
|
138
|
+
if (fdaR)
|
|
139
|
+
provenance.push(...fdaR.provenance);
|
|
140
|
+
if (ctR)
|
|
141
|
+
provenance.push(...ctR.provenance);
|
|
142
|
+
if (company && f?.data)
|
|
143
|
+
sec = { company, filings: f.data };
|
|
144
|
+
const fda = fdaR?.data && fdaR.data.recent.length ? fdaR.data : null;
|
|
145
|
+
const trialsData = ctR?.data && Object.values(ctR.data.counts).some((n) => n > 0) ? ctR.data : null;
|
|
146
|
+
// Reading 8-K text is one extra SEC request per filing; only the newest two 5.02s in the window.
|
|
147
|
+
const events = sec ? await decodeEvents(ctx, sec.filings, { since: nowMs - days * DAY_MS, read502: 2, provenance }) : [];
|
|
148
|
+
const since = nowMs - days * DAY_MS;
|
|
149
|
+
const stories = (hn.data ?? []).filter((s) => mentions(s.title, query)).sort((a, b) => b.points - a.points).slice(0, 10);
|
|
150
|
+
const gdeltNews = (gd.data ?? []).map((a) => ({ title: a.title, url: a.url, date: gdeltDate(a.seendate), source: a.domain }));
|
|
151
|
+
const news = mergeNews([gdeltNews, gn.data ?? [], gu.data ?? [], ny.data ?? [], stockOk ? (cnews?.data ?? []) : []])
|
|
152
|
+
// Company-news feeds also carry general market stories; keep only headlines that name the company or ticker.
|
|
153
|
+
.filter((n) => mentions(n.title, query) || (stockOk && new RegExp(`\\b${sym.data}\\b`).test(n.title)))
|
|
154
|
+
.slice(0, 25);
|
|
155
|
+
const mkts = (markets.data ?? []).filter((m) => mentions(m.question, query)).slice(0, 8);
|
|
156
|
+
const ghRepos = repos?.data?.filter((r) => !r.fork && Date.parse(r.created_at) >= since) ?? [];
|
|
157
|
+
const github = owner && repos?.data ? { owner, repos: ghRepos } : null;
|
|
158
|
+
const videos = (vids.data ?? []).filter((v) => mentions(v.title, query)).slice(0, 8);
|
|
159
|
+
const topPosts = (posts.data ?? []).filter((p) => mentions(p.text, query)).sort((a, b) => b.likes + b.reposts * 2 - (a.likes + a.reposts * 2)).slice(0, 8);
|
|
160
|
+
const courtData = court.data ? { total: court.data.total, cases: court.data.cases } : null;
|
|
161
|
+
const ukData = uk.data && mentions(uk.data.name, query) ? uk.data : null;
|
|
162
|
+
// Hiring trend: compare against the previous observation of this entity.
|
|
163
|
+
const kind = sec || stock ? 'company' : 'org';
|
|
164
|
+
const id = ctx.graph.upsert(kind, query, {
|
|
165
|
+
...(wikipedia ? { wikipedia: wikipedia.title, description: wikipedia.description } : {}),
|
|
166
|
+
...(sec ? { cik: sec.company.cik } : {}),
|
|
167
|
+
...(stock ? { ticker: stock.symbol } : {}),
|
|
168
|
+
...(website ? { website } : {}),
|
|
169
|
+
});
|
|
170
|
+
const openings = jobs.data ? jobs.data.reduce((a, j) => a + j.openings, 0) : null;
|
|
171
|
+
const prevOpen = ctx.graph.history(id, 'job_openings', 5).find((h) => nowMs - h.observedAt > 6 * 3600_000)?.value ?? null;
|
|
172
|
+
if (openings !== null)
|
|
173
|
+
ctx.graph.observe(id, 'hound', 'job_openings', openings, 'adzuna');
|
|
174
|
+
const hiringData = jobs.data ? Object.assign(jobs.data, { change: prevOpen ? openings / prevOpen - 1 : null }) : null;
|
|
175
|
+
const timeline = [
|
|
176
|
+
...stories.map((s) => ({ date: new Date(s.created_at_i * 1000).toISOString(), source: 'hackernews', text: `${s.title} (${s.points} pts)`, url: hnItemUrl(s.objectID) })),
|
|
177
|
+
...news.map((n) => ({ date: n.date, source: `news:${n.source}`, text: n.title, url: n.url })),
|
|
178
|
+
...ghRepos.map((r) => ({ date: r.created_at, source: 'github', text: `new repo ${r.full_name}${r.description ? `: ${r.description}` : ''}`, url: r.html_url })),
|
|
179
|
+
...(sec?.filings.filter((f) => Date.parse(f.date) >= since).map((f) => ({ date: `${f.date}T00:00:00Z`, source: 'sec-edgar', text: `${f.form}: ${events.find((e) => e.url === f.url)?.summary ?? f.description}`, url: f.url })) ?? []),
|
|
180
|
+
...(fda?.recent.map((r) => ({ date: `${r.reported}T00:00:00Z`, source: 'openfda', text: `${r.classification} ${r.category} recall: ${r.product.slice(0, 120)}`, url: r.url })) ?? []),
|
|
181
|
+
...(trialsData?.recentlyTerminated.filter((t) => /^\d{4}-\d{2}-\d{2}$/.test(t.completionDate ?? '')).map((t) => ({ date: `${t.completionDate}T00:00:00Z`, source: 'clinicaltrials', text: `trial terminated: ${t.title}`, url: t.url })) ?? []),
|
|
182
|
+
...(stock?.insiders.filter((t) => Date.parse(t.date) >= since).map((t) => ({ date: `${t.date}T00:00:00Z`, source: 'insider', text: `${t.name} ${t.change >= 0 ? 'acquired' : 'disposed of'} ${Math.abs(t.change).toLocaleString('en-US')} shares (code ${t.code})` })) ?? []),
|
|
183
|
+
...(courtData?.cases.filter((c) => Date.parse(c.filed) >= since).map((c) => ({ date: `${c.filed}T00:00:00Z`, source: 'court', text: `${c.name} (${c.court})`, url: c.url })) ?? []),
|
|
184
|
+
...videos.map((v) => ({ date: v.date, source: `youtube:${v.channel}`, text: v.title, url: v.url })),
|
|
185
|
+
]
|
|
186
|
+
.filter((t) => t.date && Date.parse(t.date) >= since)
|
|
187
|
+
.sort((a, b) => b.date.localeCompare(a.date));
|
|
188
|
+
// Graph links.
|
|
189
|
+
if (wikipedia)
|
|
190
|
+
ctx.graph.link(id, ctx.graph.upsert('article', wikipedia.title), 'described_by', 'wikipedia');
|
|
191
|
+
for (const s of stories)
|
|
192
|
+
ctx.graph.link(id, ctx.graph.upsert('story', s.title, { url: hnItemUrl(s.objectID), points: s.points }), 'mentioned_in', 'hackernews');
|
|
193
|
+
for (const m of mkts)
|
|
194
|
+
ctx.graph.link(id, ctx.graph.upsert('market', m.question, { url: m.url }), 'subject_of', 'polymarket');
|
|
195
|
+
for (const r of ghRepos)
|
|
196
|
+
ctx.graph.link(id, ctx.graph.upsert('repo', r.full_name, { url: r.html_url }), 'owns_repo', 'github');
|
|
197
|
+
for (const c of courtData?.cases.slice(0, 5) ?? [])
|
|
198
|
+
ctx.graph.link(id, ctx.graph.upsert('event', `case: ${c.name}`, { url: c.url, filed: c.filed }), 'party_to', 'courtlistener');
|
|
199
|
+
if (website)
|
|
200
|
+
ctx.graph.link(id, ctx.graph.upsert('domain', website), 'operates', 'finnhub');
|
|
201
|
+
for (const p of peerR?.data?.slice(0, 10) ?? [])
|
|
202
|
+
ctx.graph.link(id, ctx.graph.upsert('company', p, { ticker: p }), 'peer_of', 'finnhub');
|
|
203
|
+
if (wikipedia?.lastDayViews != null)
|
|
204
|
+
ctx.graph.observe(id, 'hound', 'wiki_views', wikipedia.lastDayViews, 'wikimedia-pageviews');
|
|
205
|
+
if (stock?.quote)
|
|
206
|
+
ctx.graph.observe(id, 'hound', 'price', stock.quote.price, 'finnhub', { changePct: stock.quote.changePct });
|
|
207
|
+
// Signals: each trail that is moving, then one fused signal.
|
|
208
|
+
const recent = nowMs - 3 * DAY_MS;
|
|
209
|
+
const moving = [];
|
|
210
|
+
if (wikipedia?.spike && wikipedia.spike >= 3)
|
|
211
|
+
moving.push({ source: 'wikimedia-pageviews', text: `Wikipedia readers ${wikipedia.spike.toFixed(1)}x usual (${wikipedia.lastDayViews?.toLocaleString('en-US')} yesterday)`, url: wikipedia.url, value: wikipedia.spike });
|
|
212
|
+
const hot = stories.filter((s) => s.created_at_i * 1000 >= recent && s.points >= 200);
|
|
213
|
+
if (hot.length)
|
|
214
|
+
moving.push({ source: 'hackernews', text: `${hot.length} HN stor${hot.length > 1 ? 'ies' : 'y'} with 200+ points in 3 days, top: ${hot[0].title}`, url: hnItemUrl(hot[0].objectID) });
|
|
215
|
+
if (stock?.quote && Math.abs(stock.quote.changePct) >= 5)
|
|
216
|
+
moving.push({ source: 'finnhub', text: `${stock.symbol} ${stock.quote.changePct > 0 ? '+' : ''}${stock.quote.changePct.toFixed(1)}% today at ${stock.quote.price}`, value: stock.quote.changePct });
|
|
217
|
+
const sells = stock?.insiders.filter((t) => INSIDER_SELL_CODES.has(t.code) && Date.parse(t.date) >= nowMs - 14 * DAY_MS) ?? [];
|
|
218
|
+
if (sells.length >= 3)
|
|
219
|
+
moving.push({ source: 'finnhub', text: `${sells.length} insider open-market sales in 14 days (${new Set(sells.map((s) => s.name)).size} insiders)` });
|
|
220
|
+
const eightK = sec?.filings.filter((f) => f.form.startsWith('8-K') && Date.parse(f.date) >= recent) ?? [];
|
|
221
|
+
if (eightK.length)
|
|
222
|
+
moving.push({ source: 'sec-edgar', text: `${eightK.length} 8-K filing(s) in 3 days`, url: eightK[0].url });
|
|
223
|
+
for (const e of events.filter((x) => Date.parse(x.date) >= recent))
|
|
224
|
+
moving.push(...eventEvidence(e));
|
|
225
|
+
const [rec0, rec1] = recR?.data ?? [];
|
|
226
|
+
const bullNow = rec0 ? bullishShare(rec0) : null;
|
|
227
|
+
const bullPrev = rec1 ? bullishShare(rec1) : null;
|
|
228
|
+
if (bullNow !== null && bullPrev !== null && Math.abs(bullNow - bullPrev) >= 0.1)
|
|
229
|
+
moving.push({ source: 'finnhub', text: `analyst buy ratings ${bullNow > bullPrev ? 'up' : 'down'} from ${Math.round(bullPrev * 100)}% to ${Math.round(bullNow * 100)}% (${rec1.period} to ${rec0.period})`, value: bullNow - bullPrev });
|
|
230
|
+
for (const r of fda?.newClassI.slice(0, 3) ?? [])
|
|
231
|
+
moving.push({ source: 'openfda', text: `new Class I ${r.category} recall ${r.recallNumber} (reported ${r.reported}): ${r.reason.slice(0, 140)}`, url: r.url });
|
|
232
|
+
const stoppedP3 = trialsData?.recentlyTerminated.filter((t) => isPhase3(t) && (t.completionDate ?? '') >= new Date(nowMs - 90 * DAY_MS).toISOString().slice(0, 10).slice(0, (t.completionDate ?? '').length)) ?? [];
|
|
233
|
+
for (const t of stoppedP3.slice(0, 3))
|
|
234
|
+
moving.push({ source: 'clinicaltrials', text: `phase 3 trial ${t.nctId} terminated (stopped ${t.completionDate})${t.whyStopped ? `: ${t.whyStopped.slice(0, 140)}` : ''}`, url: t.url });
|
|
235
|
+
const newCases = courtData?.cases.filter((c) => Date.parse(c.filed) >= recent) ?? [];
|
|
236
|
+
if (newCases.length)
|
|
237
|
+
moving.push({ source: 'courtlistener', text: `${newCases.length} new federal case(s) in 3 days, e.g. ${newCases[0].name}`, url: newCases[0].url });
|
|
238
|
+
const swing = mkts.filter((m) => m.change1d !== null && Math.abs(m.change1d) >= 0.08);
|
|
239
|
+
if (swing.length)
|
|
240
|
+
moving.push({ source: 'polymarket', text: `${swing[0].question}: ${swing[0].change1d > 0 ? '+' : ''}${Math.round(swing[0].change1d * 100)}pp in 24h`, url: swing[0].url });
|
|
241
|
+
const freshNews = news.filter((n) => Date.parse(n.date) >= nowMs - DAY_MS);
|
|
242
|
+
if (freshNews.length >= 8)
|
|
243
|
+
moving.push({ source: 'news', text: `${freshNews.length} news articles in 24h across ${new Set(freshNews.map((n) => n.source)).size} outlets` });
|
|
244
|
+
if (hiringData?.change != null && Math.abs(hiringData.change) >= 0.25)
|
|
245
|
+
moving.push({ source: 'adzuna', text: `job openings ${hiringData.change > 0 ? 'up' : 'down'} ${Math.round(Math.abs(hiringData.change) * 100)}% since last check (${openings})` });
|
|
246
|
+
const viral = topPosts.filter((p) => p.likes >= 500);
|
|
247
|
+
if (viral.length)
|
|
248
|
+
moving.push({ source: 'bluesky', text: `${viral.length} Bluesky post(s) with 500+ likes, top by @${viral[0].author}`, url: viral[0].url });
|
|
249
|
+
const signals = [];
|
|
250
|
+
if (moving.length) {
|
|
251
|
+
const sources = new Set(moving.map((m) => m.source));
|
|
252
|
+
signals.push({
|
|
253
|
+
id: signalId('hound', query, nowIso.slice(0, 10)),
|
|
254
|
+
module: 'hound',
|
|
255
|
+
title: sources.size >= 2 ? `${query}: activity across ${sources.size} independent sources` : `${query}: ${moving[0].text}`,
|
|
256
|
+
score: clamp(35 + moving.length * 8 + (sources.size - 1) * 10, 0, 100),
|
|
257
|
+
entity: id,
|
|
258
|
+
evidence: moving,
|
|
259
|
+
createdAt: nowIso,
|
|
260
|
+
});
|
|
261
|
+
signals.forEach((s) => ctx.graph.saveSignal(s));
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
module: 'hound',
|
|
265
|
+
input: query,
|
|
266
|
+
generatedAt: nowIso,
|
|
267
|
+
result: {
|
|
268
|
+
query,
|
|
269
|
+
wikipedia,
|
|
270
|
+
stock,
|
|
271
|
+
sec,
|
|
272
|
+
...(events.length ? { events } : {}),
|
|
273
|
+
...(recR?.data?.length ? { recommendations: recR.data.slice(0, 6) } : {}),
|
|
274
|
+
...(isR?.data?.length ? { insiderSentiment: isR.data } : {}),
|
|
275
|
+
...(peerR?.data?.length ? { peers: peerR.data } : {}),
|
|
276
|
+
...(metR?.data ? { metrics: metR.data } : {}),
|
|
277
|
+
...(earnR?.data?.length ? { earnings: earnR.data } : {}),
|
|
278
|
+
...(lobR?.data ? { lobbying: lobR.data } : {}),
|
|
279
|
+
...(govR?.data ? { govContracts: govR.data } : {}),
|
|
280
|
+
...(visaR?.data ? { visa: visaR.data } : {}),
|
|
281
|
+
...(patR?.data ? { patents: patR.data } : {}),
|
|
282
|
+
...(fda ? { fda } : {}),
|
|
283
|
+
...(trialsData ? { trials: trialsData } : {}),
|
|
284
|
+
uk: ukData,
|
|
285
|
+
brand: br?.data ?? null,
|
|
286
|
+
hiring: hiringData,
|
|
287
|
+
hiringChange: hiringData?.change ?? null,
|
|
288
|
+
court: courtData,
|
|
289
|
+
github,
|
|
290
|
+
news,
|
|
291
|
+
web: web.data ?? [],
|
|
292
|
+
stories,
|
|
293
|
+
markets: mkts,
|
|
294
|
+
videos,
|
|
295
|
+
posts: topPosts,
|
|
296
|
+
timeline,
|
|
297
|
+
},
|
|
298
|
+
signals,
|
|
299
|
+
provenance,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disaster impact: for strong earthquakes and severe storms, who lives in the affected radius (Wikidata
|
|
3
|
+
* settlements with population) and, when enough nights have passed, whether night lights dropped
|
|
4
|
+
* (VIIRS, via Condor). Population figures are an approximate exposure estimate, not a casualty estimate.
|
|
5
|
+
*/
|
|
6
|
+
import type { Ctx } from '../core/context.js';
|
|
7
|
+
import type { ModuleResult } from '../core/types.js';
|
|
8
|
+
import { type Settlement } from '../sources/wikidata.js';
|
|
9
|
+
export interface Impact {
|
|
10
|
+
event: string;
|
|
11
|
+
kind: 'earthquake' | 'storm' | 'place';
|
|
12
|
+
lat: number;
|
|
13
|
+
lon: number;
|
|
14
|
+
radiusKm: number;
|
|
15
|
+
when: string;
|
|
16
|
+
settlements: Settlement[];
|
|
17
|
+
/** Sum of listed settlement populations; places can overlap, so treat it as an order of magnitude. */
|
|
18
|
+
exposedPopulation: number;
|
|
19
|
+
lights: {
|
|
20
|
+
verdict: string;
|
|
21
|
+
ratio: number | null;
|
|
22
|
+
note: string;
|
|
23
|
+
} | null;
|
|
24
|
+
url: string;
|
|
25
|
+
}
|
|
26
|
+
/** Shaking radius that matters for people, roughly: M6 -> 50 km, M7 -> 120 km, M8 -> ~290 km. */
|
|
27
|
+
export declare const quakeRadiusKm: (mag: number) => number;
|
|
28
|
+
/** Impact of current strong quakes (M6+) and severe storms, or of a place you name. */
|
|
29
|
+
export declare function impact(ctx: Ctx, opts?: {
|
|
30
|
+
place?: {
|
|
31
|
+
name: string;
|
|
32
|
+
lat: number;
|
|
33
|
+
lon: number;
|
|
34
|
+
};
|
|
35
|
+
radiusKm?: number;
|
|
36
|
+
lights?: boolean;
|
|
37
|
+
}): Promise<ModuleResult<{
|
|
38
|
+
impacts: Impact[];
|
|
39
|
+
}>>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { clamp } from '../core/stats.js';
|
|
2
|
+
import { signalId } from '../core/text.js';
|
|
3
|
+
import { eonetEvents } from '../sources/earth.js';
|
|
4
|
+
import { recentQuakes } from '../sources/usgs.js';
|
|
5
|
+
import { settlementsNear } from '../sources/wikidata.js';
|
|
6
|
+
import { eventSeverity, lights } from './condor.js';
|
|
7
|
+
/** Shaking radius that matters for people, roughly: M6 -> 50 km, M7 -> 120 km, M8 -> ~290 km. */
|
|
8
|
+
export const quakeRadiusKm = (mag) => Math.round(clamp(50 * 2.4 ** (mag - 6), 20, 400));
|
|
9
|
+
async function assess(ctx, e, provenance, withLights) {
|
|
10
|
+
const s = await settlementsNear(ctx, e.lat, e.lon, e.radiusKm, 25);
|
|
11
|
+
provenance.push(s.prov);
|
|
12
|
+
const settlements = s.data ?? [];
|
|
13
|
+
let lightsRes = null;
|
|
14
|
+
// Night lights only say something once the gap-filled product covers nights after the event (it lags days).
|
|
15
|
+
const ageDays = (ctx.now().getTime() - Date.parse(e.when)) / 86_400_000;
|
|
16
|
+
if (withLights && settlements.length && ageDays >= 3) {
|
|
17
|
+
const top = settlements[0];
|
|
18
|
+
try {
|
|
19
|
+
const l = await lights(ctx, top.name);
|
|
20
|
+
provenance.push(...l.provenance.slice(0, 2));
|
|
21
|
+
lightsRes = { verdict: l.result.verdict, ratio: l.result.ratio, note: `night lights over ${top.name}, recent nights vs the month before` };
|
|
22
|
+
}
|
|
23
|
+
catch { }
|
|
24
|
+
}
|
|
25
|
+
else if (withLights)
|
|
26
|
+
lightsRes = { verdict: 'PENDING', ratio: null, note: 'too recent: night-light data covers this event after about 3 days' };
|
|
27
|
+
return { ...e, settlements, exposedPopulation: settlements.reduce((a, x) => a + x.population, 0), lights: lightsRes };
|
|
28
|
+
}
|
|
29
|
+
/** Impact of current strong quakes (M6+) and severe storms, or of a place you name. */
|
|
30
|
+
export async function impact(ctx, opts = {}) {
|
|
31
|
+
const provenance = [];
|
|
32
|
+
const nowIso = ctx.now().toISOString();
|
|
33
|
+
const withLights = opts.lights !== false;
|
|
34
|
+
const impacts = [];
|
|
35
|
+
if (opts.place) {
|
|
36
|
+
impacts.push(await assess(ctx, { event: opts.place.name, kind: 'place', lat: opts.place.lat, lon: opts.place.lon, radiusKm: opts.radiusKm ?? 50, when: nowIso, url: '' }, provenance, withLights));
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const [q, ev] = await Promise.all([recentQuakes(ctx), eonetEvents(ctx, 3)]);
|
|
40
|
+
provenance.push(q.prov, ev.prov);
|
|
41
|
+
for (const e of (q.data ?? []).filter((x) => x.mag >= 6 && x.lat !== null)) {
|
|
42
|
+
impacts.push(await assess(ctx, { event: `M${e.mag.toFixed(1)} earthquake ${e.place}`, kind: 'earthquake', lat: e.lat, lon: e.lon, radiusKm: quakeRadiusKm(e.mag), when: new Date(e.time).toISOString(), url: e.url }, provenance, withLights));
|
|
43
|
+
}
|
|
44
|
+
for (const e of (ev.data ?? []).filter((x) => x.category === 'severeStorms' && x.lat !== null && (eventSeverity(x)?.score ?? 0) >= 70)) {
|
|
45
|
+
impacts.push(await assess(ctx, { event: e.title, kind: 'storm', lat: e.lat, lon: e.lon, radiusKm: 150, when: e.date, url: e.url }, provenance, withLights));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const signals = impacts
|
|
49
|
+
.filter((i) => i.kind !== 'place' && i.exposedPopulation >= 100_000)
|
|
50
|
+
.map((i) => ({
|
|
51
|
+
id: signalId('impact', i.event, i.when.slice(0, 10)),
|
|
52
|
+
module: 'impact',
|
|
53
|
+
title: `${i.event}: about ${i.exposedPopulation >= 1e6 ? `${(i.exposedPopulation / 1e6).toFixed(1)}M` : `${Math.round(i.exposedPopulation / 1000)}k`} people live within ${i.radiusKm} km`,
|
|
54
|
+
score: clamp(Math.round(45 + 8 * Math.log10(i.exposedPopulation / 1e5 + 1) * 3 + (i.lights?.verdict === 'DROP' ? 15 : 0)), 0, 95),
|
|
55
|
+
evidence: [
|
|
56
|
+
...i.settlements.slice(0, 4).map((s) => ({ source: 'wikidata', text: `${s.name}: ${s.population.toLocaleString('en-US')} people, ${s.distanceKm} km away`, url: `https://www.wikidata.org/wiki/${s.qid}` })),
|
|
57
|
+
...(i.lights ? [{ source: 'nasa-gibs', text: `${i.lights.note}: ${i.lights.verdict}${i.lights.ratio ? ` (${Math.round((i.lights.ratio - 1) * 100)}%)` : ''}` }] : []),
|
|
58
|
+
],
|
|
59
|
+
createdAt: nowIso,
|
|
60
|
+
}));
|
|
61
|
+
signals.forEach((s) => ctx.graph.saveSignal(s));
|
|
62
|
+
return { module: 'impact', input: opts.place?.name ?? 'current events', generatedAt: nowIso, result: { impacts }, signals, provenance };
|
|
63
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Launch Radar: what a company is about to ship, from every footprint Oculon can see: new hostnames in
|
|
3
|
+
* certificates and scans, newly archived pages, new public repos (Ferret), new Hugging Face models,
|
|
4
|
+
* datasets and Spaces, new iOS apps and app updates, and new npm packages under its scope.
|
|
5
|
+
*/
|
|
6
|
+
import { type Ctx } from '../core/context.js';
|
|
7
|
+
import type { ModuleResult } from '../core/types.js';
|
|
8
|
+
import { type LaunchItem } from '../sources/launch.js';
|
|
9
|
+
export interface LaunchFeedItem extends LaunchItem {
|
|
10
|
+
company: string;
|
|
11
|
+
score: number;
|
|
12
|
+
}
|
|
13
|
+
export interface LaunchResult {
|
|
14
|
+
company: string;
|
|
15
|
+
domain: string | null;
|
|
16
|
+
org: string;
|
|
17
|
+
windowDays: number;
|
|
18
|
+
items: LaunchFeedItem[];
|
|
19
|
+
}
|
|
20
|
+
export declare function launches(ctx: Ctx, company: string, opts?: {
|
|
21
|
+
domain?: string;
|
|
22
|
+
org?: string;
|
|
23
|
+
days?: number;
|
|
24
|
+
}): Promise<ModuleResult<LaunchResult>>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Launch Radar: what a company is about to ship, from every footprint Oculon can see: new hostnames in
|
|
3
|
+
* certificates and scans, newly archived pages, new public repos (Ferret), new Hugging Face models,
|
|
4
|
+
* datasets and Spaces, new iOS apps and app updates, and new npm packages under its scope.
|
|
5
|
+
*/
|
|
6
|
+
import { DAY_MS } from '../core/context.js';
|
|
7
|
+
import { signalId } from '../core/text.js';
|
|
8
|
+
import { appStore, huggingFace, npmScope } from '../sources/launch.js';
|
|
9
|
+
import { ferret } from './ferret.js';
|
|
10
|
+
const KIND_SCORE = { model: 55, space: 45, dataset: 40, app: 70, 'app-update': 30, package: 45, subdomain: 50, page: 40, repo: 45 };
|
|
11
|
+
export async function launches(ctx, company, opts = {}) {
|
|
12
|
+
const days = opts.days ?? 30;
|
|
13
|
+
const org = (opts.org ?? company).toLowerCase().replace(/[^a-z0-9-]/g, '');
|
|
14
|
+
const domain = opts.domain ?? null;
|
|
15
|
+
const nowMs = ctx.now().getTime();
|
|
16
|
+
const since = nowMs - days * DAY_MS;
|
|
17
|
+
const provenance = [];
|
|
18
|
+
const [hf, apps, npm, fr] = await Promise.all([
|
|
19
|
+
huggingFace(ctx, org),
|
|
20
|
+
appStore(ctx, company),
|
|
21
|
+
npmScope(ctx, org),
|
|
22
|
+
domain ? ferret(ctx, domain, { days, org }) : Promise.resolve(null),
|
|
23
|
+
]);
|
|
24
|
+
provenance.push(hf.prov, apps.prov, npm.prov, ...(fr?.provenance ?? []));
|
|
25
|
+
const items = [...(hf.data ?? []), ...(apps.data ?? []), ...(npm.data ?? [])]
|
|
26
|
+
.filter((i) => Date.parse(i.date) >= since)
|
|
27
|
+
.map((i) => ({ ...i, company, score: KIND_SCORE[i.kind] ?? 40 }));
|
|
28
|
+
for (const f of fr?.result.findings ?? []) {
|
|
29
|
+
if (Date.parse(f.firstSeen) < since)
|
|
30
|
+
continue;
|
|
31
|
+
// Ferret already scored names (pre-release words etc.); keep its score for web footprints.
|
|
32
|
+
items.push({ kind: f.kind === 'repo' ? 'package' : 'app-update', title: f.value, date: f.firstSeen, url: f.url, company, score: f.score, detail: `${f.kind}${f.reasons.length ? `: ${f.reasons.join('; ')}` : ''}` });
|
|
33
|
+
}
|
|
34
|
+
// Re-label web footprints with their real kind for display.
|
|
35
|
+
for (const it of items)
|
|
36
|
+
if (it.detail?.startsWith('subdomain'))
|
|
37
|
+
it.kind = 'subdomain';
|
|
38
|
+
for (const it of items)
|
|
39
|
+
if (it.detail?.startsWith('page'))
|
|
40
|
+
it.kind = 'page';
|
|
41
|
+
for (const it of items)
|
|
42
|
+
if (it.detail?.startsWith('repo'))
|
|
43
|
+
it.kind = 'repo';
|
|
44
|
+
// New things first (models, apps, packages, hosts, repos), routine app updates after; newest first within each.
|
|
45
|
+
items.sort((a, b) => Number(a.kind === 'app-update') - Number(b.kind === 'app-update') || b.date.localeCompare(a.date));
|
|
46
|
+
const nowIso = new Date(nowMs).toISOString();
|
|
47
|
+
const fresh = items.filter((i) => nowMs - Date.parse(i.date) <= 3 * DAY_MS && i.kind !== 'app-update' && i.score >= 50);
|
|
48
|
+
const signals = fresh.slice(0, 5).map((i) => ({
|
|
49
|
+
id: signalId('launch', company, i.kind, i.title),
|
|
50
|
+
module: 'launch',
|
|
51
|
+
title: `${company}: new ${i.kind} ${i.title.slice(0, 100)}`,
|
|
52
|
+
score: Math.min(85, i.score + 10),
|
|
53
|
+
evidence: [{ source: i.kind, text: `${i.title}${i.detail ? ` — ${i.detail}` : ''} (${i.date.slice(0, 10)})`, url: i.url }],
|
|
54
|
+
createdAt: nowIso,
|
|
55
|
+
}));
|
|
56
|
+
signals.forEach((s) => ctx.graph.saveSignal(s));
|
|
57
|
+
const cid = ctx.graph.upsert('company', company);
|
|
58
|
+
for (const i of items.filter((x) => x.kind === 'model').slice(0, 10))
|
|
59
|
+
ctx.graph.link(cid, ctx.graph.upsert('repo', i.title, { url: i.url }), 'released_model', 'huggingface');
|
|
60
|
+
return { module: 'launch', input: company, generatedAt: nowIso, result: { company, domain, org, windowDays: days, items }, signals, provenance };
|
|
61
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Listen: turn audio into evidence. Transcribes any public audio or video file URL with Deepgram (pay per
|
|
3
|
+
* minute; free starting credit), then reports a summary, topics, and every passage that mentions the subject
|
|
4
|
+
* with its timestamp. `podcast()` finds recent episodes about a subject through the iTunes podcast directory
|
|
5
|
+
* and transcribes the newest one.
|
|
6
|
+
*/
|
|
7
|
+
import { type Ctx } from '../core/context.js';
|
|
8
|
+
import type { ModuleResult, Provenance } from '../core/types.js';
|
|
9
|
+
export interface Passage {
|
|
10
|
+
start: number;
|
|
11
|
+
text: string;
|
|
12
|
+
}
|
|
13
|
+
export interface Transcript {
|
|
14
|
+
url: string;
|
|
15
|
+
title: string | null;
|
|
16
|
+
durationSec: number;
|
|
17
|
+
language: string | null;
|
|
18
|
+
summary: string | null;
|
|
19
|
+
topics: string[];
|
|
20
|
+
words: number;
|
|
21
|
+
mentions: Passage[];
|
|
22
|
+
/** First passages, to read the opening. */
|
|
23
|
+
opening: Passage[];
|
|
24
|
+
}
|
|
25
|
+
export declare const fmtTime: (s: number) => string;
|
|
26
|
+
/** Sentences that mention any keyword of the subject, merged when close together. */
|
|
27
|
+
export declare function findMentions(sentences: {
|
|
28
|
+
text: string;
|
|
29
|
+
start: number;
|
|
30
|
+
}[], subject: string, max?: number): Passage[];
|
|
31
|
+
export declare function transcribe(ctx: Ctx, url: string, subject?: string, title?: string | null): Promise<ModuleResult<Transcript | null>>;
|
|
32
|
+
export interface Episode {
|
|
33
|
+
show: string;
|
|
34
|
+
title: string;
|
|
35
|
+
date: string;
|
|
36
|
+
audioUrl: string;
|
|
37
|
+
pageUrl: string | null;
|
|
38
|
+
}
|
|
39
|
+
/** Recent podcast episodes about a subject (iTunes directory, free), newest first. */
|
|
40
|
+
export declare function findEpisodes(ctx: Ctx, subject: string, max?: number): Promise<{
|
|
41
|
+
data: Episode[];
|
|
42
|
+
prov: Provenance;
|
|
43
|
+
}>;
|
|
44
|
+
export declare function podcast(ctx: Ctx, subject: string, pick?: number): Promise<ModuleResult<{
|
|
45
|
+
episodes: Episode[];
|
|
46
|
+
transcript: Transcript | null;
|
|
47
|
+
picked: Episode | null;
|
|
48
|
+
}>>;
|