mapsource-node 0.1.1 → 0.1.2

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 CHANGED
@@ -4,7 +4,7 @@ Mapsource Node provides a terminal dashboard for Mapsource infrastructure and
4
4
  an enrollment client for compatible Linux read-engine hosts.
5
5
 
6
6
  ```sh
7
- npm install --global mapsource-node@next
7
+ npm install --global mapsource-node
8
8
  mapsource-node
9
9
  ```
10
10
 
@@ -14,21 +14,25 @@ engine constraints, pass `--engine-strict=false` when installing this release.
14
14
 
15
15
  Use `mapsource-node --json` for a read-only telemetry snapshot. The Services
16
16
  tab shows recent queue depth and latency when the local controller measures
17
- them. The operator can run `mapsource-node services` on a configured enrollment
18
- authority to see the available service profiles.
17
+ them.
19
18
 
20
- ```sh
21
- mapsource-node invite --node new-node --services search,routing --out ./sync-key
22
- mapsource-node setup --key-file ./sync-key
23
- mapsource-node status
24
- ```
19
+ ## Enroll a node
25
20
 
26
- Run the first command on the authority and the others on the new host. Keep
27
- the key file private and remove it after the node claims the invitation.
28
- Run `mapsource-node resume` after an interruption. A registered Cloudflare
29
- peer endpoint establishes node identity and transport. Serving traffic
30
- requires a separate fleet admission. Use `disable` or `retire` to preview
31
- the services affected by either operation.
21
+ 1. On Primary, open `mapsource-node` and choose **Enrollment → Create sync key**.
22
+ Enter the new node's name. Select the services it may install or leave the
23
+ selection empty to allow every service currently offered. Admins can also
24
+ create a key under **Enrollment** in the Mapsource site dashboard.
25
+ 2. On the new host, install the package and open `mapsource-node`. The Enrollment
26
+ screen opens automatically. Paste the short-lived key to see the offered
27
+ services and local disk usage.
28
+ 3. Choose the services to install, review available storage and required space,
29
+ then confirm. Run the console as the intended node service account with
30
+ noninteractive sudo. If the session is interrupted, reopen the console and
31
+ use **Resume enrollment**. If the claim is pending, paste the original key.
32
+ 4. Watch the status screen for the registered Cloudflare peer endpoint, dataset
33
+ synchronization, and engine verification. Serving traffic requires separate
34
+ fleet admission. Use `disable` or `retire` to preview the services affected by
35
+ either operation.
32
36
 
33
37
  Use `mapsource-node --help` for the CLI and [RELEASING.md](RELEASING.md) for
34
38
  publishing.
@@ -11,7 +11,6 @@ const [command, ...args] = process.argv.slice(2);
11
11
  try {
12
12
  if (command === "--version" && !args.length) console.log(`mapsource-node ${pkg.version}`);
13
13
  else if (command === undefined || command === "--self-test" || command === "--json") {
14
- if (command === undefined && await (await import("../src/commands.mjs")).firstRun()) process.exit(0);
15
14
  const candidates = { x64: "@oven/bun-linux-x64-baseline", arm64: "@oven/bun-linux-aarch64" };
16
15
  const platform = candidates[process.arch];
17
16
  if (process.platform !== "linux" || !platform) throw new Error("The terminal interface requires Linux x64 or ARM64.");
@@ -19,7 +18,7 @@ try {
19
18
  const entrypoint = fileURLToPath(new URL("../src/index.ts", import.meta.url));
20
19
  const child = spawn(executable, ["--no-env-file", entrypoint, ...process.argv.slice(2)], {
21
20
  stdio: "inherit",
22
- env: { ...process.env, OPENTUI_LIBC: "glibc", MAPSOURCE_NODE_BUILD: pkg.version },
21
+ env: { ...process.env, OPENTUI_LIBC: "glibc", MAPSOURCE_NODE_BUILD: pkg.version, MAPSOURCE_NODE_BOOTSTRAP_EXEC: process.execPath },
23
22
  });
24
23
  const signalChild = () => child.kill("SIGTERM");
25
24
  process.once("SIGTERM", signalChild);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mapsource-node",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Mapsource node operations and enrollment",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -51,7 +51,8 @@ export async function measureHost(targets) {
51
51
  for (const [id, target] of Object.entries(targets)) {
52
52
  const directory = await nearestMount(target);
53
53
  const [volume, metadata] = await Promise.all([statfs(directory), stat(directory)]);
54
- mounts[id] = { path: target, device: metadata.dev, bytes: volume.bavail * volume.bsize, inodes: volume.ffree };
54
+ mounts[id] = { path: target, device: metadata.dev, bytes: volume.bavail * volume.bsize,
55
+ percentUsed: volume.blocks > 0 ? Math.round(100 * (volume.blocks - volume.bfree) / volume.blocks) : null, inodes: volume.ffree };
55
56
  }
56
57
  const memory = /^MemAvailable:\s+(\d+) kB$/m.exec(await readFile("/proc/meminfo", "utf8").catch(() => ""));
57
58
  const os = /^ID="?([a-z0-9-]+)"?$/m.exec(await readFile("/etc/os-release", "utf8").catch(() => ""))?.[1] ?? "unknown";
package/src/commands.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import { execFileSync } from "node:child_process";
1
+ import { execFile } from "node:child_process";
2
2
  import { access, mkdir, open, rm } from "node:fs/promises";
3
3
  import { homedir } from "node:os";
4
4
  import path from "node:path";
5
5
  import { createInterface } from "node:readline/promises";
6
- import { parseArgs } from "node:util";
6
+ import { parseArgs, promisify } from "node:util";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { measureHost, planServices, validateCatalog } from "./capability.mjs";
9
9
  import { catalogDigest, enrollmentRequest, localIdentity, operatorRequest, readEnrollment, readInvitation, saveEnrollment, secretInput } from "./enrollment.mjs";
@@ -18,12 +18,19 @@ const show = value => console.log(JSON.stringify(value, null, 2));
18
18
  const servicesOption = { services: { type: "string" } };
19
19
  const flags = (args, options) => parseArgs({ args, options }).values;
20
20
  const ids = value => value.split(",").map(item => item.trim()).filter(Boolean);
21
+ const run = promisify(execFile);
22
+ export const localCapacity = () => measureHost(targets);
23
+ export const savedEnrollment = () => readEnrollment().catch(error => { if (error.code !== "ENOENT") throw error; });
24
+ export async function hasMesh() {
25
+ const paths = ["/etc/mapsource-cd/node-v5.json", "/etc/systemd/system/mapsource-mesh-tunnel.service"];
26
+ return (await Promise.all(paths.map(file => access(file).then(() => true, () => false)))).some(Boolean);
27
+ }
21
28
  const usage = `Mapsource Node
22
29
 
23
30
  mapsource-node Open the terminal dashboard
24
31
  mapsource-node --json Read current fleet telemetry
25
32
  mapsource-node services List profiles offered by the local authority
26
- mapsource-node invite --node NAME --services ID[,ID] [--out FILE]
33
+ mapsource-node invite --node NAME [--services ID[,ID]] [--out FILE]
27
34
  mapsource-node revoke --node NAME Revoke an unused sync key
28
35
  mapsource-node setup [--key-file FILE | --key-stdin] [--services ID[,ID]] [--apply]
29
36
  mapsource-node resume Resume an authorized enrollment and deploy
@@ -65,8 +72,14 @@ async function localMesh(configuration) {
65
72
  } finally { await file.close(); }
66
73
  // Only the reviewed, npm-pinned bootstrap code is executable. The authority
67
74
  // supplies the scoped connector credential and node identity as data.
68
- const text = execFileSync(process.execPath, [bootstrap, "--execute"], {
69
- input: JSON.stringify(payload), encoding: "utf8", stdio: ["pipe", "pipe", "pipe"], timeout: 180_000,
75
+ const text = await new Promise((resolve, reject) => {
76
+ const node = process.env.MAPSOURCE_NODE_BOOTSTRAP_EXEC || process.execPath;
77
+ const child = execFile(node, [bootstrap, "--execute"], { encoding: "utf8", timeout: 180_000 }, (error, stdout) => {
78
+ if (error) reject(new Error("Local peer setup failed. Check the service user's sudo access and the SSH and tunnel services."));
79
+ else resolve(stdout);
80
+ });
81
+ child.stdin?.on("error", () => {});
82
+ child.stdin?.end(JSON.stringify(payload));
70
83
  });
71
84
  const installed = JSON.parse(text.trim().split("\n").at(-1));
72
85
  if (installed.installed !== true || installed.node !== payload.node || installed.machineId !== payload.machineId) {
@@ -76,68 +89,107 @@ async function localMesh(configuration) {
76
89
  }
77
90
 
78
91
  async function localPrivileges(services, catalog) {
79
- execFileSync("/usr/bin/sudo", ["-n", "true"], { stdio: "ignore", timeout: 5000 });
92
+ await run("/usr/bin/sudo", ["-n", "true"], { timeout: 5000 }).catch(() => { throw new Error("Setup requires noninteractive sudo for this service user."); });
80
93
  if (catalog.services.some(service => services.includes(service.id) && service.tools.includes("docker"))) {
81
- execFileSync("docker", ["info", "--format", "{{.ServerVersion}}"], { stdio: "ignore", timeout: 8000 });
82
- execFileSync("docker", ["compose", "version", "--short"], { stdio: "ignore", timeout: 8000 });
94
+ await run("docker", ["info", "--format", "{{.ServerVersion}}"], { timeout: 8000 }).catch(() => { throw new Error("Setup requires access to the running Docker daemon."); });
95
+ await run("docker", ["compose", "version", "--short"], { timeout: 8000 }).catch(() => { throw new Error("Setup requires Docker Compose."); });
83
96
  }
84
97
  }
85
98
 
86
- async function resume() {
99
+ async function authorizedCall(saved) {
100
+ const identity = await localIdentity();
101
+ return (operation, value = {}) => enrollmentRequest(saved.endpoint, operation, { node: saved.node, ...value }, { identity });
102
+ }
103
+
104
+ export async function enrollmentStatus() {
105
+ const saved = await readEnrollment();
106
+ if (saved.pendingClaim) return { node: saved.node, phase: "awaiting-key" };
107
+ return (await authorizedCall(saved))("status");
108
+ }
109
+
110
+ /** @param {(message: string) => void} onStage */
111
+ export async function resume(onStage = (_message) => {}) {
87
112
  const saved = await readEnrollment();
88
113
  if (saved.pendingClaim) throw new Error("Re-enter the same sync key with setup to resume the authorized selection.");
89
- const identity = await localIdentity();
90
- const call = (operation, value = {}) => enrollmentRequest(saved.endpoint, operation, { node: saved.node, ...value }, { identity });
114
+ const call = await authorizedCall(saved);
91
115
  let result = await call("status");
92
116
  if (["authorized", "tunnel-issued"].includes(result.phase)) {
117
+ onStage("Installing the named Cloudflare connector…");
93
118
  const peer = await call("bootstrap");
94
119
  const identityProof = await localMesh(peer);
120
+ onStage("Verifying the node through its tunnel…");
95
121
  result = await call("register", identityProof);
96
122
  }
97
123
  if (["registered", "failed"].includes(result.phase)) {
98
124
  const host = await measureHost(targets);
99
125
  const plan = planServices(saved.catalog, host, saved.services);
100
- if (!plan.eligible) { showPlan(plan); throw new Error("This host no longer meets the selected service requirements."); }
126
+ if (!plan.eligible) throw new Error(plan.errors.join(" "));
101
127
  await localPrivileges(saved.services, saved.catalog);
128
+ onStage("Requesting the dataset sync…");
102
129
  result = await call("deploy");
103
130
  }
104
131
  return result;
105
132
  }
106
133
 
134
+ export async function inspectSyncKey(raw) {
135
+ const invitation = readInvitation(raw), saved = await savedEnrollment();
136
+ if (saved && !saved.pendingClaim) throw new Error("This node already has an enrollment. Open its status to continue.");
137
+ if (saved && saved.endpoint !== invitation.endpoint) throw new Error("Resume with the original sync key.");
138
+ const grant = saved
139
+ ? { node: saved.node, allowed: saved.services, catalog: saved.catalog }
140
+ : await enrollmentRequest(invitation.endpoint, "catalog", {}, { invitation });
141
+ validateCatalog(grant.catalog);
142
+ const host = await measureHost(targets);
143
+ const services = grant.catalog.services.filter(service => grant.allowed.includes(service.id));
144
+ return { invitation, saved, grant, host, services };
145
+ }
146
+
147
+ /** @param {(message: string) => void} onStage */
148
+ export async function applySyncKey(review, selection, onStage = (_message) => {}) {
149
+ const { invitation, grant } = review;
150
+ const services = [...new Set(selection)].sort();
151
+ if (!services.length || !services.every(id => grant.allowed.includes(id))) throw new Error("Select services permitted by this sync key.");
152
+ const current = await savedEnrollment();
153
+ if (current && !current.pendingClaim) return resume(onStage);
154
+ if (current && (current.node !== grant.node || current.endpoint !== invitation.endpoint ||
155
+ JSON.stringify(current.services) !== JSON.stringify(services))) throw new Error("Resume the pending enrollment with its original selection.");
156
+ const plan = planServices(grant.catalog, await measureHost(targets), services);
157
+ if (!plan.eligible) throw new Error(plan.errors.join(" "));
158
+ await localPrivileges(services, grant.catalog);
159
+ const saved = { node: grant.node, endpoint: invitation.endpoint, services, catalog: grant.catalog, pendingClaim: true };
160
+ await saveEnrollment(saved);
161
+ onStage("Claiming the sync key…");
162
+ const identity = await localIdentity();
163
+ const receipt = await enrollmentRequest(saved.endpoint, "claim", {
164
+ machineId: identity.machineId, username: identity.username, services, catalogDigest: catalogDigest(saved.catalog),
165
+ }, { invitation, identity });
166
+ if (receipt.node !== saved.node) throw new Error("The claimed identity does not match the enrollment.");
167
+ await saveEnrollment({ ...saved, pendingClaim: false });
168
+ return resume(onStage);
169
+ }
170
+
107
171
  async function setup(args) {
108
172
  const options = flags(args, { ...servicesOption, "key-file": { type: "string" }, "key-stdin": { type: "boolean" }, apply: { type: "boolean" } });
109
173
  if (options["key-file"] && options["key-stdin"]) throw new Error("Choose one sync key input.");
110
- let saved = await readEnrollment().catch(error => { if (error.code !== "ENOENT") throw error; });
174
+ const saved = await savedEnrollment();
111
175
  if (saved && !saved.pendingClaim) { show(await resume()); return; }
112
- const invitation = readInvitation(await secretInput({ fromFile: options["key-file"], fromStdin: options["key-stdin"] }));
113
- if (saved && saved.endpoint !== invitation.endpoint) throw new Error("Resume with the original sync key.");
176
+ const review = await inspectSyncKey(await secretInput({ fromFile: options["key-file"], fromStdin: options["key-stdin"] }));
177
+ const { grant: { catalog }, host, services } = review;
114
178
  if (!saved) {
115
- const grant = await enrollmentRequest(invitation.endpoint, "catalog", {}, { invitation });
116
- const catalog = grant.catalog;
117
- validateCatalog(catalog);
118
- const host = await measureHost(targets);
119
179
  console.log(`${host.os} ${host.architecture} · ${host.cpu} threads · ${gib(host.memoryBytes)} available · CUDA device ${host.cuda ? "detected" : "absent"}`);
120
- for (const service of catalog.services.filter(item => grant.allowed.includes(item.id))) {
180
+ for (const service of services) {
121
181
  const { errors, eligible } = planServices(catalog, host, [service.id]);
122
182
  console.log(` ${service.id} ${printable(service.label)} · ${eligible ? "compatible" : printable(errors[0])}`);
123
183
  }
124
- const selection = ids(options.services ?? await input("Select service IDs separated by commas: "));
125
- if (!selection.every(id => grant.allowed.includes(id))) throw new Error("The sync key does not permit one or more selected services.");
184
+ }
185
+ const selection = saved?.services ?? ids(options.services ?? await input("Select service IDs separated by commas: "));
186
+ if (!saved) {
126
187
  const plan = planServices(catalog, host, selection);
127
188
  showPlan(plan);
128
189
  if (!plan.eligible) throw new Error("The selection exceeds this host’s capacity.");
129
190
  if (!options.apply && (!process.stdin.isTTY || (await input("Apply this plan? [y/N] ")).toLowerCase() !== "y")) return;
130
- await localPrivileges(selection, catalog);
131
- saved = { node: grant.node, endpoint: invitation.endpoint, services: [...new Set(selection)].sort(), catalog, pendingClaim: true };
132
- await saveEnrollment(saved);
133
191
  }
134
- const identity = await localIdentity();
135
- const receipt = await enrollmentRequest(saved.endpoint, "claim", {
136
- machineId: identity.machineId, username: identity.username, services: saved.services, catalogDigest: catalogDigest(saved.catalog),
137
- }, { invitation, identity });
138
- if (receipt.node !== saved.node) throw new Error("The claimed identity does not match the enrollment.");
139
- await saveEnrollment({ ...saved, pendingClaim: false });
140
- show(await resume());
192
+ show(await applySyncKey(review, selection));
141
193
  }
142
194
 
143
195
  export async function main(command, args) {
@@ -149,19 +201,19 @@ export async function main(command, args) {
149
201
  const options = flags(args, command === "invite" ? { node: { type: "string" }, out: { type: "string" }, ...servicesOption } : { node: { type: "string" } });
150
202
  if (!options.node) throw new Error("Pass --node NAME.");
151
203
  if (command === "revoke") { show(await operatorRequest(command, { node: options.node })); return; }
152
- if (!options.services) throw new Error("Pass --services with at least one service ID.");
204
+ const request = { node: options.node, ...(options.services && { services: ids(options.services) }) };
153
205
  if (options.out) {
154
206
  const fd = await open(options.out, "wx", 0o600);
155
207
  let complete = false;
156
208
  try {
157
- const result = await operatorRequest(command, { node: options.node, services: ids(options.services) });
209
+ const result = await operatorRequest(command, request);
158
210
  await fd.writeFile(result.key + "\n"); await fd.sync();
159
211
  complete = true;
160
212
  show({ node: result.node, expiresAt: result.expiresAt, keyFile: options.out });
161
213
  } finally { await fd.close(); if (!complete) await rm(options.out); }
162
214
  } else {
163
215
  if (!process.stdout.isTTY) throw new Error("Use --out FILE to avoid printing a key into logs or a pipeline.");
164
- const result = await operatorRequest(command, { node: options.node, services: ids(options.services) });
216
+ const result = await operatorRequest(command, request);
165
217
  console.log(result.key);
166
218
  console.log("Expires " + new Date(result.expiresAt).toISOString());
167
219
  }
@@ -177,16 +229,3 @@ export async function main(command, args) {
177
229
  }
178
230
  throw new Error("Unknown command. Run mapsource-node --help.");
179
231
  }
180
-
181
- export async function firstRun() {
182
- const enrolled = await Promise.all(["/etc/mapsource-cd/node-v5.json", "/etc/systemd/system/mapsource-mesh-tunnel.service"]
183
- .map(file => access(file).then(() => true, () => false)));
184
- if (enrolled.some(Boolean)) return false;
185
- const state = await readEnrollment().catch(error => { if (error.code !== "ENOENT") throw error; });
186
- if (state && !state.pendingClaim) return false;
187
- if (!process.stdin.isTTY) return false;
188
- console.log("Mapsource Node · First-time setup");
189
- console.log("Create a sync key on an enrolled host with mapsource-node invite.");
190
- await setup([]);
191
- return true;
192
- }
@@ -0,0 +1,64 @@
1
+ import assert from "node:assert/strict";
2
+ import type { createTestRenderer } from "@opentui/core/testing";
3
+ import type { CliRenderer } from "@opentui/core";
4
+ import { nodeInterface } from "./interface.ts";
5
+ import type { enrollmentActions } from "./enrollment-screen.ts";
6
+
7
+ const services = [{ id: "tiles", label: "Raster and vector tiles" }];
8
+ const secret = "mps-sync1:mapsource-enroll-primary.mapsource.io:" + "a".repeat(32) + ":" + "b".repeat(43);
9
+ const host = {
10
+ platform: "linux" as const, os: "debian", architecture: "x64" as const, cpu: 4, memoryBytes: 8 * 1024 ** 3, tools: [], cuda: false,
11
+ mounts: { data: { path: "/srv/mapsource-mirror", device: 1, bytes: 500 * 1024 ** 3, inodes: 4000, percentUsed: 32 } },
12
+ };
13
+ type Actions = typeof enrollmentActions;
14
+ type BindKeys = (renderer: CliRenderer, ui: ReturnType<typeof nodeInterface>, refresh: () => void) => void;
15
+
16
+ export async function testEnrollmentScreen(bind: BindKeys, testRenderer: typeof createTestRenderer) {
17
+ const calls: unknown[] = [];
18
+ const base: Actions = {
19
+ hasMesh: async () => true, savedEnrollment: async () => undefined, capacity: async () => host,
20
+ inspect: async () => ({ invitation: {} as Awaited<ReturnType<Actions["inspect"]>>["invitation"], saved: undefined,
21
+ grant: { node: "test-node", allowed: ["tiles"], catalog: {} }, host, services }),
22
+ apply: async (_review, selected) => { calls.push(selected); return { node: "test-node", phase: "copying" }; },
23
+ plan: () => ({ eligible: true, services, requiredCpu: 1, requiredMemory: 2 ** 30, disks: [], errors: [] }),
24
+ status: async () => ({ node: "test-node", phase: "copying" }),
25
+ resume: async () => ({ node: "test-node", phase: "copying" }),
26
+ catalog: async () => services,
27
+ invite: async (node, allowed) => { calls.push({ node, allowed }); return { node, key: secret, expiresAt: Date.now() + 600_000 }; },
28
+ revoke: async () => ({ revoked: true }),
29
+ };
30
+ for (const fresh of [false, true]) {
31
+ const { renderer, mockInput, renderOnce, captureCharFrame } = await testRenderer({ width: 100, height: 30 });
32
+ try {
33
+ const ui = nodeInterface(renderer, "test", { ...base, hasMesh: async () => !fresh });
34
+ bind(renderer, ui, () => {});
35
+ const frame = async () => { await new Promise(resolve => setTimeout(resolve, 10)); await renderOnce(); return captureCharFrame(); };
36
+ await mockInput.pressKey("4");
37
+ if (fresh) {
38
+ assert.match(await frame(), /32% used/);
39
+ await mockInput.pasteBracketedText(secret);
40
+ assert.doesNotMatch(await frame(), /mps-sync1/);
41
+ mockInput.pressEnter();
42
+ assert.match(await frame(), /Raster and vector tiles/);
43
+ mockInput.pressKey(" ");
44
+ assert.match(await frame(), /Plan · 1 threads/);
45
+ assert.equal(calls.length, 1);
46
+ mockInput.pressEnter();
47
+ assert.match(await frame(), /Copying datasets/);
48
+ assert.deepEqual(calls[1], ["tiles"]);
49
+ } else {
50
+ assert.match(await frame(), /Key issuer · Primary · connected/);
51
+ await mockInput.pressKey("g");
52
+ await mockInput.typeText("test-node");
53
+ mockInput.pressEnter();
54
+ assert.match(await frame(), /An empty selection allows all/);
55
+ mockInput.pressEnter();
56
+ assert.match(await frame(), /SYNC KEY CREATED/);
57
+ assert.deepEqual(calls[0], { node: "test-node", allowed: [] });
58
+ assert.doesNotMatch(await frame(), /mps-sync1/);
59
+ await mockInput.pressKey("v");
60
+ assert.match(await frame(), /mps-sync1/);
61
+ }
62
+ } finally { renderer.destroy(); }
63
+ }
64
+ }
@@ -0,0 +1,249 @@
1
+ import type { KeyEvent } from "@opentui/core";
2
+ import { applySyncKey, enrollmentStatus, hasMesh, inspectSyncKey, localCapacity, resume, savedEnrollment } from "./commands.mjs";
3
+ import { planServices } from "./capability.mjs";
4
+ import { operatorRequest } from "./enrollment.mjs";
5
+
6
+ type Profile = { id: string; label: string };
7
+ type Key = { node: string; key: string; expiresAt: number };
8
+ type Job = { phase: string; node: string; endpoint?: string; message?: string; services?: (string | { id: string; phase: string })[] };
9
+ type Line = { text: string; action?: () => void; tone?: "action" | "muted" };
10
+ type Mode = "home" | "name" | "allow" | "issued" | "key" | "choose" | "status" | "revoke";
11
+ const safe = (value: unknown) => String(value).replace(/[\p{Cc}\p{Cf}]/gu, "").slice(0, 600);
12
+ const gib = (bytes: number) => (bytes / 1024 ** 3).toFixed(1) + " GiB";
13
+ const phaseLabels: Record<string, string> = {
14
+ "awaiting-key": "Waiting for the original sync key",
15
+ authorized: "Authorized", "tunnel-issued": "Connector issued", registered: "Peer registered", copying: "Copying datasets",
16
+ verified: "Engines verified · awaiting fleet admission", serving: "Serving", failed: "Sync needs attention",
17
+ disabled: "Disabled", retiring: "Retiring services", retired: "Retired",
18
+ };
19
+
20
+ export const enrollmentActions = {
21
+ hasMesh, savedEnrollment, capacity: localCapacity, inspect: inspectSyncKey, apply: applySyncKey,
22
+ plan: planServices,
23
+ status: enrollmentStatus as () => Promise<Job>,
24
+ resume: resume as (stage: (message: string) => void) => Promise<Job>,
25
+ catalog: async () => (await operatorRequest("catalog", {}) as { catalog: { services: Profile[] } }).catalog.services,
26
+ invite: (node: string, services: string[]) => operatorRequest("invite", { node, ...(services.length ? { services } : {}) }) as Promise<Key>,
27
+ revoke: (node: string) => operatorRequest("revoke", { node }) as Promise<{ revoked: boolean }>,
28
+ };
29
+
30
+ export function enrollmentScreen(draw: () => void, clipboard: (text: string) => boolean, api = enrollmentActions) {
31
+ let mode: Mode = "home";
32
+ let initialized = false, mesh = false, enrolled = false, awaitingKey = false, reveal = false;
33
+ let busy = "", notice = "", input = "", target = "";
34
+ let authority: Profile[] | null = null;
35
+ let host: Awaited<ReturnType<typeof localCapacity>> | undefined;
36
+ let review: Awaited<ReturnType<typeof inspectSyncKey>> | undefined;
37
+ let issued: Key | undefined, job: Job | undefined;
38
+ let cursor = 0;
39
+ const choices = new Set<string>();
40
+ const selection = () => Array.from(choices);
41
+ const setMode = (value: Mode) => { mode = value; input = ""; notice = ""; cursor = 0; draw(); };
42
+
43
+ async function act(label: string, action: () => Promise<void>) {
44
+ if (busy) return;
45
+ busy = label; notice = ""; draw();
46
+ try { await action(); }
47
+ catch (cause) { notice = safe(cause instanceof Error ? cause.message : "Enrollment request failed."); }
48
+ finally { busy = ""; draw(); }
49
+ }
50
+
51
+ function refresh() {
52
+ return act("Checking enrollment…", async () => {
53
+ const [local, saved, capacity, offered] = await Promise.all([
54
+ api.hasMesh(), api.savedEnrollment(), api.capacity(), api.catalog().catch(() => null),
55
+ ]);
56
+ mesh = local; enrolled = !!saved; awaitingKey = !!saved?.pendingClaim; host = capacity; authority = offered;
57
+ if (!initialized) {
58
+ initialized = true;
59
+ if (enrolled && !awaitingKey) mode = "status";
60
+ else if (!mesh || awaitingKey) mode = "key";
61
+ }
62
+ if (mode === "status") job = await api.status();
63
+ if (mode === "choose" && review) review = { ...review, host: capacity };
64
+ });
65
+ }
66
+
67
+ function showStatus() {
68
+ setMode("status");
69
+ void refresh();
70
+ }
71
+
72
+ function submit() {
73
+ if (mode === "name") {
74
+ if (!/^[a-z][a-z0-9-]{0,31}$/.test(input)) { notice = "Use a lowercase node name with letters, digits or dashes."; draw(); return; }
75
+ target = input; choices.clear(); setMode("allow");
76
+ } else if (mode === "allow") {
77
+ void act("Creating a sync key…", async () => { issued = await api.invite(target, selection()); reveal = false; setMode("issued"); });
78
+ } else if (mode === "key") {
79
+ const key = input;
80
+ input = "";
81
+ void act("Checking the sync key and local capacity…", async () => {
82
+ review = await api.inspect(key);
83
+ host = review.host;
84
+ choices.clear();
85
+ for (const service of review.saved?.services ?? []) choices.add(service);
86
+ setMode("choose");
87
+ });
88
+ } else if (mode === "choose" && review) {
89
+ if (!selection().length) { notice = "Select at least one service."; draw(); return; }
90
+ const selected = api.plan(review.grant.catalog, review.host, selection());
91
+ if (!selected.eligible) { notice = "Adjust the service selection to meet the capacity checks."; draw(); return; }
92
+ const confirmed = review;
93
+ void act("Preparing enrollment…", async () => {
94
+ try { job = await api.apply(confirmed, selection(), stage => { busy = stage; draw(); }) as Job; }
95
+ finally {
96
+ // A failed request may have committed the claim. Consult the saved
97
+ // identity before offering another plan or consuming a different key.
98
+ const saved = await api.savedEnrollment();
99
+ enrolled = !!saved; awaitingKey = !!saved?.pendingClaim;
100
+ if (saved) { review = undefined; setMode(awaitingKey ? "key" : "status"); }
101
+ }
102
+ review = undefined; enrolled = true; setMode("status");
103
+ });
104
+ } else if (mode === "revoke") {
105
+ if (!/^[a-z][a-z0-9-]{0,31}$/.test(input)) { notice = "Enter the node name to revoke its unused key."; draw(); return; }
106
+ const name = input;
107
+ void act("Revoking the unused key…", async () => {
108
+ const result = await api.revoke(name);
109
+ if (issued?.node === name) issued = undefined;
110
+ setMode("home");
111
+ notice = result.revoked ? `Unused key revoked for ${name}.` : `No unused key was found for ${name}.`;
112
+ });
113
+ }
114
+ }
115
+
116
+ function copy() {
117
+ if (!issued || issued.expiresAt <= Date.now()) return;
118
+ notice = clipboard(issued.key) ? "Copy sent to your terminal clipboard." : "Clipboard unavailable here. Use Reveal to copy the key.";
119
+ draw();
120
+ }
121
+
122
+ function continueSync() {
123
+ void act("Checking the saved enrollment…", async () => {
124
+ job = await api.resume(stage => { busy = stage; draw(); });
125
+ });
126
+ }
127
+
128
+ function cancel() {
129
+ review = undefined; issued = undefined; reveal = false; choices.clear();
130
+ setMode("home");
131
+ }
132
+
133
+ const typing = () => ["name", "key", "revoke"].includes(mode);
134
+ function paste(value: string) {
135
+ if (busy || !typing()) return;
136
+ input = (input + value.trim().replace(/[^a-zA-Z0-9_.:-]/g, "")).slice(0, mode === "key" ? 180 : 32);
137
+ draw();
138
+ }
139
+
140
+ function profiles(): Profile[] { return mode === "allow" ? authority ?? [] : review?.services ?? []; }
141
+ function toggle(id: string) {
142
+ if (busy || review?.saved) return;
143
+ if (choices.has(id)) choices.delete(id); else choices.add(id);
144
+ draw();
145
+ }
146
+
147
+ function keypress(key: KeyEvent): boolean {
148
+ const name = key.name;
149
+ if (name === "escape" && mode !== "home") { if (!busy) cancel(); return true; }
150
+ if (busy) return name !== "q";
151
+ if (typing()) {
152
+ if (name === "return") submit();
153
+ else if (name === "backspace") { input = input.slice(0, -1); draw(); }
154
+ else if (!key.ctrl && !key.meta && /^[a-zA-Z0-9_.:-]$/.test(key.sequence)) paste(key.sequence);
155
+ else return !["tab", "pageup", "pagedown"].includes(name);
156
+ return true;
157
+ }
158
+ if (mode === "allow" || mode === "choose") {
159
+ const allowed = profiles();
160
+ if (name === "up" || name === "down") {
161
+ cursor = Math.max(0, Math.min(allowed.length - 1, cursor + (name === "up" ? -1 : 1))); draw();
162
+ } else if (name === "space") { if (allowed[cursor]) toggle(allowed[cursor].id); }
163
+ else if (name === "return") submit();
164
+ else if (mode === "allow" && name === "a") { choices.clear(); draw(); }
165
+ else return false;
166
+ return true;
167
+ }
168
+ if (mode === "issued" && name === "c") { copy(); return true; }
169
+ if (mode === "issued" && name === "v") { reveal = !reveal; draw(); return true; }
170
+ if (mode === "status" && name === "s") { continueSync(); return true; }
171
+ if (mode === "home" && name === "g" && authority) { setMode("name"); return true; }
172
+ if (mode === "home" && name === "x" && authority) { setMode("revoke"); return true; }
173
+ if (mode === "home" && name === "e" && (!mesh || awaitingKey) && (!enrolled || awaitingKey)) { setMode("key"); return true; }
174
+ if (mode === "home" && name === "s" && enrolled) { showStatus(); return true; }
175
+ return false;
176
+ }
177
+
178
+ function view(width: number): { title: string; lines: Line[] } {
179
+ const lines: Line[] = [];
180
+ const add = (text: string, tone?: Line["tone"]) => lines.push({ text, tone });
181
+ const button = (text: string, action: () => void) => lines.push({ text, action: () => { if (!busy) action(); }, tone: "action" });
182
+ let title = "ENROLLMENT";
183
+ if (mode === "home") {
184
+ add(authority ? "Key issuer · Primary · connected" : "Key issuer · Primary");
185
+ if (authority) {
186
+ button("[G] Create sync key", () => setMode("name"));
187
+ button("[X] Revoke unused key", () => setMode("revoke"));
188
+ } else if (mesh && !enrolled) add("Create a key on Primary or under Enrollment in the site admin.", "muted");
189
+ if ((!mesh || awaitingKey) && (!enrolled || awaitingKey)) button("[E] Enroll this node", () => setMode("key"));
190
+ if (enrolled) button("[S] View enrollment status", showStatus);
191
+ } else if (typing()) {
192
+ title = mode === "key" ? "ENROLL THIS NODE" : mode === "name" ? "CREATE SYNC KEY" : "REVOKE UNUSED KEY";
193
+ add(mode === "key" ? "Paste a sync key from Primary or the site admin." : "Node name");
194
+ add("› " + (mode === "key" && input ? "●".repeat(Math.min(24, input.length)) : input) + "▏");
195
+ button(mode === "name" ? "[Enter] Choose key permissions" : mode === "key" ? "[Enter] Check sync key" : "[Enter] Revoke unused key", submit);
196
+ } else if (mode === "allow" || mode === "choose") {
197
+ title = mode === "allow" ? "ALLOW SERVICES" : "CHOOSE SERVICES TO INSTALL";
198
+ add(`Node · ${safe(mode === "allow" ? target : review?.grant.node)}`);
199
+ add(mode === "allow" ? "An empty selection allows all offered services." : "↑↓ Select · Space Toggle · Enter Confirm", "muted");
200
+ for (const [index, service] of profiles().entries()) {
201
+ const check = review && api.plan(review.grant.catalog, review.host, [service.id]);
202
+ button(`${index === cursor ? "›" : " "} [${choices.has(service.id) ? "x" : " "}] ${safe(service.label)}${check ? check.eligible ? " · Ready" : " · Check capacity" : ""}`, () => { cursor = index; toggle(service.id); });
203
+ }
204
+ if (mode === "allow") button("[A] Allow all offered services", () => { choices.clear(); draw(); });
205
+ if (mode === "choose" && review && choices.size) {
206
+ const result = api.plan(review.grant.catalog, review.host, selection());
207
+ add(`Plan · ${result.requiredCpu} threads · ${gib(result.requiredMemory)} memory`);
208
+ for (const disk of result.disks) add(`${gib(disk.peakBytes)} peak + ${gib(disk.reserveBytes)} reserve · ${gib(disk.availableBytes)} free`, "muted");
209
+ for (const error of result.errors) add(safe(error));
210
+ }
211
+ button(mode === "allow" ? "[Enter] Create sync key" : "[Enter] Confirm and start enrollment", submit);
212
+ } else if (mode === "issued" && issued) {
213
+ title = "SYNC KEY CREATED";
214
+ add(`Node · ${safe(issued.node)}`);
215
+ add(`Expires · ${new Date(issued.expiresAt).toISOString().slice(11, 16)} UTC`);
216
+ if (issued.expiresAt <= Date.now()) add("This key has expired.");
217
+ else {
218
+ button("[C] Copy sync key", copy);
219
+ button(reveal ? "[V] Hide sync key" : "[V] Reveal sync key", () => { reveal = !reveal; draw(); });
220
+ if (reveal) {
221
+ const key = safe(issued.key), columns = Math.max(16, width - 10);
222
+ for (let offset = 0; offset < key.length; offset += columns) add(key.slice(offset, offset + columns));
223
+ }
224
+ }
225
+ } else if (mode === "status") {
226
+ title = "ENROLLMENT STATUS";
227
+ if (job) {
228
+ add(`${safe(job.node)} · ${safe(phaseLabels[job.phase] ?? job.phase)}`);
229
+ if (job.endpoint) add(safe(job.endpoint), "muted");
230
+ for (const service of job.services ?? []) add(typeof service === "string" ? safe(service) : `${safe(service.id)} · ${safe(service.phase)}`);
231
+ if (job.message) add(safe(job.message), "muted");
232
+ }
233
+ if (!job || ["failed", "authorized", "registered", "tunnel-issued"].includes(job.phase)) button("[S] Resume enrollment", continueSync);
234
+ }
235
+ if (host && ["home", "key", "choose", "status"].includes(mode)) {
236
+ add(`Local capacity · ${host.os} ${host.architecture} · ${host.cpu} threads · ${gib(host.memoryBytes)} free memory`, "muted");
237
+ for (const mount of Object.values(host.mounts)) {
238
+ add(`${mount.path} · ${mount.percentUsed === null ? "Usage unknown" : mount.percentUsed + "% used"} · ${gib(mount.bytes)} available`, "muted");
239
+ }
240
+ }
241
+ if (mode !== "home") button("[Esc] Back", cancel);
242
+ if (busy || notice) add(busy || notice);
243
+ return { title, lines };
244
+ }
245
+
246
+ return { refresh, view, keypress, paste, clearSecret() { issued = undefined; input = ""; review = undefined; if (mode === "issued" || mode === "choose") mode = "home"; },
247
+ poll() { if (mode === "status" && !busy) void act("Checking sync progress…", async () => { job = await api.status(); }); },
248
+ };
249
+ }
package/src/index.ts CHANGED
@@ -3,22 +3,27 @@ import type { CliRenderer } from "@opentui/core";
3
3
  import { mapsourcePalette } from "./palette.ts";
4
4
  import { nodeInterface } from "./interface.ts";
5
5
  import { readTelemetry } from "./telemetry.ts";
6
+ import { hasMesh } from "./commands.mjs";
6
7
 
7
8
  const version = process.env.MAPSOURCE_NODE_BUILD ?? "development";
8
9
  const usage = "Mapsource Admin\n\n mapsource-node Open the terminal dashboard\n mapsource-node --json Print one read-only telemetry snapshot\n mapsource-node --version Print the installed release\n";
9
10
  const [arg, ...remaining] = process.argv.slice(2);
10
11
 
11
12
  function bindKeys(renderer: CliRenderer, ui: ReturnType<typeof nodeInterface>, refresh: () => void) {
13
+ renderer.keyInput.on("paste", event => {
14
+ if (ui.tab() === 3) { event.preventDefault(); ui.enrollment.paste(new TextDecoder().decode(event.bytes)); }
15
+ });
12
16
  renderer.keyInput.on("keypress", key => {
17
+ if (ui.tab() === 3 && ui.enrollment.keypress(key)) { key.preventDefault(); return; }
13
18
  if (key.name === "q" || key.name === "escape") renderer.destroy();
14
- else if (key.name === "r") refresh();
19
+ else if (key.name === "r") { if (ui.tab() === 3) void ui.enrollment.refresh(); else refresh(); }
15
20
  else if (key.name === "left") ui.navigate(ui.tab() - 1);
16
21
  else if (key.name === "right" || key.name === "tab") ui.navigate(ui.tab() + 1);
17
22
  else if (key.name === "up") ui.scroll(-1);
18
23
  else if (key.name === "down") ui.scroll(1);
19
24
  else if (key.name === "pageup") ui.scroll(-10);
20
25
  else if (key.name === "pagedown") ui.scroll(10);
21
- else if (["1", "2", "3"].includes(key.name)) ui.navigate(Number(key.name) - 1);
26
+ else if (["1", "2", "3", "4"].includes(key.name)) ui.navigate(Number(key.name) - 1);
22
27
  });
23
28
  }
24
29
 
@@ -42,6 +47,7 @@ async function launch() {
42
47
  const timer = setInterval(() => void refresh(), 5000);
43
48
  renderer.once("destroy", () => { closed = true; clearInterval(timer); });
44
49
  ui.paint();
50
+ if (!await hasMesh()) ui.navigate(3);
45
51
  void refresh();
46
52
  }
47
53
 
@@ -62,8 +68,10 @@ else if (arg === "--self-test" && !remaining.length) {
62
68
  mockInput.pressArrow("right");
63
69
  await renderOnce();
64
70
  if (view.tab() !== 2 || !captureCharFrame().includes("Q Quit")) throw new Error("OpenTUI navigation verification failed");
65
- console.log("mapsource-node self-test " + version);
66
71
  } finally { renderer.destroy(); }
72
+ const { testEnrollmentScreen } = await import("./enrollment-screen-test.ts");
73
+ await testEnrollmentScreen(bindKeys, createTestRenderer);
74
+ console.log("mapsource-node self-test " + version);
67
75
  } else if (arg !== undefined || !process.stdin.isTTY || !process.stdout.isTTY) {
68
76
  process.stderr.write(arg === undefined ? "A terminal is required. SSH with -t or use mapsource-node --json.\n" : usage);
69
77
  process.exitCode = 2;
package/src/interface.ts CHANGED
@@ -2,9 +2,10 @@ import { BoxRenderable, ScrollBoxRenderable, TextAttributes, TextRenderable } fr
2
2
  import type { CliRenderer, RenderContext } from "@opentui/core";
3
3
  import { mapsourcePalette as palette } from "./palette.ts";
4
4
  import type { Telemetry } from "./telemetry.ts";
5
+ import { enrollmentScreen, type enrollmentActions } from "./enrollment-screen.ts";
5
6
 
6
- const tabs = ["Overview", "Fleet", "Services"] as const;
7
- const compactTabs = ["Node", "Fleet", "Svc"] as const;
7
+ const tabs = ["Overview", "Fleet", "Services", "Enrollment"] as const;
8
+ const compactTabs = ["Node", "Fleet", "Svc", "Enroll"] as const;
8
9
  const good = palette.focus, muted = palette.muted, amber = "#eac684", red = "#ef9990";
9
10
  const dash = "—";
10
11
  const percent = (value: number | null | undefined) => value == null ? dash : value.toFixed(1) + "%";
@@ -26,8 +27,11 @@ const stateColor = (state: string) => {
26
27
  return value.includes("unavailable") ? red : amber;
27
28
  };
28
29
 
29
- export function nodeInterface(renderer: CliRenderer, version: string) {
30
+ export function nodeInterface(renderer: CliRenderer, version: string, actions?: typeof enrollmentActions) {
30
31
  let selected = 0, snapshot: Telemetry | null = null;
32
+ let closed = false;
33
+ renderer.once("destroy", () => { closed = true; });
34
+ const enrollment = enrollmentScreen(() => { if (selected === 3 && !closed) paint(); }, value => renderer.copyToClipboardOSC52(value), actions);
31
35
  const history = new Map<string, { latency: (number | null)[]; queued: (number | null)[] }>();
32
36
  // OpenTUI's renderer getter types omit undefined on optional context fields.
33
37
  const context = renderer as unknown as RenderContext;
@@ -42,7 +46,7 @@ export function nodeInterface(renderer: CliRenderer, version: string) {
42
46
  header.add(heading);
43
47
  const navigation = box({ flexDirection: "row", height: 2, flexShrink: 0, gap: 1, paddingX: 1 });
44
48
  const navText = tabs.map((tab, index) => text(` ${index + 1} ${tab} `, muted, false, { width: tab.length + 4 }));
45
- navText.forEach(item => navigation.add(item));
49
+ navText.forEach((item, index) => { item.onMouseUp = () => navigate(index); navigation.add(item); });
46
50
  const viewport = new ScrollBoxRenderable(context, {
47
51
  flexGrow: 1, flexShrink: 1, minHeight: 0, scrollX: false, scrollY: true, viewportCulling: true,
48
52
  contentOptions: { paddingX: 1, paddingBottom: 1 },
@@ -130,11 +134,6 @@ export function nodeInterface(renderer: CliRenderer, version: string) {
130
134
  for (const service of data.services) row(local, service.name, service.state, stateColor(service.state));
131
135
  if (!data.services.length) local.add(text("Controller telemetry unavailable.", amber));
132
136
  viewport.add(local);
133
- const tools = panel("ENROLLMENT");
134
- tools.add(text("Run mapsource-node services to list profiles.", muted));
135
- tools.add(text("Run mapsource-node invite to create a sync key.", muted));
136
- tools.add(text("Run mapsource-node status for enrollment progress.", muted));
137
- viewport.add(tools);
138
137
  }
139
138
 
140
139
  function paint() {
@@ -142,21 +141,43 @@ export function nodeInterface(renderer: CliRenderer, version: string) {
142
141
  for (const child of viewport.getChildren()) child.destroyRecursively();
143
142
  heading.content = snapshot ? `MAPSOURCE ADMIN / ${snapshot.node.toUpperCase()}` : "MAPSOURCE ADMIN";
144
143
  navText.forEach((item, index) => {
145
- const name = (renderer.width < 42 ? compactTabs : tabs)[index] ?? "";
144
+ const name = (renderer.width < 58 ? compactTabs : tabs)[index] ?? "";
146
145
  item.content = ` ${index + 1} ${name} `;
147
146
  item.width = name.length + 4;
148
147
  item.fg = index === selected ? palette.ink : muted;
149
148
  item.bg = index === selected ? good : palette.ink;
150
149
  });
151
- keys.content = renderer.width < 65 ? "1–3 View · ↑↓ Scroll · R Refresh · Q Quit" :
152
- `1–3 / ← → View ↑ ↓ Scroll R Refresh Q Quit · ${version.slice(0, 12)}`;
153
- if (!snapshot) viewport.add(text("Reading node, fleet, and public status…", muted));
150
+ keys.content = renderer.width < 65 ? "1–4 View · ↑↓ Scroll · R Refresh · Q Quit" :
151
+ `1–4 / ← → View ↑ ↓ Scroll R Refresh Q Quit · ${version.slice(0, 12)}`;
152
+ if (selected === 3) {
153
+ const view = enrollment.view(renderer.width);
154
+ const section = panel(view.title);
155
+ for (const line of view.lines) {
156
+ // Standard wrapping keeps endpoint names and capacity explanations
157
+ // readable on a narrow terminal or SSH window.
158
+ const entry = new TextRenderable(context, { content: line.text,
159
+ fg: line.tone === "action" ? good : line.tone === "muted" ? muted : palette.paper,
160
+ wrapMode: "char", flexShrink: 0, ...(line.action && { onMouseUp: line.action }) });
161
+ section.add(entry);
162
+ }
163
+ viewport.add(section);
164
+ } else if (!snapshot) viewport.add(text("Reading node, fleet, and public status…", muted));
154
165
  else if (selected === 0) overview(snapshot);
155
166
  else if (selected === 1) fleet(snapshot);
156
167
  else services(snapshot);
157
168
  viewport.scrollTop = oldOffset;
158
169
  }
159
170
 
171
+ function navigate(next: number) {
172
+ const tab = (next + tabs.length) % tabs.length;
173
+ if (tab === selected) return;
174
+ if (selected === 3) enrollment.clearSecret();
175
+ selected = tab;
176
+ viewport.scrollTop = 0;
177
+ paint();
178
+ if (selected === 3) void enrollment.refresh();
179
+ }
180
+
160
181
  return {
161
182
  paint,
162
183
  update(data: Telemetry) {
@@ -168,13 +189,10 @@ export function nodeInterface(renderer: CliRenderer, version: string) {
168
189
  if (series.latency.length > 30) { series.latency.shift(); series.queued.shift(); }
169
190
  history.set(engine.name, series);
170
191
  }
171
- paint();
172
- },
173
- navigate(next: number) {
174
- selected = (next + tabs.length) % tabs.length;
175
- viewport.scrollTop = 0;
176
- paint();
192
+ if (selected === 3) enrollment.poll(); else paint();
177
193
  },
194
+ navigate,
195
+ enrollment,
178
196
  tab: () => selected,
179
197
  scroll(lines: number) { viewport.scrollBy(lines); },
180
198
  };