@floless/app 0.139.1 → 0.141.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 (41) hide show
  1. package/dist/floless-server.cjs +32765 -36490
  2. package/dist/skills/floless-app-steel-takeoff/SKILL.md +8 -3
  3. package/dist/skills/floless-app-vectorize/SKILL.md +1 -1
  4. package/dist/skills/floless-app-vectorize/scripts/extract_pdf.py +7 -1
  5. package/dist/skills/floless-app-vectorize/scripts/vision_to_contract.py +7 -1
  6. package/dist/web/app.css +163 -3
  7. package/dist/web/aware.js +657 -66
  8. package/dist/web/chat.css +387 -25
  9. package/dist/web/chat.js +2005 -108
  10. package/dist/web/commands-filter.js +86 -8
  11. package/dist/web/commands-revit.js +2 -1
  12. package/dist/web/commands-shell.js +249 -13
  13. package/dist/web/commands-steel.js +34 -24
  14. package/dist/web/commands.js +19 -0
  15. package/dist/web/filter-ai-context.js +57 -0
  16. package/dist/web/filter-ai-proposal.js +87 -0
  17. package/dist/web/filter-guidance.js +8 -0
  18. package/dist/web/index.html +72 -11
  19. package/dist/web/instructor.js +231 -33
  20. package/dist/web/left-pane.js +185 -18
  21. package/dist/web/local-discovery.js +297 -0
  22. package/dist/web/model-editor-revit-adapter.js +3 -1
  23. package/dist/web/model-editor-steel-adapter.js +3 -1
  24. package/dist/web/model-editor.css +4 -4
  25. package/dist/web/model-revit-module.js +63 -0
  26. package/dist/web/model-viewport-toolbar.js +13 -1
  27. package/dist/web/model-viewport.js +16 -1
  28. package/dist/web/overlay-escape.js +79 -0
  29. package/dist/web/revit-editor.css +7 -0
  30. package/dist/web/revit-editor.html +5 -5
  31. package/dist/web/revit-editor.js +20 -10
  32. package/dist/web/steel-detail-refs.js +0 -69
  33. package/dist/web/steel-editor.html +103 -264
  34. package/dist/web/steel-filter-core.js +298 -12
  35. package/dist/web/steel-filter-hit.js +526 -0
  36. package/dist/web/steel-filter.html +1647 -75
  37. package/dist/web/steel-split-view.js +1 -1
  38. package/dist/web/vector-3d.html +3 -0
  39. package/dist/web/vector-editor.html +9 -1
  40. package/dist/web/workspaces.js +198 -25
  41. package/package.json +5 -2
@@ -32,6 +32,8 @@
32
32
  narrative: stack.querySelector('[data-left-section="narrative"]'),
33
33
  model: stack.querySelector('[data-left-section="model"]'),
34
34
  };
35
+ const approvalTray = document.getElementById('chat-approval-tray');
36
+ const chatShell = approvalTray?.closest('.ai-chat-shell');
35
37
  const switches = {
36
38
  narrative: pane.querySelector('[data-left-section-switch="narrative"]'),
37
39
  model: pane.querySelector('[data-left-section-switch="model"]'),
@@ -61,6 +63,7 @@
61
63
  const groupDisclosure = new Map();
62
64
  let dragKey = null;
63
65
  let splitSession = null;
66
+ let modelRequestedDuringApproval = false;
64
67
  let nextActionId = 0;
65
68
  let revealSequence = 0;
66
69
  let pendingRevealId = null;
@@ -101,6 +104,71 @@
101
104
 
102
105
  function available(key) { return key === 'narrative' || state.modelAvailable; }
103
106
  function shown(key) { return available(key) && (state.visible[key] || sessionVisible[key]); }
107
+ function approvalVisible() {
108
+ return !!approvalTray?.children.length && !approvalTray.closest('.ai-chat-shell')?.classList.contains('history-open');
109
+ }
110
+ function pendingDecisionVisible() {
111
+ return approvalVisible() && !!approvalTray.querySelector('.ai-chat-approval:not(.ai-chat-approval-scope)');
112
+ }
113
+ function compactApproval() {
114
+ return window.innerHeight <= 520 && approvalVisible() && shown('narrative') && shown('model');
115
+ }
116
+ function presented(key) { return shown(key) && !(key === 'model' && compactApproval() && !modelRequestedDuringApproval); }
117
+ function minimumNarrativeRatio() { return (290 + 5.5) / stack.clientHeight * 100; }
118
+ // The AI Chat section is never shorter than the rows of its chat that do not shrink (#1515): its
119
+ // heading and controls, the chat toolbar, the recovery and attachment rows and the composer. The
120
+ // conversation feed, the ⚙ strip and the approval tray are the rows that give height back — chat.css
121
+ // declares exactly those minmax(0, …), and chat-ui.test.ts holds this list to that template. Below
122
+ // this floor the composer would be pushed out through the host's overflow: hidden edge, leaving the
123
+ // panel with no message box at all. It is measured, not a constant: the composer grows with a long
124
+ // message, an attachment row can appear, and the disclosure wraps with the panel's width. Model
125
+ // yields height to it, down to Model's own minimum and never further: a window too short for both
126
+ // is a cue to hide one.
127
+ const CHAT_YIELDING_ROWS = [1, 2, 5];
128
+ // While the conversation area holds an empty-state card that carries an action (the Claude / Codex
129
+ // chooser, Sign in…, or the pending sign-in's "Sign-in window open"), the feed stops being a row that
130
+ // gives its height back: it must keep enough room for that action. chat.css hides the card outright
131
+ // at a feed of 44px or less (#1501), so at the default split on a 1280x720 window a new user saw no
132
+ // way to start a chat at all (#1554). 53px is one above chat.css's 52px tier — the single row of title
133
+ // plus action, whose tallest form is the chooser's at 48.25px — so the card keeps its title too.
134
+ // chat-ui.test.ts ties this number to that threshold. Once a conversation starts the card is gone and
135
+ // the feed yields again, so the person's own split comes back. The open ⚙ strip is deliberately not
136
+ // counted: it still takes its height from the feed first (#1501), so with it open the feed can be
137
+ // shorter than this. That strip is never open over the Claude / Codex chooser (chat.js closes it and
138
+ // disables ⚙ there), and when it is open over a sign-in card it carries that same Sign in… action itself.
139
+ const EMPTY_ACTION_FEED_PX = 53;
140
+ function emptyActionFeedReserve() {
141
+ const feed = chatShell?.querySelector('.ai-chat-feed');
142
+ if (!feed || chatShell.classList.contains('history-open')) return 0;
143
+ return Array.from(feed.children).some((child) => child.classList.contains('ai-chat-empty') && child.querySelector('button'))
144
+ ? EMPTY_ACTION_FEED_PX : 0;
145
+ }
146
+ function narrativeFloorRatio() {
147
+ const height = stack.clientHeight;
148
+ if (!(height > 0) || !chatShell || !presented('narrative') || !presented('model')) return 0;
149
+ const rows = window.getComputedStyle(chatShell).gridTemplateRows.split(' ').map(Number.parseFloat);
150
+ if (!rows.length || rows.some((row) => !Number.isFinite(row))) return 0;
151
+ const rigid = rows.reduce((sum, row, index) => sum + (CHAT_YIELDING_ROWS.includes(index) ? 0 : row), 0)
152
+ + emptyActionFeedReserve();
153
+ const around = sections.narrative.getBoundingClientRect().height - chatShell.getBoundingClientRect().height;
154
+ const modelMinimum = Number.parseFloat(window.getComputedStyle(sections.model).minHeight) || 0;
155
+ return Math.min((around + rigid + 5.5) / height * 100, 100 - (modelMinimum + 5.5) / height * 100);
156
+ }
157
+ // The split on screen: the saved ratio, moved only as far as the AI Chat floor needs. The saved value
158
+ // is left alone, so a taller window gives the person's own layout back.
159
+ function shownRatio(floor = narrativeFloorRatio()) {
160
+ return state.order[0] === 'narrative' ? Math.max(state.ratio, floor) : Math.min(state.ratio, 100 - floor);
161
+ }
162
+ function approvalSplitLocked(first) {
163
+ if (!presented('narrative') || !presented('model') || !approvalVisible()) return false;
164
+ if (pendingDecisionVisible()) return true;
165
+ // The ratio on screen, not the saved one: the AI Chat floor can already be showing enough room.
166
+ const onScreen = shownRatio();
167
+ const narrativeRatio = first === 'narrative' ? onScreen : 100 - onScreen;
168
+ // The clamp and lock must compare in the same units: recomputing pixel height at the
169
+ // exact boundary can round 290 to 289.99999999999994 and cancel an active drag.
170
+ return !!approvalTray.querySelector('.ai-chat-approval-scope') && narrativeRatio + 1e-9 < minimumNarrativeRatio();
171
+ }
104
172
  function commandInstance(value) { return encodeURIComponent(String(value)); }
105
173
 
106
174
  function applyChatIndicator(button) {
@@ -133,7 +201,7 @@
133
201
  button.dataset.commandId = `shell.left-section#${label}`;
134
202
  button.dataset.commandInstanceLabel = label;
135
203
  button.dataset.leftCollapsedSection = key;
136
- button.setAttribute('aria-pressed', String(shown(key)));
204
+ button.setAttribute('aria-pressed', String(presented(key)));
137
205
  button.setAttribute('aria-label', `Expand ${label}`);
138
206
  button.dataset.tip = `Expand ${label}`;
139
207
  button.textContent = label;
@@ -148,28 +216,54 @@
148
216
  }
149
217
 
150
218
  function reflect() {
151
- const both = shown('narrative') && shown('model');
219
+ const both = presented('narrative') && presented('model');
152
220
  const first = state.order[0];
221
+ const splitLocked = approvalSplitLocked(first);
222
+ if (splitLocked && splitSession) finishSplit(false);
223
+ if (!presented('model') && sections.model.contains(document.activeElement)) switches.model.focus({ preventScroll: true });
153
224
  split.hidden = !both;
154
- empty.hidden = shown('narrative') || shown('model');
225
+ split.setAttribute('aria-disabled', String(splitLocked));
226
+ split.tabIndex = splitLocked ? -1 : 0;
227
+ split.dataset.tip = splitLocked ? 'Resize is paused while approval needs space' : 'Drag or use arrow keys to resize · Enter or double-click to reset';
228
+ if (splitLocked) split.dataset.blockedReason = 'Resolve or leave this approval before resizing the panels.';
229
+ else delete split.dataset.blockedReason;
230
+ if (splitLocked && document.activeElement === split) switches.narrative.focus({ preventScroll: true });
231
+ empty.hidden = presented('narrative') || presented('model');
155
232
  pane.setAttribute('aria-label', state.modelAvailable ? 'AI Chat and Model panels' : 'AI Chat panel');
156
233
  for (const key of Object.keys(sections)) {
157
- const isShown = shown(key);
234
+ const isShown = presented(key);
158
235
  sections[key].hidden = !isShown;
159
236
  switches[key].hidden = !available(key);
160
237
  switches[key].setAttribute('aria-pressed', String(isShown));
238
+ if (key === 'model') switches.model.dataset.tip = compactApproval() && !modelRequestedDuringApproval
239
+ ? 'Show Model while approval waits' : 'Show or hide Model';
240
+ }
241
+ sizeSplit(both, first, splitLocked);
242
+ collapsedHost.replaceChildren(...state.order.filter(available).map(collapsedButton));
243
+ }
244
+
245
+ // Section heights and the separator's range. Also run on its own whenever the AI Chat floor can have
246
+ // moved (see the ResizeObserver at the end), which needs none of reflect()'s focus or button work.
247
+ function sizeSplit(both = presented('narrative') && presented('model'), first = state.order[0], splitLocked = approvalSplitLocked(first)) {
248
+ const floor = narrativeFloorRatio();
249
+ const ratio = shownRatio(floor);
250
+ for (const key of Object.keys(sections)) {
161
251
  sections[key].style.flex = both
162
- ? `0 0 calc(${key === first ? state.ratio : 100 - state.ratio}% - 5.5px)`
163
- : (isShown ? '1 1 auto' : '0 0 auto');
252
+ ? `0 0 calc(${key === first ? ratio : 100 - ratio}% - 5.5px)`
253
+ : (presented(key) ? '1 1 auto' : '0 0 auto');
164
254
  }
165
- if (both) {
166
- const topPercent = Math.round(state.ratio);
167
- split.setAttribute('aria-valuemin', '25');
168
- split.setAttribute('aria-valuemax', '75');
255
+ if (both && !splitLocked) {
256
+ const topPercent = Math.round(ratio);
257
+ const low = first === 'narrative' ? Math.max(25, floor) : Math.min(25, 100 - floor);
258
+ const high = first === 'narrative' ? Math.max(75, floor) : Math.min(75, 100 - floor);
259
+ split.setAttribute('aria-valuemin', String(Math.round(low)));
260
+ split.setAttribute('aria-valuemax', String(Math.round(high)));
169
261
  split.setAttribute('aria-valuenow', String(topPercent));
170
262
  split.setAttribute('aria-valuetext', `${topPercent}% for ${first === 'model' ? 'Model' : 'AI Chat'}`);
263
+ } else if (splitLocked) {
264
+ split.removeAttribute('aria-valuemin'); split.removeAttribute('aria-valuemax'); split.removeAttribute('aria-valuenow');
265
+ split.setAttribute('aria-valuetext', 'Temporarily held to show approval; saved split returns afterward');
171
266
  }
172
- collapsedHost.replaceChildren(...state.order.filter(available).map(collapsedButton));
173
267
  }
174
268
 
175
269
  function setVisible(key, value, announce = true) {
@@ -199,7 +293,14 @@
199
293
 
200
294
  pane.addEventListener('click', (event) => {
201
295
  const switcher = event.target.closest('[data-left-section-switch]');
202
- if (switcher) { const key = switcher.dataset.leftSectionSwitch; setVisible(key, !shown(key)); return; }
296
+ if (switcher) {
297
+ const key = switcher.dataset.leftSectionSwitch;
298
+ if (key === 'model' && compactApproval() && !modelRequestedDuringApproval) {
299
+ modelRequestedDuringApproval = true; reflect();
300
+ status.textContent = 'Model panel shown while approval waits.';
301
+ } else setVisible(key, !shown(key));
302
+ return;
303
+ }
203
304
  const close = event.target.closest('[data-left-section-close]');
204
305
  if (close) {
205
306
  const key = close.dataset.leftSectionClose;
@@ -209,7 +310,9 @@
209
310
  }
210
311
  const collapsed = event.target.closest('[data-left-collapsed-section]');
211
312
  if (collapsed) {
212
- setVisible(collapsed.dataset.leftCollapsedSection, true, false);
313
+ if (collapsed.dataset.leftCollapsedSection === 'model' && compactApproval() && !modelRequestedDuringApproval) {
314
+ modelRequestedDuringApproval = true; reflect();
315
+ } else setVisible(collapsed.dataset.leftCollapsedSection, true, false);
213
316
  document.querySelector('.pane-rail-left .panel-toggle[data-side="left"]')?.click();
214
317
  }
215
318
  });
@@ -245,7 +348,23 @@
245
348
  });
246
349
  });
247
350
 
248
- function setRatio(value) { state.ratio = Math.max(25, Math.min(75, value)); reflect(); }
351
+ function setRatio(value) {
352
+ let next = Math.max(25, Math.min(75, value));
353
+ if (approvalVisible() && !pendingDecisionVisible() && presented('narrative') && presented('model')
354
+ && approvalTray.querySelector('.ai-chat-approval-scope') && stack.clientHeight > 0) {
355
+ const minimum = minimumNarrativeRatio();
356
+ if (minimum > 75) return false; // the split cannot fit both sections at this height
357
+ next = state.order[0] === 'narrative' ? Math.max(next, minimum) : Math.min(next, 100 - minimum);
358
+ next = Math.max(25, Math.min(75, next));
359
+ }
360
+ // The divider stops where the AI Chat composer would start leaving its shell (#1515).
361
+ const floor = narrativeFloorRatio();
362
+ next = state.order[0] === 'narrative' ? Math.max(next, floor) : Math.min(next, 100 - floor);
363
+ // Compared with the divider on SCREEN: a press or drag the floor absorbs moves nothing, so it must
364
+ // not replace a saved split the floor is only covering for now (a taller window would bring it back).
365
+ if (next === shownRatio(floor)) return false;
366
+ state.ratio = next; reflect(); return true;
367
+ }
249
368
  function finishSplit(commit) {
250
369
  if (!splitSession) return;
251
370
  const session = splitSession;
@@ -254,10 +373,11 @@
254
373
  if (!commit) state.ratio = session.startRatio;
255
374
  try { if (!split.hasPointerCapture || split.hasPointerCapture(session.pointerId)) split.releasePointerCapture(session.pointerId); } catch { /* capture may already be gone */ }
256
375
  reflect();
257
- if (commit) save();
376
+ if (commit && state.ratio !== session.startRatio) save();
258
377
  }
259
378
  split.addEventListener('pointerdown', (event) => {
260
379
  if (event.button !== 0 || event.isPrimary === false) return;
380
+ if (split.getAttribute('aria-disabled') === 'true') return;
261
381
  if (splitSession) finishSplit(false);
262
382
  event.preventDefault(); split.focus();
263
383
  const rect = stack.getBoundingClientRect();
@@ -277,19 +397,22 @@
277
397
  window.addEventListener('blur', () => finishSplit(false));
278
398
  document.addEventListener('visibilitychange', () => { if (document.hidden) finishSplit(false); });
279
399
  split.addEventListener('dblclick', (event) => {
400
+ if (split.getAttribute('aria-disabled') === 'true') return;
280
401
  if (splitSession) { event.preventDefault(); return; }
281
- state.ratio = defaults.ratio; save(); reflect();
402
+ if (setRatio(defaults.ratio)) save();
282
403
  });
283
404
  window.addEventListener('keydown', (event) => {
284
405
  if (event.key === 'Escape' && splitSession) { event.preventDefault(); finishSplit(false); return; }
285
406
  if (event.target !== split) return;
407
+ if (split.getAttribute('aria-disabled') === 'true') { event.preventDefault(); return; }
286
408
  if (splitSession) {
287
409
  if (['ArrowUp', 'ArrowDown', 'Enter'].includes(event.key)) event.preventDefault();
288
410
  return;
289
411
  }
290
- if (event.key === 'Enter') { event.preventDefault(); state.ratio = defaults.ratio; save(); reflect(); return; }
412
+ if (event.key === 'Enter') { event.preventDefault(); if (setRatio(defaults.ratio)) save(); return; }
291
413
  if (!['ArrowUp', 'ArrowDown'].includes(event.key)) return;
292
- event.preventDefault(); setRatio(state.ratio + (event.key === 'ArrowUp' ? -1 : 1) * (event.shiftKey ? 10 : 2)); save();
414
+ // Step from where the divider is shown, not from a saved ratio the AI Chat floor is overriding.
415
+ event.preventDefault(); if (setRatio(shownRatio() + (event.key === 'ArrowUp' ? -1 : 1) * (event.shiftKey ? 10 : 2))) save();
293
416
  });
294
417
 
295
418
  function renderNodes(nodes, host) {
@@ -632,5 +755,49 @@
632
755
  forgetModel(); hello();
633
756
  },
634
757
  });
758
+ if (approvalTray) new MutationObserver(() => {
759
+ if (!approvalTray.children.length) modelRequestedDuringApproval = false;
760
+ reflect();
761
+ }).observe(approvalTray, { childList: true });
762
+ if (chatShell) new MutationObserver(reflect).observe(chatShell, { attributes: true, attributeFilter: ['class'] });
763
+ // An empty-state card with an action arriving in, or leaving, the conversation area moves the floor
764
+ // (#1554). Its own size does not: the feed is sized by the split, so only the swap is watched, and
765
+ // re-sizing the split changes no child of the feed, so this cannot feed back into itself.
766
+ // A floor that moves can also start or end a Revoke approval's hold on the split; that needs
767
+ // reflect()'s focus, tooltip and blocked-reason work, not only new section heights.
768
+ const refitFloor = () => {
769
+ if (String(approvalSplitLocked(state.order[0])) !== split.getAttribute('aria-disabled')) reflect();
770
+ else sizeSplit();
771
+ };
772
+ const chatFeed = chatShell?.querySelector('.ai-chat-feed');
773
+ if (chatFeed) new MutationObserver(refitFloor).observe(chatFeed, { childList: true });
774
+ // The AI Chat floor moves with the chat's rows that do not shrink and with the stack's own height (the
775
+ // Instructor strip opening, not only a window resize), so the split is re-sized whenever the composer,
776
+ // the recovery or attachment row, or the stack changes size: a message growing to six lines at the
777
+ // minimum takes height from Model instead of pushing the composer out. None of these, nor the three
778
+ // below, is sized by the split, so re-sizing it cannot feed back into this. (Row 4 also holds the offscreen-activity
779
+ // badge, which follows the feed's height; chat.js only shows it with 88px of feed to spare, so it is
780
+ // counted but not watched, and the next re-size picks it up.)
781
+ if (chatShell && typeof window.ResizeObserver === 'function') {
782
+ const floorWatch = new window.ResizeObserver(refitFloor);
783
+ for (const id of ['chat-composer', 'chat-recovery', 'chat-attachments']) {
784
+ const row = document.getElementById(id);
785
+ if (row) floorWatch.observe(row);
786
+ }
787
+ // The chat toolbar and the section's own heading and controls are counted in the floor too (the
788
+ // toolbar as a rigid row, the other two as the height around the shell), and none of them is sized
789
+ // by the split. Unwatched, a change to one of them after the last fit left the floor stale: an
790
+ // independent QA run measured the conversation area 1.45px under its reserve, enough to drop the
791
+ // empty state's title (#1554).
792
+ for (const part of [chatShell.querySelector('.ai-chat-toolbar'), sections.narrative.querySelector('.left-section-heading'),
793
+ sections.narrative.querySelector('.ai-chat-controls')]) {
794
+ if (part) floorWatch.observe(part);
795
+ }
796
+ floorWatch.observe(stack);
797
+ }
798
+ window.addEventListener('resize', () => {
799
+ if (window.innerHeight > 520) modelRequestedDuringApproval = false;
800
+ reflect();
801
+ });
635
802
  arrange(); reflect();
636
803
  })();
@@ -0,0 +1,297 @@
1
+ /* Explicit, read-only local discovery. A finding is evidence, never a connection. */
2
+ (() => {
3
+ 'use strict';
4
+ const modal = document.getElementById('local-discovery-modal');
5
+ const folderList = document.getElementById('local-discovery-folders');
6
+ const results = document.getElementById('local-discovery-results');
7
+ const errors = document.getElementById('local-discovery-errors');
8
+ const status = document.getElementById('local-discovery-status');
9
+ const browse = document.getElementById('local-discovery-browse');
10
+ const filterInput = document.getElementById('local-discovery-filter');
11
+ const count = document.getElementById('local-discovery-count');
12
+ const previousButton = document.getElementById('local-discovery-previous');
13
+ const nextButton = document.getElementById('local-discovery-next');
14
+ const chooseButton = document.getElementById('local-discovery-choose');
15
+ const scanButton = document.getElementById('local-discovery-scan');
16
+ const closeButton = document.getElementById('local-discovery-close');
17
+ const selections = new Map();
18
+ let scanController = null;
19
+ let scanGeneration = 0;
20
+ let folderPending = false;
21
+ let opener = null;
22
+ let openedFromLibrary = false;
23
+ let allFindings = [];
24
+ let page = 0;
25
+ const PAGE_SIZE = 40;
26
+
27
+ const make = (tag, className, content) => {
28
+ const node = document.createElement(tag);
29
+ if (className) node.className = className;
30
+ if (content != null) node.textContent = content;
31
+ return node;
32
+ };
33
+ async function post(path, body, signal) {
34
+ let response;
35
+ try {
36
+ response = await fetch(path, {
37
+ method: 'POST', headers: { 'Content-Type': 'application/json' },
38
+ body: JSON.stringify(body), signal,
39
+ });
40
+ } catch (error) {
41
+ if (error.name === 'AbortError') throw error;
42
+ throw new Error('FloLess could not reach the local scan. Check that FloLess is open, then try again.');
43
+ }
44
+ const data = await response.json().catch(() => ({}));
45
+ if (!response.ok || !data.ok) {
46
+ const error = new Error(data.ok === false && typeof data.error === 'string'
47
+ ? data.error : 'FloLess could not check those locations. Try the scan again.');
48
+ error.code = data.code;
49
+ error.expiredSelectionIds = Array.isArray(data.expiredSelectionIds) ? data.expiredSelectionIds : null;
50
+ throw error;
51
+ }
52
+ return data;
53
+ }
54
+ function setBusy(busy) {
55
+ if (busy && document.activeElement === scanButton) closeButton.focus();
56
+ // `|| folderPending` because a Remove ends the running scan before it sends its request, and
57
+ // that setBusy(false) would otherwise hand Add back in the middle of the folder change.
58
+ chooseButton.disabled = busy || folderPending;
59
+ scanButton.disabled = busy;
60
+ scanButton.textContent = busy ? 'Scanning…' : 'Scan this computer';
61
+ scanButton.setAttribute('aria-busy', String(busy));
62
+ }
63
+ function resetResults() {
64
+ allFindings = [];
65
+ page = 0;
66
+ filterInput.value = '';
67
+ browse.hidden = true;
68
+ results.replaceChildren();
69
+ errors.replaceChildren();
70
+ errors.hidden = true;
71
+ }
72
+ // Take the server's list of what the next scan will read. It is the only place that knows — it
73
+ // alone can ask the filesystem which directory a path is, and its list moves under this window
74
+ // when a lease runs out or a second window picks something. Returns whether anything changed here.
75
+ function takeFolders(folders) {
76
+ const before = [...selections.keys()];
77
+ selections.clear();
78
+ for (const folder of folders) selections.set(folder.id, folder.path);
79
+ paintFolders();
80
+ return before.length !== folders.length || before.some((id, at) => id !== folders[at].id);
81
+ }
82
+ /**
83
+ * Run ONE folder change at a time — an Add or a Remove.
84
+ *
85
+ * Two in flight can answer out of order, and each reply is a snapshot of the WHOLE list as the
86
+ * server had it when it handled that request. An older snapshot arriving last would put back a
87
+ * folder already released, and the next scan would then refuse it as expired. Discarding all but
88
+ * the newest REPLY does not fix that: the client cannot know which request the server applied
89
+ * last, only which it sent last. Never having two in flight does.
90
+ */
91
+ async function oneFolderChangeAtATime(run) {
92
+ if (folderPending) return;
93
+ folderPending = true;
94
+ const controls = () => [chooseButton, ...folderList.querySelectorAll('button')];
95
+ for (const control of controls()) control.disabled = true;
96
+ try { await run(); } finally {
97
+ folderPending = false;
98
+ // Re-read the controls: a reply repaints the rows, so these are not the buttons we disabled.
99
+ for (const control of controls()) control.disabled = false;
100
+ // Hand Add back to whoever it belongs to. setBusy keeps it disabled while a scan runs, and a
101
+ // scan can have started during this change, so restore that rather than assume it is free.
102
+ chooseButton.disabled = Boolean(scanController);
103
+ }
104
+ }
105
+ function paintFolders() {
106
+ folderList.replaceChildren();
107
+ for (const [id, path] of selections) {
108
+ const row = make('div', 'local-discovery-folder');
109
+ row.append(make('span', '', path));
110
+ const remove = make('button', '', 'Remove');
111
+ remove.type = 'button';
112
+ remove.dataset.commandId = 'shell.discovery-remove-folder';
113
+ remove.setAttribute('aria-label', `Remove folder ${path}`);
114
+ remove.addEventListener('click', () => oneFolderChangeAtATime(async () => {
115
+ ++scanGeneration;
116
+ scanController?.abort();
117
+ scanController = null;
118
+ setBusy(false);
119
+ // Drop it on the SERVER, not just from this list: a row hidden here would still be a live
120
+ // selection, and the next pick would report it back as a folder the scan reads.
121
+ try {
122
+ const data = await post('/api/local-discovery/folders/release', { selectionId: id });
123
+ takeFolders(Array.isArray(data.folders) ? data.folders : []);
124
+ resetResults();
125
+ status.textContent = 'Scope changed. Scan again to see current findings.';
126
+ } catch (error) {
127
+ status.textContent = error.message
128
+ || 'FloLess could not remove this folder from the next scan. It is still listed — try Remove again.';
129
+ }
130
+ }));
131
+ row.append(remove);
132
+ folderList.append(row);
133
+ }
134
+ }
135
+ function close(restoreFocus = true) {
136
+ ++scanGeneration;
137
+ const wasScanning = Boolean(scanController);
138
+ scanController?.abort();
139
+ scanController = null;
140
+ setBusy(false);
141
+ if (wasScanning) status.textContent = 'Scan stopped. Start a new scan to review current findings.';
142
+ modal.classList.remove('show');
143
+ if (restoreFocus) {
144
+ if (openedFromLibrary) document.getElementById('lib-modal')?.classList.add('show');
145
+ const target = openedFromLibrary ? opener : document.getElementById('menu-btn');
146
+ if (target?.isConnected && target.getClientRects().length) target.focus();
147
+ }
148
+ opener = null;
149
+ openedFromLibrary = false;
150
+ }
151
+ function open() {
152
+ opener = document.activeElement;
153
+ openedFromLibrary = Boolean(opener?.closest('#lib-modal'));
154
+ document.getElementById('lib-modal')?.classList.remove('show');
155
+ modal.classList.add('show');
156
+ closeButton.focus();
157
+ }
158
+ function findingCard(finding) {
159
+ const card = make('article', 'local-discovery-card');
160
+ const head = make('div', 'local-discovery-card-head');
161
+ head.append(make('strong', '', finding.label || 'Unnamed tool'));
162
+ head.append(make('span', 'local-discovery-found', 'Found'));
163
+ card.append(head);
164
+ const facts = make('dl', 'local-discovery-facts');
165
+ for (const [name, value] of [
166
+ ['Type', finding.kind], ['Source', finding.source], ['Version', finding.version],
167
+ ['Path', finding.path], ['Evidence', finding.evidence],
168
+ ]) {
169
+ if (value == null || value === '') continue;
170
+ facts.append(make('dt', '', name), make('dd', '', String(value)));
171
+ }
172
+ card.append(facts);
173
+ const actions = make('div', 'local-discovery-card-actions');
174
+ if (finding.graft && typeof finding.graft.ref === 'string' && typeof finding.graft.kind === 'string') {
175
+ const graft = make('button', '', 'Open in Graft');
176
+ graft.type = 'button'; graft.dataset.commandId = 'shell.discovery-open-graft';
177
+ graft.addEventListener('click', () => {
178
+ close(false);
179
+ document.dispatchEvent(new CustomEvent('floless:discovery-graft', { detail: finding.graft }));
180
+ });
181
+ actions.append(graft);
182
+ }
183
+ const chat = make('button', '', 'Ask AI Chat');
184
+ chat.type = 'button'; chat.dataset.commandId = 'shell.discovery-ask-chat';
185
+ chat.addEventListener('click', async () => {
186
+ const detail = [finding.label, finding.kind, finding.path, finding.version].filter(Boolean).join(' · ');
187
+ const draft = `I found this local tool: ${detail}. Help me decide how to use it in this project. Do not connect to it or run anything yet.`;
188
+ try {
189
+ await window.flolessChat.openDraft(draft);
190
+ close(false);
191
+ } catch { status.textContent = 'FloLess could not open AI Chat for this finding. Open a project or workflow and try again.'; }
192
+ });
193
+ actions.append(chat);
194
+ card.append(actions);
195
+ return card;
196
+ }
197
+ function paintPage() {
198
+ const query = filterInput.value.trim().toLocaleLowerCase();
199
+ const matching = query ? allFindings.filter((finding) =>
200
+ [finding.label, finding.path].some((value) => String(value || '').toLocaleLowerCase().includes(query))) : allFindings;
201
+ const pages = Math.max(1, Math.ceil(matching.length / PAGE_SIZE));
202
+ page = Math.min(page, pages - 1);
203
+ const start = page * PAGE_SIZE;
204
+ const end = Math.min(start + PAGE_SIZE, matching.length);
205
+ results.replaceChildren();
206
+ for (const finding of matching.slice(start, end)) results.append(findingCard(finding));
207
+ if (!matching.length) results.append(make('p', 'local-discovery-no-filter-match',
208
+ 'No results match this search. Change or clear it to see all results from this scan.'));
209
+ count.textContent = query
210
+ ? `${matching.length ? `Showing ${start + 1}–${end} of ` : ''}${matching.length} matching results (${allFindings.length} total).`
211
+ : `Showing ${start + 1}–${end} of ${allFindings.length} results.`;
212
+ const hidePrevious = page === 0;
213
+ const hideNext = end >= matching.length;
214
+ if ((hidePrevious && document.activeElement === previousButton)
215
+ || (hideNext && document.activeElement === nextButton)) count.focus();
216
+ previousButton.hidden = hidePrevious;
217
+ nextButton.hidden = hideNext;
218
+ }
219
+ async function scan() {
220
+ scanController?.abort();
221
+ scanController = new AbortController();
222
+ const generation = ++scanGeneration;
223
+ resetResults();
224
+ setBusy(true); status.textContent = 'Scanning the listed locations…';
225
+ try {
226
+ const data = await post('/api/local-discovery/scan', { selectionIds: [...selections.keys()] }, scanController.signal);
227
+ if (generation !== scanGeneration) return;
228
+ if (data.code === 'selection-expired') {
229
+ for (const id of data.expiredSelectionIds || [...selections.keys()]) selections.delete(id);
230
+ paintFolders();
231
+ status.textContent = 'Expired folder choices were removed. Scan again, or add those folders again.';
232
+ return;
233
+ }
234
+ const findings = Array.isArray(data.findings) ? data.findings : [];
235
+ const failures = Array.isArray(data.errors) ? data.errors : [];
236
+ status.textContent = findings.length
237
+ ? `${findings.length} ${findings.length === 1 ? 'result' : 'results'} found. Check what FloLess found before taking another step.${failures.length ? ' Some locations could not be fully checked.' : ''}`
238
+ : failures.length ? 'FloLess found no tools in the places it could check. Some places were not fully checked. Scan again or choose a smaller folder.' : 'FloLess found no tools in the places it checked. Add a folder or scan again.';
239
+ allFindings = findings;
240
+ browse.hidden = !findings.length;
241
+ if (findings.length) paintPage();
242
+ if (failures.length) {
243
+ errors.hidden = false;
244
+ errors.append(make('strong', '', 'Some places could not be fully checked. Scan again or choose a smaller folder.'));
245
+ for (const failure of failures) errors.append(make('p', '', `${failure.source}: ${failure.message}`));
246
+ }
247
+ } catch (error) {
248
+ if (generation === scanGeneration && error.code === 'selection-expired') {
249
+ for (const id of error.expiredSelectionIds || [...selections.keys()]) selections.delete(id);
250
+ paintFolders();
251
+ status.textContent = 'Expired folder choices were removed. Scan again, or add those folders again.';
252
+ } else if (error.name !== 'AbortError' && generation === scanGeneration) {
253
+ status.textContent = error.message || 'FloLess could not check those locations. Try the scan again.';
254
+ }
255
+ } finally {
256
+ if (generation === scanGeneration) { scanController = null; setBusy(false); }
257
+ }
258
+ }
259
+ chooseButton.addEventListener('click', () => oneFolderChangeAtATime(async () => {
260
+ try {
261
+ const data = await post('/api/local-discovery/folders/choose', {});
262
+ if (!data.cancelled && Array.isArray(data.folders)) {
263
+ if (!takeFolders(data.folders)) {
264
+ // The same selections in the same order: nothing changed for this window, so the findings
265
+ // below still describe what the next scan will read. Leave them alone.
266
+ status.textContent = 'This folder is already in the next scan. Nothing was added, and no scan has started.';
267
+ return;
268
+ }
269
+ // The scan reads something different now, so the findings below it are from the older scope.
270
+ resetResults();
271
+ status.textContent = 'Folder added to the next scan. Up to three selected folders can be included. No scan has started.';
272
+ }
273
+ } catch (error) { status.textContent = error.message || 'FloLess could not choose that folder. Try another local folder.'; }
274
+ }));
275
+ scanButton.addEventListener('click', scan);
276
+ filterInput.addEventListener('input', () => { page = 0; paintPage(); });
277
+ previousButton.addEventListener('click', () => { page = Math.max(0, page - 1); paintPage(); });
278
+ nextButton.addEventListener('click', () => { page += 1; paintPage(); });
279
+ closeButton.addEventListener('click', () => close());
280
+ modal.addEventListener('click', (event) => { if (event.target === modal) close(); });
281
+ modal.addEventListener('keydown', (event) => {
282
+ if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); close(); return; }
283
+ if (event.key !== 'Tab') return;
284
+ const focusables = [...modal.querySelectorAll('button:not([disabled]):not([hidden]), [tabindex="0"]')]
285
+ .filter((item) => item.getClientRects().length);
286
+ if (!focusables.length) { event.preventDefault(); modal.querySelector('.modal')?.focus(); return; }
287
+ const first = focusables[0], last = focusables[focusables.length - 1];
288
+ if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); }
289
+ else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); }
290
+ });
291
+ document.getElementById('lib-discover-local')?.addEventListener('click', open);
292
+ const previousMenuAction = handleMenuAction;
293
+ handleMenuAction = function (action) {
294
+ if (action === 'discover-local') { open(); return; }
295
+ previousMenuAction(action);
296
+ };
297
+ })();
@@ -34,10 +34,12 @@ const CONTROLS = Object.freeze({
34
34
  'model.display-mode': {
35
35
  kind: 'menu', aria: true, el: 'revitDisplay', menu: 'revitDisplayMenu', label: 'Solid', data: { 'data-mode': 'solid' },
36
36
  tip: 'Display mode — solid, wireframe, see-through, or realistic',
37
+ // Same fidelity-ramp order as the Steel menu — Wireframe, X-ray, Solid, Realistic; Revit has no
38
+ // Shadowed — so the two 3D toolbars read alike (#1427); Solid stays the checked default.
37
39
  items: [
38
- { kind: 'item', cmd: 'revit.display-mode-set#solid', data: { 'data-mode': 'solid' }, role: 'menuitemradio', checked: true, label: 'Solid', tip: 'Solid shaded model' },
39
40
  { kind: 'item', cmd: 'revit.display-mode-set#wireframe', data: { 'data-mode': 'wire' }, role: 'menuitemradio', checked: false, label: 'Wireframe', tip: 'Edges only' },
40
41
  { kind: 'item', cmd: 'revit.display-mode-set#x-ray', data: { 'data-mode': 'xray' }, role: 'menuitemradio', checked: false, label: 'X-ray', tip: 'See through model surfaces' },
42
+ { kind: 'item', cmd: 'revit.display-mode-set#solid', data: { 'data-mode': 'solid' }, role: 'menuitemradio', checked: true, label: 'Solid', tip: 'Solid shaded model' },
41
43
  { kind: 'item', cmd: 'revit.display-mode-set#realistic', data: { 'data-mode': 'realistic' }, role: 'menuitemradio', checked: false, label: 'Realistic', tip: 'Realistic — fuller shading in the model’s own Revit colours (Revit material finishes are not part of the conversion)' },
42
44
  { kind: 'divider' },
43
45
  { kind: 'item', cmd: 'revit.lighting', el: 'revitLighting', data: { 'data-lighting': 'open' }, label: 'Lighting…', tip: 'Adjust sunlight direction and model brightness' },
@@ -266,10 +266,12 @@ const CONTROLS = Object.freeze({
266
266
  // cannot inherit a Steel element selector.
267
267
  kind: 'menu', aria: true, el: 'm3dModeBtn', menu: 'm3dMode', label: 'Solid', data: { 'data-mode': 'solid' },
268
268
  tip: 'Display mode — solid, wireframe, see-through (X-ray) or realistic materials',
269
+ // Ordered as a fidelity ramp — Wire, X-ray, Solid, Realistic, Shadowed — with the default (Solid)
270
+ // in the middle rather than first (#1427). Only the position moves: Solid stays the checked default.
269
271
  items: [
270
- { kind: 'item', cmd: 'steel.display-mode#a solid shaded model', data: { 'data-mode': 'solid' }, class: 'on', role: 'menuitemradio', checked: true, label: 'Solid', tip: 'Solid shaded model' },
271
272
  { kind: 'item', cmd: 'steel.display-mode#a wireframe', data: { 'data-mode': 'wire' }, role: 'menuitemradio', checked: false, label: 'Wire', tip: 'Wireframe — edges only' },
272
273
  { kind: 'item', cmd: 'steel.display-mode#see-through X-ray', data: { 'data-mode': 'xray' }, role: 'menuitemradio', checked: false, label: 'X-ray', tip: 'See-through — reveal hidden parts' },
274
+ { kind: 'item', cmd: 'steel.display-mode#a solid shaded model', data: { 'data-mode': 'solid' }, class: 'on', role: 'menuitemradio', checked: true, label: 'Solid', tip: 'Solid shaded model' },
273
275
  { kind: 'item', cmd: 'steel.display-mode#realistic materials', data: { 'data-mode': 'realistic' }, role: 'menuitemradio', checked: false, label: 'Realistic', tip: 'Realistic — real material finishes (steel, concrete, timber…)' },
274
276
  { kind: 'item', cmd: 'steel.display-mode#realistic with shadows', data: { 'data-mode': 'shadowed' }, role: 'menuitemradio', checked: false, label: 'Shadowed', tip: 'Realistic with cast shadows — more depth, at a cost to frame rate' },
275
277
  { kind: 'divider' },