@osdlc/wayfinder 0.7.4 → 0.9.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 +240 -0
- package/CONTRIBUTING.md +6 -0
- package/README.md +310 -150
- package/SECURITY.md +19 -5
- package/dist/actions.d.ts +23 -0
- package/dist/actions.js +97 -0
- package/dist/app.d.ts +1 -13
- package/dist/app.js +1 -13
- package/dist/args.d.ts +11 -6
- package/dist/args.js +25 -7
- package/dist/cache.d.ts +2 -4
- package/dist/cache.js +5 -10
- package/dist/catalog.d.ts +45 -4
- package/dist/catalog.js +134 -13
- package/dist/clean-command.d.ts +65 -36
- package/dist/clean-command.js +372 -226
- package/dist/cli.d.ts +24 -57
- package/dist/cli.js +139 -568
- package/dist/commands/browse.d.ts +128 -0
- package/dist/commands/browse.js +153 -0
- package/dist/commands/index.d.ts +25 -0
- package/dist/commands/index.js +71 -0
- package/dist/commands/list.d.ts +224 -0
- package/dist/commands/list.js +178 -0
- package/dist/commands/query.d.ts +166 -0
- package/dist/commands/query.js +73 -0
- package/dist/commands/run.d.ts +114 -0
- package/dist/commands/run.js +139 -0
- package/dist/commands/shared.d.ts +152 -0
- package/dist/commands/shared.js +209 -0
- package/dist/config-command.d.ts +27 -43
- package/dist/config-command.js +129 -330
- package/dist/config-keys.d.ts +25 -0
- package/dist/config-keys.js +29 -0
- package/dist/config.d.ts +272 -257
- package/dist/config.js +611 -460
- package/dist/core/copy-text.d.ts +30 -0
- package/dist/core/copy-text.js +50 -0
- package/dist/core/filter.d.ts +55 -0
- package/dist/core/filter.js +59 -0
- package/dist/core/run.d.ts +22 -0
- package/dist/core/run.js +59 -0
- package/dist/core/saved-view.d.ts +59 -0
- package/dist/core/saved-view.js +119 -0
- package/dist/core/session.d.ts +282 -0
- package/dist/core/session.js +602 -0
- package/dist/core/skills.d.ts +53 -0
- package/dist/core/skills.js +54 -0
- package/dist/core/unknowns.d.ts +72 -0
- package/dist/core/unknowns.js +68 -0
- package/dist/devlink.d.ts +3 -0
- package/dist/devlink.js +5 -2
- package/dist/document-schemas.generated.d.ts +22 -0
- package/dist/document-schemas.generated.js +916 -0
- package/dist/documents.d.ts +508 -0
- package/dist/documents.js +181 -0
- package/dist/groups.d.ts +22 -26
- package/dist/groups.js +13 -29
- package/dist/guide.d.ts +26 -13
- package/dist/guide.js +119 -103
- package/dist/index.d.ts +118 -0
- package/dist/index.js +61 -0
- package/dist/keys.d.ts +51 -0
- package/dist/keys.js +273 -0
- package/dist/page.d.ts +18 -8
- package/dist/page.js +28 -17
- package/dist/providers-command.d.ts +81 -20
- package/dist/providers-command.js +33 -75
- package/dist/schema.d.ts +48 -0
- package/dist/schema.js +61 -0
- package/dist/serve/auth.d.ts +46 -0
- package/dist/serve/auth.js +82 -0
- package/dist/serve/catalog-share.d.ts +63 -0
- package/dist/serve/catalog-share.js +155 -0
- package/dist/serve/index.d.ts +100 -0
- package/dist/serve/index.js +259 -0
- package/dist/serve/routes.d.ts +60 -0
- package/dist/serve/routes.js +186 -0
- package/dist/serve/terminal-input.d.ts +50 -0
- package/dist/serve/terminal-input.js +108 -0
- package/dist/skills.d.ts +19 -0
- package/dist/skills.js +54 -0
- package/dist/terminal-text.d.ts +8 -0
- package/dist/terminal-text.js +19 -6
- package/dist/tool-info.d.ts +24 -0
- package/dist/tool-info.js +17 -0
- package/dist/trust-command.d.ts +15 -27
- package/dist/trust-command.js +110 -208
- package/dist/trust-store.d.ts +5 -10
- package/dist/trust-store.js +9 -42
- package/dist/tui/app.d.ts +193 -0
- package/dist/tui/app.js +1400 -0
- package/dist/tui/copy.d.ts +29 -0
- package/dist/tui/copy.js +39 -0
- package/dist/tui/index.d.ts +33 -0
- package/dist/tui/index.js +97 -0
- package/dist/tui/keys-input.d.ts +27 -0
- package/dist/tui/keys-input.js +87 -0
- package/dist/tui/settings.d.ts +94 -0
- package/dist/tui/settings.js +198 -0
- package/dist/tui/style.d.ts +62 -0
- package/dist/tui/style.js +77 -0
- package/dist/version.d.ts +6 -0
- package/dist/version.js +7 -0
- package/dist/vocabulary.d.ts +91 -0
- package/dist/vocabulary.js +155 -0
- package/dist/web/main.js +2232 -582
- package/dist/web/page.html +41 -33
- package/dist/web/styles.css +513 -329
- package/dist/xdg.d.ts +76 -4
- package/dist/xdg.js +77 -5
- package/package.json +27 -8
- package/schema/config.json +133 -0
- package/dist/http.d.ts +0 -22
- package/dist/http.js +0 -149
- package/dist/origin-owner.d.ts +0 -19
- package/dist/origin-owner.js +0 -85
- package/dist/serve.d.ts +0 -98
- package/dist/serve.js +0 -671
- package/dist/tui.d.ts +0 -177
- package/dist/tui.js +0 -840
package/dist/web/main.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
//#region src/web/state.ts
|
|
2
2
|
const SEP = " › ";
|
|
3
|
+
/** The tab id for the Skills tab. No runner id starts with `@`. */
|
|
4
|
+
const SKILLS = "@skills";
|
|
5
|
+
/**
|
|
6
|
+
* The platform the server runs on, which picks the shell a copied line is
|
|
7
|
+
* quoted for. The page is served with it on `<html data-platform>`; the
|
|
8
|
+
* page runs on the same machine.
|
|
9
|
+
*/
|
|
10
|
+
function serverPlatform() {
|
|
11
|
+
return document.documentElement.dataset["platform"] ?? "linux";
|
|
12
|
+
}
|
|
3
13
|
/**
|
|
4
14
|
* Every static element this page uses is declared in `page.html` and never
|
|
5
15
|
* removed, so a failed lookup is a bug in the markup, not a case to handle at
|
|
@@ -16,6 +26,7 @@ const state = {
|
|
|
16
26
|
servicesOnly: false,
|
|
17
27
|
declaredOnly: false,
|
|
18
28
|
runnerOrder: [],
|
|
29
|
+
runnerOrderSource: "default",
|
|
19
30
|
depth: 99,
|
|
20
31
|
enabled: null,
|
|
21
32
|
collapsed: /* @__PURE__ */ new Set(),
|
|
@@ -25,47 +36,160 @@ const state = {
|
|
|
25
36
|
knownRunners: /* @__PURE__ */ new Set(),
|
|
26
37
|
checkedAt: Date.now(),
|
|
27
38
|
loading: false,
|
|
39
|
+
live: false,
|
|
40
|
+
pending: [],
|
|
41
|
+
expected: 0,
|
|
42
|
+
order: [],
|
|
43
|
+
loadStarted: 0,
|
|
28
44
|
trustable: false,
|
|
29
45
|
cache: [],
|
|
46
|
+
unknowns: [],
|
|
47
|
+
tools: [],
|
|
30
48
|
focusedId: null
|
|
31
49
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} catch {}
|
|
50
|
+
/** A tool's info by id, when `way providers` listed it. */
|
|
51
|
+
function toolInfo(id) {
|
|
52
|
+
return state.tools.find((t) => t.id === id);
|
|
36
53
|
}
|
|
37
|
-
/**
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
const saved = localStorage.getItem("wayfinder:theme");
|
|
41
|
-
if (saved === "light" || saved === "dark") return saved;
|
|
42
|
-
} catch {}
|
|
43
|
-
return null;
|
|
54
|
+
/** Every task in the catalog, in catalog order. */
|
|
55
|
+
function allTasks() {
|
|
56
|
+
return (state.catalog?.reports ?? []).flatMap((r) => r.tasks);
|
|
44
57
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region ../command-seam/dist/quote.js
|
|
60
|
+
/**
|
|
61
|
+
* Quoting for a command line printed for a person to paste, or passed to a
|
|
62
|
+
* shell. The argv runners never need the POSIX and PowerShell forms: they
|
|
63
|
+
* pass argv straight to the binary. The `cmd.exe` form is also how they
|
|
64
|
+
* start a `.cmd` or `.bat` file on Windows.
|
|
65
|
+
*/
|
|
66
|
+
/** Characters no POSIX shell treats specially. Same set as Python's `shlex.quote`. */
|
|
67
|
+
const INERT = /^[A-Za-z0-9_@%+=:,./-]+$/;
|
|
68
|
+
/**
|
|
69
|
+
* `word` as one shell word: unquoted when it holds only characters no POSIX
|
|
70
|
+
* shell treats specially (letters, digits and `_@%+=:,./-`), single-quoted
|
|
71
|
+
* otherwise. The quoted form reads the same in fish.
|
|
72
|
+
*/
|
|
73
|
+
function shellQuote(word) {
|
|
74
|
+
if (INERT.test(word)) return word;
|
|
75
|
+
return quoted(word);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* `argv` as one shell command line. A first word containing `=` is always
|
|
79
|
+
* quoted: bare, the shell would read it as a variable assignment, not a
|
|
80
|
+
* command.
|
|
81
|
+
*/
|
|
82
|
+
function shellJoin(argv) {
|
|
83
|
+
return argv.map((w, i) => i === 0 && w.includes("=") ? quoted(w) : shellQuote(w)).join(" ");
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* `word` single-quoted. A `'` is written `'\''`, and a `\` is written `'\\'`,
|
|
87
|
+
* outside the quotes: fish reads `\'` and `\\` inside single quotes as
|
|
88
|
+
* escapes, so a word ending in `\` would leave the quotes open.
|
|
89
|
+
*/
|
|
90
|
+
function quoted(word) {
|
|
91
|
+
return `'${word.replace(/['\\]/g, (c) => c === "'" ? `'\\''` : `'\\\\'`)}'`;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* `argv` as one command line for a person to paste into a shell, quoted for
|
|
95
|
+
* that shell.
|
|
96
|
+
*
|
|
97
|
+
* - `'posix'`: {@link shellJoin}. With `cwd`: `cd <dir> && <line>`.
|
|
98
|
+
* - `'powershell'`: `& <words>`. The call operator `&` is always emitted, so
|
|
99
|
+
* a quoted program path runs. A word is bare when it starts with a letter
|
|
100
|
+
* or one of `_-./\` and holds only letters, digits and `_-./\:=`;
|
|
101
|
+
* otherwise it is single-quoted, with each single quote (including the
|
|
102
|
+
* typographic ones PowerShell also accepts) doubled. With `cwd`:
|
|
103
|
+
* `if (Set-Location -LiteralPath <dir> -PassThru) { <line> }`. On success
|
|
104
|
+
* `-PassThru` returns the new location, which is true. On failure it
|
|
105
|
+
* returns nothing, so the command does not run, in Windows PowerShell 5.1
|
|
106
|
+
* and PowerShell 7 alike. Windows PowerShell 5.1 and PowerShell before 7.3
|
|
107
|
+
* drop an empty argument and mangle one with a `"` when calling a program.
|
|
108
|
+
* - `'cmd'`: a word of only letters, digits and `_@+:./\-` is bare. Any
|
|
109
|
+
* other argument is quoted by the C runtime rules and then each `cmd.exe`
|
|
110
|
+
* special character gets a `^` (see the README's Platforms section). The
|
|
111
|
+
* program and `cwd` get the `^` escapes without quotes. With `cwd`:
|
|
112
|
+
* `cd /d <dir> && <line>`.
|
|
113
|
+
*
|
|
114
|
+
* @param argv - The program, then its arguments. Must not be empty.
|
|
115
|
+
* @param opts - `platform`, `shell` and `cwd`.
|
|
116
|
+
* @returns The command line.
|
|
117
|
+
* @throws `RangeError` for an empty `argv`, or for `'cmd'` when a word or
|
|
118
|
+
* `cwd` holds a line break or a `%`, which `cmd.exe` cannot quote.
|
|
119
|
+
* @experimental
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* commandString(['git', 'commit', '-m', "it's done"], { platform: 'linux', cwd: '/repo' })
|
|
124
|
+
* // cd /repo && git commit -m 'it'\''s done'
|
|
125
|
+
* commandString(['git', 'commit', '-m', "it's done"], { platform: 'win32' })
|
|
126
|
+
* // & git commit -m 'it''s done'
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
function commandString(argv, opts = {}) {
|
|
130
|
+
if (argv.length === 0) throw new RangeError("argv must not be empty");
|
|
131
|
+
const platform = opts.platform ?? process.platform;
|
|
132
|
+
const shell = opts.shell ?? (platform === "win32" ? "powershell" : "posix");
|
|
133
|
+
const { cwd } = opts;
|
|
134
|
+
switch (shell) {
|
|
135
|
+
case "posix": {
|
|
136
|
+
const line = shellJoin(argv);
|
|
137
|
+
if (cwd === void 0) return line;
|
|
138
|
+
return `cd ${cwd.startsWith("-") ? "-- " : ""}${shellQuote(cwd)} && ${line}`;
|
|
139
|
+
}
|
|
140
|
+
case "powershell": {
|
|
141
|
+
const line = `& ${argv.map(psWord).join(" ")}`;
|
|
142
|
+
if (cwd === void 0) return line;
|
|
143
|
+
return `if (Set-Location -LiteralPath ${psWord(cwd)} -PassThru) { ${line} }`;
|
|
144
|
+
}
|
|
145
|
+
case "cmd": {
|
|
146
|
+
const words = [...argv, ...cwd === void 0 ? [] : [cwd]];
|
|
147
|
+
const broken = words.find((w) => /[\r\n]/.test(w));
|
|
148
|
+
if (broken !== void 0) throw new RangeError(`cmd.exe cannot quote a line break: ${JSON.stringify(broken)}`);
|
|
149
|
+
const percent = words.find((w) => w.includes("%"));
|
|
150
|
+
if (percent !== void 0) throw new RangeError(`cmd.exe cannot quote a %: ${JSON.stringify(percent)}`);
|
|
151
|
+
const line = argv.map((w, i) => CMD_INERT.test(w) ? w : i === 0 ? cmdCommand(w) : cmdArg(w));
|
|
152
|
+
return cwd === void 0 ? line.join(" ") : `cd /d ${cmdCommand(cwd)} && ${line.join(" ")}`;
|
|
153
|
+
}
|
|
154
|
+
default: throw new RangeError(`unknown shell ${JSON.stringify(shell)}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const PS_INERT = /^[A-Za-z_\-./\\][A-Za-z0-9_\-./\\:=]*$/;
|
|
158
|
+
/** `word` for PowerShell: bare when inert, else single-quoted. */
|
|
159
|
+
function psWord(word) {
|
|
160
|
+
if (PS_INERT.test(word)) return word;
|
|
161
|
+
return `'${word.replace(/['‘’‚‛]/g, "$&$&")}'`;
|
|
49
162
|
}
|
|
163
|
+
/** Words `cmd.exe` and the programs it starts read as typed. */
|
|
164
|
+
const CMD_INERT = /^[A-Za-z0-9_@+:./\\-]+$/;
|
|
165
|
+
/** Characters `cmd.exe` treats specially outside quotes, each escaped with `^`. */
|
|
166
|
+
const CMD_META = /[()[\]%!^"`<>&|;, *?]/g;
|
|
50
167
|
/**
|
|
51
|
-
*
|
|
168
|
+
* `arg` as one argument on a `cmd.exe` command line, for a program that
|
|
169
|
+
* splits its command line by the Microsoft C runtime rules. Two steps:
|
|
52
170
|
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
171
|
+
* 1. C runtime quoting: backslashes before a `"` are doubled and the `"`
|
|
172
|
+
* becomes `\"`; trailing backslashes are doubled; the result is wrapped
|
|
173
|
+
* in `"`.
|
|
174
|
+
* 2. `cmd.exe` escaping: each of ``()[]%!^"`<>&|;,*?`` and space gets a `^`.
|
|
175
|
+
* The quotes are escaped too, so `cmd.exe` never enters a quoted section
|
|
176
|
+
* and every `^` applies.
|
|
177
|
+
*
|
|
178
|
+
* `doubleEscape` applies step 2 twice, for a batch file that passes its
|
|
179
|
+
* arguments on with `%*` or `%1`, which `cmd.exe` parses again. The runners
|
|
180
|
+
* use it for every batch file.
|
|
181
|
+
*
|
|
182
|
+
* A line break or a `%` cannot be passed. `cmd.exe` ends the command at a
|
|
183
|
+
* line break, and it expands `%NAME%`, `%NAME:a=b%` and `%NAME:~n,m%` before
|
|
184
|
+
* it reads any `^`. Callers refuse both before calling this.
|
|
55
185
|
*/
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
} catch {}
|
|
60
|
-
state.runnerOrder = [];
|
|
186
|
+
function cmdArg(arg, doubleEscape = false) {
|
|
187
|
+
const once = `"${arg.replace(/(\\*)"/g, "$1$1\\\"").replace(/(\\*)$/, "$1$1")}"`.replace(CMD_META, "^$&");
|
|
188
|
+
return doubleEscape ? once.replace(CMD_META, "^$&") : once;
|
|
61
189
|
}
|
|
62
|
-
/**
|
|
63
|
-
function
|
|
64
|
-
|
|
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 [];
|
|
190
|
+
/** `command` as the program on a `cmd.exe` line: each special character gets a `^`, with no quotes. */
|
|
191
|
+
function cmdCommand(command) {
|
|
192
|
+
return command.replace(CMD_META, "^$&");
|
|
69
193
|
}
|
|
70
194
|
//#endregion
|
|
71
195
|
//#region ../system-model/dist/duration.js
|
|
@@ -229,7 +353,10 @@ function matchEntry(entry, queryTerms, mode) {
|
|
|
229
353
|
* the DOM or Node built-ins. The `Param` import below is type-only, so it is
|
|
230
354
|
* erased.
|
|
231
355
|
*
|
|
232
|
-
*
|
|
356
|
+
* {@link bindParams} is here too, so a page can check values before it sends
|
|
357
|
+
* them.
|
|
358
|
+
*
|
|
359
|
+
* Three callers share the display format. just's runner builds `display` with it, the
|
|
233
360
|
* TUI prints it under a command that ran without arguments, and the web view's
|
|
234
361
|
* run bar shows it under the field.
|
|
235
362
|
*/
|
|
@@ -249,11 +376,205 @@ function paramShape(parameters) {
|
|
|
249
376
|
}).join(" ");
|
|
250
377
|
}
|
|
251
378
|
//#endregion
|
|
252
|
-
//#region src/
|
|
379
|
+
//#region src/core/filter.ts
|
|
380
|
+
/**
|
|
381
|
+
* The one search and filter every surface uses: the CLI's `list` and
|
|
382
|
+
* `query`, the terminal UI's entry line and the web view's toolbar.
|
|
383
|
+
*
|
|
384
|
+
* Browser-safe: it imports only the matcher, so the page can use it.
|
|
385
|
+
*/
|
|
386
|
+
/**
|
|
387
|
+
* How deep in the repository a task is declared: the number of directories
|
|
388
|
+
* above its source file. `justfile` at the root is 0;
|
|
389
|
+
* `apps/web/client/moon.yml` is 3.
|
|
390
|
+
*/
|
|
391
|
+
function sourceDepth(task) {
|
|
392
|
+
const at = task.source.lastIndexOf("/");
|
|
393
|
+
return at === -1 ? 0 : task.source.slice(0, at).split("/").length;
|
|
394
|
+
}
|
|
395
|
+
/** Whether `task` passes every part of `filter` except the query. */
|
|
396
|
+
function keepsTask(task, filter) {
|
|
397
|
+
if (filter.servicesOnly === true && !task.persistent.value) return false;
|
|
398
|
+
if (filter.declaredOnly === true && task.origin !== "declared") return false;
|
|
399
|
+
if (filter.maxDepth !== void 0 && sourceDepth(task) > filter.maxDepth) return false;
|
|
400
|
+
if (filter.runners !== void 0 && !filter.runners.includes(task.runner)) return false;
|
|
401
|
+
return true;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* The tasks of `reports` that pass `filter`. With a query they are ranked
|
|
405
|
+
* best first, and equal scores keep catalog order. Without one they stay in
|
|
406
|
+
* catalog order.
|
|
407
|
+
*/
|
|
408
|
+
function filterTasks(reports, filter = {}) {
|
|
409
|
+
const queryTerms = terms(filter.query ?? "");
|
|
410
|
+
const mode = filter.mode ?? "fuzzy";
|
|
411
|
+
const hits = [];
|
|
412
|
+
for (const report of reports) for (const task of report.tasks) {
|
|
413
|
+
if (!keepsTask(task, filter)) continue;
|
|
414
|
+
if (queryTerms.length === 0) {
|
|
415
|
+
hits.push({
|
|
416
|
+
task,
|
|
417
|
+
score: 0,
|
|
418
|
+
labelHits: null
|
|
419
|
+
});
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
const m = matchEntry(task, queryTerms, mode);
|
|
423
|
+
if (m !== null) hits.push({
|
|
424
|
+
task,
|
|
425
|
+
score: m.score,
|
|
426
|
+
labelHits: m.labelHits
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
if (queryTerms.length > 0) hits.sort((a, b) => b.score - a.score);
|
|
430
|
+
return hits;
|
|
431
|
+
}
|
|
432
|
+
//#endregion
|
|
433
|
+
//#region src/app.ts
|
|
434
|
+
/**
|
|
435
|
+
* The app's names. Every user-facing name that carries the product name
|
|
436
|
+
* derives from here. Browser-safe: the page imports it too.
|
|
437
|
+
*/
|
|
438
|
+
/** The product name: config directory, cache directory and trust store key. Messages start with {@link BIN}. */
|
|
439
|
+
const APP = "wayfinder";
|
|
440
|
+
`${APP.toUpperCase()}`;
|
|
441
|
+
//#endregion
|
|
442
|
+
//#region src/terminal-text.ts
|
|
443
|
+
/**
|
|
444
|
+
* C0 (tab and newline included), DEL, C1, and the bidi controls: the marks
|
|
445
|
+
* U+061C, U+200E and U+200F, and U+202A-202E and U+2066-2069.
|
|
446
|
+
*/
|
|
447
|
+
const CONTROL = /[\u0000-\u001f\u007f-\u009f\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g;
|
|
448
|
+
/** The same, but tab and newline are kept. */
|
|
449
|
+
const CONTROL_KEEP_LINES = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g;
|
|
450
|
+
const REPLACEMENT = "�";
|
|
451
|
+
/**
|
|
452
|
+
* `text` with every C0 control character (ESC included), DEL, C1 control
|
|
453
|
+
* character and bidi control replaced by U+FFFD. With `multiline`, tab and
|
|
454
|
+
* newline are kept, for output that is already more than one line.
|
|
455
|
+
*/
|
|
456
|
+
function terminalSafe(text, opts = {}) {
|
|
457
|
+
return text.replace(opts.multiline === true ? CONTROL_KEEP_LINES : CONTROL, REPLACEMENT);
|
|
458
|
+
}
|
|
459
|
+
/** True when `text` holds a character {@link terminalSafe} replaces. */
|
|
460
|
+
function hasControls(text) {
|
|
461
|
+
return new RegExp(CONTROL.source).test(text);
|
|
462
|
+
}
|
|
463
|
+
//#endregion
|
|
464
|
+
//#region src/core/copy-text.ts
|
|
465
|
+
/**
|
|
466
|
+
* What Copy puts on the clipboard, in the terminal UI and the web view alike.
|
|
467
|
+
*
|
|
468
|
+
* A task is copied as its argv quoted for the platform's shell, never as
|
|
469
|
+
* `display`, so a name like `x; touch PWNED #` pastes as one quoted word.
|
|
470
|
+
* Text that holds a control character is not copied at all: an `ESC[201~`
|
|
471
|
+
* ends a terminal's bracketed paste, and a newline would run the line, so
|
|
472
|
+
* replacing them would still put text on the clipboard the person did not
|
|
473
|
+
* see.
|
|
474
|
+
*
|
|
475
|
+
* Browser-safe: the quoting comes from `@osdlc/command-seam/quote`.
|
|
476
|
+
*/
|
|
477
|
+
/** Why a copy was refused, as every surface says it. */
|
|
478
|
+
const COPY_REFUSED = "not copied: it holds a control character";
|
|
479
|
+
/** `text`, or null when it holds a control character. */
|
|
480
|
+
function clipboardText(text) {
|
|
481
|
+
return hasControls(text) ? null : text;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* The line to paste for `task`: its argv quoted for `platform`'s shell, after
|
|
485
|
+
* a change to the task's directory when it has its own. Null when the line
|
|
486
|
+
* holds a control character, so it is not copied.
|
|
487
|
+
*/
|
|
488
|
+
function taskCopyText(task, platform) {
|
|
489
|
+
if (task.argv.length === 0) return null;
|
|
490
|
+
return clipboardText(commandString(task.argv, {
|
|
491
|
+
platform,
|
|
492
|
+
...task.cwd === "." ? {} : { cwd: task.cwd }
|
|
493
|
+
}));
|
|
494
|
+
}
|
|
495
|
+
/** `/<name>` for `skill`, or null when it holds a control character. */
|
|
496
|
+
function skillCopyText(skill) {
|
|
497
|
+
return clipboardText(skill.invoke);
|
|
498
|
+
}
|
|
499
|
+
//#endregion
|
|
500
|
+
//#region src/core/skills.ts
|
|
501
|
+
/**
|
|
502
|
+
* Agent skills as catalog rows: the Skills group. A skill is not a task. It
|
|
503
|
+
* has no command line; an agent runs it when a person types `/<name>`. So
|
|
504
|
+
* the run action copies {@link SkillRow.invoke} and nothing is spawned.
|
|
505
|
+
*
|
|
506
|
+
* Skill names, descriptions and hints come from files in the repository or
|
|
507
|
+
* the user's config. Filter them like any repository text before printing.
|
|
508
|
+
*
|
|
509
|
+
* Browser-safe: it imports only the matcher, so the page can use it.
|
|
510
|
+
*/
|
|
511
|
+
/** The text a surface shows for a skill: `/review [pr-number]`. */
|
|
512
|
+
function skillLine(skill) {
|
|
513
|
+
return skill.argumentHint === null ? skill.invoke : `${skill.invoke} ${skill.argumentHint}`;
|
|
514
|
+
}
|
|
515
|
+
/** Whether `skill` passes the parts of `filter` a skill has. */
|
|
516
|
+
function keepsSkill(filter) {
|
|
517
|
+
if (filter.servicesOnly === true) return false;
|
|
518
|
+
if (filter.runners !== void 0) return false;
|
|
519
|
+
return true;
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* The skills that pass `filter`, matched like tasks: by name, then the
|
|
523
|
+
* `/<name>` line, the description and the origin. With a query they are
|
|
524
|
+
* ranked best first; without one they keep their order.
|
|
525
|
+
*/
|
|
526
|
+
function filterSkills(skills, filter = {}) {
|
|
527
|
+
if (!keepsSkill(filter)) return [];
|
|
528
|
+
const queryTerms = terms(filter.query ?? "");
|
|
529
|
+
if (queryTerms.length === 0) return skills.map((skill) => ({
|
|
530
|
+
skill,
|
|
531
|
+
score: 0,
|
|
532
|
+
labelHits: null
|
|
533
|
+
}));
|
|
534
|
+
const mode = filter.mode ?? "fuzzy";
|
|
535
|
+
const hits = [];
|
|
536
|
+
for (const skill of skills) {
|
|
537
|
+
const m = matchEntry({
|
|
538
|
+
path: [skill.name],
|
|
539
|
+
display: skillLine(skill),
|
|
540
|
+
doc: skill.description ?? "",
|
|
541
|
+
detail: "",
|
|
542
|
+
tags: [skill.origin, ...skill.harnesses]
|
|
543
|
+
}, queryTerms, mode);
|
|
544
|
+
if (m !== null) hits.push({
|
|
545
|
+
skill,
|
|
546
|
+
score: m.score,
|
|
547
|
+
labelHits: m.labelHits
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
hits.sort((a, b) => b.score - a.score);
|
|
551
|
+
return hits;
|
|
552
|
+
}
|
|
553
|
+
//#endregion
|
|
554
|
+
//#region ../system-model/dist/groups.js
|
|
555
|
+
/**
|
|
556
|
+
* `@osdlc/system-model/groups`: the groups a catalog's reports fall into.
|
|
557
|
+
* Tasks from runners come first, then the actions synthesized from package
|
|
558
|
+
* managers, tool managers and hook managers. Each synthesized group is one
|
|
559
|
+
* runner id, so a report's group follows from its `runner`.
|
|
560
|
+
*
|
|
561
|
+
* Browser-safe: no Node built-in and no dependency, so a web view can import
|
|
562
|
+
* it.
|
|
563
|
+
*/
|
|
564
|
+
/**
|
|
565
|
+
* The runner ids of the three synthesized groups.
|
|
566
|
+
*
|
|
567
|
+
* @experimental
|
|
568
|
+
*/
|
|
569
|
+
const SYNTHESIZED_RUNNERS = {
|
|
570
|
+
packageManager: "package-manager",
|
|
571
|
+
toolManager: "tool-manager",
|
|
572
|
+
hookManager: "hook-manager"
|
|
573
|
+
};
|
|
253
574
|
/**
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
575
|
+
* Every group, in display order.
|
|
576
|
+
*
|
|
577
|
+
* @experimental
|
|
257
578
|
*/
|
|
258
579
|
const GROUPS = [
|
|
259
580
|
{
|
|
@@ -263,64 +584,462 @@ const GROUPS = [
|
|
|
263
584
|
{
|
|
264
585
|
id: "dependencies",
|
|
265
586
|
title: "Dependencies",
|
|
266
|
-
runner:
|
|
587
|
+
runner: SYNTHESIZED_RUNNERS.packageManager
|
|
267
588
|
},
|
|
268
589
|
{
|
|
269
590
|
id: "tools",
|
|
270
591
|
title: "Tools",
|
|
271
|
-
runner:
|
|
592
|
+
runner: SYNTHESIZED_RUNNERS.toolManager
|
|
272
593
|
},
|
|
273
594
|
{
|
|
274
595
|
id: "hooks",
|
|
275
596
|
title: "Git hooks",
|
|
276
|
-
runner:
|
|
597
|
+
runner: SYNTHESIZED_RUNNERS.hookManager
|
|
277
598
|
}
|
|
278
599
|
];
|
|
279
|
-
/**
|
|
600
|
+
/**
|
|
601
|
+
* The group a runner's report belongs to.
|
|
602
|
+
*
|
|
603
|
+
* @experimental
|
|
604
|
+
*/
|
|
280
605
|
function groupOf(runner) {
|
|
281
606
|
return GROUPS.find((g) => g.runner === runner) ?? GROUPS[0];
|
|
282
607
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
608
|
+
//#endregion
|
|
609
|
+
//#region src/vocabulary.ts
|
|
610
|
+
/**
|
|
611
|
+
* The words every surface shows a person: the noun for a row, the name of a
|
|
612
|
+
* runner or group, and the one label for each thing wayfinder cannot know.
|
|
613
|
+
* The CLI, the terminal UI, the web view and the JSON documents take their
|
|
614
|
+
* wording from here, so a change happens in one place.
|
|
615
|
+
*
|
|
616
|
+
* Browser-safe: no Node built-in, so the page imports it.
|
|
617
|
+
*/
|
|
618
|
+
/** How long a refresh runs before the status names the runners it still waits on. */
|
|
619
|
+
const WAITING_AFTER_MS = 3e3;
|
|
620
|
+
/** What one row is called on every surface. */
|
|
621
|
+
const TASK_NOUN = {
|
|
622
|
+
one: "task",
|
|
623
|
+
many: "tasks"
|
|
624
|
+
};
|
|
625
|
+
/** `1 task`, `3 tasks`. */
|
|
626
|
+
function countTasks(n) {
|
|
627
|
+
return `${n} ${n === 1 ? TASK_NOUN.one : TASK_NOUN.many}`;
|
|
628
|
+
}
|
|
629
|
+
/** `1 runner`, `3 runners`. */
|
|
630
|
+
function countRunners(n) {
|
|
631
|
+
return `${n} runner${n === 1 ? "" : "s"}`;
|
|
286
632
|
}
|
|
287
|
-
/**
|
|
633
|
+
/**
|
|
634
|
+
* The name a person reads for a runner: the group's name for a synthesized
|
|
635
|
+
* group (`dependencies`, `tools`, `git hooks`), else the runner id. JSON and
|
|
636
|
+
* config keys keep the id.
|
|
637
|
+
*/
|
|
288
638
|
function runnerLabel(runner) {
|
|
289
639
|
const group = groupOf(runner);
|
|
290
640
|
return group.runner === runner ? group.title.toLowerCase() : runner;
|
|
291
641
|
}
|
|
292
|
-
//#endregion
|
|
293
|
-
//#region src/app.ts
|
|
294
642
|
/**
|
|
295
|
-
*
|
|
296
|
-
*
|
|
643
|
+
* A task's path as a person reads it: a runner id at its head becomes the
|
|
644
|
+
* runner's label, so `package-manager > . > npm > install` reads
|
|
645
|
+
* `dependencies > . > npm > install`.
|
|
297
646
|
*/
|
|
298
|
-
|
|
299
|
-
|
|
647
|
+
function displayPath(path, runner) {
|
|
648
|
+
return path[0] === runner ? [runnerLabel(runner), ...path.slice(1)] : [...path];
|
|
649
|
+
}
|
|
650
|
+
/** The word for a runner that was not read because reading it means running it. */
|
|
651
|
+
const WITHHELD = "withheld";
|
|
652
|
+
const WITHHELD_REASONS = {
|
|
653
|
+
untrusted: "this repository is not trusted",
|
|
654
|
+
"tool-untrusted": "a tool it runs is not trusted",
|
|
655
|
+
"exec-off": "execution is off"
|
|
656
|
+
};
|
|
657
|
+
/** `a`, `a and b`, `a, b and c`. */
|
|
658
|
+
function listWords(words) {
|
|
659
|
+
if (words.length <= 1) return words.join("");
|
|
660
|
+
return `${words.slice(0, -1).join(", ")} and ${words.at(-1)}`;
|
|
661
|
+
}
|
|
662
|
+
const EXEC_OFF = {
|
|
663
|
+
flag: "--no-exec was given",
|
|
664
|
+
user: "allowExec is false in your user config",
|
|
665
|
+
project: "allowExec is false in this project"
|
|
666
|
+
};
|
|
667
|
+
/** Why execution is off, in words: `--no-exec was given`. */
|
|
668
|
+
function execOffLabel(source) {
|
|
669
|
+
return source === void 0 ? WITHHELD_REASONS["exec-off"] : EXEC_OFF[source];
|
|
670
|
+
}
|
|
300
671
|
/**
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
672
|
+
* `withheld: this repository is not trusted`. For `tool-untrusted` with the
|
|
673
|
+
* missing tool ids: `withheld: mise is not trusted`. For `exec-off` with what
|
|
674
|
+
* turned it off: `withheld: --no-exec was given`.
|
|
304
675
|
*/
|
|
305
|
-
|
|
306
|
-
`${
|
|
307
|
-
`${
|
|
308
|
-
|
|
309
|
-
|
|
676
|
+
function withheldLabel(reason, missing = [], execOff) {
|
|
677
|
+
if (reason === "tool-untrusted" && missing.length > 0) return `${WITHHELD}: ${listWords(missing)} ${missing.length === 1 ? "is" : "are"} not trusted`;
|
|
678
|
+
if (reason === "exec-off") return `${WITHHELD}: ${execOffLabel(execOff)}`;
|
|
679
|
+
return `${WITHHELD}: ${WITHHELD_REASONS[reason]}`;
|
|
680
|
+
}
|
|
681
|
+
/** What the Skills group's rows are called. */
|
|
682
|
+
const SKILL_NOUN = {
|
|
683
|
+
one: "skill",
|
|
684
|
+
many: "skills"
|
|
685
|
+
};
|
|
686
|
+
/** `1 skill`, `3 skills`. */
|
|
687
|
+
function countSkills(n) {
|
|
688
|
+
return `${n} ${n === 1 ? SKILL_NOUN.one : SKILL_NOUN.many}`;
|
|
689
|
+
}
|
|
690
|
+
const PARAMETERS_UNKNOWN = {
|
|
691
|
+
"exec-withheld": "reading them needs execution, which is withheld",
|
|
692
|
+
"tool-missing": "the tool is not installed",
|
|
693
|
+
"tool-failed": "the tool could not list them",
|
|
694
|
+
"not-read": "this runner does not read them"
|
|
695
|
+
};
|
|
696
|
+
/** The label for a task that uses an editor variable: it cannot run outside the editor. */
|
|
697
|
+
const EDITOR_VARIABLE_LABEL = "cannot run here: the task uses an editor variable";
|
|
698
|
+
/**
|
|
699
|
+
* The label for a task whose parameters could not be read. An editor
|
|
700
|
+
* variable is not a gap in what is known: the task cannot run here at all,
|
|
701
|
+
* and the label says that ({@link EDITOR_VARIABLE_LABEL}).
|
|
702
|
+
*/
|
|
703
|
+
function parametersUnknownLabel(reason) {
|
|
704
|
+
return reason === "editor-variable" ? EDITOR_VARIABLE_LABEL : `parameters unknown: ${PARAMETERS_UNKNOWN[reason]}`;
|
|
705
|
+
}
|
|
706
|
+
const STALE_REASONS = {
|
|
707
|
+
changed: "its files changed",
|
|
708
|
+
"max-age": "it is past its age limit",
|
|
709
|
+
excludes: "the excluded paths changed",
|
|
710
|
+
exec: "it was read with another execution setting",
|
|
711
|
+
version: "another version read it",
|
|
712
|
+
tool: "the tool changed"
|
|
713
|
+
};
|
|
714
|
+
/** `stale: its files changed, 3m old`. */
|
|
715
|
+
function staleLabel(reason, ageMs) {
|
|
716
|
+
return `stale: ${reason === void 0 ? "" : `${STALE_REASONS[reason]}, `}${humanAge(ageMs)}`;
|
|
717
|
+
}
|
|
310
718
|
//#endregion
|
|
311
|
-
//#region src/
|
|
312
|
-
/** C0 (tab and newline included), DEL, C1, and bidi U+202A-202E and U+2066-2069. */
|
|
313
|
-
const CONTROL = /[\u0000-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/g;
|
|
314
|
-
/** The same, but tab and newline are kept. */
|
|
315
|
-
const CONTROL_KEEP_LINES = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/g;
|
|
316
|
-
const REPLACEMENT = "�";
|
|
719
|
+
//#region src/groups.ts
|
|
317
720
|
/**
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
721
|
+
* The row groups every surface shows: tasks from runners, then the actions
|
|
722
|
+
* system-model synthesizes from package managers, tool managers and hook
|
|
723
|
+
* managers, then agent skills. The report groups are
|
|
724
|
+
* `@osdlc/system-model/groups`; this module adds the order wayfinder sorts
|
|
725
|
+
* reports by and the Skills group, whose rows are `CatalogSnapshot.skills`
|
|
726
|
+
* rather than a report. Browser-safe: the page imports it.
|
|
321
727
|
*/
|
|
322
|
-
|
|
323
|
-
|
|
728
|
+
/** Position of a runner's group in {@link GROUPS}. */
|
|
729
|
+
function groupRank(runner) {
|
|
730
|
+
return GROUPS.indexOf(groupOf(runner));
|
|
731
|
+
}
|
|
732
|
+
/** The Skills group. Its rows are skills, not a runner's tasks, so it names no runner. */
|
|
733
|
+
const SKILLS_GROUP = {
|
|
734
|
+
id: "skills",
|
|
735
|
+
title: "Skills"
|
|
736
|
+
};
|
|
737
|
+
//#endregion
|
|
738
|
+
//#region src/keys.ts
|
|
739
|
+
/** The table. Within a view, in the order a help screen lists them. */
|
|
740
|
+
const KEY_TABLE = Object.freeze([
|
|
741
|
+
{
|
|
742
|
+
surface: "tui",
|
|
743
|
+
view: "list",
|
|
744
|
+
keys: ["type"],
|
|
745
|
+
action: "narrow the list"
|
|
746
|
+
},
|
|
747
|
+
{
|
|
748
|
+
surface: "tui",
|
|
749
|
+
view: "list",
|
|
750
|
+
keys: ["enter"],
|
|
751
|
+
action: "run the task, asking for arguments first; copy a skill",
|
|
752
|
+
hint: "enter run",
|
|
753
|
+
skillHint: "enter copy /name",
|
|
754
|
+
rank: 1
|
|
755
|
+
},
|
|
756
|
+
{
|
|
757
|
+
surface: "tui",
|
|
758
|
+
view: "list",
|
|
759
|
+
keys: ["^y"],
|
|
760
|
+
action: "copy the selected task's command line, or a skill's /name",
|
|
761
|
+
hint: "^y copy",
|
|
762
|
+
rank: 2
|
|
763
|
+
},
|
|
764
|
+
{
|
|
765
|
+
surface: "tui",
|
|
766
|
+
view: "list",
|
|
767
|
+
keys: ["tab", "shift+tab"],
|
|
768
|
+
action: "next / previous tab: all, each runner, skills",
|
|
769
|
+
hint: "tab runner",
|
|
770
|
+
rank: 3
|
|
771
|
+
},
|
|
772
|
+
{
|
|
773
|
+
surface: "tui",
|
|
774
|
+
view: "list",
|
|
775
|
+
keys: [","],
|
|
776
|
+
action: "settings: runners, discovery, excluded paths and trust",
|
|
777
|
+
hint: ", settings",
|
|
778
|
+
rank: 4
|
|
779
|
+
},
|
|
780
|
+
{
|
|
781
|
+
surface: "tui",
|
|
782
|
+
view: "list",
|
|
783
|
+
keys: ["^s"],
|
|
784
|
+
action: "trust this repository, after a y/n question",
|
|
785
|
+
hint: "^s trust",
|
|
786
|
+
rank: 5
|
|
787
|
+
},
|
|
788
|
+
{
|
|
789
|
+
surface: "tui",
|
|
790
|
+
view: "list",
|
|
791
|
+
keys: ["^r"],
|
|
792
|
+
action: "refresh: probe the repository again",
|
|
793
|
+
hint: "^r refresh",
|
|
794
|
+
rank: 6
|
|
795
|
+
},
|
|
796
|
+
{
|
|
797
|
+
surface: "tui",
|
|
798
|
+
view: "list",
|
|
799
|
+
keys: ["^t"],
|
|
800
|
+
action: "only services: tasks that run until you stop them",
|
|
801
|
+
hint: "^t services",
|
|
802
|
+
rank: 7
|
|
803
|
+
},
|
|
804
|
+
{
|
|
805
|
+
surface: "tui",
|
|
806
|
+
view: "list",
|
|
807
|
+
keys: ["^e"],
|
|
808
|
+
action: "exact search instead of fuzzy",
|
|
809
|
+
hint: "^e exact",
|
|
810
|
+
rank: 8
|
|
811
|
+
},
|
|
812
|
+
{
|
|
813
|
+
surface: "tui",
|
|
814
|
+
view: "list",
|
|
815
|
+
keys: ["^d"],
|
|
816
|
+
action: "only tasks a file declares, not inferred ones",
|
|
817
|
+
hint: "^d declared",
|
|
818
|
+
rank: 9
|
|
819
|
+
},
|
|
820
|
+
{
|
|
821
|
+
surface: "tui",
|
|
822
|
+
view: "list",
|
|
823
|
+
keys: ["^o"],
|
|
824
|
+
action: "scope: all, the root only, or at most 2 or 3 levels down",
|
|
825
|
+
hint: "^o scope",
|
|
826
|
+
rank: 10
|
|
827
|
+
},
|
|
828
|
+
{
|
|
829
|
+
surface: "tui",
|
|
830
|
+
view: "list",
|
|
831
|
+
keys: [
|
|
832
|
+
"↑",
|
|
833
|
+
"↓",
|
|
834
|
+
"^p",
|
|
835
|
+
"^n"
|
|
836
|
+
],
|
|
837
|
+
action: "move by one row"
|
|
838
|
+
},
|
|
839
|
+
{
|
|
840
|
+
surface: "tui",
|
|
841
|
+
view: "list",
|
|
842
|
+
keys: ["pgup", "pgdn"],
|
|
843
|
+
action: "move by a screenful"
|
|
844
|
+
},
|
|
845
|
+
{
|
|
846
|
+
surface: "tui",
|
|
847
|
+
view: "list",
|
|
848
|
+
keys: [
|
|
849
|
+
"home",
|
|
850
|
+
"end",
|
|
851
|
+
"^a"
|
|
852
|
+
],
|
|
853
|
+
action: "first / last row"
|
|
854
|
+
},
|
|
855
|
+
{
|
|
856
|
+
surface: "tui",
|
|
857
|
+
view: "list",
|
|
858
|
+
keys: ["backspace", "^u"],
|
|
859
|
+
action: "delete a character / clear the query"
|
|
860
|
+
},
|
|
861
|
+
{
|
|
862
|
+
surface: "tui",
|
|
863
|
+
view: "list",
|
|
864
|
+
keys: ["?"],
|
|
865
|
+
action: "this list of keys",
|
|
866
|
+
hint: "? help",
|
|
867
|
+
always: true
|
|
868
|
+
},
|
|
869
|
+
{
|
|
870
|
+
surface: "tui",
|
|
871
|
+
view: "list",
|
|
872
|
+
keys: ["esc", "^c"],
|
|
873
|
+
action: "quit, stopping any probe that is running",
|
|
874
|
+
hint: "esc quit",
|
|
875
|
+
always: true
|
|
876
|
+
},
|
|
877
|
+
{
|
|
878
|
+
surface: "tui",
|
|
879
|
+
view: "arguments",
|
|
880
|
+
keys: ["type"],
|
|
881
|
+
action: "the arguments; quotes group words as in sh"
|
|
882
|
+
},
|
|
883
|
+
{
|
|
884
|
+
surface: "tui",
|
|
885
|
+
view: "arguments",
|
|
886
|
+
keys: ["enter"],
|
|
887
|
+
action: "run with what you typed, which may be nothing",
|
|
888
|
+
hint: "enter run",
|
|
889
|
+
always: true
|
|
890
|
+
},
|
|
891
|
+
{
|
|
892
|
+
surface: "tui",
|
|
893
|
+
view: "arguments",
|
|
894
|
+
keys: ["backspace", "^u"],
|
|
895
|
+
action: "delete a character / clear the line"
|
|
896
|
+
},
|
|
897
|
+
{
|
|
898
|
+
surface: "tui",
|
|
899
|
+
view: "arguments",
|
|
900
|
+
keys: ["esc"],
|
|
901
|
+
action: "back to the list; nothing runs",
|
|
902
|
+
hint: "esc back",
|
|
903
|
+
always: true
|
|
904
|
+
},
|
|
905
|
+
{
|
|
906
|
+
surface: "tui",
|
|
907
|
+
view: "settings",
|
|
908
|
+
keys: ["↑", "↓"],
|
|
909
|
+
action: "move between settings"
|
|
910
|
+
},
|
|
911
|
+
{
|
|
912
|
+
surface: "tui",
|
|
913
|
+
view: "settings",
|
|
914
|
+
keys: ["pgup", "pgdn"],
|
|
915
|
+
action: "move by a screenful"
|
|
916
|
+
},
|
|
917
|
+
{
|
|
918
|
+
surface: "tui",
|
|
919
|
+
view: "settings",
|
|
920
|
+
keys: ["space", "enter"],
|
|
921
|
+
action: "turn a runner on or off, or change discovery",
|
|
922
|
+
hint: "space change",
|
|
923
|
+
rank: 1
|
|
924
|
+
},
|
|
925
|
+
{
|
|
926
|
+
surface: "tui",
|
|
927
|
+
view: "settings",
|
|
928
|
+
keys: ["[", "]"],
|
|
929
|
+
action: "move a runner earlier / later in the order",
|
|
930
|
+
hint: "[ ] order",
|
|
931
|
+
rank: 3
|
|
932
|
+
},
|
|
933
|
+
{
|
|
934
|
+
surface: "tui",
|
|
935
|
+
view: "settings",
|
|
936
|
+
keys: ["a"],
|
|
937
|
+
action: "add an excluded path",
|
|
938
|
+
hint: "a add path",
|
|
939
|
+
rank: 2
|
|
940
|
+
},
|
|
941
|
+
{
|
|
942
|
+
surface: "tui",
|
|
943
|
+
view: "settings",
|
|
944
|
+
keys: ["x"],
|
|
945
|
+
action: "remove the selected excluded path",
|
|
946
|
+
hint: "x remove",
|
|
947
|
+
rank: 4
|
|
948
|
+
},
|
|
949
|
+
{
|
|
950
|
+
surface: "tui",
|
|
951
|
+
view: "settings",
|
|
952
|
+
keys: ["t", "u"],
|
|
953
|
+
action: "trust the repository or the selected tool (after a y/n question) / remove it",
|
|
954
|
+
hint: "t/u trust",
|
|
955
|
+
rank: 5
|
|
956
|
+
},
|
|
957
|
+
{
|
|
958
|
+
surface: "tui",
|
|
959
|
+
view: "settings",
|
|
960
|
+
keys: ["?"],
|
|
961
|
+
action: "the list of keys",
|
|
962
|
+
hint: "? help"
|
|
963
|
+
},
|
|
964
|
+
{
|
|
965
|
+
surface: "tui",
|
|
966
|
+
view: "settings",
|
|
967
|
+
keys: ["esc", ","],
|
|
968
|
+
action: "back to the list",
|
|
969
|
+
hint: "esc back",
|
|
970
|
+
always: true
|
|
971
|
+
},
|
|
972
|
+
{
|
|
973
|
+
surface: "tui",
|
|
974
|
+
view: "help",
|
|
975
|
+
keys: [
|
|
976
|
+
"↑",
|
|
977
|
+
"↓",
|
|
978
|
+
"pgup",
|
|
979
|
+
"pgdn"
|
|
980
|
+
],
|
|
981
|
+
action: "scroll"
|
|
982
|
+
},
|
|
983
|
+
{
|
|
984
|
+
surface: "tui",
|
|
985
|
+
view: "help",
|
|
986
|
+
keys: ["esc", "?"],
|
|
987
|
+
action: "close this screen",
|
|
988
|
+
hint: "esc back",
|
|
989
|
+
always: true
|
|
990
|
+
},
|
|
991
|
+
{
|
|
992
|
+
surface: "web",
|
|
993
|
+
view: "list",
|
|
994
|
+
keys: ["/"],
|
|
995
|
+
action: "search"
|
|
996
|
+
},
|
|
997
|
+
{
|
|
998
|
+
surface: "web",
|
|
999
|
+
view: "list",
|
|
1000
|
+
keys: ["enter"],
|
|
1001
|
+
action: "copy the top hit, or the focused task"
|
|
1002
|
+
},
|
|
1003
|
+
{
|
|
1004
|
+
surface: "web",
|
|
1005
|
+
view: "list",
|
|
1006
|
+
keys: ["shift+enter"],
|
|
1007
|
+
action: "run the top hit, or the focused task"
|
|
1008
|
+
},
|
|
1009
|
+
{
|
|
1010
|
+
surface: "web",
|
|
1011
|
+
view: "list",
|
|
1012
|
+
keys: ["↑", "↓"],
|
|
1013
|
+
action: "move through the tasks"
|
|
1014
|
+
},
|
|
1015
|
+
{
|
|
1016
|
+
surface: "web",
|
|
1017
|
+
view: "list",
|
|
1018
|
+
keys: ["esc"],
|
|
1019
|
+
action: "back to search; again to clear it"
|
|
1020
|
+
},
|
|
1021
|
+
{
|
|
1022
|
+
surface: "web",
|
|
1023
|
+
view: "list",
|
|
1024
|
+
keys: ["?"],
|
|
1025
|
+
action: "this help"
|
|
1026
|
+
},
|
|
1027
|
+
{
|
|
1028
|
+
surface: "web",
|
|
1029
|
+
view: "arguments",
|
|
1030
|
+
keys: ["enter"],
|
|
1031
|
+
action: "run with what you typed"
|
|
1032
|
+
},
|
|
1033
|
+
{
|
|
1034
|
+
surface: "web",
|
|
1035
|
+
view: "arguments",
|
|
1036
|
+
keys: ["esc"],
|
|
1037
|
+
action: "close the run bar; nothing runs"
|
|
1038
|
+
}
|
|
1039
|
+
]);
|
|
1040
|
+
/** The keys of one view on one surface, in table order. */
|
|
1041
|
+
function keysFor(surface, view) {
|
|
1042
|
+
return KEY_TABLE.filter((k) => k.surface === surface && k.view === view);
|
|
324
1043
|
}
|
|
325
1044
|
//#endregion
|
|
326
1045
|
//#region src/web/view.ts
|
|
@@ -337,10 +1056,13 @@ function brandOf(runner) {
|
|
|
337
1056
|
return (state.catalog?.reports || []).find((r) => r.runner === runner)?.brand || null;
|
|
338
1057
|
}
|
|
339
1058
|
/**
|
|
340
|
-
* The runner's icon, inserted unescaped on purpose
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
1059
|
+
* The runner's icon, inserted unescaped on purpose: it is inline SVG, and
|
|
1060
|
+
* escaping it would print the markup instead of drawing it. It comes from the
|
|
1061
|
+
* tool's definition, which is code this process already runs (a repository's
|
|
1062
|
+
* own tool module loads only once it is trusted), so it is trusted as that
|
|
1063
|
+
* code is. Text fields of the same tool are still escaped, as all text is.
|
|
1064
|
+
* The page's content security policy keeps a script in the markup from
|
|
1065
|
+
* running.
|
|
344
1066
|
*/
|
|
345
1067
|
function iconHtml(runner) {
|
|
346
1068
|
const icon = brandOf(runner)?.icon;
|
|
@@ -367,7 +1089,8 @@ function rowAttrs(e) {
|
|
|
367
1089
|
return brandAttrs(e.runner) + " data-id=\"" + escapeHtml(e.id) + "\" tabindex=\"-1\"";
|
|
368
1090
|
}
|
|
369
1091
|
/** Wrap the matched character positions of `text` in <mark>. */
|
|
370
|
-
function highlight(
|
|
1092
|
+
function highlight(raw, idx) {
|
|
1093
|
+
const text = terminalSafe(raw);
|
|
371
1094
|
if (!idx || !idx.length) return escapeHtml(text);
|
|
372
1095
|
const set = new Set(idx);
|
|
373
1096
|
let out = "", open = false;
|
|
@@ -386,6 +1109,22 @@ function highlight(text, idx) {
|
|
|
386
1109
|
return out + (open ? "</mark>" : "");
|
|
387
1110
|
}
|
|
388
1111
|
/**
|
|
1112
|
+
* Repository text as HTML: escaped, with the control characters a terminal
|
|
1113
|
+
* would get replaced, so a bidi override cannot make a row read differently
|
|
1114
|
+
* from what runs. `multiline` keeps tab and newline, for prose.
|
|
1115
|
+
*/
|
|
1116
|
+
function shown(text, multiline = false) {
|
|
1117
|
+
return escapeHtml(terminalSafe(text, { multiline }));
|
|
1118
|
+
}
|
|
1119
|
+
/**
|
|
1120
|
+
* A tool's homepage as a link, or '' when it is not http or https. The core
|
|
1121
|
+
* already drops other schemes; this checks again because the page renders it.
|
|
1122
|
+
*/
|
|
1123
|
+
function homepageLink(url, text = url ?? "") {
|
|
1124
|
+
if (url === null || !/^https?:\/\//i.test(url)) return "";
|
|
1125
|
+
return "<a href=\"" + escapeHtml(url) + "\" target=\"_blank\" rel=\"noopener noreferrer\">" + escapeHtml(text) + "</a>";
|
|
1126
|
+
}
|
|
1127
|
+
/**
|
|
389
1128
|
* Rebuild the call-chain tree from whatever leaves survived the filter, so a
|
|
390
1129
|
* group header only appears while it still has something under it.
|
|
391
1130
|
*/
|
|
@@ -412,12 +1151,24 @@ function buildTree(rows) {
|
|
|
412
1151
|
}
|
|
413
1152
|
return root;
|
|
414
1153
|
}
|
|
415
|
-
|
|
1154
|
+
/**
|
|
1155
|
+
* The tree under `node`. `loading` names runners still loading; the combined
|
|
1156
|
+
* index's top level shows a row for each in the place its group will take.
|
|
1157
|
+
*/
|
|
1158
|
+
function renderNode(node, prefix, loading = []) {
|
|
416
1159
|
let html = "";
|
|
417
1160
|
const order = runnerOrder();
|
|
418
1161
|
const topLevel = treeStart() === 0 && prefix.length === 0;
|
|
419
|
-
const groups = [...node.kids.entries()]
|
|
1162
|
+
const groups = [...node.kids.entries()];
|
|
1163
|
+
if (topLevel) {
|
|
1164
|
+
for (const r of loading) if (!node.kids.has(r)) groups.push([r, null]);
|
|
1165
|
+
}
|
|
1166
|
+
groups.sort((a, b) => topLevel ? order.indexOf(a[0]) - order.indexOf(b[0]) : a[0].localeCompare(b[0]));
|
|
420
1167
|
for (const [seg, kid] of groups) {
|
|
1168
|
+
if (kid === null) {
|
|
1169
|
+
html += loadingRow(seg);
|
|
1170
|
+
continue;
|
|
1171
|
+
}
|
|
421
1172
|
const key = prefix.concat(seg).join(" ");
|
|
422
1173
|
const collapsed = state.collapsed.has(key);
|
|
423
1174
|
const depth = prefix.length;
|
|
@@ -425,7 +1176,7 @@ function renderNode(node, prefix) {
|
|
|
425
1176
|
const icon = treeStart() === 0 && depth === 0 ? iconHtml(seg) : "";
|
|
426
1177
|
const top = "calc(var(--chrome-h) + " + depth + " * var(--head-h))";
|
|
427
1178
|
const layer = Math.max(1, 20 - depth);
|
|
428
|
-
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>";
|
|
1179
|
+
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(treeStart() === 0 && depth === 0 ? runnerLabel(seg) : 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>";
|
|
429
1180
|
}
|
|
430
1181
|
if (node.leaves.length) {
|
|
431
1182
|
const sorted = node.leaves.slice().sort((a, b) => b.score - a.score || a.entry.path.join().localeCompare(b.entry.path.join()));
|
|
@@ -443,30 +1194,42 @@ function serviceIcon(declared) {
|
|
|
443
1194
|
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>";
|
|
444
1195
|
}
|
|
445
1196
|
/**
|
|
446
|
-
*
|
|
447
|
-
*
|
|
1197
|
+
* What Copy hands over, which is not always what the Command column shows:
|
|
1198
|
+
* the argv quoted for the server's shell, as the CLI and the terminal UI
|
|
1199
|
+
* copy it. A task bound to its own directory gets the `cd` it needs, since
|
|
1200
|
+
* without it the copied command would fail. Null when the line holds a
|
|
1201
|
+
* control character, so the button refuses to copy.
|
|
448
1202
|
*/
|
|
449
|
-
function
|
|
450
|
-
return
|
|
1203
|
+
function copyText(task) {
|
|
1204
|
+
return taskCopyText(task, serverPlatform());
|
|
451
1205
|
}
|
|
452
1206
|
/**
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
* Most tasks are written to run from the repository root and are copied as
|
|
456
|
-
* they are. A task bound to its own directory gets the `cd` it needs, since
|
|
457
|
-
* without it the copied command would fail. `argv` is unchanged either way,
|
|
458
|
-
* because anything that spawns a task already uses the directory.
|
|
1207
|
+
* A Copy button for `text`. A null `text` held a control character: the
|
|
1208
|
+
* button is disabled, says why, and carries nothing to copy.
|
|
459
1209
|
*/
|
|
460
|
-
function
|
|
461
|
-
|
|
1210
|
+
function copyButton(text, title) {
|
|
1211
|
+
if (text === null) return "<button class=\"copy\" disabled title=\"" + escapeHtml(COPY_REFUSED) + "\" aria-label=\"" + escapeHtml(COPY_REFUSED) + "\">copy</button>";
|
|
1212
|
+
return "<button class=\"copy\" title=\"" + escapeHtml(title) + "\" aria-label=\"" + escapeHtml("Copy " + text) + "\" data-run=\"" + escapeHtml(text) + "\">copy</button>";
|
|
462
1213
|
}
|
|
463
1214
|
/** What Run does, stated up front: the page ends and the task takes the terminal. */
|
|
464
1215
|
function runTip(task) {
|
|
465
|
-
|
|
1216
|
+
if (task.parametersUnknown === "editor-variable") return terminalSafe(task.display) + ": " + parametersUnknownLabel("editor-variable") + ".";
|
|
1217
|
+
return "Run " + terminalSafe(task.display) + " in the terminal wayfinder is serving from. The server exits and this page is finished.";
|
|
1218
|
+
}
|
|
1219
|
+
/**
|
|
1220
|
+
* The marker for a task whose parameters could not be read, with the one
|
|
1221
|
+
* label every surface shows for it. Run asks for arguments before such a
|
|
1222
|
+
* task runs, since it may need some.
|
|
1223
|
+
*/
|
|
1224
|
+
function paramsMark(task) {
|
|
1225
|
+
const reason = task.parametersUnknown;
|
|
1226
|
+
if (reason === void 0) return "";
|
|
1227
|
+
const label = parametersUnknownLabel(reason);
|
|
1228
|
+
return "<span class=\"ind-params\" title=\"" + escapeHtml(label) + "\">?<span class=\"sr\">" + escapeHtml(label) + "</span></span>";
|
|
466
1229
|
}
|
|
467
1230
|
/** Why a row's Copy is longer than its Command, said only when it is. */
|
|
468
|
-
function copyTip(task) {
|
|
469
|
-
return task.cwd === "." ? "Copy the command to the clipboard." : "Copy
|
|
1231
|
+
function copyTip(task, text) {
|
|
1232
|
+
return task.cwd === "." ? "Copy the command to the clipboard." : "Copy " + text + " — it changes directory first, because this task must run from there.";
|
|
470
1233
|
}
|
|
471
1234
|
/**
|
|
472
1235
|
* The columns, in the order the colgroup declares them, plus the depth spacer
|
|
@@ -476,8 +1239,9 @@ function copyTip(task) {
|
|
|
476
1239
|
* row's chain out of line with its neighbours.
|
|
477
1240
|
*/
|
|
478
1241
|
function cells(e, nameHtml, depth = 0) {
|
|
1242
|
+
const copied = copyText(e);
|
|
479
1243
|
const p = e.persistent;
|
|
480
|
-
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=\"" +
|
|
1244
|
+
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>" : "") + paramsMark(e) + "</span></td>" + spacerCell(depth) + "<td class=\"name\" title=\"" + shown(displayPath(e.path, e.runner).join(SEP)) + "\">" + nameHtml + "</td><td class=\"run\" title=\"" + shown(e.display) + "\">" + shown(e.display) + "</td>" + (showRuns() ? "<td class=\"doc\">" + shown(e.doc || "", true) + (e.detail && e.detail !== e.display ? "<span class=\"detail\" title=\"" + shown(e.detail, true) + "\">" + shown(e.detail, true) + "</span>" : "") + "</td>" : "") + "<td class=\"act\"><button class=\"runbtn\" data-run-id=\"" + escapeHtml(e.id) + "\" title=\"" + escapeHtml(runTip(e)) + "\" aria-label=\"" + shown("Run " + e.display + " in the terminal") + "\"" + (e.parametersUnknown === "editor-variable" ? " disabled" : "") + ">run</button>" + copyButton(copied, copied === null ? "" : copyTip(e, copied)) + "</td>";
|
|
481
1245
|
}
|
|
482
1246
|
/** Each `.kids` level costs 14px margin + 11px padding. */
|
|
483
1247
|
const INDENT_PER_LEVEL = 25;
|
|
@@ -488,17 +1252,16 @@ function outdent(depth) {
|
|
|
488
1252
|
}
|
|
489
1253
|
/**
|
|
490
1254
|
* The action column. Wide enough for `run` beside the enter-target row's
|
|
491
|
-
* `↵ copy`, the widest the column gets
|
|
492
|
-
*
|
|
493
|
-
* 35.23 + a 4px gap + `↵ copy` 57.89 + the cell's 8px right padding is 105.12.
|
|
494
|
-
*
|
|
495
|
-
* 112 rather than 106, because 106 leaves only 0.88px. A fallback font or one
|
|
496
|
-
* more pixel of button padding would then clip, and silently: the row's
|
|
497
|
-
* actions would lose their right edge. The 6.88px is spare room.
|
|
1255
|
+
* `↵ copy`, the widest the column gets, with a few pixels to spare so a
|
|
1256
|
+
* fallback font does not clip the buttons.
|
|
498
1257
|
*/
|
|
499
1258
|
const ACT_W = 112;
|
|
500
|
-
/** The
|
|
1259
|
+
/** The action column at phone width, where the buttons are smaller. */
|
|
1260
|
+
const ACT_W_NARROW = 96;
|
|
1261
|
+
/** The indicator gutter: room for the service dot and the parameters mark. */
|
|
501
1262
|
const IND_W = 30;
|
|
1263
|
+
/** Below this table width the page is laid out for a phone. */
|
|
1264
|
+
const NARROW_W = 600;
|
|
502
1265
|
/**
|
|
503
1266
|
* Below this the Runs column is dropped. Runs is cut off too much to be useful
|
|
504
1267
|
* below a 1100px viewport. `main` pads 16px on each side, so that is about
|
|
@@ -506,18 +1269,74 @@ const IND_W = 30;
|
|
|
506
1269
|
* the width of the table area (`main` minus its padding), not of the window.
|
|
507
1270
|
*/
|
|
508
1271
|
const RUNS_MIN_W = 1068;
|
|
1272
|
+
/**
|
|
1273
|
+
* Sizes measured from the rows of the last render: whether any row has
|
|
1274
|
+
* text for the Runs column, and how wide the Task column must be for the
|
|
1275
|
+
* longest name, indent included. null when it could not be measured.
|
|
1276
|
+
*/
|
|
1277
|
+
let measured = {
|
|
1278
|
+
runsHaveText: true,
|
|
1279
|
+
nameW: null
|
|
1280
|
+
};
|
|
509
1281
|
/** The width every table's columns are measured against. */
|
|
510
1282
|
function availWidth() {
|
|
511
|
-
return Math.max(
|
|
1283
|
+
return Math.max(300, state.mainWidth || 1e3);
|
|
1284
|
+
}
|
|
1285
|
+
function actWidth() {
|
|
1286
|
+
return availWidth() < NARROW_W ? ACT_W_NARROW : ACT_W;
|
|
512
1287
|
}
|
|
513
1288
|
/**
|
|
514
|
-
* Whether the Runs column is shown right now
|
|
1289
|
+
* Whether the Runs column is shown right now: the table is wide enough, and
|
|
1290
|
+
* some row has something to put in it. `colgroup`, `cells` and
|
|
515
1291
|
* `renderColHeads` all call this, because if a table's colgroup, head row and
|
|
516
1292
|
* body rows disagree on the number of columns, every column after the first
|
|
517
1293
|
* is misaligned.
|
|
518
1294
|
*/
|
|
519
1295
|
function showRuns() {
|
|
520
|
-
return availWidth() >= RUNS_MIN_W;
|
|
1296
|
+
return availWidth() >= RUNS_MIN_W && measured.runsHaveText;
|
|
1297
|
+
}
|
|
1298
|
+
/** The width of `text` in the Task column's font, or null without a canvas. */
|
|
1299
|
+
let measureCtx;
|
|
1300
|
+
function textWidth(text) {
|
|
1301
|
+
if (measureCtx === void 0) {
|
|
1302
|
+
try {
|
|
1303
|
+
measureCtx = document.createElement("canvas").getContext("2d");
|
|
1304
|
+
} catch {
|
|
1305
|
+
measureCtx = null;
|
|
1306
|
+
}
|
|
1307
|
+
if (measureCtx) {
|
|
1308
|
+
const mono = getComputedStyle(document.documentElement).getPropertyValue("--wf-font-mono");
|
|
1309
|
+
measureCtx.font = "600 13px " + (mono.trim() || "monospace");
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
return measureCtx ? measureCtx.measureText(text).width : null;
|
|
1313
|
+
}
|
|
1314
|
+
/** Measure the rows a render is about to draw. See {@link measured}. */
|
|
1315
|
+
function measureRows(rows, flat, skills = []) {
|
|
1316
|
+
let nameW = 0;
|
|
1317
|
+
const skillDepth = !flat && state.runner === "all" ? 1 : 0;
|
|
1318
|
+
for (const hit of skills) {
|
|
1319
|
+
const w = textWidth(skillLine(hit.skill));
|
|
1320
|
+
if (w === null) {
|
|
1321
|
+
nameW = null;
|
|
1322
|
+
break;
|
|
1323
|
+
}
|
|
1324
|
+
nameW = Math.max(nameW ?? 0, w + skillDepth * INDENT_PER_LEVEL);
|
|
1325
|
+
}
|
|
1326
|
+
for (const row of nameW === null ? [] : rows) {
|
|
1327
|
+
const e = row.entry;
|
|
1328
|
+
const depth = flat ? 0 : Math.max(0, e.path.length - 1 - treeStart());
|
|
1329
|
+
const w = textWidth(flat ? displayPath(e.path, e.runner).join(SEP) : e.path.at(-1) ?? "");
|
|
1330
|
+
if (w === null) {
|
|
1331
|
+
nameW = null;
|
|
1332
|
+
break;
|
|
1333
|
+
}
|
|
1334
|
+
nameW = Math.max(nameW ?? 0, w + depth * INDENT_PER_LEVEL);
|
|
1335
|
+
}
|
|
1336
|
+
measured = {
|
|
1337
|
+
runsHaveText: skills.length > 0 || rows.some((r) => (r.entry.doc ?? "") !== "" || (r.entry.detail ?? "") !== ""),
|
|
1338
|
+
nameW
|
|
1339
|
+
};
|
|
521
1340
|
}
|
|
522
1341
|
/**
|
|
523
1342
|
* The columns, named once. `tip` is the hover text. The help modal has the
|
|
@@ -527,7 +1346,7 @@ function showRuns() {
|
|
|
527
1346
|
const COLUMNS = [
|
|
528
1347
|
{
|
|
529
1348
|
label: "",
|
|
530
|
-
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."
|
|
1349
|
+
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. A ? means its parameters could not be read, so Run asks for arguments."
|
|
531
1350
|
},
|
|
532
1351
|
{
|
|
533
1352
|
label: "Task",
|
|
@@ -543,7 +1362,33 @@ const COLUMNS = [
|
|
|
543
1362
|
},
|
|
544
1363
|
{
|
|
545
1364
|
label: "",
|
|
546
|
-
tip: "Row actions. Run hands the task to the terminal
|
|
1365
|
+
tip: "Row actions. Run hands the task to the terminal " + APP + " 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."
|
|
1366
|
+
}
|
|
1367
|
+
];
|
|
1368
|
+
/**
|
|
1369
|
+
* The columns on the Skills tab, in the same slots as {@link COLUMNS}: a
|
|
1370
|
+
* skill row holds its name, what it does and where it comes from.
|
|
1371
|
+
*/
|
|
1372
|
+
const SKILL_COLUMNS = [
|
|
1373
|
+
{
|
|
1374
|
+
label: "",
|
|
1375
|
+
tip: ""
|
|
1376
|
+
},
|
|
1377
|
+
{
|
|
1378
|
+
label: SKILL_NOUN.one[0].toUpperCase() + SKILL_NOUN.one.slice(1),
|
|
1379
|
+
tip: "The /name to type to an agent, with the arguments it takes."
|
|
1380
|
+
},
|
|
1381
|
+
{
|
|
1382
|
+
label: "About",
|
|
1383
|
+
tip: "The agents that read it, and what it does."
|
|
1384
|
+
},
|
|
1385
|
+
{
|
|
1386
|
+
label: "From",
|
|
1387
|
+
tip: "Where it comes from: the project or your user folder, and its file."
|
|
1388
|
+
},
|
|
1389
|
+
{
|
|
1390
|
+
label: "",
|
|
1391
|
+
tip: "Copy puts the /name on the clipboard, ready to type to an agent."
|
|
547
1392
|
}
|
|
548
1393
|
];
|
|
549
1394
|
/**
|
|
@@ -555,23 +1400,28 @@ const COLUMNS = [
|
|
|
555
1400
|
* A leading spacer column as wide as the outdent puts the content back under
|
|
556
1401
|
* its group header, and the name column gives up the same amount. So the
|
|
557
1402
|
* command column starts at the same x at every depth, and no row text lands
|
|
558
|
-
* in the strip left of the headers.
|
|
559
|
-
* header as rows scroll under it, because a header's background stops at its
|
|
560
|
-
* own indented box.
|
|
1403
|
+
* in the strip left of the headers.
|
|
561
1404
|
*
|
|
562
|
-
*
|
|
563
|
-
*
|
|
564
|
-
*
|
|
565
|
-
*
|
|
1405
|
+
* Task is sized to its longest name, up to a share of the width (a larger
|
|
1406
|
+
* share at phone width); Command
|
|
1407
|
+
* takes what is left, shared with Runs when Runs is shown. The sized columns
|
|
1408
|
+
* add up to the table's width exactly, because `table-layout: fixed` would
|
|
1409
|
+
* spread any leftover across the columns and move the command column at
|
|
1410
|
+
* every depth.
|
|
566
1411
|
*/
|
|
567
1412
|
function colgroup(depth) {
|
|
568
1413
|
const indent = depth * INDENT_PER_LEVEL;
|
|
569
1414
|
const avail = availWidth();
|
|
1415
|
+
const act = actWidth();
|
|
570
1416
|
const wide = showRuns();
|
|
571
|
-
const rest = avail - IND_W -
|
|
572
|
-
const
|
|
573
|
-
const
|
|
574
|
-
|
|
1417
|
+
const rest = avail - IND_W - act;
|
|
1418
|
+
const content = measured.nameW === null ? null : Math.ceil(measured.nameW) + 16;
|
|
1419
|
+
const cap = Math.round(rest * (wide ? .4 : avail < NARROW_W ? .62 : .5));
|
|
1420
|
+
const nameTotal = Math.max(90, Math.min(cap, content ?? Math.round(rest * .45)));
|
|
1421
|
+
const name = Math.max(40, nameTotal - indent);
|
|
1422
|
+
const left = rest - nameTotal;
|
|
1423
|
+
const run = wide ? Math.round(left * .55) : left;
|
|
1424
|
+
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:" + act + "px\" /></colgroup>";
|
|
575
1425
|
}
|
|
576
1426
|
/** The empty leading cell the spacer column needs, when there is one. */
|
|
577
1427
|
function spacerCell(depth) {
|
|
@@ -582,13 +1432,14 @@ function renderTreeRow(row, depth) {
|
|
|
582
1432
|
const e = row.entry;
|
|
583
1433
|
const covered = treeStart() + depth;
|
|
584
1434
|
const rest = e.path.slice(covered);
|
|
585
|
-
const
|
|
1435
|
+
const restShown = displayPath(e.path, e.runner).slice(covered);
|
|
1436
|
+
const shown = restShown.join(SEP);
|
|
586
1437
|
const skipped = covered > 0 ? e.path.slice(0, covered).join(" ").length + 1 : 0;
|
|
587
1438
|
const marks = new Set(row.labelHits || []);
|
|
588
1439
|
let html = "";
|
|
589
1440
|
let at = skipped;
|
|
590
1441
|
for (let i = 0; i < rest.length; i++) {
|
|
591
|
-
html += highlight(rest[i], [...marks].map((m) => m - at).filter((m) => m >= 0 && m < rest[i].length));
|
|
1442
|
+
html += restShown[i] !== rest[i] ? escapeHtml(restShown[i]) : highlight(rest[i], [...marks].map((m) => m - at).filter((m) => m >= 0 && m < rest[i].length));
|
|
592
1443
|
at += rest[i].length + 1;
|
|
593
1444
|
if (i < rest.length - 1) html += "<span class=\"chain\"> › </span>";
|
|
594
1445
|
}
|
|
@@ -598,11 +1449,21 @@ function renderTreeRow(row, depth) {
|
|
|
598
1449
|
function renderSearchRow(row) {
|
|
599
1450
|
const e = row.entry;
|
|
600
1451
|
const chain = chainOf(e.runner);
|
|
1452
|
+
const shownPath = displayPath(e.path, e.runner);
|
|
601
1453
|
const idx = new Set(row.labelHits || []);
|
|
602
1454
|
let out = "", cursor = 0, open = false;
|
|
603
1455
|
for (let p = 0; p < e.path.length; p++) {
|
|
604
1456
|
const seg = chain[p];
|
|
605
1457
|
out += seg ? "<span class=\"seg-hit\" title=\"" + escapeHtml(seg.label + " - " + seg.hint) + "\">" : "<span>";
|
|
1458
|
+
if (shownPath[p] !== e.path[p]) {
|
|
1459
|
+
out += escapeHtml(shownPath[p]) + "</span>";
|
|
1460
|
+
cursor += e.path[p].length;
|
|
1461
|
+
if (p < e.path.length - 1) {
|
|
1462
|
+
out += "<span class=\"chain\"> › </span>";
|
|
1463
|
+
cursor++;
|
|
1464
|
+
}
|
|
1465
|
+
continue;
|
|
1466
|
+
}
|
|
606
1467
|
for (const ch of e.path[p]) {
|
|
607
1468
|
const on = idx.has(cursor);
|
|
608
1469
|
if (on && !open) {
|
|
@@ -629,38 +1490,60 @@ function renderSearchRow(row) {
|
|
|
629
1490
|
return "<tr" + rowAttrs(e) + ">" + cells(e, out) + "</tr>";
|
|
630
1491
|
}
|
|
631
1492
|
/**
|
|
632
|
-
*
|
|
633
|
-
*
|
|
634
|
-
*
|
|
635
|
-
*
|
|
636
|
-
* This is where a task is declared, not how the tree draws it. The Depth
|
|
637
|
-
* control filters on it, so "Root" is the few commands the repository itself
|
|
638
|
-
* declares, not the ones its packages do.
|
|
1493
|
+
* One skill row, in the same columns as a task: the `/<name>` line, the
|
|
1494
|
+
* harnesses and description, the origin and file, and Copy. A skill has no
|
|
1495
|
+
* command line, so it has no Run button; Run on it (Shift+Enter) copies too
|
|
1496
|
+
* (see input.ts). Nothing is sent to the server.
|
|
639
1497
|
*/
|
|
640
|
-
function
|
|
641
|
-
const
|
|
642
|
-
|
|
1498
|
+
function renderSkillRow(hit, depth = 0) {
|
|
1499
|
+
const s = hit.skill;
|
|
1500
|
+
const line = skillLine(s);
|
|
1501
|
+
const shift = s.invoke.endsWith(s.name) ? s.invoke.length - s.name.length : 0;
|
|
1502
|
+
const name = highlight(line, hit.labelHits === null ? null : hit.labelHits.map((i) => i + shift));
|
|
1503
|
+
const description = s.description ?? "";
|
|
1504
|
+
const copy = skillCopyText(s);
|
|
1505
|
+
return "<tr data-skill=\"1\" data-id=\"" + escapeHtml(s.id) + "\" tabindex=\"-1\"><td class=\"ind\"><span class=\"inds\"></span></td>" + spacerCell(depth) + "<td class=\"name\" title=\"" + shown(line) + "\">" + name + "</td><td class=\"run skill-about\" title=\"" + shown(description, true) + "\">" + s.harnesses.map((h) => "<span class=\"skill-for\">" + escapeHtml(h) + "</span>").join("") + shown(description, true) + "</td>" + (showRuns() ? "<td class=\"doc\">" + escapeHtml(s.origin) + "<span class=\"detail\" title=\"" + shown(s.path) + "\">" + shown(s.path) + "</span></td>" : "") + "<td class=\"act\">" + copyButton(copy, "Copy " + (copy ?? "") + " to type to " + (s.harnesses.join(", ") || "an agent") + ".") + "</td></tr>";
|
|
1506
|
+
}
|
|
1507
|
+
/** The skills table at `depth`. */
|
|
1508
|
+
function skillTable(hits, depth) {
|
|
1509
|
+
return "<table style=\"" + outdent(depth) + "\">" + colgroup(depth) + "<tbody>" + hits.map((h) => renderSkillRow(h, depth)).join("") + "</tbody></table>";
|
|
1510
|
+
}
|
|
1511
|
+
/** The Skills group in the combined tree: one header like a runner's, then its rows. */
|
|
1512
|
+
function skillsNode(hits) {
|
|
1513
|
+
const key = SKILLS;
|
|
1514
|
+
const collapsed = state.collapsed.has(key);
|
|
1515
|
+
return "<div class=\"node\" data-collapsed=\"" + collapsed + "\" data-key=\"" + escapeHtml(key) + "\"><div class=\"head\" style=\"top:calc(var(--chrome-h) + 0 * var(--head-h));z-index:20\"><span class=\"twisty\">" + (collapsed ? "▸" : "▾") + "</span><span class=\"seg-name\">" + escapeHtml(SKILLS_GROUP.title) + "</span><span class=\"node-count\">" + hits.length + "</span></div><div class=\"kids\">" + skillTable(hits, 1) + "</div></div>";
|
|
643
1516
|
}
|
|
644
1517
|
/**
|
|
1518
|
+
* The skills the current view shows: on the combined and Skills tabs, kept
|
|
1519
|
+
* by the same filter as the tasks. A runner's tab shows none, and so does
|
|
1520
|
+
* Services (see `filterSkills`).
|
|
1521
|
+
*/
|
|
1522
|
+
function skillHits(filter) {
|
|
1523
|
+
if (state.runner !== "all" && state.runner !== "@skills") return [];
|
|
1524
|
+
return filterSkills(state.catalog?.skills ?? [], filter);
|
|
1525
|
+
}
|
|
1526
|
+
/** Counts the status line shows for skills, set by the last render. */
|
|
1527
|
+
let skillCounts = {
|
|
1528
|
+
shown: 0,
|
|
1529
|
+
total: 0
|
|
1530
|
+
};
|
|
1531
|
+
/**
|
|
645
1532
|
* The one runner order, used by the tabs, the picker and the tree's top level.
|
|
646
1533
|
* All three must agree, or the tab bar no longer matches the page below it.
|
|
647
1534
|
*
|
|
648
|
-
* Grouped first (tasks, dependencies, tools, git hooks), then
|
|
649
|
-
* within a group.
|
|
650
|
-
*
|
|
651
|
-
*
|
|
1535
|
+
* Grouped first (tasks, dependencies, tools, git hooks), then by
|
|
1536
|
+
* `runners.order` within a group. A drag writes `runners.order` to the user
|
|
1537
|
+
* config. The server sends the catalog in the configured order, so a runner
|
|
1538
|
+
* not in the order keeps its catalog place after the ones that are.
|
|
652
1539
|
*/
|
|
653
1540
|
function runnerOrder() {
|
|
654
|
-
const
|
|
1541
|
+
const reported = (state.catalog?.reports || []).map((r) => r.runner);
|
|
1542
|
+
const present = state.live ? [...state.order, ...reported.filter((r) => !state.order.includes(r))] : reported;
|
|
655
1543
|
const saved = state.runnerOrder.filter((r) => present.includes(r));
|
|
656
|
-
const unsaved = present.filter((r) => !saved.includes(r))
|
|
1544
|
+
const unsaved = present.filter((r) => !saved.includes(r));
|
|
657
1545
|
return [...saved, ...unsaved].sort((a, b) => groupRank(a) - groupRank(b));
|
|
658
1546
|
}
|
|
659
|
-
function saveRunnerOrder(order) {
|
|
660
|
-
state.runnerOrder = order;
|
|
661
|
-
persistRunnerOrder(order);
|
|
662
|
-
render();
|
|
663
|
-
}
|
|
664
1547
|
/** The runner order re-sorted by one key, ties broken alphabetically. */
|
|
665
1548
|
function sortedRunnerOrder(key, dir) {
|
|
666
1549
|
const reports = state.catalog?.reports || [];
|
|
@@ -705,13 +1588,13 @@ function activeSort() {
|
|
|
705
1588
|
};
|
|
706
1589
|
return null;
|
|
707
1590
|
}
|
|
708
|
-
/**
|
|
1591
|
+
/** The runner order sorted by `key`, remembered as the sort last asked for. */
|
|
709
1592
|
function sortRunners(key, dir) {
|
|
710
1593
|
requestedSort = {
|
|
711
1594
|
key,
|
|
712
1595
|
dir
|
|
713
1596
|
};
|
|
714
|
-
|
|
1597
|
+
return sortedRunnerOrder(key, dir);
|
|
715
1598
|
}
|
|
716
1599
|
function scopedReports() {
|
|
717
1600
|
const all = (state.catalog?.reports || []).filter((s) => !state.enabled || state.enabled.has(s.runner));
|
|
@@ -730,18 +1613,19 @@ function treeStart() {
|
|
|
730
1613
|
return state.runner === "all" ? 0 : 1;
|
|
731
1614
|
}
|
|
732
1615
|
/**
|
|
733
|
-
*
|
|
734
|
-
*
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
1616
|
+
* A withheld runner's label, from the catalog's unknowns: `withheld: mise is
|
|
1617
|
+
* not trusted` when a tool it runs is what is missing.
|
|
1618
|
+
*/
|
|
1619
|
+
function withheldNote(runner) {
|
|
1620
|
+
return state.unknowns.find((u) => u.kind === "withheld" && u.runner === runner)?.label ?? withheldLabel(state.trustable ? "untrusted" : "exec-off");
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
* Why a runner reports nothing when execution is off, in the words every
|
|
1624
|
+
* surface uses. Three places show it: the tab's tooltip, the picker's note
|
|
1625
|
+
* and the per-runner modal.
|
|
740
1626
|
*/
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
function execNote() {
|
|
744
|
-
return state.trustable ? EXEC_NOTE_UNTRUSTED : EXEC_NOTE_OFF;
|
|
1627
|
+
function execNote(runner) {
|
|
1628
|
+
return "This runner can only be read by running it. " + withheldNote(runner) + ".";
|
|
745
1629
|
}
|
|
746
1630
|
/**
|
|
747
1631
|
* The trust grant button. Offered wherever the withheld runners are explained:
|
|
@@ -759,16 +1643,64 @@ const TRUST_BUTTON = "<button class=\"toolbtn\" data-trust-repo=\"1\" title=\"Re
|
|
|
759
1643
|
*/
|
|
760
1644
|
function foldedChip(reports) {
|
|
761
1645
|
if (reports.length === 0) return "";
|
|
762
|
-
const names = reports.map((s) => s.runner);
|
|
1646
|
+
const names = reports.map((s) => runnerLabel(s.runner));
|
|
763
1647
|
const label = names.length + (names.length === 1 ? " empty runner" : " empty runners");
|
|
764
1648
|
const list = names.length === 1 ? names[0] : names.slice(0, -1).join(", ") + " and " + names[names.length - 1];
|
|
765
1649
|
const pronoun = names.length === 1 ? "it" : "them";
|
|
766
1650
|
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>";
|
|
767
1651
|
}
|
|
1652
|
+
/**
|
|
1653
|
+
* The Skills tab, after the runners' tabs. It has no group label: the tab
|
|
1654
|
+
* itself is named Skills. It is not a runner: it is not dragged, has no info
|
|
1655
|
+
* button and is not in the picker.
|
|
1656
|
+
*/
|
|
1657
|
+
function skillsTab(total) {
|
|
1658
|
+
if (total === 0) return "";
|
|
1659
|
+
return "<span class=\"tab\"><button data-runner=\"@skills\" aria-pressed=\"" + (state.runner === SKILLS) + "\" title=\"Agent skills: copy /name to type to an agent\">" + escapeHtml(SKILLS_GROUP.title) + "<span class=\"count\">" + total + "</span></button></span>";
|
|
1660
|
+
}
|
|
1661
|
+
/**
|
|
1662
|
+
* Scroll the tab strip, where it scrolls (phone width), so the selected tab
|
|
1663
|
+
* is in view: after a resize or a rebuild it could sit off the edge.
|
|
1664
|
+
*/
|
|
1665
|
+
function keepSelectedTabInView() {
|
|
1666
|
+
const strip = $("tabs");
|
|
1667
|
+
const selected = strip.querySelector("button[aria-pressed=\"true\"]");
|
|
1668
|
+
if (selected === null || strip.scrollWidth <= strip.clientWidth) return;
|
|
1669
|
+
const box = strip.getBoundingClientRect();
|
|
1670
|
+
const tab = selected.getBoundingClientRect();
|
|
1671
|
+
if (tab.left < box.left) strip.scrollLeft += tab.left - box.left - 8;
|
|
1672
|
+
else if (tab.right > box.right) strip.scrollLeft += tab.right - box.right + 8;
|
|
1673
|
+
}
|
|
1674
|
+
/** Whether a runner has an info button: path segments to explain, or tool info. */
|
|
1675
|
+
function hasInfo(runner) {
|
|
1676
|
+
return chainOf(runner).length > 0 || toolInfo(runner) !== void 0;
|
|
1677
|
+
}
|
|
1678
|
+
/** The runners the first probe will report but has not answered with rows, in display order. */
|
|
1679
|
+
function stillLoading(reports) {
|
|
1680
|
+
if (!state.live) return [];
|
|
1681
|
+
const answered = new Set(reports.map((r) => r.runner));
|
|
1682
|
+
return runnerOrder().filter((r) => !answered.has(r));
|
|
1683
|
+
}
|
|
1684
|
+
/**
|
|
1685
|
+
* A quiet tab for a runner still loading, in the place its tab will take.
|
|
1686
|
+
* It is not a button: there is nothing to select yet.
|
|
1687
|
+
*/
|
|
1688
|
+
function loadingTab(r) {
|
|
1689
|
+
return "<span class=\"tab tab-loading\" aria-busy=\"true\" title=\"" + escapeHtml(runnerLabel(r)) + " is loading\">" + escapeHtml(runnerLabel(r)) + "<span class=\"spinner\" aria-hidden=\"true\"></span></span>";
|
|
1690
|
+
}
|
|
1691
|
+
/** A row for a runner still loading. */
|
|
1692
|
+
function loadingRow(r) {
|
|
1693
|
+
return "<div class=\"loading-row\" aria-busy=\"true\"><span class=\"spinner\" aria-hidden=\"true\"></span>" + escapeHtml(runnerLabel(r)) + " <span class=\"muted\">loading…</span></div>";
|
|
1694
|
+
}
|
|
1695
|
+
/** A row for each runner still loading, for the views that are not the tree. */
|
|
1696
|
+
function loadingRows(runners) {
|
|
1697
|
+
if (runners.length === 0) return "";
|
|
1698
|
+
return "<div class=\"loading-rows\">" + runners.map(loadingRow).join("") + "</div>";
|
|
1699
|
+
}
|
|
768
1700
|
function render() {
|
|
769
1701
|
const cat = state.catalog;
|
|
770
1702
|
if (!cat) {
|
|
771
|
-
$("out").innerHTML = "<div class=\"empty\">Loading
|
|
1703
|
+
$("out").innerHTML = "<div class=\"empty\">Loading…</div>";
|
|
772
1704
|
return;
|
|
773
1705
|
}
|
|
774
1706
|
const main = $("out");
|
|
@@ -780,36 +1712,52 @@ function render() {
|
|
|
780
1712
|
state.knownRunners.add(s.runner);
|
|
781
1713
|
enabled.add(s.runner);
|
|
782
1714
|
}
|
|
783
|
-
|
|
784
|
-
|
|
1715
|
+
const skillsTotal = cat.skills?.length ?? 0;
|
|
1716
|
+
if (state.runner === "@skills" ? skillsTotal === 0 : state.runner !== "all" && !enabled.has(state.runner)) state.runner = "all";
|
|
1717
|
+
const byOrder = runnerOrder();
|
|
1718
|
+
const loadingSet = new Set(stillLoading(cat.reports));
|
|
1719
|
+
const on = byOrder.map((id) => cat.reports.find((s) => s.runner === id)).filter((s) => s !== void 0 && enabled.has(s.runner));
|
|
785
1720
|
const total = on.reduce((n, s) => n + s.tasks.length, 0);
|
|
786
1721
|
const anyError = on.some((s) => s.status === "error");
|
|
787
1722
|
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);
|
|
788
|
-
const shown = on.filter((s) => !foldable.includes(s));
|
|
789
1723
|
const tabs = [{
|
|
790
1724
|
runner: "all",
|
|
791
1725
|
count: total,
|
|
792
1726
|
error: anyError,
|
|
793
|
-
exec: false
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
1727
|
+
exec: false,
|
|
1728
|
+
loading: false
|
|
1729
|
+
}].concat(byOrder.flatMap((id) => {
|
|
1730
|
+
if (loadingSet.has(id)) return [{
|
|
1731
|
+
runner: id,
|
|
1732
|
+
count: 0,
|
|
1733
|
+
error: false,
|
|
1734
|
+
exec: false,
|
|
1735
|
+
loading: true
|
|
1736
|
+
}];
|
|
1737
|
+
const s = on.find((r) => r.runner === id);
|
|
1738
|
+
if (s === void 0 || foldable.includes(s)) return [];
|
|
1739
|
+
return [{
|
|
1740
|
+
runner: s.runner,
|
|
1741
|
+
count: s.tasks.length,
|
|
1742
|
+
error: s.status === "error",
|
|
1743
|
+
exec: s.skippedForExec,
|
|
1744
|
+
loading: false
|
|
1745
|
+
}];
|
|
1746
|
+
}));
|
|
800
1747
|
const chainOfRunner = (id) => cat.reports.find((r) => r.runner === id)?.chain ?? [];
|
|
801
1748
|
$("tabs").innerHTML = tabs.map((t, i) => {
|
|
802
1749
|
const prev = tabs[i - 1];
|
|
803
1750
|
const group = groupOf(t.runner);
|
|
804
|
-
const header = t.runner !== "all" && prev !== void 0 && prev.runner !== "all" && groupOf(prev.runner) !== group ? "<span class=\"tabgroup\">" + escapeHtml(group.title) + "</span>" : "";
|
|
805
|
-
|
|
806
|
-
const shape =
|
|
1751
|
+
const header = t.runner !== "all" && prev !== void 0 && prev.runner !== "all" && groupOf(prev.runner) !== group && runnerLabel(t.runner) !== group.title.toLowerCase() ? "<span class=\"tabgroup\">" + escapeHtml(group.title) + "</span>" : "";
|
|
1752
|
+
if (t.loading) return header + loadingTab(t.runner);
|
|
1753
|
+
const shape = chainOfRunner(t.runner).map((c, i) => i === 0 ? runnerLabel(t.runner) : c.label).join(" › ");
|
|
807
1754
|
const draggable = t.runner !== "all" ? " draggable=\"true\"" : "";
|
|
808
|
-
const tip = t.exec ? shape ? shape + ". " + execNote() : execNote() : shape;
|
|
809
|
-
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\">
|
|
810
|
-
const info =
|
|
1755
|
+
const tip = t.exec ? shape ? shape + ". " + execNote(t.runner) : execNote(t.runner) : shape;
|
|
1756
|
+
const btn = "<button data-runner=\"" + escapeHtml(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\">withheld</span>" : "") + "</button>";
|
|
1757
|
+
const info = hasInfo(t.runner) ? "<button class=\"tabinfo\" data-info-runner=\"" + escapeHtml(t.runner) + "\" title=\"About " + escapeHtml(runnerLabel(t.runner)) + ": the tool and its path segments\" aria-label=\"About " + escapeHtml(runnerLabel(t.runner)) + "\">i</button>" : "";
|
|
811
1758
|
return header + "<span class=\"tab\">" + btn + info + "</span>";
|
|
812
|
-
}).join("") + foldedChip(foldable);
|
|
1759
|
+
}).join("") + skillsTab(skillsTotal) + foldedChip(foldable);
|
|
1760
|
+
keepSelectedTabInView();
|
|
813
1761
|
const host = $("pickerhost");
|
|
814
1762
|
const wasOpen = document.getElementById("pickmenu")?.hidden === false;
|
|
815
1763
|
const refocus = host.contains(document.activeElement) ? pickerFocusSelector(document.activeElement) : null;
|
|
@@ -822,46 +1770,68 @@ function render() {
|
|
|
822
1770
|
const scope = scopedReports();
|
|
823
1771
|
const inScope = scope.reduce((n, s) => n + s.tasks.length, 0);
|
|
824
1772
|
const terms$1 = terms(state.query);
|
|
825
|
-
const
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
});
|
|
844
|
-
}
|
|
1773
|
+
const filter = {
|
|
1774
|
+
query: state.query,
|
|
1775
|
+
mode: state.mode,
|
|
1776
|
+
servicesOnly: state.servicesOnly,
|
|
1777
|
+
declaredOnly: state.declaredOnly,
|
|
1778
|
+
...state.depth < 99 ? { maxDepth: state.depth } : {}
|
|
1779
|
+
};
|
|
1780
|
+
const rows = filterTasks(scope, filter).map((hit) => ({
|
|
1781
|
+
entry: hit.task,
|
|
1782
|
+
score: hit.score,
|
|
1783
|
+
labelHits: hit.labelHits
|
|
1784
|
+
}));
|
|
1785
|
+
const skills = skillHits(filter);
|
|
1786
|
+
skillCounts = {
|
|
1787
|
+
shown: skills.length,
|
|
1788
|
+
total: state.runner === "all" || state.runner === "@skills" ? skillsTotal : 0
|
|
1789
|
+
};
|
|
1790
|
+
measureRows(rows, terms$1.length > 0, skills);
|
|
845
1791
|
let html = "";
|
|
846
1792
|
for (const sec of scope) for (const d of sec.diagnostics || []) {
|
|
847
1793
|
if (d.severity === "info") continue;
|
|
848
1794
|
const label = d.severity === "error" ? "banner" : "banner warn";
|
|
849
1795
|
html += "<div class=\"" + label + "\">" + escapeHtml(sec.runner) + ": " + escapeHtml(d.message) + (d.source ? "\n" + escapeHtml(d.source) : "") + "</div>";
|
|
850
1796
|
}
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
1797
|
+
const onSkills = state.runner === SKILLS;
|
|
1798
|
+
const loading = state.runner === "all" ? stillLoading(cat.reports) : [];
|
|
1799
|
+
let inTree = false;
|
|
1800
|
+
if (rows.length === 0 && skills.length === 0) {
|
|
1801
|
+
const noun = onSkills ? SKILL_NOUN.one : TASK_NOUN.one;
|
|
1802
|
+
if (loading.length === 0) html += "<div class=\"empty\">" + (inScope || skillCounts.total ? "No " + noun + " matches." : "Nothing collected.") + "</div>";
|
|
1803
|
+
} else if (terms$1.length) {
|
|
1804
|
+
const hits = [...rows.map((r) => ({
|
|
1805
|
+
score: r.score,
|
|
1806
|
+
html: () => renderSearchRow(r)
|
|
1807
|
+
})), ...skills.map((h) => ({
|
|
1808
|
+
score: h.score,
|
|
1809
|
+
html: () => renderSkillRow(h)
|
|
1810
|
+
}))];
|
|
1811
|
+
hits.sort((a, b) => b.score - a.score);
|
|
1812
|
+
html += "<table>" + colgroup(0) + "<tbody>" + hits.slice(0, 400).map((h) => h.html()).join("") + "</tbody></table>";
|
|
1813
|
+
} else if (onSkills) html += skillTable(skills, 0);
|
|
1814
|
+
else {
|
|
1815
|
+
inTree = true;
|
|
1816
|
+
html += renderNode(buildTree(rows), [], loading) + (skills.length > 0 ? skillsNode(skills) : "");
|
|
1817
|
+
}
|
|
1818
|
+
if (!inTree) html += loadingRows(loading);
|
|
856
1819
|
const focusWasInList = $("out").contains(document.activeElement);
|
|
857
1820
|
$("out").innerHTML = html;
|
|
858
1821
|
markEnterTarget();
|
|
859
1822
|
if (focusWasInList) restoreListFocus();
|
|
860
1823
|
renderColHeads();
|
|
1824
|
+
searchPlaceholder();
|
|
861
1825
|
renderStatus(rows.length, inScope);
|
|
862
1826
|
renderTrustBar();
|
|
863
1827
|
measureChrome();
|
|
864
1828
|
}
|
|
1829
|
+
/** The search box names what the tab lists: `Search tasks`, or `Search skills` on Skills. */
|
|
1830
|
+
function searchPlaceholder() {
|
|
1831
|
+
const q = document.getElementById("q");
|
|
1832
|
+
if (q === null) return;
|
|
1833
|
+
q.placeholder = "Search " + (state.runner === "@skills" ? SKILL_NOUN.many : TASK_NOUN.many);
|
|
1834
|
+
}
|
|
865
1835
|
/**
|
|
866
1836
|
* Put keyboard focus back in the rebuilt list.
|
|
867
1837
|
*
|
|
@@ -899,46 +1869,68 @@ function pickerFocusSelector(el) {
|
|
|
899
1869
|
if (el.closest("[data-pick-none]")) return "[data-pick-none]";
|
|
900
1870
|
return null;
|
|
901
1871
|
}
|
|
902
|
-
/**
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
1872
|
+
/** The web view's list keys as help rows, from the table in `keys.ts`. */
|
|
1873
|
+
function keyRows() {
|
|
1874
|
+
return keysFor("web", "list").map((k) => "<dt>" + k.keys.map((key) => "<kbd>" + escapeHtml(key) + "</kbd>").join(" ") + "</dt><dd>" + escapeHtml(k.action) + "</dd>").join("");
|
|
1875
|
+
}
|
|
1876
|
+
/**
|
|
1877
|
+
* The help: what each part of the page is, named as the page names it, with
|
|
1878
|
+
* the command each action is. The two points that surprise people come
|
|
1879
|
+
* first: part of a task's chain is grouping this page adds, and a task can be
|
|
1880
|
+
* declared by a runner or only implied by a convention.
|
|
1881
|
+
*/
|
|
1882
|
+
function helpHtml() {
|
|
1883
|
+
return [
|
|
1884
|
+
"<h3 id=\"help-title\">What this is</h3>",
|
|
1885
|
+
"<p>Every " + TASK_NOUN.one + " this repository can run, from every runner it uses, in one searchable list. ",
|
|
1886
|
+
"The runners answer only for themselves — <code>just --list</code> knows nothing about moon — so " + APP + " asks each of them and merges the answers. ",
|
|
1887
|
+
"The page and <code>way</code> on the command line do the same things: each action below names its command.</p>",
|
|
1888
|
+
"<h3>Keys</h3>",
|
|
1889
|
+
"<dl class=\"keys\">" + keyRows() + "</dl>",
|
|
1890
|
+
"<h3>The columns</h3>",
|
|
1891
|
+
"<dl>",
|
|
1892
|
+
"<dt>Task</dt><dd>The call chain. The first segment is the runner, the last is the task's own name. ",
|
|
1893
|
+
"The middle is <strong>grouping this page adds</strong> so hundreds of names stay scannable — it is not part of any command. ",
|
|
1894
|
+
"Hover a segment to see what that position means for its runner.</dd>",
|
|
1895
|
+
"<dt>Command</dt><dd>Exactly what to type. Nearly every command is written to run <strong>from the repository root</strong>. ",
|
|
1896
|
+
"Where a task can only run from its own directory, Copy adds the <code>cd</code> for you.</dd>",
|
|
1897
|
+
"<dt>Runs</dt><dd>What the task runs, or the summary its runner documents. It is shown on a wide window when some task has one.</dd>",
|
|
1898
|
+
"<dt>Marks</dt><dd>A filled dot marks a service: a task that runs until you stop it, such as a dev server or a watcher. An outlined dot means that was inferred from the name. ",
|
|
1899
|
+
"A <code>?</code> means the parameters could not be read; Run then asks for arguments, which may be left empty.</dd>",
|
|
1900
|
+
"</dl>",
|
|
1901
|
+
"<h3>The controls</h3>",
|
|
1902
|
+
"<dl>",
|
|
1903
|
+
"<dt>Scope</dt><dd>How far into the repository to look, by <strong>where a task is declared</strong>. ",
|
|
1904
|
+
"<em>Root</em> is what the repository declares itself — its own justfile, package.json and moon project. <code>way list --depth N</code> is the same filter.</dd>",
|
|
1905
|
+
"<dt>Services</dt><dd>Only services. <code>way list --services</code>.</dd>",
|
|
1906
|
+
"<dt>Declared</dt><dd>Drops tasks no file declares, such as <code>cargo test</code> for a crate. <code>way list --declared</code>.</dd>",
|
|
1907
|
+
"<dt>Runners</dt><dd>Which runners this page shows, for this visit. Drag a runner, here or in the tab row, to reorder; the order is saved as <code>runners.order</code> in your user config.</dd>",
|
|
1908
|
+
"<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.</dd>",
|
|
1909
|
+
"<dt>Filters</dt><dd>On a narrow window, Scope, Services, Declared and Runners fold into this one menu.</dd>",
|
|
1910
|
+
"<dt>Collapse, Refresh</dt><dd>Collapse folds the groups. Refresh reads every runner again (<code>way list</code>).</dd>",
|
|
1911
|
+
"<dt>Theme</dt><dd>Cycles System, Light and Dark, and saves <code>theme</code> in your user config.</dd>",
|
|
1912
|
+
"</dl>",
|
|
1913
|
+
"<h3>Run and Copy</h3>",
|
|
1914
|
+
"<p><b>Run</b> hands the task to the terminal wayfinder is serving from, as <code>way run <id> -- <arguments></code> does. The server stops and this page is done. ",
|
|
1915
|
+
"A task that takes parameters, or whose parameters could not be read, asks for its arguments first. ",
|
|
1916
|
+
"<b>Copy</b> puts the command on the clipboard.</p>",
|
|
1917
|
+
"<h3>Skills</h3>",
|
|
1918
|
+
"<p>The Skills tab lists the agent skills this repository ships (the <code>skills</code> setting can add your own). ",
|
|
1919
|
+
"A skill is not a command: an agent runs it when you type <code>/<name></code>. So Copy, Enter and Run all put <code>/<name></code> on the clipboard to paste into ",
|
|
1920
|
+
"the agent the row names, and nothing runs here. The search and Services filter skills as they filter tasks.</p>",
|
|
1921
|
+
"<h3>Settings</h3>",
|
|
1922
|
+
"<p>The gear opens this project's settings (<code>way config list</code>). Edits are staged until Save, which writes each one with <code>way config set</code> and names the file it wrote. ",
|
|
1923
|
+
"Trust this repository, or one tool, asks you to confirm first. <code>allowExec</code>, the trust policy and <code>tools</code> are changed from the command line only; the screen shows the command for each.</p>",
|
|
1924
|
+
"<h3>Why a runner might show nothing</h3>",
|
|
1925
|
+
"<p>Some runners can only be read by running them — <code>moon query tasks</code> evaluates this repository's own toolchain configuration. ",
|
|
1926
|
+
"Until the repository is trusted they are withheld, and their tab says so. Trust this repository asks you to confirm, then runs <code>way trust</code>. ",
|
|
1927
|
+
"A runner can also wait on one tool, such as mise for a mise task: Settings trusts that tool alone (<code>way trust --scope <tool></code>). ",
|
|
1928
|
+
"A repository cannot grant itself that: <code>allowExec</code> in its own config file cannot raise the gate.</p>",
|
|
1929
|
+
"<h3>Staying current</h3>",
|
|
1930
|
+
"<p>The page reads the repository again when you focus it and every 15 seconds. ",
|
|
1931
|
+
"The first view may come from the stored probe, so it appears at once; the status line then names the stale runners, and a fresh read follows.</p>"
|
|
1932
|
+
].join("");
|
|
1933
|
+
}
|
|
942
1934
|
/**
|
|
943
1935
|
* The header for the selection column: a checkbox mark, sized to match the
|
|
944
1936
|
* row checkboxes below it. Visual only. The accessible name comes from the
|
|
@@ -982,10 +1974,10 @@ function renderRunnerPicker(cat) {
|
|
|
982
1974
|
const enabled = state.enabled;
|
|
983
1975
|
const items = runnerOrder().map((id) => cat.reports.find((r) => r.runner === id)).filter((s) => s !== void 0).map((s) => {
|
|
984
1976
|
const on = enabled.has(s.runner);
|
|
985
|
-
const note = s.status === "error" ? " (failed)" : s.skippedForExec ?
|
|
1977
|
+
const note = s.status === "error" ? " (failed)" : s.skippedForExec ? " (withheld)" : "";
|
|
986
1978
|
const grant = s.skippedForExec && state.trustable ? TRUST_BUTTON : "";
|
|
987
|
-
const info = s.
|
|
988
|
-
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>";
|
|
1979
|
+
const info = hasInfo(s.runner) ? "<button class=\"tabinfo\" data-info-runner=\"" + escapeHtml(s.runner) + "\" title=\"About " + escapeHtml(s.runner) + ": the tool and its path segments\" aria-label=\"About " + escapeHtml(s.runner) + "\">i</button>" : "";
|
|
1980
|
+
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(runnerLabel(s.runner)) + "<span class=\"count\">" + s.tasks.length + escapeHtml(note) + "</span></label>" + grant + info + "</div>";
|
|
989
1981
|
}).join("");
|
|
990
1982
|
const off = cat.reports.length - enabled.size;
|
|
991
1983
|
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>";
|
|
@@ -994,6 +1986,10 @@ function renderRunnerPicker(cat) {
|
|
|
994
1986
|
function listRows() {
|
|
995
1987
|
return [...$("out").querySelectorAll("tbody tr")];
|
|
996
1988
|
}
|
|
1989
|
+
/** The task rows in #out: every body row but the skills'. */
|
|
1990
|
+
function taskRows() {
|
|
1991
|
+
return listRows().filter((r) => !r.hasAttribute("data-skill"));
|
|
1992
|
+
}
|
|
997
1993
|
/**
|
|
998
1994
|
* Which row Enter takes, and where the single tab stop into the list sits.
|
|
999
1995
|
*
|
|
@@ -1036,17 +2032,27 @@ function setFocusedRow(id) {
|
|
|
1036
2032
|
markEnterTarget();
|
|
1037
2033
|
}
|
|
1038
2034
|
/**
|
|
1039
|
-
*
|
|
1040
|
-
*
|
|
2035
|
+
* A tool's description, language and homepage, from `way providers`. The
|
|
2036
|
+
* description and homepage of a custom tool are repository text, so both
|
|
2037
|
+
* are escaped, and the homepage is a link only when it is http or https.
|
|
2038
|
+
*/
|
|
2039
|
+
function toolAboutHtml(tool) {
|
|
2040
|
+
const link = homepageLink(tool.homepage);
|
|
2041
|
+
return (tool.description !== null ? "<p class=\"tool-desc\">" + escapeHtml(tool.description) + "</p>" : "") + "<dl class=\"tool-facts\"><dt>Language</dt><dd>" + escapeHtml(tool.language) + "</dd>" + (link !== "" ? "<dt>Homepage</dt><dd>" + link + "</dd>" : "") + "</dl>";
|
|
2042
|
+
}
|
|
2043
|
+
/**
|
|
2044
|
+
* One runner's explanation: the tool it is, what each position of its path
|
|
2045
|
+
* selects, and whether reading it means running anything.
|
|
1041
2046
|
*/
|
|
1042
2047
|
function showRunnerInfo(runner) {
|
|
1043
2048
|
const report = (state.catalog?.reports || []).find((r) => r.runner === runner);
|
|
1044
2049
|
if (!report) return;
|
|
2050
|
+
const tool = toolInfo(runner);
|
|
1045
2051
|
const shape = report.chain.map((c, i) => i === 0 ? runner : c.label).join(" › ");
|
|
1046
2052
|
const rows = report.chain.map((c, i) => "<dt>" + escapeHtml(i === 0 ? runner : c.label) + "</dt><dd>" + escapeHtml(c.hint) + "</dd>").join("");
|
|
1047
2053
|
const notes = [];
|
|
1048
2054
|
if (report.skippedForExec) {
|
|
1049
|
-
notes.push("<p>Not collected right now. " + execNote() + "</p>");
|
|
2055
|
+
notes.push("<p>Not collected right now. " + escapeHtml(execNote(runner)) + "</p>");
|
|
1050
2056
|
if (state.trustable) notes.push("<p>" + TRUST_BUTTON + "</p>");
|
|
1051
2057
|
}
|
|
1052
2058
|
if (report.status === "error") notes.push("<p>This runner failed to probe. Its diagnostic is shown above the list.</p>");
|
|
@@ -1054,8 +2060,8 @@ function showRunnerInfo(runner) {
|
|
|
1054
2060
|
if (d.severity !== "info") continue;
|
|
1055
2061
|
notes.push("<p>" + escapeHtml(d.message) + "</p>");
|
|
1056
2062
|
}
|
|
1057
|
-
$("help-body").innerHTML = "<h3>" + escapeHtml(runner) + "</h3
|
|
1058
|
-
|
|
2063
|
+
$("help-body").innerHTML = "<h3 id=\"help-title\">" + escapeHtml(runnerLabel(runner)) + "</h3>" + (tool !== void 0 ? toolAboutHtml(tool) : "") + (report.chain.length > 0 ? "<p>A task from this runner reads <code>" + escapeHtml(shape) + "</code>.</p><dl>" + rows + "</dl>" : "") + notes.join("") + "<p>" + escapeHtml(countTasks(report.tasks.length)) + " found.</p>";
|
|
2064
|
+
openDialogAtTop("help");
|
|
1059
2065
|
}
|
|
1060
2066
|
/**
|
|
1061
2067
|
* The column headers, drawn as their own depth-0 table in the sticky header.
|
|
@@ -1064,7 +2070,7 @@ function showRunnerInfo(runner) {
|
|
|
1064
2070
|
* column starts at the same x at every depth.
|
|
1065
2071
|
*/
|
|
1066
2072
|
function renderColHeads() {
|
|
1067
|
-
const cells = COLUMNS.filter((c) =>
|
|
2073
|
+
const cells = (state.runner === "@skills" ? SKILL_COLUMNS : COLUMNS).filter((c, i) => i !== 3 || showRuns()).map((c) => "<th title=\"" + escapeHtml(c.tip) + "\">" + (escapeHtml(c.label) || " ") + "</th>").join("");
|
|
1068
2074
|
$("colheads").innerHTML = "<table>" + colgroup(0) + "<thead><tr>" + cells + "</tr></thead></table>";
|
|
1069
2075
|
}
|
|
1070
2076
|
/**
|
|
@@ -1081,37 +2087,31 @@ function cacheSpan(rows) {
|
|
|
1081
2087
|
if (stale.length === 0) return "";
|
|
1082
2088
|
const slow = stale.filter((r) => r.slow);
|
|
1083
2089
|
const cost = (r) => r.estimateMs === null ? "never timed here" : "~" + humanMs(r.estimateMs);
|
|
1084
|
-
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>";
|
|
1085
|
-
return "<span>cached: " + escapeHtml(stale.map((r) => r.runner + " " +
|
|
2090
|
+
if (slow.length > 0) return "<span class=\"err\">cached: " + escapeHtml(slow.map((r) => runnerLabel(r.runner) + " (" + humanAge(r.ageMs) + ", " + cost(r) + ")").join(", ")) + " - slow to probe here, so re-reading takes a moment</span>";
|
|
2091
|
+
return "<span>cached: " + escapeHtml(stale.map((r) => runnerLabel(r.runner) + " (" + staleLabel(r.reason, r.ageMs) + ")").join(", ")) + " - re-probing</span>";
|
|
1086
2092
|
}
|
|
1087
2093
|
/**
|
|
1088
2094
|
* Runners withheld because execution is off, shown in the page's own bar
|
|
1089
|
-
* above everything
|
|
2095
|
+
* above everything, in the words the CLI's note uses: `2 runners withheld:
|
|
2096
|
+
* this repository is not trusted`.
|
|
1090
2097
|
*
|
|
1091
|
-
* Without it, the page would mention withheld runners only
|
|
1092
|
-
*
|
|
1093
|
-
*
|
|
1094
|
-
* that anything was missing, which this tool must never do quietly.
|
|
2098
|
+
* Without it, the page would mention withheld runners only behind a hover or
|
|
2099
|
+
* a click, and someone would see a shorter catalog with nothing saying that
|
|
2100
|
+
* anything was missing.
|
|
1095
2101
|
*
|
|
1096
|
-
* It
|
|
1097
|
-
*
|
|
1098
|
-
*
|
|
1099
|
-
* control.
|
|
1100
|
-
*
|
|
1101
|
-
* It names the runners rather than only counting them, so the reader does not
|
|
1102
|
-
* have to ask which. The trust button is included only when trust is what is
|
|
1103
|
-
* missing. Otherwise execution is off for the session and trusting the
|
|
1104
|
-
* repository would change nothing.
|
|
2102
|
+
* It names the runners rather than only counting them. The trust button is
|
|
2103
|
+
* included only when trust is what is missing. Otherwise execution is off
|
|
2104
|
+
* for the session and trusting the repository would change nothing.
|
|
1105
2105
|
*/
|
|
1106
2106
|
function withheldBar(reports) {
|
|
1107
2107
|
const held = reports.filter((s) => s.skippedForExec);
|
|
1108
2108
|
if (held.length === 0) return "";
|
|
1109
|
-
const
|
|
1110
|
-
const
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
return "<span>" +
|
|
2109
|
+
const byLabel = /* @__PURE__ */ new Map();
|
|
2110
|
+
for (const s of held) {
|
|
2111
|
+
const label = withheldNote(s.runner);
|
|
2112
|
+
byLabel.set(label, [...byLabel.get(label) ?? [], runnerLabel(s.runner)]);
|
|
2113
|
+
}
|
|
2114
|
+
return [...byLabel].map(([label, names]) => "<span>" + escapeHtml(countRunners(names.length)) + " " + escapeHtml(label) + " (<span class=\"who\">" + escapeHtml(names.join(", ")) + "</span>).</span>").join(" ") + (state.trustable ? TRUST_BUTTON : "");
|
|
1115
2115
|
}
|
|
1116
2116
|
/** Paint the trust bar, and hide it entirely when there is nothing to say. */
|
|
1117
2117
|
function renderTrustBar() {
|
|
@@ -1120,6 +2120,29 @@ function renderTrustBar() {
|
|
|
1120
2120
|
host.innerHTML = html;
|
|
1121
2121
|
host.hidden = html === "";
|
|
1122
2122
|
}
|
|
2123
|
+
/** Say `text` to a screen reader, through the page's one polite live region. */
|
|
2124
|
+
function announce(text) {
|
|
2125
|
+
$("announce").textContent = text;
|
|
2126
|
+
}
|
|
2127
|
+
/** The counts the status line showed last, for {@link refreshStatus}. */
|
|
2128
|
+
let lastCounts = {
|
|
2129
|
+
shown: 0,
|
|
2130
|
+
total: 0
|
|
2131
|
+
};
|
|
2132
|
+
/** The status line again with the counts it showed last: a load started or ended. */
|
|
2133
|
+
function refreshStatus() {
|
|
2134
|
+
renderStatus(lastCounts.shown, lastCounts.total);
|
|
2135
|
+
}
|
|
2136
|
+
/** What the status line says about a probe running: what is still loading, or that it refreshes. */
|
|
2137
|
+
function loadingText() {
|
|
2138
|
+
if (state.live) {
|
|
2139
|
+
if (state.expected < 0) return "detecting the project…";
|
|
2140
|
+
if (state.pending.length === 0) return "loading…";
|
|
2141
|
+
return "loading " + state.pending.length + " of " + state.expected + ": " + escapeHtml(state.pending.map(runnerLabel).join(", "));
|
|
2142
|
+
}
|
|
2143
|
+
if (!state.loading) return "";
|
|
2144
|
+
return " - refreshing…" + (state.pending.length > 0 && Date.now() - state.loadStarted >= 3e3 ? " waiting on " + escapeHtml(state.pending.map(runnerLabel).join(", ")) : "");
|
|
2145
|
+
}
|
|
1123
2146
|
/**
|
|
1124
2147
|
* Kept separate from the table so an unchanged poll can update the clock
|
|
1125
2148
|
* without touching the table. Otherwise Refresh on an unchanged repo would
|
|
@@ -1127,8 +2150,12 @@ function renderTrustBar() {
|
|
|
1127
2150
|
* it is.
|
|
1128
2151
|
*/
|
|
1129
2152
|
function renderStatus(shown, total) {
|
|
2153
|
+
lastCounts = {
|
|
2154
|
+
shown,
|
|
2155
|
+
total
|
|
2156
|
+
};
|
|
1130
2157
|
const errs = (state.catalog?.reports || []).filter((s) => s.status === "error").map((s) => s.runner);
|
|
1131
|
-
$("status").innerHTML = "<span>" + shown + " of " + total + " " + (state.runner === "all" ? "
|
|
2158
|
+
$("status").innerHTML = "<span>" + (state.runner === "@skills" ? skillCounts.shown + " of " + escapeHtml(countSkills(skillCounts.total)) : shown + " of " + escapeHtml(countTasks(total)) + (state.runner === "all" ? ", all runners" : " in " + escapeHtml(runnerLabel(state.runner))) + (skillCounts.total > 0 ? ", " + skillCounts.shown + " of " + escapeHtml(countSkills(skillCounts.total)) : "")) + "</span>" + (state.live ? "<span class=\"loading-note\">" + loadingText() + "</span>" : "<span>checked " + new Date(state.checkedAt).toLocaleTimeString() + loadingText() + "</span>") + cacheSpan(state.cache) + (errs.length ? "<span class=\"err\">probe failed: " + escapeHtml(errs.map(runnerLabel).join(", ")) + "</span>" : "") + (state.runner === "@skills" ? "<span class=\"keyhint\"><kbd>Enter</kbd> copy /name · <kbd>?</kbd> all keys</span>" : "<span class=\"keyhint\"><kbd>Enter</kbd> copy · <kbd>Shift+Enter</kbd> run · <kbd>?</kbd> all keys</span>");
|
|
1132
2159
|
}
|
|
1133
2160
|
/**
|
|
1134
2161
|
* The run bar: enter a task's arguments before handing over the terminal.
|
|
@@ -1146,9 +2173,9 @@ function showRunBar(task) {
|
|
|
1146
2173
|
const el = document.createElement("div");
|
|
1147
2174
|
el.id = "runbar";
|
|
1148
2175
|
el.setAttribute("role", "group");
|
|
1149
|
-
el.setAttribute("aria-label", "Arguments for " + task.display);
|
|
1150
|
-
const shape = paramShape(task.parameters);
|
|
1151
|
-
el.innerHTML = "<div class=\"runbar-line\"><span class=\"runbar-sigil\" aria-hidden=\"true\">$</span><span class=\"runbar-cmd\">" +
|
|
2176
|
+
el.setAttribute("aria-label", "Arguments for " + terminalSafe(task.display));
|
|
2177
|
+
const shape = task.parametersUnknown !== void 0 ? parametersUnknownLabel(task.parametersUnknown) + "; arguments are optional" : "takes " + paramShape(task.parameters);
|
|
2178
|
+
el.innerHTML = "<div class=\"runbar-line\"><span class=\"runbar-sigil\" aria-hidden=\"true\">$</span><span class=\"runbar-cmd\">" + shown(commandString(task.argv, { platform: serverPlatform() })) + "</span><input class=\"runbar-args\" type=\"text\" autocomplete=\"off\" spellcheck=\"false\" aria-label=\"Arguments\" /></div><div class=\"runbar-foot\"><span class=\"runbar-shape\">" + escapeHtml(shape) + "</span><span class=\"runbar-keys\"><kbd>Enter</kbd> run · <kbd>Esc</kbd> back</span></div>";
|
|
1152
2179
|
document.body.append(el);
|
|
1153
2180
|
const field = el.querySelector(".runbar-args");
|
|
1154
2181
|
field.focus();
|
|
@@ -1171,7 +2198,7 @@ function showHandoff(command) {
|
|
|
1171
2198
|
el.id = "handoff";
|
|
1172
2199
|
el.setAttribute("data-handoff", "");
|
|
1173
2200
|
el.setAttribute("role", "status");
|
|
1174
|
-
el.innerHTML = "<h2>Handed off to the terminal</h2><pre class=\"handoff-cmd\">" + escapeHtml(command) + "</pre><p>It is running in the shell
|
|
2201
|
+
el.innerHTML = "<h2>Handed off to the terminal</h2><pre class=\"handoff-cmd\">" + escapeHtml(command) + "</pre><p>It is running in the shell " + escapeHtml(APP) + " was started from. This page is done — you can close it.</p>";
|
|
1175
2202
|
document.body.append(el);
|
|
1176
2203
|
el.tabIndex = -1;
|
|
1177
2204
|
el.focus();
|
|
@@ -1194,7 +2221,71 @@ function showRunTaken(button) {
|
|
|
1194
2221
|
* sticky header or leave a gap under it.
|
|
1195
2222
|
*/
|
|
1196
2223
|
function measureChrome() {
|
|
1197
|
-
|
|
2224
|
+
const chrome = $("chrome");
|
|
2225
|
+
const sticky = getComputedStyle(chrome).position === "sticky";
|
|
2226
|
+
document.documentElement.style.setProperty("--chrome-h", (sticky ? Math.round(chrome.getBoundingClientRect().height) : 0) + "px");
|
|
2227
|
+
}
|
|
2228
|
+
/**
|
|
2229
|
+
* Open a dialog with its body scrolled to the top and focused. `showModal`
|
|
2230
|
+
* focuses the first control, the Close button at the end, which would scroll
|
|
2231
|
+
* a long body to the bottom.
|
|
2232
|
+
*/
|
|
2233
|
+
function openDialogAtTop(id) {
|
|
2234
|
+
const dialog = $(id);
|
|
2235
|
+
if (!dialog.open) dialog.showModal();
|
|
2236
|
+
const body = $(id + "-body");
|
|
2237
|
+
body.scrollTop = 0;
|
|
2238
|
+
body.focus({ preventScroll: true });
|
|
2239
|
+
}
|
|
2240
|
+
/**
|
|
2241
|
+
* The page when it could not sign in: a new tab with no boot token, a used
|
|
2242
|
+
* or expired one, or a server restarted since this tab signed in. Only the
|
|
2243
|
+
* terminal can hand out a new link.
|
|
2244
|
+
*/
|
|
2245
|
+
function showSignedOut() {
|
|
2246
|
+
document.body.innerHTML = "<main class=\"signedout\"><h1>This browser tab is not signed in.</h1><p>A sign-in link works once, in one tab. A reload keeps the tab signed in; a new tab, another browser or a restarted server needs a new link.</p><p>Go to the terminal " + escapeHtml(APP) + " is running in and press <code>Enter</code>: it opens or prints a new link. If it has stopped, start it again with <code>" + escapeHtml("way") + " serve</code>.</p></main>";
|
|
2247
|
+
}
|
|
2248
|
+
/** The colour-scheme cycle: what a click on the theme button moves to. */
|
|
2249
|
+
const THEME_CYCLE = {
|
|
2250
|
+
system: "light",
|
|
2251
|
+
light: "dark",
|
|
2252
|
+
dark: "system"
|
|
2253
|
+
};
|
|
2254
|
+
/** How the button shows each scheme when it is the one in use. */
|
|
2255
|
+
const THEME_FACE = {
|
|
2256
|
+
system: {
|
|
2257
|
+
glyph: "◐",
|
|
2258
|
+
name: "System",
|
|
2259
|
+
note: " (follows your OS)"
|
|
2260
|
+
},
|
|
2261
|
+
light: {
|
|
2262
|
+
glyph: "☀",
|
|
2263
|
+
name: "Light",
|
|
2264
|
+
note: ""
|
|
2265
|
+
},
|
|
2266
|
+
dark: {
|
|
2267
|
+
glyph: "☾",
|
|
2268
|
+
name: "Dark",
|
|
2269
|
+
note: ""
|
|
2270
|
+
}
|
|
2271
|
+
};
|
|
2272
|
+
/**
|
|
2273
|
+
* Update the theme button for the choice now in use.
|
|
2274
|
+
*
|
|
2275
|
+
* The button shows the current scheme, so both the title and the accessible
|
|
2276
|
+
* name must say two things: what is on, and what a click does next. A single
|
|
2277
|
+
* cycling button has nowhere else to say the second, and a screen-reader user
|
|
2278
|
+
* would otherwise not know what the press does. Startup calls this too, so
|
|
2279
|
+
* the button matches the restored preference from the first frame.
|
|
2280
|
+
*/
|
|
2281
|
+
function setThemeButton(choice) {
|
|
2282
|
+
const btn = $("theme");
|
|
2283
|
+
const face = THEME_FACE[choice] ?? THEME_FACE["system"];
|
|
2284
|
+
const next = THEME_FACE[THEME_CYCLE[choice] ?? "light"];
|
|
2285
|
+
btn.dataset.themeChoice = choice;
|
|
2286
|
+
btn.textContent = face.glyph;
|
|
2287
|
+
btn.title = "Colour scheme: " + face.name + face.note + ". Click for " + next.name + ".";
|
|
2288
|
+
btn.setAttribute("aria-label", "Colour scheme: " + face.name + ". Click for " + next.name + ".");
|
|
1198
2289
|
}
|
|
1199
2290
|
//#endregion
|
|
1200
2291
|
//#region src/args.ts
|
|
@@ -1202,11 +2293,16 @@ function measureChrome() {
|
|
|
1202
2293
|
* Split typed arguments into words the way a shell does, and do nothing else
|
|
1203
2294
|
* a shell does.
|
|
1204
2295
|
*
|
|
1205
|
-
* Quotes group
|
|
1206
|
-
*
|
|
1207
|
-
*
|
|
1208
|
-
*
|
|
1209
|
-
*
|
|
2296
|
+
* Quotes group words as in sh. Outside quotes a backslash escapes the next
|
|
2297
|
+
* character. Inside single quotes every character is literal, a backslash
|
|
2298
|
+
* too, so `'C:\tmp'` stays as typed. Inside double quotes a backslash escapes
|
|
2299
|
+
* only `"`, `\`, `$` and a backtick, and is kept before anything else.
|
|
2300
|
+
*
|
|
2301
|
+
* There is no globbing, no variable expansion, no operators and no
|
|
2302
|
+
* substitution. The result goes to an `execvp`-style spawn as separate argv
|
|
2303
|
+
* entries, never to a shell, so `*.log` is passed through as the five
|
|
2304
|
+
* characters typed. This is the same rule that keeps `argv` separate from
|
|
2305
|
+
* `display`.
|
|
1210
2306
|
*
|
|
1211
2307
|
* This is not `.split(/\s+/)` for one reason: a quoted `"two words"` must stay
|
|
1212
2308
|
* one argument.
|
|
@@ -1218,8 +2314,19 @@ function splitArgs(input) {
|
|
|
1218
2314
|
let quote = null;
|
|
1219
2315
|
for (let i = 0; i < input.length; i++) {
|
|
1220
2316
|
const ch = input[i];
|
|
2317
|
+
if (quote === "'") {
|
|
2318
|
+
if (ch === "'") quote = null;
|
|
2319
|
+
else current += ch;
|
|
2320
|
+
continue;
|
|
2321
|
+
}
|
|
1221
2322
|
if (ch === "\\" && i + 1 < input.length) {
|
|
1222
|
-
|
|
2323
|
+
const next = input[i + 1];
|
|
2324
|
+
if (quote === "\"" && !"\"\\$`".includes(next)) {
|
|
2325
|
+
current += ch;
|
|
2326
|
+
continue;
|
|
2327
|
+
}
|
|
2328
|
+
current += next;
|
|
2329
|
+
i++;
|
|
1223
2330
|
started = true;
|
|
1224
2331
|
continue;
|
|
1225
2332
|
}
|
|
@@ -1243,232 +2350,608 @@ function splitArgs(input) {
|
|
|
1243
2350
|
current += ch;
|
|
1244
2351
|
started = true;
|
|
1245
2352
|
}
|
|
1246
|
-
if (started) out.push(current);
|
|
1247
|
-
return out;
|
|
2353
|
+
if (started) out.push(current);
|
|
2354
|
+
return out;
|
|
2355
|
+
}
|
|
2356
|
+
//#endregion
|
|
2357
|
+
//#region src/config-keys.ts
|
|
2358
|
+
/**
|
|
2359
|
+
* Config key lists that the page needs as well as the CLI. Browser-safe: no
|
|
2360
|
+
* Node built-in, so the web view imports it.
|
|
2361
|
+
*/
|
|
2362
|
+
/** The `theme` values for the web view. `system` follows the browser. */
|
|
2363
|
+
const THEME_VALUES = [
|
|
2364
|
+
"system",
|
|
2365
|
+
"light",
|
|
2366
|
+
"dark"
|
|
2367
|
+
];
|
|
2368
|
+
/**
|
|
2369
|
+
* The keys `config set` and `config unset` change from the command line only.
|
|
2370
|
+
* cli-tool's adapters, such as the HTTP one the web view's server runs,
|
|
2371
|
+
* refuse a write of any of them: an agent or a page must not grant trust,
|
|
2372
|
+
* turn execution on, or name code to load.
|
|
2373
|
+
*/
|
|
2374
|
+
const CLI_ONLY_KEYS = [
|
|
2375
|
+
"trust",
|
|
2376
|
+
"allowExec",
|
|
2377
|
+
"tools"
|
|
2378
|
+
];
|
|
2379
|
+
/** The top-level keys only the user layer may set. */
|
|
2380
|
+
const USER_ONLY_KEYS = [
|
|
2381
|
+
"trust",
|
|
2382
|
+
"open",
|
|
2383
|
+
"theme",
|
|
2384
|
+
"skills"
|
|
2385
|
+
];
|
|
2386
|
+
/**
|
|
2387
|
+
* The file a settings screen writes `key` to, given where its value comes
|
|
2388
|
+
* from now (`default`, `user` or `project`). A user-only key goes to the
|
|
2389
|
+
* user file. `runners.order` goes to the file that sets it, else the user
|
|
2390
|
+
* file, so a reorder always takes effect. Every other key goes to the
|
|
2391
|
+
* project file.
|
|
2392
|
+
*/
|
|
2393
|
+
function settingLayer(key, source) {
|
|
2394
|
+
if (USER_ONLY_KEYS.includes(key.split(".")[0])) return "user";
|
|
2395
|
+
if (key === "runners.order") return source === "project" ? "project" : "user";
|
|
2396
|
+
return "project";
|
|
2397
|
+
}
|
|
2398
|
+
//#endregion
|
|
2399
|
+
//#region src/web/api.ts
|
|
2400
|
+
/** The media type of a streamed answer: one JSON line per event, then the document. */
|
|
2401
|
+
const NDJSON = "application/x-ndjson";
|
|
2402
|
+
/** Where the bearer token is kept for this tab. */
|
|
2403
|
+
const TOKEN_KEY = `${APP}.token`;
|
|
2404
|
+
/**
|
|
2405
|
+
* The bearer token, from `POST /session`. Kept in `sessionStorage` as well,
|
|
2406
|
+
* so a reload stays signed in: it is per tab, ends with the tab, and is never
|
|
2407
|
+
* sent with a request or put in a URL. A cookie would be sent with every
|
|
2408
|
+
* request, and `localStorage` would outlive the tab.
|
|
2409
|
+
*/
|
|
2410
|
+
let token = stored();
|
|
2411
|
+
function stored() {
|
|
2412
|
+
try {
|
|
2413
|
+
return globalThis.sessionStorage?.getItem(TOKEN_KEY) ?? "";
|
|
2414
|
+
} catch {
|
|
2415
|
+
return "";
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
function keep(value) {
|
|
2419
|
+
token = value;
|
|
2420
|
+
try {
|
|
2421
|
+
if (value === "") globalThis.sessionStorage?.removeItem(TOKEN_KEY);
|
|
2422
|
+
else globalThis.sessionStorage?.setItem(TOKEN_KEY, value);
|
|
2423
|
+
} catch {}
|
|
2424
|
+
}
|
|
2425
|
+
/**
|
|
2426
|
+
* Trade the one-shot boot token for the bearer token. False when the boot
|
|
2427
|
+
* token is used, expired or wrong, or the server is gone.
|
|
2428
|
+
*/
|
|
2429
|
+
async function signIn(boot) {
|
|
2430
|
+
try {
|
|
2431
|
+
const res = await fetch("/session", {
|
|
2432
|
+
method: "POST",
|
|
2433
|
+
headers: { "content-type": "application/json" },
|
|
2434
|
+
body: JSON.stringify({ boot }),
|
|
2435
|
+
cache: "no-store"
|
|
2436
|
+
});
|
|
2437
|
+
if (!res.ok) return false;
|
|
2438
|
+
const body = await res.json();
|
|
2439
|
+
if (typeof body.token !== "string") return false;
|
|
2440
|
+
keep(body.token);
|
|
2441
|
+
return true;
|
|
2442
|
+
} catch {
|
|
2443
|
+
return false;
|
|
2444
|
+
}
|
|
2445
|
+
}
|
|
2446
|
+
/** Whether the page holds a token: from a sign-in, or kept from before a reload. */
|
|
2447
|
+
function signedIn() {
|
|
2448
|
+
return token !== "";
|
|
2449
|
+
}
|
|
2450
|
+
/**
|
|
2451
|
+
* Whether the kept token still works, asked without signing out on a 401.
|
|
2452
|
+
* The page asks before it spends a boot token, so a tab that is already
|
|
2453
|
+
* signed in never redeems one a second time.
|
|
2454
|
+
*/
|
|
2455
|
+
async function tokenWorks() {
|
|
2456
|
+
if (token === "") return false;
|
|
2457
|
+
try {
|
|
2458
|
+
return (await fetch("/api/commands/config/path", {
|
|
2459
|
+
method: "POST",
|
|
2460
|
+
headers: authHeaders({ "content-type": "application/json" }),
|
|
2461
|
+
body: "{}",
|
|
2462
|
+
cache: "no-store"
|
|
2463
|
+
})).status !== 401;
|
|
2464
|
+
} catch {
|
|
2465
|
+
return false;
|
|
2466
|
+
}
|
|
1248
2467
|
}
|
|
1249
|
-
//#endregion
|
|
1250
|
-
//#region src/web/api.ts
|
|
1251
2468
|
/**
|
|
1252
|
-
*
|
|
1253
|
-
*
|
|
1254
|
-
* Kept in module state only. localStorage, sessionStorage and cookies either
|
|
1255
|
-
* outlive the tab or are sent with requests the page did not make. Module
|
|
1256
|
-
* state ends with the page, which is the lifetime the token should have.
|
|
2469
|
+
* Forget the token and show the signed-out page. For a 401: the server was
|
|
2470
|
+
* restarted, so the kept token is not its token.
|
|
1257
2471
|
*/
|
|
1258
|
-
|
|
2472
|
+
function signOut() {
|
|
2473
|
+
keep("");
|
|
2474
|
+
showSignedOut();
|
|
2475
|
+
}
|
|
2476
|
+
function authHeaders(extra = {}) {
|
|
2477
|
+
const headers = new Headers(extra);
|
|
2478
|
+
headers.set("authorization", `Bearer ${token}`);
|
|
2479
|
+
return headers;
|
|
2480
|
+
}
|
|
1259
2481
|
/**
|
|
1260
|
-
*
|
|
1261
|
-
*
|
|
1262
|
-
*
|
|
1263
|
-
* page the user visits can reach, so reads and writes both carry the token.
|
|
1264
|
-
* Send new endpoints through here. A request without the token gets a 401.
|
|
2482
|
+
* Read an NDJSON body: each line of the events' kind goes to `events` as it
|
|
2483
|
+
* comes, and the other line, the document or the error, is the result. Null
|
|
2484
|
+
* when the stream ends without one.
|
|
1265
2485
|
*/
|
|
1266
|
-
function
|
|
1267
|
-
const
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
2486
|
+
async function readLines(body, events) {
|
|
2487
|
+
const reader = body.getReader();
|
|
2488
|
+
const decoder = new TextDecoder();
|
|
2489
|
+
let buffered = "";
|
|
2490
|
+
let last = null;
|
|
2491
|
+
const take = (text) => {
|
|
2492
|
+
if (text.trim() === "") return;
|
|
2493
|
+
const line = JSON.parse(text);
|
|
2494
|
+
if (line["kind"] === events.kind) events.on(line);
|
|
2495
|
+
else last = line;
|
|
2496
|
+
};
|
|
1277
2497
|
try {
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
2498
|
+
for (;;) {
|
|
2499
|
+
const { done, value } = await reader.read();
|
|
2500
|
+
if (done) break;
|
|
2501
|
+
buffered += decoder.decode(value, { stream: true });
|
|
2502
|
+
let at;
|
|
2503
|
+
while ((at = buffered.indexOf("\n")) !== -1) {
|
|
2504
|
+
take(buffered.slice(0, at));
|
|
2505
|
+
buffered = buffered.slice(at + 1);
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
take(buffered + decoder.decode());
|
|
1281
2509
|
} catch {
|
|
1282
2510
|
return null;
|
|
1283
2511
|
}
|
|
2512
|
+
return last;
|
|
1284
2513
|
}
|
|
1285
2514
|
/**
|
|
1286
|
-
*
|
|
1287
|
-
*
|
|
1288
|
-
*
|
|
1289
|
-
*
|
|
1290
|
-
* survives the save (see `writeProjectConfig` in serve.ts).
|
|
1291
|
-
*
|
|
1292
|
-
* On success it returns the config as it now is in the file, so the screen
|
|
1293
|
-
* re-renders from the file in one round trip.
|
|
2515
|
+
* Run `way <words...>` with `args`, the JSON form of its flags and
|
|
2516
|
+
* positionals. `confirm` is the nonce of a confirmed 428. With `events`,
|
|
2517
|
+
* the answer streams as NDJSON: each event line goes to `events.on` as it
|
|
2518
|
+
* comes, and the document is the last line.
|
|
1294
2519
|
*/
|
|
1295
|
-
async function
|
|
2520
|
+
async function call(words, args = {}, confirm, events) {
|
|
2521
|
+
let res;
|
|
1296
2522
|
try {
|
|
1297
|
-
|
|
2523
|
+
res = await fetch("/api/commands/" + words.map(encodeURIComponent).join("/"), {
|
|
1298
2524
|
method: "POST",
|
|
1299
|
-
headers: {
|
|
1300
|
-
|
|
2525
|
+
headers: authHeaders({
|
|
2526
|
+
"content-type": "application/json",
|
|
2527
|
+
...confirm !== void 0 ? { "x-confirm": confirm } : {},
|
|
2528
|
+
...events !== void 0 ? { accept: NDJSON } : {}
|
|
2529
|
+
}),
|
|
2530
|
+
body: JSON.stringify(args),
|
|
2531
|
+
cache: "no-store"
|
|
1301
2532
|
});
|
|
1302
|
-
|
|
2533
|
+
} catch {
|
|
2534
|
+
return {
|
|
1303
2535
|
ok: false,
|
|
1304
|
-
|
|
2536
|
+
status: 0,
|
|
2537
|
+
message: "the server is gone"
|
|
1305
2538
|
};
|
|
1306
|
-
|
|
2539
|
+
}
|
|
2540
|
+
if (res.status === 401) signOut();
|
|
2541
|
+
if (events !== void 0 && res.ok && res.body !== null && (res.headers.get("content-type") ?? "").includes(NDJSON)) {
|
|
2542
|
+
const last = await readLines(res.body, events);
|
|
2543
|
+
if (last === null) return {
|
|
2544
|
+
ok: false,
|
|
2545
|
+
status: 0,
|
|
2546
|
+
message: "the server is gone"
|
|
2547
|
+
};
|
|
2548
|
+
if (last["kind"] !== "error") return {
|
|
1307
2549
|
ok: true,
|
|
1308
|
-
|
|
2550
|
+
doc: last
|
|
1309
2551
|
};
|
|
1310
|
-
} catch (err) {
|
|
1311
2552
|
return {
|
|
1312
2553
|
ok: false,
|
|
1313
|
-
|
|
2554
|
+
status: 500,
|
|
2555
|
+
message: typeof last["message"] === "string" ? last["message"] : "the command failed",
|
|
2556
|
+
...typeof last["hint"] === "string" ? { hint: last["hint"] } : {},
|
|
2557
|
+
...typeof last["code"] === "string" ? { code: last["code"] } : {}
|
|
1314
2558
|
};
|
|
1315
2559
|
}
|
|
2560
|
+
const body = await res.json().catch(() => null);
|
|
2561
|
+
if (res.ok && body !== null) return {
|
|
2562
|
+
ok: true,
|
|
2563
|
+
doc: body
|
|
2564
|
+
};
|
|
2565
|
+
const text = (key) => typeof body?.[key] === "string" ? body[key] : void 0;
|
|
2566
|
+
return {
|
|
2567
|
+
ok: false,
|
|
2568
|
+
status: res.status,
|
|
2569
|
+
message: text("message") ?? `the server answered ${res.status}`,
|
|
2570
|
+
...text("hint") !== void 0 ? { hint: text("hint") } : {},
|
|
2571
|
+
...text("code") !== void 0 ? { code: text("code") } : {},
|
|
2572
|
+
...text("nonce") !== void 0 ? { nonce: text("nonce") } : {}
|
|
2573
|
+
};
|
|
2574
|
+
}
|
|
2575
|
+
/** A failed call as one line a person reads: the message, then the hint. */
|
|
2576
|
+
function failureText(result) {
|
|
2577
|
+
return result.hint === void 0 ? result.message : `${result.message} (${result.hint})`;
|
|
2578
|
+
}
|
|
2579
|
+
function showError(prefix, detail) {
|
|
2580
|
+
$("status").innerHTML = "<span class=\"err\">" + escapeHtml(prefix + ": " + detail) + "</span>";
|
|
1316
2581
|
}
|
|
2582
|
+
/** Whether a withheld runner would be read once the repository, or a tool it runs, is trusted. */
|
|
2583
|
+
function trustableFrom(unknowns) {
|
|
2584
|
+
return unknowns.some((u) => u.kind === "withheld" && (u.reason === "untrusted" || u.reason === "tool-untrusted"));
|
|
2585
|
+
}
|
|
2586
|
+
/**
|
|
2587
|
+
* A load that was asked for while another ran, to run once that one is done.
|
|
2588
|
+
* `done` settles when it has run, for every caller that asked for it.
|
|
2589
|
+
*/
|
|
2590
|
+
let again = null;
|
|
2591
|
+
/** True while a load runs. `state.loading` is the part the status line shows. */
|
|
2592
|
+
let busy = false;
|
|
1317
2593
|
/**
|
|
1318
|
-
*
|
|
2594
|
+
* Pull the catalog with `way list`.
|
|
2595
|
+
*
|
|
2596
|
+
* `cached` answers with the newest catalog the server holds (the saved
|
|
2597
|
+
* listing at first), so the first view appears at once on a repository whose
|
|
2598
|
+
* slowest runner takes seconds. `join` lets the answer be a probe the server
|
|
2599
|
+
* is already running, for the first fresh read and the polls. Without it (a
|
|
2600
|
+
* Refresh, or a read after a change) the server starts a probe, so the
|
|
2601
|
+
* answer is never from before the click. Progress streams with nothing on
|
|
2602
|
+
* screen, for a plain load, and with `progress`; a joining poll asks for none,
|
|
2603
|
+
* since each line carries a full report. A load asked for while one runs
|
|
2604
|
+
* runs after it, so a Refresh during a poll is not lost, and its promise
|
|
2605
|
+
* settles only once that later read has run.
|
|
1319
2606
|
*
|
|
1320
|
-
* The
|
|
1321
|
-
*
|
|
2607
|
+
* The fingerprint check stops an unchanged poll from resetting the scroll
|
|
2608
|
+
* position and open groups.
|
|
1322
2609
|
*/
|
|
1323
|
-
async function
|
|
2610
|
+
async function load(opts = {}) {
|
|
2611
|
+
if (busy) {
|
|
2612
|
+
if (again === null) {
|
|
2613
|
+
let resolve = () => {};
|
|
2614
|
+
again = {
|
|
2615
|
+
opts,
|
|
2616
|
+
done: new Promise((ok) => {
|
|
2617
|
+
resolve = ok;
|
|
2618
|
+
}),
|
|
2619
|
+
resolve
|
|
2620
|
+
};
|
|
2621
|
+
} else if (opts.join !== true) again.opts = opts;
|
|
2622
|
+
return again.done;
|
|
2623
|
+
}
|
|
2624
|
+
busy = true;
|
|
1324
2625
|
try {
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
state.catalog = cat;
|
|
1332
|
-
state.trustable = cat.trustable === true;
|
|
1333
|
-
state.cache = cat.cache ?? [];
|
|
1334
|
-
state.checkedAt = cat.generatedAt;
|
|
1335
|
-
state.fingerprint = "";
|
|
1336
|
-
render();
|
|
1337
|
-
if (cat.note !== void 0) $("status").textContent = cat.note;
|
|
1338
|
-
} catch (err) {
|
|
1339
|
-
$("status").innerHTML = "<span class=\"err\">trust failed: " + escapeHtml(String(err)) + " (is the server still running?)</span>";
|
|
2626
|
+
await loadOnce(opts);
|
|
2627
|
+
} finally {
|
|
2628
|
+
busy = false;
|
|
2629
|
+
const next = again;
|
|
2630
|
+
again = null;
|
|
2631
|
+
if (next !== null) load(next.opts).finally(next.resolve);
|
|
1340
2632
|
}
|
|
1341
2633
|
}
|
|
1342
2634
|
/**
|
|
1343
|
-
*
|
|
1344
|
-
*
|
|
1345
|
-
*
|
|
1346
|
-
* setting it decided at start. See the DELETE branch in serve.ts for why the
|
|
1347
|
-
* server does not guess whether that came from the store or from `--exec`.
|
|
1348
|
-
* The caller says so, rather than implying a revoke that did not happen.
|
|
2635
|
+
* One progress line of a probe. While nothing else is on screen, the runner
|
|
2636
|
+
* that answered joins the catalog and the page draws it; otherwise only the
|
|
2637
|
+
* count of runners still loading moves.
|
|
1349
2638
|
*/
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
2639
|
+
function onProgress(line) {
|
|
2640
|
+
const event = line;
|
|
2641
|
+
const first = state.expected < 0;
|
|
2642
|
+
state.pending = event.pending;
|
|
2643
|
+
state.expected = event.total;
|
|
2644
|
+
if (!state.live) {
|
|
2645
|
+
if (Date.now() - state.loadStarted >= 3e3) refreshStatus();
|
|
2646
|
+
return;
|
|
2647
|
+
}
|
|
2648
|
+
if (first) {
|
|
2649
|
+
state.order = [...event.pending];
|
|
2650
|
+
announce("loading " + countRunners(event.total));
|
|
2651
|
+
}
|
|
2652
|
+
const report = event.report;
|
|
2653
|
+
const base = state.catalog ?? {
|
|
2654
|
+
kind: "catalog",
|
|
2655
|
+
schemaVersion: 1,
|
|
2656
|
+
root: "",
|
|
2657
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2658
|
+
discovery: "git",
|
|
2659
|
+
allowExec: false,
|
|
2660
|
+
reports: [],
|
|
2661
|
+
cache: [],
|
|
2662
|
+
unknowns: [],
|
|
2663
|
+
skills: []
|
|
2664
|
+
};
|
|
2665
|
+
if (report === void 0) state.catalog = base;
|
|
2666
|
+
else {
|
|
2667
|
+
const others = (list) => (list ?? []).filter((r) => r.runner !== report.runner);
|
|
2668
|
+
const rank = (r) => {
|
|
2669
|
+
const at = state.order.indexOf(r.runner);
|
|
2670
|
+
return at === -1 ? state.order.length : at;
|
|
2671
|
+
};
|
|
2672
|
+
state.catalog = {
|
|
2673
|
+
...base,
|
|
2674
|
+
reports: [...others(base.reports), report].sort((a, b) => rank(a) - rank(b)),
|
|
2675
|
+
cache: [...others(base.cache), ...event.cache ? [event.cache] : []],
|
|
2676
|
+
unknowns: [...others(base.unknowns), ...event.unknowns ?? []]
|
|
1356
2677
|
};
|
|
1357
|
-
|
|
2678
|
+
state.cache = state.catalog.cache ?? [];
|
|
2679
|
+
state.unknowns = state.catalog.unknowns ?? [];
|
|
2680
|
+
state.trustable = trustableFrom(state.unknowns);
|
|
2681
|
+
}
|
|
2682
|
+
scheduleRender();
|
|
2683
|
+
}
|
|
2684
|
+
/** Set while a render for progress lines waits, so a burst of lines draws once. */
|
|
2685
|
+
let renderQueued = false;
|
|
2686
|
+
/**
|
|
2687
|
+
* Draw the progress lines that arrived, once per 50 ms at most: a render
|
|
2688
|
+
* rebuilds every row, and runners often answer together. Skipped when the
|
|
2689
|
+
* load has ended, since its own render drew the whole answer.
|
|
2690
|
+
*/
|
|
2691
|
+
function scheduleRender() {
|
|
2692
|
+
if (renderQueued) return;
|
|
2693
|
+
renderQueued = true;
|
|
2694
|
+
setTimeout(() => {
|
|
2695
|
+
renderQueued = false;
|
|
2696
|
+
if (state.live) render();
|
|
2697
|
+
}, 50);
|
|
2698
|
+
}
|
|
2699
|
+
/** How long a first load waits before it says Loading, so a held catalog shows with no flash. */
|
|
2700
|
+
const LOADING_AFTER_MS = 200;
|
|
2701
|
+
async function loadOnce(opts) {
|
|
2702
|
+
const live = state.catalog === null;
|
|
2703
|
+
const progress = live || opts.progress === true || opts.join !== true;
|
|
2704
|
+
const args = {
|
|
2705
|
+
...opts.cached === true ? { cached: true } : {},
|
|
2706
|
+
...opts.join === true ? { join: true } : {},
|
|
2707
|
+
...progress ? { progress: true } : {}
|
|
2708
|
+
};
|
|
2709
|
+
state.loading = true;
|
|
2710
|
+
state.live = live;
|
|
2711
|
+
state.pending = [];
|
|
2712
|
+
state.expected = -1;
|
|
2713
|
+
state.order = [];
|
|
2714
|
+
state.loadStarted = Date.now();
|
|
2715
|
+
const timers = [setTimeout(() => {
|
|
2716
|
+
if (state.live && state.catalog === null) {
|
|
2717
|
+
render();
|
|
2718
|
+
refreshStatus();
|
|
2719
|
+
}
|
|
2720
|
+
}, LOADING_AFTER_MS), setTimeout(() => {
|
|
2721
|
+
if (state.loading && !state.live) refreshStatus();
|
|
2722
|
+
}, WAITING_AFTER_MS)];
|
|
2723
|
+
if (!live) refreshStatus();
|
|
2724
|
+
const result = await call(["list"], args, void 0, progress ? {
|
|
2725
|
+
kind: "catalog-progress",
|
|
2726
|
+
on: onProgress
|
|
2727
|
+
} : void 0);
|
|
2728
|
+
for (const timer of timers) clearTimeout(timer);
|
|
2729
|
+
state.loading = false;
|
|
2730
|
+
state.live = false;
|
|
2731
|
+
state.pending = [];
|
|
2732
|
+
state.order = [];
|
|
2733
|
+
if (!result.ok) {
|
|
2734
|
+
if (live) announce("loading failed");
|
|
2735
|
+
showError("refresh failed", result.status === 0 ? "the server is gone (is it still running?)" : failureText(result));
|
|
2736
|
+
return;
|
|
2737
|
+
}
|
|
2738
|
+
const cat = result.doc;
|
|
2739
|
+
const fp = JSON.stringify([
|
|
2740
|
+
cat.reports.map((s) => [
|
|
2741
|
+
s.runner,
|
|
2742
|
+
s.status,
|
|
2743
|
+
s.tasks.map((e) => e.display + " " + (e.doc || "") + " " + (e.parametersUnknown ?? ""))
|
|
2744
|
+
]),
|
|
2745
|
+
cat.unknowns?.map((u) => u.label),
|
|
2746
|
+
cat.skills?.map((s) => [
|
|
2747
|
+
s.id,
|
|
2748
|
+
s.argumentHint,
|
|
2749
|
+
s.description,
|
|
2750
|
+
s.harnesses
|
|
2751
|
+
]),
|
|
2752
|
+
cat.trustedTools
|
|
2753
|
+
]);
|
|
2754
|
+
state.checkedAt = cat.generatedAt;
|
|
2755
|
+
state.cache = cat.cache ?? [];
|
|
2756
|
+
state.unknowns = cat.unknowns ?? [];
|
|
2757
|
+
state.trustable = trustableFrom(state.unknowns);
|
|
2758
|
+
if (fp === state.fingerprint && state.catalog) {
|
|
1358
2759
|
state.catalog = cat;
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
return
|
|
1363
|
-
}
|
|
1364
|
-
|
|
2760
|
+
const inScope = scopedReports().reduce((n, s) => n + s.tasks.length, 0);
|
|
2761
|
+
renderStatus(taskRows().length, inScope);
|
|
2762
|
+
renderTrustBar();
|
|
2763
|
+
return;
|
|
2764
|
+
}
|
|
2765
|
+
state.fingerprint = fp;
|
|
2766
|
+
state.catalog = cat;
|
|
2767
|
+
render();
|
|
2768
|
+
if (live) announce(loadedText(cat));
|
|
2769
|
+
}
|
|
2770
|
+
/** What a screen reader hears when the first load ends. */
|
|
2771
|
+
function loadedText(cat) {
|
|
2772
|
+
const tasks = cat.reports.reduce((n, r) => n + r.tasks.length, 0);
|
|
2773
|
+
const failed = cat.reports.filter((r) => r.status === "error").length;
|
|
2774
|
+
return countTasks(tasks) + " loaded" + (failed > 0 ? ", " + failed + (failed === 1 ? " runner failed" : " runners failed") : "");
|
|
2775
|
+
}
|
|
2776
|
+
/** What the person is asked before a grant is sent. */
|
|
2777
|
+
const TRUST_QUESTION = "Trust this repository? Its runners will be read by running them, now and on every later visit, until you untrust it.";
|
|
2778
|
+
/** What the person is asked before one tool's grant is sent. */
|
|
2779
|
+
function toolTrustQuestion(tool) {
|
|
2780
|
+
return `Trust ${tool} in this repository? Runners that run it will be read by running it, now and on every later visit, until you untrust it.`;
|
|
2781
|
+
}
|
|
2782
|
+
/**
|
|
2783
|
+
* Send a `way trust` grant. The server answers 428 with a nonce, the person
|
|
2784
|
+
* is asked, and only then is the same request sent again with the nonce.
|
|
2785
|
+
*/
|
|
2786
|
+
async function grant(args, question, ask) {
|
|
2787
|
+
const first = await call(["trust"], args);
|
|
2788
|
+
if (!first.ok && (first.status !== 428 || first.nonce === void 0)) return {
|
|
2789
|
+
ok: false,
|
|
2790
|
+
declined: false,
|
|
2791
|
+
detail: failureText(first)
|
|
2792
|
+
};
|
|
2793
|
+
if (!first.ok) {
|
|
2794
|
+
if (!ask(question)) return {
|
|
2795
|
+
ok: false,
|
|
2796
|
+
declined: true,
|
|
2797
|
+
detail: "not confirmed"
|
|
2798
|
+
};
|
|
2799
|
+
const second = await call(["trust"], args, first.nonce);
|
|
2800
|
+
if (!second.ok) return {
|
|
1365
2801
|
ok: false,
|
|
1366
|
-
|
|
2802
|
+
declined: false,
|
|
2803
|
+
detail: failureText(second)
|
|
1367
2804
|
};
|
|
1368
2805
|
}
|
|
2806
|
+
state.fingerprint = "";
|
|
2807
|
+
await load();
|
|
2808
|
+
return { ok: true };
|
|
1369
2809
|
}
|
|
1370
2810
|
/**
|
|
1371
|
-
*
|
|
1372
|
-
*
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
2811
|
+
* Grant trust with `way trust`, confirmed by the person. Returns true when
|
|
2812
|
+
* the grant was made.
|
|
2813
|
+
*/
|
|
2814
|
+
async function trustRepo(ask = confirm) {
|
|
2815
|
+
const result = await grant({}, TRUST_QUESTION, ask);
|
|
2816
|
+
if (!result.ok && !result.declined) showError("trust failed", result.detail);
|
|
2817
|
+
return result.ok;
|
|
2818
|
+
}
|
|
2819
|
+
/** Remove the repository's trust with `way trust --untrust`. */
|
|
2820
|
+
async function untrustRepo() {
|
|
2821
|
+
return untrust({ untrust: true });
|
|
2822
|
+
}
|
|
2823
|
+
/** Trust one tool with `way trust --scope <tool>`, confirmed by the person. */
|
|
2824
|
+
function trustTool(tool, ask = confirm) {
|
|
2825
|
+
return grant({ scope: tool }, toolTrustQuestion(tool), ask);
|
|
2826
|
+
}
|
|
2827
|
+
/** Remove one tool's trust with `way trust --untrust --scope <tool>`. */
|
|
2828
|
+
function untrustTool(tool) {
|
|
2829
|
+
return untrust({
|
|
2830
|
+
untrust: true,
|
|
2831
|
+
scope: tool
|
|
2832
|
+
});
|
|
2833
|
+
}
|
|
2834
|
+
async function untrust(args) {
|
|
2835
|
+
const result = await call(["trust"], args);
|
|
2836
|
+
if (!result.ok) return {
|
|
2837
|
+
ok: false,
|
|
2838
|
+
detail: failureText(result)
|
|
2839
|
+
};
|
|
2840
|
+
state.fingerprint = "";
|
|
2841
|
+
await load();
|
|
2842
|
+
return { ok: true };
|
|
2843
|
+
}
|
|
2844
|
+
/** Read every tool's description, language and homepage with `way providers`. */
|
|
2845
|
+
async function loadTools() {
|
|
2846
|
+
const result = await call(["providers"]);
|
|
2847
|
+
if (!result.ok) return;
|
|
2848
|
+
state.tools = result.doc.providers.map((p) => ({
|
|
2849
|
+
id: p.id,
|
|
2850
|
+
homepage: p.homepage,
|
|
2851
|
+
description: p.description,
|
|
2852
|
+
ecosystem: p.ecosystem,
|
|
2853
|
+
language: p.language
|
|
2854
|
+
}));
|
|
2855
|
+
}
|
|
2856
|
+
/**
|
|
2857
|
+
* Read the settings with `way config list` and the trust with `way trust
|
|
2858
|
+
* --show`. Null when either fails.
|
|
2859
|
+
*/
|
|
2860
|
+
async function readConfig() {
|
|
2861
|
+
const [list, trust] = await Promise.all([call(["config", "list"]), call(["trust"], { show: true })]);
|
|
2862
|
+
if (!list.ok || !trust.ok) return null;
|
|
2863
|
+
const root = trust.doc.roots[0];
|
|
2864
|
+
return {
|
|
2865
|
+
settings: list.doc.settings,
|
|
2866
|
+
locations: list.doc.locations,
|
|
2867
|
+
trusted: root?.trusted === true,
|
|
2868
|
+
trustedBy: root?.by ?? null
|
|
2869
|
+
};
|
|
2870
|
+
}
|
|
2871
|
+
/** A setting's value in `view`. */
|
|
2872
|
+
function settingValue(view, key) {
|
|
2873
|
+
return view?.settings.find((s) => s.key === key)?.value;
|
|
2874
|
+
}
|
|
2875
|
+
/** A setting's source in `view`: `default`, `user` or `project`. */
|
|
2876
|
+
function settingSource(view, key) {
|
|
2877
|
+
return view?.settings.find((s) => s.key === key)?.source ?? "default";
|
|
2878
|
+
}
|
|
2879
|
+
/** Write one setting with `way config set <key> <json> --<layer>`. */
|
|
2880
|
+
function setSetting(key, value, layer) {
|
|
2881
|
+
return call(["config", "set"], {
|
|
2882
|
+
key,
|
|
2883
|
+
value: JSON.stringify(value),
|
|
2884
|
+
[layer]: true
|
|
2885
|
+
});
|
|
2886
|
+
}
|
|
2887
|
+
/** Remove one setting with `way config unset <key> --<layer>`. */
|
|
2888
|
+
function unsetSetting(key, layer) {
|
|
2889
|
+
return call(["config", "unset"], {
|
|
2890
|
+
key,
|
|
2891
|
+
[layer]: true
|
|
2892
|
+
});
|
|
2893
|
+
}
|
|
2894
|
+
/**
|
|
2895
|
+
* Ask the server to hand its terminal to a task, as `way run <id> -- <args>`
|
|
2896
|
+
* does. The id selects the task, and `args` are its trailing arguments. The
|
|
2897
|
+
* binary, the leading arguments and the cwd never come from the page.
|
|
1378
2898
|
*/
|
|
1379
2899
|
async function requestRun(id, args = []) {
|
|
2900
|
+
let res;
|
|
1380
2901
|
try {
|
|
1381
|
-
|
|
2902
|
+
res = await fetch("/run", {
|
|
1382
2903
|
method: "POST",
|
|
1383
|
-
headers: { "content-type": "application/json" },
|
|
2904
|
+
headers: authHeaders({ "content-type": "application/json" }),
|
|
1384
2905
|
body: JSON.stringify({
|
|
1385
2906
|
id,
|
|
1386
2907
|
args
|
|
1387
|
-
})
|
|
2908
|
+
}),
|
|
2909
|
+
cache: "no-store"
|
|
1388
2910
|
});
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
};
|
|
1398
|
-
const body = await res.json();
|
|
1399
|
-
return {
|
|
1400
|
-
outcome: "handed-off",
|
|
1401
|
-
command: body.argv?.join(" ") || body.display || "the task"
|
|
1402
|
-
};
|
|
1403
|
-
} catch (err) {
|
|
1404
|
-
if (err instanceof TypeError) return { outcome: "gone" };
|
|
2911
|
+
} catch {
|
|
2912
|
+
return { outcome: "gone" };
|
|
2913
|
+
}
|
|
2914
|
+
if (res.status === 409) return { outcome: "taken" };
|
|
2915
|
+
if (res.status === 401) signOut();
|
|
2916
|
+
const body = await res.json().catch(() => null);
|
|
2917
|
+
if (!res.ok) {
|
|
2918
|
+
if (body?.code === "task-changed") load();
|
|
1405
2919
|
return {
|
|
1406
2920
|
outcome: "failed",
|
|
1407
|
-
detail:
|
|
2921
|
+
detail: failureText({
|
|
2922
|
+
message: body?.message ?? `the server answered ${res.status}`,
|
|
2923
|
+
...body?.hint !== void 0 ? { hint: body.hint } : {}
|
|
2924
|
+
})
|
|
1408
2925
|
};
|
|
1409
2926
|
}
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
* `force` is the Refresh button, and it always runs a real probe of every
|
|
1415
|
-
* runner, since a refresh answered from a store is not a refresh. An unforced
|
|
1416
|
-
* call (first view, focus, the poll) takes the newest answer the server has.
|
|
1417
|
-
* On the first request that is the stored answer, with a probe already
|
|
1418
|
-
* running in the background. `state.cache` says which rows those were.
|
|
1419
|
-
*
|
|
1420
|
-
* The fingerprint check stops an unchanged poll from resetting the scroll
|
|
1421
|
-
* position and open groups.
|
|
1422
|
-
*/
|
|
1423
|
-
async function load(force) {
|
|
1424
|
-
if (state.loading) return;
|
|
1425
|
-
state.loading = true;
|
|
1426
|
-
try {
|
|
1427
|
-
const res = await authFetch("/api/catalog" + (force ? "?force=1" : ""));
|
|
1428
|
-
if (!res.ok) throw new Error(`the server answered ${res.status}`);
|
|
1429
|
-
const cat = await res.json();
|
|
1430
|
-
const fp = JSON.stringify(cat.reports.map((s) => [
|
|
1431
|
-
s.runner,
|
|
1432
|
-
s.status,
|
|
1433
|
-
s.tasks.map((e) => e.display + " " + (e.doc || ""))
|
|
1434
|
-
]));
|
|
1435
|
-
state.loading = false;
|
|
1436
|
-
state.checkedAt = cat.generatedAt;
|
|
1437
|
-
state.trustable = cat.trustable === true;
|
|
1438
|
-
state.cache = cat.cache ?? [];
|
|
1439
|
-
if (fp === state.fingerprint && state.catalog) {
|
|
1440
|
-
const inScope = scopedReports().reduce((n, s) => n + s.tasks.length, 0);
|
|
1441
|
-
renderStatus(listRows().length, inScope);
|
|
1442
|
-
renderTrustBar();
|
|
1443
|
-
return;
|
|
1444
|
-
}
|
|
1445
|
-
state.fingerprint = fp;
|
|
1446
|
-
state.catalog = cat;
|
|
1447
|
-
render();
|
|
1448
|
-
} catch (err) {
|
|
1449
|
-
state.loading = false;
|
|
1450
|
-
$("status").innerHTML = "<span class=\"err\">refresh failed: " + escapeHtml(String(err)) + " (is the server still running?)</span>";
|
|
1451
|
-
}
|
|
2927
|
+
return {
|
|
2928
|
+
outcome: "handed-off",
|
|
2929
|
+
command: body?.argv?.join(" ") || body?.display || "the task"
|
|
2930
|
+
};
|
|
1452
2931
|
}
|
|
1453
2932
|
//#endregion
|
|
1454
2933
|
//#region src/web/settings.ts
|
|
1455
2934
|
/**
|
|
1456
2935
|
* The settings screen: this project's configuration, and edits to it.
|
|
1457
2936
|
*
|
|
1458
|
-
*
|
|
1459
|
-
*
|
|
2937
|
+
* It reads `way config list` and `way trust --show`, and Save writes each
|
|
2938
|
+
* edit with `way config set`, so the screen and the command line read and
|
|
2939
|
+
* write the same files with the same rules. Edits are staged; nothing is
|
|
2940
|
+
* written until Save. The project config is a committed file, so a click
|
|
2941
|
+
* must not silently change someone's working tree.
|
|
1460
2942
|
*
|
|
1461
|
-
*
|
|
1462
|
-
*
|
|
2943
|
+
* Trust of the repository, or of one tool, is granted here only after the
|
|
2944
|
+
* person confirms (see `trustRepo`, `trustTool`). Settings the page may not
|
|
2945
|
+
* write (`allowExec`, the trust policy, `tools`) are shown read-only, each
|
|
2946
|
+
* with the command that changes it.
|
|
1463
2947
|
*
|
|
1464
|
-
*
|
|
1465
|
-
*
|
|
2948
|
+
* It is not the runner picker. The picker in the header filters this visit
|
|
2949
|
+
* and is then forgotten. This screen sets which runners the project uses.
|
|
1466
2950
|
*
|
|
1467
2951
|
* Its state lives here, not in `state.ts`. The staged edits belong to the
|
|
1468
|
-
* dialog and mean nothing once it closes.
|
|
1469
|
-
* user of that state would carry a field about a screen it never opens.
|
|
2952
|
+
* dialog and mean nothing once it closes.
|
|
1470
2953
|
*/
|
|
1471
|
-
/** What the server last
|
|
2954
|
+
/** What the server last said the configuration is. */
|
|
1472
2955
|
let loaded = null;
|
|
1473
2956
|
/** Runner ids the catalog reported. The config alone cannot supply them. */
|
|
1474
2957
|
let knownRunners = [];
|
|
@@ -1479,15 +2962,14 @@ let knownRunners = [];
|
|
|
1479
2962
|
let staged = {};
|
|
1480
2963
|
/** A message from the last Save, shown until the next render clears it. */
|
|
1481
2964
|
let notice = null;
|
|
2965
|
+
/** The file `key` is written to: the rule the terminal UI's session uses. */
|
|
2966
|
+
function layerOf(key) {
|
|
2967
|
+
return settingLayer(key, settingSource(loaded, key));
|
|
2968
|
+
}
|
|
1482
2969
|
/** The value a key would have if Save were pressed now. */
|
|
1483
2970
|
function valueOf(key) {
|
|
1484
2971
|
if (key in staged) return staged[key];
|
|
1485
|
-
|
|
1486
|
-
for (const segment of key.split(".")) {
|
|
1487
|
-
if (typeof cursor !== "object" || cursor === null) return void 0;
|
|
1488
|
-
cursor = cursor[segment];
|
|
1489
|
-
}
|
|
1490
|
-
return cursor;
|
|
2972
|
+
return settingValue(loaded, key);
|
|
1491
2973
|
}
|
|
1492
2974
|
function stringsAt(key) {
|
|
1493
2975
|
const value = valueOf(key);
|
|
@@ -1495,73 +2977,112 @@ function stringsAt(key) {
|
|
|
1495
2977
|
}
|
|
1496
2978
|
/**
|
|
1497
2979
|
* Stage a value, or drop the edit when it matches what the file already says.
|
|
1498
|
-
*
|
|
1499
|
-
* Dropping matters: toggling a checkbox and toggling it back should leave the
|
|
1500
|
-
* screen clean, not offer to save a no-op.
|
|
2980
|
+
* Toggling a checkbox and toggling it back leaves the screen clean.
|
|
1501
2981
|
*/
|
|
1502
2982
|
function stage(key, value) {
|
|
1503
|
-
|
|
1504
|
-
const before = staged;
|
|
1505
|
-
staged = {};
|
|
1506
|
-
const v = valueOf(key);
|
|
1507
|
-
staged = before;
|
|
1508
|
-
return v;
|
|
1509
|
-
})();
|
|
1510
|
-
if (JSON.stringify(original) === JSON.stringify(value)) delete staged[key];
|
|
2983
|
+
if (JSON.stringify(settingValue(loaded, key)) === JSON.stringify(value)) delete staged[key];
|
|
1511
2984
|
else staged[key] = value;
|
|
1512
2985
|
}
|
|
1513
2986
|
function isDirty() {
|
|
1514
2987
|
return Object.keys(staged).length > 0;
|
|
1515
2988
|
}
|
|
2989
|
+
/** The path of a layer's file. */
|
|
2990
|
+
function fileOf(layer) {
|
|
2991
|
+
return loaded?.locations.find((l) => l.layer === layer)?.path ?? layer;
|
|
2992
|
+
}
|
|
1516
2993
|
/** Where a value came from, said the way `way config list` says it. */
|
|
1517
2994
|
function layerNote(key) {
|
|
1518
2995
|
if (key in staged) return "<span class=\"set-layer\" data-layer=\"staged\">unsaved</span>";
|
|
1519
|
-
const layer = loaded
|
|
2996
|
+
const layer = settingSource(loaded, key);
|
|
1520
2997
|
const where = layer === "project" ? "this project" : layer === "user" ? "your user config" : "the default";
|
|
1521
|
-
return "<span class=\"set-layer\" data-layer=\"" + layer + "\">" + escapeHtml(where) + "</span>";
|
|
2998
|
+
return "<span class=\"set-layer\" data-layer=\"" + escapeHtml(layer) + "\">" + escapeHtml(where) + "</span>";
|
|
1522
2999
|
}
|
|
1523
3000
|
function section(title, key, body) {
|
|
1524
|
-
return "<section class=\"set-section\"><h3>" + escapeHtml(title) + layerNote(key) + "</h3>" + body + "</section>";
|
|
3001
|
+
return "<section class=\"set-section\"><h3>" + escapeHtml(title) + (key === null ? "" : layerNote(key)) + "</h3>" + body + "</section>";
|
|
3002
|
+
}
|
|
3003
|
+
/** A command a person can paste, as one line. */
|
|
3004
|
+
function command(text) {
|
|
3005
|
+
return "<code class=\"set-cmd\">" + escapeHtml(text) + "</code>";
|
|
3006
|
+
}
|
|
3007
|
+
/** The runners withheld in the current catalog, by id. */
|
|
3008
|
+
function withheldRunners() {
|
|
3009
|
+
return new Set(state.unknowns.filter((u) => u.kind === "withheld").map((u) => u.runner));
|
|
1525
3010
|
}
|
|
1526
3011
|
function runnersSection() {
|
|
1527
|
-
const localOrder = restoreRunnerOrder();
|
|
1528
3012
|
const disabled = new Set(stringsAt("runners.disabled"));
|
|
1529
|
-
const
|
|
3013
|
+
const withheld = withheldRunners();
|
|
3014
|
+
const names = [.../* @__PURE__ */ new Set([...knownRunners, ...disabled])].sort((a, b) => runnerLabel(a).localeCompare(runnerLabel(b)));
|
|
1530
3015
|
const rows = names.map((name) => {
|
|
1531
3016
|
const on = !disabled.has(name);
|
|
1532
|
-
|
|
3017
|
+
const note = on && withheld.has(name) ? ", " + withheldNote(name) : "";
|
|
3018
|
+
const tool = toolInfo(name);
|
|
3019
|
+
const about = tool === void 0 ? "" : (tool.description !== null ? "<span class=\"set-desc\">" + escapeHtml(tool.description) + "</span>" : "") + "<span class=\"set-tool\">" + escapeHtml(tool.language) + (homepageLink(tool.homepage) !== "" ? " · " + homepageLink(tool.homepage, "homepage") : "") + "</span>";
|
|
3020
|
+
return "<tr><td><input type=\"checkbox\" data-set-runner=\"" + escapeHtml(name) + "\"" + (on ? " checked" : "") + " aria-label=\"Collect " + escapeHtml(runnerLabel(name)) + "\" /></td><td><code>" + escapeHtml(runnerLabel(name)) + "</code>" + about + "</td><td class=\"set-state\">" + escapeHtml((on ? "on" : "off") + note) + "</td></tr>";
|
|
1533
3021
|
}).join("");
|
|
1534
3022
|
const order = stringsAt("runners.order");
|
|
1535
|
-
|
|
3023
|
+
const orderSource = settingSource(loaded, "runners.order");
|
|
3024
|
+
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(runnerLabel(r)) + "</code>").join(" ")) + " " + layerNote("runners.order") + (orderSource === "user" ? "<button data-reset-order=\"1\">Reset to the default order</button>" : "") + "</p><p class=\"set-sub\">Drag a tab or a Runners row to reorder; the order is saved in your user config.</p>");
|
|
1536
3025
|
}
|
|
1537
3026
|
function executionSection() {
|
|
1538
3027
|
const config = loaded;
|
|
1539
3028
|
const running = state.catalog?.allowExec === true;
|
|
1540
|
-
const trust = config.trusted ? "This repository is trusted, so runners may
|
|
1541
|
-
const action = config.trusted ? "<button data-untrust-repo=\"1\">Untrust</button>" : config.trustable ? "<button data-trust-repo-settings=\"1\">Trust this repository</button>" : "";
|
|
1542
|
-
|
|
3029
|
+
const trust = config.trusted ? "This repository is trusted" + (config.trustedBy !== null && config.trustedBy !== "marker" ? " by your trust policy (" + config.trustedBy + ")" : "") + ", so runners may run to be read." : running ? "This repository is not trusted, but execution is on: way serve was started with --exec." : state.trustable ? "This repository is not trusted, so runners that must run to be read are withheld." : "Execution is off for this session, and trusting the repository would not change that.";
|
|
3030
|
+
const action = config.trusted && config.trustedBy === "marker" ? "<button data-untrust-repo=\"1\">Untrust</button>" : !config.trusted && state.trustable ? "<button data-trust-repo-settings=\"1\">Trust this repository</button>" : "";
|
|
3031
|
+
const allowExec = settingValue(loaded, "allowExec") === true;
|
|
3032
|
+
return section("Execution", "allowExec", "<p>" + escapeHtml(trust) + "</p>" + (action === "" ? "" : "<div class=\"set-actions set-inline\">" + action + "</div>") + toolTrust() + "<p class=\"set-sub\"><code>allowExec</code>: <code>" + String(allowExec) + "</code>. It is changed from the command line only: " + command(`way config set allowExec ${String(!allowExec)} --user`) + "</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>");
|
|
3033
|
+
}
|
|
3034
|
+
/**
|
|
3035
|
+
* Trust one tool at a time: the tools trusted on their own, each with
|
|
3036
|
+
* Untrust, and the withheld runners with the tools they still need, each
|
|
3037
|
+
* with a grant. Empty when neither applies.
|
|
3038
|
+
*/
|
|
3039
|
+
function toolTrust() {
|
|
3040
|
+
const trusted = state.catalog?.trustedTools ?? [];
|
|
3041
|
+
const waiting = state.unknowns.flatMap((u) => u.kind === "withheld" && u.missing !== void 0 && u.missing.length > 0 ? [u] : []);
|
|
3042
|
+
if (trusted.length === 0 && waiting.length === 0) return "";
|
|
3043
|
+
const trustedRows = trusted.map((tool) => "<li><code>" + escapeHtml(tool) + "</code> trusted on its own <button data-untrust-tool=\"" + escapeHtml(tool) + "\" aria-label=\"" + escapeHtml("Untrust " + tool) + "\">Untrust</button></li>").join("");
|
|
3044
|
+
const offered = /* @__PURE__ */ new Set();
|
|
3045
|
+
const waitingRows = waiting.map((u) => {
|
|
3046
|
+
const grants = (u.missing ?? []).filter((tool) => {
|
|
3047
|
+
if (!state.trustable || offered.has(tool)) return false;
|
|
3048
|
+
offered.add(tool);
|
|
3049
|
+
return true;
|
|
3050
|
+
}).map((tool) => "<button data-trust-tool=\"" + escapeHtml(tool) + "\">" + escapeHtml("Trust " + tool) + "</button>").join("");
|
|
3051
|
+
return "<li><code>" + escapeHtml(runnerLabel(u.runner)) + "</code> " + escapeHtml(u.label) + " " + grants + "</li>";
|
|
3052
|
+
}).join("");
|
|
3053
|
+
return "<h4>Tools</h4><ul class=\"set-list set-tools\">" + trustedRows + waitingRows + "</ul><p class=\"set-sub\">Trusting one tool lets the runners that run it be read, and nothing else. " + command(`way trust --scope <tool>`) + " does the same; " + command(`way trust --untrust --scope <tool>`) + " removes it.</p>";
|
|
1543
3054
|
}
|
|
1544
3055
|
const DISCOVERY_MODES = [
|
|
1545
3056
|
"auto",
|
|
1546
3057
|
"git",
|
|
1547
3058
|
"walk"
|
|
1548
3059
|
];
|
|
3060
|
+
function radios(key, values) {
|
|
3061
|
+
const current = valueOf(key);
|
|
3062
|
+
return "<div class=\"set-radios\">" + values.map((v) => "<label><input type=\"radio\" name=\"set-" + escapeHtml(key) + "\" data-set-key=\"" + escapeHtml(key) + "\" data-set-value=\"" + escapeHtml(v) + "\"" + (current === v ? " checked" : "") + " /> <code>" + escapeHtml(v) + "</code></label>").join("") + "</div>";
|
|
3063
|
+
}
|
|
1549
3064
|
function discoverySection() {
|
|
1550
|
-
|
|
1551
|
-
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>");
|
|
3065
|
+
return section("Discovery", "discovery", radios("discovery", DISCOVERY_MODES) + "<p class=\"set-sub\"><code>auto</code> uses git when the root is a repository and walks it otherwise.</p>");
|
|
1552
3066
|
}
|
|
1553
3067
|
function excludedSection() {
|
|
1554
3068
|
const paths = stringsAt("excludePaths");
|
|
1555
3069
|
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>");
|
|
1556
3070
|
}
|
|
3071
|
+
function personalSection() {
|
|
3072
|
+
return section("Personal", null, "<p class=\"set-sub\">Saved in your user config, not the project.</p><h4>Theme " + layerNote("theme") + "</h4>" + radios("theme", THEME_VALUES) + "<h4>What <code>" + escapeHtml("way") + "</code> opens " + layerNote("open") + "</h4>" + radios("open", ["tui", "web"]));
|
|
3073
|
+
}
|
|
3074
|
+
/** The settings the page may not write, each with the command that does. */
|
|
3075
|
+
function cliOnlySection() {
|
|
3076
|
+
const rows = (loaded?.settings ?? []).filter((s) => s.key !== "allowExec" && CLI_ONLY_KEYS.some((k) => s.key === k || s.key.startsWith(k + "."))).map((s) => "<tr><td><code>" + escapeHtml(s.key) + "</code></td><td><code>" + escapeHtml(JSON.stringify(s.value) ?? "unset") + "</code> " + layerNote(s.key) + "</td></tr>").join("");
|
|
3077
|
+
return section("Command line only", null, "<p class=\"set-sub\">A page must not change the trust policy or name code to load, so these are changed from the command line, for example " + command(`way config set trust.paths '["~/work"]' --user`) + " or " + command(`way trust`) + ".</p>" + (rows === "" ? "" : "<table class=\"set-table set-ro\"><tbody>" + rows + "</tbody></table>"));
|
|
3078
|
+
}
|
|
1557
3079
|
/** The whole screen, from whatever the module currently holds. */
|
|
1558
3080
|
function screen() {
|
|
1559
|
-
|
|
1560
|
-
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>";
|
|
1561
|
-
const warnings = config.warnings.length === 0 ? "" : "<div class=\"set-warnings\">" + config.warnings.map((w) => "<p>" + escapeHtml(w) + "</p>").join("") + "</div>";
|
|
3081
|
+
if (loaded === null) return "<p class=\"set-empty\">Could not read the configuration. The server may have handed over the terminal; start " + escapeHtml(APP) + " again.</p>";
|
|
1562
3082
|
const dirty = isDirty();
|
|
1563
|
-
const message = notice === null ? "" : "<p class=\"set-notice\" data-kind=\"" + notice.kind + "\">" + escapeHtml(notice.text) + "</p>";
|
|
1564
|
-
|
|
3083
|
+
const message = notice === null ? "" : "<p class=\"set-notice\" role=\"status\" data-kind=\"" + escapeHtml(notice.kind) + "\">" + escapeHtml(notice.text) + "</p>";
|
|
3084
|
+
const files = [...new Set(Object.keys(staged).map((k) => layerOf(k)))];
|
|
3085
|
+
return "<div class=\"set-head\"><h2 id=\"settings-title\">Settings" + (dirty ? " <span class=\"set-dirty\">" + Object.keys(staged).length + " unsaved</span>" : "") + "</h2><p class=\"set-file\">Project: " + escapeHtml(fileOf("project")) + "</p><p class=\"set-file\">User: " + escapeHtml(fileOf("user")) + "</p></div>" + message + runnersSection() + executionSection() + discoverySection() + excludedSection() + personalSection() + cliOnlySection() + "<div class=\"set-actions\"><button data-settings-revert=\"1\"" + (dirty ? "" : " disabled") + ">Revert</button><button data-settings-save=\"1\"" + (dirty ? "" : " disabled") + ">" + escapeHtml(dirty ? "Save to " + files.map((l) => l === "user" ? "your user config" : "the project file").join(" and ") : "Save") + "</button></div>";
|
|
1565
3086
|
}
|
|
1566
3087
|
/** Repaint the dialog body in place. */
|
|
1567
3088
|
function repaint() {
|
|
@@ -1569,7 +3090,7 @@ function repaint() {
|
|
|
1569
3090
|
if (body !== null) body.innerHTML = screen();
|
|
1570
3091
|
}
|
|
1571
3092
|
/**
|
|
1572
|
-
* Seed the screen from a fresh read and
|
|
3093
|
+
* Seed the screen from a fresh read and return its markup.
|
|
1573
3094
|
*
|
|
1574
3095
|
* Staged edits are dropped: keeping them across a close would let a later Save
|
|
1575
3096
|
* write something the person had walked away from.
|
|
@@ -1596,9 +3117,9 @@ function handleSettingsClick(target) {
|
|
|
1596
3117
|
repaint();
|
|
1597
3118
|
return true;
|
|
1598
3119
|
}
|
|
1599
|
-
const
|
|
1600
|
-
if (
|
|
1601
|
-
stage("
|
|
3120
|
+
const radio = target.closest("[data-set-key]");
|
|
3121
|
+
if (radio !== null) {
|
|
3122
|
+
stage(radio.dataset["setKey"], radio.dataset["setValue"]);
|
|
1602
3123
|
repaint();
|
|
1603
3124
|
return true;
|
|
1604
3125
|
}
|
|
@@ -1619,14 +3140,44 @@ function handleSettingsClick(target) {
|
|
|
1619
3140
|
return true;
|
|
1620
3141
|
}
|
|
1621
3142
|
if (target.closest("[data-trust-repo-settings]") !== null) {
|
|
1622
|
-
|
|
3143
|
+
trustRepo().then(reload);
|
|
3144
|
+
return true;
|
|
3145
|
+
}
|
|
3146
|
+
const grant = target.closest("[data-trust-tool]");
|
|
3147
|
+
if (grant !== null) {
|
|
3148
|
+
const tool = grant.dataset["trustTool"];
|
|
3149
|
+
trustTool(tool).then((result) => {
|
|
3150
|
+
notice = result.ok ? {
|
|
3151
|
+
kind: "ok",
|
|
3152
|
+
text: "Trusted " + tool + ". The runners that run it are read now."
|
|
3153
|
+
} : result.declined ? null : {
|
|
3154
|
+
kind: "err",
|
|
3155
|
+
text: "trust " + tool + " failed: " + result.detail
|
|
3156
|
+
};
|
|
3157
|
+
reload();
|
|
3158
|
+
});
|
|
3159
|
+
return true;
|
|
3160
|
+
}
|
|
3161
|
+
const revoke = target.closest("[data-untrust-tool]");
|
|
3162
|
+
if (revoke !== null) {
|
|
3163
|
+
const tool = revoke.dataset["untrustTool"];
|
|
3164
|
+
untrustTool(tool).then((result) => {
|
|
3165
|
+
notice = result.ok ? {
|
|
3166
|
+
kind: "ok",
|
|
3167
|
+
text: "Untrusted " + tool + ". The runners that run it are withheld again."
|
|
3168
|
+
} : {
|
|
3169
|
+
kind: "err",
|
|
3170
|
+
text: "untrust " + tool + " failed: " + (result.detail ?? "")
|
|
3171
|
+
};
|
|
3172
|
+
reload();
|
|
3173
|
+
});
|
|
1623
3174
|
return true;
|
|
1624
3175
|
}
|
|
1625
3176
|
if (target.closest("[data-untrust-repo]") !== null) {
|
|
1626
3177
|
untrustRepo().then((result) => {
|
|
1627
3178
|
notice = result.ok ? {
|
|
1628
3179
|
kind: "ok",
|
|
1629
|
-
text: "Untrusted.
|
|
3180
|
+
text: "Untrusted. Runners that must run to be read are withheld again."
|
|
1630
3181
|
} : {
|
|
1631
3182
|
kind: "err",
|
|
1632
3183
|
text: result.detail ?? "untrust failed"
|
|
@@ -1636,9 +3187,20 @@ function handleSettingsClick(target) {
|
|
|
1636
3187
|
return true;
|
|
1637
3188
|
}
|
|
1638
3189
|
if (target.closest("[data-reset-order]") !== null) {
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
3190
|
+
unsetSetting("runners.order", "user").then(async (result) => {
|
|
3191
|
+
notice = result.ok ? {
|
|
3192
|
+
kind: "ok",
|
|
3193
|
+
text: "Removed runners.order from " + result.doc.file + "."
|
|
3194
|
+
} : {
|
|
3195
|
+
kind: "err",
|
|
3196
|
+
text: failureText(result)
|
|
3197
|
+
};
|
|
3198
|
+
state.runnerOrder = [];
|
|
3199
|
+
state.runnerOrderSource = "default";
|
|
3200
|
+
await load();
|
|
3201
|
+
render();
|
|
3202
|
+
await reload();
|
|
3203
|
+
});
|
|
1642
3204
|
return true;
|
|
1643
3205
|
}
|
|
1644
3206
|
if (target.closest("[data-settings-revert]") !== null) {
|
|
@@ -1655,32 +3217,87 @@ function handleSettingsClick(target) {
|
|
|
1655
3217
|
}
|
|
1656
3218
|
/**
|
|
1657
3219
|
* Re-read the configuration and repaint, keeping any staged edits and the
|
|
1658
|
-
* current notice.
|
|
1659
|
-
* reports without touching what the person has typed.
|
|
3220
|
+
* current notice.
|
|
1660
3221
|
*/
|
|
1661
3222
|
async function reload() {
|
|
1662
|
-
const fresh = await
|
|
3223
|
+
const fresh = await readConfig();
|
|
1663
3224
|
if (fresh !== null) loaded = fresh;
|
|
1664
3225
|
repaint();
|
|
1665
3226
|
}
|
|
1666
|
-
/**
|
|
3227
|
+
/** "a", "a and b", "a, b and c". */
|
|
3228
|
+
function listed(items) {
|
|
3229
|
+
return items.length <= 1 ? items[0] ?? "" : items.slice(0, -1).join(", ") + " and " + items[items.length - 1];
|
|
3230
|
+
}
|
|
3231
|
+
/**
|
|
3232
|
+
* Write the staged edits, one `config set` each, and say what was written
|
|
3233
|
+
* where. A refused write stops there and keeps it and the edits after it
|
|
3234
|
+
* staged, so nothing the person typed is lost.
|
|
3235
|
+
*/
|
|
1667
3236
|
async function commit() {
|
|
1668
|
-
const
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
}
|
|
1676
|
-
|
|
3237
|
+
const written = /* @__PURE__ */ new Map();
|
|
3238
|
+
let failure = null;
|
|
3239
|
+
for (const [key, value] of Object.entries(staged)) {
|
|
3240
|
+
const result = await setSetting(key, value, layerOf(key));
|
|
3241
|
+
if (!result.ok) {
|
|
3242
|
+
failure = key + ": " + failureText(result);
|
|
3243
|
+
break;
|
|
3244
|
+
}
|
|
3245
|
+
written.set(result.doc.file, [...written.get(result.doc.file) ?? [], key]);
|
|
3246
|
+
delete staged[key];
|
|
3247
|
+
if (key === "theme") applyTheme(value);
|
|
3248
|
+
}
|
|
3249
|
+
const saved = [...written].map(([file, keys]) => "Saved " + listed(keys) + " to " + file + ".");
|
|
3250
|
+
notice = failure === null ? {
|
|
3251
|
+
kind: "ok",
|
|
3252
|
+
text: saved.join(" ") || "Nothing to save."
|
|
3253
|
+
} : {
|
|
1677
3254
|
kind: "err",
|
|
1678
|
-
text:
|
|
3255
|
+
text: [...saved, "Not saved: " + failure].join(" ")
|
|
1679
3256
|
};
|
|
3257
|
+
const fresh = await readConfig();
|
|
3258
|
+
if (fresh !== null) loaded = fresh;
|
|
1680
3259
|
repaint();
|
|
3260
|
+
if (written.size > 0) {
|
|
3261
|
+
state.fingerprint = "";
|
|
3262
|
+
await load();
|
|
3263
|
+
}
|
|
3264
|
+
if ($("settings").hasAttribute("open")) openDialogAtTop("settings");
|
|
3265
|
+
}
|
|
3266
|
+
/** Show `theme` now, as the server will on the next load. */
|
|
3267
|
+
function applyTheme(theme) {
|
|
3268
|
+
if (theme === "system") document.documentElement.removeAttribute("data-theme");
|
|
3269
|
+
else document.documentElement.setAttribute("data-theme", theme);
|
|
3270
|
+
setThemeButton(theme);
|
|
1681
3271
|
}
|
|
1682
3272
|
//#endregion
|
|
1683
3273
|
//#region src/web/input.ts
|
|
3274
|
+
function statusLine(html) {
|
|
3275
|
+
$("status").innerHTML = html;
|
|
3276
|
+
}
|
|
3277
|
+
/**
|
|
3278
|
+
* Use `order` as the runner order and save it as `runners.order`, to the
|
|
3279
|
+
* file `settingLayer` picks: the project file when it sets the order, else
|
|
3280
|
+
* the user file. The terminal UI saves it the same way.
|
|
3281
|
+
*/
|
|
3282
|
+
async function saveRunnerOrder(order) {
|
|
3283
|
+
state.runnerOrder = order;
|
|
3284
|
+
render();
|
|
3285
|
+
const layer = settingLayer("runners.order", state.runnerOrderSource);
|
|
3286
|
+
const result = await setSetting("runners.order", order, layer);
|
|
3287
|
+
if (!result.ok) {
|
|
3288
|
+
statusLine("<span class=\"err\">" + escapeHtml("order not saved: " + failureText(result)) + "</span>");
|
|
3289
|
+
return;
|
|
3290
|
+
}
|
|
3291
|
+
state.runnerOrderSource = layer;
|
|
3292
|
+
}
|
|
3293
|
+
/**
|
|
3294
|
+
* Save the theme as `theme` in the user config. `system` removes the
|
|
3295
|
+
* setting, so the browser decides again.
|
|
3296
|
+
*/
|
|
3297
|
+
async function saveTheme(choice) {
|
|
3298
|
+
const result = choice === "system" ? await unsetSetting("theme", "user") : await setSetting("theme", choice, "user");
|
|
3299
|
+
if (!result.ok && choice !== "system") statusLine("<span class=\"err\">" + escapeHtml("theme not saved: " + failureText(result)) + "</span>");
|
|
3300
|
+
}
|
|
1684
3301
|
/**
|
|
1685
3302
|
* Ask for the terminal and handle every outcome.
|
|
1686
3303
|
*
|
|
@@ -1707,6 +3324,27 @@ async function handOff(id, args, button) {
|
|
|
1707
3324
|
} else if (result.outcome === "failed") $("status").innerHTML = "<span class=\"err\">run failed: " + escapeHtml(result.detail) + "</span>";
|
|
1708
3325
|
}
|
|
1709
3326
|
/**
|
|
3327
|
+
* Run a task the way the row's Run button does. A task that declares
|
|
3328
|
+
* parameters, or whose parameters could not be read, asks for its arguments
|
|
3329
|
+
* first: running it bare would hand over the terminal before anything could
|
|
3330
|
+
* say it needed some. A task that uses an editor variable is not run.
|
|
3331
|
+
*/
|
|
3332
|
+
function runTask(task, button) {
|
|
3333
|
+
if (task.parametersUnknown === "editor-variable") {
|
|
3334
|
+
statusLine("<span class=\"err\">" + escapeHtml(task.display + ": " + parametersUnknownLabel("editor-variable")) + "</span>");
|
|
3335
|
+
return;
|
|
3336
|
+
}
|
|
3337
|
+
if (task.parameters.length > 0 || task.parametersUnknown !== void 0) {
|
|
3338
|
+
armRunBar(task.id, showRunBar(task));
|
|
3339
|
+
return;
|
|
3340
|
+
}
|
|
3341
|
+
handOff(task.id, [], button);
|
|
3342
|
+
}
|
|
3343
|
+
/** The task a row stands for. */
|
|
3344
|
+
function taskOfRow(row) {
|
|
3345
|
+
return allTasks().find((t) => t.id === row.dataset.id);
|
|
3346
|
+
}
|
|
3347
|
+
/**
|
|
1710
3348
|
* Keys for the run bar's field: Enter runs what is typed, Escape goes back.
|
|
1711
3349
|
*
|
|
1712
3350
|
* Bound to the field rather than the document, so it goes away with the bar.
|
|
@@ -1756,6 +3394,13 @@ function wireInput() {
|
|
|
1756
3394
|
if (ev.key === "Enter") {
|
|
1757
3395
|
const row = document.querySelector("tbody tr.enter-target") ?? document.querySelector("tbody tr");
|
|
1758
3396
|
if (!row) return;
|
|
3397
|
+
if (ev.shiftKey) {
|
|
3398
|
+
ev.preventDefault();
|
|
3399
|
+
const task = taskOfRow(row);
|
|
3400
|
+
if (task) runTask(task, row.querySelector(".runbtn") ?? void 0);
|
|
3401
|
+
else copyRow(row);
|
|
3402
|
+
return;
|
|
3403
|
+
}
|
|
1759
3404
|
copyRow(row);
|
|
1760
3405
|
setFocusedRow(row.dataset.id ?? null);
|
|
1761
3406
|
row.focus();
|
|
@@ -1787,19 +3432,23 @@ function wireInput() {
|
|
|
1787
3432
|
return;
|
|
1788
3433
|
}
|
|
1789
3434
|
if (target.closest("[data-trust-repo]")) {
|
|
1790
|
-
|
|
3435
|
+
trustRepo();
|
|
1791
3436
|
return;
|
|
1792
3437
|
}
|
|
1793
3438
|
if (target.closest("#helpbtn")) {
|
|
1794
|
-
|
|
1795
|
-
|
|
3439
|
+
openHelp();
|
|
3440
|
+
return;
|
|
3441
|
+
}
|
|
3442
|
+
if (target.closest("#filtersbtn")) {
|
|
3443
|
+
setFiltersOpen($("filtersbtn").getAttribute("aria-expanded") !== "true");
|
|
1796
3444
|
return;
|
|
1797
3445
|
}
|
|
1798
3446
|
if (target.closest("[data-open-settings]") || target.closest("#settingsbtn")) {
|
|
1799
3447
|
$("settings-body").innerHTML = "<p class=\"set-empty\">Reading configuration…</p>";
|
|
1800
|
-
|
|
1801
|
-
|
|
3448
|
+
openDialogAtTop("settings");
|
|
3449
|
+
Promise.all([readConfig(), state.tools.length === 0 ? loadTools() : null]).then(([config]) => {
|
|
1802
3450
|
$("settings-body").innerHTML = openSettings(config, [...state.knownRunners]);
|
|
3451
|
+
openDialogAtTop("settings");
|
|
1803
3452
|
});
|
|
1804
3453
|
return;
|
|
1805
3454
|
}
|
|
@@ -1821,7 +3470,8 @@ function wireInput() {
|
|
|
1821
3470
|
}
|
|
1822
3471
|
const sort = target.closest("[data-sort-runners]");
|
|
1823
3472
|
if (sort) {
|
|
1824
|
-
|
|
3473
|
+
const dir = Number(sort.dataset.sortDir) === -1 ? -1 : 1;
|
|
3474
|
+
saveRunnerOrder(sortRunners(sort.dataset.sortRunners, dir));
|
|
1825
3475
|
return;
|
|
1826
3476
|
}
|
|
1827
3477
|
if (target.closest("[data-pick-all]")) {
|
|
@@ -1842,6 +3492,7 @@ function wireInput() {
|
|
|
1842
3492
|
return;
|
|
1843
3493
|
}
|
|
1844
3494
|
if (menu && !target.closest(".picker")) menu.hidden = true;
|
|
3495
|
+
if (!target.closest("#filters")) setFiltersOpen(false);
|
|
1845
3496
|
});
|
|
1846
3497
|
/**
|
|
1847
3498
|
* Drag to reorder, shared by the tab bar and the picker. Both mark their
|
|
@@ -1870,7 +3521,7 @@ function wireInput() {
|
|
|
1870
3521
|
let painted = [];
|
|
1871
3522
|
let paintQueued = false;
|
|
1872
3523
|
/** The runners the drag's own surface shows, in the order it shows them. */
|
|
1873
|
-
const shownOrder = (surface) => [...surface.children].map((c) => runnerOf(c)).filter((r) => r !== null && r !== "all");
|
|
3524
|
+
const shownOrder = (surface) => [...surface.children].map((c) => runnerOf(c)).filter((r) => r !== null && r !== "all" && r !== "@skills");
|
|
1874
3525
|
/** Record the arrangement the frame about to be drawn will show. */
|
|
1875
3526
|
function snapshotPainted(surface) {
|
|
1876
3527
|
if (paintQueued) return;
|
|
@@ -1924,7 +3575,7 @@ function wireInput() {
|
|
|
1924
3575
|
if (ev.dataTransfer) ev.dataTransfer.dropEffect = "move";
|
|
1925
3576
|
const over = ev.target.closest(".tabs .tab, [data-drag-runner]");
|
|
1926
3577
|
if (!over || over === dragEl || over.parentElement !== surface) return;
|
|
1927
|
-
if (runnerOf(over) === null || runnerOf(over) === "all") return;
|
|
3578
|
+
if (runnerOf(over) === null || runnerOf(over) === "all" || runnerOf(over) === "@skills") return;
|
|
1928
3579
|
slideInto(surface, dragEl, isAfter(ev, over) ? over.nextSibling : over);
|
|
1929
3580
|
snapshotPainted(surface);
|
|
1930
3581
|
});
|
|
@@ -1944,7 +3595,7 @@ function wireInput() {
|
|
|
1944
3595
|
if (choice === "system") document.documentElement.removeAttribute("data-theme");
|
|
1945
3596
|
else document.documentElement.setAttribute("data-theme", choice);
|
|
1946
3597
|
setThemeButton(choice);
|
|
1947
|
-
|
|
3598
|
+
saveTheme(choice);
|
|
1948
3599
|
});
|
|
1949
3600
|
$("depth").addEventListener("click", (e) => {
|
|
1950
3601
|
const b = e.target.closest("button[data-depth]");
|
|
@@ -1965,7 +3616,7 @@ function wireInput() {
|
|
|
1965
3616
|
e.currentTarget.textContent = state.allCollapsed ? "Expand" : "Collapse";
|
|
1966
3617
|
render();
|
|
1967
3618
|
});
|
|
1968
|
-
$("refresh").addEventListener("click", () => load(
|
|
3619
|
+
$("refresh").addEventListener("click", () => void load());
|
|
1969
3620
|
$("tabs").addEventListener("click", (e) => {
|
|
1970
3621
|
const b = e.target.closest("button[data-runner]");
|
|
1971
3622
|
if (!b) return;
|
|
@@ -1981,13 +3632,8 @@ function wireInput() {
|
|
|
1981
3632
|
}
|
|
1982
3633
|
const run = target.closest(".runbtn");
|
|
1983
3634
|
if (run) {
|
|
1984
|
-
const
|
|
1985
|
-
|
|
1986
|
-
if (task && task.parameters.length > 0) {
|
|
1987
|
-
armRunBar(task.id, showRunBar(task));
|
|
1988
|
-
return;
|
|
1989
|
-
}
|
|
1990
|
-
await handOff(id, [], run);
|
|
3635
|
+
const task = allTasks().find((t) => t.id === run.dataset.runId);
|
|
3636
|
+
if (task) runTask(task, run);
|
|
1991
3637
|
return;
|
|
1992
3638
|
}
|
|
1993
3639
|
const head = target.closest(".head");
|
|
@@ -2016,7 +3662,9 @@ function wireInput() {
|
|
|
2016
3662
|
if (ev.target !== row) return;
|
|
2017
3663
|
if (ev.key === "Enter") {
|
|
2018
3664
|
ev.preventDefault();
|
|
2019
|
-
|
|
3665
|
+
const task = ev.shiftKey ? taskOfRow(row) : void 0;
|
|
3666
|
+
if (task) runTask(task, row.querySelector(".runbtn") ?? void 0);
|
|
3667
|
+
else copyRow(row);
|
|
2020
3668
|
return;
|
|
2021
3669
|
}
|
|
2022
3670
|
const step = ev.key === "ArrowDown" ? 1 : ev.key === "ArrowUp" ? -1 : 0;
|
|
@@ -2031,12 +3679,24 @@ function wireInput() {
|
|
|
2031
3679
|
next.scrollIntoView({ block: "nearest" });
|
|
2032
3680
|
});
|
|
2033
3681
|
document.addEventListener("keydown", (e) => {
|
|
3682
|
+
const typing = e.target?.closest?.("input, textarea") != null;
|
|
2034
3683
|
if (e.key === "/" && document.activeElement !== $("q")) {
|
|
2035
3684
|
e.preventDefault();
|
|
2036
3685
|
$("q").focus();
|
|
2037
3686
|
$("q").select();
|
|
2038
3687
|
return;
|
|
2039
3688
|
}
|
|
3689
|
+
if (e.key === "?" && !typing && !$("help").open) {
|
|
3690
|
+
e.preventDefault();
|
|
3691
|
+
openHelp();
|
|
3692
|
+
return;
|
|
3693
|
+
}
|
|
3694
|
+
if (e.key === "Escape" && $("filtersbtn").getAttribute("aria-expanded") === "true") {
|
|
3695
|
+
e.preventDefault();
|
|
3696
|
+
setFiltersOpen(false);
|
|
3697
|
+
$("filtersbtn").focus();
|
|
3698
|
+
return;
|
|
3699
|
+
}
|
|
2040
3700
|
if (e.key !== "Escape") return;
|
|
2041
3701
|
const menu = document.getElementById("pickmenu");
|
|
2042
3702
|
const picker = document.getElementById("pickerhost");
|
|
@@ -2054,15 +3714,14 @@ function wireInput() {
|
|
|
2054
3714
|
resizeTimer = setTimeout(render, 60);
|
|
2055
3715
|
});
|
|
2056
3716
|
window.addEventListener("focus", () => {
|
|
2057
|
-
if (polling) load(
|
|
3717
|
+
if (polling) load({ join: true });
|
|
2058
3718
|
});
|
|
2059
3719
|
pollTimer = setInterval(() => {
|
|
2060
|
-
if (polling && !document.hidden) load(
|
|
3720
|
+
if (polling && !document.hidden) load({ join: true });
|
|
2061
3721
|
}, 15e3);
|
|
2062
3722
|
const q = $("q");
|
|
2063
3723
|
q.title = q.placeholder;
|
|
2064
3724
|
q.setAttribute("aria-label", q.placeholder);
|
|
2065
|
-
q.placeholder = "Search commands";
|
|
2066
3725
|
for (const id of ["mode", "depth"]) rovingGroup($(id));
|
|
2067
3726
|
rovingGroup($("tabs"), "button[data-runner]");
|
|
2068
3727
|
}
|
|
@@ -2074,13 +3733,14 @@ function wireInput() {
|
|
|
2074
3733
|
* be reported as a copy. Returns whether the write succeeded.
|
|
2075
3734
|
*/
|
|
2076
3735
|
async function copyCommand(copy) {
|
|
2077
|
-
|
|
3736
|
+
const text = copy.dataset.run;
|
|
3737
|
+
let ok = text !== void 0;
|
|
2078
3738
|
try {
|
|
2079
|
-
await navigator.clipboard.writeText(
|
|
3739
|
+
if (text !== void 0) await navigator.clipboard.writeText(text);
|
|
2080
3740
|
} catch {
|
|
2081
3741
|
ok = false;
|
|
2082
3742
|
}
|
|
2083
|
-
copy.textContent = ok ? "copied" : "blocked";
|
|
3743
|
+
copy.textContent = ok ? "copied" : text === void 0 ? "refused" : "blocked";
|
|
2084
3744
|
if (ok) copy.classList.add("done");
|
|
2085
3745
|
setTimeout(() => {
|
|
2086
3746
|
copy.textContent = "copy";
|
|
@@ -2235,66 +3895,56 @@ function rovingGroup(container, selector = "button") {
|
|
|
2235
3895
|
if (rebuilt !== void 0 && rebuilt !== document.activeElement) rebuilt.focus();
|
|
2236
3896
|
});
|
|
2237
3897
|
}
|
|
2238
|
-
/**
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
name: "System",
|
|
2249
|
-
note: " (follows your OS)"
|
|
2250
|
-
},
|
|
2251
|
-
light: {
|
|
2252
|
-
glyph: "☀",
|
|
2253
|
-
name: "Light",
|
|
2254
|
-
note: ""
|
|
2255
|
-
},
|
|
2256
|
-
dark: {
|
|
2257
|
-
glyph: "☾",
|
|
2258
|
-
name: "Dark",
|
|
2259
|
-
note: ""
|
|
2260
|
-
}
|
|
2261
|
-
};
|
|
2262
|
-
/**
|
|
2263
|
-
* Update the theme button for the choice now in use.
|
|
2264
|
-
*
|
|
2265
|
-
* The button shows the current scheme, so both the title and the accessible
|
|
2266
|
-
* name must say two things: what is on, and what a click does next. A single
|
|
2267
|
-
* cycling button has nowhere else to say the second, and a screen-reader user
|
|
2268
|
-
* would otherwise not know what the press does. Startup calls this too, so
|
|
2269
|
-
* the button matches the restored preference from the first frame.
|
|
2270
|
-
*/
|
|
2271
|
-
function setThemeButton(choice) {
|
|
2272
|
-
const btn = $("theme");
|
|
2273
|
-
const face = THEME_FACE[choice] ?? THEME_FACE["system"];
|
|
2274
|
-
const next = THEME_FACE[THEME_CYCLE[choice] ?? "light"];
|
|
2275
|
-
btn.dataset.themeChoice = choice;
|
|
2276
|
-
btn.textContent = face.glyph;
|
|
2277
|
-
btn.title = "Colour scheme: " + face.name + face.note + ". Click for " + next.name + ".";
|
|
2278
|
-
btn.setAttribute("aria-label", "Colour scheme: " + face.name + ". Click for " + next.name + ".");
|
|
3898
|
+
/** Open the help at its top, with the page's own text. */
|
|
3899
|
+
function openHelp() {
|
|
3900
|
+
$("help-body").innerHTML = helpHtml();
|
|
3901
|
+
openDialogAtTop("help");
|
|
3902
|
+
}
|
|
3903
|
+
/** Open or close the Filters menu, which holds the filters at phone width. */
|
|
3904
|
+
function setFiltersOpen(open) {
|
|
3905
|
+
$("filtersbtn").setAttribute("aria-expanded", String(open));
|
|
3906
|
+
$("filters").classList.toggle("open", open);
|
|
3907
|
+
measureChrome();
|
|
2279
3908
|
}
|
|
2280
3909
|
//#endregion
|
|
2281
3910
|
//#region src/web/main.ts
|
|
2282
3911
|
/**
|
|
2283
|
-
* Startup only:
|
|
2284
|
-
* first frame. Rendering, data loading and event handling live in
|
|
2285
|
-
* `api.ts` and `input.ts`. This module starts them in the order
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
3912
|
+
* Startup only: sign in, read the preferences, attach every listener, draw
|
|
3913
|
+
* the first frame. Rendering, data loading and event handling live in
|
|
3914
|
+
* `view.ts`, `api.ts` and `input.ts`. This module starts them in the order
|
|
3915
|
+
* the page needs.
|
|
3916
|
+
*/
|
|
3917
|
+
async function start() {
|
|
3918
|
+
const url = new URL(location.href);
|
|
3919
|
+
const boot = url.searchParams.get("boot");
|
|
3920
|
+
if (boot !== null) {
|
|
3921
|
+
url.searchParams.delete("boot");
|
|
3922
|
+
history.replaceState(null, "", url.pathname + url.search + url.hash);
|
|
3923
|
+
}
|
|
3924
|
+
if (!(signedIn() && (boot === null || await tokenWorks()) || boot !== null && await signIn(boot))) {
|
|
3925
|
+
showSignedOut();
|
|
3926
|
+
return;
|
|
3927
|
+
}
|
|
3928
|
+
const theme = document.documentElement.getAttribute("data-theme");
|
|
3929
|
+
setThemeButton(theme === "light" || theme === "dark" ? theme : "system");
|
|
3930
|
+
wireInput();
|
|
3931
|
+
measureChrome();
|
|
3932
|
+
$("q").focus();
|
|
3933
|
+
const config = readConfig().then((config) => {
|
|
3934
|
+
const order = settingValue(config, "runners.order");
|
|
3935
|
+
if (Array.isArray(order)) state.runnerOrder = order.filter((r) => typeof r === "string");
|
|
3936
|
+
state.runnerOrderSource = settingSource(config, "runners.order");
|
|
3937
|
+
});
|
|
3938
|
+
await Promise.all([
|
|
3939
|
+
config,
|
|
3940
|
+
load({ cached: true }),
|
|
3941
|
+
loadTools()
|
|
3942
|
+
]);
|
|
3943
|
+
if (!signedIn()) return;
|
|
3944
|
+
if (state.catalog?.source !== "fresh") await load({
|
|
3945
|
+
join: true,
|
|
3946
|
+
progress: true
|
|
3947
|
+
});
|
|
3948
|
+
}
|
|
3949
|
+
start();
|
|
2300
3950
|
//#endregion
|