liquilens 0.5.3 → 0.6.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/README.md +93 -4
- package/dist/api.js +74 -3
- package/dist/cli.js +81 -6
- package/dist/plain.js +91 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,6 +9,11 @@ Need the radar on your own counterparty or borrower book? A fixed-scope,
|
|
|
9
9
|
self-hosted proof pilot is available at
|
|
10
10
|
[liquilens.in/pilot](https://liquilens.in/pilot/).
|
|
11
11
|
|
|
12
|
+
The same command also answers `liquilens lens <name, key or id>`: where
|
|
13
|
+
each product in the family (LiquiLens, Seiche, Undertow, Palimpsest) holds
|
|
14
|
+
data about one institution, place, instrument or event. See
|
|
15
|
+
[The ontology lens](#the-ontology-lens).
|
|
16
|
+
|
|
12
17
|
Layout of the India board while review tiers are paused (values elided):
|
|
13
18
|
|
|
14
19
|
```
|
|
@@ -45,6 +50,7 @@ npm install --global liquilens
|
|
|
45
50
|
liquilens # India board
|
|
46
51
|
liquilens --region us # US board
|
|
47
52
|
liquilens --record # evidence status and eligibility, all markets
|
|
53
|
+
liquilens lens "IDBI Bank Ltd" # where each product holds data about it
|
|
48
54
|
```
|
|
49
55
|
|
|
50
56
|
From a source checkout:
|
|
@@ -70,6 +76,9 @@ liquilens
|
|
|
70
76
|
`validated_backtest_eligible` and `real_money_eligible`; add `--json` to
|
|
71
77
|
preserve the served `/api/evidence/markets` payload exactly. It cannot be
|
|
72
78
|
combined with `--region` or `--fail-on`.
|
|
79
|
+
- **`lens <query>`**: one-shot ontology lens for one name, key or id; see
|
|
80
|
+
[The ontology lens](#the-ontology-lens). `--json` prints the payload the
|
|
81
|
+
API served, unchanged.
|
|
73
82
|
- **`--fail-on amber|red`**: alerting for cron/CI. Exits 3 when any Indian
|
|
74
83
|
institution is at/above the band, 0 when all are below it, and 4 when the
|
|
75
84
|
tiers are paused or the board lacks the detailed inputs for a comparison.
|
|
@@ -108,6 +117,76 @@ The CLI reads this from `tier_publication.state` alone. Anything other than
|
|
|
108
117
|
`published`, including a missing field or an older cached board, is treated
|
|
109
118
|
as paused.
|
|
110
119
|
|
|
120
|
+
## The ontology lens
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
liquilens lens "IDBI Bank Ltd" # a name
|
|
124
|
+
liquilens lens "$CIN" # any key: a CIN, LEI, ISIN, CUSIP or slug
|
|
125
|
+
liquilens lens inst:in/rbi/idbi-bank-limited --view timeline # a canonical id
|
|
126
|
+
liquilens lens "IDBI Bank Ltd" --as-of 2020-01-01 --json
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
`lens` resolves the query on the LiquiLens ontology, then reads that
|
|
130
|
+
object's context: its identity, public keys, a sample of its links, the
|
|
131
|
+
events that concern it, and one coverage entry for every product read that
|
|
132
|
+
serves data about it, the most specific first, each with its MCP tool and
|
|
133
|
+
exact arguments, its REST URL or its site page. `--view` adds one bounded
|
|
134
|
+
read model (`relationships`, `timeline`, `provenance` or `neighbourhood`);
|
|
135
|
+
`--as-of` reads the name and the view on that date.
|
|
136
|
+
|
|
137
|
+
Layout (values elided):
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
LIQUILENS · ONTOLOGY CONTEXT
|
|
141
|
+
Identity and routing only. A coverage entry names a read that serves data about this object; ...
|
|
142
|
+
|
|
143
|
+
IDENTITY
|
|
144
|
+
<label>
|
|
145
|
+
id: inst:in/rbi/<name>
|
|
146
|
+
kind: inst · jurisdiction: IN · authority: rbi
|
|
147
|
+
resolved from "<query>" by <rule>
|
|
148
|
+
|
|
149
|
+
KEYS
|
|
150
|
+
<key space>: <key>
|
|
151
|
+
|
|
152
|
+
LINKS · <n> in all (<link kind> <n>)
|
|
153
|
+
out supervised_by source:in/self/reserve-bank-of-india (Reserve Bank of India)
|
|
154
|
+
|
|
155
|
+
EVENTS
|
|
156
|
+
<date> event:in/...
|
|
157
|
+
<event label>
|
|
158
|
+
|
|
159
|
+
COVERAGE · most specific first
|
|
160
|
+
1. <product> · <topic>
|
|
161
|
+
mcp: <tool> {<exact arguments>} on <MCP server>
|
|
162
|
+
rest: <URL>
|
|
163
|
+
site: <URL>
|
|
164
|
+
|
|
165
|
+
source: https://api.liquilens.in/api/experimental/v1/ontology/objects/<id>/context?view=summary
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
The lens is identity and routing, never evidence: a coverage entry says
|
|
169
|
+
that a product serves data about the object and how to ask for it, not
|
|
170
|
+
what the data says, how fresh it is, or any score, and the product that
|
|
171
|
+
answers owns its answer. An ambiguous name prints its candidate ids and
|
|
172
|
+
picks none; an unknown name says nothing was guessed. When the API trims
|
|
173
|
+
an answer to fit its size budget or withholds depth from a keyless caller,
|
|
174
|
+
the lens says so at the top, before any section, so a partial answer never
|
|
175
|
+
reads as a complete one. No coverage entry means no product read is routed
|
|
176
|
+
for the object, which says nothing about the object itself.
|
|
177
|
+
|
|
178
|
+
`lens` is never cached: a lookup the API cannot answer exits 1. It exits 0
|
|
179
|
+
for every answer, including ambiguous and unknown names; with `--json`,
|
|
180
|
+
check `status` (`resolved`, `ambiguous` or `not_found`). The JSON is the
|
|
181
|
+
context (`liquilens.ontology-context.v1`) when the query resolved, else the
|
|
182
|
+
resolve answer (`liquilens.ontology-service.v1`).
|
|
183
|
+
|
|
184
|
+
**Status (22 Nov 2026):** works once the LiquiLens API release that serves
|
|
185
|
+
the context route (`/api/experimental/v1/ontology/objects/{id}/context`)
|
|
186
|
+
is live; the resolve step is live today. Until then `lens` resolves the
|
|
187
|
+
query, then exits 1 saying the API release does not serve the context
|
|
188
|
+
route.
|
|
189
|
+
|
|
111
190
|
## Keys
|
|
112
191
|
|
|
113
192
|
| key | action |
|
|
@@ -134,7 +213,9 @@ as paused.
|
|
|
134
213
|
- **Partial failure**: if only the market-regime endpoint fails, the board
|
|
135
214
|
still renders with a "regime unavailable" note.
|
|
136
215
|
- **Tests + CI**: pure logic (columns, sorting, filtering, viewport, risk
|
|
137
|
-
bands, review-tier pause, sparkline, US formatting, cache)
|
|
216
|
+
bands, review-tier pause, sparkline, US formatting, cache) and the ontology
|
|
217
|
+
lens (with fetch stubbed, plus the real command against a loopback stub
|
|
218
|
+
API) are unit-tested (`npm test`);
|
|
138
219
|
CI runs build + tests + live smokes on Node
|
|
139
220
|
18/20/22.
|
|
140
221
|
|
|
@@ -143,13 +224,19 @@ as paused.
|
|
|
143
224
|
The CLI sends no cookies, device identifiers, installation IDs, or command
|
|
144
225
|
analytics. API requests carry the aggregate product-surface label `cli` so the
|
|
145
226
|
service can count successful board reads. Arguments, filters, cache contents,
|
|
146
|
-
and machine details are never sent as analytics.
|
|
227
|
+
and machine details are never sent as analytics. `lens` sends the name, key
|
|
228
|
+
or id you look up to the API, because that text is the lookup itself; the CLI
|
|
229
|
+
keeps no copy.
|
|
147
230
|
|
|
148
231
|
## Exit codes
|
|
149
232
|
|
|
150
233
|
0 ok · 1 no data (API down, no cache) · 2 bad usage · 3 `--fail-on` breached ·
|
|
151
234
|
4 `--fail-on` could not evaluate the board (tiers paused or detailed inputs unavailable)
|
|
152
235
|
|
|
236
|
+
`lens`: 0 answered (resolved, ambiguous or not found) · 1 the API could not
|
|
237
|
+
answer (unreachable, an HTTP error, or an API release without the context
|
|
238
|
+
route) · 2 bad usage
|
|
239
|
+
|
|
153
240
|
## Config
|
|
154
241
|
|
|
155
242
|
- `--api <url>` or `LIQUILENS_API`: API host (default
|
|
@@ -158,11 +245,13 @@ and machine details are never sent as analytics.
|
|
|
158
245
|
|
|
159
246
|
## Where things live
|
|
160
247
|
|
|
161
|
-
- `src/api.ts`: typed fetchers, retry/backoff, proxy + Happy-Eyeballs dialing
|
|
248
|
+
- `src/api.ts`: typed fetchers, retry/backoff, proxy + Happy-Eyeballs dialing,
|
|
249
|
+
and `lookupContext` for the ontology lens.
|
|
162
250
|
- `src/cache.ts`: per-region last-good-snapshot cache.
|
|
163
251
|
- `src/format.ts`: pure layout/sort/filter/viewport/sparkline logic (tested).
|
|
164
252
|
- `src/riskBands.ts`: the row-colour policies and the review-tier pause
|
|
165
253
|
check. India = absolute thresholds (domain judgment, tune here). US = rank-within-board (percentile scores
|
|
166
254
|
drift across quarters, ranks don't).
|
|
167
|
-
- `src/plain.ts`: `--plain` / `--json` renderers + `--fail-on` band logic
|
|
255
|
+
- `src/plain.ts`: `--plain` / `--json` renderers + `--fail-on` band logic, and
|
|
256
|
+
the lens renderers (`renderLens`, `renderLensJson`).
|
|
168
257
|
- `src/App.tsx`: the Ink UI. `src/cli.tsx`: entry point + arg parsing.
|
package/dist/api.js
CHANGED
|
@@ -25,6 +25,22 @@ const hasProxyEnv = Boolean(process.env.HTTPS_PROXY ??
|
|
|
25
25
|
const dispatcher = hasProxyEnv
|
|
26
26
|
? new EnvHttpProxyAgent({ connect: CONNECT_OPTS })
|
|
27
27
|
: new Agent({ connect: CONNECT_OPTS });
|
|
28
|
+
let fetchImpl = undiciFetch;
|
|
29
|
+
/** Swap the network for a stub in tests; `null` restores undici's fetch. */
|
|
30
|
+
export function setFetch(next) {
|
|
31
|
+
fetchImpl = next ?? undiciFetch;
|
|
32
|
+
}
|
|
33
|
+
/** An HTTP error status from the API, with the JSON body of a 4xx answer when it sent one. */
|
|
34
|
+
export class HttpError extends Error {
|
|
35
|
+
status;
|
|
36
|
+
body;
|
|
37
|
+
constructor(status, path, body) {
|
|
38
|
+
super(`HTTP ${status} from ${path}`);
|
|
39
|
+
this.name = "HttpError";
|
|
40
|
+
this.status = status;
|
|
41
|
+
this.body = body;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
28
44
|
export function hasRadarDetail(row) {
|
|
29
45
|
return "hazard" in row;
|
|
30
46
|
}
|
|
@@ -43,7 +59,7 @@ async function getJson(path) {
|
|
|
43
59
|
let lastErr;
|
|
44
60
|
for (let attempt = 0; attempt < RETRIES; attempt++) {
|
|
45
61
|
try {
|
|
46
|
-
const res = await
|
|
62
|
+
const res = await fetchImpl(`${apiBase}${path}`, {
|
|
47
63
|
dispatcher,
|
|
48
64
|
signal: AbortSignal.timeout(ATTEMPT_TIMEOUT_MS),
|
|
49
65
|
// These identify the product surface, not the person or machine. The
|
|
@@ -55,10 +71,10 @@ async function getJson(path) {
|
|
|
55
71
|
},
|
|
56
72
|
});
|
|
57
73
|
if (res.status === 429 || res.status >= 500) {
|
|
58
|
-
lastErr = new
|
|
74
|
+
lastErr = new HttpError(res.status, path);
|
|
59
75
|
}
|
|
60
76
|
else if (!res.ok) {
|
|
61
|
-
throw new
|
|
77
|
+
throw new HttpError(res.status, path, await res.json().catch(() => undefined));
|
|
62
78
|
}
|
|
63
79
|
else {
|
|
64
80
|
return (await res.json());
|
|
@@ -79,3 +95,58 @@ export const fetchUSBoard = () => getJson("/api/us-radar/board");
|
|
|
79
95
|
export const fetchRegime = () => getJson("/api/public-signals/market-regime");
|
|
80
96
|
export const fetchNews = (slug) => getJson(`/api/public-signals/news/${encodeURIComponent(slug)}`);
|
|
81
97
|
export const fetchEvidenceMarkets = () => getJson("/api/evidence/markets");
|
|
98
|
+
// ---------------------------------------------------------------------------
|
|
99
|
+
// Ontology lens: identity and routing for one name, key or id. Never evidence.
|
|
100
|
+
// ---------------------------------------------------------------------------
|
|
101
|
+
const ONTOLOGY = "/api/experimental/v1/ontology";
|
|
102
|
+
/** kind:jurisdiction/authority/name, each segment lowercase letters, digits and hyphens. */
|
|
103
|
+
const CANONICAL_ID = /^[a-z]+:[a-z0-9-]+\/[a-z0-9-]+\/[a-z0-9-]+$/;
|
|
104
|
+
export const LENS_VIEWS = ["summary", "relationships", "timeline", "provenance", "neighbourhood"];
|
|
105
|
+
function isRecord(value) {
|
|
106
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* A 404 from the context route that says no object has `id`. An API release
|
|
110
|
+
* without the route answers through the object route instead, for the id
|
|
111
|
+
* "<id>/context", which proves nothing about `id` itself.
|
|
112
|
+
*/
|
|
113
|
+
function unknownObject(body, id) {
|
|
114
|
+
const answer = isRecord(body) && isRecord(body.detail) ? body.detail : body;
|
|
115
|
+
if (!isRecord(answer) || answer.status !== "not_found")
|
|
116
|
+
return null;
|
|
117
|
+
return answer.id === undefined || answer.id === id ? answer : null;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Resolve a name, key or canonical id, then read where each product holds
|
|
121
|
+
* data about it. Ambiguous and unknown queries are answers, not errors; an
|
|
122
|
+
* API release without the context route is an error.
|
|
123
|
+
*/
|
|
124
|
+
export async function lookupContext(query, view = "summary", asOf = null) {
|
|
125
|
+
const dated = asOf ? `&as_of=${encodeURIComponent(asOf)}` : "";
|
|
126
|
+
const resolve = await getJson(`${ONTOLOGY}/resolve?q=${encodeURIComponent(query)}${dated}`);
|
|
127
|
+
if (resolve?.status === "ambiguous")
|
|
128
|
+
return { status: "ambiguous", query, resolve, context: null };
|
|
129
|
+
if (resolve?.status === "not_found")
|
|
130
|
+
return { status: "not_found", query, resolve, context: null };
|
|
131
|
+
const id = resolve?.status === "resolved" ? resolve.id : undefined;
|
|
132
|
+
if (typeof id !== "string" || !CANONICAL_ID.test(id)) {
|
|
133
|
+
throw new Error(`unexpected resolve answer for "${query}"`);
|
|
134
|
+
}
|
|
135
|
+
const path = `${ONTOLOGY}/objects/${id}/context?view=${encodeURIComponent(view)}${dated}`;
|
|
136
|
+
try {
|
|
137
|
+
const context = await getJson(path);
|
|
138
|
+
if (context?.status !== "resolved" || typeof context.id !== "string" || typeof context.label !== "string") {
|
|
139
|
+
throw new Error(`unexpected context answer for ${id}`);
|
|
140
|
+
}
|
|
141
|
+
return { status: "resolved", query, resolve, context, view, url: `${apiBase}${path}` };
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
if (err instanceof HttpError && err.status === 404) {
|
|
145
|
+
const answer = unknownObject(err.body, id);
|
|
146
|
+
if (answer)
|
|
147
|
+
return { status: "not_found", query, resolve, context: answer };
|
|
148
|
+
throw new Error(`"${query}" resolved to ${id}, but this API release does not serve the ontology context route (HTTP 404)`);
|
|
149
|
+
}
|
|
150
|
+
throw err;
|
|
151
|
+
}
|
|
152
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -4,9 +4,9 @@ import dns from "node:dns";
|
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { render } from "ink";
|
|
6
6
|
import App from "./App.js";
|
|
7
|
-
import { fetchBoard, fetchEvidenceMarkets, fetchRegime, fetchUSBoard, setApiBase, setClientVersion, getApiBase, DEFAULT_API, } from "./api.js";
|
|
7
|
+
import { fetchBoard, fetchEvidenceMarkets, fetchRegime, fetchUSBoard, lookupContext, setApiBase, setClientVersion, getApiBase, DEFAULT_API, LENS_VIEWS, } from "./api.js";
|
|
8
8
|
import { loadCached, saveCached, ageMinutes, describeAge, } from "./cache.js";
|
|
9
|
-
import { renderEvidenceJson, renderEvidenceRecord, renderJson, renderPlain, worstBand, } from "./plain.js";
|
|
9
|
+
import { renderEvidenceJson, renderEvidenceRecord, renderJson, renderLens, renderLensJson, renderPlain, worstBand, } from "./plain.js";
|
|
10
10
|
import { bandAtLeast } from "./riskBands.js";
|
|
11
11
|
// Some networks blackhole IPv6 (Node's fetch hangs while curl works);
|
|
12
12
|
// prefer IPv4 first; undici's autoSelectFamily in api.ts covers the rest.
|
|
@@ -27,6 +27,7 @@ setClientVersion(version);
|
|
|
27
27
|
const HELP = `liquilens ${version}: LiquiLens Failure Radar in your terminal
|
|
28
28
|
|
|
29
29
|
Usage: liquilens [options]
|
|
30
|
+
liquilens lens <name, key or id> [--view <view>] [--as-of <date>] [--json] [--api <url>]
|
|
30
31
|
|
|
31
32
|
Runs an interactive dashboard when attached to a terminal; falls back to a
|
|
32
33
|
plain table when piped. Data comes from public, no-auth LiquiLens endpoints.
|
|
@@ -47,6 +48,18 @@ Options:
|
|
|
47
48
|
-h, --help show this help
|
|
48
49
|
-v, --version show version
|
|
49
50
|
|
|
51
|
+
Ontology lens (one-shot):
|
|
52
|
+
lens <query> resolve a name, any key (CIN, LEI, ISIN, CUSIP, slug) or a
|
|
53
|
+
canonical id, then print the object's identity, keys,
|
|
54
|
+
links, events and every product read (LiquiLens, Seiche,
|
|
55
|
+
Undertow, Palimpsest) that serves data about it. Identity
|
|
56
|
+
and routing only, not evidence: the product that answers
|
|
57
|
+
owns its answer.
|
|
58
|
+
--view <view> summary (default), relationships, timeline, provenance or
|
|
59
|
+
neighbourhood
|
|
60
|
+
--as-of <date> read the name and the view on YYYY-MM-DD
|
|
61
|
+
--json the payload the API served, unchanged
|
|
62
|
+
|
|
50
63
|
Environment:
|
|
51
64
|
LIQUILENS_API same as --api
|
|
52
65
|
HTTPS_PROXY honored for all requests (CONNECT proxy)
|
|
@@ -55,18 +68,32 @@ Keys (interactive): ↑↓/jk select · ⏎ detail · t region · s sort · / fi
|
|
|
55
68
|
r refresh · q quit
|
|
56
69
|
Exit codes: 0 ok · 1 no data (API down and no cache) · 2 bad usage ·
|
|
57
70
|
3 --fail-on threshold breached ·
|
|
58
|
-
4 --fail-on could not evaluate the board (tiers paused or detailed inputs unavailable)
|
|
71
|
+
4 --fail-on could not evaluate the board (tiers paused or detailed inputs unavailable)
|
|
72
|
+
lens: 0 answered (resolved, ambiguous or not found) · 1 the API
|
|
73
|
+
could not answer (unreachable, an error, or no context route)`;
|
|
59
74
|
function fail(msg, code) {
|
|
60
75
|
process.stderr.write(`liquilens: ${msg}\n`);
|
|
61
76
|
process.exit(code);
|
|
62
77
|
}
|
|
78
|
+
/** A calendar date written YYYY-MM-DD (no rollover: 2026-02-30 is refused). */
|
|
79
|
+
function isDay(text) {
|
|
80
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(text))
|
|
81
|
+
return false;
|
|
82
|
+
const day = new Date(`${text}T00:00:00Z`);
|
|
83
|
+
return !Number.isNaN(day.getTime()) && day.toISOString().slice(0, 10) === text;
|
|
84
|
+
}
|
|
63
85
|
export function parseArgs(argv, isTTY) {
|
|
64
86
|
let mode = null;
|
|
65
87
|
let region = "in";
|
|
66
88
|
let regionExplicit = false;
|
|
67
89
|
let failOn = null;
|
|
68
90
|
let record = false;
|
|
69
|
-
|
|
91
|
+
const lens = argv[0] === "lens";
|
|
92
|
+
let query = null;
|
|
93
|
+
let view = "summary";
|
|
94
|
+
let viewExplicit = false;
|
|
95
|
+
let asOf = null;
|
|
96
|
+
for (let i = lens ? 1 : 0; i < argv.length; i++) {
|
|
70
97
|
const arg = argv[i];
|
|
71
98
|
switch (arg) {
|
|
72
99
|
case "-h":
|
|
@@ -106,10 +133,47 @@ export function parseArgs(argv, isTTY) {
|
|
|
106
133
|
setApiBase(url);
|
|
107
134
|
break;
|
|
108
135
|
}
|
|
136
|
+
case "--view": {
|
|
137
|
+
const v = argv[++i];
|
|
138
|
+
if (!LENS_VIEWS.includes(v))
|
|
139
|
+
fail(`--view must be one of ${LENS_VIEWS.join(", ")}, got "${v ?? ""}"`, 2);
|
|
140
|
+
view = v;
|
|
141
|
+
viewExplicit = true;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
case "--as-of": {
|
|
145
|
+
const d = argv[++i];
|
|
146
|
+
if (!d || !isDay(d))
|
|
147
|
+
fail(`--as-of must be a date written YYYY-MM-DD, got "${d ?? ""}"`, 2);
|
|
148
|
+
asOf = d;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
109
151
|
default:
|
|
152
|
+
if (lens && !arg.startsWith("-")) {
|
|
153
|
+
if (query !== null)
|
|
154
|
+
fail(`lens takes one query; quote a name with spaces, as in liquilens lens "IDBI Bank Ltd"`, 2);
|
|
155
|
+
query = arg;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
110
158
|
fail(`unknown option "${arg}" (try --help)`, 2);
|
|
111
159
|
}
|
|
112
160
|
}
|
|
161
|
+
if (!lens && (viewExplicit || asOf !== null))
|
|
162
|
+
fail("--view and --as-of work with lens only (try --help)", 2);
|
|
163
|
+
if (lens) {
|
|
164
|
+
if (regionExplicit || record || failOn)
|
|
165
|
+
fail("lens cannot be combined with --region, --record or --fail-on; it reads one object", 2);
|
|
166
|
+
const text = (query ?? "").trim();
|
|
167
|
+
if (text.length < 1 || text.length > 200)
|
|
168
|
+
fail(`lens needs a name, key or id of 1 to 200 characters, as in liquilens lens "IDBI Bank Ltd"`, 2);
|
|
169
|
+
return {
|
|
170
|
+
mode: mode === "json" ? "json" : "plain",
|
|
171
|
+
region,
|
|
172
|
+
failOn,
|
|
173
|
+
record,
|
|
174
|
+
lens: { query: text, view, asOf },
|
|
175
|
+
};
|
|
176
|
+
}
|
|
113
177
|
if (failOn && region === "us")
|
|
114
178
|
fail("--fail-on works with --region in only: US scores are within-quarter " +
|
|
115
179
|
"percentile ranks (a relative leaderboard), so an absolute alert " +
|
|
@@ -122,7 +186,7 @@ export function parseArgs(argv, isTTY) {
|
|
|
122
186
|
mode = "plain";
|
|
123
187
|
if (failOn && mode === null)
|
|
124
188
|
mode = "plain";
|
|
125
|
-
return { mode: mode ?? (isTTY ? "tui" : "plain"), region, failOn, record };
|
|
189
|
+
return { mode: mode ?? (isTTY ? "tui" : "plain"), region, failOn, record, lens: null };
|
|
126
190
|
}
|
|
127
191
|
async function snapshotOnce(region) {
|
|
128
192
|
if (region === "us") {
|
|
@@ -180,7 +244,18 @@ if ("exit" in parsed) {
|
|
|
180
244
|
console.log(parsed.exit);
|
|
181
245
|
process.exit(0);
|
|
182
246
|
}
|
|
183
|
-
if (parsed.
|
|
247
|
+
if (parsed.lens) {
|
|
248
|
+
let answer;
|
|
249
|
+
try {
|
|
250
|
+
answer = await lookupContext(parsed.lens.query, parsed.lens.view, parsed.lens.asOf);
|
|
251
|
+
}
|
|
252
|
+
catch (err) {
|
|
253
|
+
fail(`could not read the ontology context from ${getApiBase()} ` +
|
|
254
|
+
`(${err instanceof Error ? err.message : String(err)})`, 1);
|
|
255
|
+
}
|
|
256
|
+
console.log(parsed.mode === "json" ? renderLensJson(answer) : renderLens(answer));
|
|
257
|
+
}
|
|
258
|
+
else if (parsed.record) {
|
|
184
259
|
try {
|
|
185
260
|
const record = await fetchEvidenceMarkets();
|
|
186
261
|
console.log(parsed.mode === "json"
|
package/dist/plain.js
CHANGED
|
@@ -176,3 +176,94 @@ export function renderEvidenceRecord(record) {
|
|
|
176
176
|
export function renderEvidenceJson(record) {
|
|
177
177
|
return JSON.stringify(record, null, 2);
|
|
178
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* The ontology lens for people: identity, keys, links, events and one line per
|
|
181
|
+
* coverage route. What the API withheld or trimmed is said up front, so a
|
|
182
|
+
* partial answer never reads as a complete one.
|
|
183
|
+
*/
|
|
184
|
+
export function renderLens(answer) {
|
|
185
|
+
const lines = ["LIQUILENS · ONTOLOGY CONTEXT"];
|
|
186
|
+
if (answer.status === "ambiguous") {
|
|
187
|
+
lines.push(`"${answer.query}" names more than one object, and none is picked.`);
|
|
188
|
+
for (const candidate of answer.resolve.candidates ?? [])
|
|
189
|
+
lines.push(` ${candidate}`);
|
|
190
|
+
lines.push("Ask again with one of these ids, or with a key such as a CIN.");
|
|
191
|
+
return lines.join("\n");
|
|
192
|
+
}
|
|
193
|
+
if (answer.status === "not_found") {
|
|
194
|
+
lines.push(answer.context
|
|
195
|
+
? `"${answer.query}" resolved to ${answer.resolve.id}, but the context route knows no object with that id.`
|
|
196
|
+
: `"${answer.query}": not found. No object carries that name or key, and nothing is guessed or minted.`);
|
|
197
|
+
return lines.join("\n");
|
|
198
|
+
}
|
|
199
|
+
const { context, resolve } = answer;
|
|
200
|
+
if (context.boundary)
|
|
201
|
+
lines.push(context.boundary);
|
|
202
|
+
for (const withheld of context.access?.withheld ?? []) {
|
|
203
|
+
const needs = withheld.requires ? `; needs a ${withheld.requires} key` : "";
|
|
204
|
+
lines.push(`withheld for this caller: ${withheld.depth}` + (withheld.what ? ` (${withheld.what}${needs})` : needs));
|
|
205
|
+
}
|
|
206
|
+
if (context.access?.withheld?.length && context.access.how_to_get_access) {
|
|
207
|
+
lines.push(context.access.how_to_get_access);
|
|
208
|
+
}
|
|
209
|
+
const cuts = Object.entries(context.trimmed ?? {});
|
|
210
|
+
if (cuts.length) {
|
|
211
|
+
lines.push(`trimmed to fit the response budget: ${cuts.map(([path, n]) => `${path} ${n}`).join(", ")}`);
|
|
212
|
+
}
|
|
213
|
+
lines.push("", "IDENTITY", ` ${context.label}`, ` id: ${context.id}`);
|
|
214
|
+
lines.push(` kind: ${context.kind} · jurisdiction: ${context.jurisdiction} · authority: ${context.authority}`);
|
|
215
|
+
lines.push(` resolved from "${answer.query}" by ${resolve.rule ?? "the API"}` +
|
|
216
|
+
(resolve.as_of ? `, as of ${resolve.as_of}` : ""));
|
|
217
|
+
if (context.redirected_from)
|
|
218
|
+
lines.push(` redirected from: ${context.redirected_from}`);
|
|
219
|
+
if (context.note)
|
|
220
|
+
lines.push(` note: ${context.note}`);
|
|
221
|
+
lines.push("", "KEYS");
|
|
222
|
+
const keys = Object.entries(context.keys ?? {}).sort(([a], [b]) => a.localeCompare(b));
|
|
223
|
+
for (const [space, key] of keys)
|
|
224
|
+
lines.push(` ${space}: ${key}`);
|
|
225
|
+
if (!keys.length)
|
|
226
|
+
lines.push(" none served");
|
|
227
|
+
const links = context.links ?? { total: 0, by_kind: {}, sample: [] };
|
|
228
|
+
const kinds = Object.entries(links.by_kind ?? {}).map(([kind, n]) => `${kind} ${n}`);
|
|
229
|
+
lines.push("", `LINKS · ${links.total} in all` + (kinds.length ? ` (${kinds.join(", ")})` : ""));
|
|
230
|
+
for (const link of links.sample ?? []) {
|
|
231
|
+
lines.push(` ${link.direction} ${link.kind} ${link.id}` + (link.label ? ` (${link.label})` : ""));
|
|
232
|
+
}
|
|
233
|
+
if ((links.sample ?? []).length < links.total) {
|
|
234
|
+
lines.push(` ${(links.sample ?? []).length} of ${links.total} shown`);
|
|
235
|
+
}
|
|
236
|
+
lines.push("", "EVENTS");
|
|
237
|
+
for (const event of context.events ?? []) {
|
|
238
|
+
lines.push(` ${event.date ?? "undated"} ${event.id}`);
|
|
239
|
+
if (event.label)
|
|
240
|
+
lines.push(` ${event.label}`);
|
|
241
|
+
}
|
|
242
|
+
if (!(context.events ?? []).length)
|
|
243
|
+
lines.push(" no event object concerns this object");
|
|
244
|
+
lines.push("", "COVERAGE · most specific first");
|
|
245
|
+
(context.coverage ?? []).forEach((entry, i) => {
|
|
246
|
+
lines.push(` ${i + 1}. ${entry.product} · ${entry.topic}`);
|
|
247
|
+
if (entry.mcp) {
|
|
248
|
+
lines.push(` mcp: ${entry.mcp.tool} ${JSON.stringify(entry.mcp.arguments ?? {})} on ${entry.mcp.server}`);
|
|
249
|
+
}
|
|
250
|
+
if (entry.rest)
|
|
251
|
+
lines.push(` rest: ${entry.rest}`);
|
|
252
|
+
if (entry.site)
|
|
253
|
+
lines.push(` site: ${entry.site}`);
|
|
254
|
+
});
|
|
255
|
+
if (!(context.coverage ?? []).length) {
|
|
256
|
+
lines.push(" no product read is routed for this object; that says nothing about the object itself");
|
|
257
|
+
}
|
|
258
|
+
if (context.view) {
|
|
259
|
+
lines.push("", `VIEW · ${answer.view}`);
|
|
260
|
+
for (const line of JSON.stringify(context.view, null, 2).split("\n"))
|
|
261
|
+
lines.push(` ${line}`);
|
|
262
|
+
}
|
|
263
|
+
lines.push("", `source: ${answer.url}`);
|
|
264
|
+
return lines.join("\n");
|
|
265
|
+
}
|
|
266
|
+
/** The payload the API served, exactly: the context when the query resolved, else the resolve answer. */
|
|
267
|
+
export function renderLensJson(answer) {
|
|
268
|
+
return JSON.stringify(answer.context ?? answer.resolve, null, 2);
|
|
269
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "liquilens",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "LiquiLens Failure Radar in your terminal: a live early-warning board for Indian institutions and FDIC-scored US banks, from public data",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"homepage": "https://liquilens.in/developers/",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "tsc",
|
|
38
38
|
"dev": "tsc && node dist/cli.js",
|
|
39
|
-
"test": "tsc && node --test dist/cache.test.js dist/format.test.js dist/paused.test.js dist/record.test.js dist/riskBands.test.js dist/us.test.js",
|
|
39
|
+
"test": "tsc && node --test dist/cache.test.js dist/format.test.js dist/lens.test.js dist/paused.test.js dist/record.test.js dist/riskBands.test.js dist/us.test.js",
|
|
40
40
|
"prepare": "tsc"
|
|
41
41
|
},
|
|
42
42
|
"publishConfig": {
|