liquilens 0.5.2 → 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 +101 -12
- package/dist/App.js +19 -11
- package/dist/api.js +83 -3
- package/dist/cli.js +87 -14
- package/dist/format.js +14 -6
- package/dist/plain.js +116 -10
- 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
|
```
|
|
@@ -22,10 +27,10 @@ review tiers paused since 2026-11-03: tiers paused, research only; no grade, ban
|
|
|
22
27
|
|
|
23
28
|
Two boards, one command:
|
|
24
29
|
|
|
25
|
-
- **IN**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
- **IN** covers Indian banks, SFBs, NBFCs and MFIs. The public summary shows
|
|
31
|
+
the score, 12/24/36-month research probabilities, funding index and RBI zone.
|
|
32
|
+
Detail depends on what the API serves. Grades require published review
|
|
33
|
+
tiers. Risk bands also require the underlying inputs.
|
|
29
34
|
- **US** (the riskiest tail of 1,000+ FDIC-scored banks, undertow engine):
|
|
30
35
|
within-quarter percentile score, noncurrent assets, uninsured/brokered
|
|
31
36
|
deposits, CRE concentration, NDFI-to-tier-1.
|
|
@@ -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,10 +76,13 @@ 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
|
-
institution is at/above the band, 0 when
|
|
75
|
-
|
|
76
|
-
|
|
83
|
+
institution is at/above the band, 0 when all are below it, and 4 when the
|
|
84
|
+
tiers are paused or the board lacks the detailed inputs for a comparison.
|
|
85
|
+
On the US board, scores are within-quarter percentile ranks,
|
|
77
86
|
a relative leaderboard, so an absolute threshold would always fire.
|
|
78
87
|
|
|
79
88
|
```bash
|
|
@@ -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,12 +224,18 @@ 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
|
-
4 `--fail-on` not
|
|
234
|
+
4 `--fail-on` could not evaluate the board (tiers paused or detailed inputs unavailable)
|
|
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
|
|
152
239
|
|
|
153
240
|
## Config
|
|
154
241
|
|
|
@@ -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/App.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { Box, Text, useApp, useInput, useStdout } from "ink";
|
|
4
|
-
import { fetchBoard, fetchNews, fetchRegime, fetchUSBoard, } from "./api.js";
|
|
4
|
+
import { fetchBoard, fetchNews, fetchRegime, fetchUSBoard, hasRadarDetail, probabilities, probabilityChange, } from "./api.js";
|
|
5
5
|
import { loadCached, saveCached, ageMinutes, describeAge, } from "./cache.js";
|
|
6
|
-
import { cell, computeCols, computeUSCols, filterRows, filterUSRows, fmtAssets, fundingLabel, movement, pct, pct1, rawPct, SORT_MODES, sortRows, sortUSRows, sparkline, US_SORT_MODES, viewport, } from "./format.js";
|
|
6
|
+
import { cell, computeCols, computeUSCols, filterRows, filterUSRows, fmtAssets, fundingLabel, fundingSummary, movement, pct, pct1, rawPct, SORT_MODES, sortRows, sortUSRows, sparkline, US_SORT_MODES, viewport, } from "./format.js";
|
|
7
7
|
import { pausedLine, riskBand, tiersPublished, usRiskBandByRank, bandColor } from "./riskBands.js";
|
|
8
8
|
const ACCENT = "#9184d9"; // Nocturne
|
|
9
9
|
const DIM = "gray";
|
|
@@ -52,13 +52,14 @@ function Header({ region, regime, regimeError, usBoard, width, }) {
|
|
|
52
52
|
const spark = region === "in" && width >= 96 && regime?.series?.log_sr
|
|
53
53
|
? sparkline(regime.series.log_sr, 28)
|
|
54
54
|
: "";
|
|
55
|
-
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Text, { color: ACCENT, bold: true, children: "\u25C6 LIQUILENS" }), _jsx(Text, { color: DIM, children: " \u00B7 Failure Radar \u00B7 " }), _jsx(Text, { color: region === "in" ? ACCENT : DIM, bold: region === "in", children: "IN" }), _jsx(Text, { color: DIM, children: "/" }), _jsx(Text, { color: region === "us" ? ACCENT : DIM, bold: region === "us", children: "US" }), _jsx(Text, { color: DIM, children: " (t to switch)" })] }), region === "in" ? (regime ? (_jsxs(Box, { children: [_jsx(Text, { color: DIM, children: "market regime " }), _jsx(Text, { color: regimeColor(regime.regime), bold: true, children: regime.regime }), _jsxs(Text, { color: DIM, children: [" ", "(log-SR ", regime.log_sr_now.toFixed(2), ", last change", " ", regime.trading_days_since_last_change, "d ago)"] }), spark && (_jsxs(Text, { color: regimeColor(regime.regime), children: [" ", spark] })), _jsxs(Text, { color: DIM, children: [" \u00B7 ", regime.as_of] })] })) : regimeError ? (_jsx(Text, { color: DIM, children: "market regime unavailable right now" })) : null) : usBoard ? (_jsxs(Text, { color: DIM, children: ["top ", usBoard.board.length, " of ", usBoard.universe.banks_scored, " FDIC banks (\u2265$1B assets) \u00B7 undertow score = within-quarter percentile \u00B7 quarter ", usBoard.as_of] })) : null] }));
|
|
55
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Text, { color: ACCENT, bold: true, children: "\u25C6 LIQUILENS" }), _jsx(Text, { color: DIM, children: " \u00B7 Failure Radar \u00B7 " }), _jsx(Text, { color: region === "in" ? ACCENT : DIM, bold: region === "in", children: "IN" }), _jsx(Text, { color: DIM, children: "/" }), _jsx(Text, { color: region === "us" ? ACCENT : DIM, bold: region === "us", children: "US" }), _jsx(Text, { color: DIM, children: " (t to switch)" })] }), region === "in" ? (regime?.available ? (_jsxs(Box, { children: [_jsx(Text, { color: DIM, children: "market regime " }), _jsx(Text, { color: regimeColor(regime.regime), bold: true, children: regime.regime }), _jsxs(Text, { color: DIM, children: [" ", "(log-SR ", regime.log_sr_now.toFixed(2), ", last change", " ", regime.trading_days_since_last_change, "d ago)"] }), spark && (_jsxs(Text, { color: regimeColor(regime.regime), children: [" ", spark] })), _jsxs(Text, { color: DIM, children: [" \u00B7 ", regime.as_of] })] })) : regimeError || regime?.available === false ? (_jsx(Text, { color: DIM, children: "market regime unavailable right now" })) : null) : usBoard ? (_jsxs(Text, { color: DIM, children: ["top ", usBoard.board.length, " of ", usBoard.universe.banks_scored, " FDIC banks (\u2265$1B assets) \u00B7 undertow score = within-quarter percentile \u00B7 quarter ", usBoard.as_of] })) : null] }));
|
|
56
56
|
}
|
|
57
57
|
function InRow({ row, selected, cols, showTiers, }) {
|
|
58
58
|
// Bands, grades and their colours only while the API publishes tiers.
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
|
|
59
|
+
const detailed = hasRadarDetail(row);
|
|
60
|
+
const color = showTiers && detailed ? bandColor[riskBand(row)] : undefined;
|
|
61
|
+
const move = movement(probabilityChange(row));
|
|
62
|
+
return (_jsxs(Box, { children: [_jsx(Text, { color: selected ? ACCENT : DIM, children: selected ? "❯ " : " " }), _jsx(Text, { color: color, bold: selected, inverse: selected, children: cell(row.name, cols.name) }), _jsx(Text, { color: DIM, children: cell(row.inst_type, cols.type) }), showTiers && _jsx(Text, { color: color, children: cell(row.grade ?? "", cols.grade) }), _jsx(Text, { children: cell(String(row.score), cols.score) }), _jsx(Text, { color: color, children: cell(pct(probabilities(row).pd_12m), cols.pd) }), _jsx(Text, { color: moveColor(move.dir), children: cell(move.text, cols.move) }), _jsx(Text, { color: detailed ? fundColor(row.funding.band) : DIM, children: fundingSummary(row) })] }));
|
|
62
63
|
}
|
|
63
64
|
function UsRow({ row, rank, selected, cols, }) {
|
|
64
65
|
const band = usRiskBandByRank(rank);
|
|
@@ -71,6 +72,8 @@ function NewsLine({ news }) {
|
|
|
71
72
|
return _jsx(Text, { color: DIM, children: "news watch loading\u2026" });
|
|
72
73
|
if (news === "error")
|
|
73
74
|
return _jsx(Text, { color: DIM, children: "news watch unavailable" });
|
|
75
|
+
if ("not_computed" in news)
|
|
76
|
+
return _jsxs(Text, { color: DIM, children: ["news watch: ", news.not_computed] });
|
|
74
77
|
const stressColor = news.news_stress >= 50
|
|
75
78
|
? bandColor.red
|
|
76
79
|
: news.news_stress >= 20
|
|
@@ -79,8 +82,13 @@ function NewsLine({ news }) {
|
|
|
79
82
|
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { children: [_jsx(Text, { color: DIM, children: "news watch stress " }), _jsx(Text, { color: stressColor, bold: true, children: news.news_stress.toFixed(1) }), _jsxs(Text, { color: DIM, children: [" ", "tone ", news.tone_recent.toFixed(2), " \u00B7 distress share", " ", pct(news.distress_share), " \u00B7 coverage ", news.coverage] })] }), news.basis.slice(0, 2).map((b, i) => (_jsxs(Text, { color: DIM, children: ["\u00B7 ", b] }, i)))] }));
|
|
80
83
|
}
|
|
81
84
|
function InDetail({ row, news, showTiers, }) {
|
|
82
|
-
const
|
|
83
|
-
|
|
85
|
+
const detailed = hasRadarDetail(row);
|
|
86
|
+
const color = showTiers && detailed ? bandColor[riskBand(row)] : undefined;
|
|
87
|
+
const pd = probabilities(row);
|
|
88
|
+
return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: ACCENT, paddingX: 1, children: [_jsxs(Box, { justifyContent: "space-between", gap: 2, children: [_jsx(Text, { bold: true, color: color, children: row.name }), _jsxs(Text, { color: DIM, children: [row.inst_type, " \u00B7 ", row.quarter, " \u00B7 data as of ", row.as_of, detailed && ` (${row.age_months}mo old)`] })] }), _jsxs(Text, { children: [showTiers && _jsx(Text, { color: DIM, children: "grade " }), showTiers && _jsx(Text, { bold: true, children: row.grade ?? "" }), _jsx(Text, { color: DIM, children: showTiers ? " score " : "score " }), _jsx(Text, { bold: true, children: row.score }), _jsx(Text, { color: DIM, children: showTiers ? " PD 12/24/36m " : " PD 12/24/36m, research only " }), _jsxs(Text, { bold: true, color: color, children: [pct(pd.pd_12m), " / ", pct(pd.pd_24m), " / ", pct(pd.pd_36m)] })] }), detailed ? _jsx(InRiskInputs, { row: row }) : (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { children: ["Funding ", fundingSummary(row), " \u00B7 RBI zone ", row.rbi_zone ?? "n/a"] }), _jsx(Text, { color: DIM, children: "Detailed risk inputs are withheld in the public summary." })] })), _jsx(NewsLine, { news: news })] }));
|
|
89
|
+
}
|
|
90
|
+
function InRiskInputs({ row }) {
|
|
91
|
+
return (_jsxs(_Fragment, { children: [row.hazard.basis.length > 0 && (_jsxs(Text, { color: DIM, children: ["hazard basis: ", row.hazard.basis.join("; ")] })), _jsxs(Text, { children: [_jsx(Text, { color: DIM, children: "funding " }), _jsx(Text, { color: fundColor(row.funding.band), children: fundingLabel(row.funding.band) }), row.funding.flags.length > 0 && (_jsxs(Text, { color: bandColor.amber, children: [" \u2691 ", row.funding.flags.join(", ")] })), row.funding.basis.length > 0 && (_jsxs(Text, { color: DIM, children: [" \u00B7 ", row.funding.basis.join("; ")] }))] }), _jsxs(Text, { children: [_jsx(Text, { color: DIM, children: "PCA " }), _jsx(Text, { children: row.pca.status }), row.pca.breaches.length > 0 && (_jsxs(Text, { color: bandColor.red, children: [" breaches: ", row.pca.breaches.join(", ")] }))] }), _jsxs(Text, { children: [_jsx(Text, { color: DIM, children: "forensics " }), row.forensics.fired ? (_jsxs(Text, { color: bandColor.red, children: ["FIRED: ", row.forensics.indicators.join(", ")] })) : (_jsx(Text, { color: bandColor.green, children: "clear" }))] }), row.market && !row.market.stale && (_jsxs(Text, { children: [_jsx(Text, { color: DIM, children: "market lens DD " }), _jsx(Text, { bold: true, children: row.market.dd.toFixed(2) }), _jsx(Text, { color: DIM, children: " Merton PD 1y " }), _jsx(Text, { bold: true, children: pct(row.market.pd_merton_1y) })] }))] }));
|
|
84
92
|
}
|
|
85
93
|
function UsDetail({ row, rank }) {
|
|
86
94
|
const band = usRiskBandByRank(rank);
|
|
@@ -168,7 +176,7 @@ export default function App({ initialRegion = "in" }) {
|
|
|
168
176
|
});
|
|
169
177
|
}, []);
|
|
170
178
|
const load = useCallback((r = region) => (r === "in" ? loadIn() : loadUs()), [region, loadIn, loadUs]);
|
|
171
|
-
// Initial load only
|
|
179
|
+
// Initial load only: later loads are user- or timer-driven.
|
|
172
180
|
useEffect(() => {
|
|
173
181
|
load(region);
|
|
174
182
|
}, []);
|
|
@@ -285,7 +293,7 @@ export default function App({ initialRegion = "in" }) {
|
|
|
285
293
|
const chrome = 7 + (showDetail ? 13 : 0) + (regionStale ? 1 : 0) + pausedNotice;
|
|
286
294
|
const visible = Math.max(3, height - chrome);
|
|
287
295
|
const vp = viewport(rowCount, visible, cursor);
|
|
288
|
-
return (_jsxs(Box, { flexDirection: "column", paddingX: 1, children: [_jsx(Header, { region: region, regime: regime, regimeError: regimeError, usBoard: usBoard, width: width }), regionStale && (_jsxs(Text, { color: bandColor.amber, children: ["\u26A0 offline
|
|
296
|
+
return (_jsxs(Box, { flexDirection: "column", paddingX: 1, children: [_jsx(Header, { region: region, regime: regime, regimeError: regimeError, usBoard: usBoard, width: width }), regionStale && (_jsxs(Text, { color: bandColor.amber, children: ["\u26A0 offline: showing cached board from", " ", describeAge(ageMinutes(regionStale)), " (retrying every 5m, r to retry now)"] })), error && (_jsxs(Text, { color: bandColor.red, children: ["\u2716 ", error, "; press r to retry, or set LIQUILENS_API / HTTPS_PROXY"] })), loading && !hasData && _jsx(Text, { color: DIM, children: "\u283F loading live board\u2026" }), region === "in" && board !== null && !showTiers && (_jsx(Text, { color: bandColor.amber, children: pausedLine(board) })), hasData && (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [region === "in" ? (_jsxs(Text, { color: DIM, bold: true, children: [" ", cell("INSTITUTION", cols.name), cell("TYPE", cols.type), showTiers && cell("GRADE", cols.grade), cell("SCORE", cols.score), cell("PD 12M", cols.pd), cell("Δ PD", cols.move), "FUNDING"] })) : (_jsxs(Text, { color: DIM, bold: true, children: [" ", cell("BANK", usCols.bank), cell("STATE", usCols.state), cell("ASSETS", usCols.assets), cell("SCORE", usCols.score), cell("NONCURR", usCols.noncurr), cell("UNINSURED", usCols.uninsured), "NDFI/T1"] })), vp.above > 0 && _jsxs(Text, { color: DIM, children: [" ", "\u2191 ", vp.above, " more"] }), region === "in"
|
|
289
297
|
? inRows
|
|
290
298
|
.slice(vp.start, vp.end)
|
|
291
299
|
.map((row, i) => (_jsx(InRow, { row: row, selected: vp.start + i === cursor, cols: cols, showTiers: showTiers }, row.slug)))
|
package/dist/api.js
CHANGED
|
@@ -25,6 +25,31 @@ 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
|
+
}
|
|
44
|
+
export function hasRadarDetail(row) {
|
|
45
|
+
return "hazard" in row;
|
|
46
|
+
}
|
|
47
|
+
export function probabilities(row) {
|
|
48
|
+
return hasRadarDetail(row) ? row.hazard : row;
|
|
49
|
+
}
|
|
50
|
+
export function probabilityChange(row) {
|
|
51
|
+
return hasRadarDetail(row) ? row.movement.delta_pd_12m : row.delta_pd_12m;
|
|
52
|
+
}
|
|
28
53
|
const RETRIES = 3;
|
|
29
54
|
const ATTEMPT_TIMEOUT_MS = 15_000;
|
|
30
55
|
function sleep(ms) {
|
|
@@ -34,7 +59,7 @@ async function getJson(path) {
|
|
|
34
59
|
let lastErr;
|
|
35
60
|
for (let attempt = 0; attempt < RETRIES; attempt++) {
|
|
36
61
|
try {
|
|
37
|
-
const res = await
|
|
62
|
+
const res = await fetchImpl(`${apiBase}${path}`, {
|
|
38
63
|
dispatcher,
|
|
39
64
|
signal: AbortSignal.timeout(ATTEMPT_TIMEOUT_MS),
|
|
40
65
|
// These identify the product surface, not the person or machine. The
|
|
@@ -46,10 +71,10 @@ async function getJson(path) {
|
|
|
46
71
|
},
|
|
47
72
|
});
|
|
48
73
|
if (res.status === 429 || res.status >= 500) {
|
|
49
|
-
lastErr = new
|
|
74
|
+
lastErr = new HttpError(res.status, path);
|
|
50
75
|
}
|
|
51
76
|
else if (!res.ok) {
|
|
52
|
-
throw new
|
|
77
|
+
throw new HttpError(res.status, path, await res.json().catch(() => undefined));
|
|
53
78
|
}
|
|
54
79
|
else {
|
|
55
80
|
return (await res.json());
|
|
@@ -70,3 +95,58 @@ export const fetchUSBoard = () => getJson("/api/us-radar/board");
|
|
|
70
95
|
export const fetchRegime = () => getJson("/api/public-signals/market-regime");
|
|
71
96
|
export const fetchNews = (slug) => getJson(`/api/public-signals/news/${encodeURIComponent(slug)}`);
|
|
72
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,18 +4,18 @@ 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
|
-
// prefer IPv4 first
|
|
12
|
+
// prefer IPv4 first; undici's autoSelectFamily in api.ts covers the rest.
|
|
13
13
|
dns.setDefaultResultOrder("ipv4first");
|
|
14
14
|
// A crash should read like a message, not a stack dump, and must not leave
|
|
15
15
|
// the terminal in raw mode (Ink's unmount handles restore on normal exits).
|
|
16
16
|
function crash(err) {
|
|
17
17
|
const msg = err instanceof Error ? err.message : String(err);
|
|
18
|
-
process.stderr.write(`\nliquilens: unexpected error
|
|
18
|
+
process.stderr.write(`\nliquilens: unexpected error: ${msg}\n`);
|
|
19
19
|
process.stderr.write("Run again with --plain for a minimal path, or check --help.\n");
|
|
20
20
|
process.exit(1);
|
|
21
21
|
}
|
|
@@ -24,9 +24,10 @@ process.on("unhandledRejection", crash);
|
|
|
24
24
|
const require = createRequire(import.meta.url);
|
|
25
25
|
const { version } = require("../package.json");
|
|
26
26
|
setClientVersion(version);
|
|
27
|
-
const HELP = `liquilens ${version}
|
|
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.
|
|
@@ -40,14 +41,25 @@ Options:
|
|
|
40
41
|
--plain one-shot ANSI-free table (default when stdout is not a TTY)
|
|
41
42
|
--json one-shot machine-readable JSON dump
|
|
42
43
|
--fail-on <band> exit 3 if any institution is at/above band (amber|red).
|
|
43
|
-
India board only
|
|
44
|
+
India board only; the US board is a relative leaderboard.
|
|
44
45
|
Implies --plain unless --json is given. For cron/CI alerts.
|
|
45
|
-
|
|
46
|
-
instead: there is no band to compare.
|
|
46
|
+
Exits 4 if tiers are paused or detailed inputs are unavailable.
|
|
47
47
|
--api <url> API host (default ${DEFAULT_API}; env LIQUILENS_API)
|
|
48
48
|
-h, --help show this help
|
|
49
49
|
-v, --version show version
|
|
50
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
|
+
|
|
51
63
|
Environment:
|
|
52
64
|
LIQUILENS_API same as --api
|
|
53
65
|
HTTPS_PROXY honored for all requests (CONNECT proxy)
|
|
@@ -56,18 +68,32 @@ Keys (interactive): ↑↓/jk select · ⏎ detail · t region · s sort · / fi
|
|
|
56
68
|
r refresh · q quit
|
|
57
69
|
Exit codes: 0 ok · 1 no data (API down and no cache) · 2 bad usage ·
|
|
58
70
|
3 --fail-on threshold breached ·
|
|
59
|
-
4 --fail-on not
|
|
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)`;
|
|
60
74
|
function fail(msg, code) {
|
|
61
75
|
process.stderr.write(`liquilens: ${msg}\n`);
|
|
62
76
|
process.exit(code);
|
|
63
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
|
+
}
|
|
64
85
|
export function parseArgs(argv, isTTY) {
|
|
65
86
|
let mode = null;
|
|
66
87
|
let region = "in";
|
|
67
88
|
let regionExplicit = false;
|
|
68
89
|
let failOn = null;
|
|
69
90
|
let record = false;
|
|
70
|
-
|
|
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++) {
|
|
71
97
|
const arg = argv[i];
|
|
72
98
|
switch (arg) {
|
|
73
99
|
case "-h":
|
|
@@ -107,10 +133,47 @@ export function parseArgs(argv, isTTY) {
|
|
|
107
133
|
setApiBase(url);
|
|
108
134
|
break;
|
|
109
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
|
+
}
|
|
110
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
|
+
}
|
|
111
158
|
fail(`unknown option "${arg}" (try --help)`, 2);
|
|
112
159
|
}
|
|
113
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
|
+
}
|
|
114
177
|
if (failOn && region === "us")
|
|
115
178
|
fail("--fail-on works with --region in only: US scores are within-quarter " +
|
|
116
179
|
"percentile ranks (a relative leaderboard), so an absolute alert " +
|
|
@@ -123,7 +186,7 @@ export function parseArgs(argv, isTTY) {
|
|
|
123
186
|
mode = "plain";
|
|
124
187
|
if (failOn && mode === null)
|
|
125
188
|
mode = "plain";
|
|
126
|
-
return { mode: mode ?? (isTTY ? "tui" : "plain"), region, failOn, record };
|
|
189
|
+
return { mode: mode ?? (isTTY ? "tui" : "plain"), region, failOn, record, lens: null };
|
|
127
190
|
}
|
|
128
191
|
async function snapshotOnce(region) {
|
|
129
192
|
if (region === "us") {
|
|
@@ -181,7 +244,18 @@ if ("exit" in parsed) {
|
|
|
181
244
|
console.log(parsed.exit);
|
|
182
245
|
process.exit(0);
|
|
183
246
|
}
|
|
184
|
-
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) {
|
|
185
259
|
try {
|
|
186
260
|
const record = await fetchEvidenceMarkets();
|
|
187
261
|
console.log(parsed.mode === "json"
|
|
@@ -206,8 +280,7 @@ else {
|
|
|
206
280
|
const worst = worstBand(snap);
|
|
207
281
|
if (worst === null) {
|
|
208
282
|
// Never a silent pass: a paused board is not a calm board.
|
|
209
|
-
process.stderr.write(`liquilens: --fail-on ${parsed.failOn} not evaluated:
|
|
210
|
-
"are paused (research only), so there is no band to compare\n");
|
|
283
|
+
process.stderr.write(`liquilens: --fail-on ${parsed.failOn} not evaluated: published tiers and detailed risk inputs are required\n`);
|
|
211
284
|
process.exit(4);
|
|
212
285
|
}
|
|
213
286
|
if (bandAtLeast(worst, parsed.failOn)) {
|
package/dist/format.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { hasRadarDetail, probabilities, probabilityChange } from "./api.js";
|
|
2
|
+
export const pct = (x) => x == null ? "n/a" : `${(x * 100).toFixed(2)}%`;
|
|
2
3
|
/** Fraction -> "17.0%", tolerating missing values. */
|
|
3
|
-
export const pct1 = (x) => x == null ? "
|
|
4
|
+
export const pct1 = (x) => x == null ? "n/a" : `${(x * 100).toFixed(1)}%`;
|
|
4
5
|
/** Value already in percent units (FDIC noncurrent_ratio: 4.0 = 4%). */
|
|
5
|
-
export const rawPct = (x) => x == null ? "
|
|
6
|
+
export const rawPct = (x) => x == null ? "n/a" : `${x.toFixed(2)}%`;
|
|
6
7
|
/** Assets reported in USD thousands -> "$15.2B" / "$980M". */
|
|
7
8
|
export function fmtAssets(usdK) {
|
|
8
9
|
const usd = usdK * 1_000;
|
|
@@ -29,6 +30,8 @@ export function sparkline(values, width) {
|
|
|
29
30
|
.join("");
|
|
30
31
|
}
|
|
31
32
|
export function movement(delta) {
|
|
33
|
+
if (delta == null)
|
|
34
|
+
return { text: "n/a", dir: "flat" };
|
|
32
35
|
if (delta > 0.0005)
|
|
33
36
|
return { text: `▲ ${pct(delta)}`, dir: "up" };
|
|
34
37
|
if (delta < -0.0005)
|
|
@@ -38,6 +41,11 @@ export function movement(delta) {
|
|
|
38
41
|
export function fundingLabel(band) {
|
|
39
42
|
return band === "not_scored" ? "n/a" : band;
|
|
40
43
|
}
|
|
44
|
+
export function fundingSummary(row) {
|
|
45
|
+
if (hasRadarDetail(row))
|
|
46
|
+
return fundingLabel(row.funding.band);
|
|
47
|
+
return row.funding_index == null ? "n/a" : `index ${row.funding_index}`;
|
|
48
|
+
}
|
|
41
49
|
/**
|
|
42
50
|
* Column widths for a given terminal width. The name column absorbs all
|
|
43
51
|
* slack between a floor (narrow terminals truncate names) and a ceiling
|
|
@@ -52,7 +60,7 @@ export function computeCols(termWidth) {
|
|
|
52
60
|
const name = Math.max(18, Math.min(40, termWidth - used));
|
|
53
61
|
return { name, ...fixed };
|
|
54
62
|
}
|
|
55
|
-
/** Truncate to width (with ellipsis) then pad
|
|
63
|
+
/** Truncate to width (with ellipsis) then pad, so cells never overflow. */
|
|
56
64
|
export function cell(text, width) {
|
|
57
65
|
if (text.length > width - 1) {
|
|
58
66
|
return `${text.slice(0, Math.max(0, width - 2))}… `.padEnd(width);
|
|
@@ -64,10 +72,10 @@ export function sortRows(rows, mode) {
|
|
|
64
72
|
const sorted = [...rows];
|
|
65
73
|
switch (mode) {
|
|
66
74
|
case "risk":
|
|
67
|
-
sorted.sort((a, b) => b.
|
|
75
|
+
sorted.sort((a, b) => (probabilities(b).pd_12m ?? -Infinity) - (probabilities(a).pd_12m ?? -Infinity));
|
|
68
76
|
break;
|
|
69
77
|
case "movement":
|
|
70
|
-
sorted.sort((a, b) => b
|
|
78
|
+
sorted.sort((a, b) => (probabilityChange(b) ?? -Infinity) - (probabilityChange(a) ?? -Infinity));
|
|
71
79
|
break;
|
|
72
80
|
case "score":
|
|
73
81
|
sorted.sort((a, b) => a.score - b.score);
|
package/dist/plain.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { hasRadarDetail, probabilities, probabilityChange } from "./api.js";
|
|
2
|
+
import { cell, computeCols, computeUSCols, fmtAssets, fundingSummary, movement, pct, pct1, rawPct, sortRows, sortUSRows, } from "./format.js";
|
|
2
3
|
import { pausedLine, riskBand, tiersPublished, usRiskBandByRank } from "./riskBands.js";
|
|
3
4
|
function staleLine(stale) {
|
|
4
5
|
return stale
|
|
5
|
-
? [`WARNING: live API unreachable
|
|
6
|
+
? [`WARNING: live API unreachable; cached data from ${stale.description}`]
|
|
6
7
|
: [];
|
|
7
8
|
}
|
|
8
9
|
/** Worst risk band on the board, which drives --fail-on exit codes. Null for
|
|
@@ -13,8 +14,9 @@ export function worstBand(snap) {
|
|
|
13
14
|
// absolute alerting (enforced at arg-parse time).
|
|
14
15
|
return snap.board.board.length > 0 ? "red" : "green";
|
|
15
16
|
}
|
|
16
|
-
if (!tiersPublished(snap.board))
|
|
17
|
+
if (!tiersPublished(snap.board) || !snap.board.rows.length || !snap.board.rows.every(hasRadarDetail)) {
|
|
17
18
|
return null;
|
|
19
|
+
}
|
|
18
20
|
let worst = "green";
|
|
19
21
|
for (const row of snap.board.rows) {
|
|
20
22
|
const b = riskBand(row);
|
|
@@ -32,7 +34,7 @@ export function renderPlain(snap, width = 100) {
|
|
|
32
34
|
const cols = computeCols(width);
|
|
33
35
|
const lines = [];
|
|
34
36
|
lines.push(`LIQUILENS Failure Radar · INDIA · board as of ${snap.board.as_of}`);
|
|
35
|
-
if (snap.regime) {
|
|
37
|
+
if (snap.regime?.available) {
|
|
36
38
|
lines.push(`market regime ${snap.regime.regime} (log-SR ${snap.regime.log_sr_now.toFixed(2)}, ` +
|
|
37
39
|
`last change ${snap.regime.trading_days_since_last_change}d ago) · ${snap.regime.as_of}`);
|
|
38
40
|
}
|
|
@@ -40,6 +42,9 @@ export function renderPlain(snap, width = 100) {
|
|
|
40
42
|
const published = tiersPublished(snap.board);
|
|
41
43
|
if (!published)
|
|
42
44
|
lines.push(pausedLine(snap.board));
|
|
45
|
+
if (snap.board.rows.some((row) => !hasRadarDetail(row))) {
|
|
46
|
+
lines.push("Rows in the public summary show a funding index. Detailed risk inputs are withheld.");
|
|
47
|
+
}
|
|
43
48
|
lines.push("");
|
|
44
49
|
lines.push(" " +
|
|
45
50
|
cell("INSTITUTION", cols.name) +
|
|
@@ -55,11 +60,11 @@ export function renderPlain(snap, width = 100) {
|
|
|
55
60
|
cell(row.inst_type, cols.type) +
|
|
56
61
|
(published ? cell(row.grade ?? "", cols.grade) : "") +
|
|
57
62
|
cell(String(row.score), cols.score) +
|
|
58
|
-
cell(pct(row.
|
|
59
|
-
cell(movement(row
|
|
63
|
+
cell(pct(probabilities(row).pd_12m), cols.pd) +
|
|
64
|
+
cell(movement(probabilityChange(row)).text, cols.move) +
|
|
60
65
|
(published
|
|
61
|
-
?
|
|
62
|
-
:
|
|
66
|
+
? fundingSummary(row).padEnd(12) + (hasRadarDetail(row) ? riskBand(row).toUpperCase() : "n/a")
|
|
67
|
+
: fundingSummary(row)));
|
|
63
68
|
}
|
|
64
69
|
if (!published)
|
|
65
70
|
lines.push("* research only while review tiers are paused");
|
|
@@ -103,7 +108,11 @@ function renderPlainUS(snap, width) {
|
|
|
103
108
|
/** A row as research only: no grade letter even from an older cached board. */
|
|
104
109
|
function researchRow(r) {
|
|
105
110
|
const withoutGrade = (o) => Object.fromEntries(Object.entries(o).filter(([k]) => k !== "grade" && k !== "tier"));
|
|
106
|
-
return {
|
|
111
|
+
return {
|
|
112
|
+
...withoutGrade(r),
|
|
113
|
+
...(hasRadarDetail(r) ? { hazard: withoutGrade(r.hazard) } : {}),
|
|
114
|
+
pd_research_only: true,
|
|
115
|
+
};
|
|
107
116
|
}
|
|
108
117
|
/** Machine-readable dump for `--json`. */
|
|
109
118
|
export function renderJson(snap) {
|
|
@@ -125,7 +134,13 @@ export function renderJson(snap) {
|
|
|
125
134
|
stale: snap.stale ? { cached_at: snap.stale.savedAt } : null,
|
|
126
135
|
market_regime: snap.regime,
|
|
127
136
|
tier_publication: snap.board.tier_publication ?? null,
|
|
128
|
-
|
|
137
|
+
...(snap.board.access ? { access: snap.board.access } : {}),
|
|
138
|
+
...(snap.board.historical_evidence ? { historical_evidence: snap.board.historical_evidence } : {}),
|
|
139
|
+
rows: sortRows(snap.board.rows, "risk").map((row) => {
|
|
140
|
+
if (!published)
|
|
141
|
+
return researchRow(row);
|
|
142
|
+
return hasRadarDetail(row) ? { ...row, risk_band: riskBand(row) } : row;
|
|
143
|
+
}),
|
|
129
144
|
}, null, 2);
|
|
130
145
|
}
|
|
131
146
|
function evidenceFlag(value) {
|
|
@@ -161,3 +176,94 @@ export function renderEvidenceRecord(record) {
|
|
|
161
176
|
export function renderEvidenceJson(record) {
|
|
162
177
|
return JSON.stringify(record, null, 2);
|
|
163
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": {
|