@floless/app 0.150.0 → 0.152.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.
@@ -11,6 +11,13 @@
11
11
  dialog lists "Ready to approve" cards, "Needs you" rows, the downloads
12
12
  line and the consequence footnote; after the click, the results replace
13
13
  the cards in a live region.
14
+
15
+ While a check runs (it can take minutes: each tool download is its own
16
+ wait, see aware-aeco/aware#671) the dialog shows the server's own account
17
+ of it: the steps, which one is active, what it is on and how long it has
18
+ been on it. It asks for that at most once a second (a slow answer skips a
19
+ tick) and only while the dialog is open and a check is running; those
20
+ answers are shown, never applied as the view.
14
21
  ────────────────────────────────────────────────────────────────────────── */
15
22
  (function () {
16
23
  'use strict';
@@ -22,6 +29,8 @@
22
29
  var $title = document.getElementById('tool-updates-title');
23
30
  var $body = document.getElementById('tool-updates-body');
24
31
  var $live = document.getElementById('tool-updates-live');
32
+ var $progress = document.getElementById('tool-updates-progress');
33
+ var $announce = document.getElementById('tool-updates-announce');
25
34
  var $foot = document.getElementById('tool-updates-foot');
26
35
  var $check = document.getElementById('tool-updates-check');
27
36
  var $cancel = document.getElementById('tool-updates-cancel');
@@ -29,9 +38,213 @@
29
38
 
30
39
  var view = null;
31
40
  var results = null;
41
+
42
+ // ── The view never goes back in time (#2013; also closes #1997's stale-answer race) ──────────────────────
43
+ // Every change to the view comes from a request this page sends — the server's `tool-updates-changed` broadcast only
44
+ // starts a re-read, which is a request like any other. Each request takes a ticket when it is SENT; its answer
45
+ // replaces the view only if no answer to a later-sent request has been applied yet. An older answer still shows its
46
+ // own results and sentence, never its view. Nothing here depends on a server counter, so a server restart with this
47
+ // tab still open changes nothing: the next answer simply applies.
48
+ var sentTicket = 0;
49
+ var appliedTicket = 0;
50
+
51
+ function nextTicket() { sentTicket += 1; return sentTicket; }
52
+
53
+ /** Apply `next` (a whole view, its cleanup beside it) from the request holding `ticket`. False when superseded. */
54
+ function applyView(ticket, next) {
55
+ if (!next || ticket < appliedTicket) return false;
56
+ appliedTicket = ticket;
57
+ view = next;
58
+ return true;
59
+ }
60
+
61
+ /** Apply a cleanup view on its own (Remove from list answers with only that part), under the same ticket rule. */
62
+ function applyCleanup(ticket, next) {
63
+ if (!view || !next || ticket < appliedTicket) return false;
64
+ appliedTicket = ticket;
65
+ view = Object.assign({}, view, { cleanup: next });
66
+ return true;
67
+ }
32
68
  var busy = false;
69
+ var checking = false; // the Check for updates request is in flight
33
70
  var returnFocus = null;
34
71
 
72
+ // ── A running check, as the server describes it ───────────────────────────────────────────────────────────
73
+ // The clock is deliberately here although the headless-run styling avoids one (web/app.css, "Headless runs (#571
74
+ // slice 3)"): that run has no progress signal, so a duration there would carry no meaning. This one is the time on a
75
+ // real step, which lets a person tell waiting from stuck. The page subtracts the server's epoch from its own clock,
76
+ // which holds because the page and the server are on the same machine.
77
+ var CLOCK_AFTER_SECONDS = 10; // quick steps stay quiet; a slow one starts showing how long it has taken
78
+ var MARKS = { done: '✓', problem: '!' };
79
+ var progress = null; // the server's progress record ({steps, since}) for the check running now (null before its first answer)
80
+ var lostContact = false; // the last ask for them got no answer: the clock then says nothing it cannot back
81
+ var paintedSteps = null;
82
+ var announced = null;
83
+ var announcedProblems = {};
84
+ var watchTimer = null;
85
+ var polling = false;
86
+ var rereading = false; // the view re-read after a background check ended is on its way
87
+ var pollSentAt = 0;
88
+ var pollController = null;
89
+ var watchGeneration = 0; // bumped whenever watching stops: an answer to an older ask belongs to nothing now
90
+ var POLL_PATIENCE_MS = 6000;
91
+
92
+ function checkInFlight() { return checking || !!(view && view.checking); }
93
+ function checkRunning() { return $modal.classList.contains('show') && checkInFlight(); }
94
+
95
+ function elapsedText(seconds) {
96
+ var nb = '\u00a0'; // never wraps between the number and its unit
97
+ if (seconds < 60) return seconds + nb + 's';
98
+ var minutes = Math.floor(seconds / 60);
99
+ var rest = seconds % 60;
100
+ var pad = function (n) { return (n < 10 ? '0' : '') + n; };
101
+ if (minutes < 60) return minutes + nb + 'min' + nb + pad(rest) + nb + 's';
102
+ return Math.floor(minutes / 60) + nb + 'h' + nb + pad(minutes % 60) + nb + 'min';
103
+ }
104
+
105
+ function paintClock() {
106
+ var clock = $progress.querySelector('.tool-updates-step-clock');
107
+ if (!clock) return;
108
+ // Hidden without a start time from the server, and while the server is not answering.
109
+ var seconds = progress && typeof progress.since === 'number' && !lostContact ? Math.max(0, Math.floor((Date.now() - progress.since) / 1000)) : -1;
110
+ clock.hidden = seconds < CLOCK_AFTER_SECONDS;
111
+ if (!clock.hidden) clock.textContent = elapsedText(seconds);
112
+ }
113
+
114
+ // What a screen reader hears: a step that did not do all it set out to, once; and the active step, when it or the item
115
+ // it is on changes. Never the clock, never a repeat.
116
+ function announce(steps) {
117
+ var parts = [];
118
+ steps.forEach(function (step) {
119
+ if (step.state !== 'problem') return;
120
+ var line = step.label + ': ' + (step.detail || 'did not finish');
121
+ if (announcedProblems[step.label] === line) return;
122
+ announcedProblems[step.label] = line;
123
+ parts.push(line);
124
+ });
125
+ var active = steps.filter(function (step) { return step.state === 'active'; })[0];
126
+ var sentence = active ? active.label + (active.detail ? ': ' + active.detail : '') : '';
127
+ if (sentence !== announced) {
128
+ announced = sentence;
129
+ if (sentence) parts.push(sentence);
130
+ }
131
+ if (parts.length) $announce.textContent = parts.join('. ');
132
+ }
133
+
134
+ function paintProgress() {
135
+ var steps = progress && Array.isArray(progress.steps) ? progress.steps : [];
136
+ var signature = JSON.stringify(steps) + '|' + lostContact;
137
+ // Rebuilt only when what it shows changes; the clock beside the active step ticks in place.
138
+ if (signature !== paintedSteps || !$progress.firstChild) {
139
+ $progress.textContent = '';
140
+ $progress.appendChild(el('div', 'tool-updates-progress-head', 'Checking for updates…'));
141
+ if (lostContact) $progress.appendChild(el('div', 'tool-updates-progress-lost', 'Lost contact with FloLess. Still trying…'));
142
+ if (steps.length) {
143
+ var list = el('ol', 'tool-updates-steps');
144
+ list.setAttribute('role', 'list');
145
+ steps.forEach(function (step) {
146
+ var row = el('li', 'tool-updates-step');
147
+ row.setAttribute('data-state', step.state);
148
+ if (step.state === 'active') row.setAttribute('aria-current', 'step');
149
+ var mark = el('span', 'tool-updates-step-mark', MARKS[step.state] || '');
150
+ mark.setAttribute('aria-hidden', 'true');
151
+ row.appendChild(mark);
152
+ row.appendChild(el('span', 'tool-updates-step-label', step.label));
153
+ if (step.state === 'active') {
154
+ var clock = el('span', 'tool-updates-step-clock');
155
+ clock.hidden = true;
156
+ clock.setAttribute('aria-hidden', 'true');
157
+ clock.setAttribute('data-tip', 'Time on this item so far');
158
+ row.appendChild(clock);
159
+ }
160
+ if (step.detail) row.appendChild(el('span', 'tool-updates-step-detail', step.detail));
161
+ list.appendChild(row);
162
+ });
163
+ $progress.appendChild(list);
164
+ }
165
+ paintedSteps = signature;
166
+ }
167
+ announce(steps);
168
+ paintClock();
169
+ }
170
+
171
+ /** One ask at a time: an older answer can never arrive after, and undo, a newer one. */
172
+ async function pollProgress() {
173
+ if (polling) return;
174
+ polling = true;
175
+ pollSentAt = Date.now();
176
+ var generation = watchGeneration;
177
+ var controller = new AbortController();
178
+ pollController = controller;
179
+ var body = null;
180
+ var failed = false;
181
+ try { body = await call('/api/tool-updates/progress', 'GET', undefined, controller.signal); } catch (error) { failed = true; }
182
+ // A 200 that is not the answer (a truncated or foreign body) is no contact either.
183
+ if (!failed && (!body || body.ok !== true || typeof body.checking !== 'boolean')) failed = true;
184
+ if (pollController === controller) { pollController = null; polling = false; }
185
+ // An answer to an ask from before the dialog was closed (or the check ended) belongs to nothing now.
186
+ if (generation !== watchGeneration || !checkRunning()) return;
187
+ if (failed) {
188
+ markLost();
189
+ } else {
190
+ lostContact = false;
191
+ // Shown, never applied: this is not the view (the view's ticket order belongs to the requests above). A pass that
192
+ // is queued behind another has no steps yet: the old ones go with it rather than freeze with a running clock.
193
+ if (body.checking) {
194
+ progress = body.progress || null;
195
+ } else {
196
+ progress = null; // nothing is running: no steps, and no clock counting on one
197
+ // A check that ended without this page asking (a background one): the page reads the view and repaints, one read at a time.
198
+ if (!checking && !rereading) {
199
+ rereading = true;
200
+ var readDone = function () { rereading = false; };
201
+ refresh().then(readDone, readDone);
202
+ }
203
+ }
204
+ }
205
+ paintProgress();
206
+ }
207
+
208
+ /** The server is not answering: warn once per episode, whichever way the page found out. */
209
+ function markLost() {
210
+ if (!lostContact) console.warn('tool update progress unavailable');
211
+ lostContact = true;
212
+ }
213
+
214
+ function stopWatching() {
215
+ if (watchTimer) { clearInterval(watchTimer); watchTimer = null; }
216
+ watchGeneration += 1;
217
+ if (pollController) { pollController.abort(); pollController = null; }
218
+ polling = false;
219
+ progress = null;
220
+ lostContact = false;
221
+ paintedSteps = null;
222
+ announcedProblems = {};
223
+ $progress.textContent = '';
224
+ $announce.textContent = '';
225
+ }
226
+
227
+ /** Shows the panel exactly while a check runs in an open dialog, and asks the server how it is going. */
228
+ function syncProgress() {
229
+ var on = checkRunning();
230
+ $progress.hidden = !on;
231
+ if (on) $modal.setAttribute('data-checking', ''); else $modal.removeAttribute('data-checking');
232
+ if (!on) { stopWatching(); return; }
233
+ paintProgress();
234
+ if (watchTimer) return;
235
+ watchTimer = setInterval(function () {
236
+ // An ask that has not come back for a while is the server not answering, not a slow step: say so, give that ask
237
+ // up (it would otherwise hold every later one back for ever) and ask again on the next tick.
238
+ if (polling && Date.now() - pollSentAt > POLL_PATIENCE_MS) {
239
+ if (!lostContact) { markLost(); paintProgress(); }
240
+ if (pollController) pollController.abort();
241
+ }
242
+ paintClock();
243
+ void pollProgress();
244
+ }, 1000);
245
+ void pollProgress();
246
+ }
247
+
35
248
  function el(tag, cls, text) {
36
249
  var node = document.createElement(tag);
37
250
  if (cls) node.className = cls;
@@ -41,8 +254,8 @@
41
254
 
42
255
  function plural(n, one, many) { return n + ' ' + (n === 1 ? one : many); }
43
256
 
44
- async function call(path, method, payload) {
45
- var res = await fetch(path, { method: method || 'GET', headers: { 'content-type': 'application/json' }, body: payload });
257
+ async function call(path, method, payload, signal) {
258
+ var res = await fetch(path, { method: method || 'GET', headers: { 'content-type': 'application/json' }, body: payload, signal: signal });
46
259
  var body = await res.json().catch(function () { return { ok: false, error: 'FloLess received an unreadable answer (HTTP ' + res.status + ').' }; });
47
260
  if (!res.ok && body.ok !== true && !body.results) {
48
261
  var error = new Error(body.error || ('HTTP ' + res.status));
@@ -52,12 +265,19 @@
52
265
  return body;
53
266
  }
54
267
 
268
+ // #2013: AWARE's cleanup of unused tool versions, as the server words it (agent-store-cleanup.ts).
269
+ function cleanupNeeds() {
270
+ var c = view && view.cleanup;
271
+ return c && c.supported && Array.isArray(c.needsYou) ? c.needsYou : [];
272
+ }
273
+
55
274
  // ── The footer pill ────────────────────────────────────────────────────────
56
275
  function paintPill() {
57
276
  var offers = view && view.supported ? view.offers || [] : [];
58
277
  var needs = view && view.supported ? view.needsYou || [] : [];
278
+ var cleanup = cleanupNeeds();
59
279
  var urgent = offers.filter(function (o) { return !!o.advisory; }).length;
60
- if (!offers.length && !needs.length) {
280
+ if (!offers.length && !needs.length && !cleanup.length) {
61
281
  $pill.hidden = true;
62
282
  $pill.removeAttribute('data-state');
63
283
  if ($modal.classList.contains('show') && !results) paint();
@@ -78,7 +298,11 @@
78
298
  }
79
299
  } else {
80
300
  state = 'needs';
81
- text = plural(needs.length, 'workflow needs you', 'workflows need you');
301
+ var folders = cleanup.filter(function (c) { return c.kind !== 'unreadable'; }).length;
302
+ if (needs.length && cleanup.length) text = (needs.length + cleanup.length) + ' things need you';
303
+ else if (needs.length) text = plural(needs.length, 'workflow needs you', 'workflows need you');
304
+ else if (folders === cleanup.length) text = plural(folders, 'folder needs you', 'folders need you');
305
+ else text = plural(cleanup.length, 'item needs you', 'items need you');
82
306
  }
83
307
  $pill.textContent = text;
84
308
  $pill.setAttribute('data-state', state);
@@ -149,6 +373,84 @@
149
373
  return row;
150
374
  }
151
375
 
376
+ var forgetting = null; // the path being removed from the list, while its request is in flight
377
+
378
+ function cleanupRow(item) {
379
+ var row = el('div', 'tool-updates-needs');
380
+ row.setAttribute('data-kind', 'cleanup-' + item.kind);
381
+ row.setAttribute('data-path', item.path);
382
+ var text = el('div', 'tool-updates-needs-text');
383
+ text.appendChild(el('span', 'tool-updates-needs-name', item.name || item.path));
384
+ text.appendChild(el('span', 'tool-updates-needs-sentence', item.sentence));
385
+ row.appendChild(text);
386
+ if (item.action === 'forget-folder') {
387
+ var busyHere = forgetting === item.path;
388
+ var button = el('button', 'tool-updates-open', busyHere ? 'Removing…' : 'Remove from list');
389
+ button.type = 'button';
390
+ button.disabled = busyHere || busy;
391
+ button.setAttribute('data-command-id', 'shell.tool-updates-forget-folder');
392
+ button.setAttribute('data-tip', 'Stop keeping old tool versions for the workflows in this folder');
393
+ button.setAttribute('aria-label', 'Remove ' + (item.name || item.path) + ' from the list');
394
+ button.addEventListener('click', function () { void forgetFolder(item); });
395
+ row.appendChild(button);
396
+ }
397
+ return row;
398
+ }
399
+
400
+ async function forgetFolder(item) {
401
+ if (busy || forgetting) return;
402
+ var path = item.path;
403
+ var ok = false;
404
+ forgetting = path;
405
+ paint();
406
+ $live.textContent = 'Removing ' + (item.name || path) + ' from the list…';
407
+ var ticket = nextTicket();
408
+ try {
409
+ var body = await call('/api/tool-updates/forget-folder', 'POST', JSON.stringify({ path: path }));
410
+ applyCleanup(ticket, body.cleanup);
411
+ // The server answers 200 with ok:false when it kept the folder (it came back, or AWARE could not be asked).
412
+ ok = body.ok !== false;
413
+ $live.textContent = body.sentence || (ok ? 'Removed from the list.' : 'Nothing was removed from the list. Try again.');
414
+ } catch (error) {
415
+ if (error.body) applyCleanup(ticket, error.body.cleanup);
416
+ $live.textContent = error.message + ' Nothing was removed from the list.';
417
+ } finally {
418
+ forgetting = null;
419
+ paint();
420
+ paintPill();
421
+ // Focus never drops to the page: the next Remove button, else the section, else the title.
422
+ var next = $body.querySelector('[data-command-id="shell.tool-updates-forget-folder"]:not([disabled])');
423
+ var stay = !ok && $body.querySelector('.tool-updates-needs[data-path="' + CSS.escape(path) + '"] button');
424
+ var head = $body.querySelector('.tool-updates-section-head');
425
+ if (stay) stay.focus();
426
+ else if (next) next.focus();
427
+ else if (head) { head.tabIndex = -1; head.focus(); }
428
+ else $title.focus();
429
+ }
430
+ }
431
+
432
+ function cleanupLines() {
433
+ var c = view && view.cleanup;
434
+ if (!c) return [];
435
+ // An AWARE too old to clean up: one short line, no pill and no row.
436
+ if (!c.supported) return c.sentence ? [c.sentence] : [];
437
+ var lines = [];
438
+ if (c.sentence) lines.push(c.sentence);
439
+ if (c.waiting === 'runs') lines.push('Cleaning up unused tool versions waits until no workflow is running.');
440
+ else if (c.waiting === 'runs-unknown') lines.push('FloLess could not ask AWARE which workflows are running, so cleaning up unused tool versions waits and tries again later.');
441
+ else if (c.waiting === 'busy') lines.push('Cleaning up unused tool versions waits until AWARE is done with other tool work.');
442
+ else if (c.waiting === 'network-volume') lines.push('AWARE does not clean up tool versions stored on a network drive.');
443
+ var last = c.lastCleanup;
444
+ if (last && last.removed > 0) {
445
+ var at = new Date(last.at);
446
+ var when = isNaN(at.getTime()) ? '' : ' (' + at.toLocaleString([], { day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit' }) + ')';
447
+ var all = last.tools || [];
448
+ var tools = all.slice(0, 3).join(', ') + (all.length > 3 ? ' and ' + (all.length - 3) + ' more' : '');
449
+ lines.push('Cleaned up ' + plural(last.removed, 'unused tool version', 'unused tool versions') + (tools ? ': ' + tools : '') + when + '.');
450
+ }
451
+ return lines;
452
+ }
453
+
152
454
  function section(title, count) {
153
455
  var wrap = el('div', 'tool-updates-section');
154
456
  wrap.appendChild(el('div', 'tool-updates-section-head', title + ' (' + count + ')'));
@@ -191,7 +493,44 @@
191
493
  return 'Downloaded in the background: ' + names.join(', ') + '.';
192
494
  }
193
495
 
496
+ /** Where focus is inside the body, as something that survives a repaint (a refresh can land at any time). */
497
+ function focusKey() {
498
+ var active = document.activeElement;
499
+ if (!active || !$body.contains(active)) return null;
500
+ var row = active.closest && active.closest('.tool-updates-needs');
501
+ return {
502
+ command: active.getAttribute('data-command-id'),
503
+ path: row && row.getAttribute('data-path'),
504
+ app: row && row.getAttribute('data-app'),
505
+ head: active.classList.contains('tool-updates-section-head'),
506
+ };
507
+ }
508
+
509
+ function restoreFocus(key) {
510
+ if (!key) return;
511
+ var target = null;
512
+ if (key.head) target = $body.querySelector('.tool-updates-section-head');
513
+ else if (key.command) {
514
+ target = Array.prototype.find.call($body.querySelectorAll('[data-command-id="' + key.command + '"]'), function (b) {
515
+ var row = b.closest('.tool-updates-needs');
516
+ return !row || (row.getAttribute('data-path') === key.path && row.getAttribute('data-app') === key.app);
517
+ }) || null;
518
+ }
519
+ if (target && target.offsetParent !== null) {
520
+ if (key.head) target.tabIndex = -1;
521
+ target.focus();
522
+ } else {
523
+ $title.focus(); // its row went away: never leave focus on the page behind the dialog
524
+ }
525
+ }
526
+
194
527
  function paint() {
528
+ var keepFocus = focusKey();
529
+ try { paintNow(); } finally { restoreFocus(keepFocus); }
530
+ syncProgress();
531
+ }
532
+
533
+ function paintNow() {
195
534
  $body.textContent = '';
196
535
  $foot.textContent = '';
197
536
  var offers = (view && view.offers) || [];
@@ -223,18 +562,21 @@
223
562
  $body.appendChild(ready);
224
563
  }
225
564
  }
226
- if (needs.length) {
227
- var needsSection = section('Needs you', needs.length);
565
+ var cleanup = cleanupNeeds();
566
+ if (needs.length || cleanup.length) {
567
+ var needsSection = section('Needs you', needs.length + cleanup.length);
228
568
  needs.forEach(function (n) { needsSection.appendChild(needsRow(n)); });
569
+ cleanup.forEach(function (n) { needsSection.appendChild(cleanupRow(n)); });
229
570
  $body.appendChild(needsSection);
230
571
  }
231
- if (!results && !offers.length && !needs.length && view && view.supported && !view.sentence) {
572
+ if (!results && !offers.length && !needs.length && !cleanup.length && view && view.supported && !view.sentence) {
232
573
  $body.appendChild(el('div', 'tool-updates-summary', view.checking
233
574
  ? 'Checking which workflows a tool update affects…'
234
575
  : 'All your workflows are on the tool versions you approved.'));
235
576
  }
236
577
  var dl = downloadsLine();
237
578
  if (dl) $foot.appendChild(el('div', 'tool-updates-downloads', dl));
579
+ cleanupLines().forEach(function (line) { $foot.appendChild(el('div', 'tool-updates-downloads', line)); });
238
580
  var checked = lastChecked();
239
581
  if (checked) $foot.appendChild(el('div', 'tool-updates-downloads', checked));
240
582
  if (!results && offers.length) {
@@ -249,21 +591,25 @@
249
591
 
250
592
  function setBusy(on, label) {
251
593
  busy = on;
252
- $modal.setAttribute('aria-busy', on ? 'true' : 'false');
594
+ // Not while a check runs: a busy dialog can make a screen reader hold back the step announcements inside it.
595
+ $modal.setAttribute('aria-busy', on && !checking ? 'true' : 'false');
253
596
  [$check, $cancel, $approve].forEach(function (b) { b.disabled = on; });
597
+ Array.prototype.forEach.call($body.querySelectorAll('[data-command-id="shell.tool-updates-forget-folder"]'), function (b) { b.disabled = on || !!forgetting; });
254
598
  if (on && label) $approve.textContent = label;
255
599
  }
256
600
 
257
601
  async function refresh() {
602
+ var ticket = nextTicket();
258
603
  try {
259
604
  var body = await call('/api/tool-updates');
260
- view = body;
605
+ applyView(ticket, body);
261
606
  } catch (error) {
262
607
  // Keep the last answer on screen (and its pill): a dropped request is not "nothing to update".
263
608
  console.warn('tool updates unavailable', error);
264
609
  if ($modal.classList.contains('show') && !busy) $live.textContent = 'FloLess could not check for tool updates just now. What is shown is from the last check.';
265
610
  }
266
611
  paintPill();
612
+ syncProgress();
267
613
  }
268
614
 
269
615
  function open(fromEl) {
@@ -272,6 +618,7 @@
272
618
  $live.textContent = '';
273
619
  paint();
274
620
  $modal.classList.add('show');
621
+ syncProgress();
275
622
  // Focus the title, not the primary: approving is consequential and Enter on open must not do it.
276
623
  setTimeout(function () { $title.focus(); }, 0);
277
624
  void refresh().then(function () { if ($modal.classList.contains('show') && !busy && !results) paint(); });
@@ -280,6 +627,7 @@
280
627
  function close() {
281
628
  if (busy) return;
282
629
  $modal.classList.remove('show');
630
+ syncProgress();
283
631
  if (results) { results = null; }
284
632
  if (returnFocus && document.contains(returnFocus)) returnFocus.focus();
285
633
  returnFocus = null;
@@ -303,15 +651,23 @@
303
651
  });
304
652
 
305
653
  $check.addEventListener('click', async function () {
654
+ checking = true;
306
655
  setBusy(true);
307
- $live.textContent = 'Checking for new tool versions…';
656
+ $live.textContent = ''; // the panel below says what is being checked; the live line is for what came of it
657
+ syncProgress();
308
658
  try {
309
- view = await call('/api/tool-updates/check', 'POST');
310
- var n = (view.offers || []).length;
659
+ var ticket = nextTicket();
660
+ var answer = await call('/api/tool-updates/check', 'POST');
661
+ applyView(ticket, answer);
662
+ var n = (answer.offers || []).length;
311
663
  $live.textContent = n ? plural(n, 'workflow is', 'workflows are') + ' ready to approve.' : 'No workflows to approve.';
664
+ // The cleanup pass Check now started keeps running after this answer, and may already have finished and been
665
+ // re-read: read the server again so this (older) answer never stands over a newer cleanup result.
666
+ void refresh();
312
667
  } catch (error) {
313
668
  $live.textContent = error.message;
314
669
  } finally {
670
+ checking = false;
315
671
  setBusy(false);
316
672
  paint();
317
673
  paintPill();
@@ -326,8 +682,12 @@
326
682
  setBusy(true, 'Approving…');
327
683
  $live.textContent = 'Approving ' + plural(apps.length, 'workflow', 'workflows') + '…';
328
684
  try {
685
+ var ticket = nextTicket();
329
686
  var body = await call('/api/tool-updates/approve', 'POST', JSON.stringify({ batchId: view.batchId, apps: apps }));
330
- if (body.view) view = body.view;
687
+ // The approval answer carries the batch view and, beside it, the cleanup view (#2013). Its results always show;
688
+ // its view only if nothing newer was applied while the approval ran.
689
+ if (body.view) applyView(ticket, Object.assign({}, body.view, { cleanup: body.cleanup !== undefined ? body.cleanup : (view && view.cleanup) }));
690
+ else applyCleanup(ticket, body.cleanup);
331
691
  if (body.ok) {
332
692
  results = body.results || [];
333
693
  var moved = results.filter(function (r) { return r.outcome === 'moved'; }).length;