oculon 0.1.6 → 0.1.7
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/README.md +24 -8
- package/dist/cli/main.js +82 -0
- package/dist/core/calls.d.ts +63 -0
- package/dist/core/calls.js +120 -0
- package/dist/core/http.d.ts +11 -0
- package/dist/core/http.js +110 -30
- package/dist/core/pdf.d.ts +51 -0
- package/dist/core/pdf.js +211 -0
- package/dist/core/verdict.d.ts +30 -0
- package/dist/core/verdict.js +164 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +29 -0
- package/dist/mcp.d.ts +1 -0
- package/dist/mcp.js +129 -5
- package/dist/modules/checks.d.ts +59 -0
- package/dist/modules/checks.js +134 -0
- package/dist/modules/doc.d.ts +61 -0
- package/dist/modules/doc.js +715 -0
- package/dist/modules/utility.d.ts +27 -1
- package/dist/modules/utility.js +108 -11
- package/dist/report-pdf.d.ts +7 -0
- package/dist/report-pdf.js +81 -0
- package/dist/web/card.d.ts +28 -0
- package/dist/web/card.js +75 -0
- package/dist/web/index.html +76 -4
- package/dist/web/openapi.js +2 -0
- package/dist/web/pages.d.ts +24 -0
- package/dist/web/pages.js +139 -0
- package/dist/web/public.js +2 -0
- package/dist/web/server.js +84 -10
- package/dist/web/token.html +2 -1
- package/dist/web/utility.html +40 -14
- package/package.json +1 -1
package/dist/mcp.js
CHANGED
|
@@ -2,12 +2,17 @@
|
|
|
2
2
|
* Oculon MCP server over stdio (JSON-RPC 2.0, one message per line). No dependencies.
|
|
3
3
|
* Lets Claude and other MCP clients call every Oculon module as a tool.
|
|
4
4
|
*/
|
|
5
|
+
import { createHash } from 'node:crypto';
|
|
5
6
|
import { readFileSync } from 'node:fs';
|
|
6
7
|
import { createInterface } from 'node:readline';
|
|
7
8
|
import { Oculon, summarizeProvenance } from './index.js';
|
|
8
9
|
import { ONCHAIN_TOOLS, onchainEnabled } from './core/features.js';
|
|
9
10
|
import { availableKinds } from './modules/monitor.js';
|
|
10
|
-
|
|
11
|
+
import { CHECK_TOOLS } from './modules/checks.js';
|
|
12
|
+
import { DOC_MAX_BYTES } from './modules/doc.js';
|
|
13
|
+
import { briefOf, verdictOf } from './core/verdict.js';
|
|
14
|
+
import { CARD_HTML, CARD_URI, CARD_URI_OPENAI, MCP_APP_MIME, SKYBRIDGE_MIME } from './web/card.js';
|
|
15
|
+
export const SERVER_INFO = { name: 'oculon', version: '0.1.7' };
|
|
11
16
|
const SUPPORTED = ['2025-06-18', '2025-03-26', '2024-11-05'];
|
|
12
17
|
const str = (d) => ({ type: 'string', description: d });
|
|
13
18
|
const num = (d) => ({ type: 'number', description: d });
|
|
@@ -55,6 +60,51 @@ export function checkArgs(inputSchema, args) {
|
|
|
55
60
|
function compact(r) {
|
|
56
61
|
return { module: r.module, input: r.input, generatedAt: r.generatedAt, result: r.result, signals: r.signals, provenance: summarizeProvenance(r.provenance) };
|
|
57
62
|
}
|
|
63
|
+
/** File bytes for the document check: base64, or an https URL on a public host. */
|
|
64
|
+
async function docBytes(o, a) {
|
|
65
|
+
if (a.data) {
|
|
66
|
+
const b64 = String(a.data).replace(/^data:[^;]+;base64,/, '').replace(/\s+/g, '');
|
|
67
|
+
if (b64.length > Math.ceil(DOC_MAX_BYTES / 3) * 4 + 4)
|
|
68
|
+
throw new Error('the file is larger than 10 MB');
|
|
69
|
+
return Buffer.from(b64, 'base64');
|
|
70
|
+
}
|
|
71
|
+
if (!a.url)
|
|
72
|
+
throw new Error('give the file as data (base64) or url');
|
|
73
|
+
let u;
|
|
74
|
+
try {
|
|
75
|
+
u = new URL(String(a.url));
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
throw new Error('not a valid URL');
|
|
79
|
+
}
|
|
80
|
+
// Public https hosts only: no addresses, no internal names.
|
|
81
|
+
if (u.protocol !== 'https:' || /^(\d+\.){3}\d+$|^\[|^localhost$|\.(local|internal|localhost|lan|home|corp)$/i.test(u.hostname) || !u.hostname.includes('.'))
|
|
82
|
+
throw new Error('only https links to public hosts are fetched');
|
|
83
|
+
const r = await o.ctx.http.getBytes(u.href, { source: 'doc-download', timeoutMs: 30_000, retries: 0 });
|
|
84
|
+
if (!r.data)
|
|
85
|
+
throw new Error(`could not download the file (${r.prov.note ?? r.prov.status})`);
|
|
86
|
+
if (r.data.length > DOC_MAX_BYTES)
|
|
87
|
+
throw new Error('the file is larger than 10 MB');
|
|
88
|
+
return r.data;
|
|
89
|
+
}
|
|
90
|
+
/** The verdict card data a chat app renders next to a check result. */
|
|
91
|
+
function cardOf(kind, out, check, baseUrl) {
|
|
92
|
+
const v = verdictOf(out);
|
|
93
|
+
return {
|
|
94
|
+
kind,
|
|
95
|
+
title: v.title,
|
|
96
|
+
verdict: v.verdict,
|
|
97
|
+
tone: v.tone,
|
|
98
|
+
risk: v.risk,
|
|
99
|
+
points: v.points.slice(0, 6),
|
|
100
|
+
sources: `${v.sources.live} live, ${v.sources.cached} cached, ${v.sources.failed} failed`,
|
|
101
|
+
seenBefore: check.seenBefore ? { at: check.seenBefore.at, changes: check.seenBefore.changes } : null,
|
|
102
|
+
links: { replay: baseUrl ? baseUrl + check.replay : null, report: baseUrl ? baseUrl + check.report : null },
|
|
103
|
+
checkId: check.id,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** Tool definitions with UI templates for the chat apps that render them (MCP Apps, ChatGPT apps). */
|
|
107
|
+
const UI_META = { ui: { resourceUri: CARD_URI }, 'ui/resourceUri': CARD_URI, 'openai/outputTemplate': CARD_URI_OPENAI, 'openai/toolInvocation/invoking': 'Checking sources', 'openai/toolInvocation/invoked': 'Checked', 'openai/widgetAccessible': false };
|
|
58
108
|
export const TOOLS = [
|
|
59
109
|
{
|
|
60
110
|
name: 'oculon_radar',
|
|
@@ -327,6 +377,32 @@ export const TOOLS = [
|
|
|
327
377
|
inputSchema: schema({ address: str('Crypto address'), network: str('Optional for 0x addresses: "robinhood" for Robinhood Chain, default Ethereum') }, ['address']),
|
|
328
378
|
run: async (o, a) => compact(await o.addressCheck(String(a.address), a.network ? { network: String(a.network) } : {})),
|
|
329
379
|
},
|
|
380
|
+
{
|
|
381
|
+
name: 'oculon_doc_check',
|
|
382
|
+
description: 'Was this invoice, bank statement or payment screenshot edited? Reads a PDF, JPEG or PNG: the programs that made and saved it (online PDF editors, image editors), creation vs modification date, how many times it was saved, fonts embedded twice, white boxes over text, annotations, dangerous parts (JavaScript, launch actions), and checks every IBAN in its text. Screenshots are read with a free AI vision model when a key is set. A clean result is not proof the document is genuine.',
|
|
383
|
+
inputSchema: schema({ data: str('The file as base64 (max 10 MB)'), url: str('Or an https URL of the file'), name: str('File name, for display') }),
|
|
384
|
+
run: async (o, a) => {
|
|
385
|
+
const file = await docBytes(o, a);
|
|
386
|
+
return compact(await o.docCheck(file, a.name ? String(a.name) : a.url ? String(a.url).split('/').pop().split('?')[0] : 'document'));
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
name: 'oculon_replay',
|
|
391
|
+
description: 'Replay log of an earlier check by its check id: the verdict, what changed since the check before it, and every source called in order with status and time.',
|
|
392
|
+
inputSchema: schema({ id: str('Check id, as returned in check.id') }, ['id']),
|
|
393
|
+
run: (o, a) => {
|
|
394
|
+
const c = o.check(String(a.id));
|
|
395
|
+
if (!c)
|
|
396
|
+
throw new Error('no such check (ids are kept for 90 days)');
|
|
397
|
+
return { id: c.id, kind: c.kind, target: c.label, checkedAt: c.createdAt, durationMs: c.durationMs, verdict: c.verdict, seenBefore: c.seenBefore, calls: c.calls, history: o.checkHistory(c.id) };
|
|
398
|
+
},
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
name: 'oculon_status',
|
|
402
|
+
description: 'Which Oculon sources are up, slow, degraded or down, from real calls in the last hours: success rate, median time, last error, and sources being skipped (a mirror or cached data answers instead).',
|
|
403
|
+
inputSchema: schema({ hours: num('Window in hours (default 24, max 48)') }),
|
|
404
|
+
run: (o, a) => ({ hours: Math.min(48, Number(a.hours ?? 24) || 24), sources: o.sourceStatus(Math.min(48, Number(a.hours ?? 24) || 24)) }),
|
|
405
|
+
},
|
|
330
406
|
{
|
|
331
407
|
name: 'oculon_satellites',
|
|
332
408
|
description: 'Satellites from CelesTrak. Leave query empty for everything launched in the last 30 days, grouped by launch. Or pass a satellite name ("ISS", "starlink-1007") or NORAD catalog number for its orbit (perigee, apogee, period, inclination, regime), owner, launch date and status.',
|
|
@@ -704,15 +780,37 @@ export class McpServer {
|
|
|
704
780
|
const asked = String(msg.params?.protocolVersion ?? '');
|
|
705
781
|
return reply({
|
|
706
782
|
protocolVersion: SUPPORTED.includes(asked) ? asked : SUPPORTED[0],
|
|
707
|
-
capabilities: { tools: { listChanged: false } },
|
|
783
|
+
capabilities: { tools: { listChanged: false }, resources: { listChanged: false } },
|
|
708
784
|
serverInfo: SERVER_INFO,
|
|
709
|
-
instructions: 'Oculon is an OSINT engine. Every result includes provenance (LIVE/CACHED/UNAVAILABLE/ERROR per source). Report data as given; do not present ERROR or UNAVAILABLE sources as findings.',
|
|
785
|
+
instructions: 'Oculon is an OSINT engine. Every result includes provenance (LIVE/CACHED/UNAVAILABLE/ERROR per source). Report data as given; do not present ERROR or UNAVAILABLE sources as findings. Pass brief: true to any tool for a short answer. Check tools return check.id; oculon_replay shows every source call of a check.',
|
|
710
786
|
});
|
|
711
787
|
}
|
|
712
788
|
case 'ping':
|
|
713
789
|
return reply({});
|
|
714
790
|
case 'tools/list':
|
|
715
|
-
return reply({
|
|
791
|
+
return reply({
|
|
792
|
+
tools: (await this.allTools()).map(({ name, description, inputSchema }) => ({
|
|
793
|
+
name,
|
|
794
|
+
description,
|
|
795
|
+
inputSchema: { ...inputSchema, properties: { ...(inputSchema.properties ?? {}), brief: { type: 'boolean', description: 'Short answer for agents: verdict, risk, top reasons, sources and check id (fewer tokens)' } } },
|
|
796
|
+
...(CHECK_TOOLS[name] ? { _meta: UI_META } : {}),
|
|
797
|
+
})),
|
|
798
|
+
});
|
|
799
|
+
case 'resources/list':
|
|
800
|
+
return reply({ resources: [
|
|
801
|
+
{ uri: CARD_URI, name: 'Oculon verdict card', mimeType: MCP_APP_MIME, description: 'Verdict, risk, reasons and sources of a check' },
|
|
802
|
+
{ uri: CARD_URI_OPENAI, name: 'Oculon verdict card (ChatGPT)', mimeType: SKYBRIDGE_MIME, description: 'Verdict, risk, reasons and sources of a check' },
|
|
803
|
+
] });
|
|
804
|
+
case 'resources/templates/list':
|
|
805
|
+
return reply({ resourceTemplates: [] });
|
|
806
|
+
case 'resources/read': {
|
|
807
|
+
const uri = String(msg.params?.uri ?? '');
|
|
808
|
+
if (uri !== CARD_URI && uri !== CARD_URI_OPENAI)
|
|
809
|
+
return fail(-32002, `resource not found: ${uri}`);
|
|
810
|
+
const base = this.opts.baseUrl;
|
|
811
|
+
const domains = base && /^https:/.test(base) ? [base] : [];
|
|
812
|
+
return reply({ contents: [{ uri, mimeType: uri === CARD_URI ? MCP_APP_MIME : SKYBRIDGE_MIME, text: CARD_HTML, _meta: { ui: { csp: { connectDomains: [], resourceDomains: [] }, prefersBorder: false }, 'openai/widgetDescription': 'Oculon verdict for the check above, with its reasons and sources.', 'openai/widgetPrefersBorder': false, 'openai/widgetCSP': { connect_domains: [], resource_domains: [] }, ...(domains.length ? { 'openai/widgetDomain': domains[0] } : {}) } }] });
|
|
813
|
+
}
|
|
716
814
|
case 'tools/call': {
|
|
717
815
|
const name = String(msg.params?.name ?? '');
|
|
718
816
|
const tool = (await this.allTools()).find((t) => t.name === name);
|
|
@@ -721,6 +819,8 @@ export class McpServer {
|
|
|
721
819
|
const raw = msg.params?.arguments ?? {};
|
|
722
820
|
if (typeof raw !== 'object' || raw === null || Array.isArray(raw))
|
|
723
821
|
return reply({ content: [{ type: 'text', text: 'Error: arguments must be a JSON object' }], isError: true });
|
|
822
|
+
const brief = raw.brief === true;
|
|
823
|
+
delete raw.brief;
|
|
724
824
|
const bad = checkArgs(tool.inputSchema, raw);
|
|
725
825
|
if (bad)
|
|
726
826
|
return reply({ content: [{ type: 'text', text: `Error: ${bad}` }], isError: true });
|
|
@@ -728,7 +828,31 @@ export class McpServer {
|
|
|
728
828
|
const args = raw;
|
|
729
829
|
if (this.opts.remote && name === 'oculon_monitor')
|
|
730
830
|
args.dry_run = true;
|
|
731
|
-
const
|
|
831
|
+
const ck = CHECK_TOOLS[name];
|
|
832
|
+
let out;
|
|
833
|
+
let check = null;
|
|
834
|
+
if (ck) {
|
|
835
|
+
// Checks are kept: a check id, a replay log, and what changed since the last check of the same thing.
|
|
836
|
+
const target = name === 'oculon_doc_check' ? String(args.url ?? '') || createHash('sha256').update(String(args.data ?? '')).digest('hex') : String(args[ck.arg] ?? '');
|
|
837
|
+
const label = name === 'oculon_doc_check' ? String(args.name ?? args.url ?? 'document').slice(0, 90) : undefined;
|
|
838
|
+
const r = await this.o.recordCheck(ck.kind, target, async () => tool.run(this.o, args), label ? { label } : {});
|
|
839
|
+
out = r.value;
|
|
840
|
+
check = r.check;
|
|
841
|
+
const base = this.opts.baseUrl;
|
|
842
|
+
const meta = { id: check.id, seenBefore: check.seenBefore, replay: base ? base + check.replay : `oculon replay ${check.id}`, report: base ? base + check.report : `oculon replay ${check.id} --pdf report.pdf` };
|
|
843
|
+
if (out && typeof out === 'object')
|
|
844
|
+
out = { ...out, check: meta };
|
|
845
|
+
}
|
|
846
|
+
else {
|
|
847
|
+
out = await tool.run(this.o, args);
|
|
848
|
+
}
|
|
849
|
+
if (brief && !(out && typeof out === 'object' && '__image' in out)) {
|
|
850
|
+
const c = out?.check;
|
|
851
|
+
out = briefOf(out, c ? { check: { id: c.id, replay: c.replay, ...(c.seenBefore ? { changedSinceLast: c.seenBefore.changes } : {}) } } : {});
|
|
852
|
+
}
|
|
853
|
+
if (check) {
|
|
854
|
+
return reply({ content: [{ type: 'text', text: JSON.stringify(out) }], structuredContent: cardOf(ck.kind, out, check, this.opts.baseUrl), _meta: { 'openai/outputTemplate': CARD_URI_OPENAI } });
|
|
855
|
+
}
|
|
732
856
|
if (out && typeof out === 'object' && '__image' in out) {
|
|
733
857
|
const { __image, meta } = out;
|
|
734
858
|
const content = [{ type: 'text', text: JSON.stringify(meta) }];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Ctx } from '../core/context.js';
|
|
2
|
+
import { type CallEntry } from '../core/calls.js';
|
|
3
|
+
import { type Verdict } from '../core/verdict.js';
|
|
4
|
+
export interface SeenBefore {
|
|
5
|
+
id: string;
|
|
6
|
+
at: string;
|
|
7
|
+
verdict: string | null;
|
|
8
|
+
/** Plain-word changes since that check; empty when nothing changed. */
|
|
9
|
+
changes: string[];
|
|
10
|
+
}
|
|
11
|
+
export interface CheckMeta {
|
|
12
|
+
id: string;
|
|
13
|
+
kind: string;
|
|
14
|
+
seenBefore: SeenBefore | null;
|
|
15
|
+
replay: string;
|
|
16
|
+
report: string;
|
|
17
|
+
}
|
|
18
|
+
export interface CheckRecord {
|
|
19
|
+
id: string;
|
|
20
|
+
kind: string;
|
|
21
|
+
label: string;
|
|
22
|
+
createdAt: string;
|
|
23
|
+
durationMs: number;
|
|
24
|
+
verdict: Verdict;
|
|
25
|
+
calls: CallEntry[];
|
|
26
|
+
seenBefore: SeenBefore | null;
|
|
27
|
+
/** The full result as returned, or null when it was too large to keep. */
|
|
28
|
+
result: unknown;
|
|
29
|
+
}
|
|
30
|
+
export declare const targetKey: (kind: string, target: string) => string;
|
|
31
|
+
/** Long inputs (a pasted message, raw headers) are shown by their start only. */
|
|
32
|
+
export declare function labelFor(target: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Run a check, keep its verdict and source calls, and compare it with the last check of the same target.
|
|
35
|
+
* `target` identifies what was checked (it is hashed for matching); `label` is what pages show.
|
|
36
|
+
*/
|
|
37
|
+
export declare function recordCheck<T>(ctx: Ctx, kind: string, target: string, run: () => Promise<T>, opts?: {
|
|
38
|
+
label?: string;
|
|
39
|
+
}): Promise<{
|
|
40
|
+
value: T;
|
|
41
|
+
check: CheckMeta;
|
|
42
|
+
}>;
|
|
43
|
+
export declare function getCheck(ctx: Ctx, id: string): CheckRecord | null;
|
|
44
|
+
/** Earlier checks of the same target, newest first (for "history" on the replay page). */
|
|
45
|
+
export declare function checkHistory(ctx: Ctx, id: string, limit?: number): {
|
|
46
|
+
id: string;
|
|
47
|
+
at: string;
|
|
48
|
+
verdict: string | null;
|
|
49
|
+
risk: number | null;
|
|
50
|
+
}[];
|
|
51
|
+
/** Checks Oculon records, by web route and by MCP tool, with how to read the target from the input. */
|
|
52
|
+
export declare const CHECK_ROUTES: Record<string, {
|
|
53
|
+
kind: string;
|
|
54
|
+
param: string;
|
|
55
|
+
}>;
|
|
56
|
+
export declare const CHECK_TOOLS: Record<string, {
|
|
57
|
+
kind: string;
|
|
58
|
+
arg: string;
|
|
59
|
+
}>;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check history: every check (scam, link, IBAN, document, token...) is stored with its verdict and the source calls
|
|
3
|
+
* it made. That gives three features:
|
|
4
|
+
* - seen before: checking the same thing again says what changed since last time;
|
|
5
|
+
* - replay log: /replay/<id> shows every source called, when, how long it took and what it answered;
|
|
6
|
+
* - PDF report: /report/<id>.pdf is one investigation as a file to send on.
|
|
7
|
+
* Ids are random (96 bits) so a replay link is only known to whoever ran the check. Kept for 90 days.
|
|
8
|
+
*/
|
|
9
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
10
|
+
import { withCallLog } from '../core/calls.js';
|
|
11
|
+
import { verdictChanges, verdictOf } from '../core/verdict.js';
|
|
12
|
+
const KEEP_DAYS = 90;
|
|
13
|
+
const MAX_RESULT = 300_000;
|
|
14
|
+
const ensured = new WeakSet();
|
|
15
|
+
function db(ctx) {
|
|
16
|
+
const d = ctx.store.db;
|
|
17
|
+
if (!ensured.has(d)) {
|
|
18
|
+
d.exec(`CREATE TABLE IF NOT EXISTS checks (id TEXT PRIMARY KEY, kind TEXT NOT NULL, target_key TEXT NOT NULL, label TEXT NOT NULL, created_at INTEGER NOT NULL, duration_ms INTEGER NOT NULL, verdict TEXT NOT NULL, calls TEXT NOT NULL, seen_before TEXT, result TEXT);
|
|
19
|
+
CREATE INDEX IF NOT EXISTS checks_target ON checks (target_key, created_at);`);
|
|
20
|
+
ensured.add(d);
|
|
21
|
+
}
|
|
22
|
+
return d;
|
|
23
|
+
}
|
|
24
|
+
export const targetKey = (kind, target) => createHash('sha256').update(`${kind}\n${target.trim().toLowerCase().replace(/\s+/g, ' ')}`).digest('hex').slice(0, 32);
|
|
25
|
+
/** Long inputs (a pasted message, raw headers) are shown by their start only. */
|
|
26
|
+
export function labelFor(target) {
|
|
27
|
+
const t = target.replace(/\s+/g, ' ').trim();
|
|
28
|
+
return t.length > 90 ? `${t.slice(0, 87)}...` : t;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Run a check, keep its verdict and source calls, and compare it with the last check of the same target.
|
|
32
|
+
* `target` identifies what was checked (it is hashed for matching); `label` is what pages show.
|
|
33
|
+
*/
|
|
34
|
+
export async function recordCheck(ctx, kind, target, run, opts = {}) {
|
|
35
|
+
const t0 = Date.now();
|
|
36
|
+
const { value, calls } = await withCallLog(run);
|
|
37
|
+
const durationMs = Date.now() - t0;
|
|
38
|
+
const d = db(ctx);
|
|
39
|
+
const key = targetKey(kind, target);
|
|
40
|
+
const label = opts.label ?? labelFor(target);
|
|
41
|
+
const verdict = verdictOf(value, label);
|
|
42
|
+
const nowMs = ctx.now().getTime();
|
|
43
|
+
const prev = d.prepare('SELECT id, created_at, verdict FROM checks WHERE target_key = ? ORDER BY created_at DESC LIMIT 1').get(key);
|
|
44
|
+
let seenBefore = null;
|
|
45
|
+
if (prev) {
|
|
46
|
+
const was = JSON.parse(prev.verdict);
|
|
47
|
+
seenBefore = { id: prev.id, at: new Date(prev.created_at).toISOString(), verdict: was.verdict, changes: verdictChanges(was, verdict) };
|
|
48
|
+
}
|
|
49
|
+
const id = randomBytes(12).toString('base64url');
|
|
50
|
+
let result = JSON.stringify(value);
|
|
51
|
+
if (result.length > MAX_RESULT)
|
|
52
|
+
result = null;
|
|
53
|
+
d.prepare('INSERT INTO checks (id, kind, target_key, label, created_at, duration_ms, verdict, calls, seen_before, result) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').run(id, kind, key, label, nowMs, durationMs, JSON.stringify(verdict), JSON.stringify(calls), seenBefore ? JSON.stringify(seenBefore) : null, result);
|
|
54
|
+
if (Math.random() < 0.02)
|
|
55
|
+
d.prepare('DELETE FROM checks WHERE created_at < ?').run(nowMs - KEEP_DAYS * 86_400_000);
|
|
56
|
+
return { value, check: { id, kind, seenBefore, replay: `/replay/${id}`, report: `/report/${id}.pdf` } };
|
|
57
|
+
}
|
|
58
|
+
export function getCheck(ctx, id) {
|
|
59
|
+
if (!/^[A-Za-z0-9_-]{10,40}$/.test(id))
|
|
60
|
+
return null;
|
|
61
|
+
const r = db(ctx).prepare('SELECT * FROM checks WHERE id = ?').get(id);
|
|
62
|
+
if (!r)
|
|
63
|
+
return null;
|
|
64
|
+
return {
|
|
65
|
+
id: String(r.id),
|
|
66
|
+
kind: String(r.kind),
|
|
67
|
+
label: String(r.label),
|
|
68
|
+
createdAt: new Date(Number(r.created_at)).toISOString(),
|
|
69
|
+
durationMs: Number(r.duration_ms),
|
|
70
|
+
verdict: JSON.parse(String(r.verdict)),
|
|
71
|
+
calls: JSON.parse(String(r.calls)),
|
|
72
|
+
seenBefore: r.seen_before ? JSON.parse(String(r.seen_before)) : null,
|
|
73
|
+
result: r.result ? JSON.parse(String(r.result)) : null,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** Earlier checks of the same target, newest first (for "history" on the replay page). */
|
|
77
|
+
export function checkHistory(ctx, id, limit = 10) {
|
|
78
|
+
const d = db(ctx);
|
|
79
|
+
const row = d.prepare('SELECT target_key FROM checks WHERE id = ?').get(id);
|
|
80
|
+
if (!row)
|
|
81
|
+
return [];
|
|
82
|
+
const rows = d.prepare('SELECT id, created_at, verdict FROM checks WHERE target_key = ? ORDER BY created_at DESC LIMIT ?').all(row.target_key, limit);
|
|
83
|
+
return rows.map((r) => {
|
|
84
|
+
const v = JSON.parse(r.verdict);
|
|
85
|
+
return { id: r.id, at: new Date(r.created_at).toISOString(), verdict: v.verdict, risk: v.risk };
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/** Checks Oculon records, by web route and by MCP tool, with how to read the target from the input. */
|
|
89
|
+
export const CHECK_ROUTES = {
|
|
90
|
+
'/api/scam': { kind: 'scam', param: 'message' },
|
|
91
|
+
'/api/url': { kind: 'url', param: 'url' },
|
|
92
|
+
'/api/iban': { kind: 'iban', param: 'iban' },
|
|
93
|
+
'/api/lookalike': { kind: 'lookalike', param: 'domain' },
|
|
94
|
+
'/api/honeypot': { kind: 'honeypot', param: 'address' },
|
|
95
|
+
'/api/address': { kind: 'address', param: 'address' },
|
|
96
|
+
'/api/phone': { kind: 'phone', param: 'number' },
|
|
97
|
+
'/api/ip': { kind: 'ip', param: 'ip' },
|
|
98
|
+
'/api/hash': { kind: 'hash', param: 'hash' },
|
|
99
|
+
'/api/emailsec': { kind: 'emailsec', param: 'domain' },
|
|
100
|
+
'/api/company': { kind: 'company', param: 'q' },
|
|
101
|
+
'/api/token': { kind: 'token', param: 'address' },
|
|
102
|
+
'/api/rhtoken': { kind: 'rhtoken', param: 'address' },
|
|
103
|
+
'/api/wallet': { kind: 'wallet', param: 'address' },
|
|
104
|
+
'/api/sanctions': { kind: 'sanctions', param: 'q' },
|
|
105
|
+
'/api/factcheck': { kind: 'factcheck', param: 'claim' },
|
|
106
|
+
'/api/recall': { kind: 'recall', param: 'q' },
|
|
107
|
+
'/api/travel': { kind: 'travel', param: 'place' },
|
|
108
|
+
'/api/cve': { kind: 'cve', param: 'id' },
|
|
109
|
+
'/api/exposure': { kind: 'exposure', param: 'domain' },
|
|
110
|
+
};
|
|
111
|
+
export const CHECK_TOOLS = {
|
|
112
|
+
oculon_scam_check: { kind: 'scam', arg: 'message' },
|
|
113
|
+
oculon_url_check: { kind: 'url', arg: 'url' },
|
|
114
|
+
oculon_iban_check: { kind: 'iban', arg: 'iban' },
|
|
115
|
+
oculon_email_headers: { kind: 'headers', arg: 'headers' },
|
|
116
|
+
oculon_lookalike_domains: { kind: 'lookalike', arg: 'domain' },
|
|
117
|
+
oculon_honeypot_check: { kind: 'honeypot', arg: 'address' },
|
|
118
|
+
oculon_address_check: { kind: 'address', arg: 'address' },
|
|
119
|
+
oculon_phone_check: { kind: 'phone', arg: 'number' },
|
|
120
|
+
oculon_ip_check: { kind: 'ip', arg: 'ip' },
|
|
121
|
+
oculon_hash_check: { kind: 'hash', arg: 'hash' },
|
|
122
|
+
oculon_email_security: { kind: 'emailsec', arg: 'domain' },
|
|
123
|
+
oculon_company_lookup: { kind: 'company', arg: 'query' },
|
|
124
|
+
oculon_token: { kind: 'token', arg: 'address' },
|
|
125
|
+
oculon_robinhood_token: { kind: 'rhtoken', arg: 'address' },
|
|
126
|
+
oculon_wallet: { kind: 'wallet', arg: 'address' },
|
|
127
|
+
oculon_sanctions: { kind: 'sanctions', arg: 'query' },
|
|
128
|
+
oculon_fact_check: { kind: 'factcheck', arg: 'claim' },
|
|
129
|
+
oculon_recall: { kind: 'recall', arg: 'query' },
|
|
130
|
+
oculon_travel: { kind: 'travel', arg: 'place' },
|
|
131
|
+
oculon_cve: { kind: 'cve', arg: 'id' },
|
|
132
|
+
oculon_exposure: { kind: 'exposure', arg: 'domain' },
|
|
133
|
+
oculon_doc_check: { kind: 'doc', arg: 'name' },
|
|
134
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Ctx } from '../core/context.js';
|
|
2
|
+
import type { ModuleResult } from '../core/types.js';
|
|
3
|
+
export interface DocIban {
|
|
4
|
+
iban: string;
|
|
5
|
+
valid: boolean;
|
|
6
|
+
country: string | null;
|
|
7
|
+
problems: string[];
|
|
8
|
+
}
|
|
9
|
+
export interface DocResult {
|
|
10
|
+
name: string;
|
|
11
|
+
type: 'pdf' | 'jpeg' | 'png';
|
|
12
|
+
bytes: number;
|
|
13
|
+
sha256: string;
|
|
14
|
+
verdict: 'dangerous file' | 'likely edited' | 'signs of editing' | 'no signs of editing found';
|
|
15
|
+
risk: number;
|
|
16
|
+
flags: string[];
|
|
17
|
+
notes: string[];
|
|
18
|
+
metadata: Record<string, string>;
|
|
19
|
+
/** PDF: times the file was saved (1 = never changed after it was made). */
|
|
20
|
+
revisions: number | null;
|
|
21
|
+
signed: boolean;
|
|
22
|
+
fonts: string[];
|
|
23
|
+
text: {
|
|
24
|
+
chars: number;
|
|
25
|
+
excerpt: string;
|
|
26
|
+
from: 'text layer' | 'ocr' | 'none';
|
|
27
|
+
};
|
|
28
|
+
ibans: DocIban[];
|
|
29
|
+
domains: string[];
|
|
30
|
+
advice: string[];
|
|
31
|
+
}
|
|
32
|
+
export declare const DOC_MAX_BYTES: number;
|
|
33
|
+
interface PdfObj {
|
|
34
|
+
num: number;
|
|
35
|
+
dict: string;
|
|
36
|
+
stream: Buffer | null;
|
|
37
|
+
/** Raw stream bytes as stored (for images). */
|
|
38
|
+
raw: Buffer | null;
|
|
39
|
+
}
|
|
40
|
+
/** Objects of a PDF, including those packed in object streams. Streams are decoded when they use FlateDecode. */
|
|
41
|
+
export declare function pdfObjects(buf: Buffer): PdfObj[];
|
|
42
|
+
/** A PDF string value: (literal) with escapes, or <hex>, UTF-16 when it starts with a byte order mark. */
|
|
43
|
+
export declare function pdfString(src: string): string;
|
|
44
|
+
/** D:YYYYMMDDHHmmSS+hh'mm' to epoch milliseconds. */
|
|
45
|
+
export declare function pdfDate(s: string | null): number | null;
|
|
46
|
+
interface PdfFont {
|
|
47
|
+
name: string;
|
|
48
|
+
cmap: {
|
|
49
|
+
map: Map<string, string>;
|
|
50
|
+
bytes: number;
|
|
51
|
+
} | null;
|
|
52
|
+
twoByte: boolean;
|
|
53
|
+
}
|
|
54
|
+
/** Text shown by a content stream, plus white filled boxes that are not page backgrounds. */
|
|
55
|
+
export declare function contentText(c: string, fonts: Map<string, PdfFont>): {
|
|
56
|
+
text: string;
|
|
57
|
+
whiteBoxes: number;
|
|
58
|
+
};
|
|
59
|
+
/** Check one document. `name` is only used for display. */
|
|
60
|
+
export declare function docCheck(ctx: Ctx, file: Buffer, name?: string): Promise<ModuleResult<DocResult>>;
|
|
61
|
+
export {};
|