@mnmal-ai/substrate-tui 1.0.0-beta.8 → 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.
|
@@ -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
|
}
|
|
@@ -1474,11 +1523,6 @@ function askModule(deps, pager = listPager()) {
|
|
|
1474
1523
|
});
|
|
1475
1524
|
}
|
|
1476
1525
|
|
|
1477
|
-
//#endregion
|
|
1478
|
-
//#region src/text.ts
|
|
1479
|
-
/** Server text on one line: no escape or control bytes, and line breaks collapsed to a space. */
|
|
1480
|
-
const clean = (s) => sanitise(s.replace(/[\r\n]+/g, " "));
|
|
1481
|
-
|
|
1482
1526
|
//#endregion
|
|
1483
1527
|
//#region src/dash/derive.ts
|
|
1484
1528
|
/** Polls kept per sparkline. */
|
|
@@ -2422,9 +2466,12 @@ function compactGrant(namespaces, capabilities) {
|
|
|
2422
2466
|
if (grant.size === 0) return "(none)";
|
|
2423
2467
|
return [...grant].map(([ns, caps]) => `${ns}:${canonicalCaps(caps).map((c) => SHORT[c] ?? c).join("+")}`).join(",");
|
|
2424
2468
|
}
|
|
2425
|
-
/**
|
|
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
|
+
*/
|
|
2426
2473
|
function shortCaps(caps) {
|
|
2427
|
-
return canonicalCaps(caps).map((c) => SHORT[c] ?? `(${c})`)
|
|
2474
|
+
return canonicalCaps(caps).map((c) => SHORT[c] ?? `(${c})`);
|
|
2428
2475
|
}
|
|
2429
2476
|
/** A stored row's grant, or null when it does not parse (the table still renders it). */
|
|
2430
2477
|
function rowGrant(row) {
|
|
@@ -3393,7 +3440,7 @@ function orderForView(rows) {
|
|
|
3393
3440
|
active.sort((a, b) => {
|
|
3394
3441
|
const [aa, ah] = splitKid(a.kid);
|
|
3395
3442
|
const [ba, bh] = splitKid(b.kid);
|
|
3396
|
-
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());
|
|
3397
3444
|
});
|
|
3398
3445
|
revoked.sort((a, b) => String(b.revokedAt).localeCompare(String(a.revokedAt)) || byText(a.kid, b.kid));
|
|
3399
3446
|
return [...active, ...revoked];
|
|
@@ -3404,62 +3451,223 @@ function namespaceColumns(grants) {
|
|
|
3404
3451
|
for (const g of grants) for (const ns of g?.keys() ?? []) count.set(ns, (count.get(ns) ?? 0) + 1);
|
|
3405
3452
|
return [...count.keys()].sort((a, b) => (b === "*" ? 1 : 0) - (a === "*" ? 1 : 0) || (count.get(b) ?? 0) - (count.get(a) ?? 0) || byText(a, b));
|
|
3406
3453
|
}
|
|
3407
|
-
/** The
|
|
3408
|
-
|
|
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) {
|
|
3409
3540
|
const grants = rows.map((r) => {
|
|
3410
3541
|
const g = rowGrant(r);
|
|
3411
|
-
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)]));
|
|
3412
3543
|
});
|
|
3413
3544
|
const active = rows.flatMap((r, i) => isRevoked(r) ? [] : [i]);
|
|
3414
3545
|
const cols = namespaceColumns(active.map((i) => grants[i] ?? null));
|
|
3415
|
-
const colW = cols.map((ns) => ns
|
|
3416
|
-
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
|
+
};
|
|
3417
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;
|
|
3418
3599
|
let host;
|
|
3419
3600
|
rows.forEach((r, i) => {
|
|
3420
3601
|
if (isRevoked(r)) {
|
|
3421
|
-
if (lines.every((l) => l.kind !== "revoked-
|
|
3422
|
-
if (lines.length > 0)
|
|
3423
|
-
text: "",
|
|
3602
|
+
if (lines.every((l) => l.kind !== "revoked-band")) {
|
|
3603
|
+
if (lines.length > 0) push({
|
|
3604
|
+
parts: [{ text: " " }],
|
|
3424
3605
|
kind: "gap"
|
|
3425
3606
|
});
|
|
3426
|
-
lines.push(
|
|
3427
|
-
text: "revoked",
|
|
3428
|
-
kind: "revoked-head"
|
|
3429
|
-
});
|
|
3607
|
+
lines.push(band("revoked", revokedCount, width, "revoked-band"));
|
|
3430
3608
|
}
|
|
3431
|
-
|
|
3432
|
-
|
|
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
|
+
],
|
|
3433
3622
|
row: i,
|
|
3434
3623
|
kind: "revoked"
|
|
3435
3624
|
});
|
|
3436
3625
|
return;
|
|
3437
3626
|
}
|
|
3438
|
-
const
|
|
3439
|
-
if (
|
|
3440
|
-
if (host !== void 0)
|
|
3441
|
-
text: "",
|
|
3627
|
+
const key = splitKid(r.kid)[1].toLowerCase();
|
|
3628
|
+
if (key !== host) {
|
|
3629
|
+
if (host !== void 0) push({
|
|
3630
|
+
parts: [{ text: " " }],
|
|
3442
3631
|
kind: "gap"
|
|
3443
3632
|
});
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
});
|
|
3448
|
-
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;
|
|
3449
3636
|
}
|
|
3450
|
-
const
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
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
|
+
],
|
|
3457
3645
|
row: i,
|
|
3458
3646
|
kind: "key"
|
|
3459
3647
|
});
|
|
3460
3648
|
});
|
|
3461
3649
|
return lines;
|
|
3462
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
|
+
}
|
|
3463
3671
|
|
|
3464
3672
|
//#endregion
|
|
3465
3673
|
//#region src/keys/module.ts
|
|
@@ -3470,6 +3678,65 @@ function listLines(rows) {
|
|
|
3470
3678
|
* through a review. Locked, it reads as the agent, which a 403 turns into "admin required", and
|
|
3471
3679
|
* Enter shows a row's grant read-only. Locking closes the table and every editor panel.
|
|
3472
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
|
+
}
|
|
3473
3740
|
/** The rows the editor flows judge against: a revoked key holds no grant. */
|
|
3474
3741
|
const live = (rows) => rows.filter((r) => !isRevoked(r));
|
|
3475
3742
|
/** Opens the table and reads it; `select` is a kid whose row takes the cursor once the read lands. */
|
|
@@ -3522,38 +3789,45 @@ function keysModule(deps) {
|
|
|
3522
3789
|
keys: {
|
|
3523
3790
|
...KEYS_CHROME,
|
|
3524
3791
|
view: ({ state, theme, size }) => {
|
|
3525
|
-
const w =
|
|
3526
|
-
const
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
if (state.note !== null) return [head, ` ${sanitise(state.note)}`].join("\n");
|
|
3530
|
-
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);
|
|
3531
3796
|
const pick = state.rows[state.cursor];
|
|
3532
|
-
if (state.detail && pick !== void 0)
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
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);
|
|
3540
3807
|
const max = Math.max(1, size.rows - 3);
|
|
3541
3808
|
const at = Math.max(0, all.findIndex((l) => l.row === state.cursor));
|
|
3542
3809
|
const start = Math.max(0, Math.min(at - max + 1, all.length - max));
|
|
3543
|
-
const lines = all.slice(start, start + max).map((l) =>
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
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
|
+
];
|
|
3552
3826
|
return linesView([
|
|
3553
|
-
|
|
3827
|
+
headLine,
|
|
3554
3828
|
...lines,
|
|
3555
|
-
|
|
3556
|
-
|
|
3829
|
+
partsLine(truncateParts(legendParts(), w)),
|
|
3830
|
+
partsLine(truncateParts(hintParts(hints), w))
|
|
3557
3831
|
], theme);
|
|
3558
3832
|
},
|
|
3559
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",
|