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
package/dist/live.js
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live layer: listens continuously to two free real-time streams and flags things before they become news.
|
|
3
|
+
* Wikipedia EventStreams: an English article suddenly edited by several people (breaking events get edited
|
|
4
|
+
* within minutes, well before page views or articles catch up).
|
|
5
|
+
* Bluesky Jetstream: a name or hashtag in English posts surging against its own last hour; watched topics
|
|
6
|
+
* and companies get a lower bar.
|
|
7
|
+
* Runs inside `oculon serve` (or `oculon live`). State is in memory; signals go to the store and alerts.
|
|
8
|
+
*/
|
|
9
|
+
import { keywords, signalId } from './core/text.js';
|
|
10
|
+
const MIN = 60_000;
|
|
11
|
+
const UA = 'Oculon/0.1 (open-source OSINT engine)';
|
|
12
|
+
const STOP_TERMS = new Set('the and you for that this with have just like what your from they will about when there been more would people their time today good know only really think also because make love need want going still even back much here thank thanks happy look great right last first many most other some year years day days week night morning new now get got one two can all out how why who our was are not but has its his her him she them did does'.split(' '));
|
|
13
|
+
/** Terms worth counting in a post: hashtags and capitalized words or two-word names. */
|
|
14
|
+
export function postTerms(text) {
|
|
15
|
+
const out = new Set();
|
|
16
|
+
for (const m of text.matchAll(/#([\p{L}\p{N}_]{3,40})/gu))
|
|
17
|
+
out.add(`#${m[1].toLowerCase()}`);
|
|
18
|
+
const words = text.replace(/https?:\/\/\S+/g, ' ').split(/[^\p{L}\p{N}'’-]+/u).filter(Boolean);
|
|
19
|
+
for (let i = 0; i < words.length; i++) {
|
|
20
|
+
const w = words[i];
|
|
21
|
+
if (!/^\p{Lu}[\p{L}\p{N}'’-]{2,}$/u.test(w) || STOP_TERMS.has(w.toLowerCase()))
|
|
22
|
+
continue;
|
|
23
|
+
// Skip sentence-initial capitals unless the word is all caps (an acronym).
|
|
24
|
+
const sentenceStart = i === 0 || /[.!?]$/.test(words[i - 1] ?? '');
|
|
25
|
+
const next = words[i + 1];
|
|
26
|
+
if (next && /^\p{Lu}[\p{L}]{2,}$/u.test(next) && !STOP_TERMS.has(next.toLowerCase()))
|
|
27
|
+
out.add(`${w} ${next}`.toLowerCase());
|
|
28
|
+
if (!sentenceStart || w === w.toUpperCase())
|
|
29
|
+
out.add(w.toLowerCase());
|
|
30
|
+
}
|
|
31
|
+
return [...out];
|
|
32
|
+
}
|
|
33
|
+
/** Per-minute counters with a one-hour memory. */
|
|
34
|
+
export class TermCounter {
|
|
35
|
+
buckets = new Map();
|
|
36
|
+
add(term, minute) {
|
|
37
|
+
const b = this.buckets.get(minute) ?? new Map();
|
|
38
|
+
b.set(term, (b.get(term) ?? 0) + 1);
|
|
39
|
+
this.buckets.set(minute, b);
|
|
40
|
+
}
|
|
41
|
+
prune(nowMinute) {
|
|
42
|
+
for (const m of this.buckets.keys())
|
|
43
|
+
if (m < nowMinute - 60)
|
|
44
|
+
this.buckets.delete(m);
|
|
45
|
+
}
|
|
46
|
+
/** Counts in the last `recent` minutes and the per-window average over the rest of the hour. */
|
|
47
|
+
surge(nowMinute, recent = 10) {
|
|
48
|
+
const rec = new Map();
|
|
49
|
+
const old = new Map();
|
|
50
|
+
let oldMinutes = 0;
|
|
51
|
+
for (const [m, b] of this.buckets) {
|
|
52
|
+
const target = m > nowMinute - recent ? rec : old;
|
|
53
|
+
if (target === old)
|
|
54
|
+
oldMinutes++;
|
|
55
|
+
for (const [t, n] of b)
|
|
56
|
+
target.set(t, (target.get(t) ?? 0) + n);
|
|
57
|
+
}
|
|
58
|
+
const windows = Math.max(1, oldMinutes / recent);
|
|
59
|
+
return [...rec].map(([term, n]) => ({ term, recent: n, baseline: (old.get(term) ?? 0) / windows }));
|
|
60
|
+
}
|
|
61
|
+
minutesCovered() {
|
|
62
|
+
return this.buckets.size;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export class LiveMonitor {
|
|
66
|
+
o;
|
|
67
|
+
opts;
|
|
68
|
+
stopped = false;
|
|
69
|
+
wikiEdits = new Map();
|
|
70
|
+
flagged = new Map();
|
|
71
|
+
terms = new TermCounter();
|
|
72
|
+
timer = null;
|
|
73
|
+
ws = null;
|
|
74
|
+
abort = null;
|
|
75
|
+
stats = { wikiEdits: 0, posts: 0, signals: 0, startedAt: new Date().toISOString() };
|
|
76
|
+
constructor(o, opts = {}) {
|
|
77
|
+
this.o = o;
|
|
78
|
+
this.opts = opts;
|
|
79
|
+
}
|
|
80
|
+
log(m) {
|
|
81
|
+
this.opts.log?.(`live ${m}`);
|
|
82
|
+
}
|
|
83
|
+
start() {
|
|
84
|
+
if (this.opts.wiki !== false)
|
|
85
|
+
void this.wikiLoop();
|
|
86
|
+
if (this.opts.bluesky !== false)
|
|
87
|
+
this.blueskyConnect();
|
|
88
|
+
this.timer = setInterval(() => void this.evaluate(), MIN);
|
|
89
|
+
}
|
|
90
|
+
stop() {
|
|
91
|
+
this.stopped = true;
|
|
92
|
+
if (this.timer)
|
|
93
|
+
clearInterval(this.timer);
|
|
94
|
+
this.abort?.abort();
|
|
95
|
+
this.ws?.close();
|
|
96
|
+
}
|
|
97
|
+
async wikiLoop() {
|
|
98
|
+
while (!this.stopped) {
|
|
99
|
+
this.abort = new AbortController();
|
|
100
|
+
try {
|
|
101
|
+
const res = await fetch('https://stream.wikimedia.org/v2/stream/recentchange', { headers: { accept: 'text/event-stream', 'user-agent': UA }, signal: this.abort.signal });
|
|
102
|
+
const dec = new TextDecoder();
|
|
103
|
+
let buf = '';
|
|
104
|
+
for await (const chunk of res.body) {
|
|
105
|
+
buf += dec.decode(chunk, { stream: true });
|
|
106
|
+
let i;
|
|
107
|
+
while ((i = buf.indexOf('\n')) >= 0) {
|
|
108
|
+
const line = buf.slice(0, i);
|
|
109
|
+
buf = buf.slice(i + 1);
|
|
110
|
+
if (!line.startsWith('data:'))
|
|
111
|
+
continue;
|
|
112
|
+
try {
|
|
113
|
+
const e = JSON.parse(line.slice(5));
|
|
114
|
+
if (e.wiki !== 'enwiki' || e.namespace !== 0 || e.type !== 'edit' || e.bot || !e.title)
|
|
115
|
+
continue;
|
|
116
|
+
this.stats.wikiEdits++;
|
|
117
|
+
const list = this.wikiEdits.get(e.title) ?? [];
|
|
118
|
+
list.push({ t: Date.now(), user: e.user ?? '?' });
|
|
119
|
+
this.wikiEdits.set(e.title, list);
|
|
120
|
+
}
|
|
121
|
+
catch { }
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch (e) {
|
|
126
|
+
if (this.stopped)
|
|
127
|
+
return;
|
|
128
|
+
this.log(`wikipedia stream dropped (${e.message}); reconnecting`);
|
|
129
|
+
}
|
|
130
|
+
await new Promise((r) => setTimeout(r, 5000));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
blueskyConnect() {
|
|
134
|
+
if (this.stopped)
|
|
135
|
+
return;
|
|
136
|
+
try {
|
|
137
|
+
this.ws = new WebSocket('wss://jetstream2.us-east.bsky.network/subscribe?wantedCollections=app.bsky.feed.post');
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
setTimeout(() => this.blueskyConnect(), 10_000);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
this.ws.onmessage = (ev) => {
|
|
144
|
+
try {
|
|
145
|
+
const m = JSON.parse(String(ev.data));
|
|
146
|
+
const r = m.commit?.record;
|
|
147
|
+
if (m.commit?.operation !== 'create' || !r?.text || !r.langs?.includes('en'))
|
|
148
|
+
return;
|
|
149
|
+
this.stats.posts++;
|
|
150
|
+
const minute = Math.floor(Date.now() / MIN);
|
|
151
|
+
for (const t of postTerms(r.text))
|
|
152
|
+
this.terms.add(t, minute);
|
|
153
|
+
}
|
|
154
|
+
catch { }
|
|
155
|
+
};
|
|
156
|
+
this.ws.onclose = () => {
|
|
157
|
+
if (!this.stopped)
|
|
158
|
+
setTimeout(() => this.blueskyConnect(), 5000);
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/** Called every minute: decide what is surging. Exposed for tests. */
|
|
162
|
+
async evaluate(nowMs = Date.now()) {
|
|
163
|
+
const signals = [];
|
|
164
|
+
const nowIso = new Date(nowMs).toISOString();
|
|
165
|
+
const fresh = (key) => {
|
|
166
|
+
const last = this.flagged.get(key);
|
|
167
|
+
if (last && nowMs - last < 6 * 3_600_000)
|
|
168
|
+
return false;
|
|
169
|
+
this.flagged.set(key, nowMs);
|
|
170
|
+
return true;
|
|
171
|
+
};
|
|
172
|
+
// Wikipedia: 6+ edits by 3+ different people in 15 minutes.
|
|
173
|
+
for (const [title, list] of this.wikiEdits) {
|
|
174
|
+
const recent = list.filter((e) => nowMs - e.t <= 15 * MIN);
|
|
175
|
+
if (!recent.length) {
|
|
176
|
+
this.wikiEdits.delete(title);
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
this.wikiEdits.set(title, recent);
|
|
180
|
+
const editors = new Set(recent.map((e) => e.user)).size;
|
|
181
|
+
if (recent.length >= 6 && editors >= 3 && !/^(List of|Deaths in|\d{4} in )/.test(title) && fresh(`wiki:${title}`)) {
|
|
182
|
+
signals.push({
|
|
183
|
+
id: signalId('live', 'wiki', title, nowIso.slice(0, 13)),
|
|
184
|
+
module: 'live',
|
|
185
|
+
title: `Edit surge on Wikipedia: ${title} (${recent.length} edits by ${editors} editors in 15 min)`,
|
|
186
|
+
score: Math.min(85, 50 + recent.length * 2 + editors * 3),
|
|
187
|
+
evidence: [{ source: 'wikipedia-live', text: `${recent.length} human edits by ${editors} different editors in the last 15 minutes`, url: `https://en.wikipedia.org/w/index.php?title=${encodeURIComponent(title)}&action=history` }],
|
|
188
|
+
createdAt: nowIso,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// Bluesky: needs at least 20 minutes of history before any baseline means something.
|
|
193
|
+
const minute = Math.floor(nowMs / MIN);
|
|
194
|
+
this.terms.prune(minute);
|
|
195
|
+
if (this.terms.minutesCovered() >= 20) {
|
|
196
|
+
const watched = new Set((this.opts.watchTerms?.() ?? this.o.watchList().filter((w) => w.kind === 'topic' || w.kind === 'company').map((w) => w.target.toLowerCase())).map((t) => t.toLowerCase()));
|
|
197
|
+
for (const s of this.terms.surge(minute)) {
|
|
198
|
+
const isWatched = watched.has(s.term) || [...watched].some((w) => keywords(w).has(s.term));
|
|
199
|
+
const minRecent = isWatched ? 8 : 25;
|
|
200
|
+
const ratio = s.recent / Math.max(1, s.baseline);
|
|
201
|
+
if (s.recent < minRecent || ratio < (isWatched ? 3 : 5))
|
|
202
|
+
continue;
|
|
203
|
+
if (!fresh(`bsky:${s.term}`))
|
|
204
|
+
continue;
|
|
205
|
+
signals.push({
|
|
206
|
+
id: signalId('live', 'bsky', s.term, nowIso.slice(0, 13)),
|
|
207
|
+
module: 'live',
|
|
208
|
+
title: `Surging on Bluesky: "${s.term}" (${s.recent} posts in 10 min, ${ratio.toFixed(0)}x its last hour)${isWatched ? ' [watched]' : ''}`,
|
|
209
|
+
score: Math.min(85, Math.round(45 + Math.log2(ratio) * 6 + (isWatched ? 10 : 0))),
|
|
210
|
+
evidence: [{ source: 'bluesky-live', text: `${s.recent} English posts mention it in 10 minutes vs ~${s.baseline.toFixed(1)} per 10 minutes before`, url: `https://bsky.app/search?q=${encodeURIComponent(s.term)}` }],
|
|
211
|
+
createdAt: nowIso,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// Only the strongest few per minute; streams can be noisy.
|
|
216
|
+
const top = signals.sort((a, b) => b.score - a.score).slice(0, 5);
|
|
217
|
+
for (const s of top)
|
|
218
|
+
this.o.ctx.graph.saveSignal(s);
|
|
219
|
+
this.stats.signals += top.length;
|
|
220
|
+
if (top.length) {
|
|
221
|
+
this.log(`${top.length} live signal(s): ${top.map((s) => s.title.slice(0, 60)).join(' | ')}`);
|
|
222
|
+
await this.opts.onSignals?.(top);
|
|
223
|
+
}
|
|
224
|
+
return top;
|
|
225
|
+
}
|
|
226
|
+
/** Test hooks: feed events without network. */
|
|
227
|
+
_wikiEdit(title, user, t = Date.now()) {
|
|
228
|
+
const l = this.wikiEdits.get(title) ?? [];
|
|
229
|
+
l.push({ t, user });
|
|
230
|
+
this.wikiEdits.set(title, l);
|
|
231
|
+
}
|
|
232
|
+
_post(text, t = Date.now()) {
|
|
233
|
+
for (const term of postTerms(text))
|
|
234
|
+
this.terms.add(term, Math.floor(t / MIN));
|
|
235
|
+
}
|
|
236
|
+
}
|
package/dist/mcp.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Oculon } from './index.js';
|
|
2
|
+
export declare const SERVER_INFO: {
|
|
3
|
+
name: string;
|
|
4
|
+
version: string;
|
|
5
|
+
};
|
|
6
|
+
type Json = Record<string, unknown>;
|
|
7
|
+
export interface Tool {
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
inputSchema: Json;
|
|
11
|
+
run: (o: Oculon, a: Json) => Promise<unknown> | unknown;
|
|
12
|
+
}
|
|
13
|
+
export declare const TOOLS: Tool[];
|
|
14
|
+
interface Request {
|
|
15
|
+
jsonrpc: '2.0';
|
|
16
|
+
id?: number | string | null;
|
|
17
|
+
method: string;
|
|
18
|
+
params?: Json;
|
|
19
|
+
}
|
|
20
|
+
/** Tools this build offers: on-chain tools are left out unless OCULON_ONCHAIN=1. */
|
|
21
|
+
export declare function activeTools(): Tool[];
|
|
22
|
+
export declare class McpServer {
|
|
23
|
+
private readonly makeOculon;
|
|
24
|
+
private readonly opts;
|
|
25
|
+
private oculon;
|
|
26
|
+
/**
|
|
27
|
+
* `remote`: the server is reached over the internet by anyone (remote MCP). Tools that change what the whole
|
|
28
|
+
* install watches are left out, and oculon_monitor only shows how a request would be read.
|
|
29
|
+
*/
|
|
30
|
+
constructor(makeOculon?: () => Oculon, opts?: {
|
|
31
|
+
remote?: boolean;
|
|
32
|
+
});
|
|
33
|
+
private get o();
|
|
34
|
+
private pluginTools;
|
|
35
|
+
/** Built-in tools plus one tool per installed plugin tool (`plugin_<plugin>_<tool>`), loaded once. */
|
|
36
|
+
private allTools;
|
|
37
|
+
/** Handle one JSON-RPC message; returns the response, or null for notifications. */
|
|
38
|
+
handle(msg: Request): Promise<Json | null>;
|
|
39
|
+
close(): void;
|
|
40
|
+
}
|
|
41
|
+
/** Run on stdio. Logs go to stderr so stdout stays pure JSON-RPC. */
|
|
42
|
+
export declare function serveStdio(server?: McpServer): void;
|
|
43
|
+
export {};
|