@floless/app 0.134.2 → 0.134.3

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.
@@ -1705,7 +1705,7 @@
1705
1705
  hostReadinessStates = {};
1706
1706
  renderReadinessState = null;
1707
1707
  track('workspace_project_opened', { app: p.app }); // a real open (card click or post-create landing)
1708
- resetRevisionState(); closeRevReview(); // fresh project — drop any prior revision state and any open review
1708
+ resetRevisionState(); closeRevisionDiscard(false, false); closeRevReview(); // fresh project — drop any prior revision state and any open review
1709
1709
  // Per-project, like everything above it: never let one project's answer describe another's. Not
1710
1710
  // observable today (every history render is preceded by a fetch that sets it, and a failed fetch
1711
1711
  // renders no rows), but leaving a stale cross-project value in place is the shape of bug this
@@ -1831,6 +1831,7 @@
1831
1831
  // `revReviewState.projectId` still named the project the user had just left — so confirming would
1832
1832
  // have applied a review to a project that was no longer on screen. The card is hidden two lines
1833
1833
  // down for the same reason; the modal was simply missed.
1834
+ closeRevisionDiscard(false, false);
1834
1835
  closeRevReview();
1835
1836
  // from the OPEN project's contract and is what gates the `⋯` menu item — left set, the landing
1836
1837
  // kebab for the project just closed would still offer "Convert to the 3D model…", and clicking it
@@ -5592,6 +5593,10 @@
5592
5593
  // no SSE hook — and refreshes History on completion. Cards are DOM-built (textContent, never
5593
5594
  // innerHTML) so an AI-supplied error string can never reach the DOM as markup.
5594
5595
  let lastRevState = 'none';
5596
+ // A reconstruction refusal is permanent for that immutable staged generation. Remember it for this
5597
+ // browser session so the 3-second request poll cannot resurrect a Review action that the server has
5598
+ // already proved will never work. The exact stage id keeps a later replacement generation eligible.
5599
+ const unavailableRevisionReviewStages = new Set();
5595
5600
  let revBaseVersion = 0; // the ledger head captured at attach — success = the head advances past it
5596
5601
  let revBaseProject = null; // …and WHICH project it was captured in; a baseline means nothing anywhere else
5597
5602
  let revCardReq = null;
@@ -5632,6 +5637,18 @@
5632
5637
  $revisionCard.replaceChildren();
5633
5638
  }
5634
5639
  const isInitialRevisionRead = (req) => !req || !req.baseVersion || req.baseVersion <= 0;
5640
+ function isRevisionStale(req) {
5641
+ return !!req && Number.isInteger(req.baseVersion) && Number.isInteger(req.headVersion)
5642
+ && req.baseVersion !== req.headVersion;
5643
+ }
5644
+ function canDiscardRevision(req) {
5645
+ if (!req || req.canDiscardRevision !== true) return false;
5646
+ if (typeof req.stageId === 'string' && req.stageId.trim().length > 0) return true;
5647
+ // An audited staged request can lose its pointer/record identity to a torn or corrupt write. Its
5648
+ // server cleanup removes the opaque request directory before the request row, so it remains safe
5649
+ // to offer Discard even though there is no generation token the browser could honestly send.
5650
+ return req.status === 'staged' && req.steelAuditPolicy === 1;
5651
+ }
5635
5652
  function stopRevisionPoll() { if (revisionPoll) { clearInterval(revisionPoll); revisionPoll = null; } }
5636
5653
  function startRevisionPoll() {
5637
5654
  stopRevisionPoll();
@@ -5755,14 +5772,45 @@
5755
5772
  function buildStagedCard(req) {
5756
5773
  // A STATIC dot, not the pending spinner: the read has finished and nothing is in flight. The
5757
5774
  // spinner would say the opposite, and this state can sit here indefinitely — it waits on a person.
5775
+ const stale = isRevisionStale(req);
5776
+ const hasGeneration = typeof req.stageId === 'string' && req.stageId.trim().length > 0;
5777
+ const reviewUnavailable = hasGeneration && unavailableRevisionReviewStages.has(req.stageId);
5778
+ const canDiscard = canDiscardRevision(req);
5758
5779
  const dot = revEl('span', 'wrc-dot'); dot.setAttribute('aria-hidden', 'true');
5759
5780
  const txt = revEl('span', 'wrc-text');
5760
- txt.appendChild(revEl('b', null, 'A revision is ready for your review.'));
5761
- txt.appendChild(document.createTextNode(' Nothing has been applied yet — decide what this read may change.'));
5781
+ txt.appendChild(revEl('b', null, !hasGeneration || reviewUnavailable ? 'This revision is unavailable.' : stale ? 'This revision can’t be applied.' : 'A revision is ready for your review.'));
5782
+ txt.appendChild(document.createTextNode(!hasGeneration || reviewUnavailable
5783
+ ? reviewUnavailable
5784
+ ? canDiscard
5785
+ ? ' The original proposal cannot be reconstructed. Discard this read, then attach the drawing set again.'
5786
+ : ' The original proposal cannot be reconstructed.'
5787
+ : canDiscard
5788
+ ? ' The staged generation could not be recovered. Discard this read, then attach the drawing set again.'
5789
+ : ' The staged generation could not be recovered.'
5790
+ : stale
5791
+ ? canDiscard
5792
+ ? ` This read started from v${req.baseVersion}, but the project is now at v${req.headVersion}. View its proposed changes or discard it, then attach the drawing set again.`
5793
+ : ` This read started from v${req.baseVersion}, but the project is now at v${req.headVersion}. View its proposed changes. Release the current owner, then return here to discard it before attaching the drawing set again.`
5794
+ : canDiscard
5795
+ ? ' Nothing has been applied yet — review what this read may change, or discard it to attach another set.'
5796
+ : ' Nothing has been applied yet — review what this read may change.'));
5797
+ if (!canDiscard && req.discardWhy) {
5798
+ txt.appendChild(document.createTextNode(` ${req.discardWhy} When that ownership is released, return here to discard the read safely.`));
5799
+ } else if (!canDiscard && req.canClear === false) {
5800
+ txt.appendChild(document.createTextNode(` ${req.clearWhy || 'FloLess cannot safely release this drawing read yet.'} Open Requests for the available recovery.`));
5801
+ }
5762
5802
  const actions = revEl('span', 'wrc-actions');
5763
- const review = revEl('button', 'btn-mini', 'Review changes');
5764
- review.type = 'button'; review.dataset.revreview = ''; review.dataset.commandId = 'shell.revision-review-open';
5765
- actions.appendChild(review);
5803
+ if (hasGeneration && !reviewUnavailable) {
5804
+ const review = revEl('button', 'btn-mini', stale ? 'View proposed changes' : 'Review changes');
5805
+ review.type = 'button'; review.dataset.revreview = ''; review.dataset.commandId = 'shell.revision-review-open';
5806
+ actions.appendChild(review);
5807
+ }
5808
+ if (canDiscard) {
5809
+ const discard = revEl('button', 'btn-mini wrc-discard', 'Discard read…');
5810
+ discard.type = 'button'; discard.dataset.revdiscard = ''; discard.dataset.commandId = 'shell.revision-discard-open';
5811
+ discard.setAttribute('data-tip', 'Remove this staged drawing read without changing the model or History');
5812
+ actions.appendChild(discard);
5813
+ }
5766
5814
  return [dot, txt, actions];
5767
5815
  }
5768
5816
  function buildFailedCard(req) {
@@ -5929,13 +5977,15 @@
5929
5977
  // and the modal is the authority on this request until it closes. If the request vanished from
5930
5978
  // under it, the modal's own confirm learns that from the server and closes; the next tick then
5931
5979
  // paints the truth.
5932
- if (revReviewState) return;
5933
- const cardKey = `${state}:${revCardReq ? revCardReq.id : ''}:${pending && pending.filterSaved ? 'filter-saved' : pending && pending.prepassReady ? 'filter-ready' : 'read-pending'}:${pending && pending.run ? pending.run.state || '' : ''}`;
5980
+ if (revReviewState || revDiscardState) return;
5981
+ const cardKey = `${state}:${revCardReq ? revCardReq.id : ''}:${pending && pending.filterSaved ? 'filter-saved' : pending && pending.prepassReady ? 'filter-ready' : 'read-pending'}:${pending && pending.run ? pending.run.state || '' : ''}`
5982
+ + (staged ? `:${staged.baseVersion}:${staged.headVersion}:${staged.stageId || ''}:${staged.canDiscardRevision === true}:${staged.discardState || ''}:${staged.discardWhy || ''}:${staged.canClear === true}:${staged.clearWhy || ''}:${unavailableRevisionReviewStages.has(staged.stageId)}` : '');
5934
5983
  if ($revisionCard._renderKey === cardKey && !$revisionCard.hidden) return; // preserve focus across the 3 s poll
5935
5984
  const restoreFocus = typeof document !== 'undefined' && $revisionCard.contains(document.activeElement);
5936
5985
  $revisionCard._renderKey = cardKey;
5937
5986
  $revisionCard.className = 'ws-revision-card state-' + state
5938
- + (pending && pending.filterSaved ? ' state-filter-saved' : pending && pending.prepassReady ? ' state-filter-ready' : '');
5987
+ + (pending && pending.filterSaved ? ' state-filter-saved' : pending && pending.prepassReady ? ' state-filter-ready' : '')
5988
+ + (staged && isRevisionStale(staged) ? ' state-stale' : '');
5939
5989
  $revisionCard.replaceChildren(...(
5940
5990
  state === 'failed' ? buildFailedCard(failed)
5941
5991
  : state === 'staged' ? buildStagedCard(staged)
@@ -5968,10 +6018,35 @@
5968
6018
  frame.src = frame.dataset.want;
5969
6019
  }
5970
6020
 
6021
+ /**
6022
+ * Close the load race between the base Drawing Filter navigation and the async request poll.
6023
+ *
6024
+ * `syncDrawingRevisionRequest` can update `dataset.want` while the iframe is still booting the URL
6025
+ * assigned by `setStep`. In that window the child bridge does not exist yet, and the older navigation
6026
+ * can finish after the sync attempt, leaving the parent authoritative target on the checkpoint while
6027
+ * the visible child stays on the empty base URL. Reconcile after every child load, when its final URL
6028
+ * is observable. Exact path + query equality prevents a reload loop and preserves the bridge path for
6029
+ * an already-loaded editor with unsaved facet changes.
6030
+ */
6031
+ function reconcileDrawingRevisionRequestAfterLoad() {
6032
+ const frame = frames.drawings;
6033
+ if (!frame?.dataset.loaded || !frame.dataset.want) return;
6034
+ try {
6035
+ const wanted = new URL(frame.dataset.want, location.origin);
6036
+ const shown = new URL(frame.contentWindow.location.href);
6037
+ if (shown.pathname === wanted.pathname && shown.search === wanted.search) return;
6038
+ } catch { /* the loaded child is not ready/same-origin — navigate to the authoritative target */ }
6039
+ frame.src = frame.dataset.want;
6040
+ }
6041
+ frames.drawings.addEventListener('load', () => {
6042
+ requestAnimationFrame(reconcileDrawingRevisionRequestAfterLoad);
6043
+ });
6044
+
5971
6045
  function focusDrawingFilterSave() {
5972
6046
  const frame = frames.drawings;
5973
6047
  if (!frame) return;
5974
6048
  let onLoad;
6049
+ const focusTarget = frame.dataset.want;
5975
6050
  const focusSave = () => {
5976
6051
  try {
5977
6052
  const shown = new URL(frame.contentWindow.location.href);
@@ -5990,8 +6065,16 @@
5990
6065
  return true;
5991
6066
  } catch { return false; }
5992
6067
  };
5993
- onLoad = () => requestAnimationFrame(() => { if (!focusSave()) frame.focus(); });
5994
- frame.addEventListener('load', onLoad, { once: true });
6068
+ onLoad = () => requestAnimationFrame(() => {
6069
+ // The promised target belongs to the exact request/project that rendered the CTA. If navigation
6070
+ // retires it before the load settles, drop this listener rather than focusing a later project.
6071
+ if (frame.dataset.want !== focusTarget) { frame.removeEventListener('load', onLoad); return; }
6072
+ if (!focusSave()) frame.focus();
6073
+ });
6074
+ // Keep listening until `focusSave()` reaches the promised target. A stale/base load may fire
6075
+ // first and be followed by `reconcileDrawingRevisionRequestAfterLoad`'s authoritative checkpoint
6076
+ // navigation; `{ once:true }` would consume the promise on that intermediate document.
6077
+ frame.addEventListener('load', onLoad);
5995
6078
  if (!focusSave()) frame.focus();
5996
6079
  }
5997
6080
 
@@ -6018,6 +6101,8 @@
6018
6101
  if (!req) return;
6019
6102
  if (e.target.closest('[data-revreview]')) {
6020
6103
  openRevisionReview(req);
6104
+ } else if (e.target.closest('[data-revdiscard]')) {
6105
+ openRevisionDiscard(req, e.target.closest('[data-revdiscard]'));
6021
6106
  } else if (e.target.closest('[data-revcopy]') && bridge.copyRequest) {
6022
6107
  const copyButton = e.target.closest('[data-revcopy]');
6023
6108
  await copyRevisionCardRequest(req, copyButton);
@@ -6039,13 +6124,22 @@
6039
6124
  // the arrays it sent. So this render must preserve the order it was given, and must never filter or
6040
6125
  // re-sort a bucket — an index is only meaningful against the array it was shown in.
6041
6126
  const $revReview = document.getElementById('revreview-modal');
6127
+ const $revReviewTitle = document.getElementById('revreview-title');
6042
6128
  const $revReviewBody = document.getElementById('revreview-body');
6043
6129
  const $revReviewCounts = document.getElementById('revreview-counts');
6044
6130
  const $revReviewChanged = document.getElementById('revreview-changed');
6045
6131
  const $revReviewSub = document.getElementById('revreview-sub');
6046
6132
  const $revReviewConfirm = document.getElementById('revreview-confirm');
6047
6133
  const $revReviewCancel = document.getElementById('revreview-cancel');
6048
- let revReviewState = null; // { projectId, requestId, stageId, summary, returnFocus }
6134
+ const $revReviewDiscard = document.getElementById('revreview-discard');
6135
+ const $revDiscard = document.getElementById('revdiscard-modal');
6136
+ const $revDiscardDialog = $revDiscard.querySelector('.revision-discard');
6137
+ const $revDiscardSub = document.getElementById('revdiscard-sub');
6138
+ const $revDiscardError = document.getElementById('revdiscard-error');
6139
+ const $revDiscardCancel = document.getElementById('revdiscard-cancel');
6140
+ const $revDiscardConfirm = document.getElementById('revdiscard-confirm');
6141
+ let revReviewState = null; // { projectId, requestId, stageId, summary, request, stale, returnFocus }
6142
+ let revDiscardState = null; // { projectId, requestId, stageId, request, returnFocus, reviewWasOpen, terminal, coveredRoots }
6049
6143
 
6050
6144
  /** `elevation_in` → `Elevation in`. A fallback, not a dictionary — the keys are schema names. */
6051
6145
  const prettyKey = (k) => String(k).replace(/_/g, ' ').replace(/^./, (c) => c.toUpperCase());
@@ -6396,7 +6490,12 @@
6396
6490
  return g;
6397
6491
  }
6398
6492
 
6399
- function renderReview(summary) {
6493
+ /** A stale revision remains useful evidence, but none of its decision controls tell the truth. */
6494
+ function makeRevisionReviewReadOnly(root) {
6495
+ root.querySelectorAll('.rev-check, .rev-group-actions').forEach((control) => control.remove());
6496
+ }
6497
+
6498
+ function renderReview(summary, { readOnly = false } = {}) {
6400
6499
  // COUNTS: one quiet line, and never "0 of X" — the zero clause is simply omitted.
6401
6500
  // The numbers carry a <b>, so the two figures worth scanning stand out of the muted sentence —
6402
6501
  // the rule for it existed and nothing emitted the element.
@@ -6410,7 +6509,9 @@
6410
6509
  $revReviewCounts.appendChild(revEl('b', null, n));
6411
6510
  $revReviewCounts.appendChild(document.createTextNode(rest));
6412
6511
  });
6413
- $revReviewCounts.appendChild(document.createTextNode(' — what the read was sure of, already taken.'));
6512
+ $revReviewCounts.appendChild(document.createTextNode(readOnly
6513
+ ? ' — what this read was sure of when it was prepared.'
6514
+ : ' — what the read was sure of, already taken.'));
6414
6515
  $revReviewCounts.hidden = false;
6415
6516
  } else { $revReviewCounts.hidden = true; }
6416
6517
 
@@ -6426,12 +6527,12 @@
6426
6527
  : 'This read found no changes to make — the revised set matches what is already in the model.'));
6427
6528
  }
6428
6529
  if (props.length) {
6429
- const g = group('Needs your decision', props.length, 'proposals');
6530
+ const g = group(readOnly ? 'Changes this read proposed' : 'Needs your decision', props.length, 'proposals');
6430
6531
  props.forEach((p, i) => g.appendChild(proposalRow(p, i, 'proposals')));
6431
6532
  body.appendChild(g);
6432
6533
  }
6433
6534
  if (binds.length) {
6434
- const g = group('Evidence links', binds.length, 'bindingProposals');
6535
+ const g = group(readOnly ? 'Evidence links this read proposed' : 'Evidence links', binds.length, 'bindingProposals');
6435
6536
  binds.forEach((b, i) => g.appendChild(bindingRow(b, i)));
6436
6537
  body.appendChild(g);
6437
6538
  }
@@ -6454,6 +6555,7 @@
6454
6555
  }
6455
6556
  body.appendChild(det);
6456
6557
  }
6558
+ if (readOnly) makeRevisionReviewReadOnly(body);
6457
6559
  $revReviewBody.replaceChildren(body);
6458
6560
  }
6459
6561
 
@@ -6470,16 +6572,22 @@
6470
6572
  * Safe to call unconditionally, which is what lets `closeProject` use it: it clears a class, nulls
6471
6573
  * the state, restores focus, and `renderRevisionCard` returns immediately when no project is open.
6472
6574
  */
6473
- function closeRevReview() {
6575
+ function closeRevReview(restoreFocus = true) {
6474
6576
  const wasOpen = !!revReviewState;
6577
+ if (revDiscardState?.reviewWasOpen) closeRevisionDiscard(false, false);
6475
6578
  $revReview.classList.remove('show');
6476
6579
  const st = revReviewState;
6477
6580
  revReviewState = null;
6581
+ $revReviewTitle.textContent = 'Review this read';
6478
6582
  $revReviewChanged.hidden = true;
6479
6583
  $revReviewConfirm.disabled = false;
6584
+ $revReviewConfirm.hidden = false;
6585
+ $revReviewDiscard.hidden = true;
6480
6586
  const back = st && st.returnFocus;
6481
- if (back instanceof HTMLElement && back.isConnected) back.focus();
6482
- else { const b = $revisionCard.querySelector('[data-revreview]'); if (b) b.focus(); }
6587
+ if (restoreFocus) {
6588
+ if (back instanceof HTMLElement && back.isConnected) back.focus();
6589
+ else { const b = $revisionCard.querySelector('[data-revreview]'); if (b) b.focus(); }
6590
+ }
6483
6591
  // Only when something was actually open — otherwise every `closeProject` would fire a stray fetch.
6484
6592
  if (wasOpen) renderRevisionCard();
6485
6593
  }
@@ -6488,33 +6596,190 @@
6488
6596
  if (!current || !req) return;
6489
6597
  const projectId = current.id;
6490
6598
  const returnFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
6599
+ const trigger = returnFocus?.closest?.('[data-revreview]') || null;
6600
+ const triggerLabel = trigger?.textContent || '';
6601
+ if (trigger) {
6602
+ trigger.disabled = true;
6603
+ trigger.setAttribute('aria-busy', 'true');
6604
+ trigger.textContent = 'Loading review…';
6605
+ }
6491
6606
  let body;
6492
6607
  try {
6493
6608
  body = await api(`/api/projects/${encodeURIComponent(projectId)}/revision-read/staged?requestId=${encodeURIComponent(req.id)}`);
6494
6609
  } catch (err) {
6610
+ if (err && err.body && ['revision-base-unavailable', 'stage-unavailable'].includes(err.body.code)
6611
+ && typeof err.body.stageId === 'string' && err.body.stageId.trim().length > 0) {
6612
+ // The GET reads the pointer that is current at request time; another tab may have replaced the
6613
+ // card's generation already. Retire the exact generation the server rejected, never the stale
6614
+ // card token. Temporary read/recovery errors use a different code and remain retryable.
6615
+ unavailableRevisionReviewStages.add(err.body.stageId);
6616
+ }
6495
6617
  showToast('Could not load the review: ' + ((err && err.message) || err), 'warn');
6496
6618
  renderRevisionCard();
6497
6619
  return;
6620
+ } finally {
6621
+ if (trigger?.isConnected) {
6622
+ trigger.disabled = false;
6623
+ trigger.removeAttribute('aria-busy');
6624
+ trigger.textContent = triggerLabel;
6625
+ }
6498
6626
  }
6499
6627
  if (!current || current.id !== projectId) return; // switched projects during the fetch
6500
6628
  const summary = body && body.staged;
6501
6629
  if (!summary) { showToast('That review is no longer available', 'warn'); renderRevisionCard(); return; }
6630
+ // THE GET OWNS THE MODAL STATE. The card is a polled snapshot and the History head can advance
6631
+ // between clicking its Review action and this response arriving. Reusing the card's versions here
6632
+ // briefly exposed Apply for a review the server had already classified read-only. Fail closed on an
6633
+ // incomplete response rather than mixing one generation's rows with another generation's controls.
6634
+ if (typeof body.readOnly !== 'boolean' || !Number.isInteger(body.baseVersion) || !Number.isInteger(body.headVersion)) {
6635
+ showToast('Could not load the review: the server returned an incomplete review state', 'warn');
6636
+ renderRevisionCard();
6637
+ return;
6638
+ }
6639
+ const readOnly = body.readOnly;
6640
+ const reviewRequest = {
6641
+ ...req,
6642
+ baseVersion: body.baseVersion,
6643
+ headVersion: body.headVersion,
6644
+ stageId: summary.stageId,
6645
+ };
6502
6646
  // RENDER BEFORE ADOPTING THE STATE — the same ordering the 409 path was fixed to use, and this was
6503
6647
  // the arm that still had it backwards. `revReviewState` is what makes `renderRevisionCard` skip its
6504
6648
  // repaint, so setting it first and then throwing inside `renderReview` left the guard latched with
6505
6649
  // no modal on screen: the card would never repaint again for the life of the page.
6506
- $revReviewSub.textContent = 'Nothing is applied until you confirm. Everything starts unticked — tick what this read may change.';
6650
+ $revReviewTitle.textContent = readOnly ? 'This read is out of date' : 'Review this read';
6651
+ $revReviewSub.textContent = readOnly
6652
+ ? `This read started from v${reviewRequest.baseVersion}, but the project is now at v${reviewRequest.headVersion}. It can’t be applied to the current model. The proposal below is for reference only.`
6653
+ : 'Nothing is applied until you confirm. Everything starts unticked — tick what this read may change.';
6507
6654
  $revReviewChanged.hidden = true;
6508
- renderReview(summary);
6509
- revReviewState = { projectId, requestId: req.id, stageId: summary.stageId, summary, returnFocus };
6655
+ renderReview(summary, { readOnly });
6656
+ revReviewState = { projectId, requestId: req.id, stageId: summary.stageId, summary, request: reviewRequest, stale: readOnly, returnFocus };
6657
+ $revReviewConfirm.hidden = readOnly;
6658
+ $revReviewDiscard.hidden = !canDiscardRevision(reviewRequest);
6510
6659
  $revReview.classList.add('show');
6511
6660
  const first = $revReviewBody.querySelector('input[type="checkbox"]');
6512
6661
  (first || $revReviewCancel).focus();
6513
6662
  }
6514
6663
 
6664
+ function openRevisionDiscard(req, returnFocus = document.activeElement) {
6665
+ if (!current || !canDiscardRevision(req)) return;
6666
+ const reviewWasOpen = !!revReviewState;
6667
+ // The confirmation is the only active root whether it opens over the review or directly over the
6668
+ // workspace. Preserve exact prior states because another modal can already be layered underneath.
6669
+ const coveredRoots = [document.getElementById('app'), ...document.querySelectorAll('.modal-backdrop.show')]
6670
+ .filter((root) => root && root !== $revDiscard)
6671
+ .map((root) => ({ root, inert: !!root.inert, ariaHidden: root.getAttribute('aria-hidden') }));
6672
+ for (const { root } of coveredRoots) { root.inert = true; root.setAttribute('aria-hidden', 'true'); }
6673
+ revDiscardState = {
6674
+ projectId: current.id,
6675
+ requestId: req.id,
6676
+ stageId: req.stageId,
6677
+ request: req,
6678
+ returnFocus: returnFocus instanceof HTMLElement ? returnFocus : null,
6679
+ reviewWasOpen,
6680
+ terminal: false,
6681
+ coveredRoots,
6682
+ };
6683
+ const stale = isRevisionStale(req);
6684
+ $revDiscardSub.textContent = stale
6685
+ ? `This permanently removes the staged review based on v${req.baseVersion}. It does not change the current project at v${req.headVersion} or its History. To read these drawings again, attach the set again.`
6686
+ : 'This permanently removes this staged review. It does not change the model or History. To read these drawings again, attach the set again.';
6687
+ $revDiscardError.hidden = true;
6688
+ $revDiscardError.textContent = '';
6689
+ $revDiscardConfirm.hidden = false;
6690
+ $revDiscardConfirm.disabled = false;
6691
+ $revDiscardConfirm.textContent = 'Discard read';
6692
+ $revDiscardCancel.disabled = false;
6693
+ $revDiscardCancel.textContent = 'Keep review';
6694
+ $revDiscard.classList.add('show');
6695
+ $revDiscardCancel.focus();
6696
+ }
6697
+
6698
+ function closeRevisionDiscard(restoreFocus = true, settleTerminal = true) {
6699
+ const st = revDiscardState;
6700
+ revDiscardState = null;
6701
+ $revDiscard.classList.remove('show');
6702
+ $revDiscardDialog.removeAttribute('aria-busy');
6703
+ $revDiscardError.hidden = true;
6704
+ $revDiscardError.textContent = '';
6705
+ $revDiscardConfirm.hidden = false;
6706
+ $revDiscardConfirm.disabled = false;
6707
+ $revDiscardConfirm.removeAttribute('aria-busy');
6708
+ $revDiscardConfirm.textContent = 'Discard read';
6709
+ $revDiscardCancel.disabled = false;
6710
+ $revDiscardCancel.textContent = 'Keep review';
6711
+ for (const covered of st?.coveredRoots || []) {
6712
+ covered.root.inert = covered.inert;
6713
+ if (covered.ariaHidden === null) covered.root.removeAttribute('aria-hidden');
6714
+ else covered.root.setAttribute('aria-hidden', covered.ariaHidden);
6715
+ }
6716
+ if (settleTerminal && st?.terminal) {
6717
+ if (st.reviewWasOpen && revReviewState) closeRevReview(false);
6718
+ const focusRecovery = () => {
6719
+ if (current && current.id === st.projectId) requestAnimationFrame(() => document.getElementById('ws-attach-revision')?.focus());
6720
+ };
6721
+ // Focus recovery must not wait behind the card's network poll. `/api/requests` deliberately has
6722
+ // no client timeout, so a stalled server would otherwise leave focus parked in hidden modal chrome.
6723
+ focusRecovery();
6724
+ try { Promise.resolve(renderRevisionCard()).catch(() => {}); } catch (_) { /* focus is already safe */ }
6725
+ } else if (restoreFocus && st?.returnFocus instanceof HTMLElement && st.returnFocus.isConnected) st.returnFocus.focus();
6726
+ }
6727
+
6728
+ async function confirmRevisionDiscard() {
6729
+ const st = revDiscardState;
6730
+ if (!st || st.terminal) return;
6731
+ $revDiscardError.hidden = true;
6732
+ $revDiscardDialog.setAttribute('aria-busy', 'true');
6733
+ $revDiscardConfirm.disabled = true;
6734
+ $revDiscardConfirm.setAttribute('aria-busy', 'true');
6735
+ $revDiscardConfirm.textContent = 'Discarding…';
6736
+ $revDiscardCancel.disabled = true;
6737
+ try {
6738
+ await api(`/api/projects/${encodeURIComponent(st.projectId)}/revision-read/discard`, {
6739
+ method: 'POST', body: JSON.stringify({ requestId: st.requestId, stageId: st.stageId }),
6740
+ });
6741
+ } catch (error) {
6742
+ const code = error?.body?.code;
6743
+ const terminal = ['stage-superseded', 'revision-request-retired', 'revision-request-discarded'].includes(code);
6744
+ const conflictMessage = code === 'stage-superseded'
6745
+ ? 'A newer review is now available. Close this message and reopen the current review before discarding it.'
6746
+ : code === 'revision-request-retired'
6747
+ ? 'This review was applied elsewhere and is no longer available. Close this message to see the current project.'
6748
+ : 'This drawing read has already been discarded. Close this message to attach the set again.';
6749
+ $revDiscardError.textContent = terminal
6750
+ ? conflictMessage
6751
+ : `Couldn’t discard this read. ${(error && error.message) || 'Try again.'}`;
6752
+ $revDiscardError.hidden = false;
6753
+ $revDiscardDialog.removeAttribute('aria-busy');
6754
+ $revDiscardCancel.disabled = false;
6755
+ if (terminal) {
6756
+ st.terminal = true;
6757
+ $revDiscardConfirm.hidden = true;
6758
+ $revDiscardCancel.textContent = 'Close';
6759
+ $revDiscardCancel.focus();
6760
+ if (bridge.loadRequests) bridge.loadRequests().catch(() => {});
6761
+ } else {
6762
+ $revDiscardConfirm.disabled = false;
6763
+ $revDiscardConfirm.removeAttribute('aria-busy');
6764
+ $revDiscardConfirm.textContent = 'Discard read';
6765
+ }
6766
+ return;
6767
+ }
6768
+ const reviewWasOpen = st.reviewWasOpen;
6769
+ lastRevState = 'none';
6770
+ closeRevisionDiscard(false, false);
6771
+ if (reviewWasOpen && revReviewState) closeRevReview();
6772
+ else await renderRevisionCard();
6773
+ if (bridge.loadRequests) bridge.loadRequests().catch(() => {});
6774
+ showToast('Drawing read discarded — you can attach a revised set again', 'ok');
6775
+ if (current && current.id === st.projectId) {
6776
+ requestAnimationFrame(() => document.getElementById('ws-attach-revision')?.focus());
6777
+ }
6778
+ }
6779
+
6515
6780
  async function confirmRevisionReview() {
6516
6781
  const st = revReviewState;
6517
- if (!st) return;
6782
+ if (!st || st.stale) return;
6518
6783
  const accept = { proposals: [], bindingProposals: [] };
6519
6784
  for (const box of $revReviewBody.querySelectorAll('input[type="checkbox"]:checked')) {
6520
6785
  const bucket = box.dataset.revbucket;
@@ -6595,12 +6860,36 @@
6595
6860
  const on = bulk.dataset.revbulkon === '1';
6596
6861
  for (const box of $revReviewBody.querySelectorAll(`input[data-revbucket="${bulk.dataset.revbulk}"]`)) box.checked = on;
6597
6862
  });
6863
+ $revReviewDiscard.addEventListener('click', (e) => {
6864
+ const st = revReviewState;
6865
+ if (st) openRevisionDiscard({ ...st.request, stageId: st.stageId }, e.currentTarget);
6866
+ });
6598
6867
  $revReviewConfirm.addEventListener('click', confirmRevisionReview);
6599
6868
  $revReviewCancel.addEventListener('click', closeRevReview);
6600
6869
  onBackdropDismiss($revReview, closeRevReview, () => !$revReviewConfirm.disabled);
6601
6870
  $revReview.addEventListener('keydown', (e) => {
6602
6871
  if (e.key === 'Escape') { e.preventDefault(); if (!$revReviewConfirm.disabled) closeRevReview(); }
6603
6872
  });
6873
+ $revDiscardCancel.addEventListener('click', () => closeRevisionDiscard());
6874
+ $revDiscardConfirm.addEventListener('click', confirmRevisionDiscard);
6875
+ onBackdropDismiss($revDiscard, () => closeRevisionDiscard(), () => !$revDiscardDialog.hasAttribute('aria-busy'));
6876
+ document.addEventListener('keydown', (e) => {
6877
+ if (!$revDiscard.classList.contains('show')) return;
6878
+ if (e.key === 'Escape') {
6879
+ e.preventDefault(); e.stopPropagation();
6880
+ if (!$revDiscardDialog.hasAttribute('aria-busy')) closeRevisionDiscard();
6881
+ } else if (e.key === 'Tab') {
6882
+ const focusable = [...$revDiscard.querySelectorAll('button:not([disabled]):not([hidden]), [tabindex]:not([tabindex="-1"])')]
6883
+ .filter((el) => el instanceof HTMLElement && !el.hidden && el.getClientRects().length);
6884
+ if (!focusable.length) { e.preventDefault(); return; }
6885
+ const first = focusable[0], last = focusable[focusable.length - 1];
6886
+ if (e.shiftKey && (document.activeElement === first || !$revDiscard.contains(document.activeElement))) {
6887
+ e.preventDefault(); last.focus();
6888
+ } else if (!e.shiftKey && (document.activeElement === last || !$revDiscard.contains(document.activeElement))) {
6889
+ e.preventDefault(); first.focus();
6890
+ }
6891
+ }
6892
+ }, true);
6604
6893
 
6605
6894
  // ── History step ────────────────────────────────────────────────────────────────
6606
6895
  // The project's version ledger. A version = a commit (Approve = Model gate, Rollback = unsigned).
@@ -6664,6 +6953,27 @@
6664
6953
  };
6665
6954
  }
6666
6955
 
6956
+ function detailReconciliationWarningHtml(v) {
6957
+ if (!v || v.kind !== 'revision-read') return '';
6958
+ const audit = v.source && v.source.readAudit;
6959
+ const report = audit && audit.report;
6960
+ if (!audit || audit.version !== 1 || !report || report.version !== 1
6961
+ || report.policy !== 'steel-read-completion/v1' || !Array.isArray(report.checks)
6962
+ || !report.counts || report.counts.joints !== 0) return '';
6963
+ const matchingChecks = report.checks.filter((row) => row && typeof row === 'object'
6964
+ && row.id === 'detail-reconciliation');
6965
+ if (matchingChecks.length !== 1) return '';
6966
+ const check = matchingChecks[0];
6967
+ if ((check.status !== 'pass' && check.status !== 'warning') || typeof check.detail !== 'string') return '';
6968
+ const match = /^([1-9]\d*) detail\/connection marker\(s\) reconciled$/.exec(check.detail);
6969
+ if (!match) return '';
6970
+ const markers = Number(match[1]);
6971
+ if (!Number.isSafeInteger(markers)) return '';
6972
+ return '<div class="hist-change-caution" role="note"><span aria-hidden="true">⚠</span> ' +
6973
+ '<strong>Connection details need follow-up.</strong> The read accounted for ' + markers +
6974
+ ' detail/connection markers, but modeled 0 joints in this version.</div>';
6975
+ }
6976
+
6667
6977
  function changeCellHtml(v, meta) {
6668
6978
  const s = v.changeSummary;
6669
6979
  const n = Number(v.n);
@@ -6674,8 +6984,9 @@
6674
6984
  'data-tip="Show the complete member-by-member comparison">' +
6675
6985
  '<span class="hd-caret">▸</span><span class="hd-toggle-label">View detailed changes</span></button>'
6676
6986
  : '';
6987
+ const detailWarning = detailReconciliationWarningHtml(v);
6677
6988
  if (!s || !Array.isArray(s.bullets)) {
6678
- return `<div class="hist-event">${escapeHtml(v.message)}</div>${toggle}`;
6989
+ return `<div class="hist-event">${escapeHtml(v.message)}</div>${detailWarning}${toggle}`;
6679
6990
  }
6680
6991
  const visible = meta.canDiff ? s.bullets.slice(0, 4) : s.bullets;
6681
6992
  const more = s.bullets.length - visible.length;
@@ -6685,7 +6996,7 @@
6685
6996
  ? `<div class="hist-change-caution">⚠ ${escapeHtml(s.cautions.join(' '))}</div>`
6686
6997
  : '';
6687
6998
  return `<div class="hist-change-head">${escapeHtml(String(s.headline || v.message))}</div>` +
6688
- `<ul class="hist-change-list">${bullets}</ul>${cautions}${toggle}`;
6999
+ `<ul class="hist-change-list">${bullets}</ul>${cautions}${detailWarning}${toggle}`;
6689
7000
  }
6690
7001
 
6691
7002
  function versionRowHtml(v) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floless/app",
3
- "version": "0.134.2",
3
+ "version": "0.134.3",
4
4
  "type": "module",
5
5
  "description": "Thin localhost host for floless.app — serves web/ and shells the aware CLI. No engine, no LLM.",
6
6
  "bin": {