@floless/app 0.168.0 → 0.169.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.
Files changed (49) hide show
  1. package/cli-actions.mjs +8 -1
  2. package/dist/floless-server.cjs +83100 -68895
  3. package/dist/skills/floless-app-rfi/SKILL.md +4 -2
  4. package/dist/templates/college-phase-exporter.flo +7 -2
  5. package/dist/templates/trimble-list-projects.flo +10 -2
  6. package/dist/web/agent-steps.js +2 -2
  7. package/dist/web/agents.js +49 -13
  8. package/dist/web/app.css +44 -3
  9. package/dist/web/app.js +47 -4
  10. package/dist/web/aware-update-client.js +4 -4
  11. package/dist/web/aware.js +401 -31
  12. package/dist/web/chat.css +10 -0
  13. package/dist/web/chat.js +223 -22
  14. package/dist/web/commands-drawing-check.js +3 -0
  15. package/dist/web/commands-shell.js +111 -4
  16. package/dist/web/commands-steel.js +9 -2
  17. package/dist/web/commands-vector.js +69 -0
  18. package/dist/web/drawing-check-editor.html +10 -0
  19. package/dist/web/drawing-check-editor.js +502 -182
  20. package/dist/web/failure-copy.js +20 -2
  21. package/dist/web/flo-3d.js +310 -0
  22. package/dist/web/flo-card.js +72 -0
  23. package/dist/web/guide.js +3 -1
  24. package/dist/web/index.html +26 -4
  25. package/dist/web/instructor.js +3 -0
  26. package/dist/web/model-editor-steel-adapter.js +41 -1
  27. package/dist/web/model-viewport-toolbar.js +11 -0
  28. package/dist/web/pages.js +17 -14
  29. package/dist/web/panels.js +1 -1
  30. package/dist/web/project-history.js +2 -2
  31. package/dist/web/project-modules.js +3 -3
  32. package/dist/web/project-reconciliation.js +1 -1
  33. package/dist/web/project-rfis.js +2 -2
  34. package/dist/web/project-workflows.js +6 -4
  35. package/dist/web/renderers.js +6 -0
  36. package/dist/web/report-csp.js +68 -0
  37. package/dist/web/revit-editor.js +1 -1
  38. package/dist/web/run-history.js +2 -3
  39. package/dist/web/steel-3d-flo.js +309 -0
  40. package/dist/web/steel-3d-view.js +159 -0
  41. package/dist/web/steel-editor.html +130 -9
  42. package/dist/web/terminal-requests.js +78 -0
  43. package/dist/web/tool-updates.js +3 -2
  44. package/dist/web/vector-3d.html +1 -1
  45. package/dist/web/vector-editor.html +50 -8
  46. package/dist/web/workspace-root-management.js +1 -1
  47. package/dist/web/workspaces.js +626 -140
  48. package/launch.mjs +5 -0
  49. package/package.json +8 -8
package/dist/web/aware.js CHANGED
@@ -354,7 +354,7 @@
354
354
  awareMaintenanceRefused = true;
355
355
  }
356
356
  // The server's own words when it gave some; otherwise the shared failure sentence (#3097), never "HTTP 500".
357
- const serverText = (body.code === 'maintenance-busy' && body.message) || body.error;
357
+ const serverText = (body.code === 'maintenance-busy' && body.message) || personText(body);
358
358
  const err = new Error(serverText || apiFailureText({ status: res.status, body }, readOnly));
359
359
  err.body = body; // preserve the in-band payload (e.g. credentialIssue) for callers
360
360
  err.status = res.status; // callers need to distinguish a terminal refusal from a transient outage
@@ -4515,7 +4515,8 @@
4515
4515
  $reportOverlay.append(mkEl('div', 'spinner'), mkEl('div', null, 'Loading 3D view…'));
4516
4516
  } else {
4517
4517
  $reportFrame3d.hidden = true; $reportFrame3d.removeAttribute('src');
4518
- $reportFrame.hidden = false; $reportFrame.srcdoc = html;
4518
+ // #3130: the report's own content rules ride at its top; lastPaintedHtml keeps exactly what the run produced.
4519
+ $reportFrame.hidden = false; $reportFrame.srcdoc = window.FlolessReportCsp.withReportCsp(html);
4519
4520
  $reportOverlay.hidden = true; $reportOverlay.replaceChildren();
4520
4521
  $reportShare.hidden = false;
4521
4522
  }
@@ -4529,7 +4530,7 @@
4529
4530
  function paintReportWithFiles(html, entry) {
4530
4531
  $reportFrame3d.hidden = true; $reportFrame3d.removeAttribute('src');
4531
4532
  $reportFrame.hidden = false;
4532
- $reportFrame.srcdoc = html;
4533
+ $reportFrame.srcdoc = window.FlolessReportCsp.withReportCsp(html); // #3130
4533
4534
  $reportOverlay.hidden = true; $reportOverlay.replaceChildren();
4534
4535
  $reportOpen.hidden = true;
4535
4536
  $reportShare.hidden = true;
@@ -4603,6 +4604,9 @@
4603
4604
  // and the section speaks to that editor while it is open — the same tabs, by the same code, as the
4604
4605
  // workspace's Model step (web/model-panel-bridge.js).
4605
4606
  let contractEditorApp = null; // the workflow the editor was opened for: Approve bakes that one
4607
+ // What the overlay is showing, for Close's unsaved-work question (#3143): the name that question uses, and whether
4608
+ // the page is one whose unsaved edits Close must ask about through its save state (renderer `asksBeforeClose`).
4609
+ let overlaySurface = { name: 'the editor', asksBeforeClose: false };
4606
4610
  // The regions of #app the overlay covers. Covering them is not enough: Tab from the Close button or the left panel
4607
4611
  // would still reach the header, canvas and footer under it, and Enter there runs or compiles the workflow. Cards
4608
4612
  // drawn above the overlay (#fullscreen-nudge, #ix-ask-menu) are not covered, so they are not listed and stay usable.
@@ -4640,6 +4644,7 @@
4640
4644
  const r = window.CONTRACT_RENDERERS && window.CONTRACT_RENDERERS[type];
4641
4645
  if (!r) return false;
4642
4646
  contractEditorApp = appId;
4647
+ overlaySurface = { name: r.name || 'the editor', asksBeforeClose: !!r.asksBeforeClose };
4643
4648
  overlayModelPanel(!!r.modelPanel);
4644
4649
  coverShell(r.modelPanel ? OVERLAY_COVERS : FULL_WINDOW_COVERS);
4645
4650
  // The editor bakes the .lock on Approve — that control belongs to an editable contract editor, not
@@ -4665,6 +4670,7 @@
4665
4670
  function openLocalViewer(appId, type) {
4666
4671
  const r = window.CONTRACT_RENDERERS && window.CONTRACT_RENDERERS[type];
4667
4672
  if (!r || !r.viewerUrl) return false;
4673
+ overlaySurface = { name: 'the 3D view', asksBeforeClose: false };
4668
4674
  overlayModelPanel(false);
4669
4675
  coverShell(FULL_WINDOW_COVERS);
4670
4676
  const ap = document.getElementById('contract-editor-approve'); if (ap) ap.hidden = true;
@@ -4681,6 +4687,7 @@
4681
4687
  // steel-filter.html (layer/thickness/colour facets + eyedropper). Same seam as the editor: the
4682
4688
  // iframe talks to /api/contract directly and Save writes contract.filter.
4683
4689
  function openFilterView(appId) {
4690
+ overlaySurface = { name: 'the Drawing Filter', asksBeforeClose: false }; // it asks through its own __floGuard
4684
4691
  overlayModelPanel(false);
4685
4692
  coverShell(FULL_WINDOW_COVERS);
4686
4693
  // The filter view has its own Save; the overlay's "Approve & bake lock" (editor-only) would
@@ -4695,19 +4702,78 @@
4695
4702
  $contractEditor.hidden = false;
4696
4703
  return true;
4697
4704
  }
4705
+ // #3143: an editor that autosaves and keeps no copy of its own (the vector editor) exposes contractSaveState() and
4706
+ // flushContract() rather than a __floGuard. An unfinished write is finished first, quietly; whatever is still not
4707
+ // saved after that — a refused write (conflict), a failed one, one still running, or a state that cannot be read —
4708
+ // is asked about, because closing tears the page down and those edits with it. True = close, false = keep it open.
4709
+ const CLOSE_FLUSH_MS = 20000;
4710
+ async function savedOrLetGo(name) {
4711
+ let win = null;
4712
+ try { win = $contractEditorFrame.contentWindow; } catch (_) { win = null; }
4713
+ const read = () => {
4714
+ try { return win && typeof win.contractSaveState === 'function' ? win.contractSaveState() : 'clean'; }
4715
+ catch (_) { return 'unknown'; }
4716
+ };
4717
+ // The wait is capped, the save is not: a save still running at the cap keeps running, and waiting again waits
4718
+ // for THAT save rather than starting another one behind it.
4719
+ let pending = null;
4720
+ const flush = async () => {
4721
+ if (!win || typeof win.flushContract !== 'function') return;
4722
+ if (!pending) {
4723
+ pending = Promise.resolve().then(() => win.flushContract())
4724
+ .catch(() => { /* read() says what is left */ })
4725
+ .finally(() => { pending = null; });
4726
+ }
4727
+ let timer = null;
4728
+ try { await Promise.race([pending, new Promise((resolve) => { timer = setTimeout(resolve, CLOSE_FLUSH_MS); })]); }
4729
+ finally { clearTimeout(timer); }
4730
+ };
4731
+ let state = read();
4732
+ if (state === 'dirty' || state === 'saving') { await flush(); state = read(); }
4733
+ while (state !== 'clean') {
4734
+ const ask = state === 'conflict'
4735
+ ? [`Someone else saved this drawing while you had ${name} open, so your latest changes were not saved. If you close now, they are lost. To keep them, choose Keep editing, then click Save conflict at the top of the editor to pick which version to keep.`,
4736
+ { discard: 'Close without saving', cancel: 'Keep editing', hideSave: true, initialFocus: 'cancel' }]
4737
+ : state === 'unknown'
4738
+ ? [`FloLess couldn’t check whether your changes in ${name} are saved. If you close now, any that are not saved are lost.`,
4739
+ { discard: 'Close anyway', cancel: 'Keep editing', hideSave: true, initialFocus: 'cancel' }]
4740
+ : state === 'saving'
4741
+ ? [`FloLess is still saving your latest changes in ${name}. It is taking longer than usual. If you close now, the save may still finish, or your latest changes may be lost. Wait for the save, or keep editing.`,
4742
+ { confirm: 'Wait for the save', discard: 'Close anyway', cancel: 'Keep editing', initialFocus: 'cancel' }]
4743
+ : [`FloLess couldn’t save your latest changes in ${name}, so they are not saved yet. If you close now, they are lost. Try saving again, or keep editing.`,
4744
+ { confirm: 'Try saving again', discard: 'Close without saving', cancel: 'Keep editing', initialFocus: 'cancel' }];
4745
+ const choice = await confirmUnsavedSwitch('', ask[0], 'Your latest changes aren’t saved', ask[1]);
4746
+ if (choice === 'discard') return true;
4747
+ if (choice !== 'save') return false;
4748
+ state = read(); // the save may have landed while the question was up
4749
+ if (state !== 'clean') { await flush(); state = read(); }
4750
+ }
4751
+ return true;
4752
+ }
4753
+ // One close at a time, from Close and Esc alike (#3143): a second click while the first is still saving or asking
4754
+ // would otherwise run its own close and tear the editor down after the person chose Keep editing.
4755
+ let overlayClosing = false;
4698
4756
  async function closeContractEditor() {
4757
+ if (overlayClosing) return;
4758
+ overlayClosing = true;
4759
+ try { await closeContractEditorOnce(); } finally { overlayClosing = false; }
4760
+ }
4761
+ async function closeContractEditorOnce() {
4699
4762
  // A surface inside the iframe (the steel filter) can expose a same-origin dirty-guard so we show
4700
4763
  // OUR styled confirm modal instead of its native beforeunload "Leave site?" (#170). Cross-origin
4701
4764
  // (about:blank) access throws — treat that as "no guard".
4765
+ const surface = overlaySurface; // each opener sets a new one, so a different editor opened meanwhile is not closed
4766
+ const name = surface.name;
4702
4767
  let guard = null;
4703
4768
  try { guard = $contractEditorFrame.contentWindow && $contractEditorFrame.contentWindow.__floGuard; }
4704
4769
  catch (_) { guard = null; }
4705
4770
  if (guard && typeof guard.isDirty === 'function' && guard.isDirty()) {
4706
- const choice = await confirmUnsavedSwitch('', 'You have unsaved changes to the Drawing Filter. What would you like to do?', 'Unsaved Drawing Filter changes');
4771
+ const choice = await confirmUnsavedSwitch('', `You have unsaved changes in ${name}. What would you like to do?`, `Unsaved changes in ${name}`);
4707
4772
  if (choice === 'cancel') return; // keep the view open
4708
4773
  if (choice === 'save') { const ok = await guard.save(); if (!ok) return; } // save failed → stay open
4709
4774
  else if (choice === 'discard') { try { guard.discard(); } catch (_) {} } // silence the backstop
4710
- }
4775
+ } else if (surface.asksBeforeClose && !(await savedOrLetGo(name))) return; // keep the editor open
4776
+ if (overlaySurface !== surface) return; // the overlay shows something else now; that one closes on its own terms
4711
4777
  $contractEditor.hidden = true;
4712
4778
  overlayModelPanel(false); // the left Model section goes back to the workspace
4713
4779
  // Unhook the focus-on-load first: about:blank loading would otherwise pull focus into the now-hidden frame,
@@ -5269,17 +5335,19 @@
5269
5335
  if (!currentId) return;
5270
5336
  const verb = currentlyFrozen ? 'unfreeze' : 'freeze';
5271
5337
  try {
5272
- await api(`/api/app/${encodeURIComponent(currentId)}/${verb}`, { method: 'POST', body: JSON.stringify({ nodeId }) });
5338
+ const res = await api(`/api/app/${encodeURIComponent(currentId)}/${verb}`, { method: 'POST', body: JSON.stringify({ nodeId }) });
5273
5339
  await loadApp(currentId); // re-read → frozen badge/state repaints
5340
+ // #3132: the workflow had changes nobody approved, so the step changed but the approval did not — say that, not "done".
5341
+ if (res && res.approvalPending && typeof res.notice === 'string') { showToast(res.notice, 'warn'); return; }
5274
5342
  showToast(currentlyFrozen
5275
5343
  ? 'Node unfrozen — it will run normally.'
5276
5344
  : 'Output frozen — this node will replay its last result on the next run.',
5277
5345
  currentlyFrozen ? 'info' : 'ok');
5278
5346
  } catch (e) {
5279
- // Surface the real aware reason the route attached as body.reason — otherwise the friendly
5280
- // lead hides the actual cause. First non-empty line, capped, keeps the warn toast sane.
5347
+ // A reason the route marked diagnostic (AWARE's own output) is for the log and the AI, never
5348
+ // the toast (#3097); any other reason is shown, first non-empty line, capped.
5281
5349
  const lead = (e && e.message) || `Could not ${verb} this node.`;
5282
- const raw = e && e.body && typeof e.body.reason === 'string' ? e.body.reason.trim() : '';
5350
+ const raw = e && e.body && !e.body.diagnostic && typeof e.body.reason === 'string' ? e.body.reason.trim() : '';
5283
5351
  const reason = raw ? (raw.split('\n').find((l) => l.trim()) || '').trim().slice(0, 200) : '';
5284
5352
  showToast(reason ? `${lead} — ${reason}` : lead, 'warn');
5285
5353
  }
@@ -5699,6 +5767,7 @@
5699
5767
  $dont.textContent = (actionLabels && actionLabels.discard) || 'Don’t save';
5700
5768
  $cancel.textContent = (actionLabels && actionLabels.cancel) || 'Cancel';
5701
5769
  $dont.hidden = !!(actionLabels && actionLabels.hideDiscard);
5770
+ $save.hidden = !!(actionLabels && actionLabels.hideSave); // when there is nothing safe to save (a refused write)
5702
5771
  $title.textContent = titleMsg || 'Unsaved input changes'; // reset each call (default = the inputs-switch copy)
5703
5772
  $sub.textContent = subMsg || `You changed the inputs for “${appName}” but haven’t saved them yet. What would you like to do?`;
5704
5773
  showModal($confirmModal);
@@ -5716,6 +5785,7 @@
5716
5785
  else modal.setAttribute('aria-hidden', ariaHidden);
5717
5786
  });
5718
5787
  $dont.hidden = false;
5788
+ $save.hidden = false;
5719
5789
  document.removeEventListener('keydown', onKey, true);
5720
5790
  $save.onclick = $dont.onclick = $cancel.onclick = $confirmModal.onclick = null;
5721
5791
  if (returnFocus && returnFocus.isConnected && !returnFocus.matches(':disabled,[aria-disabled="true"]')) returnFocus.focus();
@@ -6637,7 +6707,7 @@
6637
6707
  try {
6638
6708
  await api(endpoint, { method: 'POST', body: JSON.stringify({ path: currentSavedPath }) });
6639
6709
  } catch (e) {
6640
- const detail = e && e.body && e.body.error;
6710
+ const detail = personText(e && e.body);
6641
6711
  showToast(detail ? `${failMsg} — ${detail}` : failMsg, 'warn');
6642
6712
  }
6643
6713
  }
@@ -6735,10 +6805,11 @@
6735
6805
  $reportOpen.onclick = () => {
6736
6806
  const html = lastPaintedHtml || $reportFrame.srcdoc;
6737
6807
  if (!html) return;
6738
- // Open via a blob: URL — an opaque origin, so the report can't script the
6739
- // app origin (mirrors the iframe's sandbox intent).
6740
- const url = URL.createObjectURL(new Blob([html], { type: 'text/html' }));
6741
- window.open(url, '_blank');
6808
+ // #3130: a blob: URL has THIS page's origin, so the report is never the blob itself — it would run as FloLess. The blob
6809
+ // is a script-free page holding the report in a sandboxed, opaque-origin frame (web/report-csp.js).
6810
+ const doc = window.FlolessReportCsp.openDocument(html, lastPaintedInteractive, apps.get(currentId)?.displayName);
6811
+ const url = URL.createObjectURL(new Blob([doc], { type: 'text/html' }));
6812
+ window.open(url, '_blank', 'noopener');
6742
6813
  setTimeout(() => URL.revokeObjectURL(url), 30000);
6743
6814
  };
6744
6815
 
@@ -7036,6 +7107,7 @@
7036
7107
  document.getElementById('bake-cancel').onclick = () => hideModal($bakeModal);
7037
7108
  document.getElementById('bake-confirm').onclick = () => runBake();
7038
7109
  onBackdropDismiss($bakeModal, () => hideModal($bakeModal), () => !document.getElementById('bake-confirm').disabled);
7110
+ onEscapeDismiss($bakeModal, () => hideModal($bakeModal), () => !document.getElementById('bake-cancel').disabled);
7039
7111
 
7040
7112
  // ── Graft into agent ────────────────────────────────────────────────────────
7041
7113
  // Build an agent from a foreign tool (DLL / C# source / NuGet / OpenAPI / …).
@@ -8838,7 +8910,7 @@
8838
8910
  async function runWfUpdate(u, opts = {}) {
8839
8911
  const prior = _wfRowState.get(u.id);
8840
8912
  if (prior && (prior.state === 'busy' || prior.state === 'undoing')) return false;
8841
- _wfRowState.set(u.id, { state: 'busy', offer: u });
8913
+ _wfRowState.set(u.id, { state: 'busy', offer: u, since: Date.now() });
8842
8914
  wfRowsChanged();
8843
8915
  try {
8844
8916
  const r = await fetch(`/api/workflows/${encodeURIComponent(u.id)}/update`, { method: 'POST', headers: { 'content-type': 'application/json' },
@@ -8911,7 +8983,7 @@
8911
8983
  : opts.recovery ? wfRecoveryOf(id) : s;
8912
8984
  if (!handle || !handle.backupPath || s.state === 'undoing' || s.state === 'busy') return;
8913
8985
  const putBack = (patch = {}) => { _wfRowState.set(id, { ...s, ...patch }); if (s.state === 'idle' && !Object.keys(patch).length) _wfRowState.delete(id); };
8914
- _wfRowState.set(id, { ...s, state: 'undoing' });
8986
+ _wfRowState.set(id, { ...s, state: 'undoing', since: Date.now() });
8915
8987
  wfRowsChanged();
8916
8988
  try {
8917
8989
  const r = await fetch(`/api/workflows/${encodeURIComponent(id)}/undo-update`, { method: 'POST', headers: { 'content-type': 'application/json' },
@@ -8923,6 +8995,8 @@
8923
8995
  const later = d.replacedLater && d.backupPath ? { backupPath: d.backupPath, sourceHash: d.sourceHash } : null;
8924
8996
  if (later) wfRecoverySet(id, later.backupPath, later);
8925
8997
  _wfRowState.set(id, { state: 'undone', offer: s.offer, version: d.version });
8998
+ // Paint it now: the refresh below may fail, and the dialog must not keep Not now waiting on a finished Undo (#3147).
8999
+ wfRowsChanged();
8926
9000
  const text = `Put “${wfUpdateLabel(id)}” back to ${d.version}.`
8927
9001
  + (d.replacedLater ? ' The changes made after the update are in a backup.' : '')
8928
9002
  + (d.knowledgePinNotRestored ? ' Its pinned knowledge was not brought back: pin it again in Knowledge if it needs it.' : '');
@@ -9023,8 +9097,11 @@
9023
9097
  const line = document.createElement('span');
9024
9098
  line.className = 'tool-updates-needs-sentence';
9025
9099
  const changed = wfRowChanged(s, u);
9026
- if (s.state === 'busy') line.textContent = 'Updating… a backup is saved first.';
9027
- else if (s.state === 'undoing') line.textContent = 'Putting your previous version back…';
9100
+ // In the header dialog the row also says why Not now waits, or that it no longer has to (#3147).
9101
+ const waits = !opts.textOnly ? '' : wfWaitedLong(s) ? ' This is taking longer than usual. You can close this; it still finishes.'
9102
+ : ' You can close this when it finishes.';
9103
+ if (s.state === 'busy') line.textContent = 'Updating… a backup is saved first.' + waits;
9104
+ else if (s.state === 'undoing') line.textContent = 'Putting your previous version back…' + waits;
9028
9105
  else if (s.state === 'done') line.textContent = s.laterChanges ? WF_LATER_CHANGES : 'Updated and ready to run. Your previous version is saved.';
9029
9106
  else if (recovery?.laterChanges) line.textContent = WF_LATER_CHANGES;
9030
9107
  else if (s.state === 'undone') line.textContent = recovery ? 'Your previous version is back. The changes made after the update are in a backup.' : 'Your previous version is back.';
@@ -9116,8 +9193,30 @@
9116
9193
  if (cancel) {
9117
9194
  cancel.textContent = s.state === 'done' ? 'Close' : 'Not now';
9118
9195
  cancel.hidden = s.state === 'undone'; // Done is the only thing left to do
9196
+ // #3147: closing mid-update would hide work still running, then a toast and a reload would land from nowhere.
9197
+ cancel.disabled = wfModalWorking();
9198
+ if (cancel.disabled) cancel.setAttribute('data-blocked-reason', s.state === 'busy' ? 'Still updating. You can close this when it finishes.'
9199
+ : 'Still putting your previous version back. You can close this when it finishes.');
9200
+ else cancel.removeAttribute('data-blocked-reason');
9201
+ // A run that never answers must not hold the dialog open: repaint when the wait is up, and Not now comes back.
9202
+ clearTimeout(_wfModalWaitTimer);
9203
+ if (cancel.disabled) {
9204
+ _wfModalWaitTimer = setTimeout(paintWfUpdateModal, WF_MODAL_WAIT_MS - (Date.now() - s.since) + 50);
9205
+ _wfModalWaitTimer?.unref?.();
9206
+ }
9119
9207
  }
9120
9208
  }
9209
+ const WF_MODAL_WAIT_MS = 30000;
9210
+ let _wfModalWaitTimer = null;
9211
+ /** An update or Undo still running after the wait: the dialog may close, and says the work goes on (#3147). */
9212
+ function wfWaitedLong(s) {
9213
+ return (s.state === 'busy' || s.state === 'undoing') && Date.now() - (s.since || 0) >= WF_MODAL_WAIT_MS;
9214
+ }
9215
+ /** The dialog's update or Undo is running: Not now, Escape and the backdrop wait for it, up to the wait (#3147). */
9216
+ function wfModalWorking() {
9217
+ const s = _wfModalOffer && _wfRowState.get(_wfModalOffer.id);
9218
+ return !!s && (s.state === 'busy' || s.state === 'undoing') && !wfWaitedLong(s);
9219
+ }
9121
9220
  function openWfUpdateModal(u) {
9122
9221
  if (!$wfUpdateModal) return;
9123
9222
  // Confirm exactly the offer displayed here, even if background polling replaces the live list.
@@ -9148,7 +9247,10 @@
9148
9247
  const $cancel = document.getElementById('wf-update-cancel'); if ($cancel) $cancel.onclick = dismissWfUpdateModal;
9149
9248
  const $ok = document.getElementById('wf-update-ok'); if ($ok) $ok.onclick = onWfUpdateOk;
9150
9249
  const $ai = document.getElementById('wf-update-ai'); if ($ai) $ai.onclick = () => { if (_wfModalOffer) openKeepMyChanges(_wfModalOffer); };
9151
- if ($wfUpdateModal) onBackdropDismiss($wfUpdateModal, dismissWfUpdateModal);
9250
+ if ($wfUpdateModal) {
9251
+ onBackdropDismiss($wfUpdateModal, dismissWfUpdateModal, () => !wfModalWorking());
9252
+ onEscapeDismiss($wfUpdateModal, dismissWfUpdateModal, () => !wfModalWorking());
9253
+ }
9152
9254
  }
9153
9255
 
9154
9256
  // The poll deliberately does NOT start here. Module init runs before the boot sequence, so the
@@ -11168,7 +11270,9 @@
11168
11270
  document.getElementById('app')?.removeAttribute('inert');
11169
11271
  }
11170
11272
  if (!licensed) {
11171
- renderGate(status || { state: 'unlicensed' });
11273
+ // #3134: Core opens on the chosen account's signed subscription, so a sign-in with several accounts chooses first.
11274
+ if (status?.reason === 'account-selection-required') renderAccountGate(status.accounts);
11275
+ else renderGate(status || { state: 'unlicensed' });
11172
11276
  return false;
11173
11277
  }
11174
11278
  return true;
@@ -11636,6 +11740,10 @@
11636
11740
  if (access?.reason === 'session-expired') return 'Your FloLess sign-in has expired. Sign in again, then try again.';
11637
11741
  if (access?.reason === 'signed-out') return 'You are signed out of FloLess. Sign in again, then try again.';
11638
11742
  if (access?.reason === 'seat-taken') return 'Your FloLess session has ended. Sign in again, then try again.';
11743
+ // #3134: three reasons that signing in does not fix.
11744
+ if (access?.reason === 'account-selection-required') return 'Your sign-in belongs to more than one FloLess account. Reload FloLess and choose the account to use, then try again.';
11745
+ if (access?.reason === 'core-unavailable') return 'FloLess couldn’t reach floless.io to confirm your subscription. Check your internet connection, then try again.';
11746
+ if (access?.reason === 'update-required') return 'floless.io no longer accepts this version of FloLess. Install the latest FloLess, then try again.';
11639
11747
  return 'Sign in to FloLess to check your account access, then try again.';
11640
11748
  }
11641
11749
 
@@ -14452,7 +14560,9 @@
14452
14560
  try {
14453
14561
  await api(`/api/requests/${encodeURIComponent(id)}/restore`, { method: 'POST', body: '{}' });
14454
14562
  } catch (error) {
14455
- showToast(error?.body?.error || 'FloLess couldn’t restore that request. It is still in Done; try again.', 'warn');
14563
+ showToast(personText(error?.body) || (error?.body?.diagnostic
14564
+ ? 'FloLess couldn’t tell whether that request was restored. Check Requests before trying again.'
14565
+ : 'FloLess couldn’t restore that request. It is still in Done; try again.'), 'warn');
14456
14566
  return false;
14457
14567
  }
14458
14568
  await loadRequests().catch(() => {});
@@ -14475,7 +14585,9 @@
14475
14585
  const body = error?.body;
14476
14586
  if (body?.code === 'request-held' && body.hold) return askDismissHeld(r, body.hold);
14477
14587
  if (body?.code === 'request-already-set-aside' || error?.status === 404) { await loadRequests().catch(() => {}); renderRequests(); return 'gone'; }
14478
- showToast(body?.error || 'FloLess couldn’t set that request aside. It is still in Requests; try again.', 'warn');
14588
+ showToast(personText(body) || (body?.diagnostic
14589
+ ? 'FloLess couldn’t tell whether that request was set aside. Check Requests before trying again.'
14590
+ : 'FloLess couldn’t set that request aside. It is still in Requests; try again.'), 'warn');
14479
14591
  return 'error';
14480
14592
  }
14481
14593
  return afterDismissed(r);
@@ -14606,7 +14718,11 @@
14606
14718
  if (result.failed > 0) {
14607
14719
  showToast(`${result.restored ? `${put} ` : ''}${result.failed} couldn’t be put back, so ${result.failed === 1 ? 'it is' : 'they are'} still in Done. Press Undo again to retry.`, 'warn');
14608
14720
  } else showToast(put, 'ok');
14609
- } catch (error) { showToast(error?.body?.error || 'FloLess couldn’t undo that. The requests are still in Done.', 'warn'); }
14721
+ } catch (error) {
14722
+ showToast(personText(error?.body) || (error?.body?.diagnostic
14723
+ ? 'FloLess couldn’t tell whether the requests were put back. Check Requests before pressing Undo again.'
14724
+ : 'FloLess couldn’t undo that. The requests are still in Done.'), 'warn');
14725
+ }
14610
14726
  await loadRequests().catch(() => {}); renderRequests();
14611
14727
  };
14612
14728
  const close = document.createElement('button');
@@ -18780,7 +18896,8 @@
18780
18896
  riRenderSuccess(r.ref || '', importFailure && r.importDetailsAttached === false ? importFailure.operationId : null, r.queued === true);
18781
18897
  } catch (e) {
18782
18898
  riSubmitting = false;
18783
- const err = (e && e.body && e.body.error) || '';
18899
+ // A code that picks the branch (riSendFailureCopy says the sentence), so the raw `error`, never shown.
18900
+ const err = (e && e.body && typeof e.body.error === 'string' && e.body.error) || '';
18784
18901
  if (err === 'signed_out') {
18785
18902
  riRenderSignIn(); // the action isn't possible until signed in — hide the form, don't grey it out
18786
18903
  } else if (err === 'rate_limited') {
@@ -19188,13 +19305,16 @@
19188
19305
  const duplicate = duplicateNames.get(account.displayName) > 1;
19189
19306
  const role = account.role === 'owner' ? 'Owner' : 'Member';
19190
19307
  const discriminator = duplicate ? ` · account …${String(account.accountId).slice(-8)}` : '';
19308
+ // Named before the discriminator so it survives wrapping; the row stays selectable (the gate then explains).
19309
+ const core = account.coreStatus === 'inactive' ? ' · No active subscription' : '';
19191
19310
  return `<div class="wf-option" role="option" aria-selected="false" tabindex="${index === 0 ? '0' : '-1'}" data-account-id="${escapeHtml(account.accountId)}">
19192
19311
  <span class="ag-option-copy"><span class="wf-option-name">${escapeHtml(account.displayName)}</span>
19193
- <span class="wf-option-meta">${role}${escapeHtml(discriminator)}</span></span></div>`;
19312
+ <span class="wf-option-meta">${role}${core}${escapeHtml(discriminator)}</span></span></div>`;
19194
19313
  }).join('');
19195
19314
  wrap.innerHTML = `<section class="ag-card" role="dialog"${moduleOnly ? '' : ' aria-modal="true"'} aria-labelledby="ag-title" aria-describedby="ag-copy">
19196
19315
  <h1 id="ag-title">Choose an account</h1>
19197
- <p class="ag-copy" id="ag-copy">Your sign-in belongs to more than one FloLess account. Choose which account to use for ${escapeHtml(moduleLabel)} access.</p>
19316
+ <p class="ag-copy" id="ag-copy">Your sign-in belongs to more than one FloLess account. ${moduleOnly
19317
+ ? `Choose which account to use for ${escapeHtml(moduleLabel)} access.` : 'Choose the account to use FloLess with.'}</p>
19198
19318
  ${rows.length ? `<div class="ag-list" id="ag-list" role="listbox" aria-label="FloLess accounts">${options}</div>`
19199
19319
  : '<p class="ag-copy" role="alert">No account is available for this sign-in. Ask your FloLess account owner to add you, or sign in with a different account.</p>'}
19200
19320
  <div class="ag-actions">${moduleOnly ? '<button type="button" id="ag-not-now">Not now</button>' : '<button type="button" id="ag-signout">Sign out</button>'}
@@ -19249,6 +19369,19 @@
19249
19369
  try {
19250
19370
  const response = await api('/api/license/account', { method: 'POST', body: JSON.stringify({ accountId: selected.dataset.accountId }) });
19251
19371
  const access = response.desktopAccess || {};
19372
+ if (access.state === 'active' && !moduleOnly) {
19373
+ // #3134: the choice decides Core. Open FloLess through the ordinary start (live updates, workspace) once the
19374
+ // licence confirms it; an account without an active subscription is asked about here, with the others still listed.
19375
+ let licence = null;
19376
+ try { licence = await api('/api/license/status'); } catch { /* the reload below shows whatever holds */ }
19377
+ if (licence?.reason === 'account-selection-required') {
19378
+ setStatus('That account has no active FloLess subscription. Choose another account, or sign out.', true);
19379
+ return;
19380
+ }
19381
+ setStatus('Confirmed. Opening FloLess…');
19382
+ location.reload();
19383
+ return;
19384
+ }
19252
19385
  if (access.state === 'active') {
19253
19386
  wrap.remove();
19254
19387
  if (appRoot) appRoot.inert = false;
@@ -19322,6 +19455,14 @@
19322
19455
  'signed-out': { headline: 'Sign in to continue',
19323
19456
  body: 'Sign in with your FloLess account to use floless.app.',
19324
19457
  secondary: { label: 'No subscription yet? Subscribe →', href: subUrl } },
19458
+ // #3134: FloLess opens only on floless.io's signed answer about the subscription. Neither of these is fixed by
19459
+ // signing in, so Try again comes first and signing in stays available as a plain link-style button.
19460
+ 'core-unavailable': { headline: 'Can’t confirm your subscription',
19461
+ body: 'FloLess couldn’t reach floless.io to check your subscription. Check your internet connection, then try again.',
19462
+ secondary: null, retry: 'Still couldn’t reach floless.io. Check your connection, then try again.' },
19463
+ 'update-required': { headline: 'Update FloLess to continue',
19464
+ body: 'floless.io no longer accepts this version of FloLess. Install the latest FloLess, then open it again.',
19465
+ secondary: null, retry: 'This version still isn’t accepted. Install the latest FloLess, then open it again.' },
19325
19466
  };
19326
19467
  let copy = COPY[reason] || COPY['signed-out']; // neutral fallback for an unknown/absent reason
19327
19468
  // A lost seat carries a sub-reason; only a genuine takeover should claim "another device".
@@ -19354,6 +19495,11 @@
19354
19495
  #license-gate .lg-status{min-height:18px;margin:14px 0 0;font-size:12.5px;color:var(--text-muted,#9aa5b6);}
19355
19496
  #license-gate .lg-sub{display:inline-block;margin-top:6px;font-size:12.5px;color:var(--accent,#3b82f6);text-decoration:none;}
19356
19497
  #license-gate .lg-sub:hover{text-decoration:underline;}
19498
+ #license-gate .lg-link{appearance:none;background:none;border:none;padding:2px 4px;margin-top:6px;cursor:pointer;
19499
+ font:inherit;font-size:12.5px;color:var(--accent,#3b82f6);}
19500
+ #license-gate .lg-link:hover{text-decoration:underline;}
19501
+ #license-gate .lg-link:disabled{opacity:.6;cursor:default;text-decoration:none;}
19502
+ #license-gate .primary:focus-visible,#license-gate .lg-link:focus-visible{outline:2px solid var(--accent,#3b82f6);outline-offset:2px;}
19357
19503
  #license-gate .lg-version{margin:18px 0 0;font-size:11px;font-family:var(--mono,monospace);color:var(--text-muted,#9aa5b6);}`;
19358
19504
  document.head.appendChild(style);
19359
19505
  const wrap = document.createElement('div');
@@ -19373,8 +19519,10 @@
19373
19519
  </svg></div>
19374
19520
  <h1>${escapeHtml(copy.headline)}</h1>
19375
19521
  <p>${escapeHtml(copy.body)}</p>
19376
- <button id="lg-signin" class="primary" data-command-id="shell.license-sign-in" aria-describedby="lg-status">Sign in at floless.io</button>
19522
+ ${copy.retry ? '<button id="lg-retry" class="primary" data-command-id="shell.license-retry" aria-describedby="lg-status">Try again</button>'
19523
+ : '<button id="lg-signin" class="primary" data-command-id="shell.license-sign-in" aria-describedby="lg-status">Sign in at floless.io</button>'}
19377
19524
  <p class="lg-status" id="lg-status" role="status"></p>
19525
+ ${copy.retry ? '<button id="lg-signin" class="lg-link" data-command-id="shell.license-sign-in" aria-describedby="lg-status">Sign in again</button>' : ''}
19378
19526
  ${copy.secondary ? `<a class="lg-sub" href="${copy.secondary.href}" target="_blank" rel="noopener">${escapeHtml(copy.secondary.label)}</a>` : ''}
19379
19527
  <p class="lg-version" id="lg-version"></p>
19380
19528
  </div>`;
@@ -19391,7 +19539,8 @@
19391
19539
  // #2786: one watcher, while a sign-in is under way. It reloads once FloLess is signed in, and says how the latest
19392
19540
  // sign-in ended wherever it was started (here, the report dialog, AI Chat or `floless login`), once per sign-in.
19393
19541
  const view = { waiting: false, shown: null, doneOnly: false };
19394
- const stop = (message) => { view.waiting = false; s.textContent = message; signIn.textContent = 'Try again'; };
19542
+ const signInLabel = copy.retry ? 'Sign in again' : 'Sign in at floless.io';
19543
+ const stop = (message) => { view.waiting = false; s.textContent = message; signIn.textContent = copy.retry ? signInLabel : 'Try again'; };
19395
19544
  let generation = 0;
19396
19545
  const watch = async (g = ++generation) => {
19397
19546
  let st; try { st = await api('/api/license/status'); } catch { st = null; }
@@ -19405,7 +19554,7 @@
19405
19554
  generation += 1; // an older watch stops here, so it cannot write over this sign-in while it registers
19406
19555
  view.waiting = false;
19407
19556
  s.textContent = 'Opening sign-in in your browser…';
19408
- signIn.textContent = 'Sign in at floless.io';
19557
+ signIn.textContent = signInLabel;
19409
19558
  // Starting registers the sign-in with floless.io first, so it can take a moment: one start at a time.
19410
19559
  signIn.disabled = true;
19411
19560
  signIn.setAttribute('data-blocked-reason', SIGN_IN_STARTING);
@@ -19420,6 +19569,46 @@
19420
19569
  watch();
19421
19570
  };
19422
19571
  watch(); // a sign-in started before this screen showed (or one that already ended) is said here too
19572
+ const retry = document.getElementById('lg-retry');
19573
+ if (retry) {
19574
+ // Asks the server again. FloLess opens through its ordinary start once floless.io confirms the subscription (or
19575
+ // asks which account to use); otherwise the screen says it still could not, and the button stays.
19576
+ // Anything but the same answer opens FloLess or shows the screen that answer needs, through the ordinary start.
19577
+ const changed = (st) => !!st && (st.state === 'valid' || st.state === 'offline-grace'
19578
+ || (st.state === 'expired' ? 'expired' : st.reason) !== reason);
19579
+ retry.onclick = async () => {
19580
+ if (retry.disabled) return;
19581
+ retry.disabled = true; retry.setAttribute('aria-busy', 'true');
19582
+ s.textContent = 'Checking with floless.io…';
19583
+ let st = null;
19584
+ try { st = await api('/api/license/status?fresh=1'); } catch { st = null; }
19585
+ if (changed(st)) {
19586
+ s.textContent = st.state === 'valid' || st.state === 'offline-grace' ? 'Confirmed. Opening FloLess…' : '';
19587
+ location.reload();
19588
+ return;
19589
+ }
19590
+ retry.disabled = false; retry.removeAttribute('aria-busy');
19591
+ s.textContent = copy.retry;
19592
+ retry.focus();
19593
+ };
19594
+ retry.focus();
19595
+ // A passing outage (floless.io slow to answer, or this PC still busy starting FloLess) should not need a click:
19596
+ // while this screen shows, ask again quietly every 20 s. Each ask is a fresh check (the server keeps any answer a
19597
+ // minute otherwise, and lets at most one fresh check through every few seconds whoever asks).
19598
+ if (reason === 'core-unavailable') {
19599
+ const quiet = async () => {
19600
+ if (!retry.isConnected) return;
19601
+ if (!retry.disabled) {
19602
+ let st = null;
19603
+ try { st = await api('/api/license/status?fresh=1'); } catch { st = null; }
19604
+ if (!retry.isConnected) return;
19605
+ if (changed(st)) { location.reload(); return; }
19606
+ }
19607
+ setTimeout(quiet, 20_000);
19608
+ };
19609
+ setTimeout(quiet, 20_000);
19610
+ }
19611
+ }
19423
19612
  }
19424
19613
 
19425
19614
  // ── Custom Panels bridge (web/panels.js) ─────────────────────────────────────
@@ -19515,6 +19704,9 @@
19515
19704
  // The Workflows tab's home, the counterpart of the Workspaces landing: a create card and one card per workflow. It
19516
19705
  // renders AWARE's library listing; it composes nothing.
19517
19706
  const $wfLanding = document.getElementById('wf-landing');
19707
+ // The workflow card ⋯ menu (openWorkflowCardMenu) and which card it is open for: { key (the owned workflowId), name, canCopy }.
19708
+ const $wfCardMenu = document.getElementById('wf-card-menu');
19709
+ let wfCardMenuFor = null;
19518
19710
  // #2866: a changed Sort by choice repaints the Workflows tab (the render keeps search, focus and open sections).
19519
19711
  globalThis.flolessLandingSort?.onChange('workflows', () => { if (wfLanding) renderWorkflowsLanding(); });
19520
19712
  // The landing search's query, kept outside the input because the landing re-renders with innerHTML.
@@ -19530,6 +19722,7 @@
19530
19722
  if (next && !wfLanding) wfLandingQuery = ''; // a fresh visit starts unfiltered
19531
19723
  wfLanding = next;
19532
19724
  if (wfLanding) closeDraftView();
19725
+ syncWorkflowCardMenu();
19533
19726
  document.body.classList.toggle('wf-landing-open', wfLanding);
19534
19727
  if ($wfLanding) $wfLanding.hidden = !wfLanding;
19535
19728
  // Nothing reads routines at startup (only the Routines window, routine events and a few report paths do), so the
@@ -19650,8 +19843,152 @@
19650
19843
  if (keepCaret) { const box = $wfLanding.querySelector('#wf-landing-search'); box?.focus(); box?.setSelectionRange?.(keepCaret[0], keepCaret[1]); }
19651
19844
  }
19652
19845
 
19846
+ // ── Workflow card ⋯ menu (Workflows page) — the same Rename… / Duplicate / Archive a project card offers, run
19847
+ // through the dialogs the workflow picker already uses, so every check and message is the picker's own. Only a card of
19848
+ // a workflow of yours (compiled or draft) has one. An installed card has none: renaming or copying an installed
19849
+ // workflow makes an installed app the Workflows page does not list, so a renamed one vanishes and a copy never
19850
+ // appears (#3182).
19851
+ function placeWorkflowCardMenu(anchor) {
19852
+ const r = anchor.getBoundingClientRect();
19853
+ // 288 = the menu's 280px width (.menu) + an 8px margin; flip above the ⋯ when the window has no room below.
19854
+ $wfCardMenu.style.left = Math.round(Math.max(8, Math.min(r.right - 280, window.innerWidth - 288))) + 'px';
19855
+ const below = r.bottom + 6;
19856
+ const height = $wfCardMenu.offsetHeight;
19857
+ $wfCardMenu.style.top = Math.round(below + height <= window.innerHeight - 8 ? below : Math.max(8, r.top - 6 - height)) + 'px';
19858
+ anchor.setAttribute('aria-expanded', 'true');
19859
+ // Where the ⋯ was when the menu was placed: a scroll that moves it from here closes the menu.
19860
+ if (wfCardMenuFor) wfCardMenuFor.placedAt = { top: r.top, left: r.left };
19861
+ }
19862
+ function workflowCardMenuAnchor() {
19863
+ return wfCardMenuFor && $wfLanding?.querySelector(`[data-wf-kebab="${CSS.escape(wfCardMenuFor.key)}"]`);
19864
+ }
19865
+ // focusInstead: a visible control to take focus when the ⋯ may be out of view (a scroll closed the menu).
19866
+ function closeWorkflowCardMenu(returnFocus, focusInstead = null) {
19867
+ if (!$wfCardMenu || $wfCardMenu.hidden) { wfCardMenuFor = null; return; }
19868
+ const anchor = workflowCardMenuAnchor();
19869
+ // Focus on the menu or on its own ⋯ (a click there focuses it) belongs to the menu, and moves with it.
19870
+ const hadFocus = $wfCardMenu.contains(document.activeElement) || (!!anchor && document.activeElement === anchor);
19871
+ $wfCardMenu.hidden = true;
19872
+ $wfCardMenu.classList.remove('show');
19873
+ anchor?.setAttribute('aria-expanded', 'false');
19874
+ // Give focus back to the ⋯ before an item's dialog opens, so the dialog returns it to a live control, not <body>.
19875
+ // Closing never scrolls the page (preventScroll).
19876
+ const target = focusInstead || anchor;
19877
+ if (target && (returnFocus || hadFocus)) target.focus(target === anchor ? { focusVisible: true, preventScroll: true } : { preventScroll: true });
19878
+ wfCardMenuFor = null;
19879
+ }
19880
+ // Called after each repaint of the landing (any tab) and on show/hide: the menu lives outside the landing, so a repaint
19881
+ // leaves it open. Keep it pinned to the rebuilt ⋯, or close it when the landing is hidden, another tab is showing, or
19882
+ // that card is gone (archived). A rename keeps the card: the menu is keyed by the workflow's id, not its name.
19883
+ function syncWorkflowCardMenu() {
19884
+ if (!wfCardMenuFor) return;
19885
+ const anchor = wfLanding && wfLandingTab === 'workflows' ? workflowCardMenuAnchor() : null;
19886
+ if (!anchor) { closeWorkflowCardMenu(false); return; }
19887
+ // A card the search filter hid (it hides every card it rules out, then any section left empty), or one in a closed
19888
+ // section, has left the page too: focus goes to the title.
19889
+ const card = anchor.closest('.ws-card');
19890
+ if (!card || card.hidden || card.closest('details.wf-section:not([open])')) {
19891
+ closeWorkflowCardMenu(false, $wfLanding.querySelector('#wf-landing-title'));
19892
+ return;
19893
+ }
19894
+ // Renamed elsewhere, or a draft that gained its file: rebuild the items, so they name it and offer what it has now.
19895
+ if (anchor.dataset.wfKebabName !== wfCardMenuFor.name || (anchor.dataset.wfKebabNoCopy !== '1') !== wfCardMenuFor.canCopy) {
19896
+ openWorkflowCardMenu(anchor, $wfCardMenu.contains(document.activeElement));
19897
+ } else placeWorkflowCardMenu(anchor);
19898
+ }
19899
+ function openWorkflowCardMenu(anchor, focusFirst = false) {
19900
+ if (!$wfCardMenu) return;
19901
+ closeWorkflowCardMenu(false);
19902
+ const d = anchor.dataset;
19903
+ wfCardMenuFor = { key: d.wfKebab, name: d.wfKebabName, canCopy: d.wfKebabNoCopy !== '1' };
19904
+ const { key, name } = wfCardMenuFor;
19905
+ // Each item's Instructor carrier is passed whole by its caller: a command id is never assembled from parts.
19906
+ const item = (act, carrier, text) => `<button type="button" class="menu-item" role="menuitem" tabindex="-1" data-wf-card-act="${act}" ${carrier}`
19907
+ + ` data-command-instance-label="${escapeAttr(name)}"><span class="menu-label">${escapeHtml(text)}</span></button>`;
19908
+ $wfCardMenu.setAttribute('aria-label', `Actions for ${name}`);
19909
+ $wfCardMenu.innerHTML = item('rename', `data-command-id="shell.workflows-landing-rename#${escapeAttr(key)}"`, 'Rename…')
19910
+ + (wfCardMenuFor.canCopy ? item('duplicate', `data-command-id="shell.workflows-landing-duplicate#${escapeAttr(key)}"`, 'Duplicate') : '')
19911
+ + '<div class="menu-divider" role="separator"></div>' + item('archive', `data-command-id="shell.workflows-landing-archive#${escapeAttr(key)}"`, 'Archive');
19912
+ document.dispatchEvent(new Event('floless:passive-overlay-yield'));
19913
+ $wfCardMenu.hidden = false;
19914
+ $wfCardMenu.classList.add('show');
19915
+ placeWorkflowCardMenu(anchor);
19916
+ if (focusFirst) $wfCardMenu.querySelector('.menu-item')?.focus();
19917
+ }
19918
+ if ($wfCardMenu) {
19919
+ $wfCardMenu.addEventListener('click', (event) => {
19920
+ const act = event.target.closest('[data-wf-card-act]');
19921
+ if (!act || !wfCardMenuFor) return;
19922
+ const t = wfCardMenuFor;
19923
+ closeWorkflowCardMenu(true);
19924
+ const which = act.dataset.wfCardAct;
19925
+ // The dialogs report their own failures; this catches one that escapes them (before their try), so a click never
19926
+ // ends in silence.
19927
+ const run = (pending, what) => Promise.resolve(pending).catch((error) => reportErr(error, what));
19928
+ if (which === 'rename') void run(renameOwnedWorkflow(t.key, t.name), 'rename this workflow');
19929
+ else if (which === 'duplicate') void run(copyOwnedWorkflow(t.key, t.name), 'copy this workflow');
19930
+ else if (which === 'archive') {
19931
+ // An archived card and its ⋯ are gone after the repaint: focus goes to the Your workflows heading (which now
19932
+ // counts one fewer), or the page title once that section is empty. Cancel leaves focus on the ⋯, so it is untouched.
19933
+ void run(archiveOwnedWorkflow(t.key, t.name), 'archive this workflow').then(() => {
19934
+ if (!wfLanding || document.activeElement !== document.body) return;
19935
+ ($wfLanding.querySelector('.wf-section[data-wf-section="yours"] > summary') || $wfLanding.querySelector('#wf-landing-title'))?.focus();
19936
+ });
19937
+ }
19938
+ });
19939
+ $wfCardMenu.addEventListener('keydown', (event) => {
19940
+ // A shortcut (Ctrl+R Routines, Ctrl+G…) opens its own surface without moving focus: close the menu first and let
19941
+ // the shortcut through, so the next Escape reaches that surface instead of this menu.
19942
+ if (event.ctrlKey || event.metaKey || event.altKey) { closeWorkflowCardMenu(false); return; }
19943
+ const items = [...$wfCardMenu.querySelectorAll('.menu-item')];
19944
+ const at = items.indexOf(document.activeElement);
19945
+ if (event.key === 'Escape' || event.key === 'Tab') {
19946
+ event.preventDefault(); event.stopPropagation(); closeWorkflowCardMenu(true);
19947
+ } else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
19948
+ event.preventDefault();
19949
+ const step = event.key === 'ArrowDown' ? 1 : -1;
19950
+ items[(at + step + items.length) % items.length]?.focus();
19951
+ } else if (event.key === 'Home' || event.key === 'End') {
19952
+ event.preventDefault();
19953
+ items[event.key === 'Home' ? 0 : items.length - 1]?.focus();
19954
+ }
19955
+ });
19956
+ // The menu follows focus: it closes once focus moves anywhere but the menu or its own ⋯ (Tab to another card, a
19957
+ // dialog or a shortcut taking focus), so it never stays open under something else.
19958
+ document.addEventListener('focusin', (event) => {
19959
+ if (!$wfCardMenu.hidden && !$wfCardMenu.contains(event.target) && event.target !== workflowCardMenuAnchor()) closeWorkflowCardMenu(false);
19960
+ });
19961
+ // Focus is normally inside the open menu, whose own handler takes Escape. When it is on the ⋯ itself or nowhere (a
19962
+ // click on the divider), Escape still closes the menu. Capture phase, so nothing under the menu takes that Escape.
19963
+ document.addEventListener('keydown', (event) => {
19964
+ if (event.key !== 'Escape' || $wfCardMenu.hidden || document.querySelector('.modal-backdrop.show')) return;
19965
+ if (event.target !== document.body && event.target !== workflowCardMenuAnchor()) return;
19966
+ event.preventDefault(); event.stopPropagation(); closeWorkflowCardMenu(true);
19967
+ }, true);
19968
+ document.addEventListener('mousedown', (event) => {
19969
+ if ($wfCardMenu.hidden) return;
19970
+ if (!$wfCardMenu.contains(event.target) && !event.target.closest?.('[data-wf-kebab]')) closeWorkflowCardMenu(false);
19971
+ });
19972
+ window.addEventListener('resize', () => closeWorkflowCardMenu(false));
19973
+ // A scroll that moves the ⋯ (the card list, or the whole page in the narrow layout) would leave the fixed menu hanging
19974
+ // away from it, so it closes the menu. A scroll that does not move it is ignored: AI Chat streaming beside the page,
19975
+ // the page's own scroll a moment after coming back to Workflows, a scroll that had already landed when the ⋯ was
19976
+ // clicked. 2px of slack: the card's hover lift moves the ⋯ 1px when the pointer goes into the menu. Focus that was
19977
+ // in the menu or on the ⋯ goes to the Workflows title: in the sticky heading it stays in view; in the narrow layout,
19978
+ // where the whole page scrolls, it is the top of the page, with the search box next in Tab order.
19979
+ document.addEventListener('scroll', (event) => {
19980
+ if ($wfCardMenu.hidden || $wfCardMenu.contains(event.target)) return;
19981
+ const anchor = workflowCardMenuAnchor();
19982
+ const at = wfCardMenuFor?.placedAt;
19983
+ const r = anchor?.getBoundingClientRect();
19984
+ if (anchor && at && Math.abs(r.top - at.top) <= 2 && Math.abs(r.left - at.left) <= 2) return;
19985
+ closeWorkflowCardMenu(false, $wfLanding.querySelector('#wf-landing-title'));
19986
+ }, true);
19987
+ }
19988
+
19653
19989
  function renderWorkflowsLanding() {
19654
19990
  if (!$wfLanding) return;
19991
+ if (wfLandingTab !== 'workflows') syncWorkflowCardMenu(); // the card ⋯ menu lives on the Workflows tab only
19655
19992
  if (wfLandingTab === 'pages') { renderWorkflowsPagesTab(); return; }
19656
19993
  if (wfLandingTab === 'history') { renderWorkflowsHistoryTab(); return; }
19657
19994
  const focusedTab = document.activeElement?.closest?.('#wf-landing [data-wf-tab]')?.dataset.wfTab || null;
@@ -19660,6 +19997,7 @@
19660
19997
  const keepCaret = search ? [search.selectionStart, search.selectionEnd] : null;
19661
19998
  const clearFocused = document.activeElement?.id === 'wf-search-clear';
19662
19999
  const focusedDraft = document.activeElement?.closest?.('#wf-landing [data-wf-draft]')?.dataset.wfDraft || null;
20000
+ const focusedKebab = document.activeElement?.closest?.('#wf-landing [data-wf-kebab]')?.dataset.wfKebab || null;
19663
20001
  const focusedRestore = document.activeElement?.closest?.('[data-wf-restore]')?.dataset.wfRestore || null;
19664
20002
  // Every section (Your workflows, Installed, Archived) is the same disclosure, and each keeps its open state across
19665
20003
  // repaints (apps-changed, search, restore, coming back to the tab); focus on a card inside implies open. Focus on
@@ -19675,6 +20013,8 @@
19675
20013
  const focusedRestored = document.activeElement?.closest?.('[data-wf-restored]')?.dataset.wfRestored || null;
19676
20014
  // #2866: a background repaint (apps-changed, routines) must not drop a keyboard user off the Sort by controls.
19677
20015
  const focusedSort = document.activeElement?.closest?.('#wf-landing .ls-sort button')?.id || null;
20016
+ // The page title takes focus when the landing opens and when a scroll closes a card menu; keep it across a repaint.
20017
+ const titleFocused = document.activeElement?.id === 'wf-landing-title';
19678
20018
  const esc = (s) => String(s ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
19679
20019
  // #2866: the page's Sort by choice orders the cards inside each section; the sections keep their order. Your own
19680
20020
  // workflows carry FloLess's record of when they were created and last changed (made, compiled, renamed, archived);
@@ -19715,6 +20055,13 @@
19715
20055
  // C12 (#1337): owned workflows whose installed copy AWARE could not read show as drafts that need compiling again.
19716
20056
  const unreadableOwned = new Set(wfUnreadable.map((row) => row.workflowId).filter(Boolean));
19717
20057
  const unreadableNote = unreadableWorkflowsNoteHtml(wfUnreadable, esc);
20058
+ // The ⋯ on a card of a workflow of yours (openWorkflowCardMenu): Rename… / Duplicate / Archive. The menu reads what it
20059
+ // acts on from these attributes. A draft with no workflow file yet has nothing to copy, so it is not offered Duplicate.
20060
+ // Installed cards get none (#3182).
20061
+ const kebabHtml = (workflowId, name, canCopy = true) =>
20062
+ `<button type="button" class="ws-kebab wf-kebab" data-wf-kebab="${esc(workflowId)}" data-wf-kebab-name="${esc(name)}"${canCopy ? '' : ' data-wf-kebab-no-copy="1"'}`
20063
+ + ` data-command-id="shell.workflows-landing-actions#${esc(workflowId)}" data-command-instance-label="${esc(name)}"`
20064
+ + ` aria-label="Actions for ${esc(name)}" aria-haspopup="menu" aria-expanded="false" data-tip="${canCopy ? 'Rename · Duplicate · Archive' : 'Rename · Archive'}">⋯</button>`;
19718
20065
  const draftCard = (row) => {
19719
20066
  const recompile = Boolean(row.activePublication);
19720
20067
  const name = row.displayName;
@@ -19723,7 +20070,8 @@
19723
20070
  return `<div class="ws-card wf-card wf-card-draft" role="button" tabindex="0" data-wf-draft="${esc(row.workflowId)}" data-command-id="shell.workflows-landing-open-draft#${esc(name)}" data-command-instance-label="${esc(name)}">`
19724
20071
  + `<div class="ws-body"><div class="wf-card-text"><span class="ws-kind wf-kind is-draft">${chip}</span>`
19725
20072
  + `<div class="ws-name">${esc(name)}</div><div class="ws-meta">${esc(meta)}</div>`
19726
- + (dateLine(row) ? `<div class="ws-meta wf-card-nodes">${esc(dateLine(row))}</div>` : '') + `</div></div></div>`;
20073
+ + (dateLine(row) ? `<div class="ws-meta wf-card-nodes">${esc(dateLine(row))}</div>` : '') + `</div>`
20074
+ + kebabHtml(row.workflowId, name, Boolean(row.hasSource)) + `</div></div>`;
19727
20075
  };
19728
20076
  const card = (row) => {
19729
20077
  const ownedRow = row.ownedWorkflow;
@@ -19735,7 +20083,8 @@
19735
20083
  + `<div class="ws-body"><div class="wf-card-text"><span class="ws-kind wf-kind">${chip}</span>`
19736
20084
  + (scheduledTip ? `<span class="ws-kind wf-kind wf-scheduled" data-tip="${esc(scheduledTip)}">Scheduled</span>` : '')
19737
20085
  + `<div class="ws-name">${esc(name)}</div><div class="ws-meta">${esc(where)}</div>`
19738
- + `<div class="ws-meta wf-card-nodes">${esc(workflowCardMeta(row) + (dateLine(row) ? ` · ${dateLine(row)}` : ''))}</div></div></div></div>`;
20086
+ + `<div class="ws-meta wf-card-nodes">${esc(workflowCardMeta(row) + (dateLine(row) ? ` · ${dateLine(row)}` : ''))}</div></div>`
20087
+ + (ownedRow ? kebabHtml(ownedRow.workflowId, name) : '') + `</div></div>`;
19739
20088
  };
19740
20089
  // One section: a disclosure whose summary names it and counts its cards. Your workflows and Installed start open,
19741
20090
  // Archived starts closed; a section the person opened or closed stays that way (keptSections). The summary's
@@ -19772,14 +20121,19 @@
19772
20121
  if (focusedTab) $wfLanding.querySelector(`[data-wf-tab="${focusedTab}"]`)?.focus();
19773
20122
  if (focusedId) $wfLanding.querySelector(`[data-wf-id="${CSS.escape(focusedId)}"]`)?.focus();
19774
20123
  if (focusedDraft) $wfLanding.querySelector(`[data-wf-draft="${CSS.escape(focusedDraft)}"]`)?.focus();
20124
+ if (focusedKebab) $wfLanding.querySelector(`[data-wf-kebab="${CSS.escape(focusedKebab)}"]`)?.focus();
19775
20125
  if (focusedRestore) $wfLanding.querySelector(`[data-wf-restore="${CSS.escape(focusedRestore)}"]:not(:disabled)`)?.focus();
19776
20126
  if (focusedRestored) $wfLanding.querySelector(`[data-wf-restored="${CSS.escape(focusedRestored)}"]`)?.focus();
19777
20127
  if (focusedSort) $wfLanding.querySelector(`#${CSS.escape(focusedSort)}`)?.focus({ preventScroll: true });
20128
+ if (titleFocused) $wfLanding.querySelector('#wf-landing-title')?.focus({ preventScroll: true });
19778
20129
  // #2603: project-workflows.js paints the set-apart folders it owns the answers for (globalThis: harnesses lack it).
19779
20130
  globalThis.flolessProjectWorkflows?.renderLandingSetApart?.($wfLanding.querySelector('.wf-setapart-slot'), wfSetApart, () => loadApps());
19780
20131
  if (keepCaret) $wfLanding.querySelector('#wf-landing-search')?.focus();
19781
20132
  applyWorkflowsLandingSearch(keepCaret);
19782
20133
  if (clearFocused) $wfLanding.querySelector('#wf-search-clear')?.focus(); // it only exists once the filter ran
20134
+ // Last, once the search filter and the set-apart folders have painted: the open card menu is measured and placed
20135
+ // against the cards as they finally sit, or closed if the filter hid its card.
20136
+ syncWorkflowCardMenu();
19783
20137
  }
19784
20138
 
19785
20139
  /** Hide the workflow cards that don't match the landing search: every typed word must appear somewhere in the
@@ -20107,6 +20461,13 @@
20107
20461
  if (event.target.closest('[data-wf-new]')) { requestNewWorkflow(); return; }
20108
20462
  // Clearing empties the message the button sits in, so focus goes back to the search box.
20109
20463
  if (event.target.closest('#wf-search-clear')) { setWorkflowsLandingQuery(''); $wfLanding.querySelector('#wf-landing-search')?.focus(); return; }
20464
+ const kebab = event.target.closest('[data-wf-kebab]');
20465
+ if (kebab) {
20466
+ // A click opens with focus on the first item, as Enter does, so Tab, the arrows and Escape work straight away.
20467
+ if (wfCardMenuFor?.key === kebab.dataset.wfKebab) closeWorkflowCardMenu(true);
20468
+ else openWorkflowCardMenu(kebab, true);
20469
+ return;
20470
+ }
20110
20471
  const draftEl = event.target.closest('[data-wf-draft]');
20111
20472
  if (draftEl) { if (!landingOpening) openDraftWorkflow(draftEl.dataset.wfDraft); return; }
20112
20473
  const cardEl = event.target.closest('[data-wf-id]');
@@ -20133,6 +20494,13 @@
20133
20494
  setWorkflowsLandingTab(order[to], true);
20134
20495
  return;
20135
20496
  }
20497
+ // Opening the ⋯ menu from the keyboard puts focus on its first item, so the arrows work straight away.
20498
+ const kebab = event.target.closest?.('[data-wf-kebab]');
20499
+ if (kebab && (event.key === 'Enter' || event.key === ' ' || event.key === 'ArrowDown')) {
20500
+ event.preventDefault();
20501
+ openWorkflowCardMenu(kebab, true);
20502
+ return;
20503
+ }
20136
20504
  if (event.key !== 'Enter' && event.key !== ' ') return;
20137
20505
  const target = event.target.closest('[data-wf-id], [data-wf-new], [data-wf-draft]');
20138
20506
  if (!target || target !== event.target) return;
@@ -20386,6 +20754,8 @@
20386
20754
  // writer — the workflow combo keeps updating underneath in Workspaces mode). Pass the open
20387
20755
  // project's name, 'Workspaces' on the landing, or null to hand the tab back to the workflow.
20388
20756
  setWorkspaceTitle(name, landing = false, projectId = null, kind = null) {
20757
+ // Every mode switch ends here; a name means Workspaces or Agents is on screen, where no workflow card is.
20758
+ if (name) closeWorkflowCardMenu(false);
20389
20759
  wsTitleName = name || null;
20390
20760
  wsTitleKind = wsTitleName && kind === 'agents' ? 'agents' : null;
20391
20761
  wsTitleLanding = !!(wsTitleName && landing);