@floless/app 0.156.0 → 0.158.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 (59) hide show
  1. package/cli-actions.mjs +28 -5
  2. package/dist/floless-server.cjs +110947 -67461
  3. package/dist/schemas/drawing-check.profile.v1.schema.json +15 -2
  4. package/dist/schemas/steel.model.v2.schema.json +25 -1
  5. package/dist/skills/floless-app-actions/SKILL.md +82 -17
  6. package/dist/skills/floless-app-knowledge/SKILL.md +34 -2
  7. package/dist/skills/floless-app-knowledge/references/schema.md +4 -1
  8. package/dist/skills/floless-app-new-workflow/SKILL.md +23 -7
  9. package/dist/skills/floless-app-onboarding/SKILL.md +31 -1
  10. package/dist/skills/floless-app-report-issue/SKILL.md +3 -3
  11. package/dist/skills/floless-app-rfi/SKILL.md +40 -6
  12. package/dist/skills/floless-app-routines/SKILL.md +9 -2
  13. package/dist/skills/floless-app-steel-model/SKILL.md +35 -1
  14. package/dist/skills/floless-app-steel-model/references/detail-from-a-screenshot.md +4 -2
  15. package/dist/skills/floless-app-steel-takeoff/SKILL.md +51 -1
  16. package/dist/skills/floless-app-tweak-contract/SKILL.md +25 -5
  17. package/dist/skills/floless-app-workflows/SKILL.md +46 -10
  18. package/dist/skills/floless-app-workflows/references/agent-steps.md +119 -0
  19. package/dist/web/agent-steps.js +864 -47
  20. package/dist/web/agents.js +28 -8
  21. package/dist/web/app.css +620 -17
  22. package/dist/web/app.js +110 -11
  23. package/dist/web/aware-update-client.js +1 -0
  24. package/dist/web/aware.js +921 -220
  25. package/dist/web/chat-landing-scene.js +372 -0
  26. package/dist/web/chat.css +263 -1
  27. package/dist/web/chat.js +2660 -86
  28. package/dist/web/commands-drawing-check.js +17 -0
  29. package/dist/web/commands-shell.js +1059 -8
  30. package/dist/web/commands-steel.js +6 -0
  31. package/dist/web/connections.js +1 -0
  32. package/dist/web/drawing-check-editor.html +33 -5
  33. package/dist/web/drawing-check-editor.js +538 -22
  34. package/dist/web/drawing-check-overlay.js +13 -0
  35. package/dist/web/flo-avatar.js +28 -3
  36. package/dist/web/guide.js +7 -2
  37. package/dist/web/index.html +143 -8
  38. package/dist/web/instructor.js +4 -4
  39. package/dist/web/kb-categories.js +351 -0
  40. package/dist/web/kb-graph-worker.js +73 -0
  41. package/dist/web/model-view-query.js +12 -2
  42. package/dist/web/pages.js +978 -39
  43. package/dist/web/panels.js +5 -2
  44. package/dist/web/parser-setup-recovery.js +12 -4
  45. package/dist/web/project-access.js +549 -0
  46. package/dist/web/run-page-view.js +353 -0
  47. package/dist/web/startup-admission.js +132 -0
  48. package/dist/web/steel-3d-core.js +9 -0
  49. package/dist/web/steel-editor.html +681 -22
  50. package/dist/web/steel-model-v2-commands.js +63 -5
  51. package/dist/web/step-rename.js +287 -0
  52. package/dist/web/tab-signal.js +323 -0
  53. package/dist/web/terminal-requests.js +103 -13
  54. package/dist/web/tool-updates.js +1 -0
  55. package/dist/web/workspace-root-management.js +39 -0
  56. package/dist/web/workspaces.js +2883 -146
  57. package/launch-starting-page.mjs +181 -0
  58. package/launch.mjs +97 -12
  59. package/package.json +5 -1
@@ -0,0 +1,323 @@
1
+ // The browser tab says how a run is going (tab signal). People start a long run and switch to Tekla or
2
+ // Revit; the tab is all they can see of FloLess then. While a run works, the favicon carries a progress
3
+ // ring and the title leads with the percent (or the elapsed clock when the run reports no total). When
4
+ // it ends, the favicon and title say how: done, failed, stopped, didn't run. A run that ended while the
5
+ // person was away keeps saying so until they are back, and, if they allowed it, a desktop notice says it
6
+ // too. FloLess never asks for that permission on its own: the first time a run ends while they were
7
+ // away, a toast offers it, once; the ≡ menu's "Run finished notices" switch turns it on or off any time.
8
+ //
9
+ // It never decides anything: aware.js tells it when a run begins, how it progresses and how it ended,
10
+ // and it owns no title of its own — aware.js stays the one writer of document.title and asks prefix().
11
+ // A plain script (no import/export); its one global is `flolessTabSignal`.
12
+
13
+ (function () {
14
+ const TICK_MS = 1000; // the elapsed clock in the title: at most one title change a second
15
+ const SPIN_MS = 250; // the indeterminate ring while the tab is on screen (4 fps, CPU-light)
16
+ const CLEAR_SEEN_MS = 4000; // a success the person watched happen
17
+ const CLEAR_BACK_MS = 3000; // an ending they come back to: long enough to be noticed
18
+ const NOTIFY_MIN_MS = 10_000; // a run shorter than this is noise as a desktop notice
19
+ const ICON_PX = 64;
20
+ const OFFER_KEY = 'floless.tabSignal.notifyOffered';
21
+ const PREF_KEY = 'floless.tabSignal.notify'; // '0' when the person switched notices off in the ≡ menu
22
+ const END_TEXT = { ok: '✓ Done', failed: '✕ Failed', stopped: '■ Stopped', 'not-run': "○ Didn't run" };
23
+ const NOTICE_TITLE = { ok: 'Run finished', failed: 'Run failed', stopped: 'Run stopped', 'not-run': "Run didn't start" };
24
+ // A run that did not start has no duration worth stating, and FloLess keeps no reason for it (the run strip says
25
+ // the same: run it again to see why). A failure's details stay in the Execution tab.
26
+ const noticeBody = (outcome, ms) => ({
27
+ ok: `Took ${duration(ms)}.`,
28
+ failed: `Failed after ${duration(ms)}. Open FloLess to see why.`,
29
+ stopped: `Stopped after ${duration(ms)}.`,
30
+ 'not-run': "FloLess didn't start it. Run it again to see why.",
31
+ }[outcome]);
32
+
33
+ let run = null; // { name, startedAt, fraction, runId }
34
+ let ended = null; // { outcome, name, whileAway, clearTimer }
35
+ let onChange = () => {};
36
+ let shownPrefix = '';
37
+ let tickTimer = null;
38
+ let spinAngle = 0;
39
+ let baseIcon = null; // the favicon as an <img>, once loaded
40
+ let iconLinks = null; // [{ link, href }]: the originals, restored when the signal clears
41
+ let offerPending = false; // a run ended while away and permission is undecided: offer when they are back
42
+ let prefMemory = null; // the ≡ menu choice when the browser will not store it: it still holds for this page
43
+
44
+ const reducedMotion = () => !!(window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches);
45
+ const hidden = () => document.visibilityState === 'hidden';
46
+ // Visible but not focused (FloLess on a second monitor beside Tekla) counts as away too.
47
+ const away = () => hidden() || (typeof document.hasFocus === 'function' && !document.hasFocus());
48
+ const clock = (ms) => (typeof rpClock === 'function' ? rpClock(ms) : `${Math.floor(ms / 60000)}:${String(Math.floor(ms / 1000) % 60).padStart(2, '0')}`);
49
+
50
+ function duration(ms) {
51
+ const s = Math.max(0, Math.round(ms / 1000));
52
+ if (s < 60) return `${s}s`;
53
+ const m = Math.floor(s / 60);
54
+ if (m < 60) return `${m}m ${s % 60}s`;
55
+ return `${Math.floor(m / 60)}h ${m % 60}m`;
56
+ }
57
+
58
+ /** What the title leads with, or '' when nothing is going on. */
59
+ function prefix() {
60
+ if (run) return `${run.fraction != null ? `${Math.floor(run.fraction * 100)}%` : clock(Date.now() - run.startedAt)} · `;
61
+ if (ended) return `${END_TEXT[ended.outcome]} · `;
62
+ return '';
63
+ }
64
+
65
+ // ── favicon ──────────────────────────────────────────────────────────────────────────────────────
66
+ function themeColor(name, fallback) {
67
+ const v = getComputedStyle(document.documentElement).getPropertyValue(name).trim();
68
+ return v || fallback;
69
+ }
70
+
71
+ function links() {
72
+ if (!iconLinks) iconLinks = [...document.querySelectorAll('link[rel~="icon"]')].map((link) => ({ link, href: link.getAttribute('href') }));
73
+ return iconLinks;
74
+ }
75
+
76
+ function loadBaseIcon() {
77
+ if (baseIcon || typeof Image !== 'function') return;
78
+ const svg = links().find(({ href }) => /\.svg(\?|$)/.test(href || '')) || links()[0];
79
+ if (!svg) return;
80
+ const img = new Image();
81
+ img.onload = () => { baseIcon = img; paint(); };
82
+ img.src = svg.href;
83
+ }
84
+
85
+ function restoreIcon() {
86
+ if (!iconLinks) return;
87
+ for (const { link, href } of iconLinks) link.setAttribute('href', href);
88
+ }
89
+
90
+ function paint() {
91
+ if (!run && !ended) { restoreIcon(); return; }
92
+ const canvas = document.createElement('canvas');
93
+ const g = canvas.getContext && canvas.getContext('2d');
94
+ if (!g || !baseIcon) return; // no canvas (or the logo not loaded yet): the title still carries it
95
+ canvas.width = canvas.height = ICON_PX;
96
+ g.drawImage(baseIcon, 0, 0, ICON_PX, ICON_PX);
97
+ const cx = ICON_PX * 0.72, cy = ICON_PX * 0.72, r = ICON_PX * 0.25;
98
+ // A dark disc under the badge so it reads on a light or a dark tab strip alike.
99
+ g.beginPath(); g.arc(cx, cy, r + 5, 0, Math.PI * 2); g.fillStyle = '#0f172a'; g.fill();
100
+ g.lineCap = 'round'; g.lineJoin = 'round';
101
+ if (run) {
102
+ g.lineWidth = 7;
103
+ g.beginPath(); g.arc(cx, cy, r - 2, 0, Math.PI * 2); g.strokeStyle = 'rgba(148,163,184,0.35)'; g.stroke();
104
+ const still = run.fraction == null && reducedMotion();
105
+ const start = run.fraction != null || still ? -Math.PI / 2 : spinAngle;
106
+ const sweep = run.fraction != null ? Math.max(0.04, run.fraction) * Math.PI * 2 : Math.PI / 2;
107
+ g.beginPath(); g.arc(cx, cy, r - 2, start, start + sweep); g.strokeStyle = themeColor('--accent', '#4a9eff'); g.stroke();
108
+ } else {
109
+ // Each ending has its own shape, so it reads without its color: done a disc with a tick, failed a
110
+ // triangle with a bar, stopped a square, didn't run a hollow ring.
111
+ const o = ended.outcome;
112
+ const color = o === 'ok' ? themeColor('--ok', '#4ade80') : o === 'failed' ? themeColor('--err', '#f87171') : '#94a3b8';
113
+ g.fillStyle = color; g.strokeStyle = color; g.lineWidth = 6;
114
+ g.beginPath();
115
+ if (o === 'ok') {
116
+ g.arc(cx, cy, r, 0, Math.PI * 2); g.fill();
117
+ const u = r * 0.45;
118
+ g.beginPath(); g.moveTo(cx - u, cy); g.lineTo(cx - u * 0.2, cy + u * 0.8); g.lineTo(cx + u, cy - u * 0.7);
119
+ g.strokeStyle = '#0f172a'; g.stroke();
120
+ } else if (o === 'failed') {
121
+ g.moveTo(cx, cy - r * 1.05); g.lineTo(cx + r * 1.05, cy + r * 0.8); g.lineTo(cx - r * 1.05, cy + r * 0.8); g.closePath(); g.fill();
122
+ g.beginPath(); g.moveTo(cx, cy - r * 0.3); g.lineTo(cx, cy + r * 0.25);
123
+ g.strokeStyle = '#0f172a'; g.stroke();
124
+ } else if (o === 'stopped') {
125
+ g.rect(cx - r * 0.8, cy - r * 0.8, r * 1.6, r * 1.6); g.fill();
126
+ } else {
127
+ g.arc(cx, cy, r - 3, 0, Math.PI * 2); g.stroke();
128
+ }
129
+ }
130
+ const url = canvas.toDataURL('image/png');
131
+ for (const { link } of links()) link.setAttribute('href', url);
132
+ }
133
+
134
+ // ── lifecycle ────────────────────────────────────────────────────────────────────────────────────
135
+ function changed() {
136
+ paint();
137
+ const next = prefix();
138
+ if (next === shownPrefix) return; // the spinner repaints the icon; the title moves only when its words do
139
+ shownPrefix = next;
140
+ try { onChange(); } catch { /* the title is a courtesy; a failing writer must not break a run */ }
141
+ }
142
+
143
+ function stopTicking() { if (tickTimer) { clearInterval(tickTimer); tickTimer = null; } }
144
+
145
+ function startTicking() {
146
+ stopTicking();
147
+ if (!run) return;
148
+ const spin = !hidden() && !reducedMotion() && run.fraction == null;
149
+ tickTimer = setInterval(() => {
150
+ if (!run) { stopTicking(); return; }
151
+ spinAngle = (spinAngle + Math.PI / 3) % (Math.PI * 2);
152
+ changed();
153
+ }, spin ? SPIN_MS : TICK_MS);
154
+ }
155
+
156
+ function clearEnd() {
157
+ if (!ended) return;
158
+ if (ended.clearTimer) clearTimeout(ended.clearTimer);
159
+ ended = null;
160
+ changed();
161
+ }
162
+
163
+ function begin(name, startedAt) {
164
+ if (ended && ended.clearTimer) clearTimeout(ended.clearTimer);
165
+ ended = null;
166
+ run = { name: name || 'Workflow', startedAt: typeof startedAt === 'number' ? startedAt : Date.now(), fraction: null, runId: null };
167
+ loadBaseIcon();
168
+ startTicking();
169
+ changed();
170
+ }
171
+
172
+ /** A `node-progress` record: a fraction exists only when the producer reported a total. */
173
+ function progress(rec) {
174
+ if (!run || !rec) return;
175
+ if (rec.runId) run.runId = rec.runId;
176
+ const f = typeof rec.total === 'number' && rec.total > 0 && typeof rec.done === 'number'
177
+ ? Math.max(0, Math.min(1, rec.done / rec.total)) : null;
178
+ const modeChanged = (run.fraction == null) !== (f == null);
179
+ run.fraction = f;
180
+ if (modeChanged) startTicking();
181
+ changed();
182
+ }
183
+
184
+ /** The run went away without an ending this tab can state (replaced, or no longer followed). */
185
+ function cancel() {
186
+ if (!run) return;
187
+ run = null;
188
+ stopTicking();
189
+ changed();
190
+ }
191
+
192
+ /** outcome: 'ok' | 'failed' | 'stopped' | 'not-run'. Any other (FloLess no longer knows how it ended) claims nothing. */
193
+ function finish(outcome, endedRunId) {
194
+ if (!run) return;
195
+ if (endedRunId) run.runId = endedRunId;
196
+ if (!Object.prototype.hasOwnProperty.call(END_TEXT, outcome)) { cancel(); return; }
197
+ const { name, startedAt, runId } = run;
198
+ run = null;
199
+ stopTicking();
200
+ const whileAway = away();
201
+ ended = { outcome, name, whileAway, clearTimer: null };
202
+ // A success they watched fades on its own; anything else stays until they are back and act.
203
+ if (!whileAway && ended.outcome === 'ok') ended.clearTimer = setTimeout(clearEnd, CLEAR_SEEN_MS);
204
+ changed();
205
+ const ms = Date.now() - startedAt;
206
+ if (whileAway && ms >= NOTIFY_MIN_MS) notify(ended.outcome, name, ms, runId);
207
+ }
208
+
209
+ // ── desktop notice ───────────────────────────────────────────────────────────────────────────────
210
+ function notify(outcome, name, ms, runId) {
211
+ const N = typeof Notification === 'function' ? Notification : null;
212
+ if (!N || switchedOff()) return;
213
+ if (N.permission === 'granted') {
214
+ try {
215
+ // One notice per run: two tabs following it, or a reconnect, share the tag and replace each other.
216
+ const n = new N(`${NOTICE_TITLE[outcome]} — ${name}`, { body: noticeBody(outcome, ms), tag: `floless-run:${runId || name}`, icon: '/favicon.svg?v=2', silent: true });
217
+ n.onclick = () => { try { window.focus(); } catch { /* best effort */ } n.close(); };
218
+ } catch { /* a browser that will not show one from a page: the tab still says it */ }
219
+ return;
220
+ }
221
+ if (N.permission === 'default' && !offeredBefore()) offerPending = true; // 'denied' is their answer: never ask
222
+ }
223
+
224
+ function offeredBefore() {
225
+ try { return localStorage.getItem(OFFER_KEY) === '1'; } catch { return true; } // no storage: never nag
226
+ }
227
+ function switchedOff() {
228
+ if (prefMemory != null) return prefMemory === '0'; // set only while the browser will not store the choice
229
+ try { return localStorage.getItem(PREF_KEY) === '0'; } catch { return false; }
230
+ }
231
+ function remember(key, value) {
232
+ try { localStorage.setItem(key, value); if (key === PREF_KEY) prefMemory = null; }
233
+ catch { if (key === PREF_KEY) prefMemory = value; /* held in memory for this page instead */ }
234
+ }
235
+
236
+ /** Ask the browser; once it answers, the ≡ menu switch says where things stand. */
237
+ function askPermission() {
238
+ remember(OFFER_KEY, '1');
239
+ remember(PREF_KEY, '1');
240
+ const ask = Notification.requestPermission();
241
+ const settle = (p) => {
242
+ syncMenu();
243
+ if (p === 'granted') showToast('Run finished notices are on. Switch them off in the ≡ menu.', 'ok');
244
+ };
245
+ if (ask && typeof ask.then === 'function') ask.then(settle, () => syncMenu());
246
+ }
247
+
248
+ function offer() {
249
+ offerPending = false;
250
+ // Read again now: while they were away, another FloLess tab may have answered (switched notices off, offered
251
+ // already) or the browser may have been told.
252
+ if (switchedOff() || offeredBefore() || typeof Notification !== 'function' || Notification.permission !== 'default') return;
253
+ try { localStorage.setItem(OFFER_KEY, '1'); } catch { return; }
254
+ if (typeof showToast !== 'function') return;
255
+ showToast('That run ended while you were away. Get a desktop notice next time?', 'info', {
256
+ action: {
257
+ label: 'Turn on',
258
+ commandId: 'shell.run-notify-enable',
259
+ onClick: askPermission,
260
+ },
261
+ });
262
+ }
263
+
264
+ // ── the ≡ menu switch ───────────────────────────────────────────────────────────────────────────
265
+ // On means: the browser allows notices and the person has not switched them off here. A browser that
266
+ // blocks them keeps the switch off and the hint says where to change that; FloLess cannot.
267
+ const HINT_ON = 'A desktop notice when a run ends while you are in another window.';
268
+ const HINT_BLOCKED = 'Your browser blocks notices from FloLess. Allow them in the site settings (the icon left of the address), then switch this on.';
269
+ function syncMenu() {
270
+ const row = document.getElementById('menu-run-notify');
271
+ const toggle = document.getElementById('menu-run-notify-toggle');
272
+ const hint = document.getElementById('menu-run-notify-hint');
273
+ if (!row || !toggle) return;
274
+ if (typeof Notification !== 'function') { row.hidden = true; return; }
275
+ row.hidden = false;
276
+ toggle.checked = Notification.permission === 'granted' && !switchedOff();
277
+ if (hint) hint.textContent = Notification.permission === 'denied' ? HINT_BLOCKED : HINT_ON;
278
+ }
279
+ function bindMenu() {
280
+ const toggle = document.getElementById('menu-run-notify-toggle');
281
+ if (!toggle) return;
282
+ toggle.addEventListener('change', () => {
283
+ if (!toggle.checked) { remember(PREF_KEY, '0'); remember(OFFER_KEY, '1'); syncMenu(); return; }
284
+ if (Notification.permission === 'granted') { remember(PREF_KEY, '1'); syncMenu(); return; }
285
+ if (Notification.permission === 'denied') { syncMenu(); return; } // the hint says why it stays off
286
+ toggle.checked = false; // on only once the browser says yes
287
+ askPermission();
288
+ });
289
+ syncMenu();
290
+ }
291
+ bindMenu();
292
+
293
+ // Back on the tab: an ending they missed is held a moment so it is seen, then cleared. One they watched
294
+ // happen (a failure, a stop) clears at their next click or key, since they have seen it by then.
295
+ function back() {
296
+ if (run) startTicking();
297
+ if (away()) return;
298
+ syncMenu(); // they may have changed the browser's permission in the meantime
299
+ if (ended && ended.whileAway && !ended.clearTimer) ended.clearTimer = setTimeout(clearEnd, CLEAR_BACK_MS);
300
+ if (offerPending) offer();
301
+ }
302
+ function acted() { if (ended && !ended.whileAway && !ended.clearTimer && !away()) clearEnd(); }
303
+ // Gone again before it cleared: the ending is held until they are back for good.
304
+ function left() {
305
+ if (!ended || !away() || !ended.clearTimer) return;
306
+ clearTimeout(ended.clearTimer);
307
+ ended.clearTimer = null;
308
+ ended.whileAway = true;
309
+ }
310
+ document.addEventListener('visibilitychange', () => { if (away()) { if (run) startTicking(); left(); } else back(); });
311
+ window.addEventListener('focus', back);
312
+ window.addEventListener('blur', () => { if (run) startTicking(); left(); });
313
+ // Another FloLess tab switched notices on or off: this one's switch says the same.
314
+ window.addEventListener('storage', (e) => { if (!e || e.key === PREF_KEY) syncMenu(); });
315
+ document.addEventListener('pointerdown', acted, true);
316
+ document.addEventListener('keydown', acted, true);
317
+
318
+ window.flolessTabSignal = {
319
+ begin, progress, finish, cancel, prefix,
320
+ /** aware.js hands its title writer here, so a tick re-renders the one title it owns. */
321
+ onChange(fn) { onChange = typeof fn === 'function' ? fn : () => {}; },
322
+ };
323
+ })();
@@ -19,8 +19,22 @@
19
19
  'use strict';
20
20
 
21
21
  const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
22
- const CONFIRM_VERBS = { 'workflows.run': 'Run it', 'routines.run': 'Run it', 'projects.archive': 'Archive it', 'projects.unarchive': 'Bring it back' };
22
+ const CONFIRM_VERBS = { 'workflows.run': 'Run it', 'routines.run': 'Run it', 'projects.archive': 'Archive it', 'projects.unarchive': 'Bring it back',
23
+ // #2363: what each step does on the window's side, so none of them says a bare "Do it".
24
+ 'models.start-import': 'Choose the file', 'tekla.start-upload': 'Choose the source', 'models.retry-import': 'Try it again',
25
+ 'models.cancel-import': 'Cancel it', 'tekla.cancel-import': 'Cancel it', 'parser-setup.start-fresh': 'Open the review',
26
+ 'models.retry-revit-setup': 'Try setup again', 'models.retry-tekla-setup': 'Try setup again',
27
+ 'workspace-root.review-retirement': 'Open the review', 'workspace-root.confirm-retirement': 'Record it' };
23
28
  const EYEBROWS = { write: 'Needs your OK', destructive: 'Needs your OK', 'human-only': 'Your decision' };
29
+ // #2427: the step went as far as FloLess may and left the last click to the person: theirs to finish, not a failure.
30
+ const handedOver = (p) => p?.state === 'done' && p.result?.code === 'step-handed-over';
31
+ /** Several requests that ended: the ones waiting on the person are said apart from the ones that finished. */
32
+ function endedWords(ended) {
33
+ const handed = ended.filter(handedOver).length;
34
+ if (!handed) return `${ended.length} requests from your terminal have finished.`;
35
+ if (handed === ended.length) return `${handed} requests from your terminal are waiting for you.`;
36
+ return `From your terminal: ${handed} waiting for you · ${ended.length - handed} finished.`;
37
+ }
24
38
  const FINAL = new Set(['done', 'failed', 'cancelled', 'declined', 'expired', 'superseded', 'unknown']);
25
39
 
26
40
  /** Requests shown in the dialog, by id, in the order they arrived. */
@@ -36,6 +50,7 @@
36
50
  let linkedId = null;
37
51
 
38
52
  const api = async (method, path) => {
53
+ await globalThis.flolessStartupAdmission?.admit(path, { method });
39
54
  const res = await fetch(path, { method, credentials: 'same-origin', headers: method === 'POST' ? { 'content-type': 'application/json' } : {}, body: method === 'POST' ? '{}' : undefined });
40
55
  let body = null;
41
56
  try { body = await res.json(); } catch { body = null; }
@@ -143,7 +158,8 @@
143
158
  }
144
159
 
145
160
  const dialogOpen = () => Boolean(backdrop?.classList.contains('show'));
146
- const answerable = (p) => p.state === 'proposed' && !p.restarted && Date.parse(p.expiresAt) > Date.now();
161
+ // #2420: one asked before FloLess restarted is answerable too, until its own time runs out (answering shows it again).
162
+ const answerable = (p) => p.state === 'proposed' && Date.parse(p.expiresAt) > Date.now();
147
163
  // A step only a person does is never "done" in FloLess's records: once its screen was opened here, it has done its
148
164
  // job in this window and stops asking (it still expires on the server, and the terminal was told so).
149
165
  const waiting = () => [...shown.values()].filter((e) => !e.gone && !e.opened && answerable(e.p)).map((e) => e.p);
@@ -199,7 +215,11 @@
199
215
  status.setAttribute('role', 'status');
200
216
 
201
217
  const stale = entry.gone ? ['FloLess can’t find that request', 'It may be from before FloLess last restarted. Nothing ran. Ask your terminal to try again.']
202
- : p.state === 'expired' || (p.state === 'proposed' && (p.restarted || Date.parse(p.expiresAt) <= Date.now()))
218
+ : p.state === 'expired' && p.restarted && p.supersededBy
219
+ ? ['Shown again', 'FloLess restarted after your terminal asked, so the request is shown again as it works now. Nothing ran.']
220
+ : p.state === 'expired' && p.result?.code === 'asked-again'
221
+ ? ['Your terminal asked for this again', 'FloLess restarted after it first asked, so the newer request is shown instead. Nothing ran.']
222
+ : p.state === 'expired' || (p.state === 'proposed' && Date.parse(p.expiresAt) <= Date.now())
203
223
  ? ['This request expired', 'It waited too long, so FloLess dropped it. Nothing ran. Ask your terminal again if you still want it.']
204
224
  : p.state === 'superseded' ? ['Your terminal’s request was replaced', `${p.changedNote || 'Something changed after it was asked.'} This one can’t be run. Nothing ran.`]
205
225
  : p.state === 'declined' ? [`Not run: ${summary}`, 'You chose Not now. Nothing happened. Ask your terminal again if you change your mind.']
@@ -233,7 +253,7 @@
233
253
  strong.textContent = String(p.title || 'A FloLess action');
234
254
  named.append(eyebrow, strong);
235
255
  head.append(named);
236
- const badge = { executing: 'Running', done: 'Done', failed: 'Not done', unknown: 'Unknown' }[p.state];
256
+ const badge = handedOver(p) ? 'Your turn' : { executing: 'Running', done: 'Done', failed: 'Not done', unknown: 'Unknown' }[p.state];
237
257
  if (badge) {
238
258
  const b = document.createElement('span');
239
259
  b.className = 'ai-chat-filter-state';
@@ -241,6 +261,14 @@
241
261
  head.append(b);
242
262
  }
243
263
  node.append(head);
264
+ // A step only a person does has no confirm to show again: its screen opens as it is now either way.
265
+ const askedBeforeRestart = p.state === 'proposed' && p.restarted && risk !== 'human-only';
266
+ if (askedBeforeRestart) {
267
+ const before = document.createElement('p');
268
+ before.className = 'ai-chat-filter-note ai-chat-action-changed terminal-request-restarted';
269
+ before.textContent = 'Your terminal asked for this before FloLess restarted. FloLess may have changed since, so it will show the request again as it works now. Nothing runs until you confirm that one.';
270
+ node.append(before);
271
+ }
244
272
  if (p.changedNote && p.state === 'proposed') {
245
273
  const changed = document.createElement('p');
246
274
  changed.className = 'ai-chat-filter-note ai-chat-action-changed';
@@ -251,10 +279,31 @@
251
279
  sum.className = 'ai-chat-action-summary';
252
280
  sum.textContent = summary;
253
281
  node.append(sum);
282
+ // #2521 row 3a: what confirming agrees to (a Quick model read), whole and on its own line, as on a chat card: a
283
+ // terminal's request is consented to here, so its terms are shown here.
284
+ if (p.terms) {
285
+ const terms = document.createElement('p');
286
+ terms.className = 'ai-chat-action-summary ai-chat-action-terms';
287
+ const label = document.createElement('strong');
288
+ label.className = 'ai-chat-action-terms-label';
289
+ label.textContent = 'What you agree to';
290
+ terms.append(label, document.createTextNode(String(p.terms)));
291
+ node.append(terms);
292
+ }
254
293
 
294
+ if (handedOver(p)) {
295
+ node.classList.add('is-handed-over');
296
+ status.textContent = entry.error || String(p.result?.message || 'It is ready for you. Press it to finish.');
297
+ node.append(status);
298
+ return node;
299
+ }
255
300
  if (p.state === 'done') {
256
301
  node.classList.add('is-done');
257
- status.textContent = p.next ? 'Done. Its result is ready to view.' : String(p.doneNote || 'Done.');
302
+ // A step this window was handed but could not take is said here, never left reading as done.
303
+ // #2521 row 3a: the route's own answer, when it changed what happened (a Quick read queued Precise), comes first.
304
+ const resultNote = typeof p.result?.note === 'string' && p.result.note ? p.result.note : '';
305
+ if (resultNote) node.classList.add('is-fallback');
306
+ status.textContent = entry.error || resultNote || (p.next ? 'Done. Its result is ready to view.' : String(p.doneNote || 'Done.'));
258
307
  if (p.next) {
259
308
  const actions = document.createElement('div');
260
309
  actions.className = 'ai-chat-filter-actions';
@@ -318,8 +367,11 @@
318
367
  node.append(actions, note, status);
319
368
  return node;
320
369
  }
321
- const confirm = button(entry.busy === 'confirm' ? 'Starting…' : (CONFIRM_VERBS[p.actionId] || 'Do it'), 'shell.terminal-request-confirm', p.id, summary, 'ai-chat-filter-apply');
322
- confirm.dataset.tip = risk === 'destructive' ? 'Runs it now, for real. FloLess checks first that nothing changed since your terminal asked.'
370
+ const verbLabel = askedBeforeRestart ? 'Check it again' : (CONFIRM_VERBS[p.actionId] || 'Do it');
371
+ const confirm = button(entry.busy === 'confirm' ? (askedBeforeRestart ? 'Checking…' : 'Starting…') : verbLabel,
372
+ askedBeforeRestart ? 'shell.terminal-request-check-again' : 'shell.terminal-request-confirm', p.id, summary, 'ai-chat-filter-apply');
373
+ confirm.dataset.tip = askedBeforeRestart ? 'Shows this request again as it works now. Nothing runs yet.'
374
+ : risk === 'destructive' ? 'Runs it now, for real. FloLess checks first that nothing changed since your terminal asked.'
323
375
  : 'Makes this change now. FloLess checks first that nothing changed since your terminal asked.';
324
376
  confirm.disabled = Boolean(entry.busy);
325
377
  if (entry.busy === 'confirm') confirm.setAttribute('aria-busy', 'true');
@@ -327,7 +379,7 @@
327
379
  actions.append(later, confirm);
328
380
  const pending = document.createElement('p');
329
381
  pending.className = 'ai-chat-filter-note';
330
- pending.textContent = entry.busy === 'confirm' ? 'Starting it now…' : p.expected ? 'Nothing has run yet. It uses this as it is now. If it changes before you confirm, you will be asked again.'
382
+ pending.textContent = entry.busy === 'confirm' ? (askedBeforeRestart ? 'Checking it now…' : 'Starting it now…') : askedBeforeRestart ? 'Nothing has run yet.' : p.expected ? 'Nothing has run yet. It uses this as it is now. If it changes before you confirm, you will be asked again.'
331
383
  : 'Nothing has run yet.';
332
384
  status.textContent = entry.error || '';
333
385
  node.append(actions, pending, status);
@@ -349,13 +401,15 @@
349
401
  await window.flolessWorkspaces.openChatOwner({ kind: 'project', projectId: screen.projectId }); opened = true;
350
402
  } else if (['workspaces', 'workflows'].includes(screen?.view) && typeof window.flolessWorkspaces?.setMode === 'function') {
351
403
  await window.flolessWorkspaces.setMode(screen.view); opened = true;
404
+ } else if (screen?.view === 'tool-update-policy' && typeof window.openToolUpdatePolicy === 'function') {
405
+ window.openToolUpdatePolicy(); opened = true;
352
406
  }
353
407
  } catch (error) {
354
408
  // The bridge throws sentences written for the person (e.g. "This window no longer holds that run's report…").
355
409
  opened = false;
356
410
  why = typeof error?.message === 'string' ? error.message : '';
357
411
  }
358
- if (!opened) { status.textContent = why || 'FloLess couldn’t open that from here. Open it from Workflows or Workspaces instead.'; return false; }
412
+ if (!opened) { status.textContent = why || 'FloLess couldn’t open that from here. Open it from Workflows or Workspaces instead.'; announce(status.textContent); return false; }
359
413
  if (close) closeDialog();
360
414
  return true;
361
415
  }
@@ -366,17 +420,43 @@
366
420
  entry.error = '';
367
421
  paint();
368
422
  const title = String(entry.p.title || 'the request');
423
+ // A fresh card offered in its place is where the person answers next, so focus goes to its button.
424
+ let freshId = '';
369
425
  try {
370
426
  const { ok, body, status } = await api('POST', `/api/actions/proposals/${encodeURIComponent(entry.p.id)}/${verb}`);
371
427
  if (ok && body.proposal) {
372
428
  entry.p = body.proposal;
373
429
  announce(verb === 'confirm' ? `${title}: started.` : verb === 'decline' ? 'Nothing ran.' : `Asked ${title} to stop.`);
430
+ // A step only this window may take (a model source, the setup review, Stop FloLess) is taken here once confirmed,
431
+ // exactly as a chat card does: the request stays running until this window says how the step went.
432
+ if (verb === 'confirm' && entry.p.browserStep) {
433
+ const outcome = typeof window.flolessRunBrowserStep === 'function'
434
+ ? await window.flolessRunBrowserStep(entry.p.browserStep)
435
+ : 'FloLess could not take this step from here. Open the project or screen it names and do it there.';
436
+ // #2427: a step that left the last click to the person is not an error; the request says it waits for them.
437
+ entry.error = typeof outcome === 'string' ? outcome : '';
438
+ // A Stop FloLess that went ahead is settled by the server when it accepts the stop; this window can no longer report.
439
+ const stopped = entry.p.browserStep.flow === 'stop-app' && !entry.error;
440
+ const settled = !stopped && typeof window.flolessReportBrowserStep === 'function' ? await window.flolessReportBrowserStep(entry.p.id, outcome) : null;
441
+ if (settled) entry.p = settled;
442
+ // The step opened something in this window (a project, a review). This dialog sits over it, so step aside.
443
+ // A step that left the last click to the person focused that control: closing must not pull focus back to
444
+ // whatever opened this dialog, or the person loses the very control the card told them to press (#2427).
445
+ if (!entry.error) {
446
+ if (outcome && typeof outcome === 'object') returnFocus = null;
447
+ closeDialog();
448
+ // The dialog sat over that control while it was open, so it gets focus now, once nothing covers it.
449
+ if (outcome?.focus?.isConnected) outcome.focus.focus();
450
+ }
451
+ }
374
452
  } else if (body.fresh) {
375
- // It changed or expired: the old card says so, and the fresh one is shown right below it to answer instead.
453
+ // It changed or expired: the old card says so, and the fresh one is listed first to answer instead.
454
+ const restarted = Boolean(entry.p.restarted);
376
455
  if (body.proposal) entry.p = body.proposal;
377
456
  shown.set(body.fresh.id, { p: body.fresh, busy: '', error: '' });
378
457
  focusId = body.fresh.id;
379
- announce(body.error || 'It changed after your terminal asked. The current request is shown below.');
458
+ freshId = body.fresh.id;
459
+ announce(restarted ? 'Request shown again as it works now. Nothing has run.' : body.error || 'It changed after your terminal asked. The current request is shown first.');
380
460
  } else {
381
461
  if (body.proposal) entry.p = body.proposal;
382
462
  entry.error = status === 404 ? 'FloLess no longer has that request. Ask your terminal to try again.'
@@ -387,6 +467,13 @@
387
467
  } finally {
388
468
  entry.busy = '';
389
469
  paint();
470
+ if (freshId && dialogOpen()) {
471
+ const fresh = list.querySelector(`[data-proposal-id="${CSS.escape(freshId)}"]`);
472
+ (fresh?.querySelector('.ai-chat-filter-apply') || fresh?.querySelector('.terminal-request-title'))?.focus({ preventScroll: true });
473
+ }
474
+ // #2318: the card's status line is created afresh on every repaint, and a live region that is inserted (not
475
+ // changed) is often not read out. The dialog's own live region is what says it.
476
+ if (entry.error) announce(entry.error);
390
477
  // Esc while it was starting: the dialog is gone, so the notice carries "running" instead.
391
478
  if (!dialogOpen()) showNotice();
392
479
  // A last "Not now" leaves nothing to decide: close and say so.
@@ -418,6 +505,7 @@
418
505
  if (dialogOpen()) {
419
506
  paint();
420
507
  if (!known) announce('1 more request from your terminal.');
508
+ else if (handedOver(got.p)) announce(`${got.p.title}: waiting for you.`);
421
509
  else if (got.p.state === 'done') announce(`${got.p.title}: done.`);
422
510
  // A notice the person set aside with × stays set aside; one that is showing is redrawn (or removed once nothing waits).
423
511
  } else if (!known || notice || known.p.state !== before) showNotice();
@@ -484,7 +572,9 @@
484
572
  const parts = [];
485
573
  if (going.length) parts.push(`${going.length} running`);
486
574
  if (open.length) parts.push(`${open.length} ${open.length === 1 ? 'needs' : 'need'} you`);
487
- if (ended.length) parts.push(`${ended.length} finished`);
575
+ const handed = ended.filter(handedOver).length;
576
+ if (handed) parts.push(`${handed} waiting for you`);
577
+ if (ended.length - handed) parts.push(`${ended.length - handed} finished`);
488
578
  text.textContent = `From your terminal: ${parts.join(' · ')}.`;
489
579
  } else if (open.length) {
490
580
  const head = one ? `Your terminal ${verbFor(one)} ${whatFor(one)}.` : `${open.length} requests from your terminal.`;
@@ -494,7 +584,7 @@
494
584
  text.textContent = going.length === 1 ? `Running what your terminal asked: ${String(going[0].summary || going[0].title || 'a request')}.` : `${going.length} requests from your terminal are running.`;
495
585
  target = going.length === 1 ? going[0] : null;
496
586
  } else {
497
- text.textContent = ended.length === 1 ? `${ended[0].state === 'done' ? 'Done' : 'Not done'}: ${String(ended[0].summary || ended[0].title || 'a request')}.` : `${ended.length} requests from your terminal have finished.`;
587
+ text.textContent = ended.length === 1 ? `${handedOver(ended[0]) ? 'Waiting for you' : ended[0].state === 'done' ? 'Done' : 'Not done'}: ${String(ended[0].summary || ended[0].title || 'a request')}.` : endedWords(ended);
498
588
  target = ended.length === 1 ? ended[0] : null;
499
589
  }
500
590
  const review = button('Review', 'shell.terminal-request-review', '', '', 'toast-action');
@@ -273,6 +273,7 @@
273
273
  function plural(n, one, many) { return n + ' ' + (n === 1 ? one : many); }
274
274
 
275
275
  async function call(path, method, payload, signal) {
276
+ await globalThis.flolessStartupAdmission?.admit(path, { method, signal });
276
277
  var res = await fetch(path, { method: method || 'GET', headers: { 'content-type': 'application/json' }, body: payload, signal: signal });
277
278
  var body = await res.json().catch(function (error) {
278
279
  if (error && error.name === 'AbortError') throw error; // the page gave this request up: not "an unreadable answer"
@@ -193,5 +193,44 @@
193
193
  })
194
194
  .observe(modal, { attributes: true, attributeFilter: ['class'] });
195
195
  window.addEventListener('floless:workspace-root-state', () => { if (shown && !busy) void refresh(); });
196
+ // #2363: a confirmed chat card opens this review for one saved directory and presses the same buttons the person would,
197
+ // so the preview and the recording run here, with this window's editor session. `record` also presses the confirm
198
+ // button, but only once the review needs nothing more from the person (a directory in use needs a destination first).
199
+ // Resolves '' on success, or one plain sentence: why it could not, or what the person does next.
200
+ async function until(test, ms) { const end = Date.now() + ms; while (Date.now() < end) { if (test()) return true; await new Promise((r) => setTimeout(r, 50)); } return test(); }
201
+ async function reviewRetirementForCard({ rootId, action, record }) {
202
+ if (busy) return 'A directory choice is already being recorded. Let it finish, then ask again.';
203
+ if (typeof window.flolessWorkspaceRoot?.open !== 'function') return 'FloLess could not open the saved directories from here. Use the Workspace directory button on the Workspaces screen.';
204
+ // A review the person already has open is theirs: another directory's is never thrown away for a card.
205
+ if (modal.classList.contains('show') && step) {
206
+ if (step.row.rootId !== rootId) return 'A review of another saved directory is open. Finish or close it, then ask again.';
207
+ back();
208
+ }
209
+ if (!modal.classList.contains('show')) { data = null; step = null; message = ''; problem = ''; }
210
+ await window.flolessWorkspaceRoot.open();
211
+ // Opening a dialog that is already open does not reload it, so read the list here whichever way it was opened.
212
+ if (!data) await refresh();
213
+ if (!await until(() => data || problem, 8000) || !data) return problem || 'FloLess could not read its saved directories. Close the dialog and open it again.';
214
+ const row = data.roots.find((r) => r.rootId === rootId);
215
+ if (!row) return 'That saved directory is no longer in the list, so nothing was done. Check the list in the dialog.';
216
+ const control = [...content.querySelectorAll('[data-registration-action]')].find((c) => c.dataset.registrationAction === action && c.dataset.rootId === rootId);
217
+ if (!control) {
218
+ return action === 'restore'
219
+ ? 'That directory can be restored only once it has been stopped and its original folder is back. The dialog lists each one’s state.'
220
+ : 'FloLess stops using a saved directory only when it cannot reach it right now, and not one already stopped. The dialog lists each one’s state.';
221
+ }
222
+ control.click();
223
+ if (!record) return '';
224
+ // The review this card started: if the person moves to another one while FloLess waits, theirs is left for them to decide.
225
+ const mine = step;
226
+ const needsDestination = () => step.action === 'retire' && step.row.rootId === data.activeRootId;
227
+ if (!await until(() => step && !step.checking && (step.previewId || step.failed || needsDestination()), 15000)) return 'FloLess is still checking this directory. The review is open; confirm it there when it is ready.';
228
+ if (!step?.previewId) return problem || 'The review is open. Choose where to switch, then press the confirm button there.';
229
+ if (step !== mine || mine.row.rootId !== rootId || mine.action !== action) return 'The review on screen changed while FloLess waited, so it recorded nothing. The review that is open is yours to confirm.';
230
+ content.querySelector('[data-registration-action="confirm"]')?.click();
231
+ await until(() => !busy && (!step || problem), 20000);
232
+ return problem || (step ? 'The review is open. Confirm it there to record it.' : '');
233
+ }
234
+ window.flolessWorkspaceRootReview = reviewRetirementForCard;
196
235
  render();
197
236
  })();