@floless/app 0.134.0 → 0.134.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.
@@ -33,6 +33,7 @@
33
33
  const $crumbName = document.getElementById('ws-crumb-name');
34
34
  const $status = document.getElementById('ws-status');
35
35
  const $stepTabs = document.getElementById('ws-step-tabs');
36
+ const $stageGuidance = document.getElementById('ws-stage-guidance');
36
37
  const $projMenu = document.getElementById('ws-proj-menu');
37
38
  const $wsExports = document.getElementById('ws-exports');
38
39
  const $wsHistory = document.getElementById('ws-history');
@@ -267,7 +268,7 @@
267
268
  filter: '/steel-filter.html',
268
269
  steps: [
269
270
  { key: 'knowledge', label: 'Knowledge' }, // per-project KB — the job's context, consulted by everything
270
- { key: 'drawings', label: 'Drawings' },
271
+ { key: 'drawings', label: 'Drawing Filter' },
271
272
  { key: 'model', label: 'Model' },
272
273
  { key: 'exports', label: 'Exports' },
273
274
  { key: 'history', label: 'History' },
@@ -428,16 +429,26 @@
428
429
  * `openProject` assigns it and sits earlier in the file — a `let` further down works only as long as
429
430
  * nothing calls that function during module init, which is not a property worth depending on.
430
431
  *
431
- * Unknown fails closed. Approval and export capability must come from the lifecycle response, never
432
- * from a successful presence request or stale state carried from another project.
432
+ * Unknown still fails closed for actions that require a model. It is not, however, presented as a
433
+ * confirmed stage lock: a project-open probe is routine loading, not evidence that the project is
434
+ * still preliminary.
433
435
  */
434
436
  let projectContractLifecycle = 'unknown';
435
437
  let exportsHasModel = false;
438
+ // A project may open on Model/Exports/History while its lifecycle probe is still in flight. Keep
439
+ // the most recently requested destination until the probe settles so the latest click counts.
440
+ let pendingPresenceStep = null;
441
+ // Dismiss handle for the one user-initiated checking toast. A later tab click replaces it rather
442
+ // than stacking another copy while both clicks attach to the same lifecycle request.
443
+ let pendingPresenceToast = null;
436
444
 
437
445
  /** Sequence number for model-presence probes. A project-id check is NOT a staleness guard: two
438
446
  * probes can be in flight for the SAME project, and an older "absent" answer landing last would
439
447
  * re-disable Approve on a project that now has a model. Every writer bumps it; older results drop. */
440
448
  let modelPresenceGen = 0;
449
+ // One lifecycle request per open project. Tab clicks attach to this promise instead of starting
450
+ // competing four-second probes whose generation guards make all but the last answer disappear.
451
+ let modelPresenceProbe = null;
441
452
 
442
453
  /** The header's AUTHORED tooltip, captured from the static markup so the has-a-model state restores
443
454
  * it verbatim. The first cut substituted "exports unlock after it", which is a FALSE description of
@@ -1681,6 +1692,15 @@
1681
1692
  return;
1682
1693
  }
1683
1694
  current = p;
1695
+ // Project lifecycle is project-scoped. Reset it before the first setStep so one project's model
1696
+ // cannot unlock another project's tabs (or one empty project redirect a modeled project forever).
1697
+ projectContractLifecycle = 'unknown';
1698
+ exportsHasModel = false;
1699
+ modelPresenceGen++;
1700
+ modelPresenceProbe = null;
1701
+ pendingPresenceStep = null;
1702
+ if (pendingPresenceToast) pendingPresenceToast();
1703
+ pendingPresenceToast = null;
1684
1704
  exportState = null;
1685
1705
  hostReadinessStates = {};
1686
1706
  renderReadinessState = null;
@@ -1699,6 +1719,9 @@
1699
1719
  // the 'model' frame loads the app's editor; the 'drawings' frame loads its filter (steel) OR is
1700
1720
  // left empty when the app has no filter step (vectorize — its Source step shows a placeholder).
1701
1721
  const d = wsDescOf(p); // guaranteed present — the guard above bailed on an unknown app
1722
+ if (d.filter && ['model', 'exports', 'history'].includes(initialStep)) {
1723
+ pendingPresenceStep = { projectId: p.id, step: initialStep };
1724
+ }
1702
1725
  // The LIVE app id, deliberately: the frames address the server with it (contract reads, saves),
1703
1726
  // and after a rename only the live id resolves. Only the descriptor came from the lineage root.
1704
1727
  const qs = `?app=${encodeURIComponent(p.app)}&project=${encodeURIComponent(p.id)}`;
@@ -1707,6 +1730,13 @@
1707
1730
  renderStepTabs(); // paint the tab labels for THIS app before the first step shows
1708
1731
  frames.model.src = 'about:blank'; frames.drawings.src = 'about:blank'; // reset any previous project
1709
1732
  frames.model.dataset.loaded = ''; frames.drawings.dataset.loaded = '';
1733
+ // Start the small lifecycle envelope BEFORE the heavier approval review request. Both hit the
1734
+ // same localhost event loop; sending approval first could keep the lifecycle request queued until
1735
+ // its four-second client deadline, falsely leaving an existing model in the checking state. This
1736
+ // promise also owns every tab activation until it settles (refreshModelPresence deduplicates it).
1737
+ refreshModelPresence(p.id, p.app).catch((e) => {
1738
+ console.error('[workspaces] could not resolve model presence', e);
1739
+ });
1710
1740
  // BEFORE the first step renders, and that order is the fix rather than a tidy-up.
1711
1741
  //
1712
1742
  // `initialStep` is not always 'model' — a project re-opened from the picker keeps `currentStep`,
@@ -1720,15 +1750,12 @@
1720
1750
  // this line sees a probe to park on. The waiter is deliberately NOT taught to block on a
1721
1751
  // not-yet-started probe — that would hang any surface rendered outside a project open.
1722
1752
  refreshApprovalState(p.id).catch((e) => console.error('[workspaces] could not load approval state', e));
1723
- setStep(initialStep);
1753
+ // A steel project's lifecycle answer arrives asynchronously. Do not briefly open (or falsely
1754
+ // refuse) a later stage while that answer is unknown: hold the requested destination, show the
1755
+ // first actionable stage, and restore the destination only after an explicit `model` answer.
1756
+ setStep(pendingPresenceStep ? 'drawings' : initialStep);
1724
1757
  applyMode();
1725
1758
  syncWorkspaceGuide(); // point the shared beacon at THIS project's document lifecycle
1726
- // Detached, but never silent: the lifecycle probe cannot reject, yet the code after its await can
1727
- // (stepLabel -> wsApp on a descriptor without steps), and an unhandled rejection would leave the
1728
- // header un-updated with nothing said.
1729
- refreshModelPresence(p.id, p.app).catch((e) => { // gate the header CHECK Approve for THIS project (#490)
1730
- console.error('[workspaces] could not resolve model presence', e);
1731
- });
1732
1759
  }
1733
1760
 
1734
1761
  /**
@@ -1742,11 +1769,43 @@
1742
1769
  * person who needs it — and `approveProject` re-checks the same flag rather than trusting the
1743
1770
  * attribute.
1744
1771
  */
1745
- async function refreshModelPresence(projectId, appId) {
1772
+ async function refreshModelPresence(projectId, appId, supersede = false) {
1773
+ // A caller may attach to a probe that a model-creating mutation supersedes a moment later. Follow
1774
+ // same-project successors until one actually applies, so that caller cannot mistake the stale
1775
+ // probe's completion for an authoritative timeout and show a false retry warning.
1776
+ const awaitAuthoritative = async (initialPromise) => {
1777
+ let observed = initialPromise;
1778
+ let applied = await observed;
1779
+ while (!applied) {
1780
+ const successor = modelPresenceProbe;
1781
+ if (!successor || successor.projectId !== projectId || successor.promise === observed) return false;
1782
+ observed = successor.promise;
1783
+ applied = await observed;
1784
+ }
1785
+ return true;
1786
+ };
1787
+ if (!supersede && modelPresenceProbe?.projectId === projectId) {
1788
+ return awaitAuthoritative(modelPresenceProbe.promise);
1789
+ }
1746
1790
  const gen = ++modelPresenceGen;
1747
- const present = await projectContractState(projectId, appId);
1748
- if (gen !== modelPresenceGen || !current || current.id !== projectId) return; // superseded
1749
- applyModelPresence(present);
1791
+ const promise = (async () => {
1792
+ const present = await projectContractState(projectId, appId);
1793
+ if (gen !== modelPresenceGen || !current || current.id !== projectId) return false; // superseded
1794
+ const restore = pendingPresenceStep?.projectId === projectId ? pendingPresenceStep.step : '';
1795
+ // A timeout/network error is not evidence that this project has no model. Keep the requested
1796
+ // destination so its next activation can retry the probe and restore it after recovery.
1797
+ if (present !== 'unknown') pendingPresenceStep = null;
1798
+ applyModelPresence(present);
1799
+ // Restore only when this same project's authoritative answer says a model exists. A confirmed
1800
+ // preliminary lifecycle remains on Drawing Filter and gets the real prerequisite gate below.
1801
+ if (present === 'model' && restore && currentStep === 'drawings') setStep(restore);
1802
+ return true;
1803
+ })();
1804
+ modelPresenceProbe = { projectId, promise };
1805
+ try { return await awaitAuthoritative(promise); }
1806
+ finally {
1807
+ if (modelPresenceProbe?.promise === promise) modelPresenceProbe = null;
1808
+ }
1750
1809
  }
1751
1810
 
1752
1811
  /** Push the answer to the flag AND the header together, so no two surfaces can disagree. */
@@ -1754,6 +1813,7 @@
1754
1813
  projectContractLifecycle = present;
1755
1814
  exportsHasModel = present === 'model';
1756
1815
  renderApprovalHeader();
1816
+ applyStageGating();
1757
1817
  }
1758
1818
  function closeProject() {
1759
1819
  current = null;
@@ -1779,7 +1839,9 @@
1779
1839
  // was already per-project, the two variables behind it were not.)
1780
1840
  // Reset with the rest of the per-project state — this file resets `histDiffSupported` for exactly
1781
1841
  // this reason. Bumping the generation also voids any probe still in flight for the closing project.
1782
- projectContractLifecycle = 'unknown'; exportsHasModel = false; modelPresenceGen++;
1842
+ projectContractLifecycle = 'unknown'; exportsHasModel = false; modelPresenceGen++; modelPresenceProbe = null; pendingPresenceStep = null;
1843
+ if (pendingPresenceToast) pendingPresenceToast();
1844
+ pendingPresenceToast = null;
1783
1845
  closeProjMenu(); applyMode(); syncWorkspaceGuide(); // revision state cleared by resetRevisionState() above
1784
1846
  }
1785
1847
  document.getElementById('ws-back').addEventListener('click', closeProject);
@@ -1794,11 +1856,167 @@
1794
1856
  const byKey = new Map(d.steps.map((st) => [st.key, st.label]));
1795
1857
  $stepTabs.querySelectorAll('button[data-step]').forEach((b) => {
1796
1858
  const label = byKey.get(b.dataset.step);
1797
- if (label) b.textContent = label;
1859
+ if (label) {
1860
+ b.textContent = label;
1861
+ b.setAttribute('data-command-id', `shell.workspace-step#${label}`);
1862
+ }
1798
1863
  });
1799
1864
  }
1800
1865
 
1866
+ // Keep steel projects stage-by-stage while the first drawing read is in progress. The later tabs
1867
+ // stay visible so the user can see what comes next, but explain their prerequisite instead of
1868
+ // opening empty destinations during a potentially long terminal-AI read.
1869
+ function stageGateFor(step) {
1870
+ const d = wsApp();
1871
+ if (!d || !d.filter || !['model', 'exports', 'history'].includes(step)) return '';
1872
+ const initialRead = revCardReq && isInitialRevisionRead(revCardReq);
1873
+ const waitingForInitial = initialRead && lastRevState === 'pending';
1874
+ const stagedInitial = initialRead && lastRevState === 'staged';
1875
+ const failedInitial = initialRead && lastRevState === 'failed';
1876
+ const unavailableInitial = initialRead && lastRevState === 'unavailable';
1877
+ if (projectContractLifecycle === 'model') return '';
1878
+ if (stagedInitial) return 'The drawing read is complete. Open Drawing Filter and choose Review changes before using the later stages.';
1879
+ if (failedInitial) {
1880
+ if (revCardReq?.canClear === true) return 'The drawing read failed. Return to Drawing Filter, press Dismiss, then attach the drawing set again.';
1881
+ return `${revCardReq?.clearWhy || 'FloLess cannot safely release this drawing read yet.'} Open Requests for the available recovery.`;
1882
+ }
1883
+ if (unavailableInitial) return 'This drawing read uses a status this version of FloLess does not recognize. Open Requests for details and update FloLess before continuing.';
1884
+ // Loading is not a prerequisite failure. setStep keeps the safety boundary by queueing later
1885
+ // stages until this probe produces a real lifecycle answer.
1886
+ if (projectContractLifecycle === 'unknown') return '';
1887
+ if (step === 'model') {
1888
+ if (waitingForInitial && revCardReq?.filterSaved) return 'The Drawing Filter is saved. Return to the same terminal AI session that prepared it and tell it to continue the drawing read.';
1889
+ if (waitingForInitial && revCardReq?.prepassReady) return 'Review the selected lines, then press Save filter. After Save, return to the terminal AI that prepared it and tell it to continue.';
1890
+ if (waitingForInitial) return 'The initial drawing read is waiting for your terminal AI. The model unlocks after you review the Drawing Filter and press Save filter.';
1891
+ if (projectContractLifecycle === 'filter-checkpoint') return 'Attach the drawing set again in Drawing Filter to restart the read. The earlier request is no longer available to receive a saved filter.';
1892
+ return 'Read and save a Drawing Filter first. The model will unlock after the first drawing read.';
1893
+ }
1894
+ if (waitingForInitial) return `The ${step === 'exports' ? 'steel model' : 'first model'} must be ready before ${step === 'exports' ? 'exports' : 'history'} is available.`;
1895
+ if (projectContractLifecycle === 'filter-checkpoint') return `Attach the drawing set again in Drawing Filter before opening ${step === 'exports' ? 'Exports' : 'History'}. The earlier request can no longer continue.`;
1896
+ return `Create the first steel model before opening ${step === 'exports' ? 'Exports' : 'History'}.`;
1897
+ }
1898
+
1899
+ function applyStageGating() {
1900
+ const d = wsApp();
1901
+ if (!$stepTabs) return;
1902
+ if (!d || !d.filter) {
1903
+ // The tab strip is shared across projects. Remove every steel-only gate when switching to an
1904
+ // app without a Drawing Filter, or the next app inherits disabled tabs from the previous one.
1905
+ $stepTabs.querySelectorAll('button[data-step]').forEach((b) => {
1906
+ b.classList.remove('ws-step-locked');
1907
+ b.removeAttribute('aria-disabled');
1908
+ b.removeAttribute('data-stage-locked');
1909
+ b.removeAttribute('data-tip');
1910
+ b.removeAttribute('data-blocked-reason');
1911
+ b.setAttribute('tabindex', '0');
1912
+ });
1913
+ if ($stageGuidance) $stageGuidance.hidden = true;
1914
+ return;
1915
+ }
1916
+ let locked = false;
1917
+ $stepTabs.querySelectorAll('button[data-step]').forEach((b) => {
1918
+ const reason = stageGateFor(b.dataset.step);
1919
+ const isLocked = !!reason;
1920
+ locked ||= isLocked;
1921
+ b.classList.toggle('ws-step-locked', isLocked);
1922
+ b.setAttribute('aria-disabled', String(isLocked));
1923
+ if (isLocked) {
1924
+ b.setAttribute('data-stage-locked', 'true');
1925
+ b.setAttribute('data-tip', reason);
1926
+ b.setAttribute('data-blocked-reason', reason);
1927
+ // Keep locked tabs keyboard-reachable so their prerequisite is available to keyboard users
1928
+ // and to Instructor. Activation is still blocked by the click handler and setStep.
1929
+ b.setAttribute('tabindex', '0');
1930
+ } else {
1931
+ b.removeAttribute('data-stage-locked');
1932
+ b.removeAttribute('aria-disabled');
1933
+ b.removeAttribute('data-tip');
1934
+ b.removeAttribute('data-blocked-reason');
1935
+ b.setAttribute('tabindex', '0');
1936
+ }
1937
+ });
1938
+ // A project opened on the old default Model step can become gated when the lifecycle probe
1939
+ // returns. Move it to the first actionable stage instead of leaving a locked tab selected.
1940
+ if (currentStep !== 'drawings' && stageGateFor(currentStep)) {
1941
+ setStep('drawings');
1942
+ return;
1943
+ }
1944
+ if (!$stageGuidance) return;
1945
+ const initialRead = revCardReq && isInitialRevisionRead(revCardReq);
1946
+ const waitingForInitial = initialRead && lastRevState === 'pending';
1947
+ const stagedInitial = initialRead && lastRevState === 'staged';
1948
+ const failedInitial = initialRead && lastRevState === 'failed';
1949
+ const unavailableInitial = initialRead && lastRevState === 'unavailable';
1950
+ if (!locked) {
1951
+ $stageGuidance.hidden = true;
1952
+ $stageGuidance.textContent = '';
1953
+ return;
1954
+ }
1955
+ $stageGuidance.hidden = false;
1956
+ $stageGuidance.textContent = stagedInitial
1957
+ ? 'The drawing read is complete · Open Drawing Filter and choose Review changes before moving to Model, Exports, or History.'
1958
+ : failedInitial
1959
+ ? (revCardReq?.canClear === true
1960
+ ? 'The drawing read failed · Return to Drawing Filter, press Dismiss, then attach the drawing set again.'
1961
+ : `The drawing read failed · ${revCardReq?.clearWhy || 'FloLess cannot safely release this drawing read yet.'} Open Requests for the available recovery.`)
1962
+ : unavailableInitial
1963
+ ? 'This drawing read uses a status this version of FloLess does not recognize · Open Requests for details and update FloLess before continuing.'
1964
+ : waitingForInitial && revCardReq?.filterSaved
1965
+ ? 'Stage 1 of 4 complete · The Drawing Filter is saved. Return to the same terminal AI session that prepared it and tell it to continue the drawing read. Model, Exports, and History unlock when it finishes.'
1966
+ : waitingForInitial && revCardReq?.prepassReady
1967
+ ? 'Stage 1 of 4 · Review the selected layers, line weights, and colours below. Then press Save filter in the top-right corner, return to the terminal AI that prepared it, and tell it to continue. Model, Exports, and History unlock when the read finishes.'
1968
+ : waitingForInitial
1969
+ ? 'Stage 1 of 4 · Your initial drawing read is waiting for your terminal AI. Open Requests, copy it into Claude Code, Codex, or OpenCode, then return to review and save the Drawing Filter. Model, Exports, and History unlock afterward.'
1970
+ : projectContractLifecycle === 'filter-checkpoint'
1971
+ ? 'Stage 1 of 4 · The earlier drawing request is no longer available. Attach the drawing set again in Drawing Filter to restart the read. Model, Exports, and History unlock after it finishes.'
1972
+ : 'Start in Drawing Filter by attaching a PDF or image. The Model, Exports, and History stages unlock after the first steel model is created.';
1973
+ }
1974
+
1975
+ function deferStageUntilLifecycle(s) {
1976
+ const d = wsApp();
1977
+ if (!current || !d?.filter || projectContractLifecycle !== 'unknown'
1978
+ || !['model', 'exports', 'history'].includes(s)) return false;
1979
+ pendingPresenceStep = { projectId: current.id, step: s };
1980
+ const projectId = current.id;
1981
+ if (pendingPresenceToast) pendingPresenceToast();
1982
+ const intentToast = showToast(`Checking project stages… ${stepLabel(s)} will open when ready.`, 'info');
1983
+ pendingPresenceToast = intentToast;
1984
+ refreshModelPresence(projectId, current.app).then(() => {
1985
+ // A later click owns the shared probe's feedback and destination.
1986
+ if (pendingPresenceToast !== intentToast) return;
1987
+ intentToast();
1988
+ pendingPresenceToast = null;
1989
+ // The request's four-second deadline is a recovery boundary, not a silent discarded click.
1990
+ if (current?.id !== projectId) return;
1991
+ if (projectContractLifecycle === 'unknown') {
1992
+ showToast(`Couldn’t check project stages. Select ${stepLabel(s)} again to retry.`, 'warn');
1993
+ return;
1994
+ }
1995
+ // A confirmed preliminary answer turns the apparent availability into the real prerequisite
1996
+ // gate. Reuse that specific explanation instead of replacing it with generic readiness copy.
1997
+ const reason = stageGateFor(s);
1998
+ if (reason) showToast(reason, 'warn');
1999
+ }).catch((err) => {
2000
+ if (pendingPresenceToast === intentToast) {
2001
+ intentToast();
2002
+ pendingPresenceToast = null;
2003
+ }
2004
+ console.error('[workspaces] tab lifecycle check failed', err);
2005
+ });
2006
+ return true;
2007
+ }
2008
+
1801
2009
  function setStep(s) {
2010
+ // Keep the tab visually available while the routine open-project check runs, but do not cross
2011
+ // the model boundary speculatively. The existing request is reused and this destination opens
2012
+ // automatically if it reports a model; the most recent click wins.
2013
+ if (deferStageUntilLifecycle(s)) return;
2014
+ const lockedReason = stageGateFor(s);
2015
+ if (lockedReason) {
2016
+ if (currentStep !== 'drawings') setStep('drawings');
2017
+ showToast(lockedReason, 'warn');
2018
+ return;
2019
+ }
1802
2020
  currentStep = s;
1803
2021
  $stepTabs.querySelectorAll('button').forEach((b) => {
1804
2022
  const on = b.dataset.step === s;
@@ -1837,9 +2055,16 @@
1837
2055
  // in-flight preview read), and forget the cached state so re-entering re-reads rather than
1838
2056
  // flashing a stale column.
1839
2057
  else { stopKnowledgePoll(); kbCloseConfirm(); kbResetViewer(); knowledgeState = null; }
2058
+ applyStageGating();
1840
2059
  }
1841
2060
  $stepTabs.addEventListener('click', (e) => {
1842
2061
  const b = e.target.closest('button[data-step]');
2062
+ if (b?.getAttribute('aria-disabled') === 'true') {
2063
+ e.preventDefault();
2064
+ const reason = stageGateFor(b.dataset.step);
2065
+ if (reason) showToast(reason, 'warn');
2066
+ return;
2067
+ }
1843
2068
  if (b) setStep(b.dataset.step);
1844
2069
  });
1845
2070
 
@@ -5371,7 +5596,9 @@
5371
5596
  let revBaseProject = null; // …and WHICH project it was captured in; a baseline means nothing anywhere else
5372
5597
  let revCardReq = null;
5373
5598
  let revisionPoll = null;
5374
- let revisionGen = 0; // bumped per render AND by openProject/closeProject — see renderRevisionCard
5599
+ let revisionGen = 0; // newest-wins epoch for overlapping card renders — see renderRevisionCard
5600
+ let revisionOwnerGen = 0; // bumped only when navigation retires actions owned by the current project
5601
+ let revisionAttachGen = 0; // newest Attach owns its delayed copy/modal completion within that project
5375
5602
  let revRequestsFailed = false; // one log per outage, not one per 3-second poll tick
5376
5603
  /**
5377
5604
  * Every piece of revision state above is PER-PROJECT, so opening or closing one must clear all of
@@ -5399,6 +5626,7 @@
5399
5626
  revCardReq = null;
5400
5627
  $revisionCard._renderKey = '';
5401
5628
  revisionGen++; // voids any render still in flight for the project being left
5629
+ revisionOwnerGen++; // voids Attach/Copy work, without letting a routine poll do so
5402
5630
  stopRevisionPoll();
5403
5631
  $revisionCard.hidden = true;
5404
5632
  $revisionCard.replaceChildren();
@@ -5425,28 +5653,40 @@
5425
5653
  });
5426
5654
  }
5427
5655
 
5656
+ async function copyAttachedRevision(req, ownsAttach) {
5657
+ if (!req || !bridge.copyRequest || !ownsAttach()) return false;
5658
+ try {
5659
+ const result = await bridge.copyRequest(req, ownsAttach);
5660
+ return result === 'ok' && ownsAttach();
5661
+ } catch {
5662
+ return false;
5663
+ }
5664
+ }
5665
+
5428
5666
  async function attachRevision(files) {
5429
5667
  const proj = current; // capture — the user may switch projects during the async file reads / POST
5430
5668
  if (!proj || !files.length) return;
5669
+ const projectGeneration = revisionOwnerGen;
5670
+ const attachGeneration = ++revisionAttachGen;
5671
+ const ownsAttach = () => current === proj
5672
+ && revisionOwnerGen === projectGeneration
5673
+ && revisionAttachGen === attachGeneration;
5431
5674
  const returnFocus = document.activeElement;
5432
5675
  let snapshots;
5433
5676
  try { snapshots = await Promise.all(files.map(readFileAsSnapshot)); }
5434
5677
  catch { showToast('Could not read the selected files', 'warn'); return; }
5435
- if (current !== proj) return; // switched projects mid-read — abandon rather than queue against the wrong one
5678
+ if (!ownsAttach()) return; // switched/reopened/attached again mid-read — abandon this stale completion
5436
5679
  let res;
5437
5680
  try {
5438
5681
  res = await api(`/api/projects/${encodeURIComponent(proj.id)}/revision-requests`, {
5439
5682
  method: 'POST', body: JSON.stringify({ appId: proj.app, snapshots }),
5440
5683
  });
5441
- } catch (err) { showToast('Attach failed: ' + ((err && err.message) || err), 'warn'); return; }
5684
+ } catch (err) { if (ownsAttach()) showToast('Attach failed: ' + ((err && err.message) || err), 'warn'); return; }
5442
5685
  const req = res && res.request;
5443
5686
  // Copy the paste-ready instruction so the user can hand it to their terminal AI (best-effort).
5444
- let copied = false;
5445
- if (req && bridge.copyRequest) {
5446
- try { copied = (await bridge.copyRequest(req)) === 'ok'; } catch { copied = false; }
5447
- }
5687
+ const copied = await copyAttachedRevision(req, ownsAttach);
5448
5688
  if (bridge.loadRequests) bridge.loadRequests().catch(() => {}); // refresh the footer Requests popover
5449
- if (current !== proj) return; // switched away while posting — don't drive the wrong project's card/poll
5689
+ if (!ownsAttach()) return; // don't drive a replaced project's card/poll/modal or narrate its Copy
5450
5690
  revBaseVersion = (req && typeof req.baseVersion === 'number') ? req.baseVersion : 0;
5451
5691
  revBaseProject = proj.id; // the baseline belongs to THIS project — see resetRevisionState
5452
5692
  showToast(`${revBaseVersion <= 0 ? 'Initial' : 'Revised'} set queued — ${files.length} file${files.length > 1 ? 's' : ''} for your terminal AI`, 'ok');
@@ -5465,25 +5705,52 @@
5465
5705
 
5466
5706
  function buildPendingCard(req) {
5467
5707
  const n = (req.sourceRefs && req.sourceRefs.length) || (req.snapshots && req.snapshots.length) || 1;
5708
+ if (req.prepassReady && req.filterSaved) {
5709
+ const dot = revEl('span', 'wrc-dot'); dot.setAttribute('aria-hidden', 'true');
5710
+ const txt = revEl('span', 'wrc-text');
5711
+ txt.appendChild(revEl('b', null, 'Drawing Filter saved.'));
5712
+ txt.appendChild(document.createTextNode(' Return to the same terminal AI session that prepared this Drawing Filter and tell it to continue the drawing read.'));
5713
+ return [dot, txt];
5714
+ }
5468
5715
  if (req.prepassReady) {
5469
5716
  // The terminal AI has completed the deterministic pre-read; it is now waiting on the real Filter
5470
5717
  // Save checkpoint below, not on another pasted instruction. A static dot avoids claiming work is
5471
5718
  // still running, and the real action only focuses the existing Filter iframe — it never fakes Save.
5472
5719
  const dot = revEl('span', 'wrc-dot'); dot.setAttribute('aria-hidden', 'true');
5473
5720
  const txt = revEl('span', 'wrc-text');
5474
- txt.appendChild(revEl('b', null, 'Steel Filter is ready.'));
5475
- txt.appendChild(document.createTextNode(' Review the Steel Filter and Save to continue the read.'));
5476
- const review = revEl('button', 'btn-mini', 'Review Filter');
5477
- review.type = 'button'; review.dataset.revfilter = ''; review.setAttribute('data-tip', 'Focus the Steel Filter below');
5721
+ txt.appendChild(revEl('b', null, 'Drawing Filter is ready.'));
5722
+ txt.appendChild(document.createTextNode(' Review the selected layers, line weights, and colours. Then press Save filter in the top-right corner, return to the terminal AI that prepared it, and tell it to continue the drawing read.'));
5723
+ const review = revEl('button', 'btn-mini', 'Open Drawing Filter');
5724
+ review.type = 'button'; review.dataset.revfilter = ''; review.dataset.commandId = 'shell.revision-filter-open';
5725
+ review.setAttribute('data-tip', 'Focus the Drawing Filter below');
5478
5726
  return [dot, txt, review];
5479
5727
  }
5480
- const spin = revEl('span', 'wrc-spin'); spin.setAttribute('aria-hidden', 'true');
5728
+ const runState = req.run && req.run.state;
5729
+ if (runState === 'queued' || runState === 'running') {
5730
+ // The terminal AI already owns this request. Do not offer Copy here: a second handoff is not a
5731
+ // useful fallback while the first one is active, and the Requests window carries the real Stop.
5732
+ const dot = revEl('span', 'wrc-dot'); dot.setAttribute('aria-hidden', 'true');
5733
+ const txt = revEl('span', 'wrc-text');
5734
+ txt.appendChild(revEl('b', null, `${isInitialRevisionRead(req) ? 'Initial' : 'Updated'} drawing read is running.`));
5735
+ txt.appendChild(document.createTextNode(` Your terminal AI is preparing ${n} file${n > 1 ? 's' : ''}. You can keep working in FloLess; progress and the next required step will appear here. Open Requests if you need to stop it.`));
5736
+ return [dot, txt];
5737
+ }
5738
+ // `pending` means the request is waiting for the terminal AI handoff; it does not prove that an
5739
+ // AI is actively reading. A spinner made a pasted instruction look like an already-running job.
5740
+ const dot = revEl('span', 'wrc-dot'); dot.setAttribute('aria-hidden', 'true');
5481
5741
  const txt = revEl('span', 'wrc-text');
5482
- txt.appendChild(revEl('b', null, `Reading the ${isInitialRevisionRead(req) ? 'initial' : 'revised'} set…`));
5483
- txt.appendChild(document.createTextNode(` ${n} file${n > 1 ? 's' : ''} queued for your terminal AI — paste the copied instruction there, or say “apply my floless request”.`));
5742
+ txt.appendChild(revEl('b', null, `${isInitialRevisionRead(req) ? 'Initial' : 'Updated'} drawing read is waiting for your terminal AI.`));
5743
+ // Runtime discovery belongs to the Requests surface, not this workspace card. `canRun` is only
5744
+ // server policy; it does not prove that a supported terminal AI is installed on this machine.
5745
+ // Phrase the optional shortcut conditionally so the card never points to a hidden control.
5746
+ const handoff = !isInitialRevisionRead(req) && req.canRun
5747
+ ? 'Open Requests. If Start automatically is shown, choose it; otherwise copy the request into Claude Code, Codex, or OpenCode.'
5748
+ : 'Open Requests and copy the request into Claude Code, Codex, or OpenCode.';
5749
+ txt.appendChild(document.createTextNode(` ${n} file${n > 1 ? 's' : ''} queued. ${handoff} Then return here. This may take up to 30 minutes.`));
5484
5750
  const copy = revEl('button', 'btn-mini', '⧉ Copy');
5485
- copy.type = 'button'; copy.dataset.revcopy = ''; copy.setAttribute('data-tip', 'Copy the instruction again');
5486
- return [spin, txt, copy];
5751
+ copy.type = 'button'; copy.dataset.revcopy = ''; copy.dataset.commandId = 'shell.revision-request-copy';
5752
+ copy.setAttribute('data-tip', 'Copy the instruction again');
5753
+ return [dot, txt, copy];
5487
5754
  }
5488
5755
  function buildStagedCard(req) {
5489
5756
  // A STATIC dot, not the pending spinner: the read has finished and nothing is in flight. The
@@ -5494,7 +5761,7 @@
5494
5761
  txt.appendChild(document.createTextNode(' Nothing has been applied yet — decide what this read may change.'));
5495
5762
  const actions = revEl('span', 'wrc-actions');
5496
5763
  const review = revEl('button', 'btn-mini', 'Review changes');
5497
- review.type = 'button'; review.dataset.revreview = '';
5764
+ review.type = 'button'; review.dataset.revreview = ''; review.dataset.commandId = 'shell.revision-review-open';
5498
5765
  actions.appendChild(review);
5499
5766
  return [dot, txt, actions];
5500
5767
  }
@@ -5504,12 +5771,38 @@
5504
5771
  txt.appendChild(revEl('b', null, 'The read failed.'));
5505
5772
  txt.appendChild(document.createTextNode(' '));
5506
5773
  txt.appendChild(revEl('span', 'wrc-err-detail', req.error || 'The read could not be completed.'));
5507
- txt.appendChild(document.createTextNode(' Attach the set again to retry.'));
5774
+ const canClear = req.canClear === true;
5775
+ txt.appendChild(document.createTextNode(canClear
5776
+ ? ' Press Dismiss, then attach the set again to retry.'
5777
+ : ` ${req.clearWhy || 'FloLess cannot safely release this drawing read yet.'} Open Requests for the available recovery.`));
5508
5778
  const actions = revEl('span', 'wrc-actions');
5509
- const dismiss = revEl('button', 'btn-mini', 'Dismiss'); dismiss.type = 'button'; dismiss.dataset.revdismiss = '';
5510
- actions.appendChild(dismiss);
5779
+ if (canClear) {
5780
+ const dismiss = revEl('button', 'btn-mini', 'Dismiss'); dismiss.type = 'button'; dismiss.dataset.revdismiss = '';
5781
+ dismiss.dataset.commandId = 'shell.revision-failure-dismiss';
5782
+ actions.appendChild(dismiss);
5783
+ }
5511
5784
  return [ico, txt, actions];
5512
5785
  }
5786
+ function buildUnavailableCard() {
5787
+ const ico = revEl('span', 'wrc-warn-ico', '⚠'); ico.setAttribute('aria-hidden', 'true');
5788
+ const txt = revEl('span', 'wrc-text');
5789
+ txt.appendChild(revEl('b', null, 'This drawing read cannot be shown by this version of FloLess.'));
5790
+ txt.appendChild(document.createTextNode(' Open Requests for details. If the request does not change, update FloLess before continuing.'));
5791
+ return [ico, txt];
5792
+ }
5793
+
5794
+ async function dismissFailedRevision(req) {
5795
+ try { await api(`/api/requests/${encodeURIComponent(req.id)}`, { method: 'DELETE' }); }
5796
+ catch (error) {
5797
+ showToast((error && error.message) || 'FloLess could not dismiss this drawing read.', 'warn');
5798
+ if (bridge.loadRequests) await bridge.loadRequests().catch(() => {});
5799
+ await renderRevisionCard();
5800
+ return;
5801
+ }
5802
+ lastRevState = 'none';
5803
+ if (bridge.loadRequests) bridge.loadRequests().catch(() => {});
5804
+ await renderRevisionCard();
5805
+ }
5513
5806
 
5514
5807
  async function renderRevisionCard() {
5515
5808
  // GENERATION, not just the captured object — the idiom `refreshModelPresence`/`refreshApprovalState`
@@ -5521,6 +5814,10 @@
5521
5814
  const gen = ++revisionGen;
5522
5815
  const proj = current;
5523
5816
  if (!proj) { $revisionCard.hidden = true; return; }
5817
+ // Keep the last known card painted while the request list is reloading. Switching to another
5818
+ // stage and back must not turn a long-running terminal read into a blank strip for the few
5819
+ // seconds before /api/requests answers again.
5820
+ if (currentStep === 'drawings' && revCardReq && lastRevState !== 'none') $revisionCard.hidden = false;
5524
5821
  let reqs = [];
5525
5822
  // ONCE PER OUTAGE, not once per tick. This runs on a 3-second poll, so an unguarded log turns a
5526
5823
  // server restart into a wall of red — the same "every open logs an error" noise #600 was written
@@ -5540,12 +5837,27 @@
5540
5837
  // breadcrumb, mid-poll) or paint the old project's revision state over the newly opened one.
5541
5838
  if (gen !== revisionGen || !current || current.id !== proj.id) return;
5542
5839
  const mine = reqs.filter((r) => r && r.type === 'revision-read' && r.project === proj.id);
5543
- const failed = mine.find((r) => r.status === 'failed');
5544
- const staged = mine.find((r) => r.status === 'staged');
5545
- const pending = mine.find((r) => r.status === 'pending');
5546
- // `failed` first, then `staged`, then `pending` — most-resolved wins, so a project holding both a
5547
- // finished review and a newly queued read shows the one the user can act on.
5548
- const state = failed ? 'failed' : staged ? 'staged' : pending ? 'pending' : 'none';
5840
+ // One project can retain an old failed request after the user follows its recovery instruction and
5841
+ // attaches the set again. The request list is durable oldest-first; the newest lifecycle is the one
5842
+ // this card must follow. Status priority hid the retry behind the old failure and stopped this poll.
5843
+ const activeRequest = mine.reduce((latest, request) => {
5844
+ if (!latest) return request;
5845
+ const latestAt = Date.parse(latest.createdAt || '') || 0;
5846
+ const requestAt = Date.parse(request.createdAt || '') || 0;
5847
+ return requestAt >= latestAt ? request : latest;
5848
+ }, null);
5849
+ const failed = activeRequest && activeRequest.status === 'failed' ? activeRequest : null;
5850
+ const staged = activeRequest && activeRequest.status === 'staged' ? activeRequest : null;
5851
+ const pending = activeRequest && activeRequest.status === 'pending' ? activeRequest : null;
5852
+ // Request files are durable and may have been written by a newer build (or repaired by hand).
5853
+ // Never feed an unvalidated status into the renderer: the pending fallback expects a real pending
5854
+ // request and dereferences it. Keep the unfamiliar request visible and polling in a safe state so
5855
+ // the user gets an explanation instead of a crashed card and stale stage gates.
5856
+ const state = !activeRequest ? 'none'
5857
+ : failed ? 'failed'
5858
+ : staged ? 'staged'
5859
+ : pending ? 'pending'
5860
+ : 'unavailable';
5549
5861
  // Was pending, now nothing in flight. Confirm a NEW version actually committed (the head advanced
5550
5862
  // past the attach baseVersion) before celebrating — a bare request DELETE (Dismiss / footer-clear)
5551
5863
  // must NOT show a false "complete" toast or re-lock exports.
@@ -5572,7 +5884,13 @@
5572
5884
  // pane — which on the drop-a-drawing flow is Drawings, neither of them. Without this the header
5573
5885
  // stays gated, telling the user to read a drawing they just finished reading. (approveProject
5574
5886
  // re-probes so the ACTION is never blocked; this stops the chrome lying in the meantime.)
5575
- refreshModelPresence(proj.id, proj.app).catch(() => { /* header stays as-is */ });
5887
+ // The read may have CREATED the first model. Do not attach this refresh to the older
5888
+ // pre-read lifecycle request: that answer describes the checkpoint before the mutation and
5889
+ // could re-lock the tabs after the model exists. Superseding bumps the generation so the old
5890
+ // answer is ignored and this post-mutation request becomes authoritative.
5891
+ refreshModelPresence(proj.id, proj.app, true).catch((e) => {
5892
+ console.error('[workspaces] post-read model presence did not refresh', e);
5893
+ });
5576
5894
  // AND the approval state, which model presence alone no longer covers. Before "not reviewable"
5577
5895
  // was told apart from "the probe failed", an empty project sat in the ERROR state here and the
5578
5896
  // header's click-to-retry quietly repaired it on the next click. That retry is gone by design —
@@ -5590,66 +5908,123 @@
5590
5908
  }
5591
5909
  }
5592
5910
  lastRevState = state;
5593
- if (state === 'none') { stopRevisionPoll(); $revisionCard.hidden = true; $revisionCard.replaceChildren(); return; }
5594
- // `failed` STOPS the poll; `staged` KEEPS it, and the design note that said otherwise rested on an
5595
- // assumption review disproved. It read "staged is resolved and actionable, nothing changes on its
5596
- // own" — true of THIS tab's user, false of the system: a second tab, the footer's Clear all, or a
5597
- // request DELETE removes the request without this tab acting. With the poll stopped there was
5598
- // nothing left to notice, so the card sat offering "Review changes" for a review that no longer
5599
- // existed, and the button led to a 410.
5600
- //
5601
- // The reason the poll was stopped in the first place is real, so it is handled directly instead:
5602
- // a tick must not re-render the card underneath an OPEN review. That is what `revReviewState`
5603
- // guards below — the poll keeps running, and only the repaint waits.
5604
- if (state === 'failed') stopRevisionPoll();
5605
- else if (!revisionPoll) startRevisionPoll(); // a pending read seen on load → keep it fresh
5606
- if (currentStep !== 'drawings') { $revisionCard.hidden = true; return; } // card is Drawings-scoped
5911
+ if (state === 'none') {
5912
+ revCardReq = null;
5913
+ syncDrawingRevisionRequest('');
5914
+ stopRevisionPoll(); $revisionCard.hidden = true; $revisionCard.replaceChildren(); applyStageGating(); return;
5915
+ }
5916
+ // Every durable lifecycle keeps polling until its request disappears. Failed and staged cards can
5917
+ // both change from another tab (Attach again, Clear, or a review action); stopping either interval
5918
+ // leaves this workspace permanently showing the old request because request SSE is owned by the
5919
+ // shell, not this card. `revReviewState` below handles the real repaint risk while a review is open.
5920
+ if (!revisionPoll) startRevisionPoll();
5921
+ // The card is Drawing-Filter-scoped, but its REQUEST STATE is project-scoped. Keep that state and
5922
+ // the already-loaded iframe checkpoint fresh even while the user looks at another stage. Otherwise
5923
+ // returning to Drawing Filter briefly resurrects the old "reading" state and can leave Save filter
5924
+ // unaware that the terminal prepass finished until a later poll happens to repaint the tab.
5925
+ revCardReq = failed || staged || pending || activeRequest;
5926
+ syncDrawingRevisionRequest(pending?.prepassReady && !pending.filterSaved ? pending.id : '');
5927
+ if (currentStep !== 'drawings') { $revisionCard.hidden = true; applyStageGating(); return; } // card is Drawing Filter-scoped
5607
5928
  // A REVIEW IS OPEN — leave the card alone. Repainting it would replace the button focus returns to,
5608
5929
  // and the modal is the authority on this request until it closes. If the request vanished from
5609
5930
  // under it, the modal's own confirm learns that from the server and closes; the next tick then
5610
5931
  // paints the truth.
5611
5932
  if (revReviewState) return;
5612
- revCardReq = failed || staged || pending;
5613
- if (pending?.prepassReady && frames.drawings.dataset.want) {
5614
- const u = new URL(frames.drawings.dataset.want, location.origin);
5615
- if (u.searchParams.get('revisionRequest') !== pending.id) {
5616
- u.searchParams.set('revisionRequest', pending.id);
5617
- frames.drawings.dataset.want = u.pathname + u.search;
5618
- if (frames.drawings.dataset.loaded) frames.drawings.src = frames.drawings.dataset.want;
5619
- }
5620
- }
5621
- const cardKey = `${state}:${revCardReq ? revCardReq.id : ''}:${pending && pending.prepassReady ? 'filter-ready' : 'read-pending'}`;
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 || '' : ''}`;
5622
5934
  if ($revisionCard._renderKey === cardKey && !$revisionCard.hidden) return; // preserve focus across the 3 s poll
5623
5935
  const restoreFocus = typeof document !== 'undefined' && $revisionCard.contains(document.activeElement);
5624
5936
  $revisionCard._renderKey = cardKey;
5625
- $revisionCard.className = 'ws-revision-card state-' + state + (pending && pending.prepassReady ? ' state-filter-ready' : '');
5937
+ $revisionCard.className = 'ws-revision-card state-' + state
5938
+ + (pending && pending.filterSaved ? ' state-filter-saved' : pending && pending.prepassReady ? ' state-filter-ready' : '');
5626
5939
  $revisionCard.replaceChildren(...(
5627
5940
  state === 'failed' ? buildFailedCard(failed)
5628
5941
  : state === 'staged' ? buildStagedCard(staged)
5629
- : buildPendingCard(pending)));
5942
+ : state === 'pending' ? buildPendingCard(pending)
5943
+ : buildUnavailableCard()));
5630
5944
  $revisionCard.hidden = false;
5945
+ applyStageGating();
5631
5946
  if (restoreFocus) $revisionCard.querySelector('button')?.focus();
5632
5947
  }
5633
5948
 
5949
+ /** Keep the request checkpoint in the already-open Drawing Filter without navigating away edits. */
5950
+ function syncDrawingRevisionRequest(targetRequest) {
5951
+ const frame = frames.drawings;
5952
+ if (!frame?.dataset.want) return;
5953
+ const requestId = String(targetRequest || '');
5954
+ const wanted = new URL(frame.dataset.want, location.origin);
5955
+ if (requestId) wanted.searchParams.set('revisionRequest', requestId);
5956
+ else wanted.searchParams.delete('revisionRequest');
5957
+ frame.dataset.want = wanted.pathname + wanted.search;
5958
+ if (!frame.dataset.loaded) return;
5959
+ try {
5960
+ const checkpoint = frame.contentWindow?.__floRevisionCheckpoint;
5961
+ if (checkpoint && typeof checkpoint.setRequest === 'function') {
5962
+ checkpoint.setRequest(requestId);
5963
+ return;
5964
+ }
5965
+ const shown = new URL(frame.contentWindow.location.href);
5966
+ if ((shown.searchParams.get('revisionRequest') || '') === requestId) return;
5967
+ } catch { /* not ready or not same-origin yet — navigate to the authoritative target below */ }
5968
+ frame.src = frame.dataset.want;
5969
+ }
5970
+
5971
+ function focusDrawingFilterSave() {
5972
+ const frame = frames.drawings;
5973
+ if (!frame) return;
5974
+ let onLoad;
5975
+ const focusSave = () => {
5976
+ try {
5977
+ const shown = new URL(frame.contentWindow.location.href);
5978
+ const wanted = new URL(frame.dataset.want, location.origin);
5979
+ if (shown.pathname !== wanted.pathname || shown.search !== wanted.search) return false;
5980
+ const doc = frame.contentDocument;
5981
+ const save = doc?.getElementById('save');
5982
+ if (!save) return false;
5983
+ // A disabled button cannot receive focus. When the Filter still has no selected drawing
5984
+ // lines, focus the live required-step sentence instead so "Open Drawing Filter" lands on
5985
+ // the exact action the detailer must take, rather than silently leaving focus behind.
5986
+ const target = save.disabled ? doc.getElementById('saveRequiredStatus') : save;
5987
+ if (!target || target.hidden) return false;
5988
+ target.focus();
5989
+ if (onLoad) frame.removeEventListener('load', onLoad);
5990
+ return true;
5991
+ } catch { return false; }
5992
+ };
5993
+ onLoad = () => requestAnimationFrame(() => { if (!focusSave()) frame.focus(); });
5994
+ frame.addEventListener('load', onLoad, { once: true });
5995
+ if (!focusSave()) frame.focus();
5996
+ }
5997
+
5998
+ async function copyRevisionCardRequest(req, copyButton) {
5999
+ const copyProject = current;
6000
+ const copyGeneration = revisionOwnerGen;
6001
+ const copyRenderKey = $revisionCard._renderKey;
6002
+ const ownsCopy = () => current === copyProject
6003
+ && revisionOwnerGen === copyGeneration
6004
+ && revCardReq?.id === req.id
6005
+ && $revisionCard._renderKey === copyRenderKey
6006
+ && !!copyButton?.isConnected;
6007
+ // "no instruction body" must not be reported as "copy blocked": that sends the user to the
6008
+ // Requests panel, where the ⧉ gives the real reason and contradicts this toast.
6009
+ const res = await bridge.copyRequest(req, ownsCopy);
6010
+ if (res === 'stale' || !ownsCopy()) return;
6011
+ if (res === 'ok') showToast('Instruction copied', 'ok');
6012
+ else if (res === 'empty') showToast('Nothing to copy — this request has no instruction', 'err');
6013
+ else showToast('Copy blocked — use the Requests panel', 'warn');
6014
+ }
6015
+
5634
6016
  $revisionCard.addEventListener('click', async (e) => {
5635
6017
  const req = revCardReq;
5636
6018
  if (!req) return;
5637
6019
  if (e.target.closest('[data-revreview]')) {
5638
6020
  openRevisionReview(req);
5639
6021
  } else if (e.target.closest('[data-revcopy]') && bridge.copyRequest) {
5640
- // "no instruction body" must not be reported as "copy blocked": that sends the user to the
5641
- // Requests panel, where the ⧉ gives the real reason and contradicts this toast.
5642
- const res = await bridge.copyRequest(req);
5643
- if (res === 'ok') showToast('Instruction copied', 'ok');
5644
- else if (res === 'empty') showToast('Nothing to copy — this request has no instruction', 'err');
5645
- else showToast('Copy blocked — use the Requests panel', 'warn');
6022
+ const copyButton = e.target.closest('[data-revcopy]');
6023
+ await copyRevisionCardRequest(req, copyButton);
5646
6024
  } else if (e.target.closest('[data-revfilter]')) {
5647
- frames.drawings?.focus();
6025
+ focusDrawingFilterSave();
5648
6026
  } else if (e.target.closest('[data-revdismiss]')) {
5649
- try { await api(`/api/requests/${encodeURIComponent(req.id)}`, { method: 'DELETE' }); } catch { /* already gone */ }
5650
- lastRevState = 'none';
5651
- if (bridge.loadRequests) bridge.loadRequests().catch(() => {});
5652
- renderRevisionCard();
6027
+ await dismissFailedRevision(req);
5653
6028
  }
5654
6029
  });
5655
6030