@floless/app 0.165.0 → 0.167.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 (34) hide show
  1. package/dist/floless-server.cjs +30794 -25371
  2. package/dist/schemas/drawing-check.profile.v1.schema.json +4 -2
  3. package/dist/schemas/steel.model.v2.schema.json +2 -1
  4. package/dist/skills/floless-app-knowledge/SKILL.md +8 -1
  5. package/dist/skills/floless-app-rfi/SKILL.md +7 -2
  6. package/dist/skills/floless-app-steel-model/SKILL.md +4 -1
  7. package/dist/skills/floless-app-steel-takeoff/SKILL.md +31 -17
  8. package/dist/skills/floless-app-steel-takeoff/references/elevation-registration.md +15 -1
  9. package/dist/templates/college-phase-exporter.flo +41 -49
  10. package/dist/templates/screenshot-to-saved-settings.flo +12 -2
  11. package/dist/web/app.css +120 -1
  12. package/dist/web/aware.js +385 -88
  13. package/dist/web/chat-question-card.js +3 -1
  14. package/dist/web/chat.css +32 -0
  15. package/dist/web/chat.js +1021 -88
  16. package/dist/web/commands-drawing-check.js +1 -0
  17. package/dist/web/commands-filter.js +23 -0
  18. package/dist/web/commands-shell.js +231 -19
  19. package/dist/web/commands-steel.js +22 -2
  20. package/dist/web/drawing-check-editor.html +4 -0
  21. package/dist/web/drawing-check-editor.js +82 -2
  22. package/dist/web/index.html +14 -6
  23. package/dist/web/project-history.js +163 -19
  24. package/dist/web/project-modules.js +5 -0
  25. package/dist/web/project-rfis.js +206 -20
  26. package/dist/web/steel-ai-marks.js +173 -2
  27. package/dist/web/steel-editor.html +770 -49
  28. package/dist/web/steel-filter-flo.js +171 -7
  29. package/dist/web/steel-filter.html +36 -10
  30. package/dist/web/steel-model-v2-projection.js +26 -20
  31. package/dist/web/terminal-requests.js +5 -0
  32. package/dist/web/tool-updates.js +65 -20
  33. package/dist/web/workspaces.js +632 -85
  34. package/package.json +3 -2
package/dist/web/aware.js CHANGED
@@ -2694,7 +2694,7 @@
2694
2694
  closeCombo(false);
2695
2695
  const res = await formModal({
2696
2696
  title: 'Duplicate workflow',
2697
- sub: 'Makes an independent copy you can edit and run separately — compiled and ready.',
2697
+ sub: 'Makes a copy that is yours to change. FloLess updates never replace it; the original keeps getting them.',
2698
2698
  fields: [{ name: 'name', label: 'New name', type: 'text', value: `${srcId}-copy`, placeholder: 'e.g. tekla-bom-by-phase-copy' }],
2699
2699
  okLabel: 'Duplicate',
2700
2700
  });
@@ -2888,28 +2888,47 @@
2888
2888
  expectedToVersion: repair.toVersion, expectedTemplateHash: repair.templateHash } : {};
2889
2889
  } catch (e) { reportErr(e); return; }
2890
2890
  const ok = await formModal({
2891
- title: 'Restore the official version?',
2892
- sub: 'Re-installs the official workflow and discards any changes made to its logic. Your saved inputs are kept.'
2893
- + (sourceOnly ? ' This restores the source only. Review it afterwards, then press Compile yourself before running it.' : ''),
2891
+ title: 'Restore FloLess’s version?',
2892
+ sub: 'Puts FloLess’s version of this workflow back and makes it ready to run. Your changes to its steps are replaced; your saved data is kept, and a backup is saved first so you can undo.',
2894
2893
  fields: [],
2895
2894
  okLabel: 'Restore',
2896
2895
  });
2897
2896
  if (!ok) return;
2898
- showToast('Restoring…', 'ok');
2897
+ // Say it is working the moment the person confirms: a restore recompiles and can take a while.
2898
+ const $restore = document.getElementById('restore-btn');
2899
+ const restoreLabel = $restore ? $restore.textContent : '';
2900
+ if ($restore) { $restore.disabled = true; $restore.textContent = 'Restoring…'; $restore.setAttribute('data-blocked-reason', 'Restoring this workflow now.'); }
2901
+ const working = showToast('Restoring… a backup is saved first.', 'progress');
2899
2902
  try {
2900
2903
  const restored = await api(`/api/app/${encodeURIComponent(id)}/restore`, { method: 'POST', body: JSON.stringify(review) });
2901
- await loadApps();
2902
- if (currentId === id) await loadApp(id);
2903
- await refreshWorkflowUpdates(); // back on the channel — re-offer any pending update
2904
- showToast(restored.needsCompile ? 'The official workflow source was restored. Review it, then press Compile yourself before running it.'
2905
- : 'Restored to the official version.', 'ok');
2904
+ working(true);
2905
+ _wfRowState.set(id, { state: 'done', offer: null, toVersion: restored.version, backupPath: restored.backupPath || null, sourceHash: restored.sourceHash });
2906
+ const text = `Restored “${wfDisplayName(id)}” to ${restored.version}. It’s ready to run.`;
2907
+ if (restored.backupPath) {
2908
+ // The Undo stays a full minute (closable sooner): the backup is the way back, so the way to it must not vanish while
2909
+ // the person reads, but it must not sit over their work for good either.
2910
+ const closeUndo = showToast(text, 'ok',
2911
+ { persistent: true, action: { label: 'Undo', commandId: 'shell.workflow-update-undo#' + id, onClick: () => { void undoWfChange(id); } } });
2912
+ if (typeof closeUndo === 'function') setTimeout(closeUndo, 60000)?.unref?.();
2913
+ } else showToast(text, 'ok');
2914
+ if (restored.warning) showToast(restored.warning, 'warn');
2915
+ await wfRefreshAfter(id); // back on the channel — re-offer any pending update
2906
2916
  } catch (e) {
2917
+ working(true);
2907
2918
  if (e.body && (e.body.code === 'update-changed' || e.body.code === 'workflow-changed')) {
2908
2919
  showToast('The workflow or its official version changed after you reviewed it. Your work was kept. Open Restore again to review the current versions.', 'warn');
2909
2920
  return;
2910
2921
  }
2911
2922
  console.error(e);
2912
- showToast('We couldn’t restore that workflow because FloLess could not save it. Try again.', 'warn');
2923
+ showToast(e && e.body && e.body.code === 'rollback-failed'
2924
+ ? 'Couldn’t restore, and FloLess couldn’t put your workflow back as it was, so it may not run. Ask for help: your version is kept in the backup.'
2925
+ : e && e.body && e.body.code === 'needs-consent'
2926
+ ? 'FloLess’s version has an AI step whose answer may differ each run, and you haven’t confirmed that yet, so nothing was changed. Approve the workflow yourself and tick the box, or restore it with AI Chat.'
2927
+ : e && e.body && (e.body.code === 'restore-not-started' || e.body.code === 'restore-failed')
2928
+ ? 'Couldn’t restore that workflow. It is unchanged. Try again.'
2929
+ : 'FloLess couldn’t confirm the restore finished. Reload FloLess to see the workflow, then try again if it still shows your changes.', 'warn');
2930
+ } finally {
2931
+ if ($restore) { $restore.disabled = false; $restore.textContent = restoreLabel; $restore.removeAttribute('data-blocked-reason'); }
2913
2932
  }
2914
2933
  }
2915
2934
 
@@ -8636,18 +8655,17 @@
8636
8655
  // safe to call before this block initialises.
8637
8656
  const $wfUpdate = document.getElementById('wf-update');
8638
8657
  const $wfUpdateModal = document.getElementById('wf-update-modal');
8639
- let _wfUpdateApplying = false;
8640
- let _wfReviewedUpdate = null;
8658
+ let _wfModalOffer = null; // the offer the header dialog shows, frozen as it was opened
8641
8659
  function wfUpdateFor(id) { return _wfUpdates.find((u) => u.id === id) || null; }
8642
8660
  function renderWfUpdatePill() {
8643
8661
  const el = document.getElementById('wf-update');
8644
8662
  if (!el) return;
8645
8663
  const u = currentId ? wfUpdateFor(currentId) : null;
8646
8664
  if (u) {
8647
- el.textContent = '↑ Update to v' + u.available;
8665
+ el.textContent = '↑ Update available';
8648
8666
  el.setAttribute('data-command-id', 'shell.workflow-update#' + u.id);
8649
8667
  el.setAttribute('data-command-instance-label', apps.get(u.id)?.displayName || u.id);
8650
- el.dataset.tip = 'A newer version of this workflow is available — see what changed';
8668
+ el.dataset.tip = `Version ${u.available} of this workflow is available. See what is new and update it in one click.`;
8651
8669
  el.hidden = false;
8652
8670
  } else {
8653
8671
  el.hidden = true;
@@ -8661,91 +8679,365 @@
8661
8679
  _wfUpdates = (r.ok && d.ok && Array.isArray(d.updates)) ? d.updates : [];
8662
8680
  } catch { _wfUpdates = []; }
8663
8681
  renderWfUpdatePill();
8682
+ wfRowsChanged();
8683
+ }
8684
+
8685
+ // ── One-click workflow update (owner ruling 2026-11-02) ──────────────────────────────────────────────────────────
8686
+ // "As soon as they click update, it should update", with a backup so the person can always go back. One row model is
8687
+ // shared by the header dialog (the open workflow) and the status-bar dialog (every workflow): the same states, the same
8688
+ // request, the same Undo. A workflow the person changed is the one case that warns first, because the update replaces
8689
+ // their changes (they stay in the backup). A Steel Model with changes FloLess cannot carry over is reviewed in AI Chat.
8690
+ const _wfRowState = new Map(); // id → { state: 'busy'|'done'|'failed'|'undoing'|'undone', ... }
8691
+ // After Undo anyway, the later work's backup: its own record, so nothing that happens to the row (a new update, a failed
8692
+ // one, the dialog opening) can drop the one handle on that work. Cleared only when its Undo succeeds or the backup is gone.
8693
+ // A list per workflow, newest last: a second Undo anyway never replaces the first one's handle, and each toast keeps its own.
8694
+ const _wfRecovery = new Map(); // id → [{ backupPath, sourceHash, laterChanges? }]
8695
+ const wfRecoveryOf = (id) => (_wfRecovery.get(id) || []).at(-1);
8696
+ function wfRecoverySet(id, backupPath, next) { // next: the new handle, or null to drop it
8697
+ const list = [...(_wfRecovery.get(id) || [])];
8698
+ const at = list.findIndex((h) => h.backupPath === backupPath);
8699
+ if (at < 0) { if (next) list.push(next); } else if (next) list[at] = next; else list.splice(at, 1);
8700
+ if (list.length) _wfRecovery.set(id, list); else _wfRecovery.delete(id);
8701
+ }
8702
+ // Failures that leave the workflow exactly as it was: refused before anything was written, or rolled back from the backup.
8703
+ const WF_UNCHANGED_CODES = new Set(['update-not-started', 'update-failed', 'up-to-date', 'not-installed', 'no-template', 'not-published', 'needs-review', 'needs-consent']);
8704
+ const WF_CHANGED_WARNING = 'You changed this workflow. Updating replaces your changes. They’re kept in the backup.';
8705
+ function wfDisplayName(id) {
8706
+ const a = apps.get(id);
8707
+ return (a && a.displayName) || _wfUpdates.find((u) => u.id === id)?.displayName || _wfRowState.get(id)?.offer?.displayName || id;
8708
+ }
8709
+ function wfWhatsNew(u) {
8710
+ if (u.sourceUpdate?.explanation) return u.sourceUpdate.explanation;
8711
+ const first = Array.isArray(u.changelog) ? u.changelog.find((e) => e && e.summary) : null;
8712
+ return first ? String(first.summary) : 'A newer version from FloLess. Your saved data is kept.';
8713
+ }
8714
+ /** A Steel Model: its update is reviewed in AI Chat, never applied in one click (owner ruling 2026-11-02). */
8715
+ function wfNeedsReview(u) { return !!u.sourceUpdate; }
8716
+ /** Whether the row must warn that updating replaces the person's changes: the offer says so, or the server just did. */
8717
+ function wfRowChanged(s, u) {
8718
+ return !wfNeedsReview(u) && (s.state === 'idle' || s.state === 'failed' || s.state === 'undone') && (!!u.hasChanges || !!s.hasChanges);
8664
8719
  }
8665
- function openWfUpdateModal(u) {
8666
- if (!$wfUpdateModal) return;
8667
- // Confirm exactly the offer displayed here, even if background polling replaces the live list.
8668
- _wfReviewedUpdate = Object.freeze({ ...u });
8669
- const a = apps.get(u.id);
8670
- const name = (a && a.displayName) || u.id;
8671
- document.getElementById('wf-update-title').textContent = u.sourceUpdate?.mode === 'steel-compatibility' ? `Repair “${name}” compatibility`
8672
- : u.sourceUpdate?.mode === 'steel-review' ? `Review the update for “${name}”` : `Update “${name}” to v${u.available}`;
8673
- document.getElementById('wf-update-sub').textContent = `${name} ${u.installed} → ${u.available}${u.sourceUpdate?.mode === 'steel-compatibility' ? ' available · compatibility repair only' : '. What’s new:'}`;
8674
- const note = $wfUpdateModal.querySelector('.wf-update-note');
8675
- if (note) note.textContent = u.sourceUpdate ? `${u.sourceUpdate.explanation} A backup is saved before any source change. Afterwards return to Review and approve your model.` : u.sourceOnly
8676
- ? 'This updates the unchanged older workflow file and saves a backup. It does not approve it. Review the updated workflow, then press Compile yourself before running it.'
8677
- : "Your work is safe — this updates the workflow's steps and keeps your data. A backup of the current version is saved first.";
8678
- const apply = document.getElementById('wf-update-ok');
8679
- if (apply) apply.textContent = u.sourceUpdate?.mode === 'steel-compatibility' ? 'Back up & repair compatibility'
8680
- : u.sourceUpdate?.mode === 'steel-review' ? 'Review in AI Chat' : '↑ Back up & update';
8720
+ /**
8721
+ * What Update all updates, and what its button counts: every offer the person has not changed that is not being worked on
8722
+ * or already updated (its offer can outlive the update until the list refreshes; sending it again would lose its Undo).
8723
+ */
8724
+ function wfUpdateAllTargets() {
8725
+ return _wfUpdates.filter((u) => !u.hasChanges && !wfNeedsReview(u) && !['busy', 'undoing', 'done'].includes(_wfRowState.get(u.id)?.state));
8726
+ }
8727
+ function wfRowsChanged() {
8728
+ if (_wfModalOffer) paintWfUpdateModal();
8729
+ globalThis.dispatchEvent?.(new CustomEvent('floless:workflow-update-rows'));
8730
+ }
8731
+ /** Offers still waiting plus the rows this page updated or undid (they stay listed, with Undo, until the page reloads). */
8732
+ function wfUpdateRowsForDialog() {
8733
+ const ids = new Set(_wfUpdates.map((u) => u.id));
8734
+ const kept = [..._wfRowState.entries()].filter(([id, s]) => !ids.has(id) && s.offer).map(([, s]) => s.offer);
8735
+ // A stable order by name, so a row does not jump when it is updated and leaves the live list.
8736
+ return [..._wfUpdates, ...kept].sort((a, b) => wfDisplayName(a.id).localeCompare(wfDisplayName(b.id)));
8737
+ }
8738
+ function wfUpdateRequestBody(u, replaceChanges) {
8739
+ const steel = u.sourceUpdate;
8740
+ return { expectedFromVersion: u.installed, expectedToVersion: u.available,
8741
+ expectedSourceHash: steel ? steel.sourceHash : (u.bindSourceHash || u.sourceHash),
8742
+ expectedTemplateHash: steel ? steel.templateHash : (u.bindTemplateHash || u.templateHash),
8743
+ ...(steel ? { sourceUpdateMode: steel.mode } : {}), ...(replaceChanges ? { replaceChanges: true } : {}) };
8744
+ }
8745
+ async function runWfUpdate(u, opts = {}) {
8746
+ const prior = _wfRowState.get(u.id);
8747
+ if (prior && (prior.state === 'busy' || prior.state === 'undoing')) return false;
8748
+ _wfRowState.set(u.id, { state: 'busy', offer: u });
8749
+ wfRowsChanged();
8750
+ try {
8751
+ const r = await fetch(`/api/workflows/${encodeURIComponent(u.id)}/update`, { method: 'POST', headers: { 'content-type': 'application/json' },
8752
+ body: JSON.stringify(wfUpdateRequestBody(u, !!opts.replaceChanges)) });
8753
+ const d = await r.json().catch(() => ({}));
8754
+ if (!r.ok || !d.ok) throw Object.assign(new Error(d.error || ''), { code: d.code });
8755
+ _wfRowState.set(u.id, { state: 'done', offer: u, toVersion: d.toVersion, backupPath: d.backupPath, sourceHash: d.sourceHash });
8756
+ wfRowsChanged();
8757
+ document.getElementById('wf-update-announce')?.replaceChildren(`Updated ${wfDisplayName(u.id)} to ${d.toVersion}.`);
8758
+ if (!opts.quiet) {
8759
+ const text = `Updated “${wfDisplayName(u.id)}” to ${d.toVersion}. It’s ready to run.`;
8760
+ if (d.backupPath) {
8761
+ // The Undo stays a full minute (closable sooner), as after a Restore.
8762
+ const closeUndo = showToast(text, 'ok', { persistent: true,
8763
+ action: { label: 'Undo', commandId: 'shell.workflow-update-undo#' + u.id, onClick: () => { void undoWfChange(u.id); } } });
8764
+ if (typeof closeUndo === 'function') setTimeout(closeUndo, 60000)?.unref?.();
8765
+ } else showToast(text, 'ok');
8766
+ }
8767
+ } catch (e) {
8768
+ const message = e.code === 'has-changes' ? WF_CHANGED_WARNING
8769
+ : e.code === 'update-changed' ? 'This update changed a moment ago. Nothing was changed. Check what’s new, then update again.'
8770
+ : e.code === 'in-progress' ? 'This workflow is already being updated.'
8771
+ : e.code === 'forked' ? 'This workflow is your own copy, so FloLess updates don’t replace it. Nothing was changed.'
8772
+ : e.code === 'needs-review' ? 'Steel Model updates are reviewed in AI Chat, so nothing was changed. Review the update in AI Chat; it keeps your model.'
8773
+ : e.code === 'needs-consent' ? 'This workflow has an AI step whose answer may differ each run, and you haven’t confirmed that yet, so nothing was changed. Approve the workflow yourself and tick the box, or update it with AI Chat.'
8774
+ // Put back from the backup failed too: the one outcome where "unchanged" would be untrue.
8775
+ : e.code === 'rollback-failed' ? 'Couldn’t update, and FloLess couldn’t put your workflow back as it was, so it may not run. Restore it, or ask for help: your previous version is kept in the backup.'
8776
+ // Each of these leaves the workflow exactly as it was (refused before, or rolled back from the backup).
8777
+ : WF_UNCHANGED_CODES.has(e.code) ? 'Couldn’t update. Your workflow is unchanged.'
8778
+ // No answer (the connection dropped, or something unexpected): whether it finished is not known.
8779
+ : 'FloLess couldn’t confirm the update finished. Reload FloLess to see the workflow, then try again if it is not updated.';
8780
+ _wfRowState.set(u.id, { state: 'failed', offer: u, message, hasChanges: e.code === 'has-changes' });
8781
+ if (e.code === 'update-changed') {
8782
+ await wfRefreshAfter(null);
8783
+ // The header dialog confirms exactly the offer it shows: show the current one before another click can apply it.
8784
+ if (_wfModalOffer && _wfModalOffer.id === u.id) {
8785
+ const fresh = wfUpdateFor(u.id);
8786
+ if (fresh) { _wfModalOffer = Object.freeze({ ...fresh }); _wfRowState.set(u.id, { state: 'failed', offer: fresh, message }); }
8787
+ else _wfRowState.set(u.id, { state: 'failed', offer: u, message: 'There is no update for this workflow now. Nothing was changed.' });
8788
+ paintWfUpdateModal();
8789
+ }
8790
+ } else wfRowsChanged();
8791
+ return false;
8792
+ }
8793
+ await wfRefreshAfter(u.id);
8794
+ return true;
8795
+ }
8796
+ /** What the screen shows after a change that succeeded: a failed refresh is said, never reported as a failed change. */
8797
+ async function wfRefreshAfter(id) {
8798
+ try {
8799
+ if (id) await loadApps();
8800
+ await refreshWorkflowUpdates();
8801
+ globalThis.dispatchEvent?.(new CustomEvent('floless:workflow-updates-changed'));
8802
+ if (id && currentId === id) await loadApp(id);
8803
+ } catch (e) {
8804
+ console.warn('[workflow-update] refresh after a change failed', e);
8805
+ showToast('The change is saved, but FloLess couldn’t refresh the screen. Reload FloLess to see it.', 'warn');
8806
+ }
8807
+ }
8808
+ const WF_LATER_CHANGES = 'This workflow changed after the update. Undo would replace those later changes; FloLess backs them up first, with their own Undo.';
8809
+ /**
8810
+ * Undo the last update or restore this page made of `id`, from the backup it saved first. When the workflow changed since,
8811
+ * the server says what Undo would replace and the person may Undo anyway: `replaceLater` is that state, exactly as shown.
8812
+ */
8813
+ async function undoWfChange(id, opts = {}) {
8814
+ const s = _wfRowState.get(id) || { state: 'idle' };
8815
+ // `recovery` undoes an Undo anyway (brings that later work back): `true` is the newest, a handle is that exact one (a
8816
+ // toast's). Otherwise this undoes the row's update or restore.
8817
+ const handle = typeof opts.recovery === 'object' ? (_wfRecovery.get(id) || []).find((h) => h.backupPath === opts.recovery.backupPath)
8818
+ : opts.recovery ? wfRecoveryOf(id) : s;
8819
+ if (!handle || !handle.backupPath || s.state === 'undoing' || s.state === 'busy') return;
8820
+ const putBack = (patch = {}) => { _wfRowState.set(id, { ...s, ...patch }); if (s.state === 'idle' && !Object.keys(patch).length) _wfRowState.delete(id); };
8821
+ _wfRowState.set(id, { ...s, state: 'undoing' });
8822
+ wfRowsChanged();
8823
+ try {
8824
+ const r = await fetch(`/api/workflows/${encodeURIComponent(id)}/undo-update`, { method: 'POST', headers: { 'content-type': 'application/json' },
8825
+ body: JSON.stringify({ backupPath: handle.backupPath, expectedSourceHash: handle.sourceHash, ...(opts.replaceLater ? { replaceLater: opts.replaceLater } : {}) }) });
8826
+ const d = await r.json().catch(() => ({}));
8827
+ if (!r.ok || !d.ok) throw Object.assign(new Error(d.error || ''), { code: d.code, current: d.current });
8828
+ if (opts.recovery) wfRecoverySet(id, handle.backupPath, null);
8829
+ // After Undo anyway, the later work is in its own backup, with its own Undo.
8830
+ const later = d.replacedLater && d.backupPath ? { backupPath: d.backupPath, sourceHash: d.sourceHash } : null;
8831
+ if (later) wfRecoverySet(id, later.backupPath, later);
8832
+ _wfRowState.set(id, { state: 'undone', offer: s.offer, version: d.version });
8833
+ const text = `Put “${wfDisplayName(id)}” back to ${d.version}.`
8834
+ + (d.replacedLater ? ' The changes made after the update are in a backup.' : '')
8835
+ + (d.knowledgePinNotRestored ? ' Its pinned knowledge was not brought back: pin it again in Knowledge if it needs it.' : '');
8836
+ if (later) {
8837
+ const closeUndo = showToast(text, 'ok', { persistent: true,
8838
+ action: { label: 'Undo', commandId: 'shell.workflow-update-undo#' + id, onClick: () => { void undoWfChange(id, { recovery: later }); } } });
8839
+ if (typeof closeUndo === 'function') setTimeout(closeUndo, 60000)?.unref?.();
8840
+ } else showToast(text, 'ok');
8841
+ } catch (e) {
8842
+ if (e.code === 'later-changes' && e.current) {
8843
+ // Not a refusal: say what Undo would replace, and let the person choose.
8844
+ if (opts.recovery) { wfRecoverySet(id, handle.backupPath, { ...handle, laterChanges: e.current }); putBack(); }
8845
+ else putBack({ state: 'done', laterChanges: e.current });
8846
+ wfRowsChanged();
8847
+ showToast(WF_LATER_CHANGES, 'warn', { persistent: true, action: { label: 'Undo anyway', commandId: 'shell.workflow-update-undo-anyway#' + id,
8848
+ onClick: () => { void undoWfChange(id, { ...(opts.recovery ? { recovery: handle } : {}), replaceLater: e.current }); } } });
8849
+ return;
8850
+ }
8851
+ // A backup that is gone, or an Undo that broke partway, cannot be retried from here: stop offering it.
8852
+ const final = e.code === 'no-backup' || e.code === 'undo-rollback-failed';
8853
+ if (opts.recovery) { wfRecoverySet(id, handle.backupPath, final ? null : { ...handle, laterChanges: null }); putBack(); }
8854
+ else putBack({ state: 'done', laterChanges: null, ...(final ? { backupPath: null } : {}) });
8855
+ wfRowsChanged();
8856
+ showToast(e.code === 'update-changed' ? 'Open the workflow again before undoing. Nothing was changed.'
8857
+ : e.code === 'no-backup' ? 'That backup is missing or incomplete, so this can’t be undone. Your workflow is unchanged.'
8858
+ : e.code === 'undo-rollback-failed' ? 'Undo stopped partway and couldn’t put the workflow back as it was, so it may not run. Restore it, or ask for help: both earlier versions are kept in the backup.'
8859
+ : e.code === 'undo-failed' ? 'Couldn’t undo, so nothing was changed. The backup is still saved. Try again.'
8860
+ : 'FloLess couldn’t confirm the undo finished. Reload FloLess to see the workflow, then try again if it is not undone.', 'warn');
8861
+ return;
8862
+ }
8863
+ await wfRefreshAfter(id);
8864
+ }
8865
+ /** Update every listed workflow the person has not changed, one after another. Changed ones stay, each with its own choice. */
8866
+ async function updateAllWorkflows() {
8867
+ const plain = wfUpdateAllTargets();
8868
+ let updated = 0;
8869
+ for (const u of [...plain]) { if (await runWfUpdate(u, { quiet: true })) updated++; }
8870
+ if (updated) showToast(`Updated ${updated === 1 ? '1 workflow' : updated + ' workflows'}. Each one has Undo in the list.`, 'ok');
8871
+ return updated;
8872
+ }
8873
+ function openKeepMyChanges(u) {
8874
+ if (typeof window.flolessChat?.openDraft !== 'function' || typeof window.flolessBridge?.openApp !== 'function') {
8875
+ showToast('AI Chat is still starting. Try again in a moment.', 'warn'); return;
8876
+ }
8877
+ dismissWfUpdateModal();
8878
+ globalThis.flolessToolUpdates?.close?.();
8879
+ void (async () => {
8880
+ try {
8881
+ await window.flolessBridge.openApp(u.id);
8882
+ await window.flolessChat.openDraft(`Bring my own changes in the installed workflow ${u.id} (${u.installed}) into FloLess’s newer version ${u.available} of ${u.templateId}. Explain what you will carry across before editing. Keep my saved data. Do not approve anything for me.`);
8883
+ showToast('Your request is ready in AI Chat. Nothing changes until you send it.', 'ok');
8884
+ } catch { showToast('AI Chat could not open for this workflow. Nothing was changed. Try again.', 'warn'); }
8885
+ })();
8886
+ }
8887
+ function wfButton(label, commandId, instance, onClick, cls) {
8888
+ const b = document.createElement('button');
8889
+ b.type = 'button';
8890
+ b.className = 'tool-updates-open' + (cls ? ' ' + cls : '');
8891
+ b.textContent = label;
8892
+ b.setAttribute('data-command-id', commandId + '#' + instance);
8893
+ b.setAttribute('data-command-instance-label', wfDisplayName(instance));
8894
+ b.addEventListener('click', onClick);
8895
+ return b;
8896
+ }
8897
+ /** One row: name and versions, what is new or where it stands, and the one button that does the next thing. */
8898
+ function wfUpdateRow(u, opts = {}) {
8899
+ const s = _wfRowState.get(u.id) || { state: 'idle' };
8900
+ const row = document.createElement('div');
8901
+ row.className = 'tool-updates-needs wf-upd-row';
8902
+ row.setAttribute('data-template-update', u.id);
8903
+ row.setAttribute('data-state', s.state);
8904
+ const recovery = wfRecoveryOf(u.id);
8905
+ if ((s.state === 'done' && s.laterChanges) || (s.state !== 'done' && recovery?.laterChanges)) row.setAttribute('data-next', 'undo-anyway');
8906
+ if (s.state === 'busy' || s.state === 'undoing') row.setAttribute('aria-busy', 'true');
8907
+ const text = document.createElement('div');
8908
+ text.className = 'tool-updates-needs-text';
8909
+ const name = document.createElement('span');
8910
+ name.className = 'tool-updates-needs-name';
8911
+ name.append(wfDisplayName(u.id) + ' ');
8912
+ const ver = document.createElement('span');
8913
+ ver.className = 'wf-upd-ver';
8914
+ ver.textContent = s.state === 'done' ? `now ${s.toVersion}` : s.state === 'undone' ? `back to ${s.version}` : `${u.installed} → ${u.available}`;
8915
+ name.appendChild(ver);
8916
+ // The header dialog already names the workflow, its versions and what is new: its row says only where it stands.
8917
+ if (!opts.textOnly) text.appendChild(name);
8918
+ const line = document.createElement('span');
8919
+ line.className = 'tool-updates-needs-sentence';
8920
+ const changed = wfRowChanged(s, u);
8921
+ if (s.state === 'busy') line.textContent = 'Updating… a backup is saved first.';
8922
+ else if (s.state === 'undoing') line.textContent = 'Putting your previous version back…';
8923
+ else if (s.state === 'done') line.textContent = s.laterChanges ? WF_LATER_CHANGES : 'Updated and ready to run. Your previous version is saved.';
8924
+ else if (recovery?.laterChanges) line.textContent = WF_LATER_CHANGES;
8925
+ 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.';
8926
+ else if (s.state === 'failed' && !s.hasChanges) line.textContent = s.message;
8927
+ else if (!opts.textOnly) { line.textContent = wfWhatsNew(u); line.setAttribute('data-tip', wfWhatsNew(u)); line.classList.add('wf-upd-new'); }
8928
+ if (line.textContent) text.appendChild(line);
8929
+ if (changed) {
8930
+ const warn = document.createElement('span');
8931
+ warn.className = 'wf-upd-warn';
8932
+ warn.textContent = WF_CHANGED_WARNING;
8933
+ text.appendChild(warn);
8934
+ }
8935
+ row.appendChild(text);
8936
+ if (opts.textOnly) return row;
8937
+ const actions = document.createElement('div');
8938
+ actions.className = 'wf-upd-actions';
8939
+ if (s.state === 'busy' || s.state === 'undoing') {
8940
+ const b = wfButton(s.state === 'busy' ? 'Updating…' : 'Undoing…', 'shell.workflow-update-apply', u.id, () => {});
8941
+ b.disabled = true; b.setAttribute('data-blocked-reason', 'Already working on this workflow.');
8942
+ actions.appendChild(b);
8943
+ } else if (s.state === 'done') {
8944
+ if (s.backupPath && s.laterChanges) {
8945
+ const later = s.laterChanges;
8946
+ actions.appendChild(wfButton('Undo anyway', 'shell.workflow-update-undo-anyway', u.id, () => { void undoWfChange(u.id, { replaceLater: later }); }));
8947
+ } else if (s.backupPath) actions.appendChild(wfButton('Undo', 'shell.workflow-update-undo', u.id, () => { void undoWfChange(u.id); }));
8948
+ } else {
8949
+ // After Undo anyway the later work stays one click back, whatever happens to the row next.
8950
+ if (recovery) {
8951
+ const later = recovery.laterChanges;
8952
+ actions.appendChild(later
8953
+ ? wfButton('Undo anyway', 'shell.workflow-update-undo-anyway', u.id, () => { void undoWfChange(u.id, { recovery: true, replaceLater: later }); })
8954
+ : wfButton('Undo', 'shell.workflow-update-undo', u.id, () => { void undoWfChange(u.id, { recovery: true }); }));
8955
+ }
8956
+ if (s.state === 'undone' && !wfUpdateFor(u.id)) {
8957
+ // The row says the earlier version is back, and the offer returns on the next check.
8958
+ } else if (wfNeedsReview(u)) {
8959
+ actions.appendChild(wfButton('Review in AI Chat', 'shell.workflow-update-keep-mine', u.id, () => openKeepMyChanges(u), 'wf-upd-primary'));
8960
+ } else {
8961
+ // Waiting, failed, or put back with the update offered again: it can be updated (again) from here.
8962
+ if (changed) actions.appendChild(wfButton('Keep my changes (AI)', 'shell.workflow-update-keep-mine', u.id, () => openKeepMyChanges(u)));
8963
+ actions.appendChild(wfButton(s.state === 'failed' && !changed ? 'Try again' : changed ? 'Update anyway' : 'Update',
8964
+ 'shell.workflow-update-apply', u.id, () => { void runWfUpdate(u, { replaceChanges: changed }); }, 'wf-upd-primary'));
8965
+ }
8966
+ }
8967
+ row.appendChild(actions);
8968
+ return row;
8969
+ }
8970
+
8971
+ // The header dialog: what is new in the open workflow, and the same row, updated in place.
8972
+ function paintWfUpdateModal() {
8973
+ const u = _wfModalOffer;
8974
+ if (!u || !$wfUpdateModal) return;
8975
+ const name = wfDisplayName(u.id);
8976
+ const s = _wfRowState.get(u.id) || { state: 'idle' };
8977
+ document.getElementById('wf-update-title').textContent = `Update “${name}”`;
8978
+ document.getElementById('wf-update-sub').textContent = `${u.installed} → ${u.available}. Your saved data is kept, and a backup is saved first so you can undo.`;
8681
8979
  const changelog = Array.isArray(u.changelog) ? u.changelog : [];
8682
8980
  document.getElementById('wf-update-changelog').innerHTML = changelog.map((e) => {
8683
8981
  const changes = Array.isArray(e.changes) && e.changes.length
8684
8982
  ? '<ul>' + e.changes.map((c) => `<li>${escapeHtml(String(c))}</li>`).join('') + '</ul>' : '';
8685
- return `<div class="wf-ver"><div class="wf-ver-head">v${escapeHtml(String(e.version))}</div>`
8983
+ return `<div class="wf-ver"><div class="wf-ver-head">${escapeHtml(String(e.version))}</div>`
8686
8984
  + (e.summary ? `<div class="wf-ver-sum">${escapeHtml(String(e.summary))}</div>` : '') + changes + '</div>';
8687
- }).join('') || '<div class="wf-ver-sum">No changelog provided.</div>';
8985
+ }).join('') || '<div class="wf-ver-sum">No list of changes came with this version.</div>';
8986
+ const host = document.getElementById('wf-update-row');
8987
+ if (host) { const row = wfUpdateRow(u, { textOnly: true }); host.replaceChildren(...(row.textContent ? [row] : [])); }
8988
+ const changed = wfRowChanged(s, u);
8989
+ const ok = document.getElementById('wf-update-ok');
8990
+ const ai = document.getElementById('wf-update-ai');
8991
+ const cancel = document.getElementById('wf-update-cancel');
8992
+ const review = wfNeedsReview(u) && !['busy', 'undoing', 'done', 'undone'].includes(s.state);
8993
+ if (ai) ai.hidden = !changed;
8994
+ if (ok) {
8995
+ ok.disabled = s.state === 'busy' || s.state === 'undoing';
8996
+ if (ok.disabled) ok.setAttribute('data-blocked-reason', 'Already working on this workflow.'); else ok.removeAttribute('data-blocked-reason');
8997
+ ok.textContent = s.state === 'busy' ? 'Updating…' : s.state === 'undoing' ? 'Undoing…'
8998
+ : s.state === 'done' ? (s.laterChanges ? 'Undo anyway' : 'Undo')
8999
+ : s.state === 'undone' ? 'Done' : review ? 'Review in AI Chat'
9000
+ : s.state === 'failed' && !changed ? 'Try again' : changed ? 'Update anyway' : 'Update';
9001
+ ok.setAttribute('data-command-id', s.state === 'undone' ? 'shell.dialog-cancel#the workflow update'
9002
+ : (s.state === 'done' ? (s.laterChanges ? 'shell.workflow-update-undo-anyway' : 'shell.workflow-update-undo')
9003
+ : review ? 'shell.workflow-update-keep-mine' : 'shell.workflow-update-apply') + '#' + u.id);
9004
+ ok.setAttribute('data-command-instance-label', name);
9005
+ }
9006
+ if (cancel) {
9007
+ cancel.textContent = s.state === 'done' ? 'Close' : 'Not now';
9008
+ cancel.hidden = s.state === 'undone'; // Done is the only thing left to do
9009
+ }
9010
+ }
9011
+ function openWfUpdateModal(u) {
9012
+ if (!$wfUpdateModal) return;
9013
+ // Confirm exactly the offer displayed here, even if background polling replaces the live list.
9014
+ _wfModalOffer = Object.freeze({ ...u });
9015
+ const s = _wfRowState.get(u.id);
9016
+ // Offered again after an Undo: the dialog updates. Undo anyway's backup is not row state, so it stays one click back.
9017
+ if (s && s.state === 'undone') _wfRowState.delete(u.id);
9018
+ paintWfUpdateModal();
8688
9019
  showModal($wfUpdateModal);
8689
9020
  }
8690
9021
  function dismissWfUpdateModal() {
8691
- _wfReviewedUpdate = null;
9022
+ _wfModalOffer = null;
8692
9023
  hideModal($wfUpdateModal);
8693
9024
  }
8694
- async function applyWfUpdate(u) {
8695
- if (_wfUpdateApplying) return;
8696
- if (u.sourceUpdate?.mode === 'steel-review') {
8697
- if (typeof window.flolessChat?.openDraft !== 'function' || typeof window.flolessBridge?.openApp !== 'function') {
8698
- showToast('AI Chat is still starting. Keep this review open and try again in a moment.', 'warn'); return;
8699
- }
8700
- _wfUpdateApplying = true;
8701
- const button = document.getElementById('wf-update-ok');
8702
- if (button) { button.disabled = true; button.setAttribute('data-blocked-reason', 'Opening this workflow’s chat review.'); }
8703
- try {
8704
- // Installed workflows use Workspace chat. Opening the exact workflow first leaves a project
8705
- // conversation safely; openDraft then preserves/appends the destination draft or offers a provider.
8706
- await window.flolessBridge.openApp(u.id);
8707
- await window.flolessChat.openDraft(`Review the installed workflow ${u.id} (${u.installed}) against its bundled maintained template ${u.templateId} (${u.available}). Preserve all my customizations, baked content, models and approval history. Explain the changes before editing; do not compile or approve anything for me.`);
8708
- dismissWfUpdateModal();
8709
- showToast('The update review is ready in AI Chat. Send it when you are ready; nothing was changed.', 'ok');
8710
- } catch (error) { showToast('The review could not open in this workflow’s AI Chat. Your drafts were kept. Try again.', 'warn'); }
8711
- finally { _wfUpdateApplying = false; if (button) { button.disabled = false; button.removeAttribute('data-blocked-reason'); } }
8712
- return;
8713
- }
8714
- _wfUpdateApplying = true;
8715
- const $ok = document.getElementById('wf-update-ok');
8716
- const prev = $ok ? $ok.textContent : '';
8717
- if ($ok) { $ok.disabled = true; $ok.setAttribute('data-blocked-reason', 'Updating this workflow now.'); $ok.textContent = 'Updating…'; }
8718
- try {
8719
- const r = await fetch(`/api/workflows/${encodeURIComponent(u.id)}/update`, { method: 'POST', headers: { 'content-type': 'application/json' },
8720
- body: JSON.stringify({ expectedFromVersion: u.installed, expectedToVersion: u.available,
8721
- ...(u.sourceOnly ? { expectedSourceHash: u.sourceHash, expectedTemplateHash: u.templateHash } : {}),
8722
- ...(u.sourceUpdate ? { sourceUpdateMode: u.sourceUpdate.mode, expectedSourceHash: u.sourceUpdate.sourceHash, expectedTemplateHash: u.sourceUpdate.templateHash } : {}) }) });
8723
- const d = await r.json().catch(() => ({}));
8724
- if (!r.ok || !d.ok) throw Object.assign(new Error(d.error || 'update failed'), { code: d.code });
8725
- dismissWfUpdateModal();
8726
- showToast(d.compatibilityRepaired ? `3D Viewer compatibility repaired. Workflow v${d.toVersion} and your work were preserved; a backup was saved. Return to Review and approve your model.`
8727
- : d.needsCompile ? `Updated to v${d.toVersion}. A backup was saved. Review the workflow, then press Compile yourself before running it.`
8728
- : `Updated to v${d.toVersion} — your data is preserved, a backup was saved.`, 'ok');
8729
- await refreshWorkflowUpdates();
8730
- globalThis.dispatchEvent?.(new CustomEvent('floless:workflow-updates-changed'));
8731
- if (currentId === u.id) await loadApp(currentId); // reload to show the new structure
8732
- } catch (e) {
8733
- if (e.code === 'update-changed') {
8734
- dismissWfUpdateModal();
8735
- await refreshWorkflowUpdates();
8736
- }
8737
- showToast(e.code === 'update-changed'
8738
- ? 'The workflow or its update changed after you opened this review. Your work was kept. Open the update again to review the current version.'
8739
- : 'We couldn’t update this workflow because FloLess could not save the change. Try again.', 'warn');
8740
- } finally {
8741
- _wfUpdateApplying = false;
8742
- if ($ok) { $ok.disabled = false; $ok.removeAttribute('data-blocked-reason'); $ok.textContent = prev; }
8743
- }
9025
+ function onWfUpdateOk() {
9026
+ const u = _wfModalOffer;
9027
+ if (!u) return;
9028
+ const s = _wfRowState.get(u.id) || { state: 'idle' };
9029
+ if (s.state === 'busy' || s.state === 'undoing') return;
9030
+ if (s.state === 'done') { void undoWfChange(u.id, s.laterChanges ? { replaceLater: s.laterChanges } : {}); return; }
9031
+ if (s.state === 'undone') { dismissWfUpdateModal(); return; }
9032
+ if (wfNeedsReview(u)) { openKeepMyChanges(u); return; }
9033
+ const changed = wfRowChanged(s, u);
9034
+ void runWfUpdate(u, { replaceChanges: changed });
8744
9035
  }
8745
9036
  if ($wfUpdate) {
8746
9037
  $wfUpdate.onclick = () => { const u = currentId && wfUpdateFor(currentId); if (u) openWfUpdateModal(u); };
8747
9038
  const $cancel = document.getElementById('wf-update-cancel'); if ($cancel) $cancel.onclick = dismissWfUpdateModal;
8748
- const $ok = document.getElementById('wf-update-ok'); if ($ok) $ok.onclick = () => { if (_wfReviewedUpdate) return applyWfUpdate(_wfReviewedUpdate); };
9039
+ const $ok = document.getElementById('wf-update-ok'); if ($ok) $ok.onclick = onWfUpdateOk;
9040
+ const $ai = document.getElementById('wf-update-ai'); if ($ai) $ai.onclick = () => { if (_wfModalOffer) openKeepMyChanges(_wfModalOffer); };
8749
9041
  if ($wfUpdateModal) onBackdropDismiss($wfUpdateModal, dismissWfUpdateModal);
8750
9042
  }
8751
9043
 
@@ -19718,9 +20010,14 @@
19718
20010
  async reviewWorkflowUpdate(appId) {
19719
20011
  await refreshWorkflowUpdates();
19720
20012
  const offer = wfUpdateFor(appId);
19721
- if (!offer) throw new Error('No bundled workflow update is currently available. Ask AI Chat to review the workflow requirements.');
20013
+ if (!offer) throw new Error('This workflow has no update from FloLess right now.');
19722
20014
  openWfUpdateModal(offer);
19723
20015
  },
20016
+ // One-click update (2026-11-02): the status-bar dialog lists and acts on the same rows as the header dialog.
20017
+ workflowUpdateRows: () => wfUpdateRowsForDialog(),
20018
+ workflowUpdateRow: (offer) => wfUpdateRow(offer),
20019
+ updateAllWorkflows: () => updateAllWorkflows(),
20020
+ updateAllCount: () => wfUpdateAllTargets().length,
19724
20021
  /** #2046: the ≡ menu's New workflow, opened from a Guide suggestion with its name filled in. */
19725
20022
  newWorkflow: (prefill) => requestNewWorkflow(prefill),
19726
20023
  // #2185: a Guide card's Build it — straight to its own conversation, no dialog.
@@ -19862,9 +20159,9 @@
19862
20159
  }
19863
20160
  return window.flolessChat.startProjectIntake(submissionId, payload);
19864
20161
  },
19865
- async resumeProjectChatIntake(submissionId) {
20162
+ async resumeProjectChatIntake(submissionId, options) {
19866
20163
  if (typeof window.flolessChat?.resumeProjectIntake !== 'function') return null;
19867
- return window.flolessChat.resumeProjectIntake(submissionId);
20164
+ return window.flolessChat.resumeProjectIntake(submissionId, options);
19868
20165
  },
19869
20166
  async openChatConversation(chatId) {
19870
20167
  if (typeof window.flolessChat?.openConversation !== 'function') {
@@ -273,7 +273,9 @@
273
273
  box = el('div', 'ai-chat-ask-other');
274
274
  const line = el('div', 'ai-chat-ask-other-line');
275
275
  const input = control('input', key('other-input'), question.header || 'your answer', 'ai-chat-ask-other-input');
276
- input.type = 'text'; input.autocomplete = 'off'; input.maxLength = 1000; input.spellcheck = true;
276
+ input.type = 'text'; input.autocomplete = 'off'; input.spellcheck = true;
277
+ // A card that keeps unreadable text as a note checks its own length on Submit and keeps the draft; nothing is cut here.
278
+ if (!question.otherUncapped) input.maxLength = 1000;
277
279
  input.placeholder = question.otherPlaceholder || 'Type your answer';
278
280
  input.setAttribute('aria-label', question.otherInputLabel || `Your own answer to: ${question.question}`);
279
281
  input.value = row.other;