@osdlc/wayfinder 0.8.0 → 0.11.1

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +100 -0
  2. package/CONTRIBUTING.md +6 -1
  3. package/README.md +31 -11
  4. package/dist/args.d.ts +7 -8
  5. package/dist/args.js +7 -8
  6. package/dist/catalog.d.ts +26 -3
  7. package/dist/catalog.js +65 -12
  8. package/dist/clean-command.d.ts +3 -1
  9. package/dist/clean-command.js +23 -11
  10. package/dist/cli.js +3 -3
  11. package/dist/commands/browse.js +4 -2
  12. package/dist/commands/index.js +1 -1
  13. package/dist/commands/list.d.ts +21 -2
  14. package/dist/commands/list.js +85 -9
  15. package/dist/commands/query.js +1 -1
  16. package/dist/commands/run.js +1 -1
  17. package/dist/commands/shared.js +2 -1
  18. package/dist/config-keys.d.ts +4 -0
  19. package/dist/config-keys.js +4 -0
  20. package/dist/config.d.ts +24 -9
  21. package/dist/config.js +64 -18
  22. package/dist/core/run.d.ts +2 -1
  23. package/dist/core/run.js +10 -2
  24. package/dist/core/saved-view.d.ts +2 -7
  25. package/dist/core/saved-view.js +5 -12
  26. package/dist/core/session.d.ts +32 -6
  27. package/dist/core/session.js +86 -36
  28. package/dist/core/writes.d.ts +13 -0
  29. package/dist/core/writes.js +22 -0
  30. package/dist/document-schemas.generated.js +6 -0
  31. package/dist/documents.d.ts +90 -1
  32. package/dist/documents.js +39 -12
  33. package/dist/guide.js +2 -2
  34. package/dist/index.d.ts +8 -2
  35. package/dist/index.js +8 -5
  36. package/dist/providers-command.d.ts +2 -2
  37. package/dist/schema.d.ts +1 -1
  38. package/dist/schema.js +1 -1
  39. package/dist/serve/auth.js +3 -16
  40. package/dist/serve/catalog-share.d.ts +13 -1
  41. package/dist/serve/catalog-share.js +42 -3
  42. package/dist/serve/index.d.ts +5 -3
  43. package/dist/serve/index.js +20 -12
  44. package/dist/serve/routes.d.ts +1 -1
  45. package/dist/serve/routes.js +1 -26
  46. package/dist/terminal-text.d.ts +4 -4
  47. package/dist/terminal-text.js +17 -12
  48. package/dist/tool-info.d.ts +2 -2
  49. package/dist/tools.js +1 -1
  50. package/dist/tui/app.d.ts +15 -2
  51. package/dist/tui/app.js +189 -43
  52. package/dist/tui/index.js +3 -3
  53. package/dist/vocabulary.d.ts +7 -1
  54. package/dist/vocabulary.js +5 -1
  55. package/dist/web/main.js +345 -59
  56. package/dist/web/page.html +2 -0
  57. package/dist/web/styles.css +56 -0
  58. package/dist/xdg.d.ts +0 -7
  59. package/dist/xdg.js +0 -14
  60. package/package.json +16 -14
  61. package/schema/config.json +14 -1
package/dist/web/main.js CHANGED
@@ -36,6 +36,11 @@ const state = {
36
36
  knownRunners: /* @__PURE__ */ new Set(),
37
37
  checkedAt: Date.now(),
38
38
  loading: false,
39
+ live: false,
40
+ pending: [],
41
+ expected: 0,
42
+ order: [],
43
+ loadStarted: 0,
39
44
  trustable: false,
40
45
  cache: [],
41
46
  unknowns: [],
@@ -130,6 +135,7 @@ function commandString(argv, opts = {}) {
130
135
  case "posix": {
131
136
  const line = shellJoin(argv);
132
137
  if (cwd === void 0) return line;
138
+ if (cwd === "-") return `cd ./- && ${line}`;
133
139
  return `cd ${cwd.startsWith("-") ? "-- " : ""}${shellQuote(cwd)} && ${line}`;
134
140
  }
135
141
  case "powershell": {
@@ -212,9 +218,9 @@ function cmdCommand(command) {
212
218
  * probe cost is a rough estimate, and `1.4s` is easier to read than `1423ms`.
213
219
  */
214
220
  function humanMs(ms) {
215
- if (ms < 1e3) return `${Math.round(ms)}ms`;
216
- if (ms < 1e4) return `${(ms / 1e3).toFixed(1)}s`;
217
- if (ms < 6e4) return `${Math.round(ms / 1e3)}s`;
221
+ if (Math.round(ms) < 1e3) return `${Math.round(ms)}ms`;
222
+ if (ms < 9950) return `${(ms / 1e3).toFixed(1)}s`;
223
+ if (Math.round(ms / 1e3) < 60) return `${Math.round(ms / 1e3)}s`;
218
224
  return `${Math.round(ms / 6e4)}m`;
219
225
  }
220
226
  /**
@@ -228,30 +234,17 @@ function humanMs(ms) {
228
234
  */
229
235
  function humanAge(ms) {
230
236
  if (ms === void 0) return "of unknown age";
231
- if (ms < 6e4) return `${Math.max(1, Math.round(ms / 1e3))}s old`;
232
- if (ms < 36e5) return `${Math.round(ms / 6e4)}m old`;
233
- if (ms < 864e5) return `${Math.round(ms / 36e5)}h old`;
237
+ const seconds = Math.max(1, Math.round(ms / 1e3));
238
+ if (seconds < 60) return `${seconds}s old`;
239
+ const minutes = Math.round(ms / 6e4);
240
+ if (minutes < 60) return `${minutes}m old`;
241
+ const hours = Math.round(ms / 36e5);
242
+ if (hours < 24) return `${hours}h old`;
234
243
  return `${Math.round(ms / 864e5)}d old`;
235
244
  }
236
245
  //#endregion
237
246
  //#region ../system-model/dist/match.js
238
247
  /**
239
- * Ranked search over catalog entries. Both views use this one matcher.
240
- *
241
- * Every view of this catalog must agree on what a query means. Otherwise the
242
- * same query ranks differently depending on which view you use. The terminal
243
- * UI imports it directly. The web view loads it transpiled for the browser.
244
- * That is why it has its own `./match` export subpath, and why it must not use
245
- * the DOM or Node built-ins. Importing anything from `node:fs` here breaks the
246
- * browser build.
247
- *
248
- * Query language:
249
- * - terms are whitespace-separated and ANDed; every term must match a field
250
- * - a leading `'` forces that term to match as a substring, fzf-style
251
- * - `mode: "exact"` forces every term to, without the prefix
252
- * - matching is case-insensitive throughout
253
- */
254
- /**
255
248
  * Case-insensitive subsequence match. Consecutive characters and matches at a
256
249
  * word boundary score higher, so "ddev" ranks "determined:dev" above an
257
250
  * incidental scatter of those letters.
@@ -425,6 +418,38 @@ function filterTasks(reports, filter = {}) {
425
418
  return hits;
426
419
  }
427
420
  //#endregion
421
+ //#region ../ux/dist/text.js
422
+ /**
423
+ * Bidirectional controls, which reorder the text around them: the marks ALM,
424
+ * LRM and RLM, and the embeddings, overrides and isolates. A character-class
425
+ * body.
426
+ */
427
+ const BIDI = "\\u061c\\u200e\\u200f\\u202a-\\u202e\\u2066-\\u2069";
428
+ new RegExp(`[\\u0000-\\u001f\\u007f-\\u009f${BIDI}]`);
429
+ /** The C0 class body for each choice of kept tab and line feed. */
430
+ function c0Class(options) {
431
+ const tab = options.tab === true;
432
+ const newline = options.newline === true;
433
+ if (tab && newline) return "\\u0000-\\u0008\\u000b-\\u001f";
434
+ if (tab) return "\\u0000-\\u0008\\u000a-\\u001f";
435
+ if (newline) return "\\u0000-\\u0009\\u000b-\\u001f";
436
+ return "\\u0000-\\u001f";
437
+ }
438
+ /**
439
+ * A global `RegExp` that matches, one character at a time, every control
440
+ * character {@link stripControls} removes with the same `options`: C0 (a tab
441
+ * or line feed kept by `options` excepted; a carriage return always
442
+ * matches), DEL, C1 and the bidirectional controls.
443
+ *
444
+ * It does not know escape sequences, so it matches only the ESC or C1
445
+ * introducer of one, not the rest. For a filter that must keep the text's
446
+ * length, such as one that replaces each control with U+FFFD so offsets into
447
+ * the text stay valid.
448
+ */
449
+ function controlPattern(options = {}) {
450
+ return new RegExp(`[${c0Class(options)}\\u007f-\\u009f${BIDI}]`, "g");
451
+ }
452
+ //#endregion
428
453
  //#region src/app.ts
429
454
  /**
430
455
  * The app's names. Every user-facing name that carries the product name
@@ -439,9 +464,12 @@ const APP = "wayfinder";
439
464
  * C0 (tab and newline included), DEL, C1, and the bidi controls: the marks
440
465
  * U+061C, U+200E and U+200F, and U+202A-202E and U+2066-2069.
441
466
  */
442
- const CONTROL = /[\u0000-\u001f\u007f-\u009f\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g;
467
+ const CONTROL = controlPattern();
443
468
  /** 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;
469
+ const CONTROL_KEEP_LINES = controlPattern({
470
+ newline: true,
471
+ tab: true
472
+ });
445
473
  const REPLACEMENT = "�";
446
474
  /**
447
475
  * `text` with every C0 control character (ESC included), DEL, C1 control
@@ -610,6 +638,8 @@ function groupOf(runner) {
610
638
  *
611
639
  * Browser-safe: no Node built-in, so the page imports it.
612
640
  */
641
+ /** How long a refresh runs before the status names the runners it still waits on. */
642
+ const WAITING_AFTER_MS = 3e3;
613
643
  /** What one row is called on every surface. */
614
644
  const TASK_NOUN = {
615
645
  one: "task",
@@ -1144,12 +1174,24 @@ function buildTree(rows) {
1144
1174
  }
1145
1175
  return root;
1146
1176
  }
1147
- function renderNode(node, prefix) {
1177
+ /**
1178
+ * The tree under `node`. `loading` names runners still loading; the combined
1179
+ * index's top level shows a row for each in the place its group will take.
1180
+ */
1181
+ function renderNode(node, prefix, loading = []) {
1148
1182
  let html = "";
1149
1183
  const order = runnerOrder();
1150
1184
  const topLevel = treeStart() === 0 && prefix.length === 0;
1151
- const groups = [...node.kids.entries()].sort((a, b) => topLevel ? order.indexOf(a[0]) - order.indexOf(b[0]) : a[0].localeCompare(b[0]));
1185
+ const groups = [...node.kids.entries()];
1186
+ if (topLevel) {
1187
+ for (const r of loading) if (!node.kids.has(r)) groups.push([r, null]);
1188
+ }
1189
+ groups.sort((a, b) => topLevel ? order.indexOf(a[0]) - order.indexOf(b[0]) : a[0].localeCompare(b[0]));
1152
1190
  for (const [seg, kid] of groups) {
1191
+ if (kid === null) {
1192
+ html += loadingRow(seg);
1193
+ continue;
1194
+ }
1153
1195
  const key = prefix.concat(seg).join(" ");
1154
1196
  const collapsed = state.collapsed.has(key);
1155
1197
  const depth = prefix.length;
@@ -1519,7 +1561,8 @@ let skillCounts = {
1519
1561
  * not in the order keeps its catalog place after the ones that are.
1520
1562
  */
1521
1563
  function runnerOrder() {
1522
- const present = (state.catalog?.reports || []).map((r) => r.runner);
1564
+ const reported = (state.catalog?.reports || []).map((r) => r.runner);
1565
+ const present = state.live ? [...state.order, ...reported.filter((r) => !state.order.includes(r))] : reported;
1523
1566
  const saved = state.runnerOrder.filter((r) => present.includes(r));
1524
1567
  const unsaved = present.filter((r) => !saved.includes(r));
1525
1568
  return [...saved, ...unsaved].sort((a, b) => groupRank(a) - groupRank(b));
@@ -1655,10 +1698,32 @@ function keepSelectedTabInView() {
1655
1698
  function hasInfo(runner) {
1656
1699
  return chainOf(runner).length > 0 || toolInfo(runner) !== void 0;
1657
1700
  }
1701
+ /** The runners the first probe will report but has not answered with rows, in display order. */
1702
+ function stillLoading(reports) {
1703
+ if (!state.live) return [];
1704
+ const answered = new Set(reports.map((r) => r.runner));
1705
+ return runnerOrder().filter((r) => !answered.has(r));
1706
+ }
1707
+ /**
1708
+ * A quiet tab for a runner still loading, in the place its tab will take.
1709
+ * It is not a button: there is nothing to select yet.
1710
+ */
1711
+ function loadingTab(r) {
1712
+ return "<span class=\"tab tab-loading\" aria-busy=\"true\" title=\"" + escapeHtml(runnerLabel(r)) + " is loading\">" + escapeHtml(runnerLabel(r)) + "<span class=\"spinner\" aria-hidden=\"true\"></span></span>";
1713
+ }
1714
+ /** A row for a runner still loading. */
1715
+ function loadingRow(r) {
1716
+ return "<div class=\"loading-row\" aria-busy=\"true\"><span class=\"spinner\" aria-hidden=\"true\"></span>" + escapeHtml(runnerLabel(r)) + " <span class=\"muted\">loading…</span></div>";
1717
+ }
1718
+ /** A row for each runner still loading, for the views that are not the tree. */
1719
+ function loadingRows(runners) {
1720
+ if (runners.length === 0) return "";
1721
+ return "<div class=\"loading-rows\">" + runners.map(loadingRow).join("") + "</div>";
1722
+ }
1658
1723
  function render() {
1659
1724
  const cat = state.catalog;
1660
1725
  if (!cat) {
1661
- $("out").innerHTML = "<div class=\"empty\">Loading...</div>";
1726
+ $("out").innerHTML = "<div class=\"empty\">Loading…</div>";
1662
1727
  return;
1663
1728
  }
1664
1729
  const main = $("out");
@@ -1672,27 +1737,42 @@ function render() {
1672
1737
  }
1673
1738
  const skillsTotal = cat.skills?.length ?? 0;
1674
1739
  if (state.runner === "@skills" ? skillsTotal === 0 : state.runner !== "all" && !enabled.has(state.runner)) state.runner = "all";
1675
- const on = runnerOrder().map((id) => cat.reports.find((s) => s.runner === id)).filter((s) => s !== void 0 && enabled.has(s.runner));
1740
+ const byOrder = runnerOrder();
1741
+ const loadingSet = new Set(stillLoading(cat.reports));
1742
+ const on = byOrder.map((id) => cat.reports.find((s) => s.runner === id)).filter((s) => s !== void 0 && enabled.has(s.runner));
1676
1743
  const total = on.reduce((n, s) => n + s.tasks.length, 0);
1677
1744
  const anyError = on.some((s) => s.status === "error");
1678
1745
  const foldable = on.filter((s) => s.tasks.length === 0 && s.status !== "error" && !s.skippedForExec && !(s.diagnostics || []).some((d) => d.severity === "warning") && s.runner !== state.runner);
1679
- const shown = on.filter((s) => !foldable.includes(s));
1680
1746
  const tabs = [{
1681
1747
  runner: "all",
1682
1748
  count: total,
1683
1749
  error: anyError,
1684
- exec: false
1685
- }].concat(shown.map((s) => ({
1686
- runner: s.runner,
1687
- count: s.tasks.length,
1688
- error: s.status === "error",
1689
- exec: s.skippedForExec
1690
- })));
1750
+ exec: false,
1751
+ loading: false
1752
+ }].concat(byOrder.flatMap((id) => {
1753
+ if (loadingSet.has(id)) return [{
1754
+ runner: id,
1755
+ count: 0,
1756
+ error: false,
1757
+ exec: false,
1758
+ loading: true
1759
+ }];
1760
+ const s = on.find((r) => r.runner === id);
1761
+ if (s === void 0 || foldable.includes(s)) return [];
1762
+ return [{
1763
+ runner: s.runner,
1764
+ count: s.tasks.length,
1765
+ error: s.status === "error",
1766
+ exec: s.skippedForExec,
1767
+ loading: false
1768
+ }];
1769
+ }));
1691
1770
  const chainOfRunner = (id) => cat.reports.find((r) => r.runner === id)?.chain ?? [];
1692
1771
  $("tabs").innerHTML = tabs.map((t, i) => {
1693
1772
  const prev = tabs[i - 1];
1694
1773
  const group = groupOf(t.runner);
1695
1774
  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>" : "";
1775
+ if (t.loading) return header + loadingTab(t.runner);
1696
1776
  const shape = chainOfRunner(t.runner).map((c, i) => i === 0 ? runnerLabel(t.runner) : c.label).join(" › ");
1697
1777
  const draggable = t.runner !== "all" ? " draggable=\"true\"" : "";
1698
1778
  const tip = t.exec ? shape ? shape + ". " + execNote(t.runner) : execNote(t.runner) : shape;
@@ -1738,9 +1818,11 @@ function render() {
1738
1818
  html += "<div class=\"" + label + "\">" + escapeHtml(sec.runner) + ": " + escapeHtml(d.message) + (d.source ? "\n" + escapeHtml(d.source) : "") + "</div>";
1739
1819
  }
1740
1820
  const onSkills = state.runner === SKILLS;
1821
+ const loading = state.runner === "all" ? stillLoading(cat.reports) : [];
1822
+ let inTree = false;
1741
1823
  if (rows.length === 0 && skills.length === 0) {
1742
1824
  const noun = onSkills ? SKILL_NOUN.one : TASK_NOUN.one;
1743
- html += "<div class=\"empty\">" + (inScope || skillCounts.total ? "No " + noun + " matches." : "Nothing collected.") + "</div>";
1825
+ if (loading.length === 0) html += "<div class=\"empty\">" + (inScope || skillCounts.total ? "No " + noun + " matches." : "Nothing collected.") + "</div>";
1744
1826
  } else if (terms$1.length) {
1745
1827
  const hits = [...rows.map((r) => ({
1746
1828
  score: r.score,
@@ -1752,7 +1834,11 @@ function render() {
1752
1834
  hits.sort((a, b) => b.score - a.score);
1753
1835
  html += "<table>" + colgroup(0) + "<tbody>" + hits.slice(0, 400).map((h) => h.html()).join("") + "</tbody></table>";
1754
1836
  } else if (onSkills) html += skillTable(skills, 0);
1755
- else html += renderNode(buildTree(rows), []) + (skills.length > 0 ? skillsNode(skills) : "");
1837
+ else {
1838
+ inTree = true;
1839
+ html += renderNode(buildTree(rows), [], loading) + (skills.length > 0 ? skillsNode(skills) : "");
1840
+ }
1841
+ if (!inTree) html += loadingRows(loading);
1756
1842
  const focusWasInList = $("out").contains(document.activeElement);
1757
1843
  $("out").innerHTML = html;
1758
1844
  markEnterTarget();
@@ -2057,6 +2143,29 @@ function renderTrustBar() {
2057
2143
  host.innerHTML = html;
2058
2144
  host.hidden = html === "";
2059
2145
  }
2146
+ /** Say `text` to a screen reader, through the page's one polite live region. */
2147
+ function announce(text) {
2148
+ $("announce").textContent = text;
2149
+ }
2150
+ /** The counts the status line showed last, for {@link refreshStatus}. */
2151
+ let lastCounts = {
2152
+ shown: 0,
2153
+ total: 0
2154
+ };
2155
+ /** The status line again with the counts it showed last: a load started or ended. */
2156
+ function refreshStatus() {
2157
+ renderStatus(lastCounts.shown, lastCounts.total);
2158
+ }
2159
+ /** What the status line says about a probe running: what is still loading, or that it refreshes. */
2160
+ function loadingText() {
2161
+ if (state.live) {
2162
+ if (state.expected < 0) return "detecting the project…";
2163
+ if (state.pending.length === 0) return "loading…";
2164
+ return "loading " + state.pending.length + " of " + state.expected + ": " + escapeHtml(state.pending.map(runnerLabel).join(", "));
2165
+ }
2166
+ if (!state.loading) return "";
2167
+ return " - refreshing…" + (state.pending.length > 0 && Date.now() - state.loadStarted >= 3e3 ? " waiting on " + escapeHtml(state.pending.map(runnerLabel).join(", ")) : "");
2168
+ }
2060
2169
  /**
2061
2170
  * Kept separate from the table so an unchanged poll can update the clock
2062
2171
  * without touching the table. Otherwise Refresh on an unchanged repo would
@@ -2064,8 +2173,12 @@ function renderTrustBar() {
2064
2173
  * it is.
2065
2174
  */
2066
2175
  function renderStatus(shown, total) {
2176
+ lastCounts = {
2177
+ shown,
2178
+ total
2179
+ };
2067
2180
  const errs = (state.catalog?.reports || []).filter((s) => s.status === "error").map((s) => s.runner);
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 &middot; <kbd>?</kbd> all keys</span>" : "<span class=\"keyhint\"><kbd>Enter</kbd> copy &middot; <kbd>Shift+Enter</kbd> run &middot; <kbd>?</kbd> all keys</span>");
2181
+ $("status").innerHTML = "<span>" + (state.runner === "@skills" ? skillCounts.shown + " of " + escapeHtml(countSkills(skillCounts.total)) : shown + " of " + escapeHtml(countTasks(total)) + (state.runner === "all" ? ", all runners" : " in " + escapeHtml(runnerLabel(state.runner))) + (skillCounts.total > 0 ? ", " + skillCounts.shown + " of " + escapeHtml(countSkills(skillCounts.total)) : "")) + "</span>" + (state.live ? "<span class=\"loading-note\">" + loadingText() + "</span>" : "<span>checked " + new Date(state.checkedAt).toLocaleTimeString() + loadingText() + "</span>") + cacheSpan(state.cache) + (errs.length ? "<span class=\"err\">probe failed: " + escapeHtml(errs.map(runnerLabel).join(", ")) + "</span>" : "") + (state.runner === "@skills" ? "<span class=\"keyhint\"><kbd>Enter</kbd> copy /name &middot; <kbd>?</kbd> all keys</span>" : "<span class=\"keyhint\"><kbd>Enter</kbd> copy &middot; <kbd>Shift+Enter</kbd> run &middot; <kbd>?</kbd> all keys</span>");
2069
2182
  }
2070
2183
  /**
2071
2184
  * The run bar: enter a task's arguments before handing over the terminal.
@@ -2275,6 +2388,8 @@ const THEME_VALUES = [
2275
2388
  "light",
2276
2389
  "dark"
2277
2390
  ];
2391
+ /** The `open` values: what the bare `way` command opens. */
2392
+ const OPEN_VALUES = ["tui", "web"];
2278
2393
  /**
2279
2394
  * The keys `config set` and `config unset` change from the command line only.
2280
2395
  * cli-tool's adapters, such as the HTTP one the web view's server runs,
@@ -2307,6 +2422,15 @@ function settingLayer(key, source) {
2307
2422
  }
2308
2423
  //#endregion
2309
2424
  //#region src/web/api.ts
2425
+ /**
2426
+ * The page's calls to the server. Every action but Run is a command of the
2427
+ * tree, sent to `POST /api/commands/<command>` with a JSON body of its flags
2428
+ * and positionals, exactly as `way <command> --json` would run it. Run is
2429
+ * `POST /run`, which resolves the task with `way run --dry-run`. Which
2430
+ * command each action is lives in `../actions.ts`, where a test checks it.
2431
+ */
2432
+ /** The media type of a streamed answer: one JSON line per event, then the document. */
2433
+ const NDJSON = "application/x-ndjson";
2310
2434
  /** Where the bearer token is kept for this tab. */
2311
2435
  const TOKEN_KEY = `${APP}.token`;
2312
2436
  /**
@@ -2387,17 +2511,53 @@ function authHeaders(extra = {}) {
2387
2511
  return headers;
2388
2512
  }
2389
2513
  /**
2514
+ * Read an NDJSON body: each line of the events' kind goes to `events` as it
2515
+ * comes, and the other line, the document or the error, is the result. Null
2516
+ * when the stream ends without one.
2517
+ */
2518
+ async function readLines(body, events) {
2519
+ const reader = body.getReader();
2520
+ const decoder = new TextDecoder();
2521
+ let buffered = "";
2522
+ let last = null;
2523
+ const take = (text) => {
2524
+ if (text.trim() === "") return;
2525
+ const line = JSON.parse(text);
2526
+ if (line["kind"] === events.kind) events.on(line);
2527
+ else last = line;
2528
+ };
2529
+ try {
2530
+ for (;;) {
2531
+ const { done, value } = await reader.read();
2532
+ if (done) break;
2533
+ buffered += decoder.decode(value, { stream: true });
2534
+ let at;
2535
+ while ((at = buffered.indexOf("\n")) !== -1) {
2536
+ take(buffered.slice(0, at));
2537
+ buffered = buffered.slice(at + 1);
2538
+ }
2539
+ }
2540
+ take(buffered + decoder.decode());
2541
+ } catch {
2542
+ return null;
2543
+ }
2544
+ return last;
2545
+ }
2546
+ /**
2390
2547
  * Run `way <words...>` with `args`, the JSON form of its flags and
2391
- * positionals. `confirm` is the nonce of a confirmed 428.
2548
+ * positionals. `confirm` is the nonce of a confirmed 428. With `events`,
2549
+ * the answer streams as NDJSON: each event line goes to `events.on` as it
2550
+ * comes, and the document is the last line.
2392
2551
  */
2393
- async function call(words, args = {}, confirm) {
2552
+ async function call(words, args = {}, confirm, events) {
2394
2553
  let res;
2395
2554
  try {
2396
2555
  res = await fetch("/api/commands/" + words.map(encodeURIComponent).join("/"), {
2397
2556
  method: "POST",
2398
2557
  headers: authHeaders({
2399
2558
  "content-type": "application/json",
2400
- ...confirm !== void 0 ? { "x-confirm": confirm } : {}
2559
+ ...confirm !== void 0 ? { "x-confirm": confirm } : {},
2560
+ ...events !== void 0 ? { accept: NDJSON } : {}
2401
2561
  }),
2402
2562
  body: JSON.stringify(args),
2403
2563
  cache: "no-store"
@@ -2410,6 +2570,25 @@ async function call(words, args = {}, confirm) {
2410
2570
  };
2411
2571
  }
2412
2572
  if (res.status === 401) signOut();
2573
+ if (events !== void 0 && res.ok && res.body !== null && (res.headers.get("content-type") ?? "").includes(NDJSON)) {
2574
+ const last = await readLines(res.body, events);
2575
+ if (last === null) return {
2576
+ ok: false,
2577
+ status: 0,
2578
+ message: "the server is gone"
2579
+ };
2580
+ if (last["kind"] !== "error") return {
2581
+ ok: true,
2582
+ doc: last
2583
+ };
2584
+ return {
2585
+ ok: false,
2586
+ status: 500,
2587
+ message: typeof last["message"] === "string" ? last["message"] : "the command failed",
2588
+ ...typeof last["hint"] === "string" ? { hint: last["hint"] } : {},
2589
+ ...typeof last["code"] === "string" ? { code: last["code"] } : {}
2590
+ };
2591
+ }
2413
2592
  const body = await res.json().catch(() => null);
2414
2593
  if (res.ok && body !== null) return {
2415
2594
  ok: true,
@@ -2451,7 +2630,9 @@ let busy = false;
2451
2630
  * slowest runner takes seconds. `join` lets the answer be a probe the server
2452
2631
  * is already running, for the first fresh read and the polls. Without it (a
2453
2632
  * 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
2633
+ * answer is never from before the click. Progress streams with nothing on
2634
+ * screen, for a plain load, and with `progress`; a joining poll asks for none,
2635
+ * since each line carries a full report. A load asked for while one runs
2455
2636
  * runs after it, so a Refresh during a poll is not lost, and its promise
2456
2637
  * settles only once that later read has run.
2457
2638
  *
@@ -2482,15 +2663,111 @@ async function load(opts = {}) {
2482
2663
  if (next !== null) load(next.opts).finally(next.resolve);
2483
2664
  }
2484
2665
  }
2666
+ /**
2667
+ * One progress line of a probe. While nothing else is on screen, the runner
2668
+ * that answered, or the skills, join the catalog and the page draws them;
2669
+ * otherwise only the count of runners still loading moves.
2670
+ */
2671
+ function onProgress(line) {
2672
+ const event = line;
2673
+ const first = state.expected < 0;
2674
+ state.pending = event.pending;
2675
+ state.expected = event.total;
2676
+ if (!state.live) {
2677
+ if (Date.now() - state.loadStarted >= 3e3) refreshStatus();
2678
+ return;
2679
+ }
2680
+ if (first) {
2681
+ state.order = [...event.pending];
2682
+ announce("loading " + countRunners(event.total));
2683
+ }
2684
+ const report = event.report;
2685
+ const base = state.catalog ?? {
2686
+ kind: "catalog",
2687
+ schemaVersion: 1,
2688
+ root: "",
2689
+ generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
2690
+ discovery: "git",
2691
+ allowExec: false,
2692
+ reports: [],
2693
+ cache: [],
2694
+ unknowns: [],
2695
+ skills: []
2696
+ };
2697
+ if (event.skills !== void 0) state.catalog = {
2698
+ ...base,
2699
+ skills: event.skills
2700
+ };
2701
+ else if (report === void 0) state.catalog = base;
2702
+ else {
2703
+ const others = (list) => (list ?? []).filter((r) => r.runner !== report.runner);
2704
+ const rank = (r) => {
2705
+ const at = state.order.indexOf(r.runner);
2706
+ return at === -1 ? state.order.length : at;
2707
+ };
2708
+ state.catalog = {
2709
+ ...base,
2710
+ reports: [...others(base.reports), report].sort((a, b) => rank(a) - rank(b)),
2711
+ cache: [...others(base.cache), ...event.cache ? [event.cache] : []],
2712
+ unknowns: [...others(base.unknowns), ...event.unknowns ?? []]
2713
+ };
2714
+ state.cache = state.catalog.cache ?? [];
2715
+ state.unknowns = state.catalog.unknowns ?? [];
2716
+ state.trustable = trustableFrom(state.unknowns);
2717
+ }
2718
+ scheduleRender();
2719
+ }
2720
+ /** Set while a render for progress lines waits, so a burst of lines draws once. */
2721
+ let renderQueued = false;
2722
+ /**
2723
+ * Draw the progress lines that arrived, once per 50 ms at most: a render
2724
+ * rebuilds every row, and runners often answer together. Skipped when the
2725
+ * load has ended, since its own render drew the whole answer.
2726
+ */
2727
+ function scheduleRender() {
2728
+ if (renderQueued) return;
2729
+ renderQueued = true;
2730
+ setTimeout(() => {
2731
+ renderQueued = false;
2732
+ if (state.live) render();
2733
+ }, 50);
2734
+ }
2735
+ /** How long a first load waits before it says Loading, so a held catalog shows with no flash. */
2736
+ const LOADING_AFTER_MS = 200;
2485
2737
  async function loadOnce(opts) {
2738
+ const live = state.catalog === null;
2739
+ const progress = live || opts.progress === true || opts.join !== true;
2486
2740
  const args = {
2487
2741
  ...opts.cached === true ? { cached: true } : {},
2488
- ...opts.join === true ? { join: true } : {}
2742
+ ...opts.join === true ? { join: true } : {},
2743
+ ...progress ? { progress: true } : {}
2489
2744
  };
2490
2745
  state.loading = true;
2491
- const result = await call(["list"], args);
2746
+ state.live = live;
2747
+ state.pending = [];
2748
+ state.expected = -1;
2749
+ state.order = [];
2750
+ state.loadStarted = Date.now();
2751
+ const timers = [setTimeout(() => {
2752
+ if (state.live && state.catalog === null) {
2753
+ render();
2754
+ refreshStatus();
2755
+ }
2756
+ }, LOADING_AFTER_MS), setTimeout(() => {
2757
+ if (state.loading && !state.live) refreshStatus();
2758
+ }, WAITING_AFTER_MS)];
2759
+ if (!live) refreshStatus();
2760
+ const result = await call(["list"], args, void 0, progress ? {
2761
+ kind: "catalog-progress",
2762
+ on: onProgress
2763
+ } : void 0);
2764
+ for (const timer of timers) clearTimeout(timer);
2492
2765
  state.loading = false;
2766
+ state.live = false;
2767
+ state.pending = [];
2768
+ state.order = [];
2493
2769
  if (!result.ok) {
2770
+ if (live) announce("loading failed");
2494
2771
  showError("refresh failed", result.status === 0 ? "the server is gone (is it still running?)" : failureText(result));
2495
2772
  return;
2496
2773
  }
@@ -2524,6 +2801,13 @@ async function loadOnce(opts) {
2524
2801
  state.fingerprint = fp;
2525
2802
  state.catalog = cat;
2526
2803
  render();
2804
+ if (live) announce(loadedText(cat));
2805
+ }
2806
+ /** What a screen reader hears when the first load ends. */
2807
+ function loadedText(cat) {
2808
+ const tasks = cat.reports.reduce((n, r) => n + r.tasks.length, 0);
2809
+ const failed = cat.reports.filter((r) => r.status === "error").length;
2810
+ return countTasks(tasks) + " loaded" + (failed > 0 ? ", " + failed + (failed === 1 ? " runner failed" : " runners failed") : "");
2527
2811
  }
2528
2812
  /** What the person is asked before a grant is sent. */
2529
2813
  const TRUST_QUESTION = "Trust this repository? Its runners will be read by running them, now and on every later visit, until you untrust it.";
@@ -2676,9 +2960,10 @@ async function requestRun(id, args = []) {
2676
2960
  })
2677
2961
  };
2678
2962
  }
2963
+ const argv = body?.argv;
2679
2964
  return {
2680
2965
  outcome: "handed-off",
2681
- command: body?.argv?.join(" ") || body?.display || "the task"
2966
+ command: argv !== void 0 && argv.length > 0 ? commandString(argv, { platform: serverPlatform() }) : body?.display || "the task"
2682
2967
  };
2683
2968
  }
2684
2969
  //#endregion
@@ -2821,7 +3106,7 @@ function excludedSection() {
2821
3106
  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>");
2822
3107
  }
2823
3108
  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"]));
3109
+ 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", OPEN_VALUES));
2825
3110
  }
2826
3111
  /** The settings the page may not write, each with the command that does. */
2827
3112
  function cliOnlySection() {
@@ -2976,10 +3261,6 @@ async function reload() {
2976
3261
  if (fresh !== null) loaded = fresh;
2977
3262
  repaint();
2978
3263
  }
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
3264
  /**
2984
3265
  * Write the staged edits, one `config set` each, and say what was written
2985
3266
  * where. A refused write stops there and keeps it and the edits after it
@@ -2998,7 +3279,7 @@ async function commit() {
2998
3279
  delete staged[key];
2999
3280
  if (key === "theme") applyTheme(value);
3000
3281
  }
3001
- const saved = [...written].map(([file, keys]) => "Saved " + listed(keys) + " to " + file + ".");
3282
+ const saved = [...written].map(([file, keys]) => "Saved " + listWords(keys) + " to " + file + ".");
3002
3283
  notice = failure === null ? {
3003
3284
  kind: "ok",
3004
3285
  text: saved.join(" ") || "Nothing to save."
@@ -3682,16 +3963,21 @@ async function start() {
3682
3963
  wireInput();
3683
3964
  measureChrome();
3684
3965
  $("q").focus();
3685
- const [config] = await Promise.all([
3686
- readConfig(),
3966
+ const config = readConfig().then((config) => {
3967
+ const order = settingValue(config, "runners.order");
3968
+ if (Array.isArray(order)) state.runnerOrder = order.filter((r) => typeof r === "string");
3969
+ state.runnerOrderSource = settingSource(config, "runners.order");
3970
+ });
3971
+ await Promise.all([
3972
+ config,
3687
3973
  load({ cached: true }),
3688
3974
  loadTools()
3689
3975
  ]);
3690
3976
  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 });
3977
+ if (state.catalog?.source !== "fresh") await load({
3978
+ join: true,
3979
+ progress: true
3980
+ });
3695
3981
  }
3696
3982
  start();
3697
3983
  //#endregion
@@ -10,6 +10,8 @@
10
10
  of counts and keyboard hints. -->
11
11
  <div class="trustbar" id="trustbar" hidden></div>
12
12
  <div class="status" id="status"></div>
13
+ <!-- One stable live region, so a screen reader hears when loading starts and ends. -->
14
+ <div class="sr-only" id="announce" aria-live="polite"></div>
13
15
  <header>
14
16
  <div class="searchrow">
15
17
  <div class="searchbox">