liquilens 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +31 -0
- package/README.md +128 -0
- package/dist/App.js +292 -0
- package/dist/api.js +71 -0
- package/dist/cache.js +57 -0
- package/dist/cli.js +179 -0
- package/dist/format.js +152 -0
- package/dist/plain.js +118 -0
- package/dist/riskBands.js +45 -0
- package/package.json +59 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Source-Available License v1.0
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 beepboop2025. All rights reserved.
|
|
4
|
+
|
|
5
|
+
This source code is published for **transparency, learning, and evaluation**. It is
|
|
6
|
+
**not** open source and **not** free for commercial use.
|
|
7
|
+
|
|
8
|
+
## Permitted
|
|
9
|
+
You may **view, study, and fork** this code on GitHub, and run it **locally** for
|
|
10
|
+
personal study, evaluation, or non-commercial research — provided you keep this license,
|
|
11
|
+
the copyright notice, and all attribution intact.
|
|
12
|
+
|
|
13
|
+
## Not permitted (without a separate written commercial license)
|
|
14
|
+
- Using the software, in whole or part, for any **commercial purpose**.
|
|
15
|
+
- **Hosting or operating** it (or a substantial/derivative portion) **as a service** or
|
|
16
|
+
product for third parties.
|
|
17
|
+
- Building or operating a **competing product or service**.
|
|
18
|
+
- **Redistributing, sublicensing, selling, or relicensing** it or derivatives.
|
|
19
|
+
|
|
20
|
+
## Reserved
|
|
21
|
+
All rights not expressly granted are reserved. No trademark or patent rights are granted.
|
|
22
|
+
Any **data, models, or credentials** referenced by the software are not licensed for reuse.
|
|
23
|
+
|
|
24
|
+
## Commercial use
|
|
25
|
+
Want to use this commercially? That's available under a separate agreement — open a GitHub
|
|
26
|
+
issue or contact the author.
|
|
27
|
+
|
|
28
|
+
## No warranty
|
|
29
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. IN NO EVENT SHALL THE
|
|
30
|
+
AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY ARISING FROM THE SOFTWARE OR
|
|
31
|
+
ITS USE.
|
package/README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# liquilens — the terminal
|
|
2
|
+
|
|
3
|
+
The LiquiLens Failure Radar as a live terminal dashboard, in the spirit of
|
|
4
|
+
Claude Code / htop. Zero keys required: it reads the same public, no-auth
|
|
5
|
+
endpoints that power the web board, and keeps working offline from a cached
|
|
6
|
+
snapshot.
|
|
7
|
+
|
|
8
|
+
Need the radar on your own counterparty or borrower book? A fixed-scope,
|
|
9
|
+
self-hosted proof pilot is available at
|
|
10
|
+
[liquilens.in/pilot](https://liquilens.in/pilot/).
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
◆ LIQUILENS · Failure Radar · IN/US (t to switch)
|
|
14
|
+
market regime SHIFT (log-SR 1.16, last change 13d ago) ███▁▁▂▂▂ · 2026-07-16
|
|
15
|
+
|
|
16
|
+
INSTITUTION TYPE GRADE SCORE PD 12M Δ PD FUNDING
|
|
17
|
+
❯ ESAF Small Finance Bank sfb BBB 66 0.40% ▲ 0.09% stable
|
|
18
|
+
...
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Two boards, one command:
|
|
22
|
+
|
|
23
|
+
- **IN** — Indian institutions (banks/SFBs/NBFCs/MFIs): grades, 12/24/36-month
|
|
24
|
+
failure probabilities, funding bands, PCA status, forensics, market lens,
|
|
25
|
+
GDELT news watch.
|
|
26
|
+
- **US** — the riskiest tail of 1,000+ FDIC-scored banks (undertow engine):
|
|
27
|
+
within-quarter percentile score, noncurrent assets, uninsured/brokered
|
|
28
|
+
deposits, CRE concentration, NDFI-to-tier-1.
|
|
29
|
+
|
|
30
|
+
## Install
|
|
31
|
+
|
|
32
|
+
Run once without keeping an install:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npx --yes github:beepboop2025/liquilens-cli
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Or keep the command on your PATH:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install --global github:beepboop2025/liquilens-cli
|
|
42
|
+
liquilens # India board
|
|
43
|
+
liquilens --region us # US board
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
From a source checkout:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm ci
|
|
50
|
+
npm link
|
|
51
|
+
liquilens
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Modes
|
|
55
|
+
|
|
56
|
+
- **Interactive TUI** (default in a terminal): live board, auto-refreshes
|
|
57
|
+
every 5 minutes, adapts to any terminal size (scrolling viewport on short
|
|
58
|
+
terminals, adaptive columns on narrow ones), `t` switches region.
|
|
59
|
+
- **`--plain`** (automatic when piped): one-shot ANSI-free table — safe for
|
|
60
|
+
scripts, cron mails, CI logs.
|
|
61
|
+
- **`--json`**: one-shot machine-readable dump (rows + `risk_band` + regime).
|
|
62
|
+
- **`--fail-on amber|red`**: alerting for cron/CI — exits 3 when any Indian
|
|
63
|
+
institution is at/above the band. (India only: US scores are within-quarter
|
|
64
|
+
percentile ranks — a relative leaderboard — so an absolute threshold would
|
|
65
|
+
always fire.)
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
# cron: mail me the board only when something turns red
|
|
69
|
+
liquilens --fail-on red > /tmp/board.txt || mail -s "LiquiLens RED" me@x < /tmp/board.txt
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Keys
|
|
73
|
+
|
|
74
|
+
| key | action |
|
|
75
|
+
| --- | --- |
|
|
76
|
+
| ↑/↓ or j/k | move selection |
|
|
77
|
+
| ⏎ | toggle institution detail |
|
|
78
|
+
| t | switch region (IN ↔ US) |
|
|
79
|
+
| s | cycle sort (IN: risk/movement/score/name · US: risk/noncurrent/uninsured/assets/name) |
|
|
80
|
+
| / | incremental filter (IN: name/slug/type · US: bank/state/FDIC cert) |
|
|
81
|
+
| r | refresh now |
|
|
82
|
+
| esc | close detail / clear filter |
|
|
83
|
+
| q | quit |
|
|
84
|
+
|
|
85
|
+
## Reliability
|
|
86
|
+
|
|
87
|
+
- **Retries**: 3 attempts with backoff on network errors, 429s and 5xx.
|
|
88
|
+
- **Offline cache**: every good board is snapshotted per region (atomic write,
|
|
89
|
+
XDG cache dir; `%LOCALAPPDATA%` on Windows). If the API is unreachable you
|
|
90
|
+
get the cached board with a clear "offline — cached from Xh ago" banner.
|
|
91
|
+
Exit 1 only when there is no data at all.
|
|
92
|
+
- **Networks**: IPv4-first DNS plus undici `autoSelectFamily` (fast Happy
|
|
93
|
+
Eyeballs) — works on IPv6-blackholed *and* IPv6-only networks. `HTTPS_PROXY`
|
|
94
|
+
/ `HTTP_PROXY` / `NO_PROXY` are honored.
|
|
95
|
+
- **Partial failure**: if only the market-regime endpoint fails, the board
|
|
96
|
+
still renders with a "regime unavailable" note.
|
|
97
|
+
- **Tests + CI**: pure logic (columns, sorting, filtering, viewport, risk
|
|
98
|
+
bands, sparkline, US formatting, cache) is unit-tested (`npm test`);
|
|
99
|
+
CI runs build + tests + live smokes on Node
|
|
100
|
+
18/20/22.
|
|
101
|
+
|
|
102
|
+
## Privacy
|
|
103
|
+
|
|
104
|
+
The CLI sends no cookies, device identifiers, installation IDs, or command
|
|
105
|
+
analytics. API requests carry the aggregate product-surface label `cli` so the
|
|
106
|
+
service can count successful board reads. Arguments, filters, cache contents,
|
|
107
|
+
and machine details are never sent as analytics.
|
|
108
|
+
|
|
109
|
+
## Exit codes
|
|
110
|
+
|
|
111
|
+
0 ok · 1 no data (API down, no cache) · 2 bad usage · 3 `--fail-on` breached
|
|
112
|
+
|
|
113
|
+
## Config
|
|
114
|
+
|
|
115
|
+
- `--api <url>` or `LIQUILENS_API` — API host (default
|
|
116
|
+
`https://api.liquilens.in`), e.g. a local backend on `:8000`.
|
|
117
|
+
- `HTTPS_PROXY` — standard CONNECT proxy, honored by all requests.
|
|
118
|
+
|
|
119
|
+
## Where things live
|
|
120
|
+
|
|
121
|
+
- `src/api.ts` — typed fetchers, retry/backoff, proxy + Happy-Eyeballs dialing.
|
|
122
|
+
- `src/cache.ts` — per-region last-good-snapshot cache.
|
|
123
|
+
- `src/format.ts` — pure layout/sort/filter/viewport/sparkline logic (tested).
|
|
124
|
+
- `src/riskBands.ts` — the row-colour policies. India = absolute thresholds
|
|
125
|
+
(domain judgment — tune here). US = rank-within-board (percentile scores
|
|
126
|
+
drift across quarters, ranks don't).
|
|
127
|
+
- `src/plain.ts` — `--plain` / `--json` renderers + `--fail-on` band logic.
|
|
128
|
+
- `src/App.tsx` — the Ink UI. `src/cli.tsx` — entry point + arg parsing.
|
package/dist/App.js
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { Box, Text, useApp, useInput, useStdout } from "ink";
|
|
4
|
+
import { fetchBoard, fetchNews, fetchRegime, fetchUSBoard, } from "./api.js";
|
|
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";
|
|
7
|
+
import { riskBand, usRiskBandByRank, bandColor } from "./riskBands.js";
|
|
8
|
+
const ACCENT = "#9184d9"; // Nocturne
|
|
9
|
+
const DIM = "gray";
|
|
10
|
+
const REFRESH_MS = 5 * 60_000;
|
|
11
|
+
const NEWS_DEBOUNCE_MS = 250;
|
|
12
|
+
function moveColor(dir) {
|
|
13
|
+
if (dir === "up")
|
|
14
|
+
return bandColor.red;
|
|
15
|
+
if (dir === "down")
|
|
16
|
+
return bandColor.green;
|
|
17
|
+
return DIM;
|
|
18
|
+
}
|
|
19
|
+
function fundColor(band) {
|
|
20
|
+
if (band === "stable")
|
|
21
|
+
return bandColor.green;
|
|
22
|
+
if (band === "not_scored")
|
|
23
|
+
return DIM;
|
|
24
|
+
return bandColor.amber;
|
|
25
|
+
}
|
|
26
|
+
function regimeColor(regime) {
|
|
27
|
+
const r = regime.toUpperCase();
|
|
28
|
+
if (r.includes("ALARM"))
|
|
29
|
+
return bandColor.red;
|
|
30
|
+
if (r.includes("SHIFT") || r.includes("WATCH"))
|
|
31
|
+
return bandColor.amber;
|
|
32
|
+
return bandColor.green;
|
|
33
|
+
}
|
|
34
|
+
function useTermSize() {
|
|
35
|
+
const { stdout } = useStdout();
|
|
36
|
+
const [size, setSize] = useState({
|
|
37
|
+
width: stdout?.columns ?? 80,
|
|
38
|
+
height: stdout?.rows ?? 24,
|
|
39
|
+
});
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (!stdout)
|
|
42
|
+
return;
|
|
43
|
+
const onResize = () => setSize({ width: stdout.columns ?? 80, height: stdout.rows ?? 24 });
|
|
44
|
+
stdout.on("resize", onResize);
|
|
45
|
+
return () => {
|
|
46
|
+
stdout.off("resize", onResize);
|
|
47
|
+
};
|
|
48
|
+
}, [stdout]);
|
|
49
|
+
return size;
|
|
50
|
+
}
|
|
51
|
+
function Header({ region, regime, regimeError, usBoard, width, }) {
|
|
52
|
+
const spark = region === "in" && width >= 96 && regime?.series?.log_sr
|
|
53
|
+
? sparkline(regime.series.log_sr, 28)
|
|
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] }));
|
|
56
|
+
}
|
|
57
|
+
function InRow({ row, selected, cols, }) {
|
|
58
|
+
const band = riskBand(row);
|
|
59
|
+
const move = movement(row.movement.delta_pd_12m);
|
|
60
|
+
return (_jsxs(Box, { children: [_jsx(Text, { color: selected ? ACCENT : DIM, children: selected ? "❯ " : " " }), _jsx(Text, { color: bandColor[band], bold: selected, inverse: selected, children: cell(row.name, cols.name) }), _jsx(Text, { color: DIM, children: cell(row.inst_type, cols.type) }), _jsx(Text, { color: bandColor[band], children: cell(row.grade, cols.grade) }), _jsx(Text, { children: cell(String(row.score), cols.score) }), _jsx(Text, { color: bandColor[band], children: cell(pct(row.hazard.pd_12m), cols.pd) }), _jsx(Text, { color: moveColor(move.dir), children: cell(move.text, cols.move) }), _jsx(Text, { color: fundColor(row.funding.band), children: fundingLabel(row.funding.band) })] }));
|
|
61
|
+
}
|
|
62
|
+
function UsRow({ row, rank, selected, cols, }) {
|
|
63
|
+
const band = usRiskBandByRank(rank);
|
|
64
|
+
return (_jsxs(Box, { children: [_jsx(Text, { color: selected ? ACCENT : DIM, children: selected ? "❯ " : " " }), _jsx(Text, { color: bandColor[band], bold: selected, inverse: selected, children: cell(row.bank, cols.bank) }), _jsx(Text, { color: DIM, children: cell(row.state, cols.state) }), _jsx(Text, { children: cell(fmtAssets(row.assets_usd_k), cols.assets) }), _jsx(Text, { color: bandColor[band], children: cell(row.undertow_score_v02.toFixed(3), cols.score) }), _jsx(Text, { children: cell(rawPct(row.noncurrent_ratio), cols.noncurr) }), _jsx(Text, { children: cell(pct1(row.uninsured_ratio), cols.uninsured) }), _jsx(Text, { color: DIM, children: pct1(row.ndfi_to_tier1) })] }));
|
|
65
|
+
}
|
|
66
|
+
function NewsLine({ news }) {
|
|
67
|
+
if (news === null)
|
|
68
|
+
return null;
|
|
69
|
+
if (news === "loading")
|
|
70
|
+
return _jsx(Text, { color: DIM, children: "news watch loading\u2026" });
|
|
71
|
+
if (news === "error")
|
|
72
|
+
return _jsx(Text, { color: DIM, children: "news watch unavailable" });
|
|
73
|
+
const stressColor = news.news_stress >= 50
|
|
74
|
+
? bandColor.red
|
|
75
|
+
: news.news_stress >= 20
|
|
76
|
+
? bandColor.amber
|
|
77
|
+
: bandColor.green;
|
|
78
|
+
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)))] }));
|
|
79
|
+
}
|
|
80
|
+
function InDetail({ row, news, }) {
|
|
81
|
+
const band = riskBand(row);
|
|
82
|
+
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: bandColor[band], children: row.name }), _jsxs(Text, { color: DIM, children: [row.inst_type, " \u00B7 ", row.quarter, " \u00B7 data as of ", row.as_of, " (", row.age_months, "mo old)"] })] }), _jsxs(Text, { children: [_jsx(Text, { color: DIM, children: "grade " }), _jsx(Text, { bold: true, children: row.grade }), _jsx(Text, { color: DIM, children: " score " }), _jsx(Text, { bold: true, children: row.score }), _jsx(Text, { color: DIM, children: " PD 12/24/36m " }), _jsxs(Text, { bold: true, color: bandColor[band], children: [pct(row.hazard.pd_12m), " / ", pct(row.hazard.pd_24m), " /", " ", pct(row.hazard.pd_36m)] })] }), 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: [" \u2014 ", 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) })] })), _jsx(NewsLine, { news: news })] }));
|
|
83
|
+
}
|
|
84
|
+
function UsDetail({ row, rank }) {
|
|
85
|
+
const band = usRiskBandByRank(rank);
|
|
86
|
+
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: bandColor[band], children: row.bank }), _jsxs(Text, { color: DIM, children: [row.state, " \u00B7 FDIC cert ", row.cert, " \u00B7 ", fmtAssets(row.assets_usd_k), " ", "assets"] })] }), _jsxs(Text, { children: [_jsx(Text, { color: DIM, children: "undertow score " }), _jsx(Text, { bold: true, color: bandColor[band], children: row.undertow_score_v02.toFixed(4) }), _jsxs(Text, { color: DIM, children: [" ", "(#", rank + 1, " riskiest \u00B7 within-quarter percentile \u00B7", " ", row.signals_available, " signals)"] })] }), _jsxs(Text, { children: [_jsx(Text, { color: DIM, children: "noncurrent assets " }), _jsx(Text, { bold: true, children: rawPct(row.noncurrent_ratio) }), _jsx(Text, { color: DIM, children: " uninsured deposits " }), _jsx(Text, { bold: true, children: pct1(row.uninsured_ratio) }), _jsx(Text, { color: DIM, children: " brokered deposits " }), _jsx(Text, { bold: true, children: pct1(row.brokered_ratio) })] }), _jsxs(Text, { children: [_jsx(Text, { color: DIM, children: "CRE concentration " }), _jsx(Text, { bold: true, children: pct1(row.cre_concentration) }), _jsx(Text, { color: DIM, children: " NDFI exposure / tier-1 " }), _jsx(Text, { bold: true, children: pct1(row.ndfi_to_tier1) })] }), _jsx(Text, { color: DIM, children: "source: FDIC BankFind Suite (public domain) \u00B7 undertow engine \u00B7 relative rank, not a PD" })] }));
|
|
87
|
+
}
|
|
88
|
+
export default function App({ initialRegion = "in" }) {
|
|
89
|
+
const { exit } = useApp();
|
|
90
|
+
const { width, height } = useTermSize();
|
|
91
|
+
const [region, setRegion] = useState(initialRegion);
|
|
92
|
+
const [board, setBoard] = useState(null);
|
|
93
|
+
const [regime, setRegime] = useState(null);
|
|
94
|
+
const [regimeError, setRegimeError] = useState(false);
|
|
95
|
+
const [usBoard, setUsBoard] = useState(null);
|
|
96
|
+
const [staleFrom, setStaleFrom] = useState({
|
|
97
|
+
in: null,
|
|
98
|
+
us: null,
|
|
99
|
+
});
|
|
100
|
+
const [error, setError] = useState(null);
|
|
101
|
+
const [loading, setLoading] = useState(true);
|
|
102
|
+
const [cursor, setCursor] = useState(0);
|
|
103
|
+
const [showDetail, setShowDetail] = useState(false);
|
|
104
|
+
const [inSort, setInSort] = useState("risk");
|
|
105
|
+
const [usSort, setUsSort] = useState("risk");
|
|
106
|
+
const [filterMode, setFilterMode] = useState(false);
|
|
107
|
+
const [query, setQuery] = useState("");
|
|
108
|
+
const [news, setNews] = useState(null);
|
|
109
|
+
const newsCache = useRef(new Map());
|
|
110
|
+
const loadSeq = useRef(0);
|
|
111
|
+
const loadIn = useCallback(() => {
|
|
112
|
+
const seq = ++loadSeq.current;
|
|
113
|
+
setLoading(true);
|
|
114
|
+
setError(null);
|
|
115
|
+
Promise.allSettled([fetchBoard(), fetchRegime()]).then(([boardRes, regimeRes]) => {
|
|
116
|
+
if (seq !== loadSeq.current)
|
|
117
|
+
return;
|
|
118
|
+
setLoading(false);
|
|
119
|
+
const gotRegime = regimeRes.status === "fulfilled" ? regimeRes.value : null;
|
|
120
|
+
setRegimeError(regimeRes.status === "rejected");
|
|
121
|
+
if (boardRes.status === "fulfilled") {
|
|
122
|
+
setBoard(boardRes.value);
|
|
123
|
+
setStaleFrom((s) => ({ ...s, in: null }));
|
|
124
|
+
if (gotRegime)
|
|
125
|
+
setRegime(gotRegime);
|
|
126
|
+
saveCached("in", { board: boardRes.value, regime: gotRegime });
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const cached = loadCached("in");
|
|
130
|
+
if (cached) {
|
|
131
|
+
setBoard(cached.data.board);
|
|
132
|
+
setRegime(gotRegime ?? cached.data.regime);
|
|
133
|
+
setStaleFrom((s) => ({ ...s, in: cached.savedAt }));
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
setError(String(boardRes.reason?.message ?? boardRes.reason));
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}, []);
|
|
140
|
+
const loadUs = useCallback(() => {
|
|
141
|
+
const seq = ++loadSeq.current;
|
|
142
|
+
setLoading(true);
|
|
143
|
+
setError(null);
|
|
144
|
+
fetchUSBoard()
|
|
145
|
+
.then((b) => {
|
|
146
|
+
if (seq !== loadSeq.current)
|
|
147
|
+
return;
|
|
148
|
+
setUsBoard(b);
|
|
149
|
+
setStaleFrom((s) => ({ ...s, us: null }));
|
|
150
|
+
saveCached("us", b);
|
|
151
|
+
})
|
|
152
|
+
.catch((err) => {
|
|
153
|
+
if (seq !== loadSeq.current)
|
|
154
|
+
return;
|
|
155
|
+
const cached = loadCached("us");
|
|
156
|
+
if (cached) {
|
|
157
|
+
setUsBoard(cached.data);
|
|
158
|
+
setStaleFrom((s) => ({ ...s, us: cached.savedAt }));
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
setError(String(err?.message ?? err));
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
.finally(() => {
|
|
165
|
+
if (seq === loadSeq.current)
|
|
166
|
+
setLoading(false);
|
|
167
|
+
});
|
|
168
|
+
}, []);
|
|
169
|
+
const load = useCallback((r = region) => (r === "in" ? loadIn() : loadUs()), [region, loadIn, loadUs]);
|
|
170
|
+
// Initial load only — later loads are user- or timer-driven.
|
|
171
|
+
useEffect(() => {
|
|
172
|
+
load(region);
|
|
173
|
+
}, []);
|
|
174
|
+
useEffect(() => {
|
|
175
|
+
const t = setInterval(() => load(region), REFRESH_MS);
|
|
176
|
+
return () => clearInterval(t);
|
|
177
|
+
}, [load, region]);
|
|
178
|
+
const inRows = useMemo(() => sortRows(filterRows(board?.rows ?? [], query), inSort), [board, query, inSort]);
|
|
179
|
+
// US rank (risk position) must be computed on the risk ordering, then we
|
|
180
|
+
// re-sort for display so colours stay stable across sort modes.
|
|
181
|
+
const usRows = useMemo(() => {
|
|
182
|
+
const byRisk = sortUSRows(usBoard?.board ?? [], "risk");
|
|
183
|
+
const rank = new Map(byRisk.map((r, i) => [r.cert, i]));
|
|
184
|
+
return sortUSRows(filterUSRows(byRisk, query), usSort).map((r) => ({
|
|
185
|
+
row: r,
|
|
186
|
+
rank: rank.get(r.cert) ?? 99,
|
|
187
|
+
}));
|
|
188
|
+
}, [usBoard, query, usSort]);
|
|
189
|
+
const rowCount = region === "in" ? inRows.length : usRows.length;
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
setCursor((c) => Math.min(c, Math.max(0, rowCount - 1)));
|
|
192
|
+
}, [rowCount]);
|
|
193
|
+
// Debounced lazy news for the selected Indian institution.
|
|
194
|
+
const selectedIn = region === "in" ? inRows[cursor] : undefined;
|
|
195
|
+
useEffect(() => {
|
|
196
|
+
if (!showDetail || !selectedIn) {
|
|
197
|
+
setNews(null);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const hit = newsCache.current.get(selectedIn.slug);
|
|
201
|
+
if (hit) {
|
|
202
|
+
setNews(hit);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
let cancelled = false;
|
|
206
|
+
setNews("loading");
|
|
207
|
+
const timer = setTimeout(() => {
|
|
208
|
+
fetchNews(selectedIn.slug)
|
|
209
|
+
.then((n) => {
|
|
210
|
+
newsCache.current.set(selectedIn.slug, n);
|
|
211
|
+
if (!cancelled)
|
|
212
|
+
setNews(n);
|
|
213
|
+
})
|
|
214
|
+
.catch(() => {
|
|
215
|
+
if (!cancelled)
|
|
216
|
+
setNews("error");
|
|
217
|
+
});
|
|
218
|
+
}, NEWS_DEBOUNCE_MS);
|
|
219
|
+
return () => {
|
|
220
|
+
cancelled = true;
|
|
221
|
+
clearTimeout(timer);
|
|
222
|
+
};
|
|
223
|
+
}, [showDetail, selectedIn?.slug]);
|
|
224
|
+
useInput((input, key) => {
|
|
225
|
+
if (filterMode) {
|
|
226
|
+
if (key.escape) {
|
|
227
|
+
setFilterMode(false);
|
|
228
|
+
setQuery("");
|
|
229
|
+
}
|
|
230
|
+
else if (key.return) {
|
|
231
|
+
setFilterMode(false);
|
|
232
|
+
}
|
|
233
|
+
else if (key.backspace || key.delete) {
|
|
234
|
+
setQuery((q) => q.slice(0, -1));
|
|
235
|
+
}
|
|
236
|
+
else if (input && !key.ctrl && !key.meta) {
|
|
237
|
+
setQuery((q) => q + input);
|
|
238
|
+
}
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (input === "q" || (key.ctrl && input === "c"))
|
|
242
|
+
exit();
|
|
243
|
+
if (input === "r")
|
|
244
|
+
load(region);
|
|
245
|
+
if (input === "t") {
|
|
246
|
+
const next = region === "in" ? "us" : "in";
|
|
247
|
+
setRegion(next);
|
|
248
|
+
setCursor(0);
|
|
249
|
+
setShowDetail(false);
|
|
250
|
+
setQuery("");
|
|
251
|
+
if (next === "us" && !usBoard)
|
|
252
|
+
loadUs();
|
|
253
|
+
if (next === "in" && !board)
|
|
254
|
+
loadIn();
|
|
255
|
+
}
|
|
256
|
+
if (input === "s") {
|
|
257
|
+
if (region === "in")
|
|
258
|
+
setInSort((m) => SORT_MODES[(SORT_MODES.indexOf(m) + 1) % SORT_MODES.length]);
|
|
259
|
+
else
|
|
260
|
+
setUsSort((m) => US_SORT_MODES[(US_SORT_MODES.indexOf(m) + 1) % US_SORT_MODES.length]);
|
|
261
|
+
}
|
|
262
|
+
if (input === "/")
|
|
263
|
+
setFilterMode(true);
|
|
264
|
+
if (key.upArrow || input === "k")
|
|
265
|
+
setCursor((c) => Math.max(0, c - 1));
|
|
266
|
+
if (key.downArrow || input === "j")
|
|
267
|
+
setCursor((c) => Math.min(rowCount - 1, c + 1));
|
|
268
|
+
if (key.return)
|
|
269
|
+
setShowDetail((d) => !d);
|
|
270
|
+
if (key.escape) {
|
|
271
|
+
if (showDetail)
|
|
272
|
+
setShowDetail(false);
|
|
273
|
+
else if (query)
|
|
274
|
+
setQuery("");
|
|
275
|
+
}
|
|
276
|
+
}, { isActive: process.stdin.isTTY === true });
|
|
277
|
+
const cols = useMemo(() => computeCols(width), [width]);
|
|
278
|
+
const usCols = useMemo(() => computeUSCols(width), [width]);
|
|
279
|
+
const hasData = region === "in" ? board !== null : usBoard !== null;
|
|
280
|
+
const regionStale = staleFrom[region];
|
|
281
|
+
const sortMode = region === "in" ? inSort : usSort;
|
|
282
|
+
const chrome = 7 + (showDetail ? 13 : 0) + (regionStale ? 1 : 0);
|
|
283
|
+
const visible = Math.max(3, height - chrome);
|
|
284
|
+
const vp = viewport(rowCount, visible, cursor);
|
|
285
|
+
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 \u2014 showing cached board from", " ", describeAge(ageMinutes(regionStale)), " (retrying every 5m, r to retry now)"] })), error && (_jsxs(Text, { color: bandColor.red, children: ["\u2716 ", error, " \u2014 press r to retry, or set LIQUILENS_API / HTTPS_PROXY"] })), loading && !hasData && _jsx(Text, { color: DIM, children: "\u283F loading live board\u2026" }), 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), 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"
|
|
286
|
+
? inRows
|
|
287
|
+
.slice(vp.start, vp.end)
|
|
288
|
+
.map((row, i) => (_jsx(InRow, { row: row, selected: vp.start + i === cursor, cols: cols }, row.slug)))
|
|
289
|
+
: usRows
|
|
290
|
+
.slice(vp.start, vp.end)
|
|
291
|
+
.map(({ row, rank }, i) => (_jsx(UsRow, { row: row, rank: rank, selected: vp.start + i === cursor, cols: usCols }, row.cert))), vp.below > 0 && _jsxs(Text, { color: DIM, children: [" ", "\u2193 ", vp.below, " more"] }), rowCount === 0 && (_jsxs(Text, { color: DIM, children: [" ", "no institutions match \"", query, "\""] })), showDetail && region === "in" && selectedIn && (_jsx(Box, { marginTop: 1, children: _jsx(InDetail, { row: selectedIn, news: news }) })), showDetail && region === "us" && usRows[cursor] && (_jsx(Box, { marginTop: 1, children: _jsx(UsDetail, { row: usRows[cursor].row, rank: usRows[cursor].rank }) }))] })), (filterMode || query) && (_jsxs(Text, { children: [_jsx(Text, { color: ACCENT, children: "/" }), _jsx(Text, { children: query }), filterMode && _jsx(Text, { color: ACCENT, children: "\u258F" }), _jsxs(Text, { color: DIM, children: [" ", "(", rowCount, " match", rowCount === 1 ? "" : "es", filterMode ? ", ⏎ keep · esc clear" : ", esc clear", ")"] })] })), _jsx(Box, { marginTop: 1, children: _jsxs(Text, { color: DIM, wrap: "truncate", children: ["\u2191\u2193 select \u00B7 \u23CE detail \u00B7 t region \u00B7 s sort (", sortMode, ") \u00B7 / filter \u00B7 r refresh \u00B7 q quit", region === "in" && board ? ` · as of ${board.as_of}` : "", region === "us" && usBoard ? ` · quarter ${usBoard.as_of}` : "", " · liquilens.in", loading && hasData ? " · refreshing…" : ""] }) })] }));
|
|
292
|
+
}
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { fetch as undiciFetch, Agent, EnvHttpProxyAgent, } from "undici";
|
|
2
|
+
export const DEFAULT_API = "https://api.liquilens.in";
|
|
3
|
+
let apiBase = process.env.LIQUILENS_API ?? DEFAULT_API;
|
|
4
|
+
let clientVersion = "dev";
|
|
5
|
+
export function setApiBase(url) {
|
|
6
|
+
apiBase = url.replace(/\/+$/, "");
|
|
7
|
+
}
|
|
8
|
+
export function getApiBase() {
|
|
9
|
+
return apiBase;
|
|
10
|
+
}
|
|
11
|
+
export function setClientVersion(version) {
|
|
12
|
+
clientVersion = version;
|
|
13
|
+
}
|
|
14
|
+
const CONNECT_OPTS = {
|
|
15
|
+
timeout: 10_000,
|
|
16
|
+
// Real Happy Eyeballs with a fast fallback: survives networks that
|
|
17
|
+
// blackhole IPv6 after connect, and still works on IPv6-only networks.
|
|
18
|
+
autoSelectFamily: true,
|
|
19
|
+
autoSelectFamilyAttemptTimeout: 300,
|
|
20
|
+
};
|
|
21
|
+
const hasProxyEnv = Boolean(process.env.HTTPS_PROXY ??
|
|
22
|
+
process.env.https_proxy ??
|
|
23
|
+
process.env.HTTP_PROXY ??
|
|
24
|
+
process.env.http_proxy);
|
|
25
|
+
const dispatcher = hasProxyEnv
|
|
26
|
+
? new EnvHttpProxyAgent({ connect: CONNECT_OPTS })
|
|
27
|
+
: new Agent({ connect: CONNECT_OPTS });
|
|
28
|
+
const RETRIES = 3;
|
|
29
|
+
const ATTEMPT_TIMEOUT_MS = 15_000;
|
|
30
|
+
function sleep(ms) {
|
|
31
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
32
|
+
}
|
|
33
|
+
async function getJson(path) {
|
|
34
|
+
let lastErr;
|
|
35
|
+
for (let attempt = 0; attempt < RETRIES; attempt++) {
|
|
36
|
+
try {
|
|
37
|
+
const res = await undiciFetch(`${apiBase}${path}`, {
|
|
38
|
+
dispatcher,
|
|
39
|
+
signal: AbortSignal.timeout(ATTEMPT_TIMEOUT_MS),
|
|
40
|
+
// These identify the product surface, not the person or machine. The
|
|
41
|
+
// API aggregates successful board reads by this allow-listed value;
|
|
42
|
+
// there is no client-side telemetry, cookie, or installation ID.
|
|
43
|
+
headers: {
|
|
44
|
+
"user-agent": `liquilens-cli/${clientVersion}`,
|
|
45
|
+
"x-liquilens-client": "cli",
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
if (res.status === 429 || res.status >= 500) {
|
|
49
|
+
lastErr = new Error(`HTTP ${res.status} from ${path}`);
|
|
50
|
+
}
|
|
51
|
+
else if (!res.ok) {
|
|
52
|
+
throw new Error(`HTTP ${res.status} from ${path}`);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return (await res.json());
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
if (err instanceof Error && err.message.startsWith("HTTP 4"))
|
|
60
|
+
throw err;
|
|
61
|
+
lastErr = err;
|
|
62
|
+
}
|
|
63
|
+
if (attempt < RETRIES - 1)
|
|
64
|
+
await sleep(500 * 2 ** attempt);
|
|
65
|
+
}
|
|
66
|
+
throw lastErr instanceof Error ? lastErr : new Error(String(lastErr));
|
|
67
|
+
}
|
|
68
|
+
export const fetchBoard = () => getJson("/api/failure-radar/board");
|
|
69
|
+
export const fetchUSBoard = () => getJson("/api/us-radar/board");
|
|
70
|
+
export const fetchRegime = () => getJson("/api/public-signals/market-regime");
|
|
71
|
+
export const fetchNews = (slug) => getJson(`/api/public-signals/news/${encodeURIComponent(slug)}`);
|
package/dist/cache.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
function cacheDir() {
|
|
5
|
+
if (process.env.XDG_CACHE_HOME)
|
|
6
|
+
return path.join(process.env.XDG_CACHE_HOME, "liquilens");
|
|
7
|
+
if (process.platform === "win32" && process.env.LOCALAPPDATA)
|
|
8
|
+
return path.join(process.env.LOCALAPPDATA, "liquilens", "cache");
|
|
9
|
+
return path.join(os.homedir(), ".cache", "liquilens");
|
|
10
|
+
}
|
|
11
|
+
function cacheFile(region) {
|
|
12
|
+
return path.join(cacheDir(), `last-${region}.json`);
|
|
13
|
+
}
|
|
14
|
+
export function saveCached(region, data) {
|
|
15
|
+
try {
|
|
16
|
+
const file = cacheFile(region);
|
|
17
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
18
|
+
const entry = { data, savedAt: new Date().toISOString() };
|
|
19
|
+
// Write-then-rename so a crash mid-write never corrupts the cache.
|
|
20
|
+
const tmp = `${file}.tmp`;
|
|
21
|
+
fs.writeFileSync(tmp, JSON.stringify(entry));
|
|
22
|
+
fs.renameSync(tmp, file);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// Cache is best-effort; never let it break the live path.
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export function loadCached(region) {
|
|
29
|
+
try {
|
|
30
|
+
const raw = fs.readFileSync(cacheFile(region), "utf8");
|
|
31
|
+
const entry = JSON.parse(raw);
|
|
32
|
+
if (!entry?.data || !entry.savedAt)
|
|
33
|
+
return null;
|
|
34
|
+
return entry;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function ageMinutes(savedAt, now = Date.now()) {
|
|
41
|
+
const t = Date.parse(savedAt);
|
|
42
|
+
if (Number.isNaN(t))
|
|
43
|
+
return Infinity;
|
|
44
|
+
return Math.max(0, Math.round((now - t) / 60_000));
|
|
45
|
+
}
|
|
46
|
+
export function describeAge(minutes) {
|
|
47
|
+
if (!Number.isFinite(minutes))
|
|
48
|
+
return "unknown age";
|
|
49
|
+
if (minutes < 1)
|
|
50
|
+
return "just now";
|
|
51
|
+
if (minutes < 60)
|
|
52
|
+
return `${minutes}m ago`;
|
|
53
|
+
const hours = Math.floor(minutes / 60);
|
|
54
|
+
if (hours < 48)
|
|
55
|
+
return `${hours}h ago`;
|
|
56
|
+
return `${Math.floor(hours / 24)}d ago`;
|
|
57
|
+
}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import dns from "node:dns";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { render } from "ink";
|
|
6
|
+
import App from "./App.js";
|
|
7
|
+
import { fetchBoard, fetchRegime, fetchUSBoard, setApiBase, setClientVersion, getApiBase, DEFAULT_API, } from "./api.js";
|
|
8
|
+
import { loadCached, saveCached, ageMinutes, describeAge, } from "./cache.js";
|
|
9
|
+
import { renderJson, renderPlain, worstBand } from "./plain.js";
|
|
10
|
+
import { bandAtLeast } from "./riskBands.js";
|
|
11
|
+
// Some networks blackhole IPv6 (Node's fetch hangs while curl works);
|
|
12
|
+
// prefer IPv4 first — undici's autoSelectFamily in api.ts covers the rest.
|
|
13
|
+
dns.setDefaultResultOrder("ipv4first");
|
|
14
|
+
// A crash should read like a message, not a stack dump, and must not leave
|
|
15
|
+
// the terminal in raw mode (Ink's unmount handles restore on normal exits).
|
|
16
|
+
function crash(err) {
|
|
17
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
18
|
+
process.stderr.write(`\nliquilens: unexpected error — ${msg}\n`);
|
|
19
|
+
process.stderr.write("Run again with --plain for a minimal path, or check --help.\n");
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
process.on("uncaughtException", crash);
|
|
23
|
+
process.on("unhandledRejection", crash);
|
|
24
|
+
const require = createRequire(import.meta.url);
|
|
25
|
+
const { version } = require("../package.json");
|
|
26
|
+
setClientVersion(version);
|
|
27
|
+
const HELP = `liquilens ${version} — LiquiLens Failure Radar in your terminal
|
|
28
|
+
|
|
29
|
+
Usage: liquilens [options]
|
|
30
|
+
|
|
31
|
+
Runs an interactive dashboard when attached to a terminal; falls back to a
|
|
32
|
+
plain table when piped. Data comes from public, no-auth LiquiLens endpoints.
|
|
33
|
+
|
|
34
|
+
Options:
|
|
35
|
+
--region <in|us> board to show (default in). in = India institutions,
|
|
36
|
+
us = FDIC-scored US banks (undertow engine)
|
|
37
|
+
--plain one-shot ANSI-free table (default when stdout is not a TTY)
|
|
38
|
+
--json one-shot machine-readable JSON dump
|
|
39
|
+
--fail-on <band> exit 3 if any institution is at/above band (amber|red).
|
|
40
|
+
India board only — the US board is a relative leaderboard.
|
|
41
|
+
Implies --plain unless --json is given. For cron/CI alerts.
|
|
42
|
+
--api <url> API host (default ${DEFAULT_API}; env LIQUILENS_API)
|
|
43
|
+
-h, --help show this help
|
|
44
|
+
-v, --version show version
|
|
45
|
+
|
|
46
|
+
Environment:
|
|
47
|
+
LIQUILENS_API same as --api
|
|
48
|
+
HTTPS_PROXY honored for all requests (CONNECT proxy)
|
|
49
|
+
|
|
50
|
+
Keys (interactive): ↑↓/jk select · ⏎ detail · t region · s sort · / filter ·
|
|
51
|
+
r refresh · q quit
|
|
52
|
+
Exit codes: 0 ok · 1 no data (API down and no cache) · 2 bad usage ·
|
|
53
|
+
3 --fail-on threshold breached`;
|
|
54
|
+
function fail(msg, code) {
|
|
55
|
+
process.stderr.write(`liquilens: ${msg}\n`);
|
|
56
|
+
process.exit(code);
|
|
57
|
+
}
|
|
58
|
+
export function parseArgs(argv, isTTY) {
|
|
59
|
+
let mode = null;
|
|
60
|
+
let region = "in";
|
|
61
|
+
let failOn = null;
|
|
62
|
+
for (let i = 0; i < argv.length; i++) {
|
|
63
|
+
const arg = argv[i];
|
|
64
|
+
switch (arg) {
|
|
65
|
+
case "-h":
|
|
66
|
+
case "--help":
|
|
67
|
+
return { exit: HELP };
|
|
68
|
+
case "-v":
|
|
69
|
+
case "--version":
|
|
70
|
+
return { exit: version };
|
|
71
|
+
case "--plain":
|
|
72
|
+
mode = "plain";
|
|
73
|
+
break;
|
|
74
|
+
case "--json":
|
|
75
|
+
mode = "json";
|
|
76
|
+
break;
|
|
77
|
+
case "--region": {
|
|
78
|
+
const r = argv[++i];
|
|
79
|
+
if (r !== "in" && r !== "us")
|
|
80
|
+
fail(`--region must be "in" or "us", got "${r ?? ""}"`, 2);
|
|
81
|
+
region = r;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
case "--fail-on": {
|
|
85
|
+
const b = argv[++i];
|
|
86
|
+
if (b !== "amber" && b !== "red")
|
|
87
|
+
fail(`--fail-on must be "amber" or "red", got "${b ?? ""}"`, 2);
|
|
88
|
+
failOn = b;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case "--api": {
|
|
92
|
+
const url = argv[++i];
|
|
93
|
+
if (!url || !/^https?:\/\//.test(url))
|
|
94
|
+
fail("--api needs an http(s):// URL", 2);
|
|
95
|
+
setApiBase(url);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
default:
|
|
99
|
+
fail(`unknown option "${arg}" (try --help)`, 2);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (failOn && region === "us")
|
|
103
|
+
fail("--fail-on works with --region in only: US scores are within-quarter " +
|
|
104
|
+
"percentile ranks (a relative leaderboard), so an absolute alert " +
|
|
105
|
+
"threshold would always fire", 2);
|
|
106
|
+
if (failOn && mode === null)
|
|
107
|
+
mode = "plain";
|
|
108
|
+
return { mode: mode ?? (isTTY ? "tui" : "plain"), region, failOn };
|
|
109
|
+
}
|
|
110
|
+
async function snapshotOnce(region) {
|
|
111
|
+
if (region === "us") {
|
|
112
|
+
try {
|
|
113
|
+
const board = await fetchUSBoard();
|
|
114
|
+
saveCached("us", board);
|
|
115
|
+
return { region: "us", board, stale: null };
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
const cached = loadCached("us");
|
|
119
|
+
if (cached) {
|
|
120
|
+
return {
|
|
121
|
+
region: "us",
|
|
122
|
+
board: cached.data,
|
|
123
|
+
stale: {
|
|
124
|
+
savedAt: cached.savedAt,
|
|
125
|
+
description: describeAge(ageMinutes(cached.savedAt)),
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
fail(`could not reach ${getApiBase()} and no cached data exists ` +
|
|
130
|
+
`(${err instanceof Error ? err.message : String(err)})`, 1);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const [boardRes, regimeRes] = await Promise.allSettled([
|
|
134
|
+
fetchBoard(),
|
|
135
|
+
fetchRegime(),
|
|
136
|
+
]);
|
|
137
|
+
const regime = regimeRes.status === "fulfilled" ? regimeRes.value : null;
|
|
138
|
+
if (boardRes.status === "fulfilled") {
|
|
139
|
+
saveCached("in", {
|
|
140
|
+
board: boardRes.value,
|
|
141
|
+
regime,
|
|
142
|
+
});
|
|
143
|
+
return { region: "in", board: boardRes.value, regime, stale: null };
|
|
144
|
+
}
|
|
145
|
+
const cached = loadCached("in");
|
|
146
|
+
if (cached) {
|
|
147
|
+
return {
|
|
148
|
+
region: "in",
|
|
149
|
+
board: cached.data.board,
|
|
150
|
+
regime: regime ?? cached.data.regime,
|
|
151
|
+
stale: {
|
|
152
|
+
savedAt: cached.savedAt,
|
|
153
|
+
description: describeAge(ageMinutes(cached.savedAt)),
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const reason = boardRes.reason;
|
|
158
|
+
fail(`could not reach ${getApiBase()} and no cached data exists ` +
|
|
159
|
+
`(${reason instanceof Error ? reason.message : String(reason)})`, 1);
|
|
160
|
+
}
|
|
161
|
+
const parsed = parseArgs(process.argv.slice(2), process.stdout.isTTY === true);
|
|
162
|
+
if ("exit" in parsed) {
|
|
163
|
+
console.log(parsed.exit);
|
|
164
|
+
process.exit(0);
|
|
165
|
+
}
|
|
166
|
+
if (parsed.mode === "tui") {
|
|
167
|
+
render(_jsx(App, { initialRegion: parsed.region }));
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
const snap = await snapshotOnce(parsed.region);
|
|
171
|
+
const width = process.stdout.columns && process.stdout.isTTY
|
|
172
|
+
? process.stdout.columns
|
|
173
|
+
: 110;
|
|
174
|
+
console.log(parsed.mode === "json" ? renderJson(snap) : renderPlain(snap, width));
|
|
175
|
+
if (parsed.failOn && bandAtLeast(worstBand(snap), parsed.failOn)) {
|
|
176
|
+
process.stderr.write(`liquilens: --fail-on ${parsed.failOn} breached\n`);
|
|
177
|
+
process.exit(3);
|
|
178
|
+
}
|
|
179
|
+
}
|
package/dist/format.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
export const pct = (x) => `${(x * 100).toFixed(2)}%`;
|
|
2
|
+
/** Fraction -> "17.0%", tolerating missing values. */
|
|
3
|
+
export const pct1 = (x) => x == null ? "—" : `${(x * 100).toFixed(1)}%`;
|
|
4
|
+
/** Value already in percent units (FDIC noncurrent_ratio: 4.0 = 4%). */
|
|
5
|
+
export const rawPct = (x) => x == null ? "—" : `${x.toFixed(2)}%`;
|
|
6
|
+
/** Assets reported in USD thousands -> "$15.2B" / "$980M". */
|
|
7
|
+
export function fmtAssets(usdK) {
|
|
8
|
+
const usd = usdK * 1_000;
|
|
9
|
+
if (usd >= 1e12)
|
|
10
|
+
return `$${(usd / 1e12).toFixed(1)}T`;
|
|
11
|
+
if (usd >= 1e9)
|
|
12
|
+
return `$${(usd / 1e9).toFixed(1)}B`;
|
|
13
|
+
return `$${Math.round(usd / 1e6)}M`;
|
|
14
|
+
}
|
|
15
|
+
const SPARK_GLYPHS = "▁▂▃▄▅▆▇█";
|
|
16
|
+
/** Unicode sparkline of the last `width` values; flat series stays low. */
|
|
17
|
+
export function sparkline(values, width) {
|
|
18
|
+
const vals = values.filter((v) => Number.isFinite(v)).slice(-width);
|
|
19
|
+
if (vals.length < 2)
|
|
20
|
+
return "";
|
|
21
|
+
const min = Math.min(...vals);
|
|
22
|
+
const max = Math.max(...vals);
|
|
23
|
+
const span = max - min;
|
|
24
|
+
return vals
|
|
25
|
+
.map((v) => {
|
|
26
|
+
const t = span === 0 ? 0 : (v - min) / span;
|
|
27
|
+
return SPARK_GLYPHS[Math.min(7, Math.floor(t * 8))];
|
|
28
|
+
})
|
|
29
|
+
.join("");
|
|
30
|
+
}
|
|
31
|
+
export function movement(delta) {
|
|
32
|
+
if (delta > 0.0005)
|
|
33
|
+
return { text: `▲ ${pct(delta)}`, dir: "up" };
|
|
34
|
+
if (delta < -0.0005)
|
|
35
|
+
return { text: `▼ ${pct(Math.abs(delta))}`, dir: "down" };
|
|
36
|
+
return { text: "─", dir: "flat" };
|
|
37
|
+
}
|
|
38
|
+
export function fundingLabel(band) {
|
|
39
|
+
return band === "not_scored" ? "n/a" : band;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Column widths for a given terminal width. The name column absorbs all
|
|
43
|
+
* slack between a floor (narrow terminals truncate names) and a ceiling
|
|
44
|
+
* (ultra-wide terminals shouldn't produce a mile of whitespace).
|
|
45
|
+
*/
|
|
46
|
+
export function computeCols(termWidth) {
|
|
47
|
+
const fixed = { type: 6, grade: 6, score: 6, pd: 8, move: 10 };
|
|
48
|
+
const overhead = 2 /* pointer */ +
|
|
49
|
+
2 /* outer padding */ +
|
|
50
|
+
11; /* funding col, unpadded but reserve room for "not_scored" */
|
|
51
|
+
const used = fixed.type + fixed.grade + fixed.score + fixed.pd + fixed.move + overhead;
|
|
52
|
+
const name = Math.max(18, Math.min(40, termWidth - used));
|
|
53
|
+
return { name, ...fixed };
|
|
54
|
+
}
|
|
55
|
+
/** Truncate to width (with ellipsis) then pad — cells never overflow. */
|
|
56
|
+
export function cell(text, width) {
|
|
57
|
+
if (text.length > width - 1) {
|
|
58
|
+
return `${text.slice(0, Math.max(0, width - 2))}… `.padEnd(width);
|
|
59
|
+
}
|
|
60
|
+
return text.padEnd(width);
|
|
61
|
+
}
|
|
62
|
+
export const SORT_MODES = ["risk", "movement", "score", "name"];
|
|
63
|
+
export function sortRows(rows, mode) {
|
|
64
|
+
const sorted = [...rows];
|
|
65
|
+
switch (mode) {
|
|
66
|
+
case "risk":
|
|
67
|
+
sorted.sort((a, b) => b.hazard.pd_12m - a.hazard.pd_12m);
|
|
68
|
+
break;
|
|
69
|
+
case "movement":
|
|
70
|
+
sorted.sort((a, b) => b.movement.delta_pd_12m - a.movement.delta_pd_12m);
|
|
71
|
+
break;
|
|
72
|
+
case "score":
|
|
73
|
+
sorted.sort((a, b) => a.score - b.score);
|
|
74
|
+
break;
|
|
75
|
+
case "name":
|
|
76
|
+
sorted.sort((a, b) => a.name.localeCompare(b.name));
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
return sorted;
|
|
80
|
+
}
|
|
81
|
+
export function filterRows(rows, query) {
|
|
82
|
+
const q = query.trim().toLowerCase();
|
|
83
|
+
if (!q)
|
|
84
|
+
return rows;
|
|
85
|
+
return rows.filter((r) => r.name.toLowerCase().includes(q) ||
|
|
86
|
+
r.slug.includes(q) ||
|
|
87
|
+
r.inst_type.toLowerCase().includes(q));
|
|
88
|
+
}
|
|
89
|
+
export const US_SORT_MODES = [
|
|
90
|
+
"risk",
|
|
91
|
+
"noncurrent",
|
|
92
|
+
"uninsured",
|
|
93
|
+
"assets",
|
|
94
|
+
"name",
|
|
95
|
+
];
|
|
96
|
+
export function sortUSRows(rows, mode) {
|
|
97
|
+
const sorted = [...rows];
|
|
98
|
+
const num = (x) => x ?? -Infinity;
|
|
99
|
+
switch (mode) {
|
|
100
|
+
case "risk":
|
|
101
|
+
sorted.sort((a, b) => b.undertow_score_v02 - a.undertow_score_v02);
|
|
102
|
+
break;
|
|
103
|
+
case "noncurrent":
|
|
104
|
+
sorted.sort((a, b) => num(b.noncurrent_ratio) - num(a.noncurrent_ratio));
|
|
105
|
+
break;
|
|
106
|
+
case "uninsured":
|
|
107
|
+
sorted.sort((a, b) => num(b.uninsured_ratio) - num(a.uninsured_ratio));
|
|
108
|
+
break;
|
|
109
|
+
case "assets":
|
|
110
|
+
sorted.sort((a, b) => b.assets_usd_k - a.assets_usd_k);
|
|
111
|
+
break;
|
|
112
|
+
case "name":
|
|
113
|
+
sorted.sort((a, b) => a.bank.localeCompare(b.bank));
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
return sorted;
|
|
117
|
+
}
|
|
118
|
+
export function filterUSRows(rows, query) {
|
|
119
|
+
const q = query.trim().toLowerCase();
|
|
120
|
+
if (!q)
|
|
121
|
+
return rows;
|
|
122
|
+
return rows.filter((r) => r.bank.toLowerCase().includes(q) ||
|
|
123
|
+
r.state.toLowerCase().includes(q) ||
|
|
124
|
+
String(r.cert) === q);
|
|
125
|
+
}
|
|
126
|
+
export function computeUSCols(termWidth) {
|
|
127
|
+
const fixed = { state: 15, assets: 8, score: 7, noncurr: 9, uninsured: 10, ndfi: 6 };
|
|
128
|
+
const overhead = 2 /* pointer */ + 2; /* outer padding */
|
|
129
|
+
const used = fixed.state +
|
|
130
|
+
fixed.assets +
|
|
131
|
+
fixed.score +
|
|
132
|
+
fixed.noncurr +
|
|
133
|
+
fixed.uninsured +
|
|
134
|
+
fixed.ndfi +
|
|
135
|
+
overhead;
|
|
136
|
+
const bank = Math.max(16, Math.min(36, termWidth - used));
|
|
137
|
+
return { bank, ...fixed };
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Visible slice of the table for a viewport of `visible` rows, keeping the
|
|
141
|
+
* cursor in view. Returns the slice bounds and how many rows are hidden
|
|
142
|
+
* above/below.
|
|
143
|
+
*/
|
|
144
|
+
export function viewport(total, visible, cursor) {
|
|
145
|
+
if (total <= visible || visible <= 0) {
|
|
146
|
+
return { start: 0, end: total, above: 0, below: 0 };
|
|
147
|
+
}
|
|
148
|
+
let start = cursor - Math.floor(visible / 2);
|
|
149
|
+
start = Math.max(0, Math.min(start, total - visible));
|
|
150
|
+
const end = start + visible;
|
|
151
|
+
return { start, end, above: start, below: total - end };
|
|
152
|
+
}
|
package/dist/plain.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { cell, computeCols, computeUSCols, fmtAssets, fundingLabel, movement, pct, pct1, rawPct, sortRows, sortUSRows, } from "./format.js";
|
|
2
|
+
import { riskBand, usRiskBandByRank } from "./riskBands.js";
|
|
3
|
+
function staleLine(stale) {
|
|
4
|
+
return stale
|
|
5
|
+
? [`WARNING: live API unreachable — cached data from ${stale.description}`]
|
|
6
|
+
: [];
|
|
7
|
+
}
|
|
8
|
+
/** Worst risk band on the board — drives --fail-on exit codes. */
|
|
9
|
+
export function worstBand(snap) {
|
|
10
|
+
if (snap.region === "us") {
|
|
11
|
+
// US board is a relative leaderboard; callers must not use it for
|
|
12
|
+
// absolute alerting (enforced at arg-parse time).
|
|
13
|
+
return snap.board.board.length > 0 ? "red" : "green";
|
|
14
|
+
}
|
|
15
|
+
let worst = "green";
|
|
16
|
+
for (const row of snap.board.rows) {
|
|
17
|
+
const b = riskBand(row);
|
|
18
|
+
if (b === "red")
|
|
19
|
+
return "red";
|
|
20
|
+
if (b === "amber")
|
|
21
|
+
worst = "amber";
|
|
22
|
+
}
|
|
23
|
+
return worst;
|
|
24
|
+
}
|
|
25
|
+
/** ANSI-free table for pipes, scripts, CI logs, and `--plain`. */
|
|
26
|
+
export function renderPlain(snap, width = 100) {
|
|
27
|
+
if (snap.region === "us")
|
|
28
|
+
return renderPlainUS(snap, width);
|
|
29
|
+
const cols = computeCols(width);
|
|
30
|
+
const lines = [];
|
|
31
|
+
lines.push(`LIQUILENS Failure Radar · INDIA · board as of ${snap.board.as_of}`);
|
|
32
|
+
if (snap.regime) {
|
|
33
|
+
lines.push(`market regime ${snap.regime.regime} (log-SR ${snap.regime.log_sr_now.toFixed(2)}, ` +
|
|
34
|
+
`last change ${snap.regime.trading_days_since_last_change}d ago) · ${snap.regime.as_of}`);
|
|
35
|
+
}
|
|
36
|
+
lines.push(...staleLine(snap.stale));
|
|
37
|
+
lines.push("");
|
|
38
|
+
lines.push(" " +
|
|
39
|
+
cell("INSTITUTION", cols.name) +
|
|
40
|
+
cell("TYPE", cols.type) +
|
|
41
|
+
cell("GRADE", cols.grade) +
|
|
42
|
+
cell("SCORE", cols.score) +
|
|
43
|
+
cell("PD 12M", cols.pd) +
|
|
44
|
+
cell("Δ PD", cols.move) +
|
|
45
|
+
"FUNDING BAND");
|
|
46
|
+
for (const row of sortRows(snap.board.rows, "risk")) {
|
|
47
|
+
const band = riskBand(row);
|
|
48
|
+
lines.push(" " +
|
|
49
|
+
cell(row.name, cols.name) +
|
|
50
|
+
cell(row.inst_type, cols.type) +
|
|
51
|
+
cell(row.grade, cols.grade) +
|
|
52
|
+
cell(String(row.score), cols.score) +
|
|
53
|
+
cell(pct(row.hazard.pd_12m), cols.pd) +
|
|
54
|
+
cell(movement(row.movement.delta_pd_12m).text, cols.move) +
|
|
55
|
+
cell(fundingLabel(row.funding.band), 9) +
|
|
56
|
+
band.toUpperCase());
|
|
57
|
+
}
|
|
58
|
+
lines.push("");
|
|
59
|
+
lines.push(`${snap.board.rows.length} institutions · liquilens.in`);
|
|
60
|
+
return lines.join("\n");
|
|
61
|
+
}
|
|
62
|
+
function renderPlainUS(snap, width) {
|
|
63
|
+
const cols = computeUSCols(width);
|
|
64
|
+
const { board } = snap;
|
|
65
|
+
const lines = [];
|
|
66
|
+
lines.push(`LIQUILENS Failure Radar · US · quarter as of ${board.as_of} · ` +
|
|
67
|
+
`top ${board.board.length} of ${board.universe.banks_scored} banks scored`);
|
|
68
|
+
lines.push(`source: ${board.provenance.source} · ${board.provenance.engine}`);
|
|
69
|
+
lines.push(...staleLine(snap.stale));
|
|
70
|
+
lines.push("");
|
|
71
|
+
lines.push(" " +
|
|
72
|
+
cell("BANK", cols.bank) +
|
|
73
|
+
cell("STATE", cols.state) +
|
|
74
|
+
cell("ASSETS", cols.assets) +
|
|
75
|
+
cell("SCORE", cols.score) +
|
|
76
|
+
cell("NONCURR", cols.noncurr) +
|
|
77
|
+
cell("UNINSURED", cols.uninsured) +
|
|
78
|
+
"NDFI/T1");
|
|
79
|
+
const rows = sortUSRows(board.board, "risk");
|
|
80
|
+
rows.forEach((r, i) => {
|
|
81
|
+
lines.push(" " +
|
|
82
|
+
cell(r.bank, cols.bank) +
|
|
83
|
+
cell(r.state, cols.state) +
|
|
84
|
+
cell(fmtAssets(r.assets_usd_k), cols.assets) +
|
|
85
|
+
cell(r.undertow_score_v02.toFixed(3), cols.score) +
|
|
86
|
+
cell(rawPct(r.noncurrent_ratio), cols.noncurr) +
|
|
87
|
+
cell(pct1(r.uninsured_ratio), cols.uninsured) +
|
|
88
|
+
cell(pct1(r.ndfi_to_tier1), 8) +
|
|
89
|
+
usRiskBandByRank(i).toUpperCase());
|
|
90
|
+
});
|
|
91
|
+
lines.push("");
|
|
92
|
+
lines.push("score = within-quarter percentile rank (relative leaderboard, not a PD) · liquilens.in");
|
|
93
|
+
return lines.join("\n");
|
|
94
|
+
}
|
|
95
|
+
/** Machine-readable dump for `--json`. */
|
|
96
|
+
export function renderJson(snap) {
|
|
97
|
+
if (snap.region === "us") {
|
|
98
|
+
const rows = sortUSRows(snap.board.board, "risk");
|
|
99
|
+
return JSON.stringify({
|
|
100
|
+
region: "us",
|
|
101
|
+
as_of: snap.board.as_of,
|
|
102
|
+
stale: snap.stale ? { cached_at: snap.stale.savedAt } : null,
|
|
103
|
+
universe: snap.board.universe,
|
|
104
|
+
provenance: snap.board.provenance,
|
|
105
|
+
rows: rows.map((r, i) => ({ ...r, risk_band: usRiskBandByRank(i) })),
|
|
106
|
+
}, null, 2);
|
|
107
|
+
}
|
|
108
|
+
return JSON.stringify({
|
|
109
|
+
region: "in",
|
|
110
|
+
as_of: snap.board.as_of,
|
|
111
|
+
stale: snap.stale ? { cached_at: snap.stale.savedAt } : null,
|
|
112
|
+
market_regime: snap.regime,
|
|
113
|
+
rows: sortRows(snap.board.rows, "risk").map((r) => ({
|
|
114
|
+
...r,
|
|
115
|
+
risk_band: riskBand(r),
|
|
116
|
+
})),
|
|
117
|
+
}, null, 2);
|
|
118
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps a board row to the colour band used for the whole row in the terminal.
|
|
3
|
+
*
|
|
4
|
+
* This is a product/domain judgment, not a rendering detail: it decides what a
|
|
5
|
+
* reader's eye is pulled to first. Inputs available on `row`:
|
|
6
|
+
* - hazard.pd_12m 12-month failure probability (0..1)
|
|
7
|
+
* - grade / hazard.grade letter grades
|
|
8
|
+
* - funding.band "stable" | "watch" | "strain"
|
|
9
|
+
* - pca.risk_level 0..3, breaches list
|
|
10
|
+
* - forensics.fired forensic indicators tripped
|
|
11
|
+
*/
|
|
12
|
+
export function riskBand(row) {
|
|
13
|
+
if (row.forensics.fired || row.pca.breaches.length > 0)
|
|
14
|
+
return "red";
|
|
15
|
+
if (row.hazard.pd_12m >= 0.05)
|
|
16
|
+
return "red";
|
|
17
|
+
const fundingStressed = !["stable", "not_scored"].includes(row.funding.band);
|
|
18
|
+
if (row.hazard.pd_12m >= 0.015 || fundingStressed || row.pca.risk_level > 0)
|
|
19
|
+
return "amber";
|
|
20
|
+
return "green";
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* US board banding is RELATIVE, not absolute: undertow scores are
|
|
24
|
+
* within-quarter percentile ranks and the API already returns only the
|
|
25
|
+
* riskiest tail (top 50 of ~1,000+), so fixed thresholds would drift across
|
|
26
|
+
* quarters. Band by rank within the returned board instead: the reader's
|
|
27
|
+
* question is "what's at the very top of the risky tail right now".
|
|
28
|
+
*/
|
|
29
|
+
export function usRiskBandByRank(rankInBoard) {
|
|
30
|
+
if (rankInBoard < 10)
|
|
31
|
+
return "red";
|
|
32
|
+
if (rankInBoard < 30)
|
|
33
|
+
return "amber";
|
|
34
|
+
return "green";
|
|
35
|
+
}
|
|
36
|
+
const BAND_ORDER = { green: 0, amber: 1, red: 2 };
|
|
37
|
+
/** True when `band` is at least as severe as `threshold` (for --fail-on). */
|
|
38
|
+
export function bandAtLeast(band, threshold) {
|
|
39
|
+
return BAND_ORDER[band] >= BAND_ORDER[threshold];
|
|
40
|
+
}
|
|
41
|
+
export const bandColor = {
|
|
42
|
+
red: "#f26d6d",
|
|
43
|
+
amber: "#e8b64f",
|
|
44
|
+
green: "#66c28f",
|
|
45
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "liquilens",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "LiquiLens Failure Radar in your terminal — live early-warning board for Indian institutions and FDIC-scored US banks, from public data",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
|
+
"homepage": "https://liquilens.in/developers/",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/beepboop2025/liquilens-cli.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/beepboop2025/liquilens-cli/issues"
|
|
13
|
+
},
|
|
14
|
+
"author": "beepboop2025",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"cli",
|
|
17
|
+
"tui",
|
|
18
|
+
"finance",
|
|
19
|
+
"risk",
|
|
20
|
+
"early-warning",
|
|
21
|
+
"bank-failure",
|
|
22
|
+
"fdic",
|
|
23
|
+
"rbi",
|
|
24
|
+
"liquidity",
|
|
25
|
+
"terminal-dashboard"
|
|
26
|
+
],
|
|
27
|
+
"type": "module",
|
|
28
|
+
"bin": {
|
|
29
|
+
"liquilens": "dist/cli.js"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"!dist/*.test.js",
|
|
34
|
+
"LICENSE.md"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc",
|
|
38
|
+
"dev": "tsc && node dist/cli.js",
|
|
39
|
+
"test": "tsc && node --test dist/cache.test.js dist/format.test.js dist/riskBands.test.js dist/us.test.js",
|
|
40
|
+
"prepare": "tsc"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public",
|
|
44
|
+
"provenance": true
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=18.17"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"ink": "^5.2.0",
|
|
51
|
+
"react": "^18.3.1",
|
|
52
|
+
"undici": "^6.28.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/node": "^22.10.0",
|
|
56
|
+
"@types/react": "^18.3.0",
|
|
57
|
+
"typescript": "^5.6.0"
|
|
58
|
+
}
|
|
59
|
+
}
|