@floless/app 0.123.2 → 0.124.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.
@@ -103,8 +103,12 @@ input:focus-visible{outline:2px solid var(--brand);outline-offset:1px}
103
103
  }
104
104
  .facet.dim{opacity:.4} .facet.dim .opts,.facet.dim .acts{pointer-events:none}
105
105
  .hint{color:var(--mut);font-size:11px;line-height:1.5}
106
- footer{margin-top:auto;display:flex;align-items:center;gap:6px;flex-wrap:wrap;border-top:1px solid var(--line);padding-top:12px}
107
- #count{font-size:11px;color:var(--mut);width:100%;margin-bottom:4px}
106
+ /* #count is the footer's only child since #603 took the Fit/Zoom buttons out of the rail, so the
107
+ flex row that used to wrap around them is gone with them — as are #count's width:100% and
108
+ margin-bottom, which existed only to push the count onto its own line above those wrapped
109
+ buttons and now just left 4px of dead space at the panel's bottom edge. */
110
+ footer{margin-top:auto;border-top:1px solid var(--line);padding-top:12px}
111
+ #count{font-size:11px;color:var(--mut)}
108
112
  #count b{color:var(--text)}
109
113
  #stage{flex:1;position:relative;background:var(--bg);min-width:0}
110
114
  #canvas{width:100%;height:100%;cursor:grab;touch-action:none;display:block}
@@ -124,7 +128,51 @@ body.publication-blocked #canvas,
124
128
  body.publication-blocked #zoombar{display:none}
125
129
  body.publication-blocked #stage{display:flex}
126
130
  body.publication-blocked #empty{position:static;flex:1}
127
- #zoombar{position:absolute;left:12px;bottom:12px;display:flex;gap:6px;background:var(--panel);border:1px solid var(--line);border-radius:8px;padding:6px 8px;box-shadow:0 4px 14px rgba(0,0,0,.45)}
131
+ /* max-width earns its place: #zoombar is absolutely positioned with only a LEFT offset, so nothing
132
+ bounded its right edge and it overhung #stage (body{overflow:hidden} then clipped it) once the
133
+ pane got narrow. Measured on the real app by reconstructing master's exact rules: it first
134
+ overflowed at ~425px of iframe width — and at 400px it did so with the OLD "Steel" label too, so
135
+ this is the bar's own defect, not the longer label's. (A natural-width calculation says ~457px;
136
+ the real number is lower because master put no white-space:nowrap on these buttons, so the label
137
+ wrapped INSIDE the button and let the bar compress from 145px to 115px first. Worth knowing
138
+ before trusting any figure here that was computed rather than measured.) Capping it at the stage width minus its two 12px insets means it can never
139
+ overhang at any width; the buttons compress instead, and their data-tip still carries the full
140
+ meaning.
141
+ overflow:hidden on the BAR is the other half, and the cap is NOT safe without it: max-width clamps
142
+ the bar's own box, but each button has an intrinsic ~22px floor (its padding and border), and a
143
+ nowrap flex row whose items no longer fit lets that content SPILL OUT of the clamped box. #stage
144
+ does not clip, so the spill reached the iframe edge and a button was sliced there. An independent
145
+ QA pass measured it before these lines existed: at a 710px window the buttons sat 3px outside the
146
+ drawing, at 700px one was no longer hit-testable, at 680px one was fully outside.
147
+ flex-wrap:wrap is what keeps that from merely becoming a prettier failure. With the clip alone the
148
+ second button survived as an 8.4px sliver at a 710px window; wrapping stacks the two instead, and
149
+ both come back FULLY visible at 27.2px each — measured in that same configuration. There is always
150
+ vertical room in a drawing pane, so trading height for legibility is free here.
151
+ Known residual, stated rather than glossed: the bar cannot shrink below ~18px (its own padding +
152
+ border) and sits at a fixed left:12px, so a stage narrower than ~30px still can't hold it —
153
+ measured at ~330px of iframe width, which is roughly a 670px window. (Two criteria get quoted for
154
+ this and they differ: by PAINTED pixels — the bar's own box, which is what a user sees — it is
155
+ ~330px; the QA harness reports 340px because it measures the BUTTONS' layout rects, and
156
+ overflow:hidden clips those without moving them. The painted figure is the one that matters here.)
157
+ That is below the 760px breakpoint at which the app collapses its side panels, so the view is
158
+ already out of its supported shape, and the drawing area there is under 40px showing nothing.
159
+ Closing that last few px would take a container query on #stage hiding the bar outright. That
160
+ would work — #stage's only children are #canvas, #empty and this bar, all already contained by
161
+ its position:relative, and #eye is a sibling of #app rather than a descendant, so the layout
162
+ containment container-type brings would not reach it. It is left undone as a judgement call, not
163
+ a blocked one: it is a second layout mechanism on this surface to serve a window width at which
164
+ the drawing area shows nothing at all.
165
+ On the button rule: min-width:0 and overflow:hidden are ALTERNATIVE ways to defeat a flex item's
166
+ content-based automatic minimum size, not a pair — measured by toggling each, and removing either
167
+ one alone still let the button shrink to 46px, while removing BOTH pinned it at its 86px content
168
+ width. Both are kept so the behaviour survives a later edit to either. text-overflow:ellipsis IS
169
+ live here despite the label being a bare text node in the button (a documented reason it can go
170
+ inert) — but flex-wrap changed WHEN it engages, so note what is actually true now: at a forced
171
+ 96px cap the bar wraps first, "Fit" keeps its full 35.5px untruncated, and only "Zoom steel"
172
+ ellipsises (scrollWidth 84 vs clientWidth 77). A button now moves to its own line before it
173
+ shrinks, so the ellipsis is the second line of defence, not the first. */
174
+ #zoombar{position:absolute;left:12px;bottom:12px;max-width:calc(100% - 24px);overflow:hidden;display:flex;flex-wrap:wrap;gap:6px;background:var(--panel);border:1px solid var(--line);border-radius:8px;padding:6px 8px;box-shadow:0 4px 14px rgba(0,0,0,.45)}
175
+ #zoombar button{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
128
176
  /* eyedropper popover */
129
177
  #eye{position:fixed;display:none;z-index:50;background:var(--panel);border:1px solid var(--line);border-radius:8px;padding:10px;box-shadow:0 8px 24px rgba(0,0,0,.5);min-width:210px}
130
178
  #eye.show{display:block}
@@ -187,10 +235,15 @@ body.publication-blocked #empty{position:static;flex:1}
187
235
  <h2>Colors <span class="acts"><button data-all="colors">all</button><button data-none="colors">none</button></span></h2>
188
236
  <div class="opts"></div>
189
237
  </section>
238
+ <!-- Viewport controls do NOT live here. This panel is about WHICH ELEMENTS are shown (the
239
+ facets); how the viewport is FRAMED belongs on the canvas it acts on, so Fit / Zoom steel
240
+ are the #zoombar pair over #stage and nothing else. Until #603 both existed, bound to the
241
+ same two handlers under two different names each, which read as four commands. If a viewport
242
+ control is ever wanted here again, note the rail is not a fallback for the floating bar:
243
+ `body.publication-blocked` hides #panel and #zoombar in the SAME rule, so neither survives
244
+ the other. -->
190
245
  <footer>
191
246
  <span id="count"></span>
192
- <button id="fit">Fit page</button>
193
- <button id="zoomsteel">Zoom to steel</button>
194
247
  </footer>
195
248
  </aside>
196
249
  <main id="stage">
@@ -218,7 +271,12 @@ body.publication-blocked #empty{position:static;flex:1}
218
271
  <p class="hint" style="margin-top:8px;max-width:340px">Your terminal AI reads the drawing once (PyMuPDF) and bakes its layers, thicknesses and colours here. Use <b>Re-read &amp; re-bake ▸</b> on the canvas — this view updates on its own once it’s done.</p>
219
272
  </div>
220
273
  </div>
221
- <div id="zoombar"><button id="fit2">Fit</button><button id="zoomsteel2">Steel</button></div>
274
+ <!-- The ONLY fit/zoom controls. Labels stay terse so both stay fully legible before the bar's
275
+ max-width cap (see its CSS) starts compressing them in a narrow Workspaces pane — the cap
276
+ means longer text costs legibility, never an overhanging bar. "Zoom steel" not "Steel": a
277
+ bare noun read as a category, not a command. data-tip (never title=) carries the full
278
+ sentence. -->
279
+ <div id="zoombar"><button id="fit2" data-tip="Fit the whole page in view">Fit</button><button id="zoomsteel2" data-tip="Zoom to fit the steel elements on this sheet">Zoom steel</button></div>
222
280
  </main>
223
281
  </div>
224
282
  <div id="eye">
@@ -1005,9 +1063,7 @@ svg.addEventListener('pointerup', e => {
1005
1063
  });
1006
1064
  function fit(){ vb = { ...base }; setVB(); }
1007
1065
  function zoomSteel(){ const b = sheets[active] && sheets[active].steelBbox; if(!b){ fit(); return; } const pad = 40; vb = { x: b[0]-pad, y: b[1]-pad, w: (b[2]-b[0])+2*pad, h: (b[3]-b[1])+2*pad }; setVB(); }
1008
- document.getElementById('fit').onclick = fit;
1009
1066
  document.getElementById('fit2').onclick = fit;
1010
- document.getElementById('zoomsteel').onclick = zoomSteel;
1011
1067
  document.getElementById('zoomsteel2').onclick = zoomSteel;
1012
1068
 
1013
1069
  // --- save: write the selection + mode onto C.filter and PUT the contract ---
@@ -163,7 +163,17 @@
163
163
  // /api/contract call so two vectorize projects of the same app never share a draft (spec §4.3).
164
164
  const PROJECT = params.get('project') || '';
165
165
  const PROJECT_QS = PROJECT ? ('?project=' + encodeURIComponent(PROJECT)) : '';
166
- const src = params.get('src') || (app ? ('/api/contract/' + encodeURIComponent(app) + PROJECT_QS) : '/vector-example.json');
166
+ // `quietMissing=1` answers 204 instead of 404 for a project that holds no drawing yet — the state
167
+ // every freshly created project is in, and the state this editor already renders as a friendly
168
+ // empty message. Handling the 404 in JS was never enough: the browser logs its own red
169
+ // "Failed to load resource: 404" for the response itself, so the only way to stop it is to not be
170
+ // a 404. Same probe `workspaces.js` uses for model presence, and same reason.
171
+ //
172
+ // PROJECT-SCOPED ONLY. Without ?project the route has a second, RICHER 404 (a node's publication
173
+ // that is genuinely missing) which this would flatten into the same silent 204, and that absence is
174
+ // not expected. The legacy app-keyed URL therefore stays byte-for-byte what it was.
175
+ const src = params.get('src')
176
+ || (app ? ('/api/contract/' + encodeURIComponent(app) + (PROJECT ? PROJECT_QS + '&quietMissing=1' : '')) : '/vector-example.json');
167
177
  const WEAK = 0.5;
168
178
 
169
179
  let sheet = null;
@@ -634,6 +644,10 @@
634
644
  // The server's tag for what we just read; echoed back on save so a write that would land on top
635
645
  // of someone else's is refused rather than silently winning.
636
646
  if (r.ok && editable) serverEtag = r.headers.get('ETag');
647
+ // 204 is the quiet "no drawing here yet", and it carries no body to parse — `load(null)` shows
648
+ // the friendly empty state. The 404 branch stays for the app-keyed URL, which does not ask to
649
+ // be quieted, and for any older server that does not honour quietMissing.
650
+ if (r.status === 204) return null;
637
651
  if (!r.ok) {
638
652
  // 404 with no contract yet is expected state for a fresh Workspaces project — show the friendly empty-state message
639
653
  if (r.status === 404) return null;
@@ -473,6 +473,13 @@
473
473
  label = 'Checking changes…';
474
474
  tip = 'Checking the working copy against the latest approved version.';
475
475
  unavailable = true;
476
+ } else if (s.status === 'unreviewable') {
477
+ // Same LABEL as the error row, deliberately — it is the honest one either way, and a verb-led
478
+ // label ("Duplicate to approve") would promise an action this button does not perform. The tip
479
+ // carries the difference, and it is the server's plain-English sentence, not a raw error.
480
+ label = 'Review unavailable';
481
+ tip = s.error || 'This project cannot be approved.';
482
+ unavailable = true;
476
483
  } else if (s.status === 'error' || s.status === 'unavailable') {
477
484
  label = 'Review unavailable';
478
485
  tip = s.error || 'Approval status is unavailable — try again.';
@@ -504,6 +511,18 @@
504
511
  try {
505
512
  const review = await api(`/api/projects/${encodeURIComponent(projectId)}/approval-review`);
506
513
  if (gen !== approvalStateGen || !current || current.id !== projectId) return null;
514
+ // NOT an error, and kept apart from one on purpose: the route answers this 200 for a project
515
+ // that legitimately has nothing to review (no model read in yet, or too old to carry the
516
+ // incarnation approval proves against). Folding it into `error` would mean the retry below
517
+ // re-asks a question whose answer cannot change, and would call a standing condition a failure.
518
+ if (review.reviewable === false) {
519
+ approvalState = { status: 'unreviewable', reason: review.reason, review: null, pendingCount: 0,
520
+ headVersion: null, error: review.message || 'This project cannot be approved.' };
521
+ renderApprovalHeader();
522
+ syncWorkspaceGuide();
523
+ if (!$wsExports.hidden) paintExports(current.approvedAt);
524
+ return null;
525
+ }
507
526
  const groups = Array.isArray(review.groups) ? review.groups : [];
508
527
  const headVersion = approvalHeadVersion(review);
509
528
  approvalState = { status: 'ready', review, pendingCount: groups.length, headVersion, error: '' };
@@ -812,6 +831,263 @@
812
831
  appsChangedTimer = setTimeout(appsChangedRefresh, 250);
813
832
  });
814
833
 
834
+ // The same reconciliation for the OPEN project. The listener above keeps the LANDING honest; a
835
+ // project open in THIS tab was never reconciled at all when another tab (or the terminal AI)
836
+ // renamed or archived it — `current` is assigned only in openProject and cleared only in
837
+ // closeProject, and no cross-tab path reached either. So every surface derived from it went stale
838
+ // together: the breadcrumb, the header name, the header project picker (its rows come from
839
+ // `projects` and mark the open one by id) — and the step frames, which is the part that actually
840
+ // breaks. They carry `?project=<id>`, a rename mints a NEW id, and the next contract read or
841
+ // autosave from this tab then 404s. Relabelling would leave exactly that defect in place, so the
842
+ // answer is to re-open (openProject re-points both frames — blanking them now, re-srcing each on
843
+ // first show) or to close.
844
+ //
845
+ // The toasts below say "elsewhere" and mean it: a project action is LANDING-ONLY (`openProjMenu`
846
+ // is wired to the landing grid alone, and the landing is hidden whenever `current` is set), so a
847
+ // tab with a project open cannot be the tab that renamed or archived it. `broadcast` carries no
848
+ // origin and this listener has no self-echo suppression, so surfacing rename/archive from the
849
+ // open-project chrome — which `openProjMenu`'s own comment contemplates — would break that, and
850
+ // the copy with it. Named here so it is a dependency, not a coincidence. (Found by review.)
851
+ // WHICH PROJECT THIS IS, across a rename: `uuid`. A rename mints a new id (the folder moves) but
852
+ // PRESERVES the record's uuid, and archive preserves it too — while duplicate and import mint a
853
+ // fresh one, so a copy can never be mistaken for the original. That makes the live list
854
+ // self-describing: the row still carrying our uuid IS this project under whatever name and id it
855
+ // now has, and its absence means the project was retired.
856
+ //
857
+ // THIS REPLACED AN EVENT-MAPPING MACHINE, and the deletion is the point. An earlier cut rebuilt the
858
+ // old→new id link from the rename event, on the reasoning that "nothing in the live list records
859
+ // that B used to be A" — which was simply wrong; the uuid does. Inferring identity from events cost
860
+ // a mapping bound to its project, a chain rule for A→B→C, a rule for which answers were stale
861
+ // enough to discard, and a bound on how long to defer. Four review rounds found a defect in each,
862
+ // and most of the last round's findings were caused by the previous round's fixes. Reading identity
863
+ // instead of reconstructing it makes those questions not arise: a snapshot either carries our uuid
864
+ // or it does not, whenever it was taken and whichever events this tab missed.
865
+ //
866
+ // Legacy projects predate `uuid` and it is deliberately never backfilled, so they fall back to
867
+ // matching on the id — which cannot tell a rename from an archive, and whose copy says so.
868
+ let reconciling = false; // one reconcile at a time — they all ask the same question
869
+ let reconcileAgain = false;
870
+ let retryTimer = null; // module-scoped ON PURPOSE — see reportUnverified
871
+ let retriesLeft = 1; // …and so is the budget, which only a real event refills
872
+
873
+ window.addEventListener('floless:projects-changed', (e) => {
874
+ const m = (e && e.detail) || {};
875
+ if (!current) {
876
+ // THE LANDING IS DERIVED FROM THE SAME LIVE SET, so it goes stale on exactly these events —
877
+ // and not merely cosmetically: its cards carry `data-open`/`data-kebab` ids, so after a rename
878
+ // elsewhere the ⋯ menu acts on an id the server no longer has (the rename PATCH answers 400
879
+ // `unknown project`). The listener above only ever hears `apps-changed`, which the rename
880
+ // route does not raise. Hit in the real two-tab pass this change was verified with.
881
+ //
882
+ // DROP THE RETIRED ROW NOW, and only then debounce the repaint. The rebuild can be deferred a
883
+ // long way — `appsChangedRefresh` re-arms every 250 ms while a modal is open — and until it
884
+ // runs the card still carries the dead id. `openProject` reads this cache BEFORE the server
885
+ // (a hit means no round-trip at all), so a click in that window would open a project that no
886
+ // longer exists, with nothing to catch it. Invalidation is not the thing to debounce; the
887
+ // repaint is. Without the row, the same click falls through to the server and is refused
888
+ // honestly. (Found by review.)
889
+ if (typeof m.previousProjectId === 'string') projects = projects.filter((p) => p.id !== m.previousProjectId);
890
+ clearTimeout(appsChangedTimer);
891
+ appsChangedTimer = setTimeout(appsChangedRefresh, 250);
892
+ return;
893
+ }
894
+ // The event is only a NUDGE from here on: it says the live set moved, never what this tab should
895
+ // do about it. Everything the decision needs is read back, keyed on the uuid above — which is
896
+ // also why the payload-less nudge a reconnect sends works exactly as well as a real event.
897
+ //
898
+ // A REAL EVENT is also the only thing that refills the retry budget: circumstances have actually
899
+ // changed, so one more attempt is warranted. Refilling it in `reconcileNow` would not bound
900
+ // anything, because the retry calls that itself. (Found by review round 5.)
901
+ retriesLeft = 1;
902
+ reconcileNow();
903
+ });
904
+
905
+ /**
906
+ * The one way to start a reconcile. NOTHING INSIDE it catches, and `openProject`/`closeProject` are
907
+ * not throw-free (renderStepTabs maps over the descriptor's steps; the teardown chain is a dozen
908
+ * sync calls). Without this an internal fault becomes an unhandled rejection: a red console and not
909
+ * a word to the user, in the function whose whole job is to stop them working against a project
910
+ * that moved. (Found by review round 2 — the first cut had a `.catch` on both call sites, the
911
+ * rewrite lost it.) Named rather than inlined so the retry inside uses the same handler.
912
+ */
913
+ function reconcileNow() {
914
+ clearTimeout(retryTimer); // a real attempt supersedes a pending retry rather than racing it
915
+ retryTimer = null;
916
+ reconcileOpenProject().catch((err) => {
917
+ console.error('[workspaces] the open-project reconcile failed: ' + ((err && err.message) || err));
918
+ showToast('Couldn’t check whether this project is still here — reload if it was changed elsewhere.', 'warn');
919
+ });
920
+ }
921
+
922
+ /**
923
+ * Reconcile the OPEN project against the server's live set — the answer to "is what I have still
924
+ * there, and under what id".
925
+ *
926
+ * IT RE-READS RATHER THAN TRUSTING THE EVENT, and that is the whole design. An earlier cut acted
927
+ * off the event shape alone: rename → re-open, anything else → close. Review found the same class
928
+ * of hole four times over — an event arriving during an in-flight read was dropped even when it was
929
+ * this project's own archive; two quick renames left the tab on the intermediate id; a read taken
930
+ * before the mutation was allowed to settle it. All of them are one mistake: treating an event as
931
+ * the truth. The event is now only a nudge, and the answer is read back and matched on `uuid`.
932
+ *
933
+ * Serialized, with a trailing re-run: an event landing mid-flight sets `reconcileAgain` rather than
934
+ * being discarded, so the loop asks again against a read taken after it. It terminates — every pass
935
+ * either records the id it checked or is superseded by a user action, and both are finite.
936
+ */
937
+ async function reconcileOpenProject() {
938
+ if (reconciling) { reconcileAgain = true; return; } // fold in, never drop — see above
939
+ reconciling = true;
940
+ // The id this run has actually CHECKED against the server. The loop keeps going while it does not
941
+ // name the open project, so "the user switched project while we were reading" re-runs instead of
942
+ // exiting — a trailing pass conditioned only on a new EVENT arriving would leave the project they
943
+ // switched to unverified, which is the state this function exists to prevent. (Found by review.)
944
+ let validated = null;
945
+ try {
946
+ do {
947
+ reconcileAgain = false;
948
+ if (!current) return; // closed under us — nothing to reconcile
949
+ const id = current.id;
950
+ const uuid = current.uuid;
951
+ // Join the same monotonic sequence `loadProjects` uses, because this writes the same cache.
952
+ // Without it a slower load already in flight lands afterwards and puts the retired project
953
+ // back — reviving exactly the stale row the write below exists to clear. Bumping it also
954
+ // marks those older loads stale, which is what that counter is for. (Found by review.)
955
+ const seq = ++projectsLoadSeq;
956
+ let res;
957
+ try {
958
+ res = await api('/api/projects');
959
+ } catch (err) {
960
+ // Never silent, and never only in the console: "we could not tell" leaves the user in the
961
+ // exact unknown state this exists to resolve, and the event that would have asked again is
962
+ // already consumed. Say so, and name the recovery. (Found by review — the first cut logged
963
+ // and abandoned.)
964
+ console.error('[workspaces] could not check whether the open project still exists: ' + ((err && err.message) || err));
965
+ reportUnverified();
966
+ return;
967
+ }
968
+ if (!Array.isArray(res.projects)) {
969
+ // A 200 whose shape we do not recognise is NOT an empty live set. `|| []` would have read
970
+ // it as "everything was archived" and closed the user's project with a sentence that is
971
+ // false. Refuse to act on an answer we cannot read. (Found by review.)
972
+ console.error('[workspaces] /api/projects returned no project list — cannot verify the open project');
973
+ reportUnverified();
974
+ return;
975
+ }
976
+ // TAKE THE FRESH LIST — it is the same read `loadProjects` does, and while a project is open
977
+ // NOTHING else refreshes this cache (`applyMode` reloads only under `ws && !current`). Left
978
+ // stale, it holds the retired row and no row for the new id, and the header project picker
979
+ // renders straight off it: the open project shows unmarked, and clicking the stale row hands
980
+ // `openProject` a cache hit for the dead id — re-entering the very 404 this change removes,
981
+ // through the fix's own path. `openProject`'s fallback fetch keeps one entry and discards the
982
+ // array, so this is the only place the whole list lands. (Found by review.)
983
+ if (!current || current.id !== id) continue; // the user moved on mid-read; ask again for the new one
984
+ if (seq === projectsLoadSeq) projects = res.projects;
985
+ // Identity first; the id only as the legacy fallback.
986
+ const mine = uuid
987
+ ? res.projects.find((p) => p.uuid === uuid)
988
+ : res.projects.find((p) => p.id === id);
989
+ // ONLY AN AUTHORITATIVE ANSWER COUNTS AS VALIDATION. With a newer event already pending this
990
+ // read predates it, so recording it would let the loop exit on a claim that was never true —
991
+ // and the trailing pass re-reads anyway. (Found by review round 3.)
992
+ if (mine && mine.id === id) { if (!reconcileAgain) validated = id; continue; } // still here, unchanged
993
+ if (!mine) {
994
+ closeProject(); // → applyMode() → loadProjects(), so the landing repaints without it
995
+ // 'warn', not 'ok', and the parallel wording is deliberate (design review): this file
996
+ // spends 'ok' on what the user did HERE and succeeded at. Both of these are the opposite —
997
+ // something that happened elsewhere, interrupting them — so they follow `kbHandleMissing`'s
998
+ // precedent ("That reference was removed"), which demotes the very same fact purely because
999
+ // this tab discovered it unprompted. Each names the cause ("elsewhere") and the consequence.
1000
+ //
1001
+ // WHAT WE KNOW is that it is no longer in the live set — not, strictly, that it was
1002
+ // archived. Holding a uuid does rule out a rename (that would have kept it listed under the
1003
+ // new id), but `listProjects` also drops a project whose folder stopped matching its own
1004
+ // recorded id, which `projects-store` documents happening in the wild when a file-sync tool
1005
+ // leaves a conflict copy. So the sentence says archived-or-removed: still one cause short of
1006
+ // vague, and true in every case that reaches it. Only the legacy fallback additionally
1007
+ // cannot rule out a rename, and only it says so. (Review round 3 caught the mirror image —
1008
+ // an earlier cut asserting "archived" about renames it had merely not heard about; round 5
1009
+ // caught this one.)
1010
+ showToast(uuid
1011
+ ? 'This project was archived or removed elsewhere — closing it here too.'
1012
+ : 'This project isn’t here any more — it was renamed, archived or removed elsewhere. Closing it here too.', 'warn');
1013
+ continue;
1014
+ }
1015
+ // Renamed. Re-open under the new id, on the step the user was already on — the reload is
1016
+ // unavoidable (the old id is gone), so it should at least land them back where they were.
1017
+ //
1018
+ // NOT FLUSHED FIRST, and that is a decision rather than an oversight (review raised it
1019
+ // twice). A flush cannot help: the editor would PUT to the id the rename has already
1020
+ // retired, so it 404s. What is genuinely lost is anything inside the editor's 500 ms
1021
+ // autosave debounce, plus any parked draft, whose key is `app|project|type` — a new project
1022
+ // id orphans the row. Carrying those across would mean re-keying the draft (or handing the
1023
+ // frame's in-memory contract to the new id), which is a bigger seam than this fix and is a
1024
+ // PRE-EXISTING gap: `openProject` has never flushed, so the user-initiated project switch
1025
+ // loses the same window today. What this change adds is that the teardown can now arrive
1026
+ // UNPROMPTED. Tracked separately rather than smuggled in here.
1027
+ const target = mine.id;
1028
+ try {
1029
+ await openProject(target, currentStep);
1030
+ } catch (err) {
1031
+ // THE REJECTING TWIN of the branch below, and it needs the same sentence: `openProject`
1032
+ // reassigns `current` and repaints the header BEFORE it re-srcs the frames, so a throw in
1033
+ // between (renderStepTabs on a descriptor without steps is a named one) leaves the tab
1034
+ // labelled with the new project and pointed at the retired id. Falling through to the
1035
+ // call-site catch would report "couldn't check", which describes none of that.
1036
+ // (Found by review round 3.)
1037
+ console.error('[workspaces] re-open after rename threw; this tab is on a retired id: ' + id + ' — ' + ((err && err.message) || err));
1038
+ showToast('This project was renamed elsewhere and this tab couldn’t follow it — reload to continue.', 'warn');
1039
+ // Only ever an id this pass actually checked — never a third project the user switched to
1040
+ // during the re-open, which has been verified against nothing. (Found by review round 4.)
1041
+ validated = current && current.id === id ? id : null;
1042
+ continue;
1043
+ }
1044
+ if (current && current.id === target) {
1045
+ showToast(`This project was renamed to “${current.name}” elsewhere — reopening it here.`, 'warn');
1046
+ } else if (current && current.id === id) {
1047
+ // openProject RESOLVES on its own failures (a swallowed list read, an unknown app) rather
1048
+ // than throwing, so "it returned" is not "it opened" — and this tab is now knowingly on a
1049
+ // retired id, which is the very defect being fixed. Never let that pass in silence.
1050
+ // (Found by review; the first cut only had a `.catch`, which those paths never reach.)
1051
+ console.error('[workspaces] renamed project could not be reopened; this tab is on a retired id: ' + id);
1052
+ showToast('This project was renamed elsewhere and this tab couldn’t follow it — reload to continue.', 'warn');
1053
+ }
1054
+ // Whatever the re-open did, THIS pass is spent: it either landed on `target` (already checked
1055
+ // against the live list above) or reported that it could not. Recording what we now hold stops
1056
+ // the `current.id !== validated` condition from re-running the same failed follow forever.
1057
+ // Only ever record an id this pass ACTUALLY checked, though — if the user switched to a third
1058
+ // project during the re-open, that one has been verified against nothing, and claiming it had
1059
+ // been would exit the loop silently. (Found by review round 3.)
1060
+ validated = current && (current.id === target || current.id === id) ? current.id : null;
1061
+ // A rename that arrived DURING the re-open is not lost — the listener set `reconcileAgain`.
1062
+ } while (reconcileAgain || (current && current.id !== validated));
1063
+ } finally {
1064
+ reconciling = false;
1065
+ }
1066
+ }
1067
+
1068
+ /**
1069
+ * "We could not read the truth" — one exit for both unreadable answers, so they cannot drift apart.
1070
+ * It schedules ONE retry: the event that would have asked again is already consumed and nothing
1071
+ * else re-arms (a read that fails without dropping the socket leaves the status dot green), so a
1072
+ * single transient blip would otherwise cost the reconcile entirely.
1073
+ *
1074
+ * THE BUDGET IS A COUNTER, NOT THE TIMER HANDLE, and that distinction is the whole bound. Round 4
1075
+ * moved the handle to module scope and called it bounded; round 5 found the guard was dead code,
1076
+ * because `reconcileNow` — which the retry itself calls — nulls that handle immediately before this
1077
+ * runs. So the retry's own failure kept scheduling another: a two-second poll for as long as reads
1078
+ * fail, with a warning toast each time and no dedupe behind it. A counter that only a real event
1079
+ * refills cannot be reset by the retry path, so the bound is where it can actually be observed.
1080
+ * The handle stays module-scoped for its own reason — `reconcileNow` clears it, so a real event
1081
+ * supersedes a pending retry rather than racing it.
1082
+ */
1083
+ function reportUnverified() {
1084
+ reconcileAgain = false; // nothing is pending; a leftover `true` reads as "a re-run is coming"
1085
+ showToast('Couldn’t check whether this project is still here — reload if it was changed elsewhere.', 'warn');
1086
+ if (retriesLeft <= 0) return;
1087
+ retriesLeft--;
1088
+ retryTimer = setTimeout(() => { retryTimer = null; if (current) reconcileNow(); }, 2000);
1089
+ }
1090
+
815
1091
  // Translate the failures we can recognise into the user's language, the way kbPaintError does for
816
1092
  // the Knowledge viewer. Returns '' for anything unrecognised — better to show only the raw detail
817
1093
  // than to guess wrong about why. The raw string is shown either way, just demoted.
@@ -1514,7 +1790,7 @@
1514
1790
  const facts = Array.isArray(group.technicalFacts) && group.technicalFacts.length
1515
1791
  ? `<details class="approval-tech"><summary>Technical details</summary>${group.technicalFacts.map((fact) => `<div><b>${escapeHtml(String(fact.label || 'Detail'))}</b> <span>${escapeHtml(String(JSON.stringify(fact.before) ?? '—'))} → ${escapeHtml(String(JSON.stringify(fact.after) ?? '—'))}</span></div>`).join('')}</details>` : '';
1516
1792
  const discard = review.selective ? `<button type="button" class="approval-discard" data-approval-discard="${escapeAttr(group.id)}">Discard change…</button>` : '';
1517
- return `<section class="approval-group" data-approval-group="${escapeAttr(group.id)}"><div class="approval-group-head"><div>`
1793
+ return `<section class="approval-group"><div class="approval-group-head"><div>`
1518
1794
  + `<span class="approval-risk ${escapeAttr(String(group.risk || 'low'))}">${escapeHtml(String(group.risk || 'low'))}</span><b>${escapeHtml(String(group.headline || group.category || 'Change'))}</b></div>`
1519
1795
  + `<span>${escapeHtml(String(group.location || ''))}</span></div><p>${escapeHtml(String(group.detail || ''))}</p>`
1520
1796
  + `<div class="approval-decisions" role="radiogroup" aria-label="Decision for ${escapeAttr(String(group.headline || 'change'))}">`
@@ -1530,7 +1806,7 @@
1530
1806
  const conflictHtml = conflicts.map((conflict) => {
1531
1807
  const picked = conflictDecisions[conflict.id];
1532
1808
  const required = requiredConflictDecision(conflict);
1533
- return `<section class="approval-group approval-conflict" data-approval-conflict-card="${escapeAttr(conflict.id)}"><div class="approval-group-head"><div><span class="approval-risk high">overlap</span><b>${escapeHtml(conflict.headline)}</b></div><span>${escapeHtml(conflict.path)}</span></div><p>${escapeHtml(conflict.detail)}</p>`
1809
+ return `<section class="approval-group approval-conflict"><div class="approval-group-head"><div><span class="approval-risk high">overlap</span><b>${escapeHtml(conflict.headline)}</b></div><span>${escapeHtml(conflict.path)}</span></div><p>${escapeHtml(conflict.detail)}</p>`
1534
1810
  + `<div class="approval-decisions" role="radiogroup" aria-label="Overlap decision for ${escapeAttr(conflict.path)}">`
1535
1811
  + `<button type="button" role="radio" aria-checked="${String(picked === 'use-draft')}" class="${picked === 'use-draft' ? 'selected' : ''}" data-approval-conflict="use-draft" data-conflict-id="${escapeAttr(conflict.id)}"${required !== 'use-draft' ? ' disabled' : ''}>Use my DRAFT value</button>`
1536
1812
  + `<button type="button" role="radio" aria-checked="${String(picked === 'keep-latest-pending')}" class="${picked === 'keep-latest-pending' ? 'selected' : ''}" data-approval-conflict="keep-latest-pending" data-conflict-id="${escapeAttr(conflict.id)}"${required !== 'keep-latest-pending' ? ' disabled' : ''}>Keep v${escapeHtml(String(review.moveForward.toVersion))} · save mine as pending</button></div></section>`;
@@ -1581,6 +1857,23 @@
1581
1857
  if (currentStep !== 'history' && win && typeof win.flushContract === 'function') await win.flushContract();
1582
1858
  const review = await api(`/api/projects/${encodeURIComponent(project.id)}/approval-review`);
1583
1859
  if (!current || current.id !== project.id || !approvalDialogState) return;
1860
+ // THE SECOND CONSUMER of this route, and it needs the same guard `refreshApprovalState` has —
1861
+ // found by review, having shipped without it. The quiet answer is a 200, so `api()` no longer
1862
+ // throws and the catch below no longer sees it; the success path would then read a body with no
1863
+ // `groups` as a review of ZERO changes. That is not a cosmetic mis-render: `pendingCount: 0` with
1864
+ // a null `headVersion` matches NO branch in `renderApprovalHeader`, so the header falls through
1865
+ // to the enabled default "Review & approve" — on a project the server has just said cannot be
1866
+ // approved at all — while the modal claims "No pending changes". Reachable today from History's
1867
+ // empty state and the Exports gate, both of which offer Approve whenever a model is present,
1868
+ // which is exactly the shape of a legacy project.
1869
+ if (review.reviewable === false) {
1870
+ closeApprovalReview();
1871
+ approvalState = { status: 'unreviewable', reason: review.reason, review: null, pendingCount: 0,
1872
+ headVersion: null, error: review.message || 'This project cannot be approved.' };
1873
+ renderApprovalHeader();
1874
+ showToast(review.message || 'This project cannot be approved.', 'warn');
1875
+ return;
1876
+ }
1584
1877
  approvalDialogState.review = review;
1585
1878
  approvalState = { status: 'ready', review, pendingCount: Array.isArray(review.groups) ? review.groups.length : 0,
1586
1879
  headVersion: approvalHeadVersion(review), error: '' };
@@ -1685,7 +1978,15 @@
1685
1978
  });
1686
1979
  $approveBtn?.addEventListener('click', () => {
1687
1980
  if ($approveBtn.getAttribute('aria-disabled') === 'true') {
1688
- if (approvalState.status === 'error' || approvalState.status === 'unavailable') refreshApprovalState();
1981
+ // Re-ask only where the answer can differ. A failed probe can; so can `no-contract`, which stops
1982
+ // being true the moment anything writes a model — and the writers we know about say so
1983
+ // explicitly, but this is the backstop for the ones we do not (another tab, the terminal AI, a
1984
+ // project-scoped SSE the shell does not currently forward). `no-incarnation` cannot: nothing the
1985
+ // user does on THIS screen mints an incarnation, so re-asking would spend a request to redraw the
1986
+ // identical refusal, and teach that clicking a refusal again might work.
1987
+ const retryable = approvalState.status === 'error' || approvalState.status === 'unavailable'
1988
+ || (approvalState.status === 'unreviewable' && approvalState.reason === 'no-contract');
1989
+ if (retryable) refreshApprovalState();
1689
1990
  return;
1690
1991
  }
1691
1992
  approveProject();
@@ -5072,6 +5373,13 @@
5072
5373
  // stays gated, telling the user to read a drawing they just finished reading. (approveProject
5073
5374
  // re-probes so the ACTION is never blocked; this stops the chrome lying in the meantime.)
5074
5375
  refreshModelPresence(current.id, current.app).catch(() => { /* header stays as-is */ });
5376
+ // AND the approval state, which model presence alone no longer covers. Before "not reviewable"
5377
+ // was told apart from "the probe failed", an empty project sat in the ERROR state here and the
5378
+ // header's click-to-retry quietly repaired it on the next click. That retry is gone by design —
5379
+ // it cannot help a project that is simply too old — so the read completing, which is the event
5380
+ // that just made `no-contract` false, has to say so itself. Without this the header keeps
5381
+ // telling someone to read a drawing they have this second finished reading.
5382
+ refreshApprovalState(current.id).catch((e) => console.error('[workspaces] approval header did not refresh after the read', e));
5075
5383
  if (!$wsHistory.hidden) renderHistory();
5076
5384
  // …and the Exports pane, if it is the one showing. "Exports re-lock" was the intent, but
5077
5385
  // nothing repainted them: the pane kept its live buttons and its per-destination Details
@@ -6429,6 +6737,18 @@
6429
6737
  if (!$wsHistory.hidden) renderHistory();
6430
6738
  if (!$wsExports.hidden) renderExports();
6431
6739
  syncWorkspaceGuide();
6740
+ // AND the Approve header, for the same reason the line above gives. Converting a legacy
6741
+ // project MINTS its incarnation (`ensureProjectIncarnationLocked`, inside the migration
6742
+ // transaction), so the "duplicate it to sign off" state this header was showing is now false
6743
+ // — and nothing else re-asks. It survived before only because the header's click-to-retry
6744
+ // treated that state as a failed probe; it is not one, so the thing that CHANGES the
6745
+ // condition is what has to say so.
6746
+ // Reported, not swallowed — matching openProject's identical call. `refreshApprovalState`
6747
+ // handles its own fetch failures, so the only way this rejects is a throw from the render it
6748
+ // does BEFORE its try (a missing node, a descriptor with no steps). Dropping that would leave
6749
+ // the header still telling the user to duplicate a project whose incarnation was just minted,
6750
+ // with nothing said anywhere.
6751
+ refreshApprovalState(st.projectId).catch((e) => console.error('[workspaces] approval header did not refresh after conversion', e));
6432
6752
  }
6433
6753
  showToast(`Converted to the 3D model — version ${res.versionN} is on History`, 'ok');
6434
6754
  closeMigrate();
@@ -6563,7 +6883,7 @@
6563
6883
  const diffStatus = meta.canDiff
6564
6884
  ? `<div class="sr-only" data-diff-status="${escapeAttr(String(v.n))}" role="status" aria-live="polite"></div>`
6565
6885
  : '';
6566
- const verRow = `<tr class="${v.current ? 'current' : ''}" data-ver="${escapeAttr(String(v.n))}">` +
6886
+ const verRow = `<tr class="${v.current ? 'current' : ''}">` +
6567
6887
  `<td><span class="ver${v.current ? ' cur' : ''}">v${escapeHtml(String(v.n))}</span></td>` +
6568
6888
  `<td class="htime">${escapeHtml(histWhen(v.ts))}</td>` +
6569
6889
  `<td><span class="hby">${avatarFor(v.author)}${escapeHtml(v.author)}</span></td>` +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floless/app",
3
- "version": "0.123.2",
3
+ "version": "0.124.0",
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": {