@floless/app 0.120.2 → 0.122.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/dist/web/aware.js CHANGED
@@ -146,6 +146,10 @@
146
146
  $messages.scrollTop = $messages.scrollHeight;
147
147
  };
148
148
 
149
+ // Declared here, above its first use in api(), rather than beside the recovery helper that reads
150
+ // it — a `let` referenced before its declaration executes is a TDZ crash, not a false.
151
+ let awareMaintenanceRefused = false;
152
+
149
153
  async function api(path, opts) {
150
154
  const res = await fetch(path, {
151
155
  headers: { 'content-type': 'application/json' },
@@ -153,7 +157,19 @@
153
157
  });
154
158
  const body = await res.json().catch(() => ({ ok: false, error: `HTTP ${res.status}` }));
155
159
  if (!res.ok || body.ok === false) {
156
- const err = new Error(body.error || `HTTP ${res.status}`);
160
+ // Centralised so EVERY caller that spawns `aware` reports the refusal honestly rather than
161
+ // showing the raw `aware_maintenance_busy` code. The server refuses instead of queuing
162
+ // because the wait would start before any child exists — invisible to every timeout and
163
+ // uncancellable by Stop — so what reaches the user has to explain itself and say how far
164
+ // along the repair is.
165
+ if (body.code === 'maintenance-busy') {
166
+ // Remembered so the terminal transition can re-run whatever was turned away. Set here
167
+ // rather than at each call site: every `aware`-spawning route funnels through api().
168
+ awareMaintenanceRefused = true;
169
+ }
170
+ const err = new Error(
171
+ (body.code === 'maintenance-busy' && body.message) || body.error || `HTTP ${res.status}`,
172
+ );
157
173
  err.body = body; // preserve the in-band payload (e.g. credentialIssue) for callers
158
174
  throw err;
159
175
  }
@@ -5192,21 +5208,56 @@
5192
5208
  let awareUpgradeFloor = null, awareUpgradeFloorUntil = 0;
5193
5209
  let awareUpdateCheck = null;
5194
5210
  let applyAwareUpdate = null;
5211
+ /**
5212
+ * The one place the "needs attention" pill is painted, so its four properties cannot drift apart
5213
+ * across the three call sites that reach this state. The tooltip matters more than it looks: the
5214
+ * static markup default says an AWARE *upgrade* is available, so a pill that reaches this state
5215
+ * without passing through an offer branch would otherwise hover-explain the wrong thing entirely.
5216
+ */
5217
+ function paintAwareAttentionPill() {
5218
+ if (!$awareUpdate) return;
5219
+ $awareUpdate.hidden = false;
5220
+ $awareUpdate.disabled = false;
5221
+ $awareUpdate.textContent = 'Installed bridges need attention';
5222
+ $awareUpdate.dataset.tip = 'A bridge repair did not finish — open it to see which bridge and try again';
5223
+ $awareUpdate.setAttribute('aria-haspopup', 'dialog');
5224
+ }
5225
+
5226
+ /**
5227
+ * Terminal states whose remaining problem is BRIDGES, whoever started the job.
5228
+ *
5229
+ * Scoped to the operation on purpose: `partial` always means some bridges failed, but a
5230
+ * `runtime-failed` on a runtime UPGRADE is the upgrade failing — labelling that "Installed
5231
+ * bridges need attention" would be the same class of lie this change set out to remove, and the
5232
+ * ordinary re-check below correctly re-offers the upgrade instead.
5233
+ */
5234
+ const awareNeedsAttention = (s) => !!s && (s.status === 'partial'
5235
+ || (s.status === 'runtime-failed' && (s.operation || awareUpgradeOperation) === 'bridge-repair'));
5236
+
5237
+ /**
5238
+ * True when the live job state owns the pill and this generic re-check must keep its hands off.
5239
+ *
5240
+ * Checked BOTH before the fetch and again after it. Before-only was not enough and the gap was
5241
+ * observed, not theorised: at page load this runs while the controller is still `idle`, sails
5242
+ * past the guard, and by the time the response lands `adopt()` has discovered a failed automatic
5243
+ * repair and painted the attention pill — which the stale in-flight answer then overwrote with a
5244
+ * cheerful "Repair 1 installed bridge", erasing the only sign anything had gone wrong.
5245
+ */
5246
+ function awareJobOwnsPill() {
5247
+ const s = window.awareUpdateController && window.awareUpdateController.getState();
5248
+ if (!s) return false;
5249
+ if (s.status === 'starting' || s.status === 'running' || s.status === 'retrying') return true;
5250
+ if (awareNeedsAttention(s)) { paintAwareAttentionPill(); return true; }
5251
+ return false;
5252
+ }
5253
+
5195
5254
  async function refreshAwareUpdate() {
5196
5255
  if (!$awareUpdate) return;
5197
- if (window.awareUpdateController) {
5198
- const updateState = window.awareUpdateController.getState();
5199
- if (updateState.status === 'starting' || updateState.status === 'running' || updateState.status === 'retrying') return;
5200
- if (updateState.status === 'partial') {
5201
- $awareUpdate.hidden = false;
5202
- $awareUpdate.disabled = false;
5203
- $awareUpdate.textContent = 'Installed bridges need attention';
5204
- return;
5205
- }
5206
- }
5256
+ if (awareJobOwnsPill()) return;
5207
5257
  try {
5208
5258
  const r = await fetch('/api/aware/update');
5209
5259
  const d = await r.json();
5260
+ if (awareJobOwnsPill()) return; // the job resolved while this request was in flight
5210
5261
  awareUpdateCheck = r.ok ? d : null;
5211
5262
  if (r.ok && d.updateAvailable && d.targetVersion && d.operation === 'bridge-repair') {
5212
5263
  const count = Array.isArray(d.bridges) ? d.bridges.filter((row) => row.status !== 'current').length : 0;
@@ -5263,6 +5314,16 @@
5263
5314
 
5264
5315
  function closeAwareUpgradeModal() {
5265
5316
  if (!$awareUpgradeModal) return;
5317
+ // Retire an AUTOMATIC terminal result the user has now seen, or /active keeps handing it back
5318
+ // on every page load for the whole retention window. Scoped to this transaction and refused
5319
+ // server-side while it is still running, so closing the modal mid-repair cannot retire a job
5320
+ // that has not failed yet.
5321
+ if (awareUpdateClient) {
5322
+ const s = awareUpdateClient.getState();
5323
+ if (s.origin === 'auto' && (s.status === 'partial' || s.status === 'runtime-failed')) {
5324
+ awareUpdateClient.acknowledge(s.transaction).catch(() => {});
5325
+ }
5326
+ }
5266
5327
  hideModal($awareUpgradeModal);
5267
5328
  const restore = awareUpgradeReturnFocus;
5268
5329
  awareUpgradeReturnFocus = null;
@@ -5328,7 +5389,12 @@
5328
5389
  $awareUpgradeResults.insertAdjacentHTML('afterbegin', `<div class="aware-update-summary">${escapeHtml(s.retryError)}</div>`);
5329
5390
  }
5330
5391
  } else if (status === 'runtime-failed') {
5331
- $awareUpgradeLive.textContent = 'AWARE could not be upgraded.';
5392
+ // A bridge repair can terminalize here too (a failed preflight, smoke, or a runtime that
5393
+ // moved underneath it) — and it never set out to upgrade anything, so the generic wording
5394
+ // would be simply untrue.
5395
+ $awareUpgradeLive.textContent = operation === 'bridge-repair'
5396
+ ? "AWARE's installed bridges could not be refreshed."
5397
+ : 'AWARE could not be upgraded.';
5332
5398
  const reason = s.error && s.error.message ? s.error.message : 'Check your connection and try again.';
5333
5399
  $awareUpgradeResults.innerHTML = `<div class="aware-update-summary">${escapeHtml(reason)}</div>`;
5334
5400
  } else if (status === 'expired') {
@@ -5337,6 +5403,21 @@
5337
5403
  }
5338
5404
  }
5339
5405
 
5406
+ /**
5407
+ * Re-run the loads that unattended maintenance refused while it held the writer.
5408
+ *
5409
+ * The gate answers `maintenance-busy` rather than queuing — the wait it would otherwise impose
5410
+ * starts before any child exists, so nothing times it out and Stop cannot cancel it. But that
5411
+ * refusal also lands on ordinary reads like loadApps(), which have no reason to know about
5412
+ * bridges: without this the workflow list would simply stay empty until something else happened
5413
+ * to reload it. Only for `auto` work; a user-initiated upgrade already owns its own modal flow.
5414
+ */
5415
+ function awareMaintenanceRecover(s) {
5416
+ if (s.origin !== 'auto' || !awareMaintenanceRefused) return;
5417
+ awareMaintenanceRefused = false;
5418
+ loadApps().catch(() => { /* the picker keeps its own empty/error state */ });
5419
+ }
5420
+
5340
5421
  async function openAwareUpgrade(version, returnFocusTo) {
5341
5422
  if (!$awareUpgradeModal || !awareUpdateClient) {
5342
5423
  showToast('Could not open the AWARE update dialog.', 'warn');
@@ -5348,7 +5429,10 @@
5348
5429
  }
5349
5430
  const current = awareUpdateClient.getState();
5350
5431
  let target = version || awareUpgradeTarget || ($awareUpdate && $awareUpdate.dataset.target) || '';
5351
- if (!target && !awareBusy(current.status) && current.status !== 'partial') {
5432
+ // A registry hiccup must not swallow a terminal state we already hold: without widening this
5433
+ // to every attention state, a runtime-failed repair returns early with a toast and the modal
5434
+ // explaining the failure never opens.
5435
+ if (!target && !awareBusy(current.status) && !awareNeedsAttention(current)) {
5352
5436
  try {
5353
5437
  const check = await awareUpdateClient.check();
5354
5438
  awareUpdateCheck = check;
@@ -5363,7 +5447,11 @@
5363
5447
  awareUpgradeInventory = Array.isArray(check.bridges) ? check.bridges : [];
5364
5448
  awareUpgradeTarget = target;
5365
5449
  awareUpgradeReturnFocus = returnFocusTo || document.activeElement;
5366
- paintAwareUpgrade(awareBusy(current.status) || current.status === 'partial'
5450
+ // `runtime-failed` belongs here alongside `partial`. Without it, clicking the attention pill
5451
+ // synthesized a fresh IDLE offer — whose paint clears the results panel and empties the live
5452
+ // region — so the operation-specific explanation ("AWARE's installed bridges could not be
5453
+ // refreshed.") was composed and then never shown to anyone.
5454
+ paintAwareUpgrade(awareBusy(current.status) || awareNeedsAttention(current)
5367
5455
  ? current : { status: 'idle', transaction: null, target: awareUpgradeTarget });
5368
5456
  showModal($awareUpgradeModal);
5369
5457
  setTimeout(() => {
@@ -5379,30 +5467,51 @@
5379
5467
  if (awareUpdateClient && $awareUpgradeModal) {
5380
5468
  awareUpdateClient.subscribe((s) => {
5381
5469
  const busy = awareBusy(s.status);
5470
+ // The job's OWN operation, not the module variable openAwareUpgrade sets. A repair the
5471
+ // server started never opened the modal, so the variable still says 'runtime-update' and the
5472
+ // pill would announce "Upgrading AWARE…" while it is in fact refreshing bridges.
5473
+ const operation = s.operation || awareUpgradeOperation;
5382
5474
  if ($awareUpdate) {
5383
5475
  $awareUpdate.disabled = busy;
5384
5476
  $awareUpdate.setAttribute('aria-busy', busy ? 'true' : 'false');
5385
5477
  if (busy) {
5386
5478
  $awareUpdate.hidden = false;
5479
+ // The ↑ glyph means "a runtime upgrade is on offer" everywhere else in this footer;
5480
+ // every bridge-repair label deliberately goes without it, and a retry is bridge work.
5387
5481
  $awareUpdate.textContent = s.status === 'retrying'
5388
- ? '↑ Retrying bridge…'
5389
- : awareUpgradeOperation === 'bridge-repair' ? 'Repairing installed bridges…' : '↑ Upgrading AWARE…';
5390
- } else if (s.status === 'partial') {
5391
- $awareUpdate.hidden = false;
5392
- $awareUpdate.textContent = 'Installed bridges need attention';
5482
+ ? 'Retrying bridge…'
5483
+ : operation === 'bridge-repair' ? 'Repairing installed bridges…' : '↑ Upgrading AWARE…';
5484
+ } else if (awareNeedsAttention(s)) {
5485
+ // Every suppressed automatic failure must land on an ENABLED attention pill. Without the
5486
+ // runtime-failed arm the pill stays frozen on "Repairing installed bridges…" forever,
5487
+ // because the modal that would otherwise have explained it never opened.
5488
+ paintAwareAttentionPill();
5393
5489
  }
5394
5490
  }
5395
5491
  _updateApplying = busy ? 'aware' : (_updateApplying === 'aware' ? null : _updateApplying);
5396
5492
  paintAwareUpgrade(s);
5397
5493
  if (s.status === 'partial' || s.status === 'runtime-failed' || s.status === 'expired') {
5398
- if (!$awareUpgradeModal.classList.contains('show')) {
5494
+ // Stealing focus is right for a repair the user CLICKED — they are watching and it carries
5495
+ // recovery actions. It is wrong for one the server started: a modal thrown over the
5496
+ // workspace on launch is precisely the interruption "run it in the background" was chosen
5497
+ // to avoid. The attention pill above carries it instead, and opens this on demand.
5498
+ awareMaintenanceRecover(s);
5499
+ const hijack = s.origin !== 'auto';
5500
+ if (hijack && !$awareUpgradeModal.classList.contains('show')) {
5399
5501
  awareUpgradeReturnFocus = document.activeElement;
5400
5502
  showModal($awareUpgradeModal);
5401
5503
  setTimeout(() => (!$awareUpgradeRetry.hidden ? $awareUpgradeRetry : $awareUpgradeCancel).focus(), 0);
5504
+ } else if (!hijack && awareNeedsAttention(s)) {
5505
+ // Suppressing the modal must not mean suppressing the NEWS. Without this the quieter
5506
+ // outcome was louder than the urgent one: an automatic success toasted, while an
5507
+ // automatic failure — drag-out still broken — changed a footer label nobody was told to
5508
+ // look at. paintAwareUpgrade(s) ran just above, so this copy is already the right one.
5509
+ showToast($awareUpgradeLive.textContent, 'warn');
5402
5510
  }
5403
5511
  refreshAwareUpdate();
5404
5512
  } else if (s.status === 'success') {
5405
5513
  const version = s.observedVersion || s.target;
5514
+ awareMaintenanceRecover(s);
5406
5515
  const wv = document.getElementById('aware-version');
5407
5516
  if (wv && version) {
5408
5517
  wv.textContent = 'AWARE ' + version;
@@ -5443,12 +5552,29 @@
5443
5552
  if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); }
5444
5553
  else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); }
5445
5554
  };
5446
- awareUpdateClient.resume();
5555
+ // SERIALIZED, not fired together. A stored transaction lost across a server restart makes
5556
+ // resume() 404, clear storage, and fall through to the LEASED check route — which blocks
5557
+ // behind a running repair. Awaiting resume() first means adopt() then finds the live job
5558
+ // instead of the browser never learning about it.
5559
+ (async () => {
5560
+ // resume() is allowed to FAIL here — a transaction lost across a server restart is the
5561
+ // ordinary case — and adopt() must still run. Awaiting it unguarded meant one rejected
5562
+ // resume skipped discovery entirely, which is precisely the situation adopt() exists for.
5563
+ try { await awareUpdateClient.resume(); } catch { /* stale transaction; discovery continues */ }
5564
+ await awareUpdateClient.adopt();
5565
+ })().catch(() => {});
5447
5566
  }
5448
5567
 
5449
5568
  if ($awareUpdate) {
5450
5569
  $awareUpdate.onclick = () => {
5451
- if (awareUpdateClient && awareUpdateClient.getState().status === 'partial') {
5570
+ // Both attention states, not just `partial`. A runtime-failed automatic repair paints the
5571
+ // same pill but has no `dataset.operation` (paintAwareAttentionPill does not set it, and the
5572
+ // offer branches that would are now unreachable because awareJobOwnsPill bails first), so it
5573
+ // fell through to the release-notes popover with an empty version — the pill whose tooltip
5574
+ // says "open it to see which bridge" opened the changelog. It also made the failure
5575
+ // unacknowledgeable, since acknowledge only fires when this modal closes, so the warn toast
5576
+ // returned on every load for the full retention window.
5577
+ if (awareUpdateClient && awareNeedsAttention(awareUpdateClient.getState())) {
5452
5578
  openAwareUpgrade('', $awareUpdate);
5453
5579
  return;
5454
5580
  }
@@ -6232,6 +6358,11 @@
6232
6358
  // (installing only) → dim ticker; `status`/`reason` drive the card state.
6233
6359
  if (m.line != null) setBootstrapLogLine(m.line);
6234
6360
  if (m.status) updateBootstrap({ status: m.status, reason: m.reason ?? null, remediation: m.remediation ?? null });
6361
+ } else if (m.type === 'aware-update') {
6362
+ // The server started an automatic bridge repair. Adopt it now so an ALREADY-OPEN tab shows
6363
+ // it immediately; the init-time adopt() only covers tabs opened after it began. adopt() is
6364
+ // single-flight and idempotent, so the two racing is fine.
6365
+ if (window.awareUpdateController) window.awareUpdateController.adopt().catch(() => {});
6235
6366
  } else if (m.type === 'render-progress') {
6236
6367
  // Relayed as a DOM event rather than widening the bridge: workspaces.js owns the Exports
6237
6368
  // card and is the only listener, and a render can outlive several repaints of it.
@@ -93,7 +93,7 @@
93
93
  </div>
94
94
  <span class="ctl-sep" aria-hidden="true"></span>
95
95
  <button id="ws-approve" type="button" class="primary"
96
- data-tip="Locks in this version — your edits already auto-save; this is the sign-off.">✓ Approve</button>
96
+ data-tip="Review every pending change before signing off.">Review &amp; approve</button>
97
97
  </div>
98
98
  <!-- Per-workflow onboarding beacon. Pulses "✨ Start here" while this workflow is
99
99
  new to the user (no first Run completed, not dismissed); calms to a quiet
@@ -578,7 +578,10 @@
578
578
  </div>
579
579
  </div>
580
580
 
581
- <div class="toast-container" id="toast-container"></div>
581
+ <!-- polite live region: toasts are the only channel for a few system conditions the user did not
582
+ trigger (the maintenance-busy refusal above all), and without this a screen-reader user gets
583
+ silence where a sighted user gets an explanation. -->
584
+ <div class="toast-container" id="toast-container" role="status" aria-live="polite"></div>
582
585
 
583
586
  <!-- Reusable styled prompt/form modal — used for node inputs (double-click an
584
587
  input node) and Tweak. Replaces native window.prompt so dialogs match the
@@ -614,6 +617,24 @@
614
617
  </div>
615
618
  </div>
616
619
 
620
+ <!-- Approval is a mandatory review, never a one-click mutation. The server supplies every group
621
+ and all plain-English copy; this surface only records an explicit decision for each group. -->
622
+ <div class="modal-backdrop" id="approval-review-modal" role="dialog" aria-modal="true" aria-labelledby="approval-review-title" aria-describedby="approval-review-sub">
623
+ <div class="modal revreview approval-review" tabindex="-1">
624
+ <div class="modal-title" id="approval-review-title">Review and approve</div>
625
+ <div class="modal-sub" id="approval-review-sub"></div>
626
+ <div class="approval-impact" id="approval-review-impact" role="status" aria-live="polite"></div>
627
+ <div class="revreview-body approval-review-body" id="approval-review-body"></div>
628
+ <div class="approval-review-footer">
629
+ <div class="rev-counts" id="approval-review-counts" role="status" aria-live="polite"></div>
630
+ <div class="modal-actions">
631
+ <button id="approval-review-cancel" type="button">Cancel</button>
632
+ <button id="approval-review-confirm" type="button" class="primary" disabled>Approve selected changes</button>
633
+ </div>
634
+ </div>
635
+ </div>
636
+ </div>
637
+
617
638
  <!-- Convert to the model (steel.takeoff/v1 → steel.model/v2, unit 5, P7e).
618
639
  A SEPARATE element from #revreview-modal rather than a reuse of it: the two have different
619
640
  titles, different sub-copy and materially different Confirm semantics — that one applies a