@feigi/fleet-ctl 3.107.0 → 3.109.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/board.html +130 -17
- package/scripts/label-map.mjs +182 -0
package/package.json
CHANGED
package/scripts/board.html
CHANGED
|
@@ -8,12 +8,13 @@
|
|
|
8
8
|
:root { color-scheme: dark; --bg:#0d1117; --panel:#161b22; --line:#30363d;
|
|
9
9
|
--fg:#e6edf3; --dim:#8b949e; --red:#f85149; --amber:#d29922; --green:#3fb950; --blue:#58a6ff; }
|
|
10
10
|
* { box-sizing: border-box; }
|
|
11
|
-
/* The page is the window's height: header, banner, attention strip,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
columns to nothing or
|
|
11
|
+
/* The page is the window's height: header, banner, attention strip, the tab
|
|
12
|
+
strip and footer keep their natural height and never shrink; the open
|
|
13
|
+
tab's pane (#board or #spend, the other is hidden) takes the rest, and
|
|
14
|
+
each board column scrolls on its own past that. The panes' min-height is
|
|
15
|
+
the floor for a window too short for the fixed parts — they then overflow
|
|
16
|
+
body and the PAGE scrolls, rather than squeezing the columns to nothing or
|
|
17
|
+
clipping anything off. */
|
|
17
18
|
body { margin:0; background:var(--bg); color:var(--fg);
|
|
18
19
|
font:14px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;
|
|
19
20
|
height:100vh; display:flex; flex-direction:column; }
|
|
@@ -32,7 +33,8 @@
|
|
|
32
33
|
#stale-banner.dead { background:var(--red); color:#fff; }
|
|
33
34
|
#attention { padding:8px 16px; border-bottom:1px solid var(--line); background:#2d1618; }
|
|
34
35
|
#attention:empty { display:none; }
|
|
35
|
-
.att { display:inline-block; margin:2px 10px 2px 0; }
|
|
36
|
+
.att { display:inline-block; margin:2px 10px 2px 0; color:inherit; text-decoration:none; }
|
|
37
|
+
.att:hover { text-decoration:underline; }
|
|
36
38
|
.att .n { color:var(--blue); font-weight:600; }
|
|
37
39
|
.flag { color:var(--red); font-weight:600; }
|
|
38
40
|
#board { display:grid; grid-template-columns:repeat(5,1fr); grid-template-rows:minmax(0,1fr); gap:10px; padding:14px; align-items:start;
|
|
@@ -59,9 +61,19 @@
|
|
|
59
61
|
.badge { border:1px solid var(--line); border-radius:10px; padding:0 6px; }
|
|
60
62
|
.badge.flag { border-color:var(--red); color:var(--red); }
|
|
61
63
|
footer { color:var(--dim); padding:10px 16px; border-top:1px solid var(--line); font-size:12px; }
|
|
64
|
+
/* A pane carries its own display (grid, block), which would beat the UA's
|
|
65
|
+
[hidden] rule; the closed tab's pane must stay closed. */
|
|
66
|
+
[hidden] { display:none !important; }
|
|
67
|
+
#tabs { display:flex; gap:4px; padding:8px 14px 0; border-bottom:1px solid var(--line); }
|
|
68
|
+
#tabs a { color:var(--dim); text-decoration:none; padding:5px 14px; border:1px solid transparent; border-bottom:0;
|
|
69
|
+
border-radius:6px 6px 0 0; margin-bottom:-1px; }
|
|
70
|
+
#tabs a:hover { color:var(--fg); }
|
|
71
|
+
#tabs a.on { color:var(--fg); background:var(--bg); border-color:var(--line); }
|
|
72
|
+
/* A hash link's target flashes once on arrival. The duration is FLASH_MS in the script. */
|
|
73
|
+
.card.flash { animation:flash 1.2s ease-out 1; }
|
|
74
|
+
@keyframes flash { from { box-shadow:0 0 0 2px var(--blue); background:#12233a; } to { box-shadow:0 0 0 2px transparent; } }
|
|
62
75
|
footer .filed { margin-top:4px; }
|
|
63
|
-
#spend { padding:0
|
|
64
|
-
#spend:empty { display:none; }
|
|
76
|
+
#spend { padding:14px; flex:1 1 0; min-height:200px; overflow-y:auto; }
|
|
65
77
|
.spend-wrap { background:var(--panel); border:1px solid var(--line); border-radius:8px; padding:10px 12px; }
|
|
66
78
|
.spend-hd { display:flex; align-items:baseline; gap:10px; margin-bottom:8px; }
|
|
67
79
|
.spend-hd h2 { font-size:11px; letter-spacing:.06em; color:var(--dim); margin:0; text-transform:uppercase; }
|
|
@@ -83,8 +95,9 @@
|
|
|
83
95
|
<header><h1 id="heading">🛰 fleet cockpit</h1><span id="age"></span></header>
|
|
84
96
|
<div id="stale-banner"></div>
|
|
85
97
|
<div id="attention"></div>
|
|
98
|
+
<nav id="tabs"><a id="tab-board" class="on" href="#board" aria-current="page">Board</a><a id="tab-tokens" href="#tokens">Tokens</a></nav>
|
|
86
99
|
<div id="board"></div>
|
|
87
|
-
<div id="spend"></div>
|
|
100
|
+
<div id="spend" hidden></div>
|
|
88
101
|
<footer id="footer"></footer>
|
|
89
102
|
<script>
|
|
90
103
|
const COLUMNS = ["POOL", "IMPLEMENTING", "REVIEW", "READY", "MERGED"];
|
|
@@ -110,6 +123,37 @@ let repoUrl = null; // full repo URL from the model (carries the host) — PR li
|
|
|
110
123
|
const TITLE = "fleet cockpit";
|
|
111
124
|
function boardTitle(repo) { return repo ? `${TITLE} — ${repo}` : TITLE; }
|
|
112
125
|
|
|
126
|
+
// Where a URL hash lands: which tab is open, and which card (an issue number,
|
|
127
|
+
// as a string) to bring into view on it. The router's whole decision, as a
|
|
128
|
+
// value with no DOM or location touched, so it is liftable out of the source
|
|
129
|
+
// the way spendView is. It closes over nothing, for the same reason.
|
|
130
|
+
//
|
|
131
|
+
// Every hash the page draws is a tab (`#board`, `#tokens`) or a card on the
|
|
132
|
+
// Board (`#board/<issue>`). Anything else — no hash, a tab the page does not
|
|
133
|
+
// have, a target the tab does not have — lands on Board's top, or the named
|
|
134
|
+
// tab's top, never on a blank page and never on an error.
|
|
135
|
+
function routeHash(hash) {
|
|
136
|
+
const [tab, target, ...more] = String(hash).replace(/^#/, "").split("/");
|
|
137
|
+
if (tab === "board") return { tab, target: more.length === 0 && /^[1-9]\d*$/.test(target) ? target : null };
|
|
138
|
+
if (tab === "tokens") return { tab, target: null };
|
|
139
|
+
return { tab: "board", target: null };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Each tab, and the pane it opens.
|
|
143
|
+
const PANES = { board: "board", tokens: "spend" };
|
|
144
|
+
|
|
145
|
+
// Which card is still owed a scroll. The cards are rebuilt every tick, so a
|
|
146
|
+
// hash that arrives before the first render (a reload, a pasted link) cannot
|
|
147
|
+
// scroll yet: it waits here for the render.
|
|
148
|
+
let rendered = false;
|
|
149
|
+
let pending = null;
|
|
150
|
+
|
|
151
|
+
// The card flashing now, and when it started. A tick rebuilds every card, so
|
|
152
|
+
// the flash lives here rather than on a node the next tick throws away.
|
|
153
|
+
// FLASH_MS is `.card.flash`'s animation duration.
|
|
154
|
+
const FLASH_MS = 1200;
|
|
155
|
+
let flashing = null;
|
|
156
|
+
|
|
113
157
|
const el = (t, cls, txt) => { const e = document.createElement(t); if (cls) e.className = cls; if (txt != null) e.textContent = txt; return e; };
|
|
114
158
|
const mins = (ms) => Math.floor((Date.now() - ms) / 60000);
|
|
115
159
|
|
|
@@ -236,14 +280,14 @@ function renderSpend(sp) {
|
|
|
236
280
|
|
|
237
281
|
const wrap = el("div", "spend-wrap");
|
|
238
282
|
const hd = el("div", "spend-hd");
|
|
239
|
-
hd.append(el("h2", null, "
|
|
283
|
+
hd.append(el("h2", null, "tokens"));
|
|
240
284
|
hd.append(el("span", "lede", v.lede));
|
|
241
285
|
hd.append(el("span", "note", v.note));
|
|
242
286
|
wrap.append(hd);
|
|
243
287
|
|
|
244
288
|
const cols = el("div", "spend-cols");
|
|
245
289
|
const byRole = el("div");
|
|
246
|
-
byRole.append(el("h3", null, "by role"));
|
|
290
|
+
byRole.append(el("h3", null, "by member role"));
|
|
247
291
|
spendRows(byRole, v.roles, {
|
|
248
292
|
label: (r) => `${r.role} ×${r.agents}`,
|
|
249
293
|
value: (r) => k(r.cacheWrite),
|
|
@@ -285,10 +329,12 @@ function render(m) {
|
|
|
285
329
|
const att = document.getElementById("attention");
|
|
286
330
|
att.innerHTML = "";
|
|
287
331
|
for (const t of m.attention || []) {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
332
|
+
// A link into the Board, never a new window: the hash carries the card.
|
|
333
|
+
const a = el("a", "att");
|
|
334
|
+
a.href = "#board/" + t.issue;
|
|
335
|
+
a.append(el("span", "n", "#" + t.issue), document.createTextNode(" "));
|
|
336
|
+
a.append(el("span", "flag", (t.flags || []).join(" ")));
|
|
337
|
+
att.append(a);
|
|
292
338
|
}
|
|
293
339
|
// columns — each built once and kept, its contents rewritten every tick.
|
|
294
340
|
// A column scrolls on its own and a scroll offset lives on
|
|
@@ -374,6 +420,12 @@ function render(m) {
|
|
|
374
420
|
} else if (capMsg) {
|
|
375
421
|
showBanner(capMsg);
|
|
376
422
|
} else { banner.style.display = "none"; banner.className = ""; }
|
|
423
|
+
// Last, once the banner and footer have taken their place in the layout, so
|
|
424
|
+
// a card scrolled to is scrolled to where it will stay.
|
|
425
|
+
rendered = true;
|
|
426
|
+
// Its own catch: the board above is already written, so a failed scroll is
|
|
427
|
+
// not a failed render.
|
|
428
|
+
try { settle(); } catch (e) { warn("⚠ scroll to card failed: " + e.message); }
|
|
377
429
|
}
|
|
378
430
|
|
|
379
431
|
// The heartbeat's mark, rendered. A dead run's tickets keep the label
|
|
@@ -421,6 +473,7 @@ function ledgerBanner(state) {
|
|
|
421
473
|
|
|
422
474
|
function card(t) {
|
|
423
475
|
const c = el("div", "card");
|
|
476
|
+
c.id = "card-" + t.issue;
|
|
424
477
|
const top = el("div", "top");
|
|
425
478
|
top.append(el("span", "n", "#" + t.issue));
|
|
426
479
|
top.append(el("span", "title", t.title || ""));
|
|
@@ -438,6 +491,9 @@ function card(t) {
|
|
|
438
491
|
for (const f of t.flags || []) meta.append(el("span", "badge flag", f));
|
|
439
492
|
if (t.ruling) meta.append(el("span", "badge", "ruled:" + t.ruling));
|
|
440
493
|
c.append(meta);
|
|
494
|
+
// A card rebuilt mid-flash picks the flash up where it was, not from the start.
|
|
495
|
+
const age = flashing && flashing.issue === String(t.issue) ? Date.now() - flashing.at : Infinity;
|
|
496
|
+
if (age < FLASH_MS) flash(c, age);
|
|
441
497
|
return c;
|
|
442
498
|
}
|
|
443
499
|
|
|
@@ -454,6 +510,49 @@ function warn(msg) {
|
|
|
454
510
|
showBanner(msg);
|
|
455
511
|
}
|
|
456
512
|
|
|
513
|
+
// Opens the tab the hash names and settles the card it targets. The two
|
|
514
|
+
// panes stay in the page either way, so a tick keeps filling both.
|
|
515
|
+
function applyHash() {
|
|
516
|
+
const r = routeHash(location.hash);
|
|
517
|
+
for (const [t, pane] of Object.entries(PANES)) {
|
|
518
|
+
const on = t === r.tab;
|
|
519
|
+
document.getElementById(pane).hidden = !on;
|
|
520
|
+
const a = document.getElementById("tab-" + t);
|
|
521
|
+
a.classList.toggle("on", on);
|
|
522
|
+
if (on) a.setAttribute("aria-current", "page"); else a.removeAttribute("aria-current");
|
|
523
|
+
}
|
|
524
|
+
pending = r;
|
|
525
|
+
settle();
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
// The arrival: the target card scrolls into view and flashes once; no target,
|
|
529
|
+
// or a target no card on the board carries, lands on the tab's top. Taken
|
|
530
|
+
// off `pending` first, so a later tick never scrolls the page again; nothing
|
|
531
|
+
// settles before the first render.
|
|
532
|
+
function settle() {
|
|
533
|
+
if (!pending || !rendered) return;
|
|
534
|
+
const { target } = pending;
|
|
535
|
+
pending = null;
|
|
536
|
+
const hit = target && document.getElementById("card-" + target);
|
|
537
|
+
if (!hit) {
|
|
538
|
+
window.scrollTo(0, 0);
|
|
539
|
+
document.getElementById("spend").scrollTop = 0;
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
hit.scrollIntoView({ block: "center" });
|
|
543
|
+
flashing = { issue: target, at: Date.now() };
|
|
544
|
+
flash(hit, 0);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// Runs the flash on a card `age` ms into it.
|
|
548
|
+
function flash(node, age) {
|
|
549
|
+
node.classList.remove("flash");
|
|
550
|
+
void node.offsetWidth; // restart the animation when the same card is targeted again
|
|
551
|
+
node.style.animationDelay = -age + "ms";
|
|
552
|
+
node.classList.add("flash");
|
|
553
|
+
node.addEventListener("animationend", () => node.classList.remove("flash"), { once: true });
|
|
554
|
+
}
|
|
555
|
+
|
|
457
556
|
async function poll() {
|
|
458
557
|
let r;
|
|
459
558
|
try {
|
|
@@ -473,7 +572,21 @@ async function poll() {
|
|
|
473
572
|
}
|
|
474
573
|
setTimeout(poll, interval * 1000);
|
|
475
574
|
}
|
|
476
|
-
|
|
575
|
+
|
|
576
|
+
// Clicking the link to the hash already open fires no hashchange, so the
|
|
577
|
+
// click is routed to applyHash by hand: a card scrolled away from can be
|
|
578
|
+
// brought back by the same link.
|
|
579
|
+
function boot() {
|
|
580
|
+
window.addEventListener("hashchange", applyHash);
|
|
581
|
+
document.addEventListener("click", (e) => {
|
|
582
|
+
if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
|
|
583
|
+
const a = e.target.closest?.('a[href^="#"]');
|
|
584
|
+
if (a && a.getAttribute("href") === location.hash) { e.preventDefault(); applyHash(); }
|
|
585
|
+
});
|
|
586
|
+
applyHash();
|
|
587
|
+
poll();
|
|
588
|
+
}
|
|
589
|
+
boot();
|
|
477
590
|
</script>
|
|
478
591
|
</body>
|
|
479
592
|
</html>
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The Label map: the string the consumer's tracker uses for each Label role.
|
|
3
|
+
// This module owns the map's cache format — the file, its validity rules, the
|
|
4
|
+
// writer and the reader every role-reading script imports — and the `show`
|
|
5
|
+
// verb. It derives nothing: the derivation step is `ensure`, which is not
|
|
6
|
+
// here yet, so every refusal below names it as the step that writes the map.
|
|
7
|
+
//
|
|
8
|
+
// THE CACHE is `.fleet/labels.json`, resolved through fleet-dir.mjs's
|
|
9
|
+
// fleetFile() like the pre-flight marker, so a member in its own worktree and
|
|
10
|
+
// the controller in the main checkout name one file. `.fleet/` is gitignored,
|
|
11
|
+
// so the file is never committed, and it is never written by hand. Content:
|
|
12
|
+
// derivedAt ISO time of the derivation that wrote it
|
|
13
|
+
// table what the triage-label table said then: { present, rows: {role: string} }
|
|
14
|
+
// roles every Label role -> the string the tracker uses
|
|
15
|
+
// origin every Label role -> "table" | "default" | "maintainer"
|
|
16
|
+
//
|
|
17
|
+
// VALID STRINGS (labelStringFaults): non-empty after trimming, at most 50
|
|
18
|
+
// characters, no `"` and no `\`, and no two roles mapping to one string,
|
|
19
|
+
// compared ignoring case.
|
|
20
|
+
//
|
|
21
|
+
// THE READER (readLabelMap) returns `roles` when the cache parses, holds every
|
|
22
|
+
// Label role and passes the string rules; anything else throws
|
|
23
|
+
// LabelMapUnreadable. It never reads the tracker's live label list and has no
|
|
24
|
+
// defaults: an absent or broken map is a refusal, never a guess.
|
|
25
|
+
//
|
|
26
|
+
// THE WRITER (writeLabelMap) writes the whole cache to a temp file beside the
|
|
27
|
+
// target and renames it over the target, so a reader never sees half of it.
|
|
28
|
+
// It writes what it is handed: checking the map is its caller's step.
|
|
29
|
+
//
|
|
30
|
+
// CLI:
|
|
31
|
+
// label-map.mjs show [<role>] the mapped string for <role>, or the whole
|
|
32
|
+
// `roles` object as JSON with no role.
|
|
33
|
+
// Exit 0 printed; 1 no cache or an invalid one, the message naming `ensure`;
|
|
34
|
+
// 2 an unknown role, no repository, or a usage refusal (any other verb).
|
|
35
|
+
//
|
|
36
|
+
// Zero deps: node builtins and sibling scripts only.
|
|
37
|
+
|
|
38
|
+
import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
39
|
+
import { dirname } from "node:path";
|
|
40
|
+
import { isCLI } from "./is-cli.mjs";
|
|
41
|
+
import { makeDie, writeAll } from "./arg.mjs";
|
|
42
|
+
import { fleetFile, FleetDirUnresolvable } from "./fleet-dir.mjs";
|
|
43
|
+
|
|
44
|
+
const NAME = "label-map";
|
|
45
|
+
const die = makeDie(NAME);
|
|
46
|
+
const USAGE = "usage: label-map.mjs show [<role>]";
|
|
47
|
+
const MAX_LENGTH = 50;
|
|
48
|
+
const DERIVE = "run `label-map.mjs ensure`, the Label map derivation step";
|
|
49
|
+
|
|
50
|
+
export const LABEL_MAP_FILE = "labels.json";
|
|
51
|
+
|
|
52
|
+
export const LABEL_ROLES = Object.freeze([
|
|
53
|
+
"needs-triage",
|
|
54
|
+
"needs-info",
|
|
55
|
+
"ready-for-agent",
|
|
56
|
+
"ready-for-human",
|
|
57
|
+
"wontfix",
|
|
58
|
+
"in-progress",
|
|
59
|
+
"onhold",
|
|
60
|
+
"ready-to-merge",
|
|
61
|
+
]);
|
|
62
|
+
|
|
63
|
+
export class LabelMapUnreadable extends Error {
|
|
64
|
+
constructor(message) {
|
|
65
|
+
super(message);
|
|
66
|
+
this.name = "LabelMapUnreadable";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// The rule a single string breaks on its own, or null.
|
|
71
|
+
function stringFault(value) {
|
|
72
|
+
if (value === undefined) return "missing";
|
|
73
|
+
if (typeof value !== "string") return `not a string (${JSON.stringify(value)})`;
|
|
74
|
+
if (value.trim() === "") return "empty after trimming";
|
|
75
|
+
if (value.length > MAX_LENGTH) return `longer than ${MAX_LENGTH} characters (${value.length})`;
|
|
76
|
+
if (value.includes('"')) return 'contains `"`';
|
|
77
|
+
if (value.includes("\\")) return "contains `\\`";
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Every way `roles` (role -> string) breaks the Label map's string rules, as
|
|
83
|
+
* `[{ role, rule }]` in role order; empty when it breaks none. A role absent
|
|
84
|
+
* from `roles` is a fault too. Two roles mapping to one string, compared
|
|
85
|
+
* ignoring case, is reported once, on the later role, its rule naming the
|
|
86
|
+
* earlier one; a string that already breaks a rule on its own is not compared.
|
|
87
|
+
*/
|
|
88
|
+
export function labelStringFaults(roles) {
|
|
89
|
+
const faults = [];
|
|
90
|
+
const seen = new Map();
|
|
91
|
+
for (const role of LABEL_ROLES) {
|
|
92
|
+
const value = Object.hasOwn(roles, role) ? roles[role] : undefined;
|
|
93
|
+
const rule = stringFault(value);
|
|
94
|
+
if (rule) {
|
|
95
|
+
faults.push({ role, rule });
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const key = value.toLowerCase();
|
|
99
|
+
const first = seen.get(key);
|
|
100
|
+
if (first) faults.push({ role, rule: `maps to the same string as ${first} (${JSON.stringify(value)}), compared ignoring case` });
|
|
101
|
+
else seen.set(key, role);
|
|
102
|
+
}
|
|
103
|
+
return faults;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Write `map` ({ derivedAt, table, roles, origin }) as the cache of the
|
|
108
|
+
* repository `cwd` belongs to, through a temp file beside it, and return the
|
|
109
|
+
* cache's path. Throws FleetDirUnresolvable outside a repository, and the
|
|
110
|
+
* filesystem's own error when the file cannot be written.
|
|
111
|
+
*/
|
|
112
|
+
export function writeLabelMap(map, { cwd = process.cwd() } = {}) {
|
|
113
|
+
const file = fleetFile(LABEL_MAP_FILE, { cwd });
|
|
114
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
115
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
116
|
+
try {
|
|
117
|
+
writeFileSync(tmp, `${JSON.stringify(map)}\n`);
|
|
118
|
+
renameSync(tmp, file);
|
|
119
|
+
} catch (e) {
|
|
120
|
+
// The write's own error is the one to report: a temp file that cannot be
|
|
121
|
+
// removed (a directory in its place) must not replace it.
|
|
122
|
+
try { rmSync(tmp, { force: true }); } catch {}
|
|
123
|
+
throw e;
|
|
124
|
+
}
|
|
125
|
+
return file;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The `roles` object (every Label role -> its string) of the cache of the
|
|
130
|
+
* repository `cwd` belongs to. Throws LabelMapUnreadable, its message naming
|
|
131
|
+
* `ensure`, when the cache is absent, does not parse, lacks a role or breaks
|
|
132
|
+
* the string rules; throws FleetDirUnresolvable outside a repository.
|
|
133
|
+
*/
|
|
134
|
+
export function readLabelMap({ cwd = process.cwd() } = {}) {
|
|
135
|
+
const file = fleetFile(LABEL_MAP_FILE, { cwd });
|
|
136
|
+
let text;
|
|
137
|
+
try {
|
|
138
|
+
text = readFileSync(file, "utf8");
|
|
139
|
+
} catch (e) {
|
|
140
|
+
if (e.code === "ENOENT") throw new LabelMapUnreadable(`no Label map at ${file}: ${DERIVE}`);
|
|
141
|
+
throw new LabelMapUnreadable(`cannot read the Label map at ${file} (${e.code ?? e.message}): ${DERIVE}`);
|
|
142
|
+
}
|
|
143
|
+
let cache;
|
|
144
|
+
try {
|
|
145
|
+
cache = JSON.parse(text);
|
|
146
|
+
} catch (e) {
|
|
147
|
+
throw new LabelMapUnreadable(`the Label map at ${file} does not parse (${e.message}): ${DERIVE}`);
|
|
148
|
+
}
|
|
149
|
+
const roles = cache?.roles;
|
|
150
|
+
if (roles === null || typeof roles !== "object" || Array.isArray(roles)) {
|
|
151
|
+
throw new LabelMapUnreadable(`the Label map at ${file} holds no \`roles\` object: ${DERIVE}`);
|
|
152
|
+
}
|
|
153
|
+
const faults = labelStringFaults(roles);
|
|
154
|
+
if (faults.length) {
|
|
155
|
+
const why = faults.map(({ role, rule }) => `${role}: ${rule}`).join("; ");
|
|
156
|
+
throw new LabelMapUnreadable(`the Label map at ${file} is invalid — ${why}: ${DERIVE}`);
|
|
157
|
+
}
|
|
158
|
+
return Object.fromEntries(LABEL_ROLES.map((role) => [role, roles[role]]));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function main() {
|
|
162
|
+
const [verb, ...rest] = process.argv.slice(2);
|
|
163
|
+
if (verb !== "show") die(verb === undefined ? USAGE : `unknown verb ${JSON.stringify(verb)}; ${USAGE}`);
|
|
164
|
+
if (rest.length > 1) die(`show takes at most one role, got: ${rest.join(" ")}; ${USAGE}`);
|
|
165
|
+
const [role] = rest;
|
|
166
|
+
if (role !== undefined && !LABEL_ROLES.includes(role)) {
|
|
167
|
+
die(`unknown role ${JSON.stringify(role)}; the roles are ${LABEL_ROLES.join(", ")}`);
|
|
168
|
+
}
|
|
169
|
+
let roles;
|
|
170
|
+
try {
|
|
171
|
+
roles = readLabelMap();
|
|
172
|
+
} catch (e) {
|
|
173
|
+
if (e instanceof FleetDirUnresolvable) die(e.message);
|
|
174
|
+
if (!(e instanceof LabelMapUnreadable)) throw e;
|
|
175
|
+
writeAll(2, `\n${NAME}: ${e.message}\n`);
|
|
176
|
+
process.exitCode = 1;
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
console.log(role === undefined ? JSON.stringify(roles) : roles[role]);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (isCLI(import.meta.url)) main();
|