@osdlc/wayfinder 0.7.0 → 0.7.2

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/dist/tui.js CHANGED
@@ -1,21 +1,19 @@
1
1
  /**
2
- * The terminal UI — browse every task in a repository, and run one.
2
+ * The terminal UI: browse every task in a repository, and run one.
3
3
  *
4
- * The affordance a browser cannot have: Enter RUNS the selected task, in this
5
- * shell, with the terminal handed to it. A web view can only ever offer you
6
- * something to paste.
4
+ * Unlike the page, Enter runs the selected task in this shell and hands it the
5
+ * terminal. The page can only give you a command to paste.
7
6
  *
8
- * Dependency-free: raw mode, ANSI, and one frame string per keystroke. A TUI
9
- * toolkit would be a heavier dependency than the code it saves, and this has to
10
- * keep working from a checkout whose node_modules is the thing you are trying
11
- * to repair. The CLI routes its output through the `CliIo` seam so
12
- * `main()` is testable without touching a real stream, but this file writes
13
- * to `process.stdout` directly — owning the interactive terminal, raw mode,
14
- * the alternate screen, handing the terminal to a spawned task, is the whole
15
- * point of it, and that job is outside the seam by design.
7
+ * No dependencies: raw mode, ANSI, and one frame string per keystroke. A TUI
8
+ * toolkit would weigh more than the code it saves, and this has to keep
9
+ * working from a checkout whose node_modules is what you are trying to repair.
10
+ * The CLI sends its output through `CliIo` so `main()` can be tested without
11
+ * a real stream. This file writes to `process.stdout` directly, because its
12
+ * job is to control the terminal: raw mode, the alternate screen, and handing
13
+ * the terminal to a spawned task.
16
14
  *
17
- * Collection is asynchronous, which is what most of the state machinery below
18
- * is for: keystrokes arrive mid-refresh, and a row can be stale.
15
+ * Collection is async, which is what most of the state handling below is for:
16
+ * keystrokes arrive during a refresh, and a row can be stale.
19
17
  */
20
18
  import { spawnRunner, streamRunner } from '@osdlc/command-seam';
21
19
  import { tasks as allTasks, } from '@osdlc/system-model/detect';
@@ -29,6 +27,7 @@ import { collectAndCache, freshStates, fromStore, makeProject, orderedCatalog, r
29
27
  import { loadConfig } from "./config.js";
30
28
  import { appTrustStore } from "./trust-store.js";
31
29
  import { groupOf, runnerLabel } from "./groups.js";
30
+ import { terminalSafe } from "./terminal-text.js";
32
31
  // ---------------------------------------------------------------- ansi
33
32
  const ALT_ON = '\x1b[?1049h';
34
33
  const ALT_OFF = '\x1b[?1049l';
@@ -50,7 +49,9 @@ const hit = sgr('1;33');
50
49
  /**
51
50
  * Compose chunks into one line of exactly `width` columns. Truncation happens
52
51
  * on the PLAIN text — measuring a string that already carries escape sequences
53
- * counts the escapes as columns and wraps the line.
52
+ * counts the escapes as columns and wraps the line. Every chunk's text goes
53
+ * through {@link terminalSafe} first, so repository text never writes a
54
+ * control sequence; only `paint` adds escapes.
54
55
  */
55
56
  function line(chunks, width) {
56
57
  let used = 0;
@@ -58,7 +59,7 @@ function line(chunks, width) {
58
59
  for (const chunk of chunks) {
59
60
  if (used >= width)
60
61
  break;
61
- let text = chunk.text;
62
+ let text = terminalSafe(chunk.text);
62
63
  if (used + text.length > width)
63
64
  text = text.slice(0, Math.max(0, width - used - 1)) + '…';
64
65
  used += text.length;
@@ -71,10 +72,10 @@ const ALL = 'all';
71
72
  /**
72
73
  * The module singleton.
73
74
  *
74
- * Exported for one reason: `runTui` owns a real terminal and never returns, so
75
- * the selection rule — the thing that must survive a refresh reordering and
76
- * dropping rows underneath the cursor — is only testable through this and
77
- * { recompute}. Nothing outside a test writes to it.
75
+ * Exported for one reason. `runTui` takes over a real terminal and never
76
+ * returns, so the selection rule (the selection must survive a refresh that
77
+ * reorders or drops rows under the cursor) can only be tested through this
78
+ * and {@link recompute}. Nothing outside a test writes to it.
78
79
  */
79
80
  export const state = {
80
81
  catalog: null,
@@ -106,7 +107,7 @@ export const state = {
106
107
  function reportFor(runner) {
107
108
  return state.catalog?.reports.find((r) => r.runner === runner);
108
109
  }
109
- /** How many runners went uncollected for want of trust; 0 when trust is not the reason. */
110
+ /** How many runners were not collected for lack of trust; 0 when trust is not the reason. */
110
111
  function withheldForTrust() {
111
112
  if (state.gate?.reason !== 'untrusted')
112
113
  return 0;
@@ -126,15 +127,15 @@ function staleRunners() {
126
127
  /**
127
128
  * What the status line says about the rows on screen, in three states.
128
129
  *
129
- * Fresh says NOTHING: a line that is always there is a line nobody reads, and
130
- * there is nothing here to report.
130
+ * Fresh says nothing. A line that is always shown is a line nobody reads,
131
+ * and there is nothing to report.
131
132
  *
132
- * Stale-and-slow is separated from ordinary stale because it is the case the
133
- * whole cache exists for. A runner this repository has MEASURED at several
134
- * seconds is why the screen would otherwise have been empty, and telling the
135
- * user "a moment" in the same voice as a 200ms refresh would waste the one
136
- * warning that matters. Slow is measured, never declared — a runner that is
137
- * quick here is not called slow because it is slow elsewhere.
133
+ * Stale and slow is kept apart from ordinary stale because it is the case the
134
+ * cache exists for. A runner measured at several seconds in this repository
135
+ * is why the screen would otherwise be empty. Showing it the same way as a
136
+ * 200ms refresh would hide the one warning that matters. Slowness is
137
+ * measured, never assumed: a runner that is quick here is not called slow
138
+ * because it is slow elsewhere.
138
139
  */
139
140
  export function refreshNote(rows, loading) {
140
141
  const stale = rows.filter((r) => r.state === 'stale');
@@ -146,8 +147,7 @@ export function refreshNote(rows, loading) {
146
147
  const slow = stale.filter((r) => r.slow);
147
148
  if (!loading) {
148
149
  // The refresh is over and these rows are still what the store held: it
149
- // failed, or it has not been asked for yet. Saying "re-probing" would
150
- // describe work nobody is doing.
150
+ // failed, or it has not been asked for yet. "re-probing" would be untrue.
151
151
  return {
152
152
  slow: slow.length > 0,
153
153
  text: `cached rows: ${stale.map((r) => `${r.runner} ${humanAge(r.ageMs)}`).join(', ')} — ^r to re-probe`,
@@ -235,10 +235,10 @@ function chainChunks(row) {
235
235
  /**
236
236
  * The whole screen as one string.
237
237
  *
238
- * Exported alongside {@link state} and {@link recompute} so the three cache
239
- * states can be asserted as RENDERED lines rather than as the helper that feeds
240
- * them — the status line is the surface a user reads, and a note that is
241
- * correct but composed into the wrong line helps nobody.
238
+ * Exported with {@link state} and {@link recompute} so tests can check the
239
+ * three cache states in the rendered lines, not only in the helper that
240
+ * builds them. The user reads the status line, and a correct note placed in
241
+ * the wrong line helps nobody.
242
242
  */
243
243
  export function frame(width, height) {
244
244
  const out = [];
@@ -250,10 +250,10 @@ export function frame(width, height) {
250
250
  const count = name === ALL
251
251
  ? (state.catalog?.reports ?? []).reduce((n, r) => n + r.tasks.length, 0)
252
252
  : (reportFor(name)?.tasks.length ?? 0);
253
- // Marked at the TAB, not per row: the whole runner's rows are as old as
254
- // each other, so a per-row mark would repeat one fact hundreds of times and
255
- // the row renderer would have to know about the cache. A leading `~` reads
256
- // as "about" at a glance and survives NO_COLOR.
253
+ // Marked on the tab, not per row. All of a runner's rows are the same age,
254
+ // so a per-row mark would repeat one fact many times, and the row
255
+ // renderer would have to know about the cache. A leading `~` reads as
256
+ // "about" and still shows under NO_COLOR.
257
257
  const stale = name === ALL ? staleRunners().length > 0 : cacheFor(name)?.state === 'stale';
258
258
  // A bar between groups: tasks, then dependencies, tools and git hooks.
259
259
  const prev = tabs()[tabs().indexOf(name) - 1];
@@ -285,16 +285,16 @@ export function frame(width, height) {
285
285
  ...(state.loading && refreshNote(state.cache, true) === null
286
286
  ? [{ text: ' refreshing', paint: yellow }]
287
287
  : []),
288
- // The cache's three states. Fresh returns null and says nothing;
289
- // stale-and-slow paints red so it does not read like the ordinary
290
- // refresh note beside it.
288
+ // The cache's three states. Fresh returns null and shows nothing.
289
+ // Stale and slow is red, so it stands apart from an ordinary
290
+ // refresh note.
291
291
  ...(() => {
292
292
  const note = refreshNote(state.cache, state.loading);
293
293
  return note === null ? [] : [{ text: ` ${note.text}`, paint: note.slow ? red : yellow }];
294
294
  })(),
295
295
  ...(state.message ? [{ text: ` ${state.message}`, paint: yellow }] : []),
296
- // A note beside the counts, not a modal: you may well have come here to
297
- // look at what is already collected and run nothing.
296
+ // A note beside the counts, not a modal, since you may only want to
297
+ // look at what is already collected.
298
298
  ...(state.confirmingTrust
299
299
  ? [{ text: ' trust this repository? y/n', paint: yellow }]
300
300
  : withheldForTrust() > 0
@@ -309,9 +309,8 @@ export function frame(width, height) {
309
309
  .filter((r) => r.status === 'error')
310
310
  .map((r) => ({ text: ` ${r.runner} failed`, paint: red })),
311
311
  ], width));
312
- // 4a. the settings screen, which REPLACES the list while it is open. It is
313
- // a different view of the same repository rather than an overlay on this
314
- // one, so nothing below it renders.
312
+ // 4a. the settings screen, which replaces the list while it is open. It is
313
+ // a separate view, not an overlay, so nothing below it renders.
315
314
  if (state.settings !== null) {
316
315
  const room = Math.max(1, height - out.length - 2);
317
316
  for (let i = 0; i < room; i++) {
@@ -324,9 +323,9 @@ export function frame(width, height) {
324
323
  out.push(line([{ text: `reading only — edit with \`${BIN} config set\` esc back`, paint: dim }], width));
325
324
  return HOME + out.join('\r\n') + CLEAR_BELOW;
326
325
  }
327
- // 4. the list, sized by what the chrome leaves. The entry line costs one
328
- // more row than the key hints it replaces, so the list gives one up while
329
- // arguments are being typed rather than the bottom line falling off screen.
326
+ // 4. the list, in the rows left over. The entry line takes one more row
327
+ // than the key hints it replaces, so the list gives up a row while
328
+ // arguments are typed, and the bottom line stays on screen.
330
329
  const listHeight = Math.max(1, height - out.length - (state.entering ? 5 : 4));
331
330
  clampScroll(at, listHeight);
332
331
  for (let i = 0; i < listHeight; i++) {
@@ -341,7 +340,7 @@ export function frame(width, height) {
341
340
  ...chainChunks(row),
342
341
  ], width));
343
342
  }
344
- // 5. what Enter would run — always on screen, so it is never a surprise
343
+ // 5. what Enter would run, always on screen
345
344
  const current = state.rows[at];
346
345
  out.push(line([{ text: '-'.repeat(width), paint: dim }], width));
347
346
  if (current) {
@@ -362,10 +361,10 @@ export function frame(width, height) {
362
361
  out.push(line([{ text: state.query ? 'no match' : 'nothing collected', paint: dim }], width));
363
362
  out.push(line([], width));
364
363
  }
365
- // 6. keys — or, while arguments are being typed, the entry line in their
366
- // place. It replaces the key hints rather than sitting above them because
367
- // the keys that matter while typing are the two this line names, and a
368
- // second row would push the list up mid-task.
364
+ // 6. keys, or the entry line in their place while arguments are typed. It
365
+ // replaces the key hints rather than sitting above them, because the only
366
+ // keys that matter while typing are the two this line names, and an extra
367
+ // row would push the list up.
369
368
  if (state.entering) {
370
369
  const { task, text } = state.entering;
371
370
  const shape = paramShape(task.parameters);
@@ -399,10 +398,10 @@ function clampScroll(at, listHeight) {
399
398
  * Rebuild the visible rows and re-anchor the selection onto a task that is
400
399
  * still there.
401
400
  *
402
- * Split out of {@link draw} so it can be exercised without a terminal. It is
403
- * the whole reason selection is held by task id: a refresh reorders rows and
404
- * drops some of them, and an index would silently point at a different task —
405
- * which is the same keystroke running the wrong command.
401
+ * Split out of {@link draw} so it can be tested without a terminal. This is
402
+ * why selection is held by task id: a refresh reorders and drops rows, and an
403
+ * index would silently point at a different task, so the same keystroke
404
+ * would run the wrong command.
406
405
  */
407
406
  export function recompute() {
408
407
  state.rows = visibleRows();
@@ -415,15 +414,13 @@ function draw() {
415
414
  process.stdout.write(frame(process.stdout.columns || 100, process.stdout.rows || 30));
416
415
  }
417
416
  /**
418
- * The settings screen, as text — the same four sections the page shows, in the
419
- * config schema's own key order, so the two surfaces describe a project the
420
- * same way.
417
+ * The settings screen, as text: the same four sections the page shows, in
418
+ * the config schema's key order, so both describe a project the same way.
421
419
  *
422
- * READ ONLY, and it says so on screen. The page can edit because it has a
423
- * server to POST to and a pointer to click with; giving the terminal the same
424
- * would mean an input mode per field, which is a larger thing than showing
425
- * someone what their configuration is. `way config set` is the editor
426
- * this line points at.
420
+ * Read only, and it says so on screen. The page can edit because it has a
421
+ * server to POST to and a pointer to click with. Editing here would need an
422
+ * input mode per field, which is more than showing the configuration needs.
423
+ * The screen points to `way config set` for edits.
427
424
  */
428
425
  async function settingsLines() {
429
426
  const loaded = await loadConfig(state.root, state.env, state.home);
@@ -482,10 +479,14 @@ async function settingsLines() {
482
479
  */
483
480
  function copy(task) {
484
481
  const dir = /^[\w.\-/@+]+$/.test(task.cwd) ? task.cwd : `'${task.cwd.replace(/'/g, "'\\''")}'`;
485
- const text = task.cwd === '.' ? task.display : `cd ${dir} && ${task.display}`;
482
+ // The text shown, so a control character in it cannot reach the paste.
483
+ const text = terminalSafe(task.cwd === '.' ? task.display : `cd ${dir} && ${task.display}`);
486
484
  const bin = process.platform === 'darwin' ? 'pbcopy' : 'xclip';
487
485
  const args = process.platform === 'darwin' ? [] : ['-selection', 'clipboard'];
488
- const res = spawnRunner(bin).run(args, { input: text, cwd: state.root });
486
+ const res = spawnRunner(bin, { absolutePathOnly: true }).run(args, {
487
+ input: text,
488
+ cwd: state.root,
489
+ });
489
490
  return res.exitCode === 0;
490
491
  }
491
492
  let restored = false;
@@ -499,60 +500,56 @@ function restoreTerminal() {
499
500
  process.stdout.write(SHOW + ALT_OFF);
500
501
  }
501
502
  /**
502
- * Hand the terminal to the selected task and take this process out of the way.
503
- * It streams through the command seam, so the task owns the terminal while it
504
- * runs.
503
+ * Hand the terminal to the selected task and exit when it finishes. It
504
+ * streams through `@osdlc/command-seam`, so the task has the terminal while
505
+ * it runs.
505
506
  *
506
- * `argv` is spawned WITHOUT a shell. `display` would be wrong to run — for a
507
- * parameterised recipe it carries `<placeholders>`, which a shell reads as
507
+ * `argv` is spawned without a shell. Running `display` would be wrong: for a
508
+ * recipe with parameters it has `<placeholders>`, which a shell reads as
508
509
  * redirections.
509
510
  */
510
511
  function runAndExit(task, args = []) {
511
512
  // Abandon any in-flight probe before the terminal changes hands.
512
513
  state.inFlight?.abort();
513
514
  restoreTerminal();
514
- // Echo what actually RAN, not `display` — for a parameterised task those
515
- // differ, and printing the placeholder form above a command that did not
516
- // include it would be a lie about what just happened.
515
+ // Print what actually runs, not `display`. For a task with parameters they
516
+ // differ, and printing the placeholder form would misstate what ran.
517
517
  let argv;
518
518
  try {
519
519
  argv = runArgv(state.project, task, args);
520
520
  }
521
521
  catch (err) {
522
- process.stderr.write(`${APP}: ${err instanceof Error ? err.message : String(err)}\n`);
522
+ process.stderr.write(`${APP}: ${terminalSafe(err instanceof Error ? err.message : String(err))}\n`);
523
523
  process.exit(1);
524
524
  }
525
- process.stdout.write(`${dim('$')} ${bold(argv.join(' '))}\n`);
526
- // The shape is worth repeating only when it went unanswered: a task run
527
- // WITH its arguments has just shown them on the line above, and naming the
528
- // placeholders again would read as a complaint about a command that was
529
- // complete.
525
+ process.stdout.write(`${dim('$')} ${bold(terminalSafe(argv.join(' ')))}\n`);
526
+ // Show the parameters only when none were given. A task run with its
527
+ // arguments has just shown them on the line above.
530
528
  if (task.parameters.length > 0 && args.length === 0) {
531
- process.stdout.write(`${dim(` takes ${paramShape(task.parameters)}`)}\n`);
529
+ process.stdout.write(`${dim(` takes ${terminalSafe(paramShape(task.parameters))}`)}\n`);
532
530
  }
533
531
  const [binary, ...rest] = argv;
534
532
  const res = streamRunner(binary).run(rest, {
535
533
  cwd: task.cwd === '.' ? state.root : `${state.root}/${task.cwd}`,
536
534
  quiet: true,
537
535
  });
538
- // A spawn that never started at all — no such binary, no such directory. The
539
- // row may simply have been wrong: it came out of the store, and the task it
540
- // named can have been renamed or deleted since. Naming the staleness turns an
541
- // unexplained failure into one the user can act on.
536
+ // The spawn never started: no such binary, or no such directory. The row may
537
+ // be out of date. It came from the store, and its task may have been
538
+ // renamed or deleted since. Saying so gives the user something to act on.
542
539
  if (res.reason === 'spawn') {
543
- process.stderr.write(`${APP}: ${binary}: ${res.error ?? 'could not start'}\n`);
540
+ process.stderr.write(terminalSafe(`${APP}: ${binary}: ${res.error ?? 'could not start'}`) + '\n');
544
541
  const from = cacheFor(task.runner);
545
542
  if (from !== undefined && from.state === 'stale') {
546
- process.stderr.write(`${APP}: that row came from a cached listing of ${task.runner} taken ${humanAge(from.ageMs)}` +
543
+ process.stderr.write(`${APP}: that row came from a cached listing of ${terminalSafe(task.runner)} taken ${humanAge(from.ageMs)}` +
547
544
  ` — the task may no longer exist; start ${BIN} again to re-probe\n`);
548
545
  }
549
546
  }
550
547
  process.exit(res.exitCode);
551
548
  }
552
549
  /**
553
- * Re-probe. Guarded three ways, all of which the synchronous version got for
554
- * free: a single in-flight probe, a generation token so a superseded result is
555
- * discarded, and an abort signal so an abandoned one stops working.
550
+ * Re-probe, with three protections: one probe in flight at a time, a
551
+ * generation number so an older result is discarded, and an abort signal so
552
+ * an abandoned probe stops.
556
553
  */
557
554
  async function refresh() {
558
555
  if (state.loading)
@@ -564,10 +561,9 @@ async function refresh() {
564
561
  state.message = '';
565
562
  draw();
566
563
  try {
567
- // ALWAYS a real probe, never a cache read — ^r means "ask again", and a
568
- // refresh that could answer from the store would make the one key that
569
- // guarantees accuracy indistinguishable from doing nothing. It writes the
570
- // store on the way out, so the next start still paints instantly.
564
+ // Always a real probe, never a cache read. ^r means "ask again", and an
565
+ // answer from the store would look the same as doing nothing. The probe
566
+ // writes the store, so the next start still shows rows at once.
571
567
  const collected = await collectAndCache(state.project, state.root, { ...state.options, signal: controller.signal }, state.store);
572
568
  if (generation !== state.generation)
573
569
  return; // a newer refresh won
@@ -590,9 +586,8 @@ async function refresh() {
590
586
  /**
591
587
  * Grant trust, then re-probe in place so the runners appear where the note was.
592
588
  *
593
- * The hint is dropped at the same time: it tells the user to trust the
594
- * repository, which they just did, and a catalog carrying it after the fact
595
- * would be instructing them to repeat themselves.
589
+ * The hint is dropped at the same time. It tells the user to trust the
590
+ * repository, which they just did.
596
591
  */
597
592
  async function grantTrust() {
598
593
  try {
@@ -602,8 +597,8 @@ async function grantTrust() {
602
597
  }).trust(state.root);
603
598
  }
604
599
  catch (err) {
605
- // Never silent: the keystroke did something, and if it failed the user has
606
- // to know the runners are still hidden for a reason they can act on.
600
+ // Never silent. If the grant failed, the user must know why the runners
601
+ // are still hidden.
607
602
  state.message = `trust failed: ${err instanceof Error ? err.message : String(err)}`;
608
603
  return;
609
604
  }
@@ -615,11 +610,11 @@ async function grantTrust() {
615
610
  state.message = state.projectToolsPending
616
611
  ? `trusted — re-probing; the project's tools load the next time ${BIN} starts with execution allowed`
617
612
  : 'trusted — re-probing';
618
- // A probe started before the grant was collected under the old gate, and
619
- // `refresh` drops a request while one is running — so the grant would be
620
- // announced and never acted on. Abandon that probe first; `refresh` bumps
621
- // the generation synchronously, so the abandoned one cannot come back and
622
- // overwrite the new result or its bookkeeping.
613
+ // A probe started before the grant runs with the old settings, and
614
+ // `refresh` ignores a call while one is running, so the grant would be
615
+ // announced and never used. Abandon that probe first. `refresh` increases
616
+ // the generation synchronously, so the abandoned probe cannot overwrite
617
+ // the new result or its state.
623
618
  state.inFlight?.abort();
624
619
  state.inFlight = null;
625
620
  state.loading = false;
@@ -636,9 +631,9 @@ function cycleRunner(step) {
636
631
  /**
637
632
  * One keystroke.
638
633
  *
639
- * Exported for the same reason `state` is: `runTui` owns a real terminal and
640
- * never returns, so the keys that reach disk — settings, trust — are only
641
- * reachable from a test through this.
634
+ * Exported for the same reason `state` is. `runTui` takes over a real
635
+ * terminal and never returns, so tests reach the keys that touch disk
636
+ * (settings, trust) only through this.
642
637
  */
643
638
  export function handle(key) {
644
639
  const listHeight = Math.max(1, (process.stdout.rows || 30) - 7);
@@ -646,9 +641,8 @@ export function handle(key) {
646
641
  select(cursor() + n);
647
642
  state.message = '';
648
643
  };
649
- // The armed prompt owns the keyboard for exactly one keystroke. `y` grants;
650
- // anything else cancels and is swallowed, so the key that cancelled cannot
651
- // also do its usual job in the same breath.
644
+ // The trust prompt takes exactly one keystroke. `y` grants. Any other key
645
+ // cancels and is consumed, so it does not also do its usual job.
652
646
  if (state.confirmingTrust) {
653
647
  state.confirmingTrust = false;
654
648
  state.message = '';
@@ -656,17 +650,16 @@ export function handle(key) {
656
650
  void grantTrust().finally(draw);
657
651
  return;
658
652
  }
659
- // The settings screen owns the keyboard while it is open, for the same
660
- // reason the entry line does: the keys below act on a list that is not on
661
- // screen.
653
+ // The settings screen takes all keys while it is open, as the entry line
654
+ // does, because the keys below act on a list that is not on screen.
662
655
  if (state.settings !== null) {
663
656
  if (key === '\x1b' || key === '\x03' || key === ',' || key === 'q')
664
657
  state.settings = null;
665
658
  return;
666
659
  }
667
- // Typing arguments owns the keyboard: every key is text or one of the two
668
- // that end it. Placed before the switch so ^y, tab and the arrows cannot
669
- // act on a list the user is no longer looking at.
660
+ // While arguments are typed, every key is text or one of the two that end
661
+ // it. This comes before the switch so ^y, tab and the arrows cannot act on
662
+ // a list the user is no longer looking at.
670
663
  if (state.entering) {
671
664
  const entering = state.entering;
672
665
  if (key === '\x1b' || key === '\x03') {
@@ -701,9 +694,9 @@ export function handle(key) {
701
694
  const row = state.rows[cursor()];
702
695
  if (!row)
703
696
  break;
704
- // A parameterised recipe collects its arguments first. Running it here
697
+ // A recipe with parameters asks for its arguments first. Running it here
705
698
  // would spawn the command without them and hand over the terminal, so
706
- // the mistake could not even be reported.
699
+ // the mistake could not be reported.
707
700
  if (row.task.parameters.length > 0)
708
701
  state.entering = { task: row.task, text: '' };
709
702
  else
@@ -725,9 +718,9 @@ export function handle(key) {
725
718
  state.selectedId = null;
726
719
  break;
727
720
  case ',':
728
- // Loaded on open, not on every frame — it is a disk read. A disk read
729
- // fails: an unparseable config throws, and without the catch that is an
730
- // unhandled rejection instead of a line the user can act on.
721
+ // Loaded on open, not on every frame, because it reads from disk. A
722
+ // config that will not parse throws, and without the catch that would
723
+ // be an unhandled rejection instead of a message.
731
724
  void settingsLines()
732
725
  .then((lines) => {
733
726
  state.settings = lines;
@@ -826,13 +819,14 @@ export async function runTui({ project, projectToolsPending, root, options, runn
826
819
  }
827
820
  draw();
828
821
  });
829
- // Stale-then-refresh. The first paint costs a few file hashes rather than a
830
- // full probe, so a repository whose slowest runner takes seconds shows its
831
- // tasks at once — marked as cached — instead of an empty frame. The probe
832
- // then lands underneath and the rows update in place.
822
+ // Show the store, then refresh. The first frame costs a few file hashes
823
+ // rather than a full probe, so even when the slowest runner takes seconds
824
+ // the tasks show at once, marked as cached, instead of an empty frame. When
825
+ // the probe finishes, the rows update in place.
833
826
  const stored = await readCachedCatalog(project, root, options, state.store);
834
- // Only painted when something came OUT of the store: with execution off, a
835
- // cold store still yields withheld reports, an empty list posing as an answer.
827
+ // Shown only when something came from the store. With execution off, an
828
+ // empty store still returns withheld reports, which would look like an
829
+ // empty answer.
836
830
  if (stored.catalog !== null && fromStore(stored)) {
837
831
  state.catalog = orderedCatalog(stored.catalog, runnerOrder);
838
832
  state.cache = stored.runners;