@mnmal-ai/substrate-tui 1.0.0-beta.7 → 1.0.0-beta.9
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 +1 -1
- package/dist/{app-DmFXZmFW.js → app-Cj1astMb.js} +348 -72
- package/dist/bin/substrate-tui.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Without an admin identity it is read-only.
|
|
|
9
9
|
- Free text is a natural-language question, answered by `substrate-nl` (streamed). Tab completes types, fields and values.
|
|
10
10
|
- `/ns <namespace>` switches the namespace that questions, completion and the status row use. The schema browser always lists every namespace.
|
|
11
11
|
- `/frame` shows the Substrate frame behind the last answer.
|
|
12
|
-
- `/asof <date-time>` reads relative phrases ("yesterday", "past 2 days") as of that moment, for the questions that follow. It must be ISO-8601 with an offset, e.g. `2026-10-24T23:59:59-05:00`. `/asof off` returns to the server clock, and `/asof` alone shows which is in use. `/frame` shows the clock the server read the last question against.
|
|
12
|
+
- `/asof <date-time>` reads relative phrases ("yesterday", "past 2 days") as of that moment, for the questions that follow. It must be ISO-8601 with an offset, in years 1000 to 9998, e.g. `2026-10-24T23:59:59-05:00`. `/asof off` returns to the server clock, and `/asof` alone shows which is in use. `/frame` shows the clock the server read the last question against.
|
|
13
13
|
- `/schema [namespace] [type]` opens the schema browser: namespaces, then types, then fields.
|
|
14
14
|
- `/dash` shows service, traffic and engine metrics, live while open.
|
|
15
15
|
- `/doctor` runs live checks against this deployment.
|
|
@@ -6,7 +6,7 @@ import { createApp, defineModule, listPager, sanitise } from "@mnmal-ai/surface-
|
|
|
6
6
|
import { marathon } from "@mnmal-ai/surface-theme";
|
|
7
7
|
import { Box, Text } from "ink";
|
|
8
8
|
import { createElement } from "react";
|
|
9
|
-
import { Panel, cellWidth, padCells, sparkline, truncateCells } from "@mnmal-ai/surface-kit";
|
|
9
|
+
import { Panel, cellWidth, cutToWidth, padCells, sparkline, truncateCells } from "@mnmal-ai/surface-kit";
|
|
10
10
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
import { complete } from "@mnmal-ai/substrate-nl/complete";
|
|
12
12
|
import { readFile } from "node:fs/promises";
|
|
@@ -14,14 +14,63 @@ import { createHash, createPublicKey } from "node:crypto";
|
|
|
14
14
|
import { homedir } from "node:os";
|
|
15
15
|
import { readFileSync } from "node:fs";
|
|
16
16
|
|
|
17
|
+
//#region src/text.ts
|
|
18
|
+
/** Server text on one line: no escape or control bytes, and each run of line breaks one space. */
|
|
19
|
+
const clean = (s) => sanitise(s.replace(/[\n\v\f\r\u0085\u2028\u2029]+/g, " "));
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
17
22
|
//#region src/lines.tsx
|
|
18
|
-
/**
|
|
23
|
+
/** A column of toned or styled text lines, shared by the panels that render one (surgery, `/keys`). */
|
|
24
|
+
/** A line of styled parts, each sanitised onto one line (idempotent), whoever built it. */
|
|
25
|
+
function partsLine(parts) {
|
|
26
|
+
const safe = parts.map((p) => ({
|
|
27
|
+
...p,
|
|
28
|
+
text: clean(p.text)
|
|
29
|
+
}));
|
|
30
|
+
return {
|
|
31
|
+
text: safe.map((p) => p.text).join(""),
|
|
32
|
+
parts: safe
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** Cut parts to `max` cells with a trailing `…`, keeping each kept part's styling. */
|
|
36
|
+
function truncateParts(parts, max) {
|
|
37
|
+
const joined = parts.map((p) => p.text).join("");
|
|
38
|
+
const cut = truncateCells(joined, max);
|
|
39
|
+
if (cut === joined) return [...parts];
|
|
40
|
+
let left = cut.length - 1;
|
|
41
|
+
const out = [];
|
|
42
|
+
for (const p of parts) {
|
|
43
|
+
if (left <= 0) break;
|
|
44
|
+
if (p.text.length > left) {
|
|
45
|
+
out.push({
|
|
46
|
+
...p,
|
|
47
|
+
text: `${p.text.slice(0, left)}…`
|
|
48
|
+
});
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
out.push(p);
|
|
52
|
+
left -= p.text.length;
|
|
53
|
+
}
|
|
54
|
+
const last = out[out.length - 1];
|
|
55
|
+
out.push(last !== void 0 ? {
|
|
56
|
+
...last,
|
|
57
|
+
text: "…"
|
|
58
|
+
} : { text: "…" });
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
/** Lines as a column of `Text`, each in its tone or parts: a joined string view has none to give. */
|
|
19
62
|
function linesView(lines, theme) {
|
|
20
63
|
return /* @__PURE__ */ jsx(Box, {
|
|
21
64
|
flexDirection: "column",
|
|
22
65
|
children: lines.map((l, i) => /* @__PURE__ */ jsx(Text, {
|
|
23
|
-
...l.tone !== void 0 ? { color: theme.color[l.tone] } : {},
|
|
24
|
-
children: l.
|
|
66
|
+
...l.tone !== void 0 && l.parts === void 0 ? { color: theme.color[l.tone] } : {},
|
|
67
|
+
children: l.parts !== void 0 ? l.parts.map((p, j) => /* @__PURE__ */ jsx(Text, {
|
|
68
|
+
...p.tone !== void 0 ? { color: theme.color[p.tone] } : {},
|
|
69
|
+
...p.bg !== void 0 ? { backgroundColor: theme.color[p.bg] } : {},
|
|
70
|
+
...p.bold ? { bold: true } : {},
|
|
71
|
+
...p.strike ? { strikethrough: true } : {},
|
|
72
|
+
children: p.text
|
|
73
|
+
}, j)) : l.text
|
|
25
74
|
}, i))
|
|
26
75
|
});
|
|
27
76
|
}
|
|
@@ -729,6 +778,7 @@ const COLS = {
|
|
|
729
778
|
};
|
|
730
779
|
const titleWidth = (columns) => Math.max(COLS.minTitle, columns - (COLS.id + COLS.status + COLS.project + COLS.gaps));
|
|
731
780
|
const FN_LABEL = {
|
|
781
|
+
count: "count",
|
|
732
782
|
avg: "average",
|
|
733
783
|
sum: "total",
|
|
734
784
|
min: "min",
|
|
@@ -832,7 +882,8 @@ const rows = ({ data, theme, size }) => {
|
|
|
832
882
|
}, `d${i}`));
|
|
833
883
|
const agg = o.aggregate;
|
|
834
884
|
if (agg !== void 0) {
|
|
835
|
-
const
|
|
885
|
+
const fnLabel = Object.hasOwn(FN_LABEL, agg.fn) ? FN_LABEL[agg.fn] : str(agg.fn);
|
|
886
|
+
const head = agg.fn === "count" ? fnLabel : `${fnLabel} ${str(agg.field)}`;
|
|
836
887
|
const errs = errorLines(o.errors).map((l, i) => /* @__PURE__ */ jsx(Text, {
|
|
837
888
|
color: theme.color.error,
|
|
838
889
|
children: ` ${l}`
|
|
@@ -1245,8 +1296,8 @@ function explain(err, endpoint) {
|
|
|
1245
1296
|
if (e.status === 401 || e.status === 403) return `not authorised (${e.status}) — check SUBSTRATE_AGENT_KEY_ID / SUBSTRATE_AGENT_KEY_PATH`;
|
|
1246
1297
|
return e.message ?? String(err);
|
|
1247
1298
|
}
|
|
1248
|
-
/** What the server accepts for `asOf`: a date-time with an explicit offset. */
|
|
1249
|
-
const ISO_WITH_OFFSET =
|
|
1299
|
+
/** What the server accepts for `asOf`: a date-time with an explicit offset, in years 1000 to 9998. */
|
|
1300
|
+
const ISO_WITH_OFFSET = /^(?!9999)[1-9]\d{3}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/;
|
|
1250
1301
|
/**
|
|
1251
1302
|
* The ask module. A plain list of rows goes to `pager`, whose module the app must also register;
|
|
1252
1303
|
* the default is for an app that registers it from here, as the tests do.
|
|
@@ -1350,7 +1401,7 @@ function askModule(deps, pager = listPager()) {
|
|
|
1350
1401
|
asOf = void 0;
|
|
1351
1402
|
return ctx.print("asOf → server clock");
|
|
1352
1403
|
}
|
|
1353
|
-
if (!ISO_WITH_OFFSET.test(v) || Number.isNaN(Date.parse(v))) return ctx.print("asOf needs an ISO-8601 date-time with an offset, e.g. 2026-10-24T23:59:59-05:00");
|
|
1404
|
+
if (!ISO_WITH_OFFSET.test(v) || Number.isNaN(Date.parse(v))) return ctx.print("asOf needs an ISO-8601 date-time with an offset, in years 1000 to 9998, e.g. 2026-10-24T23:59:59-05:00");
|
|
1354
1405
|
asOf = v;
|
|
1355
1406
|
ctx.print(`asOf → ${asOf}`);
|
|
1356
1407
|
}
|
|
@@ -1472,11 +1523,6 @@ function askModule(deps, pager = listPager()) {
|
|
|
1472
1523
|
});
|
|
1473
1524
|
}
|
|
1474
1525
|
|
|
1475
|
-
//#endregion
|
|
1476
|
-
//#region src/text.ts
|
|
1477
|
-
/** Server text on one line: no escape or control bytes, and line breaks collapsed to a space. */
|
|
1478
|
-
const clean = (s) => sanitise(s.replace(/[\r\n]+/g, " "));
|
|
1479
|
-
|
|
1480
1526
|
//#endregion
|
|
1481
1527
|
//#region src/dash/derive.ts
|
|
1482
1528
|
/** Polls kept per sparkline. */
|
|
@@ -2420,9 +2466,12 @@ function compactGrant(namespaces, capabilities) {
|
|
|
2420
2466
|
if (grant.size === 0) return "(none)";
|
|
2421
2467
|
return [...grant].map(([ns, caps]) => `${ns}:${canonicalCaps(caps).map((c) => SHORT[c] ?? c).join("+")}`).join(",");
|
|
2422
2468
|
}
|
|
2423
|
-
/**
|
|
2469
|
+
/**
|
|
2470
|
+
* A namespace's capabilities as tokens in canonical order: read, mutate, admin → `r`, `m`, `a`, and
|
|
2471
|
+
* one with no short form spelled out as `(name)`.
|
|
2472
|
+
*/
|
|
2424
2473
|
function shortCaps(caps) {
|
|
2425
|
-
return canonicalCaps(caps).map((c) => SHORT[c] ?? `(${c})`)
|
|
2474
|
+
return canonicalCaps(caps).map((c) => SHORT[c] ?? `(${c})`);
|
|
2426
2475
|
}
|
|
2427
2476
|
/** A stored row's grant, or null when it does not parse (the table still renders it). */
|
|
2428
2477
|
function rowGrant(row) {
|
|
@@ -3391,7 +3440,7 @@ function orderForView(rows) {
|
|
|
3391
3440
|
active.sort((a, b) => {
|
|
3392
3441
|
const [aa, ah] = splitKid(a.kid);
|
|
3393
3442
|
const [ba, bh] = splitKid(b.kid);
|
|
3394
|
-
return byText(ah, bh) || byText(aa, ba);
|
|
3443
|
+
return (bh === NO_HOST ? 1 : 0) - (ah === NO_HOST ? 1 : 0) || byText(ah.toLowerCase(), bh.toLowerCase()) || byText(aa.toLowerCase(), ba.toLowerCase());
|
|
3395
3444
|
});
|
|
3396
3445
|
revoked.sort((a, b) => String(b.revokedAt).localeCompare(String(a.revokedAt)) || byText(a.kid, b.kid));
|
|
3397
3446
|
return [...active, ...revoked];
|
|
@@ -3402,62 +3451,223 @@ function namespaceColumns(grants) {
|
|
|
3402
3451
|
for (const g of grants) for (const ns of g?.keys() ?? []) count.set(ns, (count.get(ns) ?? 0) + 1);
|
|
3403
3452
|
return [...count.keys()].sort((a, b) => (b === "*" ? 1 : 0) - (a === "*" ? 1 : 0) || (count.get(b) ?? 0) - (count.get(a) ?? 0) || byText(a, b));
|
|
3404
3453
|
}
|
|
3405
|
-
/** The
|
|
3406
|
-
|
|
3454
|
+
/** The widest a name may be before it truncates with `…`. */
|
|
3455
|
+
const NAME_CAP = 22;
|
|
3456
|
+
const BAND_END = 50;
|
|
3457
|
+
const GUTTER = " ";
|
|
3458
|
+
/** Terminal cells the parts take. */
|
|
3459
|
+
const len = (parts) => parts.reduce((n, p) => n + cellWidth(p.text), 0);
|
|
3460
|
+
/** A gap is one space: an empty Ink `Text` renders no row at all. */
|
|
3461
|
+
const pad = (n) => n > 0 ? [{ text: " ".repeat(n) }] : [];
|
|
3462
|
+
/** `── label ──── count`, the count ending at one shared column. */
|
|
3463
|
+
function band(label, count, width, kind) {
|
|
3464
|
+
const l = clean(label);
|
|
3465
|
+
const n = String(count);
|
|
3466
|
+
const rule = Math.max(2, Math.min(width, BAND_END) - (4 + cellWidth(l) + 2 + cellWidth(n)));
|
|
3467
|
+
return {
|
|
3468
|
+
parts: truncateParts([
|
|
3469
|
+
{
|
|
3470
|
+
text: " ── ",
|
|
3471
|
+
tone: "dim"
|
|
3472
|
+
},
|
|
3473
|
+
kind === "band" ? {
|
|
3474
|
+
text: l,
|
|
3475
|
+
tone: "text",
|
|
3476
|
+
bold: true
|
|
3477
|
+
} : {
|
|
3478
|
+
text: l,
|
|
3479
|
+
tone: "dimMid",
|
|
3480
|
+
bold: true
|
|
3481
|
+
},
|
|
3482
|
+
{ text: " " },
|
|
3483
|
+
{
|
|
3484
|
+
text: "─".repeat(rule),
|
|
3485
|
+
tone: "dim"
|
|
3486
|
+
},
|
|
3487
|
+
{ text: " " },
|
|
3488
|
+
{
|
|
3489
|
+
text: n,
|
|
3490
|
+
tone: "dimMid"
|
|
3491
|
+
}
|
|
3492
|
+
], width),
|
|
3493
|
+
kind
|
|
3494
|
+
};
|
|
3495
|
+
}
|
|
3496
|
+
/** The majority spelling of each host (lowercased), a tie going to the spelling that sorts first. */
|
|
3497
|
+
function hostLabels(rows) {
|
|
3498
|
+
const spellings = /* @__PURE__ */ new Map();
|
|
3499
|
+
for (const r of rows) {
|
|
3500
|
+
if (isRevoked(r)) continue;
|
|
3501
|
+
const h = splitKid(r.kid)[1];
|
|
3502
|
+
const m = spellings.get(h.toLowerCase()) ?? /* @__PURE__ */ new Map();
|
|
3503
|
+
m.set(h, (m.get(h) ?? 0) + 1);
|
|
3504
|
+
spellings.set(h.toLowerCase(), m);
|
|
3505
|
+
}
|
|
3506
|
+
return new Map([...spellings].map(([k, m]) => [k, [...m].sort((a, b) => b[1] - a[1] || byText(a[0], b[0]))[0]?.[0] ?? k]));
|
|
3507
|
+
}
|
|
3508
|
+
/** A hostless key's name and a dimMid short id sized to the cap; its kid when it has no name. */
|
|
3509
|
+
function hostlessName(name, kid) {
|
|
3510
|
+
if (name === "") return [{
|
|
3511
|
+
text: kid,
|
|
3512
|
+
tone: "text"
|
|
3513
|
+
}];
|
|
3514
|
+
const n = Math.min(8, 22 - cellWidth(name) - 2);
|
|
3515
|
+
return n < 4 ? [{
|
|
3516
|
+
text: name,
|
|
3517
|
+
tone: "text"
|
|
3518
|
+
}] : [
|
|
3519
|
+
{
|
|
3520
|
+
text: name,
|
|
3521
|
+
tone: "text"
|
|
3522
|
+
},
|
|
3523
|
+
{ text: " " },
|
|
3524
|
+
{
|
|
3525
|
+
text: `${cutToWidth(kid, n)}…`,
|
|
3526
|
+
tone: "dimMid"
|
|
3527
|
+
}
|
|
3528
|
+
];
|
|
3529
|
+
}
|
|
3530
|
+
const capPart = (c) => c === "a" ? {
|
|
3531
|
+
text: c,
|
|
3532
|
+
tone: "warn",
|
|
3533
|
+
bold: true
|
|
3534
|
+
} : {
|
|
3535
|
+
text: c,
|
|
3536
|
+
tone: "text"
|
|
3537
|
+
};
|
|
3538
|
+
/** The ordered rows as display lines, each truncated to `width` (the view adds the cursor). */
|
|
3539
|
+
function listLines(rows, width) {
|
|
3407
3540
|
const grants = rows.map((r) => {
|
|
3408
3541
|
const g = rowGrant(r);
|
|
3409
|
-
return g === null ? null : new Map([...g].map(([ns, caps]) => [ns, shortCaps(caps)]));
|
|
3542
|
+
return g === null ? null : new Map([...g].map(([ns, caps]) => [clean(ns), shortCaps(caps).map(clean)]));
|
|
3410
3543
|
});
|
|
3411
3544
|
const active = rows.flatMap((r, i) => isRevoked(r) ? [] : [i]);
|
|
3412
3545
|
const cols = namespaceColumns(active.map((i) => grants[i] ?? null));
|
|
3413
|
-
const colW = cols.map((ns) => ns
|
|
3414
|
-
const
|
|
3546
|
+
const colW = cols.map((ns) => cellWidth(ns) + 1 + Math.max(1, ...active.map((i) => cellWidth(grants[i]?.get(ns)?.join("") ?? ""))));
|
|
3547
|
+
const labels = hostLabels(rows);
|
|
3548
|
+
const names = /* @__PURE__ */ new Map();
|
|
3549
|
+
for (const i of active) {
|
|
3550
|
+
const r = rows[i];
|
|
3551
|
+
const [agent, host] = splitKid(r.kid);
|
|
3552
|
+
const parts = host === NO_HOST ? hostlessName(clean(r.name), clean(r.kid)) : [{
|
|
3553
|
+
text: clean(agent),
|
|
3554
|
+
tone: "text"
|
|
3555
|
+
}, ...host === labels.get(host.toLowerCase()) ? [] : [{
|
|
3556
|
+
text: `@${clean(host)}`,
|
|
3557
|
+
tone: "dimMid"
|
|
3558
|
+
}]];
|
|
3559
|
+
names.set(i, truncateParts(parts, 22));
|
|
3560
|
+
}
|
|
3561
|
+
const nameW = Math.max(4, ...[...names.values()].map(len));
|
|
3562
|
+
const grantParts = (i) => {
|
|
3563
|
+
const r = rows[i];
|
|
3564
|
+
const g = grants[i];
|
|
3565
|
+
if (g === null || g === void 0) return [{
|
|
3566
|
+
text: clean(compactGrant(r.namespaces, r.capabilities)),
|
|
3567
|
+
tone: "text"
|
|
3568
|
+
}];
|
|
3569
|
+
if (g.size === 0) return [{
|
|
3570
|
+
text: "(none)",
|
|
3571
|
+
tone: "dim"
|
|
3572
|
+
}];
|
|
3573
|
+
const last = cols.findLastIndex((ns) => g.has(ns));
|
|
3574
|
+
const out = [];
|
|
3575
|
+
cols.slice(0, last + 1).forEach((ns, k) => {
|
|
3576
|
+
const caps = g.get(ns);
|
|
3577
|
+
if (k > 0) out.push({ text: " " });
|
|
3578
|
+
if (caps === void 0) {
|
|
3579
|
+
out.push(...pad(colW[k]));
|
|
3580
|
+
return;
|
|
3581
|
+
}
|
|
3582
|
+
const star = ns === "*";
|
|
3583
|
+
out.push({
|
|
3584
|
+
text: clean(ns),
|
|
3585
|
+
tone: star ? "warn" : "dimMid",
|
|
3586
|
+
...star ? { bold: true } : {}
|
|
3587
|
+
});
|
|
3588
|
+
out.push({ text: " " }, ...caps.map(capPart));
|
|
3589
|
+
if (k < last) out.push(...pad(colW[k] - cellWidth(ns) - 1 - cellWidth(caps.join(""))));
|
|
3590
|
+
});
|
|
3591
|
+
return out;
|
|
3592
|
+
};
|
|
3415
3593
|
const lines = [];
|
|
3594
|
+
const push = (l) => lines.push({
|
|
3595
|
+
...l,
|
|
3596
|
+
parts: truncateParts(l.parts, width)
|
|
3597
|
+
});
|
|
3598
|
+
const revokedCount = rows.length - active.length;
|
|
3416
3599
|
let host;
|
|
3417
3600
|
rows.forEach((r, i) => {
|
|
3418
3601
|
if (isRevoked(r)) {
|
|
3419
|
-
if (lines.every((l) => l.kind !== "revoked-
|
|
3420
|
-
if (lines.length > 0)
|
|
3421
|
-
text: "",
|
|
3602
|
+
if (lines.every((l) => l.kind !== "revoked-band")) {
|
|
3603
|
+
if (lines.length > 0) push({
|
|
3604
|
+
parts: [{ text: " " }],
|
|
3422
3605
|
kind: "gap"
|
|
3423
3606
|
});
|
|
3424
|
-
lines.push(
|
|
3425
|
-
text: "revoked",
|
|
3426
|
-
kind: "revoked-head"
|
|
3427
|
-
});
|
|
3607
|
+
lines.push(band("revoked", revokedCount, width, "revoked-band"));
|
|
3428
3608
|
}
|
|
3429
|
-
|
|
3430
|
-
|
|
3609
|
+
push({
|
|
3610
|
+
parts: [
|
|
3611
|
+
{ text: GUTTER },
|
|
3612
|
+
{
|
|
3613
|
+
text: clean(r.kid),
|
|
3614
|
+
tone: "dim",
|
|
3615
|
+
strike: true
|
|
3616
|
+
},
|
|
3617
|
+
{
|
|
3618
|
+
text: ` ${clean(String(r.revokedAt).slice(0, 10))}`,
|
|
3619
|
+
tone: "dim"
|
|
3620
|
+
}
|
|
3621
|
+
],
|
|
3431
3622
|
row: i,
|
|
3432
3623
|
kind: "revoked"
|
|
3433
3624
|
});
|
|
3434
3625
|
return;
|
|
3435
3626
|
}
|
|
3436
|
-
const
|
|
3437
|
-
if (
|
|
3438
|
-
if (host !== void 0)
|
|
3439
|
-
text: "",
|
|
3627
|
+
const key = splitKid(r.kid)[1].toLowerCase();
|
|
3628
|
+
if (key !== host) {
|
|
3629
|
+
if (host !== void 0) push({
|
|
3630
|
+
parts: [{ text: " " }],
|
|
3440
3631
|
kind: "gap"
|
|
3441
3632
|
});
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
});
|
|
3446
|
-
host = h;
|
|
3633
|
+
const count = active.filter((j) => splitKid(rows[j].kid)[1].toLowerCase() === key).length;
|
|
3634
|
+
lines.push(band(labels.get(key) ?? key, count, width, "band"));
|
|
3635
|
+
host = key;
|
|
3447
3636
|
}
|
|
3448
|
-
const
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3637
|
+
const name = names.get(i);
|
|
3638
|
+
push({
|
|
3639
|
+
parts: [
|
|
3640
|
+
{ text: GUTTER },
|
|
3641
|
+
...name,
|
|
3642
|
+
...pad(nameW - len(name) + 2),
|
|
3643
|
+
...grantParts(i)
|
|
3644
|
+
],
|
|
3455
3645
|
row: i,
|
|
3456
3646
|
kind: "key"
|
|
3457
3647
|
});
|
|
3458
3648
|
});
|
|
3459
3649
|
return lines;
|
|
3460
3650
|
}
|
|
3651
|
+
/** A line as the cursor row: a `glyph` gutter, then a selection band padded out to `width`. */
|
|
3652
|
+
function selectLine(line, cursorGlyph, width = 0) {
|
|
3653
|
+
const body = line.parts.slice(1).map((p) => ({
|
|
3654
|
+
text: p.text,
|
|
3655
|
+
bg: "selection",
|
|
3656
|
+
tone: "surface",
|
|
3657
|
+
bold: true,
|
|
3658
|
+
...p.strike ? { strike: true } : {}
|
|
3659
|
+
}));
|
|
3660
|
+
const fill = width - cellWidth(`${cursorGlyph} `) - len(body);
|
|
3661
|
+
const last = body[body.length - 1];
|
|
3662
|
+
if (last !== void 0 && fill > 0) body[body.length - 1] = {
|
|
3663
|
+
...last,
|
|
3664
|
+
text: last.text + " ".repeat(fill)
|
|
3665
|
+
};
|
|
3666
|
+
return [{
|
|
3667
|
+
text: `${cursorGlyph} `,
|
|
3668
|
+
tone: "selection"
|
|
3669
|
+
}, ...body];
|
|
3670
|
+
}
|
|
3461
3671
|
|
|
3462
3672
|
//#endregion
|
|
3463
3673
|
//#region src/keys/module.ts
|
|
@@ -3468,6 +3678,65 @@ function listLines(rows) {
|
|
|
3468
3678
|
* through a review. Locked, it reads as the agent, which a 403 turns into "admin required", and
|
|
3469
3679
|
* Enter shows a row's grant read-only. Locking closes the table and every editor panel.
|
|
3470
3680
|
*/
|
|
3681
|
+
const count = (s) => {
|
|
3682
|
+
if (s.rows === null) return "";
|
|
3683
|
+
const gone = s.rows.filter(isRevoked).length;
|
|
3684
|
+
return ` · ${s.rows.length - gone} active${s.revoked ? ` · ${gone} revoked` : ""}`;
|
|
3685
|
+
};
|
|
3686
|
+
/** The head line: accent glyph, bold `keys`, then the counts and source in dimMid. */
|
|
3687
|
+
function headParts(state, titleGlyph) {
|
|
3688
|
+
return [
|
|
3689
|
+
{
|
|
3690
|
+
text: titleGlyph,
|
|
3691
|
+
tone: "accent"
|
|
3692
|
+
},
|
|
3693
|
+
{ text: " " },
|
|
3694
|
+
{
|
|
3695
|
+
text: "keys",
|
|
3696
|
+
tone: "text",
|
|
3697
|
+
bold: true
|
|
3698
|
+
},
|
|
3699
|
+
{
|
|
3700
|
+
text: `${count(state)} · ${state.source}`,
|
|
3701
|
+
tone: "dimMid"
|
|
3702
|
+
}
|
|
3703
|
+
];
|
|
3704
|
+
}
|
|
3705
|
+
/** The grant legend, dim with its `a` in warn bold. */
|
|
3706
|
+
function legendParts() {
|
|
3707
|
+
return [
|
|
3708
|
+
{
|
|
3709
|
+
text: ` ${GRANT_LEGEND.slice(0, GRANT_LEGEND.lastIndexOf("a="))}`,
|
|
3710
|
+
tone: "dim"
|
|
3711
|
+
},
|
|
3712
|
+
{
|
|
3713
|
+
text: "a",
|
|
3714
|
+
tone: "warn",
|
|
3715
|
+
bold: true
|
|
3716
|
+
},
|
|
3717
|
+
{
|
|
3718
|
+
text: GRANT_LEGEND.slice(GRANT_LEGEND.lastIndexOf("a=") + 1),
|
|
3719
|
+
tone: "dim"
|
|
3720
|
+
}
|
|
3721
|
+
];
|
|
3722
|
+
}
|
|
3723
|
+
/** Key hints: key names text, actions dimMid, `·` separators dim. */
|
|
3724
|
+
function hintParts(pairs) {
|
|
3725
|
+
return [{ text: " " }, ...pairs.flatMap(([key, action], i) => [
|
|
3726
|
+
...i > 0 ? [{
|
|
3727
|
+
text: " · ",
|
|
3728
|
+
tone: "dim"
|
|
3729
|
+
}] : [],
|
|
3730
|
+
{
|
|
3731
|
+
text: key,
|
|
3732
|
+
tone: "text"
|
|
3733
|
+
},
|
|
3734
|
+
{
|
|
3735
|
+
text: ` ${action}`,
|
|
3736
|
+
tone: "dimMid"
|
|
3737
|
+
}
|
|
3738
|
+
])];
|
|
3739
|
+
}
|
|
3471
3740
|
/** The rows the editor flows judge against: a revoked key holds no grant. */
|
|
3472
3741
|
const live = (rows) => rows.filter((r) => !isRevoked(r));
|
|
3473
3742
|
/** Opens the table and reads it; `select` is a kid whose row takes the cursor once the read lands. */
|
|
@@ -3520,38 +3789,45 @@ function keysModule(deps) {
|
|
|
3520
3789
|
keys: {
|
|
3521
3790
|
...KEYS_CHROME,
|
|
3522
3791
|
view: ({ state, theme, size }) => {
|
|
3523
|
-
const w =
|
|
3524
|
-
const
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
if (state.note !== null) return [head, ` ${sanitise(state.note)}`].join("\n");
|
|
3528
|
-
if (state.rows === null) return [head, " reading…"].join("\n");
|
|
3792
|
+
const w = size.columns;
|
|
3793
|
+
const headLine = partsLine(truncateParts(headParts(state, theme.glyph.title), w));
|
|
3794
|
+
if (state.note !== null) return linesView([headLine, { text: ` ${sanitise(state.note)}` }], theme);
|
|
3795
|
+
if (state.rows === null) return linesView([headLine, { text: " reading…" }], theme);
|
|
3529
3796
|
const pick = state.rows[state.cursor];
|
|
3530
|
-
if (state.detail && pick !== void 0)
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3797
|
+
if (state.detail && pick !== void 0) {
|
|
3798
|
+
const detail = [
|
|
3799
|
+
truncateCells(clean(` ${pick.kid} ${pick.name} ${pick.algorithm}`), w),
|
|
3800
|
+
...isRevoked(pick) ? [truncateCells(clean(` revoked ${pick.revokedAt}`), w)] : [],
|
|
3801
|
+
...describeGrant(pick.namespaces, pick.capabilities).map((g) => truncateCells(clean(` ${g}`), w)),
|
|
3802
|
+
" backspace back · esc close"
|
|
3803
|
+
];
|
|
3804
|
+
return linesView([headLine, ...detail.map((text) => ({ text }))], theme);
|
|
3805
|
+
}
|
|
3806
|
+
const all = listLines(state.rows, w);
|
|
3538
3807
|
const max = Math.max(1, size.rows - 3);
|
|
3539
3808
|
const at = Math.max(0, all.findIndex((l) => l.row === state.cursor));
|
|
3540
3809
|
const start = Math.max(0, Math.min(at - max + 1, all.length - max));
|
|
3541
|
-
const lines = all.slice(start, start + max).map((l) =>
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3810
|
+
const lines = all.slice(start, start + max).map((l) => partsLine(l.row !== void 0 && l.row === state.cursor ? selectLine(l, theme.glyph.cursor, w) : l.parts));
|
|
3811
|
+
const toggle = state.revoked ? "hide revoked" : "show revoked";
|
|
3812
|
+
const hints = state.source === "admin" && deps.admin.unlocked() ? [
|
|
3813
|
+
["↑↓/jk", "move"],
|
|
3814
|
+
["enter", "edit"],
|
|
3815
|
+
["x", "revoke"],
|
|
3816
|
+
["i", "invite"],
|
|
3817
|
+
["n", "register"],
|
|
3818
|
+
["r", toggle],
|
|
3819
|
+
["esc", "close"]
|
|
3820
|
+
] : [
|
|
3821
|
+
["↑↓/jk", "move"],
|
|
3822
|
+
["enter", "grant"],
|
|
3823
|
+
["r", toggle],
|
|
3824
|
+
["esc", "close"]
|
|
3825
|
+
];
|
|
3550
3826
|
return linesView([
|
|
3551
|
-
|
|
3827
|
+
headLine,
|
|
3552
3828
|
...lines,
|
|
3553
|
-
|
|
3554
|
-
|
|
3829
|
+
partsLine(truncateParts(legendParts(), w)),
|
|
3830
|
+
partsLine(truncateParts(hintParts(hints), w))
|
|
3555
3831
|
], theme);
|
|
3556
3832
|
},
|
|
3557
3833
|
keymap: [
|
|
@@ -51,7 +51,7 @@ async function main() {
|
|
|
51
51
|
}
|
|
52
52
|
Object.assign(process.env, colorDepthEnv(process.env));
|
|
53
53
|
const [{ createTui }, { makeDeps }, { prepareTerminal }, { terminalOptions }] = await Promise.all([
|
|
54
|
-
import("../app-
|
|
54
|
+
import("../app-Cj1astMb.js"),
|
|
55
55
|
import("../deps-CMPHUv70.js"),
|
|
56
56
|
import("@mnmal-ai/surface-core/pure"),
|
|
57
57
|
import("../terminal-BAd8sH3d.js")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mnmal-ai/substrate-tui",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.9",
|
|
4
4
|
"description": "Terminal UI for Substrate: ask in natural language, browse the schema, see the service status.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@mnmal-ai/substrate": "1.0.0-beta.
|
|
24
|
-
"@mnmal-ai/substrate-nl": "1.0.0-beta.
|
|
23
|
+
"@mnmal-ai/substrate": "1.0.0-beta.9",
|
|
24
|
+
"@mnmal-ai/substrate-nl": "1.0.0-beta.9",
|
|
25
25
|
"@mnmal-ai/surface-core": "0.17.1",
|
|
26
26
|
"@mnmal-ai/surface-kit": "0.17.1",
|
|
27
27
|
"@mnmal-ai/surface-theme": "0.17.1",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@biomejs/biome": "2.6.4",
|
|
33
|
-
"@mnmal-ai/substrate-config": "1.0.0-beta.
|
|
33
|
+
"@mnmal-ai/substrate-config": "1.0.0-beta.9",
|
|
34
34
|
"@types/node": "^26.6.4",
|
|
35
35
|
"@types/react": "^19.2.0",
|
|
36
36
|
"ink-testing-library": "^4.0.0",
|