@mnmal-ai/substrate-tui 1.0.0-beta.5 → 1.0.0-beta.6

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.
@@ -2420,6 +2420,10 @@ function compactGrant(namespaces, capabilities) {
2420
2420
  if (grant.size === 0) return "(none)";
2421
2421
  return [...grant].map(([ns, caps]) => `${ns}:${canonicalCaps(caps).map((c) => SHORT[c] ?? c).join("+")}`).join(",");
2422
2422
  }
2423
+ /** A namespace's capabilities as their short letters in canonical order: read, mutate, admin → `rma`. */
2424
+ function shortCaps(caps) {
2425
+ return canonicalCaps(caps).map((c) => SHORT[c] ?? `(${c})`).join("");
2426
+ }
2423
2427
  /** A stored row's grant, or null when it does not parse (the table still renders it). */
2424
2428
  function rowGrant(row) {
2425
2429
  try {
@@ -3370,6 +3374,91 @@ function editorPanels(deps) {
3370
3374
  }
3371
3375
  }
3372
3376
 
3377
+ //#endregion
3378
+ //#region src/keys/layout.ts
3379
+ const NO_HOST = "(no host)";
3380
+ const isRevoked = (r) => typeof r.revokedAt === "string";
3381
+ /** `agent@host` → [agent, host]; a kid without `@` has no host. */
3382
+ function splitKid(kid) {
3383
+ const at = kid.lastIndexOf("@");
3384
+ return at <= 0 ? [kid, NO_HOST] : [kid.slice(0, at), kid.slice(at + 1)];
3385
+ }
3386
+ const byText = (a, b) => a.localeCompare(b, void 0, { sensitivity: "base" }) || (a < b ? -1 : a > b ? 1 : 0);
3387
+ /** Display order: active keys by host then agent, then revoked keys, most recently revoked first. */
3388
+ function orderForView(rows) {
3389
+ const active = rows.filter((r) => !isRevoked(r));
3390
+ const revoked = rows.filter(isRevoked);
3391
+ active.sort((a, b) => {
3392
+ const [aa, ah] = splitKid(a.kid);
3393
+ const [ba, bh] = splitKid(b.kid);
3394
+ return byText(ah, bh) || byText(aa, ba);
3395
+ });
3396
+ revoked.sort((a, b) => String(b.revokedAt).localeCompare(String(a.revokedAt)) || byText(a.kid, b.kid));
3397
+ return [...active, ...revoked];
3398
+ }
3399
+ /** Namespaces in column order: `*` first, then the most widely granted, then by name. */
3400
+ function namespaceColumns(grants) {
3401
+ const count = /* @__PURE__ */ new Map();
3402
+ for (const g of grants) for (const ns of g?.keys() ?? []) count.set(ns, (count.get(ns) ?? 0) + 1);
3403
+ return [...count.keys()].sort((a, b) => (b === "*" ? 1 : 0) - (a === "*" ? 1 : 0) || (count.get(b) ?? 0) - (count.get(a) ?? 0) || byText(a, b));
3404
+ }
3405
+ /** The ordered rows as display lines (no cursor mark; the view adds it). */
3406
+ function listLines(rows) {
3407
+ const grants = rows.map((r) => {
3408
+ const g = rowGrant(r);
3409
+ return g === null ? null : new Map([...g].map(([ns, caps]) => [ns, shortCaps(caps)]));
3410
+ });
3411
+ const active = rows.flatMap((r, i) => isRevoked(r) ? [] : [i]);
3412
+ const cols = namespaceColumns(active.map((i) => grants[i] ?? null));
3413
+ const colW = cols.map((ns) => ns.length + 1 + Math.max(1, ...active.map((i) => grants[i]?.get(ns)?.length ?? 0)));
3414
+ const agentW = Math.max(4, ...active.map((i) => splitKid(rows[i].kid)[0].length));
3415
+ const lines = [];
3416
+ let host;
3417
+ rows.forEach((r, i) => {
3418
+ if (isRevoked(r)) {
3419
+ if (lines.every((l) => l.kind !== "revoked-head")) {
3420
+ if (lines.length > 0) lines.push({
3421
+ text: "",
3422
+ kind: "gap"
3423
+ });
3424
+ lines.push({
3425
+ text: "revoked",
3426
+ kind: "revoked-head"
3427
+ });
3428
+ }
3429
+ lines.push({
3430
+ text: `${r.kid} ${String(r.revokedAt).slice(0, 10)}`,
3431
+ row: i,
3432
+ kind: "revoked"
3433
+ });
3434
+ return;
3435
+ }
3436
+ const [agent, h] = splitKid(r.kid);
3437
+ if (h !== host) {
3438
+ if (host !== void 0) lines.push({
3439
+ text: "",
3440
+ kind: "gap"
3441
+ });
3442
+ lines.push({
3443
+ text: h,
3444
+ kind: "host"
3445
+ });
3446
+ host = h;
3447
+ }
3448
+ const g = grants[i];
3449
+ const grant = g === null || g === void 0 ? compactGrant(r.namespaces, r.capabilities) : g.size === 0 ? "(none)" : cols.map((ns, k) => {
3450
+ const caps = g.get(ns);
3451
+ return (caps === void 0 ? "" : `${ns} ${caps}`).padEnd(colW[k]);
3452
+ }).join(" ").trimEnd();
3453
+ lines.push({
3454
+ text: `${agent.padEnd(agentW)} ${grant}`,
3455
+ row: i,
3456
+ kind: "key"
3457
+ });
3458
+ });
3459
+ return lines;
3460
+ }
3461
+
3373
3462
  //#endregion
3374
3463
  //#region src/keys/module.ts
3375
3464
  /**
@@ -3379,7 +3468,6 @@ function editorPanels(deps) {
3379
3468
  * through a review. Locked, it reads as the agent, which a 403 turns into "admin required", and
3380
3469
  * Enter shows a row's grant read-only. Locking closes the table and every editor panel.
3381
3470
  */
3382
- const isRevoked = (r) => typeof r.revokedAt === "string";
3383
3471
  /** The rows the editor flows judge against: a revoked key holds no grant. */
3384
3472
  const live = (rows) => rows.filter((r) => !isRevoked(r));
3385
3473
  /** Opens the table and reads it; `select` is a kid whose row takes the cursor once the read lands. */
@@ -3395,10 +3483,10 @@ async function loadKeys(ctx, deps, select, revoked = false) {
3395
3483
  });
3396
3484
  const filter = revoked ? "all" : "active";
3397
3485
  try {
3398
- const rows = source === "admin" ? await deps.admin.run(({ client }) => client.admin.keys({
3486
+ const rows = orderForView(source === "admin" ? await deps.admin.run(({ client }) => client.admin.keys({
3399
3487
  signal: ctx.signal,
3400
3488
  filter
3401
- })) : await deps.keys(ctx.signal, filter);
3489
+ })) : await deps.keys(ctx.signal, filter));
3402
3490
  const at = select === void 0 ? -1 : rows.findIndex((r) => r.kid === select);
3403
3491
  const cursor = Math.max(0, at);
3404
3492
  const mine = (s) => s.source === source && s.revoked === revoked;
@@ -3446,16 +3534,14 @@ function keysModule(deps) {
3446
3534
  ...describeGrant(pick.namespaces, pick.capabilities).map((g) => truncateCells(sanitise(` ${g}`), w)),
3447
3535
  " backspace back · esc close"
3448
3536
  ].join("\n");
3449
- const kidW = Math.min(40, Math.max(4, ...state.rows.map((r) => r.kid.length)));
3450
- const nameW = Math.min(24, Math.max(4, ...state.rows.map((r) => r.name.length)));
3537
+ const all = listLines(state.rows);
3451
3538
  const max = Math.max(1, size.rows - 3);
3452
- const start = Math.max(0, Math.min(state.cursor - max + 1, state.rows.length - max));
3453
- const lines = state.rows.slice(start, start + max).map((r, k) => {
3454
- const mark = start + k === state.cursor ? theme.glyph.cursor : " ";
3455
- const grant = compactGrant(r.namespaces, r.capabilities);
3456
- const gone = isRevoked(r);
3457
- const text = truncateCells(sanitise(`${mark} ${r.kid.padEnd(kidW)} ${r.name.padEnd(nameW)} ${gone ? `revoked ${r.revokedAt} ` : ""}${grant}`), w);
3458
- return gone ? {
3539
+ const at = Math.max(0, all.findIndex((l) => l.row === state.cursor));
3540
+ const start = Math.max(0, Math.min(at - max + 1, all.length - max));
3541
+ const lines = all.slice(start, start + max).map((l) => {
3542
+ const mark = l.row !== void 0 && l.row === state.cursor ? theme.glyph.cursor : " ";
3543
+ const text = truncateCells(sanitise(l.kind === "key" || l.kind === "revoked" ? `${mark} ${l.text}` : ` ${l.text}`), w);
3544
+ return l.kind === "revoked" || l.kind === "revoked-head" ? {
3459
3545
  text,
3460
3546
  tone: "dim"
3461
3547
  } : { text };
@@ -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-h4FA6Urt.js"),
54
+ import("../app-DmFXZmFW.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.5",
3
+ "version": "1.0.0-beta.6",
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.5",
24
- "@mnmal-ai/substrate-nl": "1.0.0-beta.5",
23
+ "@mnmal-ai/substrate": "1.0.0-beta.6",
24
+ "@mnmal-ai/substrate-nl": "1.0.0-beta.6",
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.5",
33
+ "@mnmal-ai/substrate-config": "1.0.0-beta.6",
34
34
  "@types/node": "^26.6.4",
35
35
  "@types/react": "^19.2.0",
36
36
  "ink-testing-library": "^4.0.0",