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