@osdlc/wayfinder 0.0.0-stage → 0.7.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/CHANGELOG.md +231 -0
- package/CONTRIBUTING.md +62 -0
- package/LICENSE-APACHE +202 -0
- package/LICENSE-MIT +21 -0
- package/README.md +507 -2
- package/SECURITY.md +44 -0
- package/bin/way.js +18 -0
- package/dist/app.d.ts +24 -0
- package/dist/app.js +24 -0
- package/dist/args.d.ts +44 -0
- package/dist/args.js +93 -0
- package/dist/cache.d.ts +7 -0
- package/dist/cache.js +15 -0
- package/dist/catalog.d.ts +38 -0
- package/dist/catalog.js +61 -0
- package/dist/clean-command.d.ts +43 -0
- package/dist/clean-command.js +274 -0
- package/dist/cli.d.ts +76 -0
- package/dist/cli.js +612 -0
- package/dist/config-command.d.ts +52 -0
- package/dist/config-command.js +342 -0
- package/dist/config.d.ts +367 -0
- package/dist/config.js +700 -0
- package/dist/devlink.d.ts +14 -0
- package/dist/devlink.js +30 -0
- package/dist/groups.d.ts +34 -0
- package/dist/groups.js +38 -0
- package/dist/guide.d.ts +32 -0
- package/dist/guide.js +411 -0
- package/dist/http.d.ts +22 -0
- package/dist/http.js +149 -0
- package/dist/origin-owner.d.ts +14 -0
- package/dist/origin-owner.js +69 -0
- package/dist/page.d.ts +15 -0
- package/dist/page.js +58 -0
- package/dist/providers-command.d.ts +40 -0
- package/dist/providers-command.js +132 -0
- package/dist/serve.d.ts +97 -0
- package/dist/serve.js +678 -0
- package/dist/tools.d.ts +46 -0
- package/dist/tools.js +102 -0
- package/dist/trust-command.d.ts +33 -0
- package/dist/trust-command.js +221 -0
- package/dist/trust-store.d.ts +18 -0
- package/dist/trust-store.js +46 -0
- package/dist/tui.d.ts +178 -0
- package/dist/tui.js +846 -0
- package/dist/web/main.js +2315 -0
- package/dist/web/page.html +110 -0
- package/dist/web/styles.css +1514 -0
- package/dist/xdg.d.ts +10 -0
- package/dist/xdg.js +17 -0
- package/package.json +72 -3
package/dist/web/main.js
ADDED
|
@@ -0,0 +1,2315 @@
|
|
|
1
|
+
//#region src/web/state.ts
|
|
2
|
+
const SEP = " › ";
|
|
3
|
+
/**
|
|
4
|
+
* Every static element this page touches is declared in `page.html` and never
|
|
5
|
+
* removed, so a lookup that fails is a bug in the markup, not a runtime case
|
|
6
|
+
* to handle — the `!` reflects that invariant rather than hiding a real null.
|
|
7
|
+
*/
|
|
8
|
+
function $(id) {
|
|
9
|
+
return document.getElementById(id);
|
|
10
|
+
}
|
|
11
|
+
const state = {
|
|
12
|
+
catalog: null,
|
|
13
|
+
runner: "all",
|
|
14
|
+
query: "",
|
|
15
|
+
mode: "fuzzy",
|
|
16
|
+
servicesOnly: false,
|
|
17
|
+
declaredOnly: false,
|
|
18
|
+
runnerOrder: [],
|
|
19
|
+
depth: 99,
|
|
20
|
+
enabled: null,
|
|
21
|
+
collapsed: /* @__PURE__ */ new Set(),
|
|
22
|
+
allCollapsed: false,
|
|
23
|
+
fingerprint: "",
|
|
24
|
+
mainWidth: 0,
|
|
25
|
+
knownRunners: /* @__PURE__ */ new Set(),
|
|
26
|
+
checkedAt: Date.now(),
|
|
27
|
+
loading: false,
|
|
28
|
+
trustable: false,
|
|
29
|
+
cache: [],
|
|
30
|
+
focusedId: null
|
|
31
|
+
};
|
|
32
|
+
function persistTheme(choice) {
|
|
33
|
+
try {
|
|
34
|
+
localStorage.setItem("wayfinder:theme", choice);
|
|
35
|
+
} catch {}
|
|
36
|
+
}
|
|
37
|
+
/** The saved theme choice, or null when there is none — the system default stands. */
|
|
38
|
+
function restoreTheme() {
|
|
39
|
+
try {
|
|
40
|
+
const saved = localStorage.getItem("wayfinder:theme");
|
|
41
|
+
if (saved === "light" || saved === "dark") return saved;
|
|
42
|
+
} catch {}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
function persistRunnerOrder(order) {
|
|
46
|
+
try {
|
|
47
|
+
localStorage.setItem("wayfinder:runner-order", JSON.stringify(order));
|
|
48
|
+
} catch {}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Drop the saved arrangement, so the configured order applies again.
|
|
52
|
+
*
|
|
53
|
+
* Once a tab has been dragged, `runners.order` from the project config can
|
|
54
|
+
* never take effect again in this browser. This is the way back.
|
|
55
|
+
*/
|
|
56
|
+
function clearRunnerOrder() {
|
|
57
|
+
try {
|
|
58
|
+
localStorage.removeItem("wayfinder:runner-order");
|
|
59
|
+
} catch {}
|
|
60
|
+
state.runnerOrder = [];
|
|
61
|
+
}
|
|
62
|
+
/** The saved runner arrangement, or `[]` when there is none — alphabetical stands. */
|
|
63
|
+
function restoreRunnerOrder() {
|
|
64
|
+
try {
|
|
65
|
+
const savedOrder = JSON.parse(localStorage.getItem("wayfinder:runner-order") ?? "[]");
|
|
66
|
+
if (Array.isArray(savedOrder)) return savedOrder.filter((r) => typeof r === "string");
|
|
67
|
+
} catch {}
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region ../system-model/dist/duration.js
|
|
72
|
+
/**
|
|
73
|
+
* Durations and ages a person reads, not numbers of milliseconds.
|
|
74
|
+
*
|
|
75
|
+
* These format the two numbers `cache.ts` measures — how long a probe takes
|
|
76
|
+
* ({@link humanMs}) and how old a stored answer is ({@link humanAge}) — and
|
|
77
|
+
* every surface that reports on the cache (both CLIs, the TUI, the web view)
|
|
78
|
+
* prints one or both of them.
|
|
79
|
+
*
|
|
80
|
+
* They are NOT in `cache.ts`, for the same reason `match.ts` is not: the web
|
|
81
|
+
* view is bundled for the browser, and `cache.ts` reaches for `node:fs`,
|
|
82
|
+
* `node:crypto` and `node:os`. This module has its own `./duration` export
|
|
83
|
+
* subpath and must stay free of DOM and of node builtins.
|
|
84
|
+
*
|
|
85
|
+
* What a surface does NOT get from here is the sentence around the number. The
|
|
86
|
+
* CLIs say "35s old, refresh usually about 149ms", the TUI says "~149ms", the
|
|
87
|
+
* page says "never timed here" — four voices, deliberately, each written for
|
|
88
|
+
* where it is read. Only the number's spelling is shared.
|
|
89
|
+
*/
|
|
90
|
+
/**
|
|
91
|
+
* A duration, at a precision that suits its size: milliseconds under a second,
|
|
92
|
+
* one decimal of a second under ten, then whole seconds and whole minutes. A
|
|
93
|
+
* probe cost is a rough expectation, and `1.4s` reads where `1423ms` does not.
|
|
94
|
+
*/
|
|
95
|
+
function humanMs(ms) {
|
|
96
|
+
if (ms < 1e3) return `${Math.round(ms)}ms`;
|
|
97
|
+
if (ms < 1e4) return `${(ms / 1e3).toFixed(1)}s`;
|
|
98
|
+
if (ms < 6e4) return `${Math.round(ms / 1e3)}s`;
|
|
99
|
+
return `${Math.round(ms / 6e4)}m`;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* How old a cached answer is. `undefined` is a miss, which has no age at all —
|
|
103
|
+
* and says so rather than reading as "0s old", which would claim a freshness
|
|
104
|
+
* nothing measured.
|
|
105
|
+
*
|
|
106
|
+
* The floor of one second is deliberate: an answer read out of the store
|
|
107
|
+
* moments after it was written is still an answer from the store, and "0s old"
|
|
108
|
+
* invites the reader to think it is live.
|
|
109
|
+
*/
|
|
110
|
+
function humanAge(ms) {
|
|
111
|
+
if (ms === void 0) return "of unknown age";
|
|
112
|
+
if (ms < 6e4) return `${Math.max(1, Math.round(ms / 1e3))}s old`;
|
|
113
|
+
if (ms < 36e5) return `${Math.round(ms / 6e4)}m old`;
|
|
114
|
+
if (ms < 864e5) return `${Math.round(ms / 36e5)}h old`;
|
|
115
|
+
return `${Math.round(ms / 864e5)}d old`;
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region ../system-model/dist/match.js
|
|
119
|
+
/**
|
|
120
|
+
* Ranked search over catalog entries — the one matcher both views use.
|
|
121
|
+
*
|
|
122
|
+
* Every surface over this catalog has to agree on what a query means, or the
|
|
123
|
+
* same keystrokes rank differently depending on which one you reached for.
|
|
124
|
+
* The terminal UI imports it directly; the web view loads it transpiled for
|
|
125
|
+
* the browser, which is why it has its own `./match` export subpath and why it
|
|
126
|
+
* must stay free of DOM and of node builtins. Importing anything from
|
|
127
|
+
* `node:fs` here breaks the browser build.
|
|
128
|
+
*
|
|
129
|
+
* Query language, such as it is:
|
|
130
|
+
* - terms are whitespace-separated and ANDed; every term must match a field
|
|
131
|
+
* - a leading `'` forces that term to match as a substring, fzf-style
|
|
132
|
+
* - `mode: "exact"` forces every term to, without the prefix
|
|
133
|
+
* - matching is case-insensitive throughout
|
|
134
|
+
*/
|
|
135
|
+
/**
|
|
136
|
+
* Case-insensitive subsequence match. Consecutive characters and matches at a
|
|
137
|
+
* word boundary score higher, so "ddev" ranks "determined:dev" above an
|
|
138
|
+
* incidental scatter of those letters.
|
|
139
|
+
*/
|
|
140
|
+
function fuzzy(text, rawTerm) {
|
|
141
|
+
const hay = text.toLowerCase();
|
|
142
|
+
const term = rawTerm.toLowerCase();
|
|
143
|
+
let ti = 0;
|
|
144
|
+
let score = 0;
|
|
145
|
+
let streak = 0;
|
|
146
|
+
const idx = [];
|
|
147
|
+
for (let i = 0; i < hay.length && ti < term.length; i++) {
|
|
148
|
+
if (hay[i] !== term[ti]) {
|
|
149
|
+
streak = 0;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const boundary = i === 0 || /[^a-z0-9]/.test(hay[i - 1]);
|
|
153
|
+
score += 1 + streak * 2 + (boundary ? 3 : 0);
|
|
154
|
+
streak++;
|
|
155
|
+
idx.push(i);
|
|
156
|
+
ti++;
|
|
157
|
+
}
|
|
158
|
+
if (ti !== term.length) return null;
|
|
159
|
+
if (idx[idx.length - 1] - idx[0] + 1 > term.length * 4 + 8) return null;
|
|
160
|
+
return {
|
|
161
|
+
score,
|
|
162
|
+
idx
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/** Substring hit. Always outranks any subsequence hit on the same field. */
|
|
166
|
+
function exact(text, rawTerm) {
|
|
167
|
+
const term = rawTerm.toLowerCase();
|
|
168
|
+
const at = text.toLowerCase().indexOf(term);
|
|
169
|
+
if (at < 0) return null;
|
|
170
|
+
const boundary = at === 0 || /[^a-z0-9]/.test(text[at - 1].toLowerCase());
|
|
171
|
+
const idx = [];
|
|
172
|
+
for (let k = 0; k < term.length; k++) idx.push(at + k);
|
|
173
|
+
return {
|
|
174
|
+
score: 1e3 + term.length * 4 + (boundary ? 20 : 0),
|
|
175
|
+
idx
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/** Split a raw query into terms. Empty query means "everything matches". */
|
|
179
|
+
function terms(query) {
|
|
180
|
+
return query.trim().toLowerCase().split(/\s+/).filter(Boolean);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Score one entry against every term, or return null if any term misses.
|
|
184
|
+
* Fields are ordered most- to least-identifying and scores decay by position,
|
|
185
|
+
* so a hit on the command's name beats the same hit buried in its tags.
|
|
186
|
+
*/
|
|
187
|
+
function matchEntry(entry, queryTerms, mode) {
|
|
188
|
+
const fields = [
|
|
189
|
+
entry.path.join(" "),
|
|
190
|
+
entry.display,
|
|
191
|
+
entry.doc || "",
|
|
192
|
+
entry.detail || "",
|
|
193
|
+
entry.tags.join(" ")
|
|
194
|
+
];
|
|
195
|
+
let total = 0;
|
|
196
|
+
let labelHits = null;
|
|
197
|
+
for (const raw of queryTerms) {
|
|
198
|
+
const forced = raw.startsWith("'");
|
|
199
|
+
const term = forced ? raw.slice(1) : raw;
|
|
200
|
+
if (!term) continue;
|
|
201
|
+
const match = forced || mode === "exact" ? exact : (t, x) => exact(t, x) || fuzzy(t, x);
|
|
202
|
+
let best = null;
|
|
203
|
+
let bestField = -1;
|
|
204
|
+
for (let f = 0; f < fields.length; f++) {
|
|
205
|
+
const hit = match(fields[f], term);
|
|
206
|
+
if (hit && (!best || hit.score - f * 6 > best.score - bestField * 6)) {
|
|
207
|
+
best = hit;
|
|
208
|
+
bestField = f;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (!best) return null;
|
|
212
|
+
total += best.score - bestField * 6;
|
|
213
|
+
if (bestField === 0 && !labelHits) labelHits = best.idx;
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
score: total,
|
|
217
|
+
labelHits
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region ../system-model/dist/params.js
|
|
222
|
+
/**
|
|
223
|
+
* How a task's parameters are spelled for a reader.
|
|
224
|
+
*
|
|
225
|
+
* Its own module with its own `./params` export subpath, for the same reason
|
|
226
|
+
* `duration.ts` and `match.ts` are: the web view is bundled for the browser,
|
|
227
|
+
* and importing this from the package entry would drag `node:fs`,
|
|
228
|
+
* `node:crypto` and `child_process` into that bundle. This module must stay
|
|
229
|
+
* free of DOM and of node builtins — the `Param` import below is a type, so it
|
|
230
|
+
* is erased.
|
|
231
|
+
*
|
|
232
|
+
* One spelling, three callers: just's runner builds `display` with it, the
|
|
233
|
+
* TUI prints it under a command that ran without arguments, and the web view's
|
|
234
|
+
* run bar shows it under the field.
|
|
235
|
+
*/
|
|
236
|
+
/**
|
|
237
|
+
* Parameters in just's own notation — `<required>`, `[optional]`, and `+`/`*`
|
|
238
|
+
* for a variadic that does and does not need an argument.
|
|
239
|
+
*
|
|
240
|
+
* Display only, and never executable: `<name>` is a shell redirection and `*`
|
|
241
|
+
* globs, which is exactly why `argv` and `display` are separate fields. Empty
|
|
242
|
+
* string for a task that takes none, so a caller can concatenate without a
|
|
243
|
+
* length check.
|
|
244
|
+
*/
|
|
245
|
+
function paramShape(parameters) {
|
|
246
|
+
return parameters.map((p) => {
|
|
247
|
+
if (p.variadic) return `${p.required ? "+" : "*"}${p.name}`;
|
|
248
|
+
return p.required ? `<${p.name}>` : `[${p.name}]`;
|
|
249
|
+
}).join(" ");
|
|
250
|
+
}
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/groups.ts
|
|
253
|
+
/**
|
|
254
|
+
* In display order. The runner ids are `SYNTHESIZED_RUNNERS` from
|
|
255
|
+
* `@osdlc/system-model/detect`, restated because that entry is not
|
|
256
|
+
* browser-safe; a test checks they agree.
|
|
257
|
+
*/
|
|
258
|
+
const GROUPS = [
|
|
259
|
+
{
|
|
260
|
+
id: "tasks",
|
|
261
|
+
title: "Tasks"
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
id: "dependencies",
|
|
265
|
+
title: "Dependencies",
|
|
266
|
+
runner: "package-manager"
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
id: "tools",
|
|
270
|
+
title: "Tools",
|
|
271
|
+
runner: "tool-manager"
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
id: "hooks",
|
|
275
|
+
title: "Git hooks",
|
|
276
|
+
runner: "hook-manager"
|
|
277
|
+
}
|
|
278
|
+
];
|
|
279
|
+
/** The group a runner's report belongs to. */
|
|
280
|
+
function groupOf(runner) {
|
|
281
|
+
return GROUPS.find((g) => g.runner === runner) ?? GROUPS[0];
|
|
282
|
+
}
|
|
283
|
+
/** Position of a runner's group in {@link GROUPS}. */
|
|
284
|
+
function groupRank(runner) {
|
|
285
|
+
return GROUPS.indexOf(groupOf(runner));
|
|
286
|
+
}
|
|
287
|
+
/** What a tab shows for a runner: the group's name for a synthesized group, else the runner id. */
|
|
288
|
+
function runnerLabel(runner) {
|
|
289
|
+
const group = groupOf(runner);
|
|
290
|
+
return group.runner === runner ? group.title.toLowerCase() : runner;
|
|
291
|
+
}
|
|
292
|
+
//#endregion
|
|
293
|
+
//#region src/web/view.ts
|
|
294
|
+
function escapeHtml(s) {
|
|
295
|
+
return s.replace(/[&<>"]/g, (c) => ({
|
|
296
|
+
"&": "&",
|
|
297
|
+
"<": "<",
|
|
298
|
+
">": ">",
|
|
299
|
+
"\"": """
|
|
300
|
+
})[c]);
|
|
301
|
+
}
|
|
302
|
+
/** The runner's optional visual identity, straight off its report. */
|
|
303
|
+
function brandOf(runner) {
|
|
304
|
+
return (state.catalog?.reports || []).find((r) => r.runner === runner)?.brand || null;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* The runner's icon, injected RAW on purpose: it is inline SVG the server's
|
|
308
|
+
* own providers declare, the same trust this page already extends to every
|
|
309
|
+
* field it renders. Running it through escapeHtml would print the markup as
|
|
310
|
+
* text instead of drawing it.
|
|
311
|
+
*/
|
|
312
|
+
function iconHtml(runner) {
|
|
313
|
+
const icon = brandOf(runner)?.icon;
|
|
314
|
+
return icon ? "<span class=\"ricon\" aria-hidden=\"true\">" + icon + "</span>" : "";
|
|
315
|
+
}
|
|
316
|
+
/** Row tint attributes. The color is data handed to CSS, so it IS escaped. */
|
|
317
|
+
function brandAttrs(runner) {
|
|
318
|
+
const color = brandOf(runner)?.color;
|
|
319
|
+
return color ? " class=\"branded\" style=\"--rb:" + escapeHtml(color) + "\"" : "";
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* The attributes every body row carries: the brand tint, the task's stable id,
|
|
323
|
+
* and a roving-tabindex slot.
|
|
324
|
+
*
|
|
325
|
+
* `data-id` is the task's own id, not its position: the list is traversed by
|
|
326
|
+
* keyboard and render() replaces #out wholesale, so the focused row has to be
|
|
327
|
+
* findable again by identity after a rebuild reorders or drops rows.
|
|
328
|
+
*
|
|
329
|
+
* Every row starts at -1. markEnterTarget() promotes exactly one to 0, so the
|
|
330
|
+
* whole list is a single tab stop and the arrows move within it — the same
|
|
331
|
+
* pattern rovingGroup() uses for the toolbar segments.
|
|
332
|
+
*/
|
|
333
|
+
function rowAttrs(e) {
|
|
334
|
+
return brandAttrs(e.runner) + " data-id=\"" + escapeHtml(e.id) + "\" tabindex=\"-1\"";
|
|
335
|
+
}
|
|
336
|
+
/** Wrap the matched character positions of `text` in <mark>. */
|
|
337
|
+
function highlight(text, idx) {
|
|
338
|
+
if (!idx || !idx.length) return escapeHtml(text);
|
|
339
|
+
const set = new Set(idx);
|
|
340
|
+
let out = "", open = false;
|
|
341
|
+
for (let i = 0; i < text.length; i++) {
|
|
342
|
+
const on = set.has(i);
|
|
343
|
+
if (on && !open) {
|
|
344
|
+
out += "<mark>";
|
|
345
|
+
open = true;
|
|
346
|
+
}
|
|
347
|
+
if (!on && open) {
|
|
348
|
+
out += "</mark>";
|
|
349
|
+
open = false;
|
|
350
|
+
}
|
|
351
|
+
out += escapeHtml(text[i]);
|
|
352
|
+
}
|
|
353
|
+
return out + (open ? "</mark>" : "");
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Rebuild the call-chain tree from whatever leaves survived the filter, so a
|
|
357
|
+
* group header only appears while it still has something under it.
|
|
358
|
+
*/
|
|
359
|
+
function buildTree(rows) {
|
|
360
|
+
const root = {
|
|
361
|
+
kids: /* @__PURE__ */ new Map(),
|
|
362
|
+
leaves: [],
|
|
363
|
+
count: 0
|
|
364
|
+
};
|
|
365
|
+
for (const row of rows) {
|
|
366
|
+
const chain = row.entry.path.slice(treeStart(), -1);
|
|
367
|
+
let node = root;
|
|
368
|
+
node.count++;
|
|
369
|
+
for (const seg of chain) {
|
|
370
|
+
if (!node.kids.has(seg)) node.kids.set(seg, {
|
|
371
|
+
kids: /* @__PURE__ */ new Map(),
|
|
372
|
+
leaves: [],
|
|
373
|
+
count: 0
|
|
374
|
+
});
|
|
375
|
+
node = node.kids.get(seg);
|
|
376
|
+
node.count++;
|
|
377
|
+
}
|
|
378
|
+
node.leaves.push(row);
|
|
379
|
+
}
|
|
380
|
+
return root;
|
|
381
|
+
}
|
|
382
|
+
function renderNode(node, prefix) {
|
|
383
|
+
let html = "";
|
|
384
|
+
const order = runnerOrder();
|
|
385
|
+
const topLevel = treeStart() === 0 && prefix.length === 0;
|
|
386
|
+
const groups = [...node.kids.entries()].sort((a, b) => topLevel ? order.indexOf(a[0]) - order.indexOf(b[0]) : a[0].localeCompare(b[0]));
|
|
387
|
+
for (const [seg, kid] of groups) {
|
|
388
|
+
const key = prefix.concat(seg).join(" ");
|
|
389
|
+
const collapsed = state.collapsed.has(key);
|
|
390
|
+
const depth = prefix.length;
|
|
391
|
+
const meta = chainOf(treeStart() === 0 ? depth === 0 ? seg : prefix[0] : state.runner)[depth + treeStart()];
|
|
392
|
+
const icon = treeStart() === 0 && depth === 0 ? iconHtml(seg) : "";
|
|
393
|
+
const top = "calc(var(--chrome-h) + " + depth + " * var(--head-h))";
|
|
394
|
+
const layer = Math.max(1, 20 - depth);
|
|
395
|
+
html += "<div class=\"node\" data-collapsed=\"" + collapsed + "\" data-key=\"" + escapeHtml(key) + "\"><div class=\"head\" style=\"top:" + top + ";z-index:" + layer + "\"><span class=\"twisty\">" + (collapsed ? "▸" : "▾") + "</span>" + icon + "<span class=\"seg-name\"" + (meta ? " title=\"" + escapeHtml(meta.label + " - " + meta.hint) + "\"" : "") + ">" + escapeHtml(seg) + "</span>" + (meta ? "<span class=\"seg-kind\">" + escapeHtml(meta.label) + "</span>" : "") + "<span class=\"node-count\">" + kid.count + "</span></div><div class=\"kids\">" + renderNode(kid, prefix.concat(seg)) + "</div></div>";
|
|
396
|
+
}
|
|
397
|
+
if (node.leaves.length) {
|
|
398
|
+
const sorted = node.leaves.slice().sort((a, b) => b.score - a.score || a.entry.path.join().localeCompare(b.entry.path.join()));
|
|
399
|
+
html += "<table style=\"" + outdent(prefix.length) + "\">" + colgroup(prefix.length) + "<tbody>" + sorted.map((r) => renderTreeRow(r, prefix.length)).join("") + "</tbody></table>";
|
|
400
|
+
}
|
|
401
|
+
return html;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* The service icon, authored here rather than taken from a runner's brand:
|
|
405
|
+
* the brand icons identify RUNNERS, and this marks a property of the task.
|
|
406
|
+
* No fixed size and no colour of its own — styles.css sizes the box and
|
|
407
|
+
* `currentColor` lets the theme tokens paint it.
|
|
408
|
+
*/
|
|
409
|
+
function serviceIcon(declared) {
|
|
410
|
+
return declared ? "<svg viewBox=\"0 0 16 16\" aria-hidden=\"true\"><circle cx=\"8\" cy=\"8\" r=\"4.5\" fill=\"currentColor\" /></svg>" : "<svg viewBox=\"0 0 16 16\" aria-hidden=\"true\"><circle cx=\"8\" cy=\"8\" r=\"4\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.6\" /></svg>";
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* A directory in a form a shell will take. Quoted only when it needs to be,
|
|
414
|
+
* so the common case stays readable.
|
|
415
|
+
*/
|
|
416
|
+
function quoteDir(dir) {
|
|
417
|
+
return /^[\w.\-/@+]+$/.test(dir) ? dir : "'" + dir.replace(/'/g, "'\\''") + "'";
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* What Copy hands over, which is not always what the Command column shows.
|
|
421
|
+
*
|
|
422
|
+
* Most tasks are written to run from the repository root and copy bare. A task
|
|
423
|
+
* bound to its own directory gets the `cd` that makes it work — omitting it
|
|
424
|
+
* would hand the user a command that fails. `argv` is untouched either way:
|
|
425
|
+
* anything that SPAWNS a task already has the directory.
|
|
426
|
+
*/
|
|
427
|
+
function copyText(task) {
|
|
428
|
+
return task.cwd === "." ? task.display : "cd " + quoteDir(task.cwd) + " && " + task.display;
|
|
429
|
+
}
|
|
430
|
+
/** What Run costs, said up front: the page ends and the terminal takes over. */
|
|
431
|
+
function runTip(task) {
|
|
432
|
+
return "Run " + task.display + " in the terminal wayfinder is serving from. The server exits and this page is finished.";
|
|
433
|
+
}
|
|
434
|
+
/** Why a row's Copy is longer than its Command, said only when it is. */
|
|
435
|
+
function copyTip(task) {
|
|
436
|
+
return task.cwd === "." ? "Copy the command to the clipboard." : "Copy — includes cd " + quoteDir(task.cwd) + " because this task must run from there.";
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* The columns, in the order the colgroup declares them, plus the depth spacer
|
|
440
|
+
* that sits between the first two below the root. Five of them, or four once
|
|
441
|
+
* Runs drops at a narrow width (see `showRuns`). The indicator sits in its own
|
|
442
|
+
* gutter rather than inline in the name: prefixing the text pushed every marked
|
|
443
|
+
* row's chain out of line with its neighbours.
|
|
444
|
+
*/
|
|
445
|
+
function cells(e, nameHtml, depth = 0) {
|
|
446
|
+
const p = e.persistent;
|
|
447
|
+
return "<td class=\"ind\"><span class=\"inds\">" + (p.value ? "<span class=\"ind-svc" + (p.declared ? "" : " inferred") + "\" title=\"" + escapeHtml(p.declared ? "Service: the runner declares this one persistent. It runs until you stop it." : "Service, inferred from the task's name — the runner did not say so.") + "\">" + serviceIcon(p.declared) + "<span class=\"sr\">" + (p.declared ? "Service" : "Service, inferred") + "</span></span>" : "") + "</span></td>" + spacerCell(depth) + "<td class=\"name\" title=\"" + escapeHtml(e.path.join(SEP)) + "\">" + nameHtml + "</td><td class=\"run\" title=\"" + escapeHtml(e.display) + "\">" + escapeHtml(e.display) + "</td>" + (showRuns() ? "<td class=\"doc\">" + escapeHtml(e.doc || "") + (e.detail && e.detail !== e.display ? "<span class=\"detail\" title=\"" + escapeHtml(e.detail) + "\">" + escapeHtml(e.detail) + "</span>" : "") + "</td>" : "") + "<td class=\"act\"><button class=\"runbtn\" data-run-id=\"" + escapeHtml(e.id) + "\" title=\"" + escapeHtml(runTip(e)) + "\" aria-label=\"" + escapeHtml("Run " + e.display + " in the terminal") + "\">run</button><button class=\"copy\" title=\"" + escapeHtml(copyTip(e)) + "\" data-run=\"" + escapeHtml(copyText(e)) + "\">copy</button></td>";
|
|
448
|
+
}
|
|
449
|
+
/** Each `.kids` level costs 14px margin + 11px padding. */
|
|
450
|
+
const INDENT_PER_LEVEL = 25;
|
|
451
|
+
function outdent(depth) {
|
|
452
|
+
if (depth === 0) return "";
|
|
453
|
+
const px = depth * INDENT_PER_LEVEL;
|
|
454
|
+
return "margin-left:-" + px + "px;width:calc(100% + " + px + "px)";
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* The action gutter. Wide enough for `run` beside the enter-target row's
|
|
458
|
+
* `↵ copy`, which is the widest the column ever gets — the plain `copy` on
|
|
459
|
+
* every other row leaves 14px more spare. Measured in Chromium at 1700px and
|
|
460
|
+
* 1100px, which agree: `run` 35.23 + a 4px gap + `↵ copy` 57.89 + the cell's
|
|
461
|
+
* own 8px right padding is 105.12.
|
|
462
|
+
*
|
|
463
|
+
* 112 rather than that 106, because 106 left 0.88px. Nothing clipped, but a
|
|
464
|
+
* fallback font or one more pixel of button padding would have, and the
|
|
465
|
+
* failure is silent — the row's actions simply lose their right edge. The
|
|
466
|
+
* 6.88px here is slack a re-measure can spend.
|
|
467
|
+
*/
|
|
468
|
+
const ACT_W = 112;
|
|
469
|
+
/** The indicator gutter: one icon wide, with room to centre a second later. */
|
|
470
|
+
const IND_W = 30;
|
|
471
|
+
/**
|
|
472
|
+
* Below this the Runs column is dropped. The UX review put the point where
|
|
473
|
+
* Runs truncates to noise at a 1100px VIEWPORT; `main` pads 16px each side,
|
|
474
|
+
* so that is about 1068px of table width. The number is in the same units as
|
|
475
|
+
* `availWidth()` — the width of the table area itself (`main` minus its own
|
|
476
|
+
* padding), not of the window.
|
|
477
|
+
*/
|
|
478
|
+
const RUNS_MIN_W = 1068;
|
|
479
|
+
/** The width every table's columns are measured against. */
|
|
480
|
+
function availWidth() {
|
|
481
|
+
return Math.max(320, state.mainWidth || 1e3);
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Whether the Runs column exists at all right now. `colgroup`, `cells` and
|
|
485
|
+
* `renderColHeads` all ask this one question, because a table whose colgroup,
|
|
486
|
+
* head row and body rows disagree about how many columns there are misaligns
|
|
487
|
+
* every column after the first.
|
|
488
|
+
*/
|
|
489
|
+
function showRuns() {
|
|
490
|
+
return availWidth() >= RUNS_MIN_W;
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* The columns, named once. `tip` is the hover explanation; the modal carries
|
|
494
|
+
* the longer version for anything a tooltip cannot hold. This is the full
|
|
495
|
+
* roster; `renderColHeads` drops Runs from it when the width does.
|
|
496
|
+
*/
|
|
497
|
+
const COLUMNS = [
|
|
498
|
+
{
|
|
499
|
+
label: "",
|
|
500
|
+
tip: "Row indicators. A filled dot marks a service — a task that runs until you stop it, such as a dev server, a watcher or a preview. An outlined dot means that was inferred from the task's name rather than declared by the runner."
|
|
501
|
+
},
|
|
502
|
+
{
|
|
503
|
+
label: "Task",
|
|
504
|
+
tip: "What to run, as its call chain: the runner, where it lives, and the task's own name. The middle segments are grouping this page adds; they are not part of the command."
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
label: "Command",
|
|
508
|
+
tip: "The exact command. Nearly every one is written to run from the repository root; where a task must run from its own directory, Copy adds the cd for you."
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
label: "Runs",
|
|
512
|
+
tip: "What the task actually executes, or the summary its runner documents where there is one."
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
label: "",
|
|
516
|
+
tip: "Row actions. Run hands the task to the terminal wayfinder is serving from, and ends this page. Copy puts the command on the clipboard, with the cd that a task bound to its own directory needs; on the row Enter would take it reads ↵ copy."
|
|
517
|
+
}
|
|
518
|
+
];
|
|
519
|
+
/**
|
|
520
|
+
* Column widths, in pixels rather than percentages, because the tables are
|
|
521
|
+
* different widths: each is outdented by its depth (see `outdent`) so their
|
|
522
|
+
* left edges agree, which makes a percentage mean a different number of
|
|
523
|
+
* pixels at every level.
|
|
524
|
+
*
|
|
525
|
+
* A leading spacer column of exactly the outdent puts the CONTENT back where
|
|
526
|
+
* its group header is, and the name column gives up the same amount — so the
|
|
527
|
+
* command column starts at the same absolute x whatever the depth, and no row
|
|
528
|
+
* text lands in the strip to the left of the headers. Painting text there was
|
|
529
|
+
* the visible bug: a header's background stops at its own indented box, so a
|
|
530
|
+
* row scrolling under one showed through beside it.
|
|
531
|
+
*
|
|
532
|
+
* Which columns exist is itself a function of the width: under RUNS_MIN_W the
|
|
533
|
+
* Runs column is dropped and its space goes back to Task and Command. That
|
|
534
|
+
* has to happen in this arithmetic rather than in a media query, because the
|
|
535
|
+
* widths are computed pixels — a media query can hide the cells but cannot
|
|
536
|
+
* recompute what the others are worth.
|
|
537
|
+
*/
|
|
538
|
+
function colgroup(depth) {
|
|
539
|
+
const indent = depth * INDENT_PER_LEVEL;
|
|
540
|
+
const avail = availWidth();
|
|
541
|
+
const wide = showRuns();
|
|
542
|
+
const rest = avail - IND_W - ACT_W;
|
|
543
|
+
const name = wide ? Math.max(80, Math.round(avail * .4) - indent) : Math.max(80, Math.round(rest * .54) - indent);
|
|
544
|
+
const run = wide ? Math.round(avail * .34) : rest - indent - name;
|
|
545
|
+
return "<colgroup><col style=\"width:30px\" />" + (indent > 0 ? "<col style=\"width:" + indent + "px\" />" : "") + "<col style=\"width:" + name + "px\" /><col style=\"width:" + run + "px\" />" + (wide ? "<col />" : "") + "<col style=\"width:112px\" /></colgroup>";
|
|
546
|
+
}
|
|
547
|
+
/** The empty leading cell the spacer column needs, when there is one. */
|
|
548
|
+
function spacerCell(depth) {
|
|
549
|
+
return depth > 0 ? "<td class=\"spacer\"></td>" : "";
|
|
550
|
+
}
|
|
551
|
+
/** Under a group header the parent chain is already on screen; show the leaf. */
|
|
552
|
+
function renderTreeRow(row, depth) {
|
|
553
|
+
const e = row.entry;
|
|
554
|
+
const covered = treeStart() + depth;
|
|
555
|
+
const rest = e.path.slice(covered);
|
|
556
|
+
const shown = rest.join(SEP);
|
|
557
|
+
const skipped = covered > 0 ? e.path.slice(0, covered).join(" ").length + 1 : 0;
|
|
558
|
+
const marks = new Set(row.labelHits || []);
|
|
559
|
+
let html = "";
|
|
560
|
+
let at = skipped;
|
|
561
|
+
for (let i = 0; i < rest.length; i++) {
|
|
562
|
+
html += highlight(rest[i], [...marks].map((m) => m - at).filter((m) => m >= 0 && m < rest[i].length));
|
|
563
|
+
at += rest[i].length + 1;
|
|
564
|
+
if (i < rest.length - 1) html += "<span class=\"chain\"> › </span>";
|
|
565
|
+
}
|
|
566
|
+
return "<tr" + rowAttrs(e) + ">" + cells(e, html || escapeHtml(shown), depth) + "</tr>";
|
|
567
|
+
}
|
|
568
|
+
/** A ranked search hit stands alone, so it carries its whole chain. */
|
|
569
|
+
function renderSearchRow(row) {
|
|
570
|
+
const e = row.entry;
|
|
571
|
+
const chain = chainOf(e.runner);
|
|
572
|
+
const idx = new Set(row.labelHits || []);
|
|
573
|
+
let out = "", cursor = 0, open = false;
|
|
574
|
+
for (let p = 0; p < e.path.length; p++) {
|
|
575
|
+
const seg = chain[p];
|
|
576
|
+
out += seg ? "<span class=\"seg-hit\" title=\"" + escapeHtml(seg.label + " - " + seg.hint) + "\">" : "<span>";
|
|
577
|
+
for (const ch of e.path[p]) {
|
|
578
|
+
const on = idx.has(cursor);
|
|
579
|
+
if (on && !open) {
|
|
580
|
+
out += "<mark>";
|
|
581
|
+
open = true;
|
|
582
|
+
}
|
|
583
|
+
if (!on && open) {
|
|
584
|
+
out += "</mark>";
|
|
585
|
+
open = false;
|
|
586
|
+
}
|
|
587
|
+
out += escapeHtml(ch);
|
|
588
|
+
cursor++;
|
|
589
|
+
}
|
|
590
|
+
if (open) {
|
|
591
|
+
out += "</mark>";
|
|
592
|
+
open = false;
|
|
593
|
+
}
|
|
594
|
+
out += "</span>";
|
|
595
|
+
if (p < e.path.length - 1) {
|
|
596
|
+
out += "<span class=\"chain\"> › </span>";
|
|
597
|
+
cursor++;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
return "<tr" + rowAttrs(e) + ">" + cells(e, out) + "</tr>";
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* How deep in the repository a task is DECLARED — the number of directories
|
|
604
|
+
* above its source file. `justfile` and `moon.yml` at the root are 0;
|
|
605
|
+
* `apps/web/client/moon.yml` is 3.
|
|
606
|
+
*
|
|
607
|
+
* This is where a task LIVES, not how the tree draws it. The Depth control
|
|
608
|
+
* filters on it, so "Root" is the handful of commands the repository itself
|
|
609
|
+
* declares rather than the ones its packages do.
|
|
610
|
+
*/
|
|
611
|
+
function sourceDepth(task) {
|
|
612
|
+
const at = task.source.lastIndexOf("/");
|
|
613
|
+
return at === -1 ? 0 : task.source.slice(0, at).split("/").length;
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* The one runner order, driving the tabs, the picker and the tree's top
|
|
617
|
+
* level — three surfaces that must agree or the tab bar stops predicting the
|
|
618
|
+
* page under it.
|
|
619
|
+
*
|
|
620
|
+
* Grouped first (tasks, dependencies, tools, git hooks), then alphabetical
|
|
621
|
+
* within a group. Any explicit arrangement (dragged on either surface) is
|
|
622
|
+
* kept in localStorage and wins within its group. A runner not in the saved
|
|
623
|
+
* arrangement slots in alphabetically after it rather than vanishing.
|
|
624
|
+
*/
|
|
625
|
+
function runnerOrder() {
|
|
626
|
+
const present = (state.catalog?.reports || []).map((r) => r.runner);
|
|
627
|
+
const saved = state.runnerOrder.filter((r) => present.includes(r));
|
|
628
|
+
const unsaved = present.filter((r) => !saved.includes(r)).sort();
|
|
629
|
+
return [...saved, ...unsaved].sort((a, b) => groupRank(a) - groupRank(b));
|
|
630
|
+
}
|
|
631
|
+
function saveRunnerOrder(order) {
|
|
632
|
+
state.runnerOrder = order;
|
|
633
|
+
persistRunnerOrder(order);
|
|
634
|
+
render();
|
|
635
|
+
}
|
|
636
|
+
/** The runner order re-sorted by one key, ties broken alphabetically. */
|
|
637
|
+
function sortedRunnerOrder(key, dir) {
|
|
638
|
+
const reports = state.catalog?.reports || [];
|
|
639
|
+
const count = (r) => reports.find((s) => s.runner === r)?.tasks.length ?? 0;
|
|
640
|
+
const shown = (r) => state.enabled?.has(r) === true ? 1 : 0;
|
|
641
|
+
const rank = (a, b) => key === "name" ? a.localeCompare(b) : key === "count" ? count(a) - count(b) : shown(a) - shown(b);
|
|
642
|
+
return runnerOrder().slice().sort((a, b) => {
|
|
643
|
+
const by = rank(a, b);
|
|
644
|
+
return by !== 0 ? dir * by : a.localeCompare(b);
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* The sort the user last ASKED for. Not a claim about the order on screen —
|
|
649
|
+
* activeSort verifies it against the live order before the header shows
|
|
650
|
+
* anything, so a drag clears the arrow. It only decides WHICH column is
|
|
651
|
+
* credited when an order satisfies two sorts, which every order does when the
|
|
652
|
+
* counts are all equal.
|
|
653
|
+
*/
|
|
654
|
+
let requestedSort = null;
|
|
655
|
+
/**
|
|
656
|
+
* Which sort the order ALREADY is, if any - verified by comparing, never taken
|
|
657
|
+
* on trust. A stored "sorted by name" flag alone would keep claiming that after
|
|
658
|
+
* a drag had rearranged the list out from under it, and the header would be
|
|
659
|
+
* lying about what is on screen.
|
|
660
|
+
*
|
|
661
|
+
* The last requested sort is tried FIRST, because two sorts can both describe
|
|
662
|
+
* one order and only one of them is the one the user pressed.
|
|
663
|
+
*/
|
|
664
|
+
function activeSort() {
|
|
665
|
+
const now = runnerOrder().join("\0");
|
|
666
|
+
const matches = (s) => sortedRunnerOrder(s.key, s.dir).join("\0") === now;
|
|
667
|
+
if (requestedSort && matches(requestedSort)) return requestedSort;
|
|
668
|
+
for (const key of [
|
|
669
|
+
"name",
|
|
670
|
+
"count",
|
|
671
|
+
"shown"
|
|
672
|
+
]) for (const dir of [1, -1]) if (matches({
|
|
673
|
+
key,
|
|
674
|
+
dir
|
|
675
|
+
})) return {
|
|
676
|
+
key,
|
|
677
|
+
dir
|
|
678
|
+
};
|
|
679
|
+
return null;
|
|
680
|
+
}
|
|
681
|
+
/** Sorting IS reordering: one persisted order, so the tab bar follows at once. */
|
|
682
|
+
function sortRunners(key, dir) {
|
|
683
|
+
requestedSort = {
|
|
684
|
+
key,
|
|
685
|
+
dir
|
|
686
|
+
};
|
|
687
|
+
saveRunnerOrder(sortedRunnerOrder(key, dir));
|
|
688
|
+
}
|
|
689
|
+
function scopedReports() {
|
|
690
|
+
const all = (state.catalog?.reports || []).filter((s) => !state.enabled || state.enabled.has(s.runner));
|
|
691
|
+
return state.runner === "all" ? all : all.filter((s) => s.runner === state.runner);
|
|
692
|
+
}
|
|
693
|
+
/** What each position of a given runner's chain means. */
|
|
694
|
+
function chainOf(runner) {
|
|
695
|
+
return (state.catalog?.reports || []).find((s) => s.runner === runner)?.chain || [];
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* Where the tree starts inside `entry.path`. A single-runner tab already
|
|
699
|
+
* names its runner, so the tree begins one segment in; the combined index
|
|
700
|
+
* uses the runner itself as its top node.
|
|
701
|
+
*/
|
|
702
|
+
function treeStart() {
|
|
703
|
+
return state.runner === "all" ? 0 : 1;
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Why a runner reports nothing when execution is off. Said in one place
|
|
707
|
+
* because three surfaces say it: the tab's tooltip, the picker's note and the
|
|
708
|
+
* per-runner modal.
|
|
709
|
+
*
|
|
710
|
+
* Two sentences, because there are two reasons. Reading this runner means
|
|
711
|
+
* running it either way; whether that is fixable from here depends on whether
|
|
712
|
+
* trust is what is missing, which only the server knows (see `state.trustable`).
|
|
713
|
+
*/
|
|
714
|
+
const EXEC_NOTE_OFF = "This runner can only be read by running it, and execution is off for this session.";
|
|
715
|
+
const EXEC_NOTE_UNTRUSTED = "This runner can only be read by running it, and this repository is not trusted yet.";
|
|
716
|
+
function execNote() {
|
|
717
|
+
return state.trustable ? EXEC_NOTE_UNTRUSTED : EXEC_NOTE_OFF;
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* The grant. Offered wherever the withholding is EXPLAINED, which now includes
|
|
721
|
+
* the status bar: this used to appear only in the per-runner modal and the
|
|
722
|
+
* picker, on the reasoning that the toolbar was the wrong place for it, and the
|
|
723
|
+
* result was that a person who opened neither was never told anything at all. A
|
|
724
|
+
* three-letter badge and a tooltip are not telling. Confirmed before it POSTs —
|
|
725
|
+
* see input.ts.
|
|
726
|
+
*/
|
|
727
|
+
const TRUST_BUTTON = "<button class=\"toolbtn\" data-trust-repo=\"1\" title=\"Record that this repository may run subprocesses to be read. Remembered per repository.\">Trust this repository</button>";
|
|
728
|
+
/**
|
|
729
|
+
* The stand-in for every folded runner's tab: one quiet chip naming how many,
|
|
730
|
+
* with the who and the why in its title. It is not a menu of its own — the
|
|
731
|
+
* runner picker already lists each one with its count and its (failed) /
|
|
732
|
+
* (needs --exec) / (not trusted) note, so this only has to point there (see
|
|
733
|
+
* input.ts).
|
|
734
|
+
*/
|
|
735
|
+
function foldedChip(reports) {
|
|
736
|
+
if (reports.length === 0) return "";
|
|
737
|
+
const names = reports.map((s) => s.runner);
|
|
738
|
+
const label = names.length + (names.length === 1 ? " empty runner" : " empty runners");
|
|
739
|
+
const list = names.length === 1 ? names[0] : names.slice(0, -1).join(", ") + " and " + names[names.length - 1];
|
|
740
|
+
const pronoun = names.length === 1 ? "it" : "them";
|
|
741
|
+
return "<button class=\"tab-folded\" data-open-picker=\"1\" title=\"" + escapeHtml(list + " found no tasks in this repository. Open the runner picker to see " + pronoun + " or turn " + pronoun + " off.") + "\">" + label + "</button>";
|
|
742
|
+
}
|
|
743
|
+
function render() {
|
|
744
|
+
const cat = state.catalog;
|
|
745
|
+
if (!cat) {
|
|
746
|
+
$("out").innerHTML = "<div class=\"empty\">Loading...</div>";
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
const main = $("out");
|
|
750
|
+
const pad = getComputedStyle(main);
|
|
751
|
+
state.mainWidth = Math.round(main.clientWidth - parseFloat(pad.paddingLeft) - parseFloat(pad.paddingRight));
|
|
752
|
+
state.enabled ??= new Set(cat.reports.map((s) => s.runner));
|
|
753
|
+
const enabled = state.enabled;
|
|
754
|
+
for (const s of cat.reports) if (!state.knownRunners.has(s.runner)) {
|
|
755
|
+
state.knownRunners.add(s.runner);
|
|
756
|
+
enabled.add(s.runner);
|
|
757
|
+
}
|
|
758
|
+
if (state.runner !== "all" && !enabled.has(state.runner)) state.runner = "all";
|
|
759
|
+
const on = runnerOrder().map((id) => cat.reports.find((s) => s.runner === id)).filter((s) => s !== void 0 && enabled.has(s.runner));
|
|
760
|
+
const total = on.reduce((n, s) => n + s.tasks.length, 0);
|
|
761
|
+
const anyError = on.some((s) => s.status === "error");
|
|
762
|
+
const foldable = on.filter((s) => s.tasks.length === 0 && s.status !== "error" && !s.skippedForExec && !(s.diagnostics || []).some((d) => d.severity === "warning") && s.runner !== state.runner);
|
|
763
|
+
const shown = on.filter((s) => !foldable.includes(s));
|
|
764
|
+
const tabs = [{
|
|
765
|
+
runner: "all",
|
|
766
|
+
count: total,
|
|
767
|
+
error: anyError,
|
|
768
|
+
exec: false
|
|
769
|
+
}].concat(shown.map((s) => ({
|
|
770
|
+
runner: s.runner,
|
|
771
|
+
count: s.tasks.length,
|
|
772
|
+
error: s.status === "error",
|
|
773
|
+
exec: s.skippedForExec
|
|
774
|
+
})));
|
|
775
|
+
const chainOfRunner = (id) => cat.reports.find((r) => r.runner === id)?.chain ?? [];
|
|
776
|
+
$("tabs").innerHTML = tabs.map((t, i) => {
|
|
777
|
+
const prev = tabs[i - 1];
|
|
778
|
+
const group = groupOf(t.runner);
|
|
779
|
+
const header = t.runner !== "all" && prev !== void 0 && prev.runner !== "all" && groupOf(prev.runner) !== group ? "<span class=\"tabgroup\">" + escapeHtml(group.title) + "</span>" : "";
|
|
780
|
+
const chain = chainOfRunner(t.runner);
|
|
781
|
+
const shape = chain.map((c, i) => i === 0 ? t.runner : c.label).join(" › ");
|
|
782
|
+
const draggable = t.runner !== "all" ? " draggable=\"true\"" : "";
|
|
783
|
+
const tip = t.exec ? shape ? shape + ". " + execNote() : execNote() : shape;
|
|
784
|
+
const btn = "<button data-runner=\"" + t.runner + "\" aria-pressed=\"" + (t.runner === state.runner) + "\"" + draggable + (tip ? " title=\"" + escapeHtml(tip) + "\"" : "") + ">" + iconHtml(t.runner) + escapeHtml(t.runner === "all" ? "all" : runnerLabel(t.runner)) + "<span class=\"count\">" + t.count + (t.error ? " !" : "") + "</span>" + (t.exec ? "<span class=\"count exec\">exec</span>" : "") + "</button>";
|
|
785
|
+
const info = chain.length ? "<button class=\"tabinfo\" data-info-runner=\"" + escapeHtml(t.runner) + "\" title=\"What " + escapeHtml(t.runner) + "'s path segments mean\" aria-label=\"About " + escapeHtml(t.runner) + "\">i</button>" : "";
|
|
786
|
+
return header + "<span class=\"tab\">" + btn + info + "</span>";
|
|
787
|
+
}).join("") + foldedChip(foldable);
|
|
788
|
+
const host = $("pickerhost");
|
|
789
|
+
const wasOpen = document.getElementById("pickmenu")?.hidden === false;
|
|
790
|
+
const refocus = host.contains(document.activeElement) ? pickerFocusSelector(document.activeElement) : null;
|
|
791
|
+
host.innerHTML = renderRunnerPicker(cat);
|
|
792
|
+
if (wasOpen) {
|
|
793
|
+
host.querySelector("#pickmenu")?.removeAttribute("hidden");
|
|
794
|
+
host.querySelector("#pickbtn")?.setAttribute("aria-expanded", "true");
|
|
795
|
+
}
|
|
796
|
+
if (refocus) host.querySelector(refocus)?.focus();
|
|
797
|
+
const scope = scopedReports();
|
|
798
|
+
const inScope = scope.reduce((n, s) => n + s.tasks.length, 0);
|
|
799
|
+
const terms$1 = terms(state.query);
|
|
800
|
+
const rows = [];
|
|
801
|
+
for (const sec of scope) for (const entry of sec.tasks) {
|
|
802
|
+
if (state.servicesOnly && !entry.persistent.value) continue;
|
|
803
|
+
if (state.declaredOnly && entry.origin !== "declared") continue;
|
|
804
|
+
if (sourceDepth(entry) > state.depth) continue;
|
|
805
|
+
if (terms$1.length === 0) {
|
|
806
|
+
rows.push({
|
|
807
|
+
entry,
|
|
808
|
+
score: 0,
|
|
809
|
+
labelHits: null
|
|
810
|
+
});
|
|
811
|
+
continue;
|
|
812
|
+
}
|
|
813
|
+
const m = matchEntry(entry, terms$1, state.mode);
|
|
814
|
+
if (m) rows.push({
|
|
815
|
+
entry,
|
|
816
|
+
score: m.score,
|
|
817
|
+
labelHits: m.labelHits
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
let html = "";
|
|
821
|
+
for (const sec of scope) for (const d of sec.diagnostics || []) {
|
|
822
|
+
if (d.severity === "info") continue;
|
|
823
|
+
const label = d.severity === "error" ? "banner" : "banner warn";
|
|
824
|
+
html += "<div class=\"" + label + "\">" + escapeHtml(sec.runner) + ": " + escapeHtml(d.message) + (d.source ? "\n" + escapeHtml(d.source) : "") + "</div>";
|
|
825
|
+
}
|
|
826
|
+
if (rows.length === 0) html += "<div class=\"empty\">" + (inScope ? "No command matches." : "Nothing collected.") + "</div>";
|
|
827
|
+
else if (terms$1.length) {
|
|
828
|
+
rows.sort((a, b) => b.score - a.score);
|
|
829
|
+
html += "<table>" + colgroup(0) + "<tbody>" + rows.slice(0, 400).map(renderSearchRow).join("") + "</tbody></table>";
|
|
830
|
+
} else html += renderNode(buildTree(rows), []);
|
|
831
|
+
const focusWasInList = $("out").contains(document.activeElement);
|
|
832
|
+
$("out").innerHTML = html;
|
|
833
|
+
markEnterTarget();
|
|
834
|
+
if (focusWasInList) restoreListFocus();
|
|
835
|
+
renderColHeads();
|
|
836
|
+
renderStatus(rows.length, inScope);
|
|
837
|
+
renderTrustBar();
|
|
838
|
+
measureChrome();
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* Put keyboard focus back in the rebuilt list.
|
|
842
|
+
*
|
|
843
|
+
* The focused row is found by task id. When that task is gone — a filter, the
|
|
844
|
+
* 15s poll or a resize dropped it — focus would otherwise fall to <body> and
|
|
845
|
+
* the arrows would stop working with nothing on screen saying why. The first
|
|
846
|
+
* surviving row takes it instead, and with no rows left focus goes back to the
|
|
847
|
+
* search box, which is where the user can act.
|
|
848
|
+
*/
|
|
849
|
+
function restoreListFocus() {
|
|
850
|
+
const rows = listRows();
|
|
851
|
+
const row = (state.focusedId !== null ? rows.find((r) => r.dataset.id === state.focusedId) : void 0) ?? rows[0];
|
|
852
|
+
if (row) {
|
|
853
|
+
setFocusedRow(row.dataset.id ?? null);
|
|
854
|
+
row.focus();
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
857
|
+
$("q").focus();
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* A selector naming one picker control, stable across a rebuild.
|
|
861
|
+
*
|
|
862
|
+
* The picker's markup is regenerated wholesale, so a node reference is useless
|
|
863
|
+
* afterwards. Every control in it is identified by a runner id or a fixed
|
|
864
|
+
* attribute, which survives.
|
|
865
|
+
*/
|
|
866
|
+
function pickerFocusSelector(el) {
|
|
867
|
+
if (el.closest("#pickbtn")) return "#pickbtn";
|
|
868
|
+
const toggled = el.closest("[data-toggle-runner]")?.dataset.toggleRunner;
|
|
869
|
+
if (toggled) return "input[data-toggle-runner=\"" + CSS.escape(toggled) + "\"]";
|
|
870
|
+
const info = el.closest("[data-info-runner]")?.dataset.infoRunner;
|
|
871
|
+
if (info) return "button[data-info-runner=\"" + CSS.escape(info) + "\"]";
|
|
872
|
+
const sorted = el.closest("[data-sort-runners]")?.dataset.sortRunners;
|
|
873
|
+
if (sorted) return "[data-sort-runners=\"" + CSS.escape(sorted) + "\"]";
|
|
874
|
+
if (el.closest("[data-pick-all]")) return "[data-pick-all]";
|
|
875
|
+
if (el.closest("[data-pick-none]")) return "[data-pick-none]";
|
|
876
|
+
return null;
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* The longer explanation, for what a tooltip is too small to hold — chiefly
|
|
880
|
+
* the two distinctions that surprise people: part of a task's chain is
|
|
881
|
+
* grouping this page invents, and a task can be one a runner declares or one
|
|
882
|
+
* a convention merely implies.
|
|
883
|
+
*/
|
|
884
|
+
const HELP = [
|
|
885
|
+
"<h3>What this is</h3>",
|
|
886
|
+
"<p>Every task this repository can run, from every runner it uses, in one searchable list. ",
|
|
887
|
+
"The runners answer only for themselves — <code>just --list</code> knows nothing about moon — so this asks each of them and merges the answers.</p>",
|
|
888
|
+
"<h3>The columns</h3>",
|
|
889
|
+
"<dl>",
|
|
890
|
+
"<dt>Task</dt><dd>The call chain. The first segment is the runner, the last is the task's own name. ",
|
|
891
|
+
"The middle is <strong>grouping this page adds</strong> so hundreds of names stay scannable — it is not part of any command. ",
|
|
892
|
+
"Hover a segment to see what that position means for its runner.</dd>",
|
|
893
|
+
"<dt>Command</dt><dd>Exactly what to type. Nearly every command is written to run <strong>from the repository root</strong>, which is why you see flags like ",
|
|
894
|
+
"<code>--cwd</code>, <code>-C</code> and <code>--justfile</code>. Where a task can only run from its own directory, Copy prefixes the <code>cd</code> for you.</dd>",
|
|
895
|
+
"<dt>Runs</dt><dd>What the task actually executes, or the summary its runner documents where there is one. ",
|
|
896
|
+
"It is dropped on a narrow window, where it has too little room to say anything useful.</dd>",
|
|
897
|
+
"<dt>Service</dt><dd>The leftmost column carries row indicators. A filled green dot marks a service: a task that runs until you stop it — a dev server, a watcher. An outlined dot means that was inferred from the name rather than declared by the runner.</dd>",
|
|
898
|
+
"</dl>",
|
|
899
|
+
"<h3>The controls</h3>",
|
|
900
|
+
"<dl>",
|
|
901
|
+
"<dt>Depth</dt><dd>How far into the repository to look, by <strong>where a task is declared</strong>. ",
|
|
902
|
+
"<em>Root</em> is the handful the repository declares itself — its own justfile, package.json and moon project. Everything else belongs to one of its packages.</dd>",
|
|
903
|
+
"<dt>Services</dt><dd>Only services — tasks that run until you stop them: dev servers, watchers, previews. Marked with a dot in the leftmost column.</dd>",
|
|
904
|
+
"<dt>Declared</dt><dd>Drops tasks no file declares. <code>cargo test</code> and <code>ruff check .</code> are written down nowhere — they are what a crate, or a ruff-configured project, runs by convention.</dd>",
|
|
905
|
+
"<dt>Collapse</dt><dd>Folds the groups. Presentation only; it changes nothing about which tasks exist.</dd>",
|
|
906
|
+
"<dt>Runners</dt><dd>Which runners this page shows. Unchecking one drops it from the search and from every tab; it is still collected, so its count is current the moment you turn it back on.</dd>",
|
|
907
|
+
"<dt>Fuzzy / Exact</dt><dd>Terms are ANDed, so <code>photo dev</code> narrows to a photo app's dev server. A leading quote forces one term to match exactly, even in fuzzy mode.</dd>",
|
|
908
|
+
"</dl>",
|
|
909
|
+
"<h3>Why a runner might show nothing</h3>",
|
|
910
|
+
"<p>Some runners can only be read by running them — <code>moon query tasks</code> evaluates this repository's own toolchain configuration. ",
|
|
911
|
+
"Those keep their tab, marked <code>exec</code> beside the count, so a runner held back that way says so rather than pretending to be absent.</p>",
|
|
912
|
+
"<p>Reading them therefore needs your consent, remembered once per repository. Open a held-back runner's <code>i</code> button, or the Runners picker, for a button that records it. ",
|
|
913
|
+
"A repository cannot grant itself that: <code>allowExec</code> in <code>wayfinder.config.json</code> cannot raise the gate.</p>",
|
|
914
|
+
"<h3>Staying current</h3>",
|
|
915
|
+
"<p>The page refreshes when you focus it and on a slow poll, and <b>Refresh</b> always re-reads every runner for real — an explicit refresh that could be answered from a stored listing is not a refresh.</p>",
|
|
916
|
+
"<p>The very first paint may come from a stored listing so the page appears at once on a repository whose slowest runner takes seconds. When it does, the status bar names those runners after <code>cached:</code> and marks their tabs with <code>~</code>, and a fresh read is already running behind the page. Rows never come from a store without saying so.</p>"
|
|
917
|
+
].join("");
|
|
918
|
+
/**
|
|
919
|
+
* The header cell for the selection column: a checkbox mark, sized to sit with
|
|
920
|
+
* the row checkboxes below it. Presentational only — the accessible name comes
|
|
921
|
+
* from the button's aria-label, so a screen reader hears "Shown", not a shape.
|
|
922
|
+
*/
|
|
923
|
+
const CHECK_GLYPH = "<svg viewBox=\"0 0 16 16\" width=\"11\" height=\"11\" aria-hidden=\"true\" focusable=\"false\"><rect x=\"1.5\" y=\"1.5\" width=\"13\" height=\"13\" rx=\"2.5\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.6\"/><path d=\"M4.5 8.4l2.4 2.4 4.6-5\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.8\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/></svg>";
|
|
924
|
+
/**
|
|
925
|
+
* The picker's sort header: three columns that reorder the one persisted order.
|
|
926
|
+
*
|
|
927
|
+
* The columns are emitted in the order the ROW puts them — shown, name, count.
|
|
928
|
+
* A header column names the thing underneath it, so it has to sit above the
|
|
929
|
+
* column it sorts; one placed elsewhere reads as a control belonging to
|
|
930
|
+
* whatever it is nearest.
|
|
931
|
+
*
|
|
932
|
+
* The row's leading drag handle is repeated here, hidden, rather than being
|
|
933
|
+
* replaced by a width. It is the same element and the same character, so the
|
|
934
|
+
* columns keep starting where the row's own content starts even if that handle
|
|
935
|
+
* ever changes.
|
|
936
|
+
*
|
|
937
|
+
* Real buttons, so the header is reachable by Tab and by voice. The arrow
|
|
938
|
+
* appears only while the current order IS that sort - after a drag breaks it,
|
|
939
|
+
* neither column claims anything. Count reads the live task counts, so it
|
|
940
|
+
* follows a refresh rather than a snapshot.
|
|
941
|
+
*/
|
|
942
|
+
function renderSortHead() {
|
|
943
|
+
const active = activeSort();
|
|
944
|
+
const col = (key, label, glyph) => {
|
|
945
|
+
const on = active?.key === key;
|
|
946
|
+
const next = on ? active.dir === 1 ? -1 : 1 : key === "name" ? 1 : -1;
|
|
947
|
+
const way = key === "shown" ? next === -1 ? "shown first" : "hidden first" : key === "count" ? next === -1 ? "most tasks first" : "fewest tasks first" : next === 1 ? "A to Z" : "Z to A";
|
|
948
|
+
return "<button class=\"picksort\" data-sort-runners=\"" + key + "\" data-sort-dir=\"" + next + "\" aria-pressed=\"" + on + "\" aria-label=\"" + label + "\" title=\"Order the runners " + way + "\">" + (glyph ?? label) + "<span class=\"sortdir\" aria-hidden=\"true\">" + (on ? active.dir === 1 ? "▲" : "▼" : "") + "</span></button>";
|
|
949
|
+
};
|
|
950
|
+
return "<div class=\"pickhead\"><span class=\"grip\" aria-hidden=\"true\">⠿</span>" + col("shown", "Shown", CHECK_GLYPH) + col("name", "Name") + col("count", "Count") + "</div>";
|
|
951
|
+
}
|
|
952
|
+
/**
|
|
953
|
+
* The runner picker, a control in the toolbar's Scope cluster.
|
|
954
|
+
*
|
|
955
|
+
* A DISABLED runner is still collected — the library probes what it probes —
|
|
956
|
+
* and only hidden here. That keeps the toggle instant, and the counts you see
|
|
957
|
+
* when you re-enable one are current rather than stale. A runner that failed to
|
|
958
|
+
* probe still lists, with its error, so unchecking it silences a broken one.
|
|
959
|
+
*/
|
|
960
|
+
function renderRunnerPicker(cat) {
|
|
961
|
+
const enabled = state.enabled;
|
|
962
|
+
const items = runnerOrder().map((id) => cat.reports.find((r) => r.runner === id)).filter((s) => s !== void 0).map((s) => {
|
|
963
|
+
const on = enabled.has(s.runner);
|
|
964
|
+
const note = s.status === "error" ? " (failed)" : s.skippedForExec ? state.trustable ? " (not trusted)" : " (needs --exec)" : "";
|
|
965
|
+
const grant = s.skippedForExec && state.trustable ? TRUST_BUTTON : "";
|
|
966
|
+
const info = s.chain.length ? "<button class=\"tabinfo\" data-info-runner=\"" + escapeHtml(s.runner) + "\" title=\"What " + escapeHtml(s.runner) + "'s path segments mean\" aria-label=\"About " + escapeHtml(s.runner) + "\">i</button>" : "";
|
|
967
|
+
return "<div class=\"pick\" draggable=\"true\" data-drag-runner=\"" + escapeHtml(s.runner) + "\"><span class=\"grip\" title=\"Drag to reorder\">⠿</span><label class=\"pick-label\"><input type=\"checkbox\" data-toggle-runner=\"" + escapeHtml(s.runner) + "\"" + (on ? " checked" : "") + " /> " + iconHtml(s.runner) + escapeHtml(s.runner) + "<span class=\"count\">" + s.tasks.length + escapeHtml(note) + "</span></label>" + grant + info + "</div>";
|
|
968
|
+
}).join("");
|
|
969
|
+
const off = cat.reports.length - enabled.size;
|
|
970
|
+
return "<div class=\"picker\"><button class=\"toolbtn\" id=\"pickbtn\" aria-expanded=\"false\" title=\"Choose which runners to search and display\">Runners" + (off > 0 ? " <span class=\"count\">" + off + " off</span>" : "") + "</button><div class=\"pickmenu\" id=\"pickmenu\" hidden>" + renderSortHead() + items + "<div class=\"pickactions\"><button data-pick-all=\"1\">All</button><button data-pick-none=\"1\">None</button></div><p class=\"picknote\">Filters this session only. <button class=\"linkish\" data-open-settings=\"1\">Settings</button> turns a runner off for the project.</p></div></div>";
|
|
971
|
+
}
|
|
972
|
+
/** Every body row in #out, in document order across all of the group tables. */
|
|
973
|
+
function listRows() {
|
|
974
|
+
return [...$("out").querySelectorAll("tbody tr")];
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* Which row Enter takes, and where the single tab stop into the list sits.
|
|
978
|
+
*
|
|
979
|
+
* Two meanings, by whether a row is focused. While `focusedId` names a row the
|
|
980
|
+
* mark follows it: Enter there copies the row you are on. The mark reverts to
|
|
981
|
+
* the top hit when `focusedId` is cleared, which is what the search box's own
|
|
982
|
+
* focus handler does (see input.ts) — moving to a toolbar button leaves the
|
|
983
|
+
* row marked, because Enter from there still belongs to that button, not to
|
|
984
|
+
* the list. The top hit is only marked while a query is active: with no query
|
|
985
|
+
* there is no "top" anything, and a permanently marked first row would be a
|
|
986
|
+
* lie about what the key does.
|
|
987
|
+
*
|
|
988
|
+
* A focused row whose task no longer exists (a filter dropped it) clears
|
|
989
|
+
* `focusedId` rather than leaving the list marked with a row that is gone.
|
|
990
|
+
*/
|
|
991
|
+
function markEnterTarget() {
|
|
992
|
+
const rows = listRows();
|
|
993
|
+
for (const r of rows) {
|
|
994
|
+
r.classList.remove("enter-target");
|
|
995
|
+
r.tabIndex = -1;
|
|
996
|
+
}
|
|
997
|
+
let target = null;
|
|
998
|
+
if (state.focusedId !== null) {
|
|
999
|
+
target = rows.find((r) => r.dataset.id === state.focusedId) ?? null;
|
|
1000
|
+
if (!target) state.focusedId = null;
|
|
1001
|
+
}
|
|
1002
|
+
if (!target && terms(state.query).length > 0) target = rows[0] ?? null;
|
|
1003
|
+
if (target) target.classList.add("enter-target");
|
|
1004
|
+
const roving = target ?? rows[0];
|
|
1005
|
+
if (roving) roving.tabIndex = 0;
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
1008
|
+
* Move the list's keyboard focus to `id`, or off the list entirely with null.
|
|
1009
|
+
*
|
|
1010
|
+
* Re-marks rather than re-rendering: the rows themselves have not changed, and
|
|
1011
|
+
* a full render() on every arrow key would rebuild the whole table to move one
|
|
1012
|
+
* class.
|
|
1013
|
+
*/
|
|
1014
|
+
function setFocusedRow(id) {
|
|
1015
|
+
state.focusedId = id;
|
|
1016
|
+
markEnterTarget();
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* One runner's own explanation: what each position of its path selects, how
|
|
1020
|
+
* it is read, and whether reading it means running anything.
|
|
1021
|
+
*
|
|
1022
|
+
* This is what the legend's chain chips used to say, for every runner at
|
|
1023
|
+
* once. Asked for one runner at a time it fits, and it can say more than a
|
|
1024
|
+
* chip had room for.
|
|
1025
|
+
*/
|
|
1026
|
+
function showRunnerInfo(runner) {
|
|
1027
|
+
const report = (state.catalog?.reports || []).find((r) => r.runner === runner);
|
|
1028
|
+
if (!report) return;
|
|
1029
|
+
const shape = report.chain.map((c, i) => i === 0 ? runner : c.label).join(" › ");
|
|
1030
|
+
const rows = report.chain.map((c, i) => "<dt>" + escapeHtml(i === 0 ? runner : c.label) + "</dt><dd>" + escapeHtml(c.hint) + "</dd>").join("");
|
|
1031
|
+
const notes = [];
|
|
1032
|
+
if (report.skippedForExec) {
|
|
1033
|
+
notes.push("<p>Not collected right now. " + execNote() + "</p>");
|
|
1034
|
+
if (state.trustable) notes.push("<p>" + TRUST_BUTTON + "</p>");
|
|
1035
|
+
}
|
|
1036
|
+
if (report.status === "error") notes.push("<p>This runner failed to probe. Its diagnostic is shown above the list.</p>");
|
|
1037
|
+
for (const d of report.diagnostics) {
|
|
1038
|
+
if (d.severity !== "info") continue;
|
|
1039
|
+
notes.push("<p>" + escapeHtml(d.message) + "</p>");
|
|
1040
|
+
}
|
|
1041
|
+
$("help-body").innerHTML = "<h3>" + escapeHtml(runner) + "</h3><p>A task from this runner reads <code>" + escapeHtml(shape) + "</code>.</p><dl>" + rows + "</dl>" + notes.join("") + "<p>" + escapeHtml(String(report.tasks.length)) + " task(s) found.</p>";
|
|
1042
|
+
$("help").showModal();
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* The column heads, drawn as their own depth-0 table in the chrome. Putting a
|
|
1046
|
+
* `thead` in each group's table would repeat the row down the whole page;
|
|
1047
|
+
* this stays put and still lines up, because every table's command column
|
|
1048
|
+
* starts at the same x whatever its depth.
|
|
1049
|
+
*/
|
|
1050
|
+
function renderColHeads() {
|
|
1051
|
+
const cells = COLUMNS.filter((c) => c.label !== "Runs" || showRuns()).map((c) => "<th title=\"" + escapeHtml(c.tip) + "\">" + (escapeHtml(c.label) || " ") + "</th>").join("");
|
|
1052
|
+
$("colheads").innerHTML = "<table>" + colgroup(0) + "<thead><tr>" + cells + "</tr></thead></table>";
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* The cache's three states, as one status span — the same three the TUI shows.
|
|
1056
|
+
*
|
|
1057
|
+
* Fresh returns "": there is nothing to report, and a span that is always
|
|
1058
|
+
* present is a span nobody reads. Stale-and-SLOW is separated from ordinary
|
|
1059
|
+
* stale because it is the case the cache exists for — a runner MEASURED at
|
|
1060
|
+
* seconds is why the page has rows instead of a spinner, and it earns the
|
|
1061
|
+
* louder class. Slow is measured, never declared.
|
|
1062
|
+
*/
|
|
1063
|
+
function cacheSpan(rows) {
|
|
1064
|
+
const stale = rows.filter((r) => r.state === "stale");
|
|
1065
|
+
if (stale.length === 0) return "";
|
|
1066
|
+
const slow = stale.filter((r) => r.slow);
|
|
1067
|
+
const cost = (r) => r.estimateMs === null ? "never timed here" : "~" + humanMs(r.estimateMs);
|
|
1068
|
+
if (slow.length > 0) return "<span class=\"err\">cached: " + escapeHtml(slow.map((r) => r.runner + " (" + humanAge(r.ageMs) + ", " + cost(r) + ")").join(", ")) + " - slow to probe here, so re-reading takes a moment</span>";
|
|
1069
|
+
return "<span>cached: " + escapeHtml(stale.map((r) => r.runner + " " + humanAge(r.ageMs)).join(", ")) + " - re-probing</span>";
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Runners held back for want of execution, as the page's own bar above
|
|
1073
|
+
* everything — the equivalent of the CLI's "N runners not collected" line.
|
|
1074
|
+
*
|
|
1075
|
+
* This exists because the page used to say it NOWHERE at rest. The withholding
|
|
1076
|
+
* was on the tab as a three-letter badge, in that tab's tooltip, in the
|
|
1077
|
+
* per-runner modal and in the picker — every one of them behind a hover or a
|
|
1078
|
+
* click. Someone looking at a repository whose exec runners were all withheld
|
|
1079
|
+
* saw a shorter catalog and no statement that anything was missing, which is
|
|
1080
|
+
* the one thing this tool must never do quietly.
|
|
1081
|
+
*
|
|
1082
|
+
* Its own bar rather than a span in the status strip. The first attempt put it
|
|
1083
|
+
* there, between the clock and the keyboard hints, and it was wrong for a
|
|
1084
|
+
* reason worth keeping written down: that strip reports NUMBERS about what you
|
|
1085
|
+
* are looking at, and this asks for a DECISION about what you are not. A button
|
|
1086
|
+
* in a row of counts reads as one more piece of chrome.
|
|
1087
|
+
*
|
|
1088
|
+
* It names the runners rather than only counting them: "3 runners" invites the
|
|
1089
|
+
* question the sentence should already answer. The grant rides along only when
|
|
1090
|
+
* trust is what is missing — when it is not, execution is off for the session
|
|
1091
|
+
* and trusting the repository would change nothing, so offering it would be a
|
|
1092
|
+
* wrong instruction.
|
|
1093
|
+
*/
|
|
1094
|
+
function withheldBar(reports) {
|
|
1095
|
+
const held = reports.filter((s) => s.skippedForExec);
|
|
1096
|
+
if (held.length === 0) return "";
|
|
1097
|
+
const names = held.map((s) => s.runner).join(", ");
|
|
1098
|
+
const one = held.length === 1;
|
|
1099
|
+
const lead = held.length + (one ? " runner was" : " runners were") + " not read: ";
|
|
1100
|
+
const why = one ? "It can only be read by running it, and " : "They can only be read by running them, and ";
|
|
1101
|
+
const gate = state.trustable ? "this repository is not trusted yet." : "execution is off for this session.";
|
|
1102
|
+
return "<span>" + lead + "<span class=\"who\">" + escapeHtml(names) + "</span>. " + why + gate + "</span>" + (state.trustable ? TRUST_BUTTON : "");
|
|
1103
|
+
}
|
|
1104
|
+
/** Paint the trust bar, and hide it entirely when there is nothing to say. */
|
|
1105
|
+
function renderTrustBar() {
|
|
1106
|
+
const host = $("trustbar");
|
|
1107
|
+
const html = withheldBar(state.catalog?.reports || []);
|
|
1108
|
+
host.innerHTML = html;
|
|
1109
|
+
host.hidden = html === "";
|
|
1110
|
+
}
|
|
1111
|
+
/**
|
|
1112
|
+
* Kept separate from the table so an unchanged poll can refresh the clock
|
|
1113
|
+
* without touching the DOM under it. Otherwise pressing Refresh on a repo
|
|
1114
|
+
* that has not changed looks like nothing happened, and the timestamp claims
|
|
1115
|
+
* data is older than it was just verified to be.
|
|
1116
|
+
*/
|
|
1117
|
+
function renderStatus(shown, total) {
|
|
1118
|
+
const errs = (state.catalog?.reports || []).filter((s) => s.status === "error").map((s) => s.runner);
|
|
1119
|
+
$("status").innerHTML = "<span>" + shown + " of " + total + " " + (state.runner === "all" ? "commands, all runners" : state.runner + " commands") + "</span><span>checked " + new Date(state.checkedAt).toLocaleTimeString() + (state.loading ? " - refreshing" : "") + "</span>" + cacheSpan(state.cache) + (errs.length ? "<span class=\"err\">probe failed: " + errs.join(", ") + "</span>" : "") + "<span><kbd>/</kbd> search · <kbd>Enter</kbd> copy top hit · <kbd>↑</kbd><kbd>↓</kbd> move · <kbd>Esc</kbd> back to search, again to clear it</span>";
|
|
1120
|
+
}
|
|
1121
|
+
/**
|
|
1122
|
+
* The run bar: supply a parameterised task's arguments before handing over.
|
|
1123
|
+
*
|
|
1124
|
+
* The command PREFIX is static text, not part of the field. The server appends
|
|
1125
|
+
* what this sends to the argv it looked up itself and ignores anything else,
|
|
1126
|
+
* so an editable `just` that silently still ran `just` would be a control that
|
|
1127
|
+
* lies. Only the tail is yours to type, and the bar shows exactly that.
|
|
1128
|
+
*
|
|
1129
|
+
* A bar rather than a modal: it costs no click to dismiss, and the row that
|
|
1130
|
+
* opened it stays on screen behind it.
|
|
1131
|
+
*/
|
|
1132
|
+
function showRunBar(task) {
|
|
1133
|
+
hideRunBar();
|
|
1134
|
+
const el = document.createElement("div");
|
|
1135
|
+
el.id = "runbar";
|
|
1136
|
+
el.setAttribute("role", "group");
|
|
1137
|
+
el.setAttribute("aria-label", "Arguments for " + task.display);
|
|
1138
|
+
const shape = paramShape(task.parameters);
|
|
1139
|
+
el.innerHTML = "<div class=\"runbar-line\"><span class=\"runbar-sigil\" aria-hidden=\"true\">$</span><span class=\"runbar-cmd\">" + escapeHtml(task.argv.join(" ")) + "</span><input class=\"runbar-args\" type=\"text\" autocomplete=\"off\" spellcheck=\"false\" aria-label=\"Arguments\" /></div><div class=\"runbar-foot\"><span class=\"runbar-shape\">takes " + escapeHtml(shape) + "</span><span class=\"runbar-keys\"><kbd>Enter</kbd> run · <kbd>Esc</kbd> back</span></div>";
|
|
1140
|
+
document.body.append(el);
|
|
1141
|
+
const field = el.querySelector(".runbar-args");
|
|
1142
|
+
field.focus();
|
|
1143
|
+
return field;
|
|
1144
|
+
}
|
|
1145
|
+
/** Take the run bar down. Idempotent — `esc`, a run and a re-open all call it. */
|
|
1146
|
+
function hideRunBar() {
|
|
1147
|
+
document.getElementById("runbar")?.remove();
|
|
1148
|
+
}
|
|
1149
|
+
/**
|
|
1150
|
+
* The end of the page: the task now owns the terminal and this server is gone.
|
|
1151
|
+
*
|
|
1152
|
+
* It replaces the view rather than sitting beside it, because everything still
|
|
1153
|
+
* on screen is about to be a lie — the catalog cannot be refreshed, the
|
|
1154
|
+
* buttons cannot act, and a poll would only paint a failed fetch. Saying the
|
|
1155
|
+
* tab is finished is the honest state.
|
|
1156
|
+
*/
|
|
1157
|
+
function showHandoff(command) {
|
|
1158
|
+
const el = document.createElement("div");
|
|
1159
|
+
el.id = "handoff";
|
|
1160
|
+
el.setAttribute("data-handoff", "");
|
|
1161
|
+
el.setAttribute("role", "status");
|
|
1162
|
+
el.innerHTML = "<h2>Handed off to the terminal</h2><pre class=\"handoff-cmd\">" + escapeHtml(command) + "</pre><p>It is running in the shell wayfinder was started from. This page is done — you can close it.</p>";
|
|
1163
|
+
document.body.append(el);
|
|
1164
|
+
el.tabIndex = -1;
|
|
1165
|
+
el.focus();
|
|
1166
|
+
}
|
|
1167
|
+
/** Said on the row that asked, when another run got the terminal first. */
|
|
1168
|
+
function showRunTaken(button) {
|
|
1169
|
+
const cell = button.closest("td.act");
|
|
1170
|
+
if (!cell || cell.querySelector(".runerr")) return;
|
|
1171
|
+
const note = document.createElement("span");
|
|
1172
|
+
note.className = "runerr";
|
|
1173
|
+
note.setAttribute("role", "status");
|
|
1174
|
+
note.textContent = "another run already took the terminal";
|
|
1175
|
+
cell.append(note);
|
|
1176
|
+
setTimeout(() => note.remove(), 4e3);
|
|
1177
|
+
}
|
|
1178
|
+
/**
|
|
1179
|
+
* Publish the sticky chrome's real height as a CSS variable. It is measured
|
|
1180
|
+
* rather than hard-coded because the search row and the status line wrap at narrow
|
|
1181
|
+
* widths, and a stale number would either hide the first group header behind
|
|
1182
|
+
* the chrome or leave a gap under it.
|
|
1183
|
+
*/
|
|
1184
|
+
function measureChrome() {
|
|
1185
|
+
document.documentElement.style.setProperty("--chrome-h", Math.round($("chrome").getBoundingClientRect().height) + "px");
|
|
1186
|
+
}
|
|
1187
|
+
//#endregion
|
|
1188
|
+
//#region src/args.ts
|
|
1189
|
+
/**
|
|
1190
|
+
* Split a typed argument tail the way a shell splits words, and in no other
|
|
1191
|
+
* way a shell behaves.
|
|
1192
|
+
*
|
|
1193
|
+
* Quotes group and a backslash escapes the next character. There is no
|
|
1194
|
+
* globbing, no variable expansion, no operators, no substitution: the result
|
|
1195
|
+
* goes to an `execvp`-style spawn as separate argv entries, never to a shell,
|
|
1196
|
+
* so `*.log` is passed through as the four characters somebody typed. That is
|
|
1197
|
+
* the same rule `argv` and `display` exist to keep.
|
|
1198
|
+
*
|
|
1199
|
+
* Splitting rather than `.split(/\s+/)` for exactly one reason: a quoted
|
|
1200
|
+
* `"two words"` has to stay ONE argument.
|
|
1201
|
+
*/
|
|
1202
|
+
function splitArgs(input) {
|
|
1203
|
+
const out = [];
|
|
1204
|
+
let current = "";
|
|
1205
|
+
let started = false;
|
|
1206
|
+
let quote = null;
|
|
1207
|
+
for (let i = 0; i < input.length; i++) {
|
|
1208
|
+
const ch = input[i];
|
|
1209
|
+
if (ch === "\\" && i + 1 < input.length) {
|
|
1210
|
+
current += input[++i];
|
|
1211
|
+
started = true;
|
|
1212
|
+
continue;
|
|
1213
|
+
}
|
|
1214
|
+
if (quote === null && (ch === "\"" || ch === "'")) {
|
|
1215
|
+
quote = ch;
|
|
1216
|
+
started = true;
|
|
1217
|
+
continue;
|
|
1218
|
+
}
|
|
1219
|
+
if (quote === ch) {
|
|
1220
|
+
quote = null;
|
|
1221
|
+
continue;
|
|
1222
|
+
}
|
|
1223
|
+
if (quote === null && /\s/.test(ch)) {
|
|
1224
|
+
if (started) {
|
|
1225
|
+
out.push(current);
|
|
1226
|
+
current = "";
|
|
1227
|
+
started = false;
|
|
1228
|
+
}
|
|
1229
|
+
continue;
|
|
1230
|
+
}
|
|
1231
|
+
current += ch;
|
|
1232
|
+
started = true;
|
|
1233
|
+
}
|
|
1234
|
+
if (started) out.push(current);
|
|
1235
|
+
return out;
|
|
1236
|
+
}
|
|
1237
|
+
//#endregion
|
|
1238
|
+
//#region src/app.ts
|
|
1239
|
+
/**
|
|
1240
|
+
* The app's names. Every user-facing name that carries the product name
|
|
1241
|
+
* derives from here. Browser-safe: the page imports it too.
|
|
1242
|
+
*/
|
|
1243
|
+
/** The product name: config directory, cache directory, trust store key, message prefix. */
|
|
1244
|
+
const APP = "wayfinder";
|
|
1245
|
+
/**
|
|
1246
|
+
* The name before the rename to wayfinder. Its user config, project config,
|
|
1247
|
+
* trust store and config variable are still read when the new ones are
|
|
1248
|
+
* absent. Nothing is written under it.
|
|
1249
|
+
*/
|
|
1250
|
+
const LEGACY_APP = "waypost";
|
|
1251
|
+
`${APP.toUpperCase()}`;
|
|
1252
|
+
`${LEGACY_APP.toUpperCase()}`;
|
|
1253
|
+
/** The request header that carries the web view's session token. */
|
|
1254
|
+
const TOKEN_HEADER = `x-${APP}-token`;
|
|
1255
|
+
//#endregion
|
|
1256
|
+
//#region src/web/api.ts
|
|
1257
|
+
/**
|
|
1258
|
+
* The session token the server embedded in this page, read once at import.
|
|
1259
|
+
*
|
|
1260
|
+
* Module state and nothing else. localStorage, sessionStorage and cookies all
|
|
1261
|
+
* outlive the tab or ride along on requests the page did not make; this dies
|
|
1262
|
+
* with the page, which is the lifetime it should have.
|
|
1263
|
+
*/
|
|
1264
|
+
const token = globalThis.__WAYFINDER_TOKEN__ ?? "";
|
|
1265
|
+
/**
|
|
1266
|
+
* Every server call goes through here — the one place the token is attached.
|
|
1267
|
+
*
|
|
1268
|
+
* The endpoints are on loopback, which any process on this machine and any
|
|
1269
|
+
* page the user is visiting can reach, so reads and mutations alike carry the
|
|
1270
|
+
* token. Route new endpoints through here; one that skips it gets a 401,
|
|
1271
|
+
* which is the point.
|
|
1272
|
+
*/
|
|
1273
|
+
function authFetch(path, init = {}) {
|
|
1274
|
+
const headers = new Headers(init.headers);
|
|
1275
|
+
headers.set(TOKEN_HEADER, token);
|
|
1276
|
+
return fetch(path, {
|
|
1277
|
+
...init,
|
|
1278
|
+
headers,
|
|
1279
|
+
cache: "no-store"
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
/** Read this project's configuration, or null when the request fails. */
|
|
1283
|
+
async function getConfig() {
|
|
1284
|
+
try {
|
|
1285
|
+
const res = await authFetch("/api/config");
|
|
1286
|
+
if (!res.ok) return null;
|
|
1287
|
+
return await res.json();
|
|
1288
|
+
} catch {
|
|
1289
|
+
return null;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* Write staged settings to the project file, and read back what that produced.
|
|
1294
|
+
*
|
|
1295
|
+
* A PATCH of dotted keys, matching what `way config set` names. The server
|
|
1296
|
+
* applies it to the file's raw contents, so a key this version does not know
|
|
1297
|
+
* survives the save — see `writeProjectConfig` in serve.ts.
|
|
1298
|
+
*
|
|
1299
|
+
* The success arm carries the config as it now IS rather than as the caller
|
|
1300
|
+
* hoped: one round trip, and the screen re-renders from the file.
|
|
1301
|
+
*/
|
|
1302
|
+
async function saveConfig(set) {
|
|
1303
|
+
try {
|
|
1304
|
+
const res = await authFetch("/api/config", {
|
|
1305
|
+
method: "POST",
|
|
1306
|
+
headers: { "content-type": "application/json" },
|
|
1307
|
+
body: JSON.stringify({ set })
|
|
1308
|
+
});
|
|
1309
|
+
if (!res.ok) return {
|
|
1310
|
+
ok: false,
|
|
1311
|
+
detail: await res.text() || `the server answered ${res.status}`
|
|
1312
|
+
};
|
|
1313
|
+
return {
|
|
1314
|
+
ok: true,
|
|
1315
|
+
config: await res.json()
|
|
1316
|
+
};
|
|
1317
|
+
} catch (err) {
|
|
1318
|
+
return {
|
|
1319
|
+
ok: false,
|
|
1320
|
+
detail: err instanceof TypeError ? "the server is gone" : String(err)
|
|
1321
|
+
};
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
/**
|
|
1325
|
+
* Grant this repository trust, then re-render from what comes back.
|
|
1326
|
+
*
|
|
1327
|
+
* The server returns a freshly probed catalog with the grant already applied,
|
|
1328
|
+
* so the runners appear in one round trip rather than after the next poll.
|
|
1329
|
+
*/
|
|
1330
|
+
async function trustRepo() {
|
|
1331
|
+
try {
|
|
1332
|
+
const res = await authFetch("/api/trust", { method: "POST" });
|
|
1333
|
+
if (!res.ok) {
|
|
1334
|
+
$("status").innerHTML = "<span class=\"err\">trust failed: " + escapeHtml(await res.text()) + " (HTTP " + res.status + ")</span>";
|
|
1335
|
+
return;
|
|
1336
|
+
}
|
|
1337
|
+
const cat = await res.json();
|
|
1338
|
+
state.catalog = cat;
|
|
1339
|
+
state.trustable = cat.trustable === true;
|
|
1340
|
+
state.cache = cat.cache ?? [];
|
|
1341
|
+
state.checkedAt = cat.generatedAt;
|
|
1342
|
+
state.fingerprint = "";
|
|
1343
|
+
render();
|
|
1344
|
+
if (cat.note !== void 0) $("status").textContent = cat.note;
|
|
1345
|
+
} catch (err) {
|
|
1346
|
+
$("status").innerHTML = "<span class=\"err\">trust failed: " + escapeHtml(String(err)) + " (is the server still running?)</span>";
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
/**
|
|
1350
|
+
* Revoke this repository's trust.
|
|
1351
|
+
*
|
|
1352
|
+
* The store is the durable answer and this makes it `false`. The RUNNING
|
|
1353
|
+
* session keeps whatever execution gate it resolved at startup — see the
|
|
1354
|
+
* DELETE branch in serve.ts for why the server will not guess whether that
|
|
1355
|
+
* came from the store or from an explicit `--exec`. The caller shows that
|
|
1356
|
+
* rather than implying a revoke the process did not perform.
|
|
1357
|
+
*/
|
|
1358
|
+
async function untrustRepo() {
|
|
1359
|
+
try {
|
|
1360
|
+
const res = await authFetch("/api/trust", { method: "DELETE" });
|
|
1361
|
+
if (!res.ok) return {
|
|
1362
|
+
ok: false,
|
|
1363
|
+
detail: await res.text() || `the server answered ${res.status}`
|
|
1364
|
+
};
|
|
1365
|
+
const cat = await res.json();
|
|
1366
|
+
state.catalog = cat;
|
|
1367
|
+
state.trustable = cat.trustable === true;
|
|
1368
|
+
state.cache = cat.cache ?? [];
|
|
1369
|
+
render();
|
|
1370
|
+
return { ok: true };
|
|
1371
|
+
} catch (err) {
|
|
1372
|
+
return {
|
|
1373
|
+
ok: false,
|
|
1374
|
+
detail: err instanceof TypeError ? "the server is gone" : String(err)
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
/**
|
|
1379
|
+
* Ask the server to hand its terminal to a task.
|
|
1380
|
+
*
|
|
1381
|
+
* The id selects the command; `args` is the tail a parameterised recipe needs
|
|
1382
|
+
* (`staging` for `just deploy <env>`). The server looks the task up in the
|
|
1383
|
+
* catalog it built itself and APPENDS these — the binary, the leading
|
|
1384
|
+
* arguments and the cwd never come from here, because a command sent from this
|
|
1385
|
+
* side would be a command the server was told to run by whatever could reach
|
|
1386
|
+
* the port.
|
|
1387
|
+
*/
|
|
1388
|
+
async function requestRun(id, args = []) {
|
|
1389
|
+
try {
|
|
1390
|
+
const res = await authFetch("/api/run", {
|
|
1391
|
+
method: "POST",
|
|
1392
|
+
headers: { "content-type": "application/json" },
|
|
1393
|
+
body: JSON.stringify({
|
|
1394
|
+
id,
|
|
1395
|
+
args
|
|
1396
|
+
})
|
|
1397
|
+
});
|
|
1398
|
+
if (res.status === 409) return { outcome: "taken" };
|
|
1399
|
+
if (res.status === 404) return {
|
|
1400
|
+
outcome: "failed",
|
|
1401
|
+
detail: await res.text().catch(() => "") || "the server answered 404"
|
|
1402
|
+
};
|
|
1403
|
+
if (!res.ok) return {
|
|
1404
|
+
outcome: "failed",
|
|
1405
|
+
detail: "the server answered " + res.status
|
|
1406
|
+
};
|
|
1407
|
+
const body = await res.json();
|
|
1408
|
+
return {
|
|
1409
|
+
outcome: "handed-off",
|
|
1410
|
+
command: body.argv?.join(" ") || body.display || "the task"
|
|
1411
|
+
};
|
|
1412
|
+
} catch (err) {
|
|
1413
|
+
if (err instanceof TypeError) return { outcome: "gone" };
|
|
1414
|
+
return {
|
|
1415
|
+
outcome: "failed",
|
|
1416
|
+
detail: String(err)
|
|
1417
|
+
};
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
/**
|
|
1421
|
+
* Pull the catalog.
|
|
1422
|
+
*
|
|
1423
|
+
* `force` is the Refresh button, and it is always a real probe of every runner
|
|
1424
|
+
* — an explicit refresh that could be answered from a store is not a refresh.
|
|
1425
|
+
* An unforced call (first paint, focus, the poll) takes whatever the server has
|
|
1426
|
+
* freshest, which on the very first request is the stored answer with a probe
|
|
1427
|
+
* already running behind it; `state.cache` says which rows those were.
|
|
1428
|
+
*
|
|
1429
|
+
* The fingerprint check keeps an unchanged poll from blowing away scroll
|
|
1430
|
+
* position and open groups.
|
|
1431
|
+
*/
|
|
1432
|
+
async function load(force) {
|
|
1433
|
+
if (state.loading) return;
|
|
1434
|
+
state.loading = true;
|
|
1435
|
+
try {
|
|
1436
|
+
const res = await authFetch("/api/catalog" + (force ? "?force=1" : ""));
|
|
1437
|
+
if (!res.ok) throw new Error(`the server answered ${res.status}`);
|
|
1438
|
+
const cat = await res.json();
|
|
1439
|
+
const fp = JSON.stringify(cat.reports.map((s) => [
|
|
1440
|
+
s.runner,
|
|
1441
|
+
s.status,
|
|
1442
|
+
s.tasks.map((e) => e.display + " " + (e.doc || ""))
|
|
1443
|
+
]));
|
|
1444
|
+
state.loading = false;
|
|
1445
|
+
state.checkedAt = cat.generatedAt;
|
|
1446
|
+
state.trustable = cat.trustable === true;
|
|
1447
|
+
state.cache = cat.cache ?? [];
|
|
1448
|
+
if (fp === state.fingerprint && state.catalog) {
|
|
1449
|
+
const inScope = scopedReports().reduce((n, s) => n + s.tasks.length, 0);
|
|
1450
|
+
renderStatus(listRows().length, inScope);
|
|
1451
|
+
renderTrustBar();
|
|
1452
|
+
return;
|
|
1453
|
+
}
|
|
1454
|
+
state.fingerprint = fp;
|
|
1455
|
+
state.catalog = cat;
|
|
1456
|
+
render();
|
|
1457
|
+
} catch (err) {
|
|
1458
|
+
state.loading = false;
|
|
1459
|
+
$("status").innerHTML = "<span class=\"err\">refresh failed: " + escapeHtml(String(err)) + " (is the server still running?)</span>";
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
//#endregion
|
|
1463
|
+
//#region src/web/settings.ts
|
|
1464
|
+
/**
|
|
1465
|
+
* The settings screen — this project's configuration, and edits to it.
|
|
1466
|
+
*
|
|
1467
|
+
* Edits STAGE: nothing here writes until Save. The project config is a
|
|
1468
|
+
* committed file, so a click must not dirty someone's working tree silently.
|
|
1469
|
+
*
|
|
1470
|
+
* It is deliberately NOT the runner picker. The picker in the header filters
|
|
1471
|
+
* this session and forgets; this describes what the project uses at all.
|
|
1472
|
+
*
|
|
1473
|
+
* Section order follows the config schema's own key order — runners,
|
|
1474
|
+
* execution, discovery, excluded paths — so the screen reads like the file it
|
|
1475
|
+
* describes.
|
|
1476
|
+
*
|
|
1477
|
+
* STATE LIVES HERE, not in `state.ts`. The staged document is the dialog's
|
|
1478
|
+
* own and meaningless once the dialog closes; in the page-wide `AppState`
|
|
1479
|
+
* every consumer would carry a field about a screen they never open.
|
|
1480
|
+
*/
|
|
1481
|
+
/** What the server last told us the configuration is. */
|
|
1482
|
+
let loaded = null;
|
|
1483
|
+
/** Runner ids the catalog reported — the config alone cannot supply them. */
|
|
1484
|
+
let knownRunners = [];
|
|
1485
|
+
/**
|
|
1486
|
+
* Edits not yet written, by dotted key. Empty means clean — that is the whole
|
|
1487
|
+
* dirty test; a separate boolean could disagree with it.
|
|
1488
|
+
*/
|
|
1489
|
+
let staged = {};
|
|
1490
|
+
/** A message from the last Save, shown until the next render clears it. */
|
|
1491
|
+
let notice = null;
|
|
1492
|
+
/** The value a key would have if Save were pressed now. */
|
|
1493
|
+
function valueOf(key) {
|
|
1494
|
+
if (key in staged) return staged[key];
|
|
1495
|
+
let cursor = loaded?.effective ?? {};
|
|
1496
|
+
for (const segment of key.split(".")) {
|
|
1497
|
+
if (typeof cursor !== "object" || cursor === null) return void 0;
|
|
1498
|
+
cursor = cursor[segment];
|
|
1499
|
+
}
|
|
1500
|
+
return cursor;
|
|
1501
|
+
}
|
|
1502
|
+
function stringsAt(key) {
|
|
1503
|
+
const value = valueOf(key);
|
|
1504
|
+
return Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
|
|
1505
|
+
}
|
|
1506
|
+
/**
|
|
1507
|
+
* Stage a value, or drop the edit when it matches what the file already says.
|
|
1508
|
+
*
|
|
1509
|
+
* Dropping matters: toggling a checkbox and toggling it back should leave the
|
|
1510
|
+
* screen clean, not offer to save a no-op.
|
|
1511
|
+
*/
|
|
1512
|
+
function stage(key, value) {
|
|
1513
|
+
const original = (() => {
|
|
1514
|
+
const before = staged;
|
|
1515
|
+
staged = {};
|
|
1516
|
+
const v = valueOf(key);
|
|
1517
|
+
staged = before;
|
|
1518
|
+
return v;
|
|
1519
|
+
})();
|
|
1520
|
+
if (JSON.stringify(original) === JSON.stringify(value)) delete staged[key];
|
|
1521
|
+
else staged[key] = value;
|
|
1522
|
+
}
|
|
1523
|
+
function isDirty() {
|
|
1524
|
+
return Object.keys(staged).length > 0;
|
|
1525
|
+
}
|
|
1526
|
+
/** Where a value came from, said the way `way config list` says it. */
|
|
1527
|
+
function layerNote(key) {
|
|
1528
|
+
if (key in staged) return "<span class=\"set-layer\" data-layer=\"staged\">unsaved</span>";
|
|
1529
|
+
const layer = loaded?.sources[key] ?? "default";
|
|
1530
|
+
const where = layer === "project" ? "this project" : layer === "user" ? "your user config" : "the default";
|
|
1531
|
+
return "<span class=\"set-layer\" data-layer=\"" + layer + "\">" + escapeHtml(where) + "</span>";
|
|
1532
|
+
}
|
|
1533
|
+
function section(title, key, body) {
|
|
1534
|
+
return "<section class=\"set-section\"><h3>" + escapeHtml(title) + layerNote(key) + "</h3>" + body + "</section>";
|
|
1535
|
+
}
|
|
1536
|
+
function runnersSection() {
|
|
1537
|
+
const localOrder = restoreRunnerOrder();
|
|
1538
|
+
const disabled = new Set(stringsAt("runners.disabled"));
|
|
1539
|
+
const names = [.../* @__PURE__ */ new Set([...knownRunners, ...disabled])].sort();
|
|
1540
|
+
const rows = names.map((name) => {
|
|
1541
|
+
const on = !disabled.has(name);
|
|
1542
|
+
return "<tr><td><input type=\"checkbox\" data-set-runner=\"" + escapeHtml(name) + "\"" + (on ? " checked" : "") + " aria-label=\"Collect " + escapeHtml(name) + "\" /></td><td><code>" + escapeHtml(name) + "</code></td><td class=\"set-state\">" + (on ? "collected" : "not collected") + "</td></tr>";
|
|
1543
|
+
}).join("");
|
|
1544
|
+
const order = stringsAt("runners.order");
|
|
1545
|
+
return section("Runners", "runners.disabled", (names.length === 0 ? "<p class=\"set-empty\">no runners detected</p>" : "<table class=\"set-table\"><tbody>" + rows + "</tbody></table>") + "<p class=\"set-sub\">Order: " + (order.length === 0 ? "alphabetical" : order.map((r) => "<code>" + escapeHtml(r) + "</code>").join(" ")) + "</p>" + (localOrder.length === 0 ? "" : "<p class=\"set-sub set-override\">A dragged order is in force in this browser and wins over the setting above.<button data-reset-order=\"1\">Reset to configured order</button></p>"));
|
|
1546
|
+
}
|
|
1547
|
+
function executionSection() {
|
|
1548
|
+
const config = loaded;
|
|
1549
|
+
const running = state.catalog?.allowExec === true;
|
|
1550
|
+
const trust = config.trusted ? "This repository is trusted, so runners may spawn probes." : running ? "This repository is not trusted, but execution is on for this session — the gate was resolved when wayfinder started and does not change while it runs." : config.trustable ? "This repository is not trusted, so runners that must be run to be read were skipped." : "Execution is off for this project, and trusting the repository would not change that.";
|
|
1551
|
+
const action = config.trusted ? "<button data-untrust-repo=\"1\">Untrust</button>" : config.trustable ? "<button data-trust-repo-settings=\"1\">Trust this repository</button>" : "";
|
|
1552
|
+
return section("Execution", "allowExec", "<p>" + escapeHtml(trust) + "</p>" + (action === "" ? "" : "<div class=\"set-actions set-inline\">" + action + "</div>") + "<p class=\"set-sub\"><code>allowExec</code>: <code>" + String(valueOf("allowExec") === true) + "</code></p><p class=\"set-sub\">A project file can only turn execution <em>off</em>. Turning it on is the trust grant — a repository cannot grant itself permission to run its own code.</p>");
|
|
1553
|
+
}
|
|
1554
|
+
const DISCOVERY_MODES = [
|
|
1555
|
+
"auto",
|
|
1556
|
+
"git",
|
|
1557
|
+
"walk"
|
|
1558
|
+
];
|
|
1559
|
+
function discoverySection() {
|
|
1560
|
+
const current = valueOf("discovery");
|
|
1561
|
+
return section("Discovery", "discovery", "<div class=\"set-radios\">" + DISCOVERY_MODES.map((mode) => "<label><input type=\"radio\" name=\"set-discovery\" data-set-discovery=\"" + mode + "\"" + (current === mode ? " checked" : "") + " /> <code>" + mode + "</code></label>").join("") + "</div><p class=\"set-sub\"><code>auto</code> uses git when the root is a repository and walks it otherwise.</p>");
|
|
1562
|
+
}
|
|
1563
|
+
function excludedSection() {
|
|
1564
|
+
const paths = stringsAt("excludePaths");
|
|
1565
|
+
return section("Excluded paths", "excludePaths", (paths.length === 0 ? "<p class=\"set-empty\">none</p>" : "<ul class=\"set-list\">" + paths.map((p, i) => "<li><code>" + escapeHtml(p) + "</code><button class=\"set-x\" data-drop-path=\"" + i + "\" aria-label=\"Remove " + escapeHtml(p) + "\">×</button></li>").join("") + "</ul>") + "<div class=\"set-add\"><input type=\"text\" id=\"set-path\" placeholder=\"vendor, or src/fixtures\" aria-label=\"Path to exclude\" /><button data-add-path=\"1\">Add</button></div><p class=\"set-sub\">A bare name matches any path segment; a value with a slash matches from the root. This narrows where runners look, and is not the same as turning a runner off.</p>");
|
|
1566
|
+
}
|
|
1567
|
+
/** The whole screen, from whatever the module currently holds. */
|
|
1568
|
+
function screen() {
|
|
1569
|
+
const config = loaded;
|
|
1570
|
+
if (config === null) return "<p class=\"set-empty\">Could not read the configuration — the server may have handed over the terminal. Start wayfinder again.</p>";
|
|
1571
|
+
const warnings = config.warnings.length === 0 ? "" : "<div class=\"set-warnings\">" + config.warnings.map((w) => "<p>" + escapeHtml(w) + "</p>").join("") + "</div>";
|
|
1572
|
+
const dirty = isDirty();
|
|
1573
|
+
const message = notice === null ? "" : "<p class=\"set-notice\" data-kind=\"" + notice.kind + "\">" + escapeHtml(notice.text) + "</p>";
|
|
1574
|
+
return "<div class=\"set-head\"><h2>Settings" + (dirty ? " <span class=\"set-dirty\">" + Object.keys(staged).length + " unsaved</span>" : "") + "</h2><p class=\"set-file\">" + escapeHtml(config.locations.project) + "</p></div>" + warnings + message + runnersSection() + executionSection() + discoverySection() + excludedSection() + "<div class=\"set-actions\"><button data-settings-revert=\"1\"" + (dirty ? "" : " disabled") + ">Revert</button><button data-settings-save=\"1\"" + (dirty ? "" : " disabled") + ">Save to wayfinder.config.json</button></div>";
|
|
1575
|
+
}
|
|
1576
|
+
/** Repaint the dialog body in place. */
|
|
1577
|
+
function repaint() {
|
|
1578
|
+
const body = document.getElementById("settings-body");
|
|
1579
|
+
if (body !== null) body.innerHTML = screen();
|
|
1580
|
+
}
|
|
1581
|
+
/**
|
|
1582
|
+
* Seed the screen from a fresh read and paint it.
|
|
1583
|
+
*
|
|
1584
|
+
* Staged edits are dropped: keeping them across a close would let a later Save
|
|
1585
|
+
* write something the person had walked away from.
|
|
1586
|
+
*/
|
|
1587
|
+
function openSettings(config, known) {
|
|
1588
|
+
loaded = config;
|
|
1589
|
+
knownRunners = known;
|
|
1590
|
+
staged = {};
|
|
1591
|
+
notice = null;
|
|
1592
|
+
return screen();
|
|
1593
|
+
}
|
|
1594
|
+
/**
|
|
1595
|
+
* Handle a click inside the settings dialog. Returns true when it was ours, so
|
|
1596
|
+
* the page's delegated listener can stop.
|
|
1597
|
+
*/
|
|
1598
|
+
function handleSettingsClick(target) {
|
|
1599
|
+
const runner = target.closest("[data-set-runner]");
|
|
1600
|
+
if (runner !== null) {
|
|
1601
|
+
const name = runner.dataset["setRunner"];
|
|
1602
|
+
const disabled = new Set(stringsAt("runners.disabled"));
|
|
1603
|
+
if (runner.checked) disabled.delete(name);
|
|
1604
|
+
else disabled.add(name);
|
|
1605
|
+
stage("runners.disabled", [...disabled].sort());
|
|
1606
|
+
repaint();
|
|
1607
|
+
return true;
|
|
1608
|
+
}
|
|
1609
|
+
const mode = target.closest("[data-set-discovery]");
|
|
1610
|
+
if (mode !== null) {
|
|
1611
|
+
stage("discovery", mode.dataset["setDiscovery"]);
|
|
1612
|
+
repaint();
|
|
1613
|
+
return true;
|
|
1614
|
+
}
|
|
1615
|
+
const drop = target.closest("[data-drop-path]");
|
|
1616
|
+
if (drop !== null) {
|
|
1617
|
+
const paths = stringsAt("excludePaths");
|
|
1618
|
+
paths.splice(Number(drop.dataset["dropPath"]), 1);
|
|
1619
|
+
stage("excludePaths", paths);
|
|
1620
|
+
repaint();
|
|
1621
|
+
return true;
|
|
1622
|
+
}
|
|
1623
|
+
if (target.closest("[data-add-path]") !== null) {
|
|
1624
|
+
const value = document.getElementById("set-path")?.value.trim() ?? "";
|
|
1625
|
+
if (value !== "") {
|
|
1626
|
+
stage("excludePaths", [...stringsAt("excludePaths"), value]);
|
|
1627
|
+
repaint();
|
|
1628
|
+
}
|
|
1629
|
+
return true;
|
|
1630
|
+
}
|
|
1631
|
+
if (target.closest("[data-trust-repo-settings]") !== null) {
|
|
1632
|
+
if (confirm("Trust this repository? Its runners will be read by running them, now and on every later visit, until you untrust it.")) trustRepo().then(reload);
|
|
1633
|
+
return true;
|
|
1634
|
+
}
|
|
1635
|
+
if (target.closest("[data-untrust-repo]") !== null) {
|
|
1636
|
+
untrustRepo().then((result) => {
|
|
1637
|
+
notice = result.ok ? {
|
|
1638
|
+
kind: "ok",
|
|
1639
|
+
text: "Untrusted. This session keeps the execution it started with — start wayfinder again to re-probe without it."
|
|
1640
|
+
} : {
|
|
1641
|
+
kind: "err",
|
|
1642
|
+
text: result.detail ?? "untrust failed"
|
|
1643
|
+
};
|
|
1644
|
+
reload();
|
|
1645
|
+
});
|
|
1646
|
+
return true;
|
|
1647
|
+
}
|
|
1648
|
+
if (target.closest("[data-reset-order]") !== null) {
|
|
1649
|
+
clearRunnerOrder();
|
|
1650
|
+
render();
|
|
1651
|
+
repaint();
|
|
1652
|
+
return true;
|
|
1653
|
+
}
|
|
1654
|
+
if (target.closest("[data-settings-revert]") !== null) {
|
|
1655
|
+
staged = {};
|
|
1656
|
+
notice = null;
|
|
1657
|
+
repaint();
|
|
1658
|
+
return true;
|
|
1659
|
+
}
|
|
1660
|
+
if (target.closest("[data-settings-save]") !== null) {
|
|
1661
|
+
commit();
|
|
1662
|
+
return true;
|
|
1663
|
+
}
|
|
1664
|
+
return false;
|
|
1665
|
+
}
|
|
1666
|
+
/**
|
|
1667
|
+
* Re-read the configuration and repaint, keeping any staged edits and the
|
|
1668
|
+
* current notice. Used after trust changes, which alter what the server
|
|
1669
|
+
* reports without touching what the person has typed.
|
|
1670
|
+
*/
|
|
1671
|
+
async function reload() {
|
|
1672
|
+
const fresh = await getConfig();
|
|
1673
|
+
if (fresh !== null) loaded = fresh;
|
|
1674
|
+
repaint();
|
|
1675
|
+
}
|
|
1676
|
+
/** Write the staged edits, then re-seed from what the server produced. */
|
|
1677
|
+
async function commit() {
|
|
1678
|
+
const result = await saveConfig(staged);
|
|
1679
|
+
if (result.ok) {
|
|
1680
|
+
loaded = result.config;
|
|
1681
|
+
staged = {};
|
|
1682
|
+
notice = {
|
|
1683
|
+
kind: "ok",
|
|
1684
|
+
text: "Saved."
|
|
1685
|
+
};
|
|
1686
|
+
} else notice = {
|
|
1687
|
+
kind: "err",
|
|
1688
|
+
text: result.detail
|
|
1689
|
+
};
|
|
1690
|
+
repaint();
|
|
1691
|
+
}
|
|
1692
|
+
//#endregion
|
|
1693
|
+
//#region src/web/input.ts
|
|
1694
|
+
/**
|
|
1695
|
+
* Ask for the terminal and deal with every way that ends.
|
|
1696
|
+
*
|
|
1697
|
+
* Shared by the row button and the run bar so the four outcomes are handled
|
|
1698
|
+
* once. `button`, when given, is disabled for the round trip: a double click
|
|
1699
|
+
* would otherwise send a second POST the server can only answer 409 to, and
|
|
1700
|
+
* "another run took the terminal" is a confusing thing to be told about
|
|
1701
|
+
* yourself.
|
|
1702
|
+
*/
|
|
1703
|
+
async function handOff(id, args, button) {
|
|
1704
|
+
if (button) button.disabled = true;
|
|
1705
|
+
const result = await requestRun(id, args);
|
|
1706
|
+
if (result.outcome === "handed-off") {
|
|
1707
|
+
stopPolling();
|
|
1708
|
+
hideRunBar();
|
|
1709
|
+
showHandoff(result.command);
|
|
1710
|
+
return;
|
|
1711
|
+
}
|
|
1712
|
+
if (button) button.disabled = false;
|
|
1713
|
+
if (result.outcome === "taken" && button) showRunTaken(button);
|
|
1714
|
+
else if (result.outcome === "taken") $("status").innerHTML = "<span class=\"err\">another run already took the terminal.</span>";
|
|
1715
|
+
else if (result.outcome === "gone") {
|
|
1716
|
+
stopPolling();
|
|
1717
|
+
$("status").innerHTML = "<span class=\"err\">the terminal has already been handed off - this page is done.</span>";
|
|
1718
|
+
} else if (result.outcome === "failed") $("status").innerHTML = "<span class=\"err\">run failed: " + escapeHtml(result.detail) + "</span>";
|
|
1719
|
+
}
|
|
1720
|
+
/**
|
|
1721
|
+
* Keys for the run bar's field: Enter runs what is typed, Escape goes back.
|
|
1722
|
+
*
|
|
1723
|
+
* Bound to the field itself rather than the document, so it dies with the bar
|
|
1724
|
+
* and cannot outlive it — a stale document listener would send a run for a
|
|
1725
|
+
* task the user had already dismissed.
|
|
1726
|
+
*/
|
|
1727
|
+
function armRunBar(id, field) {
|
|
1728
|
+
field.addEventListener("keydown", (ev) => {
|
|
1729
|
+
if (ev.key === "Escape") {
|
|
1730
|
+
ev.preventDefault();
|
|
1731
|
+
hideRunBar();
|
|
1732
|
+
return;
|
|
1733
|
+
}
|
|
1734
|
+
if (ev.key !== "Enter") return;
|
|
1735
|
+
ev.preventDefault();
|
|
1736
|
+
const args = splitArgs(field.value);
|
|
1737
|
+
hideRunBar();
|
|
1738
|
+
handOff(id, args);
|
|
1739
|
+
});
|
|
1740
|
+
}
|
|
1741
|
+
/**
|
|
1742
|
+
* The refresh loop, and the flag that ends it.
|
|
1743
|
+
*
|
|
1744
|
+
* The flag is not redundant with clearing the interval: the focus listener is
|
|
1745
|
+
* a second way in, and one flag turns both off in one place.
|
|
1746
|
+
*/
|
|
1747
|
+
let pollTimer;
|
|
1748
|
+
let polling = true;
|
|
1749
|
+
/** Stop refreshing for good. The server is exiting; there is nothing to poll. */
|
|
1750
|
+
function stopPolling() {
|
|
1751
|
+
polling = false;
|
|
1752
|
+
clearInterval(pollTimer);
|
|
1753
|
+
}
|
|
1754
|
+
/** Wire every listener the page needs. Called once, at boot. */
|
|
1755
|
+
function wireInput() {
|
|
1756
|
+
let debounce;
|
|
1757
|
+
$("q").addEventListener("input", (e) => {
|
|
1758
|
+
state.query = e.target.value;
|
|
1759
|
+
clearTimeout(debounce);
|
|
1760
|
+
debounce = setTimeout(render, 40);
|
|
1761
|
+
});
|
|
1762
|
+
$("q").addEventListener("focus", () => {
|
|
1763
|
+
if (state.focusedId !== null) setFocusedRow(null);
|
|
1764
|
+
});
|
|
1765
|
+
$("q").addEventListener("keydown", (e) => {
|
|
1766
|
+
const ev = e;
|
|
1767
|
+
if (ev.key === "Enter") {
|
|
1768
|
+
const row = document.querySelector("tbody tr.enter-target") ?? document.querySelector("tbody tr");
|
|
1769
|
+
if (!row) return;
|
|
1770
|
+
copyRow(row);
|
|
1771
|
+
setFocusedRow(row.dataset.id ?? null);
|
|
1772
|
+
row.focus();
|
|
1773
|
+
}
|
|
1774
|
+
if (ev.key === "Escape") {
|
|
1775
|
+
state.query = "";
|
|
1776
|
+
$("q").value = "";
|
|
1777
|
+
render();
|
|
1778
|
+
}
|
|
1779
|
+
});
|
|
1780
|
+
$("mode").addEventListener("click", (e) => {
|
|
1781
|
+
const b = e.target.closest("button[data-mode]");
|
|
1782
|
+
if (!b) return;
|
|
1783
|
+
state.mode = b.dataset.mode;
|
|
1784
|
+
for (const btn of $("mode").children) btn.setAttribute("aria-pressed", String(btn === b));
|
|
1785
|
+
render();
|
|
1786
|
+
});
|
|
1787
|
+
$("services").addEventListener("click", (e) => {
|
|
1788
|
+
state.servicesOnly = !state.servicesOnly;
|
|
1789
|
+
e.currentTarget.setAttribute("aria-pressed", String(state.servicesOnly));
|
|
1790
|
+
render();
|
|
1791
|
+
});
|
|
1792
|
+
document.addEventListener("click", (e) => {
|
|
1793
|
+
const target = e.target;
|
|
1794
|
+
if (target.closest("#settings") !== null && handleSettingsClick(target)) return;
|
|
1795
|
+
const info = target.closest("[data-info-runner]");
|
|
1796
|
+
if (info) {
|
|
1797
|
+
showRunnerInfo(info.dataset.infoRunner);
|
|
1798
|
+
return;
|
|
1799
|
+
}
|
|
1800
|
+
if (target.closest("[data-trust-repo]")) {
|
|
1801
|
+
if (confirm("Trust this repository? Its runners will be read by running them, now and on every later visit, until you untrust it.")) trustRepo();
|
|
1802
|
+
return;
|
|
1803
|
+
}
|
|
1804
|
+
if (target.closest("#helpbtn")) {
|
|
1805
|
+
$("help-body").innerHTML = HELP;
|
|
1806
|
+
$("help").showModal();
|
|
1807
|
+
return;
|
|
1808
|
+
}
|
|
1809
|
+
if (target.closest("[data-open-settings]") || target.closest("#settingsbtn")) {
|
|
1810
|
+
$("settings-body").innerHTML = "<p class=\"set-empty\">Reading configuration…</p>";
|
|
1811
|
+
$("settings").showModal();
|
|
1812
|
+
getConfig().then((config) => {
|
|
1813
|
+
$("settings-body").innerHTML = openSettings(config, [...state.knownRunners]);
|
|
1814
|
+
});
|
|
1815
|
+
return;
|
|
1816
|
+
}
|
|
1817
|
+
const menu = document.getElementById("pickmenu");
|
|
1818
|
+
const openBtn = target.closest("#pickbtn");
|
|
1819
|
+
if (openBtn && menu) {
|
|
1820
|
+
const show = menu.hidden;
|
|
1821
|
+
menu.hidden = !show;
|
|
1822
|
+
openBtn.setAttribute("aria-expanded", String(show));
|
|
1823
|
+
return;
|
|
1824
|
+
}
|
|
1825
|
+
const box = target.closest("input[data-toggle-runner]");
|
|
1826
|
+
if (box) {
|
|
1827
|
+
const runner = box.dataset.toggleRunner;
|
|
1828
|
+
if (box.checked) state.enabled?.add(runner);
|
|
1829
|
+
else state.enabled?.delete(runner);
|
|
1830
|
+
render();
|
|
1831
|
+
return;
|
|
1832
|
+
}
|
|
1833
|
+
const sort = target.closest("[data-sort-runners]");
|
|
1834
|
+
if (sort) {
|
|
1835
|
+
sortRunners(sort.dataset.sortRunners, Number(sort.dataset.sortDir) === -1 ? -1 : 1);
|
|
1836
|
+
return;
|
|
1837
|
+
}
|
|
1838
|
+
if (target.closest("[data-pick-all]")) {
|
|
1839
|
+
state.enabled = new Set(state.knownRunners);
|
|
1840
|
+
render();
|
|
1841
|
+
return;
|
|
1842
|
+
}
|
|
1843
|
+
if (target.closest("[data-pick-none]")) {
|
|
1844
|
+
state.enabled = /* @__PURE__ */ new Set();
|
|
1845
|
+
render();
|
|
1846
|
+
return;
|
|
1847
|
+
}
|
|
1848
|
+
if (target.closest("[data-open-picker]")) {
|
|
1849
|
+
const btn = document.getElementById("pickbtn");
|
|
1850
|
+
if (menu) menu.hidden = false;
|
|
1851
|
+
btn?.setAttribute("aria-expanded", "true");
|
|
1852
|
+
btn?.focus();
|
|
1853
|
+
return;
|
|
1854
|
+
}
|
|
1855
|
+
if (menu && !target.closest(".picker")) menu.hidden = true;
|
|
1856
|
+
});
|
|
1857
|
+
/**
|
|
1858
|
+
* Drag-to-reorder, shared by the tab bar and the picker: both mark their
|
|
1859
|
+
* draggables with a runner id, so one pair of handlers serves the two
|
|
1860
|
+
* surfaces.
|
|
1861
|
+
*
|
|
1862
|
+
* The drag PREVIEWS itself. A solid clone carries the pointer in place of
|
|
1863
|
+
* the browser's near-transparent default ghost, and the real elements move
|
|
1864
|
+
* as the pointer passes their midpoints - the dragged one among them, faded,
|
|
1865
|
+
* marking the slot it would land in. So the list shows the order the drop
|
|
1866
|
+
* will produce rather than only revealing it afterwards.
|
|
1867
|
+
*
|
|
1868
|
+
* The DOM is only the preview. State stays the source of truth: the drop
|
|
1869
|
+
* commits through saveRunnerOrder, and a drag abandoned without one
|
|
1870
|
+
* re-renders from the persisted order, which snaps everything back.
|
|
1871
|
+
*/
|
|
1872
|
+
let dragging = null;
|
|
1873
|
+
let dragEl = null;
|
|
1874
|
+
let ghost = null;
|
|
1875
|
+
/**
|
|
1876
|
+
* The arrangement the user has actually SEEN, refreshed once per animation
|
|
1877
|
+
* frame. Chromium delivers a last `dragover` in the same task as the `drop`,
|
|
1878
|
+
* so the move that dragover makes is committed without ever being painted -
|
|
1879
|
+
* and what persisted was one position off from what was on screen.
|
|
1880
|
+
* Committing this snapshot instead makes what lands what was last shown.
|
|
1881
|
+
*/
|
|
1882
|
+
let painted = [];
|
|
1883
|
+
let paintQueued = false;
|
|
1884
|
+
/** The runners the drag's own surface shows, in the order it shows them. */
|
|
1885
|
+
const shownOrder = (surface) => [...surface.children].map((c) => runnerOf(c)).filter((r) => r !== null && r !== "all");
|
|
1886
|
+
/** Record the arrangement the frame about to be drawn will show. */
|
|
1887
|
+
function snapshotPainted(surface) {
|
|
1888
|
+
if (paintQueued) return;
|
|
1889
|
+
paintQueued = true;
|
|
1890
|
+
requestAnimationFrame(() => {
|
|
1891
|
+
paintQueued = false;
|
|
1892
|
+
if (dragEl) painted = shownOrder(surface);
|
|
1893
|
+
});
|
|
1894
|
+
}
|
|
1895
|
+
/**
|
|
1896
|
+
* Put the page back the way a drag found it. Idempotent, and called from BOTH
|
|
1897
|
+
* ends: `drop` runs it before committing, because the commit re-renders the
|
|
1898
|
+
* tab strip and the picker, which detaches the drag source - and Chromium
|
|
1899
|
+
* fires no `dragend` for a source that is no longer in the document. Cleanup
|
|
1900
|
+
* left to that event alone simply never ran, so every committed drag leaked
|
|
1901
|
+
* its ghost and left the drag state armed.
|
|
1902
|
+
*
|
|
1903
|
+
* Returns whether there was a drag to end, which is what tells `dragend` it
|
|
1904
|
+
* is the cancel path rather than the tail of a commit.
|
|
1905
|
+
*/
|
|
1906
|
+
function endDrag() {
|
|
1907
|
+
if (!dragEl) return false;
|
|
1908
|
+
ghost?.remove();
|
|
1909
|
+
dragEl.classList.remove("dragging");
|
|
1910
|
+
ghost = null;
|
|
1911
|
+
dragEl = null;
|
|
1912
|
+
dragging = null;
|
|
1913
|
+
painted = [];
|
|
1914
|
+
return true;
|
|
1915
|
+
}
|
|
1916
|
+
document.addEventListener("dragstart", (e) => {
|
|
1917
|
+
const el = e.target.closest("[data-runner][draggable], [data-drag-runner]");
|
|
1918
|
+
const dt = e.dataTransfer;
|
|
1919
|
+
const runner = el ? el.dataset.dragRunner ?? el.dataset.runner ?? null : null;
|
|
1920
|
+
if (!el || !dt || runner === null) return;
|
|
1921
|
+
dragEl = el.closest(".tab") ?? el;
|
|
1922
|
+
dragging = runner;
|
|
1923
|
+
dt.effectAllowed = "move";
|
|
1924
|
+
dt.setData("text/plain", runner);
|
|
1925
|
+
ghost = makeDragGhost(dragEl, e, dt);
|
|
1926
|
+
dragEl.classList.add("dragging");
|
|
1927
|
+
const surface = dragEl.parentElement;
|
|
1928
|
+
painted = surface ? shownOrder(surface) : [];
|
|
1929
|
+
});
|
|
1930
|
+
document.addEventListener("dragover", (e) => {
|
|
1931
|
+
if (!dragEl) return;
|
|
1932
|
+
const ev = e;
|
|
1933
|
+
const surface = dragEl.parentElement;
|
|
1934
|
+
if (!surface || !surface.contains(ev.target)) return;
|
|
1935
|
+
ev.preventDefault();
|
|
1936
|
+
if (ev.dataTransfer) ev.dataTransfer.dropEffect = "move";
|
|
1937
|
+
const over = ev.target.closest(".tabs .tab, [data-drag-runner]");
|
|
1938
|
+
if (!over || over === dragEl || over.parentElement !== surface) return;
|
|
1939
|
+
if (runnerOf(over) === null || runnerOf(over) === "all") return;
|
|
1940
|
+
slideInto(surface, dragEl, isAfter(ev, over) ? over.nextSibling : over);
|
|
1941
|
+
snapshotPainted(surface);
|
|
1942
|
+
});
|
|
1943
|
+
document.addEventListener("drop", (e) => {
|
|
1944
|
+
if (!dragEl || dragging === null) return;
|
|
1945
|
+
e.preventDefault();
|
|
1946
|
+
const moved = dragging;
|
|
1947
|
+
const shown = painted;
|
|
1948
|
+
endDrag();
|
|
1949
|
+
commitDragOrder(shown, moved);
|
|
1950
|
+
});
|
|
1951
|
+
document.addEventListener("dragend", () => {
|
|
1952
|
+
if (endDrag()) render();
|
|
1953
|
+
});
|
|
1954
|
+
$("theme").addEventListener("click", () => {
|
|
1955
|
+
const choice = THEME_CYCLE[$("theme").dataset.themeChoice ?? "system"] ?? "light";
|
|
1956
|
+
if (choice === "system") document.documentElement.removeAttribute("data-theme");
|
|
1957
|
+
else document.documentElement.setAttribute("data-theme", choice);
|
|
1958
|
+
setThemeButton(choice);
|
|
1959
|
+
persistTheme(choice);
|
|
1960
|
+
});
|
|
1961
|
+
$("depth").addEventListener("click", (e) => {
|
|
1962
|
+
const b = e.target.closest("button[data-depth]");
|
|
1963
|
+
if (!b) return;
|
|
1964
|
+
state.depth = Number(b.dataset.depth);
|
|
1965
|
+
for (const btn of $("depth").children) btn.setAttribute("aria-pressed", String(btn === b));
|
|
1966
|
+
render();
|
|
1967
|
+
});
|
|
1968
|
+
$("declared").addEventListener("click", (e) => {
|
|
1969
|
+
state.declaredOnly = !state.declaredOnly;
|
|
1970
|
+
e.currentTarget.setAttribute("aria-pressed", String(state.declaredOnly));
|
|
1971
|
+
render();
|
|
1972
|
+
});
|
|
1973
|
+
$("expand").addEventListener("click", (e) => {
|
|
1974
|
+
state.allCollapsed = !state.allCollapsed;
|
|
1975
|
+
if (state.allCollapsed) for (const n of document.querySelectorAll(".node")) state.collapsed.add(n.dataset.key);
|
|
1976
|
+
else state.collapsed.clear();
|
|
1977
|
+
e.currentTarget.textContent = state.allCollapsed ? "Expand" : "Collapse";
|
|
1978
|
+
render();
|
|
1979
|
+
});
|
|
1980
|
+
$("refresh").addEventListener("click", () => load(true));
|
|
1981
|
+
$("tabs").addEventListener("click", (e) => {
|
|
1982
|
+
const b = e.target.closest("button[data-runner]");
|
|
1983
|
+
if (!b) return;
|
|
1984
|
+
state.runner = b.dataset.runner;
|
|
1985
|
+
render();
|
|
1986
|
+
});
|
|
1987
|
+
$("out").addEventListener("click", async (e) => {
|
|
1988
|
+
const target = e.target;
|
|
1989
|
+
const copy = target.closest(".copy");
|
|
1990
|
+
if (copy) {
|
|
1991
|
+
await copyCommand(copy);
|
|
1992
|
+
return;
|
|
1993
|
+
}
|
|
1994
|
+
const run = target.closest(".runbtn");
|
|
1995
|
+
if (run) {
|
|
1996
|
+
const id = run.dataset.runId ?? "";
|
|
1997
|
+
const task = (state.catalog?.reports ?? []).flatMap((r) => r.tasks).find((t) => t.id === id);
|
|
1998
|
+
if (task && task.parameters.length > 0) {
|
|
1999
|
+
armRunBar(task.id, showRunBar(task));
|
|
2000
|
+
return;
|
|
2001
|
+
}
|
|
2002
|
+
await handOff(id, [], run);
|
|
2003
|
+
return;
|
|
2004
|
+
}
|
|
2005
|
+
const head = target.closest(".head");
|
|
2006
|
+
if (!head) return;
|
|
2007
|
+
const node = head.parentElement;
|
|
2008
|
+
const key = node.dataset.key;
|
|
2009
|
+
if (state.collapsed.has(key)) state.collapsed.delete(key);
|
|
2010
|
+
else state.collapsed.add(key);
|
|
2011
|
+
node.dataset.collapsed = String(state.collapsed.has(key));
|
|
2012
|
+
node.querySelector(".twisty").textContent = state.collapsed.has(key) ? "▸" : "▾";
|
|
2013
|
+
});
|
|
2014
|
+
/**
|
|
2015
|
+
* The results list as one keyboard surface. Rows are <tr> spread across a
|
|
2016
|
+
* table per tree group, so "next row" is the next row in DOCUMENT order
|
|
2017
|
+
* across all of #out rather than within one table.
|
|
2018
|
+
*/
|
|
2019
|
+
$("out").addEventListener("keydown", (e) => {
|
|
2020
|
+
const ev = e;
|
|
2021
|
+
const row = ev.target.closest("tbody tr");
|
|
2022
|
+
if (!row) return;
|
|
2023
|
+
if (ev.key === "Escape") {
|
|
2024
|
+
ev.preventDefault();
|
|
2025
|
+
$("q").focus();
|
|
2026
|
+
return;
|
|
2027
|
+
}
|
|
2028
|
+
if (ev.target !== row) return;
|
|
2029
|
+
if (ev.key === "Enter") {
|
|
2030
|
+
ev.preventDefault();
|
|
2031
|
+
copyRow(row);
|
|
2032
|
+
return;
|
|
2033
|
+
}
|
|
2034
|
+
const step = ev.key === "ArrowDown" ? 1 : ev.key === "ArrowUp" ? -1 : 0;
|
|
2035
|
+
if (step === 0) return;
|
|
2036
|
+
ev.preventDefault();
|
|
2037
|
+
const rows = listRows();
|
|
2038
|
+
const at = rows.indexOf(row);
|
|
2039
|
+
const next = rows[Math.min(rows.length - 1, Math.max(0, at + step))];
|
|
2040
|
+
if (!next || next === row) return;
|
|
2041
|
+
setFocusedRow(next.dataset.id ?? null);
|
|
2042
|
+
next.focus();
|
|
2043
|
+
next.scrollIntoView({ block: "nearest" });
|
|
2044
|
+
});
|
|
2045
|
+
document.addEventListener("keydown", (e) => {
|
|
2046
|
+
if (e.key === "/" && document.activeElement !== $("q")) {
|
|
2047
|
+
e.preventDefault();
|
|
2048
|
+
$("q").focus();
|
|
2049
|
+
$("q").select();
|
|
2050
|
+
return;
|
|
2051
|
+
}
|
|
2052
|
+
if (e.key !== "Escape") return;
|
|
2053
|
+
const menu = document.getElementById("pickmenu");
|
|
2054
|
+
const picker = document.getElementById("pickerhost");
|
|
2055
|
+
if (!menu || menu.hidden || !picker?.contains(document.activeElement)) return;
|
|
2056
|
+
e.preventDefault();
|
|
2057
|
+
menu.hidden = true;
|
|
2058
|
+
const btn = document.getElementById("pickbtn");
|
|
2059
|
+
btn?.setAttribute("aria-expanded", "false");
|
|
2060
|
+
btn?.focus();
|
|
2061
|
+
});
|
|
2062
|
+
let resizeTimer;
|
|
2063
|
+
window.addEventListener("resize", () => {
|
|
2064
|
+
measureChrome();
|
|
2065
|
+
clearTimeout(resizeTimer);
|
|
2066
|
+
resizeTimer = setTimeout(render, 60);
|
|
2067
|
+
});
|
|
2068
|
+
window.addEventListener("focus", () => {
|
|
2069
|
+
if (polling) load(false);
|
|
2070
|
+
});
|
|
2071
|
+
pollTimer = setInterval(() => {
|
|
2072
|
+
if (polling && !document.hidden) load(false);
|
|
2073
|
+
}, 15e3);
|
|
2074
|
+
const q = $("q");
|
|
2075
|
+
q.title = q.placeholder;
|
|
2076
|
+
q.setAttribute("aria-label", q.placeholder);
|
|
2077
|
+
q.placeholder = "Search commands";
|
|
2078
|
+
for (const id of ["mode", "depth"]) rovingGroup($(id));
|
|
2079
|
+
rovingGroup($("tabs"), "button[data-runner]");
|
|
2080
|
+
}
|
|
2081
|
+
/**
|
|
2082
|
+
* Put a row's command on the clipboard and say what happened.
|
|
2083
|
+
*
|
|
2084
|
+
* The button is the ONLY evidence anyone has that the paste buffer changed, so
|
|
2085
|
+
* a refused write — a permissions policy, a page that is not the active
|
|
2086
|
+
* document — must not be reported as a copy. Returns whether it landed.
|
|
2087
|
+
*/
|
|
2088
|
+
async function copyCommand(copy) {
|
|
2089
|
+
let ok = true;
|
|
2090
|
+
try {
|
|
2091
|
+
await navigator.clipboard.writeText(copy.dataset.run ?? "");
|
|
2092
|
+
} catch {
|
|
2093
|
+
ok = false;
|
|
2094
|
+
}
|
|
2095
|
+
copy.textContent = ok ? "copied" : "blocked";
|
|
2096
|
+
if (ok) copy.classList.add("done");
|
|
2097
|
+
setTimeout(() => {
|
|
2098
|
+
copy.textContent = "copy";
|
|
2099
|
+
copy.classList.remove("done");
|
|
2100
|
+
}, 1200);
|
|
2101
|
+
return ok;
|
|
2102
|
+
}
|
|
2103
|
+
/**
|
|
2104
|
+
* Copy a row's command and say so on the row.
|
|
2105
|
+
*
|
|
2106
|
+
* The confirmation is on the ROW, not just the button, because both paths that
|
|
2107
|
+
* reach here act at a distance: from the search box the button is off to the
|
|
2108
|
+
* right of where the eye is, and from a focused row the keypress named the row
|
|
2109
|
+
* rather than the button. One helper, so the two paths cannot drift.
|
|
2110
|
+
*/
|
|
2111
|
+
function copyRow(row) {
|
|
2112
|
+
const button = row.querySelector(".copy");
|
|
2113
|
+
if (button === null) return;
|
|
2114
|
+
const menu = document.getElementById("pickmenu");
|
|
2115
|
+
if (menu) menu.hidden = true;
|
|
2116
|
+
copyCommand(button).then((ok) => {
|
|
2117
|
+
if (!ok) return;
|
|
2118
|
+
row.classList.remove("copied");
|
|
2119
|
+
row.offsetWidth;
|
|
2120
|
+
row.classList.add("copied");
|
|
2121
|
+
setTimeout(() => row.classList.remove("copied"), 700);
|
|
2122
|
+
});
|
|
2123
|
+
}
|
|
2124
|
+
/** Whether the pointer is past the target's midpoint (x for tabs, y for picker rows). */
|
|
2125
|
+
function isAfter(e, el) {
|
|
2126
|
+
const box = el.getBoundingClientRect();
|
|
2127
|
+
return el.hasAttribute("data-drag-runner") ? e.clientY > box.top + box.height / 2 : e.clientX > box.left + box.width / 2;
|
|
2128
|
+
}
|
|
2129
|
+
/** The runner a reorderable element stands for, or null when it stands for none. */
|
|
2130
|
+
function runnerOf(el) {
|
|
2131
|
+
return el.dataset.dragRunner ?? el.querySelector("[data-runner]")?.dataset.runner ?? null;
|
|
2132
|
+
}
|
|
2133
|
+
/**
|
|
2134
|
+
* The drag image: a solid, elevated copy of what is being dragged.
|
|
2135
|
+
*
|
|
2136
|
+
* setDragImage only takes an element that is rendered, so the clone is put in
|
|
2137
|
+
* the document and parked off-screen by its own class. It is removed at
|
|
2138
|
+
* dragend rather than on the next tick, because a snapshot the engine has not
|
|
2139
|
+
* taken yet cannot be removed early.
|
|
2140
|
+
*/
|
|
2141
|
+
function makeDragGhost(el, e, dt) {
|
|
2142
|
+
const box = el.getBoundingClientRect();
|
|
2143
|
+
const clone = el.cloneNode(true);
|
|
2144
|
+
clone.classList.add("dragghost");
|
|
2145
|
+
clone.setAttribute("data-drag-ghost", "");
|
|
2146
|
+
clone.removeAttribute("draggable");
|
|
2147
|
+
for (const node of [clone, ...clone.querySelectorAll("*")]) {
|
|
2148
|
+
node.removeAttribute("id");
|
|
2149
|
+
for (const attr of [
|
|
2150
|
+
"data-drag-runner",
|
|
2151
|
+
"data-runner",
|
|
2152
|
+
"data-toggle-runner",
|
|
2153
|
+
"data-info-runner"
|
|
2154
|
+
]) node.removeAttribute(attr);
|
|
2155
|
+
}
|
|
2156
|
+
clone.style.height = box.height + "px";
|
|
2157
|
+
document.body.appendChild(clone);
|
|
2158
|
+
const width = clone.getBoundingClientRect().width;
|
|
2159
|
+
dt.setDragImage(clone, Math.min(e.clientX - box.left, width), e.clientY - box.top);
|
|
2160
|
+
return clone;
|
|
2161
|
+
}
|
|
2162
|
+
/**
|
|
2163
|
+
* Move `moving` before `before` and let the displaced siblings slide there.
|
|
2164
|
+
*
|
|
2165
|
+
* insertBefore is instant, so the shift would otherwise be a jump with nothing
|
|
2166
|
+
* connecting the two arrangements. Each sibling's old position is measured,
|
|
2167
|
+
* then it is offset back to it and released - the standard
|
|
2168
|
+
* first/last/invert/play. Reduced motion keeps the jump, which is the setting
|
|
2169
|
+
* asking for exactly that.
|
|
2170
|
+
*/
|
|
2171
|
+
function slideInto(parent, moving, before) {
|
|
2172
|
+
if (moving.nextSibling === before && before !== null) return;
|
|
2173
|
+
const kids = [...parent.children];
|
|
2174
|
+
const was = new Map(kids.map((k) => [k, k.getBoundingClientRect()]));
|
|
2175
|
+
parent.insertBefore(moving, before);
|
|
2176
|
+
if (matchMedia("(prefers-reduced-motion: reduce)").matches) return;
|
|
2177
|
+
for (const k of kids) {
|
|
2178
|
+
if (k === moving) continue;
|
|
2179
|
+
const from = was.get(k);
|
|
2180
|
+
const to = k.getBoundingClientRect();
|
|
2181
|
+
const dx = from.left - to.left, dy = from.top - to.top;
|
|
2182
|
+
if (!dx && !dy) continue;
|
|
2183
|
+
k.style.transition = "none";
|
|
2184
|
+
k.style.transform = "translate(" + dx + "px, " + dy + "px)";
|
|
2185
|
+
requestAnimationFrame(() => {
|
|
2186
|
+
k.style.transition = "";
|
|
2187
|
+
k.style.transform = "";
|
|
2188
|
+
});
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
/**
|
|
2192
|
+
* Commit a previewed arrangement to the persisted order.
|
|
2193
|
+
*
|
|
2194
|
+
* The surface being dragged shows a SUBSET of the runners - the tab bar folds
|
|
2195
|
+
* the empty ones and hides the disabled ones - so the preview cannot simply
|
|
2196
|
+
* become the order. All a drag settles is where the moved runner sits AMONG THE
|
|
2197
|
+
* ONES ON SCREEN, and the runners it never showed must keep the neighbours they
|
|
2198
|
+
* have. So the moved runner is anchored to its new visible SUCCESSOR, or to its
|
|
2199
|
+
* visible predecessor when it was dropped last: a drop at the head means
|
|
2200
|
+
* "before the first VISIBLE runner", not "at the front of the full list", which
|
|
2201
|
+
* would hoist it past folded and disabled runners the user never saw.
|
|
2202
|
+
*/
|
|
2203
|
+
function commitDragOrder(shown, moved) {
|
|
2204
|
+
const order = runnerOrder().filter((r) => r !== moved);
|
|
2205
|
+
const at = shown.indexOf(moved);
|
|
2206
|
+
if (at === -1) return;
|
|
2207
|
+
const after = shown.slice(at + 1).find((r) => order.includes(r));
|
|
2208
|
+
const before = shown.slice(0, at).reverse().find((r) => order.includes(r));
|
|
2209
|
+
const to = after !== void 0 ? order.indexOf(after) : before !== void 0 ? order.indexOf(before) + 1 : 0;
|
|
2210
|
+
order.splice(to, 0, moved);
|
|
2211
|
+
saveRunnerOrder(order);
|
|
2212
|
+
}
|
|
2213
|
+
/**
|
|
2214
|
+
* Make a group of buttons ONE tab stop, moved within by arrow keys.
|
|
2215
|
+
*
|
|
2216
|
+
* Without this, two segmented controls and eight runner tabs are a dozen
|
|
2217
|
+
* stops between the search box and anything else — Tab stops meaning "next
|
|
2218
|
+
* control" and starts meaning "next button", which is the opposite of what
|
|
2219
|
+
* a keyboard user expects. Only the active button stays reachable by Tab;
|
|
2220
|
+
* the rest are reached with the arrows, as a radio group or tablist is.
|
|
2221
|
+
*/
|
|
2222
|
+
function rovingGroup(container, selector = "button") {
|
|
2223
|
+
if (!container) return;
|
|
2224
|
+
const buttons = () => [...container.querySelectorAll(selector)];
|
|
2225
|
+
const sync = () => {
|
|
2226
|
+
const all = buttons();
|
|
2227
|
+
const active = all.find((b) => b.getAttribute("aria-pressed") === "true") ?? all[0];
|
|
2228
|
+
for (const b of all) b.tabIndex = b === active ? 0 : -1;
|
|
2229
|
+
};
|
|
2230
|
+
sync();
|
|
2231
|
+
new MutationObserver(sync).observe(container, {
|
|
2232
|
+
childList: true,
|
|
2233
|
+
subtree: true
|
|
2234
|
+
});
|
|
2235
|
+
container.addEventListener("keydown", (e) => {
|
|
2236
|
+
const ev = e;
|
|
2237
|
+
const step = ev.key === "ArrowRight" ? 1 : ev.key === "ArrowLeft" ? -1 : 0;
|
|
2238
|
+
if (step === 0) return;
|
|
2239
|
+
e.preventDefault();
|
|
2240
|
+
const all = buttons();
|
|
2241
|
+
const at = all.indexOf(document.activeElement);
|
|
2242
|
+
const index = (Math.max(0, at) + step + all.length) % all.length;
|
|
2243
|
+
const next = all[index];
|
|
2244
|
+
if (!next) return;
|
|
2245
|
+
next.focus();
|
|
2246
|
+
next.click();
|
|
2247
|
+
const rebuilt = buttons()[index];
|
|
2248
|
+
if (rebuilt !== void 0 && rebuilt !== document.activeElement) rebuilt.focus();
|
|
2249
|
+
});
|
|
2250
|
+
}
|
|
2251
|
+
/** The colour-scheme cycle: what a click on the theme button moves to. */
|
|
2252
|
+
const THEME_CYCLE = {
|
|
2253
|
+
system: "light",
|
|
2254
|
+
light: "dark",
|
|
2255
|
+
dark: "system"
|
|
2256
|
+
};
|
|
2257
|
+
/** How each scheme presents itself once it is the one in force. */
|
|
2258
|
+
const THEME_FACE = {
|
|
2259
|
+
system: {
|
|
2260
|
+
glyph: "◐",
|
|
2261
|
+
name: "System",
|
|
2262
|
+
note: " (follows your OS)"
|
|
2263
|
+
},
|
|
2264
|
+
light: {
|
|
2265
|
+
glyph: "☀",
|
|
2266
|
+
name: "Light",
|
|
2267
|
+
note: ""
|
|
2268
|
+
},
|
|
2269
|
+
dark: {
|
|
2270
|
+
glyph: "☾",
|
|
2271
|
+
name: "Dark",
|
|
2272
|
+
note: ""
|
|
2273
|
+
}
|
|
2274
|
+
};
|
|
2275
|
+
/**
|
|
2276
|
+
* Paint the theme button for the choice now in force.
|
|
2277
|
+
*
|
|
2278
|
+
* The button shows the CURRENT scheme, so both the title and the accessible
|
|
2279
|
+
* name have to carry two facts: what is on, and what a click does next. A
|
|
2280
|
+
* single cycling control has no other place to say the second one, and a name
|
|
2281
|
+
* carrying only the first would leave a screen-reader user guessing what the
|
|
2282
|
+
* press does. Boot calls this too, so the button and the restored preference
|
|
2283
|
+
* agree from the first frame.
|
|
2284
|
+
*/
|
|
2285
|
+
function setThemeButton(choice) {
|
|
2286
|
+
const btn = $("theme");
|
|
2287
|
+
const face = THEME_FACE[choice] ?? THEME_FACE["system"];
|
|
2288
|
+
const next = THEME_FACE[THEME_CYCLE[choice] ?? "light"];
|
|
2289
|
+
btn.dataset.themeChoice = choice;
|
|
2290
|
+
btn.textContent = face.glyph;
|
|
2291
|
+
btn.title = "Colour scheme: " + face.name + face.note + ". Click for " + next.name + ".";
|
|
2292
|
+
btn.setAttribute("aria-label", "Colour scheme: " + face.name + ". Click for " + next.name + ".");
|
|
2293
|
+
}
|
|
2294
|
+
//#endregion
|
|
2295
|
+
//#region src/web/main.ts
|
|
2296
|
+
/**
|
|
2297
|
+
* Boot only: restore saved preferences, wire every listener, draw the first
|
|
2298
|
+
* frame. The actual behavior — rendering, data loading, event handling —
|
|
2299
|
+
* lives in `view.ts`, `api.ts` and `input.ts`; this module just sequences
|
|
2300
|
+
* their startup in the order the page depends on.
|
|
2301
|
+
*/
|
|
2302
|
+
if (new URL(location.href).searchParams.has("boot")) {
|
|
2303
|
+
const clean = new URL(location.href);
|
|
2304
|
+
clean.searchParams.delete("boot");
|
|
2305
|
+
history.replaceState(null, "", clean.pathname + clean.search + clean.hash);
|
|
2306
|
+
}
|
|
2307
|
+
state.runnerOrder = restoreRunnerOrder();
|
|
2308
|
+
const savedTheme = restoreTheme();
|
|
2309
|
+
if (savedTheme) document.documentElement.setAttribute("data-theme", savedTheme);
|
|
2310
|
+
setThemeButton(savedTheme ?? "system");
|
|
2311
|
+
wireInput();
|
|
2312
|
+
measureChrome();
|
|
2313
|
+
$("q").focus();
|
|
2314
|
+
load(false);
|
|
2315
|
+
//#endregion
|