@floless/app 0.157.0 → 0.159.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 (44) hide show
  1. package/cli-actions.mjs +7 -0
  2. package/dist/floless-server.cjs +188306 -155284
  3. package/dist/schemas/drawing-check.profile.v1.schema.json +33 -1
  4. package/dist/skills/floless-app-actions/SKILL.md +26 -5
  5. package/dist/skills/floless-app-bridge/SKILL.md +5 -3
  6. package/dist/skills/floless-app-knowledge/SKILL.md +14 -1
  7. package/dist/skills/floless-app-knowledge/references/schema.md +4 -1
  8. package/dist/skills/floless-app-onboarding/SKILL.md +67 -4
  9. package/dist/skills/floless-app-onboarding/references/floless-surfaces.md +7 -4
  10. package/dist/skills/floless-app-queue/SKILL.md +3 -1
  11. package/dist/skills/floless-app-steel-model/SKILL.md +41 -1
  12. package/dist/skills/floless-app-steel-takeoff/SKILL.md +71 -1
  13. package/dist/skills/floless-app-workflows/SKILL.md +6 -3
  14. package/dist/web/agents.js +12 -5
  15. package/dist/web/app.css +229 -27
  16. package/dist/web/app.js +6 -0
  17. package/dist/web/aware.js +275 -64
  18. package/dist/web/chat.css +60 -22
  19. package/dist/web/chat.js +396 -59
  20. package/dist/web/commands-shell.js +546 -11
  21. package/dist/web/commands-steel.js +1 -0
  22. package/dist/web/drawing-check-editor.html +10 -0
  23. package/dist/web/drawing-check-editor.js +44 -0
  24. package/dist/web/guide.js +4 -2
  25. package/dist/web/index.html +66 -12
  26. package/dist/web/instructor.js +21 -9
  27. package/dist/web/kb-categories.js +351 -0
  28. package/dist/web/kb-graph-worker.js +73 -0
  29. package/dist/web/pages.js +185 -19
  30. package/dist/web/project-access.js +67 -8
  31. package/dist/web/project-modules.js +474 -0
  32. package/dist/web/project-workflows.js +274 -0
  33. package/dist/web/run-page-view.js +353 -0
  34. package/dist/web/steel-3d-core.js +46 -0
  35. package/dist/web/steel-3d-view.js +8 -38
  36. package/dist/web/steel-editor.html +225 -43
  37. package/dist/web/tab-signal.js +323 -0
  38. package/dist/web/terminal-requests.js +48 -7
  39. package/dist/web/workspace-root-recovery.js +119 -0
  40. package/dist/web/workspaces.js +1597 -220
  41. package/launch-starting-page.mjs +184 -0
  42. package/launch.mjs +214 -73
  43. package/package.json +7 -1
  44. package/dist/web/report-files.js +0 -50
package/dist/web/chat.js CHANGED
@@ -41,6 +41,17 @@
41
41
  moveSecondary: el('chat-move-secondary'), moveDismiss: el('chat-move-dismiss'),
42
42
  };
43
43
 
44
+ // The hint line under the message box only takes room when it says something about this moment. Its idle text
45
+ // ("Enter to send …") is kept for screen readers but not drawn. Watched rather than set at each of the many places
46
+ // that write the hint, so a new writer can never leave an error hidden behind the idle class.
47
+ function markIdleHint() {
48
+ ui.hint?.classList.toggle('is-idle', /^Enter to send /.test(ui.hint.textContent || ''));
49
+ }
50
+ if (ui.hint && typeof MutationObserver === 'function') {
51
+ new MutationObserver(markIdleHint).observe(ui.hint, { childList: true, characterData: true, subtree: true });
52
+ markIdleHint();
53
+ }
54
+
44
55
  const state = {
45
56
  // #2438: the picks waiting to go with the next message (per conversation), and the open @ list.
46
57
  mentions: {}, mentionMenu: null, mentionDismissed: null,
@@ -621,6 +632,7 @@
621
632
  const workspaceSurface = {
622
633
  drawings: 'drawing-filter', model: 'project-model', exports: 'project-exports',
623
634
  history: 'project-history', knowledge: 'project-knowledge', pages: 'project-pages',
635
+ workflows: 'project-workflows', // #2470 R6.2
624
636
  }[selectedStep || ''] || 'project-list';
625
637
  const workspaceProjectOpen = document.getElementById('ws-project')?.hidden === false;
626
638
  const dashboardVisible = document.getElementById('dashboard')?.hidden === false;
@@ -666,6 +678,7 @@
666
678
  case 'project-history': return shellText('ws-history');
667
679
  case 'project-knowledge': return shellText('ws-knowledge');
668
680
  case 'project-pages': return shellText('ws-pages');
681
+ case 'project-workflows': return shellText('ws-workflows');
669
682
  case 'project-list': return shellText('ws-landing');
670
683
  case 'workflow-list': return shellText('wf-landing');
671
684
  case 'agent-list': case 'agent-page': return shellText('agents-surface');
@@ -681,7 +694,7 @@
681
694
  function floLessContextLabel(context = currentFloLessContext()) {
682
695
  const labels = {
683
696
  'drawing-filter': 'Drawing Filter', 'project-model': 'project model', 'project-exports': 'project exports',
684
- 'project-history': 'project history', 'project-knowledge': 'project Knowledge', 'project-pages': 'project Pages', 'project-list': 'project list',
697
+ 'project-history': 'project history', 'project-knowledge': 'project Knowledge', 'project-pages': 'project Pages', 'project-workflows': 'project Workflows', 'project-list': 'project list',
685
698
  'workflow-canvas': 'workflow canvas', dashboard: 'dashboard', report: 'report', '3d-report': '3D report',
686
699
  'model-editor': 'model editor', 'workflow-list': 'workflow list', 'agent-list': 'list of agents', 'agent-page': 'agent page',
687
700
  };
@@ -859,6 +872,66 @@
859
872
  return node;
860
873
  }
861
874
 
875
+ /*
876
+ * #2582: the two source viewers (a cited source, a readiness place) open over a backdrop of their own, never as a
877
+ * native modal <dialog>. showModal() lifts a dialog into the browser's top layer and makes the rest of the page inert,
878
+ * the Instructor included: `?` explained a viewer's control in a band nobody could see, and "see all" opened a command
879
+ * sheet nobody could click. Like the Page viewer, the backdrop sits under the band and the sheet (app.css), Tab stays
880
+ * in the viewer, and a press on the backdrop itself closes it. The rest of the app is made inert as a modal would make
881
+ * it, all but the band and its Ask menu, so the sheet takes a person to the viewer's own control and never to the same
882
+ * command on a chip behind it. Returns what puts it all back; the caller's `close` must call it.
883
+ */
884
+ function showChatViewer(dialog, close) {
885
+ const backdrop = document.createElement('div');
886
+ backdrop.className = 'modal-backdrop show ai-chat-viewer-backdrop';
887
+ // The Instructor's command sheet may open over this viewer, as over the Page viewer: its controls are built at run time.
888
+ backdrop.dataset.commandSheetOver = '';
889
+ dialog.setAttribute('aria-modal', 'true');
890
+ backdrop.append(dialog);
891
+ // What was inert already stays so when the viewer closes: put back, never cleared.
892
+ const covered = [...document.querySelectorAll('#app > *')].filter((node) => node.id !== 'instructor' && node.id !== 'ix-ask-menu')
893
+ .map((node) => [node, node.inert]);
894
+ for (const [node] of covered) node.inert = true;
895
+ document.body.append(backdrop);
896
+ dialog.show();
897
+ let pressedBackdrop = false;
898
+ backdrop.addEventListener('mousedown', (event) => { pressedBackdrop = event.target === backdrop; });
899
+ backdrop.addEventListener('click', (event) => {
900
+ const hit = pressedBackdrop && event.target === backdrop;
901
+ pressedBackdrop = false;
902
+ if (hit) close();
903
+ });
904
+ // On the document, in capture, not on the dialog: a click on the picture or the title leaves focus on <body>, and a
905
+ // shown (not modal) dialog has no Escape of its own, so a dialog-level listener would never hear the key. The viewer
906
+ // takes Escape and Tab from wherever focus is (the viewer, the band, a toast, the page itself), except while
907
+ // something above it owns the keys: another dialog (the command sheet, or a form the band's Ask menu opens) or the
908
+ // Ask menu itself, open or holding focus. Tab goes round the viewer's controls and then the band's, so "see all" and
909
+ // Ask stay reachable from the keyboard.
910
+ const forThisViewer = (event) => {
911
+ if ([...document.querySelectorAll('.modal-backdrop.show')].some((node) => node !== backdrop)) return false;
912
+ const askMenu = document.getElementById('ix-ask-menu');
913
+ return !(askMenu && (!askMenu.hidden || askMenu.contains(event.target)));
914
+ };
915
+ const onKey = (event) => {
916
+ if ((event.key !== 'Escape' && event.key !== 'Tab') || !forThisViewer(event)) return;
917
+ event.preventDefault();
918
+ if (event.key === 'Escape') { event.stopPropagation(); close(); return; }
919
+ const reachable = (node) => !node.disabled && !node.closest('[inert]') && node.getClientRects().length;
920
+ const band = document.getElementById('instructor');
921
+ const focusables = [...dialog.querySelectorAll('button, a[href], [tabindex="0"]'), ...(band?.querySelectorAll('button, a[href], [tabindex="0"]') ?? [])].filter(reachable);
922
+ if (!focusables.length) return;
923
+ const at = focusables.indexOf(document.activeElement);
924
+ const step = event.shiftKey ? -1 : 1;
925
+ focusables[at < 0 ? (event.shiftKey ? focusables.length - 1 : 0) : (at + step + focusables.length) % focusables.length].focus();
926
+ };
927
+ document.addEventListener('keydown', onKey, true);
928
+ return () => {
929
+ document.removeEventListener('keydown', onKey, true);
930
+ backdrop.remove();
931
+ for (const [node, wasInert] of covered) node.inert = wasInert;
932
+ };
933
+ }
934
+
862
935
  // The composer's disclosure line. Derived from state in ONE place and called from every render
863
936
  // entry point, rather than switched on where the chooser is built and off in each of the paths
864
937
  // that leave it: a guarantee assembled from N call sites is only as good as the one someone
@@ -1708,8 +1781,12 @@
1708
1781
  } finally { trigger.disabled = false; }
1709
1782
  }
1710
1783
 
1784
+ // Today's messages need only the time. Anything older carries its full date too: scrolling back through a chat
1785
+ // from days ago, a bare "14:02" says nothing about when it happened.
1711
1786
  function eventTime(event) {
1712
- return new Intl.DateTimeFormat(undefined, { hour: '2-digit', minute: '2-digit' }).format(new Date(event.createdAt));
1787
+ const today = formatDay(event.createdAt) === 'Today';
1788
+ return new Intl.DateTimeFormat(undefined, today ? { hour: '2-digit', minute: '2-digit' }
1789
+ : { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' }).format(new Date(event.createdAt));
1713
1790
  }
1714
1791
 
1715
1792
  function beginRename() {
@@ -2170,7 +2247,7 @@
2170
2247
  // The conversation and owner are taken now, from what is being rendered: a chip clicked later opens THIS
2171
2248
  // conversation's source even while the app is between conversations (QA #2437: after Open in Knowledge).
2172
2249
  byAnchor.set(entry.anchor, { anchor: entry.anchor, entry, citationId: event.eventId, index, number: 0,
2173
- chatId: state.chat?.chatId ?? null, owner: ownerQuery() });
2250
+ chatId: state.chat?.chatId ?? null, owner: ownerQuery(), ownerObject: state.scope?.owner ?? null });
2174
2251
  });
2175
2252
  }
2176
2253
  let n = 0;
@@ -2178,8 +2255,37 @@
2178
2255
  return { byAnchor, order };
2179
2256
  }
2180
2257
 
2181
- function citationProvenance(read) {
2182
- return `Found: yes · Read by AI: ${CITATION_READ[read] || CITATION_READ.no} · Checked: no`;
2258
+ /**
2259
+ * #2471: what "Read by AI" says, by kind — each kind has its own receipts. A member counts only by its @-mention line in
2260
+ * the person's message; a file only by a look that showed it, and one that merely went with the question says so.
2261
+ */
2262
+ function citationReadWords(entry) {
2263
+ if (entry.kind === 'member') return entry.read === 'mentioned' ? 'yes, its @-mention was in your message' : 'not recorded';
2264
+ if (entry.kind === 'attachment') {
2265
+ if (entry.read === 'looked') {
2266
+ const pages = Array.isArray(entry.ref?.pagesLooked) ? entry.ref.pagesLooked : [];
2267
+ return pages.length ? `yes, ${pages.length === 1 ? 'page' : 'pages'} ${pages.join(', ')}` : 'yes';
2268
+ }
2269
+ // In the message itself: a data file as its text, checked against the attached file and cut at 16,000 characters.
2270
+ if (entry.read === 'in-message') return 'yes, its text was in your message (up to the first 16,000 characters)';
2271
+ return entry.read === 'sent' ? 'not recorded, it went with your question' : 'not recorded';
2272
+ }
2273
+ return CITATION_READ[entry.read] || CITATION_READ.no;
2274
+ }
2275
+
2276
+ function citationProvenance(entry) {
2277
+ return `Found: yes · Read by AI: ${citationReadWords(entry)} · Checked: no`;
2278
+ }
2279
+
2280
+ /** The chip's tag, in words: never a colour or a tick. */
2281
+ function citationMarks(entry) {
2282
+ if (entry.kind === 'attachment' && entry.read === 'sent') return 'FOUND · SENT WITH QUESTION';
2283
+ return ['whole-sheet', 'tiles', 'yes', 'mentioned', 'looked', 'in-message'].includes(entry.read) ? 'FOUND · READ BY AI' : 'FOUND';
2284
+ }
2285
+
2286
+ /** A member is named with its profile, which is what tells it from a member with a like mark. */
2287
+ function citationLabel(entry) {
2288
+ return entry.kind === 'member' && entry.status === 'resolved' && entry.ref?.profile ? `${entry.label} · ${entry.ref.profile}` : entry.label;
2183
2289
  }
2184
2290
 
2185
2291
  function citationUrl(row, what, extra = '') {
@@ -2214,13 +2320,13 @@
2214
2320
  const marker = button(resolved ? String(row.number) : '?', 'shell.chat-cite-anchor', `ai-chat-cite${resolved ? '' : ' unresolved'}`);
2215
2321
  marker.dataset.turnId = turnId || '';
2216
2322
  marker.dataset.anchor = spec.anchor;
2217
- const label = resolved ? row.entry.label : 'no source';
2323
+ const label = resolved ? citationLabel(row.entry) : 'no source';
2218
2324
  // No citation for this anchor on this page is "none recorded", not "none found": the AI may have given none, or the
2219
2325
  // record has not reached this page yet.
2220
2326
  const missing = row ? 'No source was found for this claim' : 'No source is recorded for this claim';
2221
2327
  marker.dataset.commandInstanceLabel = label;
2222
2328
  marker.setAttribute('aria-label', resolved ? `Source ${row.number}: ${label}` : missing);
2223
- marker.dataset.tip = resolved ? `${label} · ${citationProvenance(row.entry.read)}` : missing;
2329
+ marker.dataset.tip = resolved ? `${label} · ${citationProvenance(row.entry)}` : missing;
2224
2330
  marker.addEventListener('click', () => {
2225
2331
  const chip = [...ui.feed.querySelectorAll('.ai-chat-source')].find((node) => node.dataset.turnId === turnId && node.dataset.anchor === spec.anchor);
2226
2332
  if (!chip) { announce(resolved ? 'Its source is listed under the answer.' : 'The AI gave no source for this claim.'); return; }
@@ -2248,7 +2354,7 @@
2248
2354
  why.textContent = `No source: ${entry.reason}`;
2249
2355
  const ask = button('Ask for the source', 'shell.chat-cite-ask', 'ai-chat-source-action');
2250
2356
  ask.dataset.tip = 'Puts a question in the message box asking where this comes from. Nothing is sent until you press Send';
2251
- ask.addEventListener('click', () => addToMessageBox(`${unsourcedClaim(turnId, row.anchor)}: which sheet or Knowledge page does it come from? Cite it, or say plainly that it is an assumption.`));
2357
+ ask.addEventListener('click', () => addToMessageBox(`${unsourcedClaim(turnId, row.anchor)}: which sheet, model member, attached file or Knowledge page does it come from? Cite it, or say plainly that it is an assumption.`));
2252
2358
  const assume = button('Go on with this as an assumption', 'shell.chat-cite-assume', 'ai-chat-source-action');
2253
2359
  assume.dataset.tip = 'Puts a message in the message box asking the AI to carry on with it as a labelled assumption. Nothing is sent until you press Send';
2254
2360
  assume.addEventListener('click', () => addToMessageBox(`${unsourcedClaim(turnId, row.anchor)}: go on with it as an assumption, and label it as an assumption wherever you use it.`));
@@ -2265,13 +2371,14 @@
2265
2371
  chip.append(thumb);
2266
2372
  }
2267
2373
  }
2268
- const open = button(entry.label, 'shell.chat-cite-open', 'ai-chat-answer-open ai-chat-source-open');
2269
- open.dataset.commandInstanceLabel = entry.label;
2270
- open.setAttribute('aria-label', `Open ${entry.label}`);
2271
- open.dataset.tip = citationProvenance(entry.read);
2374
+ const label = citationLabel(entry);
2375
+ const open = button(label, 'shell.chat-cite-open', 'ai-chat-answer-open ai-chat-source-open');
2376
+ open.dataset.commandInstanceLabel = label;
2377
+ open.setAttribute('aria-label', `Open ${label}`);
2378
+ open.dataset.tip = citationProvenance(entry);
2272
2379
  open.addEventListener('click', () => openCitedSource(row, turnId));
2273
2380
  const marks = document.createElement('span'); marks.className = 'ai-chat-source-marks';
2274
- marks.textContent = entry.read === 'no' ? 'FOUND' : 'FOUND · READ BY AI';
2381
+ marks.textContent = citationMarks(entry);
2275
2382
  chip.append(open, marks);
2276
2383
  return chip;
2277
2384
  }
@@ -2296,7 +2403,7 @@
2296
2403
  const open = button(label, 'shell.chat-cite-open-knowledge', 'ai-chat-answer-open ai-chat-source-open');
2297
2404
  open.dataset.commandInstanceLabel = label;
2298
2405
  open.setAttribute('aria-label', `Open ${label}`);
2299
- open.dataset.tip = citationProvenance('unknown');
2406
+ open.dataset.tip = citationProvenance({ kind: 'kb-page', read: 'unknown' });
2300
2407
  open.addEventListener('click', () => {
2301
2408
  if (window.flolessWorkspaces?.openKnowledgePage) window.flolessWorkspaces.openKnowledgePage(event.payload.projectId, page.slug, event.payload.generationId);
2302
2409
  else announce('Knowledge is not available on this page.');
@@ -2367,9 +2474,9 @@
2367
2474
  async function openCitedSource(row, turnId) {
2368
2475
  const entry = row.entry;
2369
2476
  const dialog = document.createElement('dialog'); dialog.className = 'ai-chat-source-viewer';
2370
- dialog.setAttribute('aria-label', entry.label);
2477
+ dialog.setAttribute('aria-label', citationLabel(entry));
2371
2478
  const head = document.createElement('div'); head.className = 'ai-chat-source-viewer-head';
2372
- const title = Object.assign(document.createElement('strong'), { textContent: entry.label });
2479
+ const title = Object.assign(document.createElement('strong'), { textContent: citationLabel(entry) });
2373
2480
  const close = button('Close', 'shell.chat-cite-close', 'ai-chat-source-viewer-close');
2374
2481
  // Closing is done here, not left to the dialog's own `close` event, which an embedding browser may never fire: the
2375
2482
  // viewer is removed, its picture released and focus handed back to the chip, once, whichever way it closes.
@@ -2379,25 +2486,29 @@
2379
2486
  if (finished) return;
2380
2487
  finished = true;
2381
2488
  if (dialog.open) dialog.close();
2382
- dialog.remove();
2489
+ hide();
2383
2490
  if (picture) URL.revokeObjectURL(picture);
2384
2491
  liveCitationOpener(turnId, row.anchor)?.focus({ preventScroll: true });
2385
2492
  };
2386
2493
  close.addEventListener('click', finish);
2387
- dialog.addEventListener('keydown', (event) => { if (event.key === 'Escape') { event.preventDefault(); finish(); } });
2388
2494
  dialog.addEventListener('close', finish);
2389
2495
  head.append(title, close);
2390
- const note = Object.assign(document.createElement('span'), { className: 'ai-chat-source-viewer-note', textContent: citationProvenance(entry.read) });
2496
+ const note = Object.assign(document.createElement('span'), { className: 'ai-chat-source-viewer-note', textContent: citationProvenance(entry) });
2391
2497
  const body = document.createElement('div'); body.className = 'ai-chat-source-viewer-body';
2392
2498
  const status = Object.assign(document.createElement('p'), { className: 'ai-chat-source-viewer-status', textContent: 'Opening…' });
2393
2499
  status.setAttribute('role', 'status');
2394
2500
  body.append(status);
2395
2501
  dialog.append(head, note, body);
2396
- document.body.append(dialog);
2397
- dialog.showModal();
2502
+ const hide = showChatViewer(dialog, finish);
2503
+ close.focus({ preventScroll: true });
2398
2504
  const refused = async (response) => {
2399
2505
  if (response.status === 404) return 'FloLess no longer holds this source, or its project is no longer part of this conversation.';
2400
- if (response.status === 410) return 'This Knowledge page has changed since the answer, so FloLess does not show it as the page the answer cited.';
2506
+ if (response.status === 410) {
2507
+ if (entry.kind !== 'attachment') return 'This Knowledge page has changed since the answer, so FloLess does not show it as the page the answer cited.';
2508
+ // Changed bytes, or no longer the plain file that was attached: the server says which.
2509
+ const said = await response.json().catch(() => null);
2510
+ return typeof said?.message === 'string' && said.message ? said.message : 'This file has changed since the answer cited it, so FloLess does not show it as the cited file.';
2511
+ }
2401
2512
  // 503: FloLess could not check it just now; anything else is said as "try again", never as "gone".
2402
2513
  const said = await response.json().catch(() => null);
2403
2514
  return typeof said?.message === 'string' && said.message ? said.message : 'FloLess could not open this source right now. Try again in a moment.';
@@ -2427,6 +2538,57 @@
2427
2538
  body.append(image);
2428
2539
  return;
2429
2540
  }
2541
+ if (entry.kind === 'member') { await showCitedMember(row, { dialog, body, status, finish, refused, done: () => finished }); return; }
2542
+ if (entry.kind === 'attachment') {
2543
+ const response = await fetch(citationUrl(row, 'attachment'), { credentials: 'same-origin', cache: 'no-store' });
2544
+ if (!response.ok) { const why = await refused(response); if (!finished) status.textContent = why; return; }
2545
+ const type = (response.headers.get('Content-Type') || '').split(';')[0].trim().toLowerCase();
2546
+ if (type.startsWith('image/')) {
2547
+ const bytes = await response.blob();
2548
+ if (finished) return;
2549
+ picture = URL.createObjectURL(bytes);
2550
+ status.textContent = 'The file as it was attached.';
2551
+ body.append(Object.assign(document.createElement('img'), { src: picture, alt: entry.label }));
2552
+ } else if (type === 'text/plain') {
2553
+ const text = await response.text();
2554
+ if (finished) return;
2555
+ // A data file reaches the AI cut to its first 16,000 characters (attachment-text.ts MAX_TEXT_CHARS): said, never hidden.
2556
+ status.textContent = 'The file as it was attached. The AI is given at most the first 16,000 characters of a data file.';
2557
+ const shown = [...text];
2558
+ const pre = Object.assign(document.createElement('pre'), { className: 'ai-chat-source-viewer-text', tabIndex: 0,
2559
+ textContent: shown.length > 16000 ? shown.slice(0, 16000).join('') : text });
2560
+ pre.setAttribute('aria-label', `Text of ${entry.label}`);
2561
+ body.append(pre);
2562
+ if (shown.length > 16000) {
2563
+ body.append(Object.assign(document.createElement('p'), { className: 'ai-chat-source-viewer-status',
2564
+ textContent: `Showing the first 16,000 of ${shown.length.toLocaleString()} characters. Open it in its default app to see all of it.` }));
2565
+ }
2566
+ } else {
2567
+ await response.body?.cancel().catch(() => {});
2568
+ if (finished) return;
2569
+ status.textContent = 'FloLess does not show this kind of file here. Open it in its default app.';
2570
+ }
2571
+ const external = button('Open in its default app', 'shell.chat-cite-open-file', 'ai-chat-source-viewer-knowledge');
2572
+ external.addEventListener('click', async () => {
2573
+ try {
2574
+ await request(citationUrl(row, 'attachment/open'), { method: 'POST', body: JSON.stringify({ owner: row.ownerObject }) });
2575
+ announce(`Opened ${entry.label} in its default app.`);
2576
+ } catch (error) {
2577
+ // Why, by what the server answered (its code), or why it could not be asked.
2578
+ const why = {
2579
+ 'chat-page-closed': 'This conversation is no longer the one open here. Open it again, then press Open in its default app.',
2580
+ 'citation-source-unavailable': 'FloLess no longer holds this file in this conversation, so there is nothing to open.',
2581
+ 'citation-source-changed': 'This file has changed since the answer cited it, so FloLess does not open it as the cited file.',
2582
+ 'citation-source-not-as-attached': 'This file is no longer the plain file that was attached, so FloLess does not open it as the cited file. Attach the file again if you still need it.',
2583
+ 'citation-source-unreadable': 'FloLess could not check this file just now. Try again in a moment.',
2584
+ }[error?.code] || '';
2585
+ if (!why) console.error('[chat] a cited file could not be opened in its app', error);
2586
+ announce(why || `FloLess could not open ${entry.label} in its default app. Try again in a moment, or open the file from the message it was attached to.`);
2587
+ }
2588
+ });
2589
+ dialog.append(external);
2590
+ return;
2591
+ }
2430
2592
  const response = await fetch(citationUrl(row, 'page'), { credentials: 'same-origin', cache: 'no-store' });
2431
2593
  if (!response.ok) { const why = await refused(response); if (!finished) status.textContent = why; return; }
2432
2594
  const { page } = await response.json();
@@ -2448,6 +2610,61 @@
2448
2610
  }
2449
2611
  }
2450
2612
 
2613
+ /**
2614
+ * #2471: a cited member in the source viewer — first as it was cited (FloLess's snapshot), then where the model stands
2615
+ * now, then the way to it. "Show current in the model" whenever the model changed: what is framed is the member as it
2616
+ * is now, not as the answer described it. The member's route is asked again right before moving, so a project that
2617
+ * left the conversation since is never opened.
2618
+ */
2619
+ async function showCitedMember(row, view) {
2620
+ const { dialog, body, status, finish, refused, done } = view;
2621
+ const response = await fetch(citationUrl(row, 'member'), { credentials: 'same-origin', cache: 'no-store' });
2622
+ if (!response.ok) { const why = await refused(response); if (!done()) status.textContent = why; return; }
2623
+ const { member } = await response.json();
2624
+ if (done()) return;
2625
+ const facts = document.createElement('dl'); facts.className = 'ai-chat-source-viewer-facts';
2626
+ const fact = (term, value) => facts.append(Object.assign(document.createElement('dt'), { textContent: term }),
2627
+ Object.assign(document.createElement('dd'), { textContent: value }));
2628
+ fact('Mark', member.mark ?? 'No mark');
2629
+ fact('Profile', member.profile ?? 'Not recorded');
2630
+ const views = Array.isArray(member.views) ? member.views : [];
2631
+ fact('Read on', views.length ? views.map((v) => (v.title ? `${v.sheet} (${v.title})` : v.sheet)).join(', ') : 'No sheet recorded');
2632
+ body.insertBefore(Object.assign(document.createElement('p'), { className: 'ai-chat-source-viewer-sub', textContent: 'As the answer cited it' }), status);
2633
+ body.insertBefore(facts, status);
2634
+ status.textContent = member.model === 'same' ? 'The model is the same version as when the answer cited it.'
2635
+ : member.model === 'changed' ? 'The model has changed since this answer; the member is still in it. Its size or position may differ from what the answer described.'
2636
+ : member.model === 'no-model' ? 'This project has no steel model FloLess can show now, so the member cannot be shown in it.'
2637
+ : 'This member is no longer in the model.';
2638
+ if (member.model === 'gone' || member.model === 'no-model') return;
2639
+ const show = button(member.model === 'same' ? 'Show in the model' : 'Show current in the model', 'shell.chat-cite-show-member', 'ai-chat-source-viewer-knowledge');
2640
+ show.dataset.tip = 'Opens the project\'s model with this member selected and framed. Nothing changes';
2641
+ show.addEventListener('click', async () => {
2642
+ const unreachable = 'FloLess could not open the model from here. Open the project from Workspaces, then try again.';
2643
+ let said;
2644
+ try {
2645
+ const again = await fetch(citationUrl(row, 'member'), { credentials: 'same-origin', cache: 'no-store' });
2646
+ if (!again.ok) { status.textContent = await refused(again); return; }
2647
+ const now = (await again.json()).member;
2648
+ if (now.model === 'gone' || now.model === 'no-model') {
2649
+ status.textContent = now.model === 'gone' ? 'This member is no longer in the model.' : 'This project has no steel model FloLess can show now, so the member cannot be shown in it.';
2650
+ show.remove(); return;
2651
+ }
2652
+ finish();
2653
+ if (typeof window.flolessWorkspaces?.openConnection !== 'function') { announce(unreachable); return; }
2654
+ const outcome = await window.flolessWorkspaces.openConnection({ projectId: now.projectId, projectUuid: now.projectUuid, memberId: now.memberId });
2655
+ if (outcome?.superseded) return;
2656
+ const name = now.mark ? `member ${now.mark}` : `member ${now.memberId}`;
2657
+ said = !outcome ? unreachable : outcome.ok !== true ? (outcome.said || `The ${name} was not shown. Open the Model step, then press Show in the model again.`)
2658
+ : `Showing ${name} in the model.`;
2659
+ } catch (error) {
2660
+ if (error?.plain !== true) console.error('[chat] Show in the model failed', error);
2661
+ said = error?.plain === true && error.message ? error.message : unreachable;
2662
+ }
2663
+ if (said) announce(said);
2664
+ });
2665
+ dialog.append(show);
2666
+ }
2667
+
2451
2668
  function openChatAttachment(attachment) {
2452
2669
  return request(`/api/chat/conversations/${encodeURIComponent(state.chat.chatId)}/attachments/${encodeURIComponent(attachment.attachmentId)}/open`, {
2453
2670
  method: 'POST', body: JSON.stringify({ owner: state.scope.owner }),
@@ -3440,7 +3657,10 @@
3440
3657
  return false;
3441
3658
  }
3442
3659
 
3443
- /** Take a confirmed step FloLess's own window must take (#2290). Returns a plain failure sentence, or '' when it went. */
3660
+ /**
3661
+ * Take a confirmed step FloLess's own window must take (#2290). Returns a plain failure sentence, or '' when it went,
3662
+ * or { handedOver: sentence } when it went as far as it may and the last click is the person's (#2427).
3663
+ */
3444
3664
  async function runBrowserStep(step) {
3445
3665
  if (step?.flow === 'stop-app') {
3446
3666
  // The menu's own Stop FloLess: it asks about anything not saved, then closes FloLess and shows the stopped screen.
@@ -3471,13 +3691,13 @@
3471
3691
  // #2363: the project's own Source step presses its own Replace / Try again / Cancel control, so the real call
3472
3692
  // runs with this window's editor session. It answers a plain sentence when it could not, or when the person must act.
3473
3693
  if (typeof window.flolessWorkspaces?.modelSourceStep !== 'function') return 'FloLess could not open the project from here. Open it from Workspaces and use its Source step.';
3474
- try { return String((await window.flolessWorkspaces.modelSourceStep(step)) || ''); }
3694
+ try { return stepAnswer(await window.flolessWorkspaces.modelSourceStep(step)); }
3475
3695
  catch { return 'FloLess could not open the project’s Source step from here. Open it from Workspaces.'; }
3476
3696
  }
3477
3697
  if (step?.flow === 'knowledge-pick') {
3478
3698
  // #2399 slice 0b: the project's Knowledge step opens its own file picker; what the person picks there is added.
3479
3699
  if (typeof window.flolessWorkspaces?.knowledgePickStep !== 'function') return 'FloLess could not open the project from here. Open it from Workspaces and use its Knowledge step.';
3480
- try { return String((await window.flolessWorkspaces.knowledgePickStep(step)) || ''); }
3700
+ try { return stepAnswer(await window.flolessWorkspaces.knowledgePickStep(step)); }
3481
3701
  catch { return 'FloLess could not open the project’s Knowledge step from here. Open it from Workspaces.'; }
3482
3702
  }
3483
3703
  if (step?.flow === 'parser-setup') {
@@ -3492,16 +3712,25 @@
3492
3712
  }
3493
3713
  return 'FloLess did not recognise the step this card asked its window to take, so it did nothing. Try it from the screen instead.';
3494
3714
  }
3715
+ /** A step's own answer: a failure sentence, '' when it went, or a hand-over to the person with the sentence it showed. */
3716
+ function stepAnswer(said) {
3717
+ if (said && typeof said === 'object' && typeof said.handedOver === 'string' && said.handedOver) {
3718
+ return { handedOver: said.handedOver, ...(said.focus && typeof said.focus.focus === 'function' ? { focus: said.focus } : {}) };
3719
+ }
3720
+ return String(said || '');
3721
+ }
3495
3722
  /**
3496
3723
  * Tell FloLess how a step this window took for a confirmed card went: done, or not done with the sentence shown here.
3497
3724
  * Until it is told, the card stays running (a restart marks it "not known"), so a failed report only leaves it
3498
3725
  * honest, never "done". Returns the settled proposal, or null when the report did not land.
3499
3726
  */
3500
- async function reportBrowserStep(proposalId, failed) {
3727
+ async function reportBrowserStep(proposalId, outcome) {
3728
+ const handed = outcome && typeof outcome === 'object' && outcome.handedOver ? String(outcome.handedOver) : '';
3729
+ const failed = handed ? '' : outcome;
3501
3730
  try {
3502
3731
  const response = await fetch(`/api/actions/proposals/${encodeURIComponent(proposalId)}/step`, {
3503
3732
  method: 'POST', credentials: 'same-origin', headers: { 'content-type': 'application/json' },
3504
- body: JSON.stringify(failed ? { done: false, note: String(failed) } : { done: true }),
3733
+ body: JSON.stringify(handed ? { done: true, handedOver: true, note: handed } : failed ? { done: false, note: String(failed) } : { done: true }),
3505
3734
  });
3506
3735
  const body = await response.json().catch(() => null);
3507
3736
  return response.ok && body?.ok === true ? body.proposal || null : null;
@@ -3535,13 +3764,16 @@
3535
3764
  // #2290: a step only this window may take (its route checks the window's own origin) is taken here, now that the
3536
3765
  // person confirmed it: the same flow the menu or the Requests button runs.
3537
3766
  if (verb === 'confirm' && event.payload?.browserStep) {
3538
- const failed = await runBrowserStep(event.payload.browserStep);
3767
+ const outcome = await runBrowserStep(event.payload.browserStep);
3768
+ const failed = typeof outcome === 'string' ? outcome : '';
3539
3769
  if (failed) entry.error = failed;
3540
3770
  // The record says how the step went, so neither the card nor the AI calls it done when it was not. A Stop FloLess
3541
3771
  // that went ahead is settled by the server when it accepts the stop: this window's requests are already stopped.
3542
3772
  const stopped = event.payload.browserStep.flow === 'stop-app' && !failed;
3543
- const settled = stopped ? null : await reportBrowserStep(proposalId, failed);
3773
+ const settled = stopped ? null : await reportBrowserStep(proposalId, outcome);
3544
3774
  if (settled) entry.local = { state: settled.state || entry.local.state, result: settled.result || null, supersededBy: null };
3775
+ // #2427: the report did not land, so the card stays running: still show the person what to press.
3776
+ else if (outcome && typeof outcome === 'object' && outcome.handedOver) entry.error = String(outcome.handedOver);
3545
3777
  }
3546
3778
  } else if (body.fresh) {
3547
3779
  // The target changed or the offer ended: the old card says so, and a fresh card shows the current state.
@@ -3600,7 +3832,10 @@
3600
3832
  const eyebrow = document.createElement('span');
3601
3833
  eyebrow.className = 'guide-move-eyebrow';
3602
3834
  // A request that has been answered no longer "needs your OK": the eyebrow says where it ended up.
3603
- eyebrow.textContent = { executing: actionId === 'workflows.run' || actionId === 'routines.run' ? 'Running' : 'Working', done: 'Finished', failed: 'Could not finish', unknown: 'Outcome unknown' }[current.state] || ACTION_EYEBROWS[risk];
3835
+ // #2427: a step that left the last click to the person is theirs to finish, not a failure and not yet done.
3836
+ const handedOver = current.state === 'done' && current.result?.code === 'step-handed-over';
3837
+ eyebrow.textContent = handedOver ? 'Waiting for you'
3838
+ : { executing: actionId === 'workflows.run' || actionId === 'routines.run' ? 'Running' : 'Working', done: 'Finished', failed: 'Could not finish', unknown: 'Outcome unknown' }[current.state] || ACTION_EYEBROWS[risk];
3604
3839
  const strong = document.createElement('strong');
3605
3840
  strong.id = titleId;
3606
3841
  strong.textContent = title;
@@ -3608,7 +3843,7 @@
3608
3843
  named.className = 'ai-chat-action-named';
3609
3844
  named.append(eyebrow, strong);
3610
3845
  head.append(named);
3611
- const badgeText = { executing: 'Running', done: 'Done', failed: 'Not done', unknown: 'Unknown' }[current.state];
3846
+ const badgeText = handedOver ? 'Your turn' : { executing: 'Running', done: 'Done', failed: 'Not done', unknown: 'Unknown' }[current.state];
3612
3847
  if (badgeText) {
3613
3848
  const badge = document.createElement('span');
3614
3849
  badge.className = 'ai-chat-filter-state';
@@ -3626,11 +3861,33 @@
3626
3861
  summary.className = 'ai-chat-action-summary';
3627
3862
  summary.textContent = summaryText;
3628
3863
  card.append(summary);
3629
-
3864
+ // #2521 row 3a: what confirming agrees to (a Quick model read), whole and on its own line: the summary is cut to its
3865
+ // limit, terms never are.
3866
+ if (payload.terms) {
3867
+ const terms = document.createElement('p');
3868
+ terms.className = 'ai-chat-action-summary ai-chat-action-terms';
3869
+ // A real element, not CSS content, so a screen reader announces it with the terms.
3870
+ const label = document.createElement('strong');
3871
+ label.className = 'ai-chat-action-terms-label';
3872
+ label.textContent = 'What you agree to';
3873
+ terms.append(label, document.createTextNode(String(payload.terms)));
3874
+ card.append(terms);
3875
+ }
3876
+
3877
+ if (handedOver) {
3878
+ card.classList.add('is-handed-over');
3879
+ status.textContent = entry.error || String(current.result?.message || 'It is ready for you. Press it to finish.');
3880
+ card.append(status);
3881
+ return card;
3882
+ }
3630
3883
  if (current.state === 'done') {
3631
3884
  card.classList.add('is-done');
3632
3885
  // A step this window took after the confirm (#2290) can still fail here; that is said, never "Done." over it.
3633
- status.textContent = entry.error || (current.next ? 'Done. Its result is ready to view.' : String(payload.doneNote || 'Done.'));
3886
+ // #2521 row 3a: the route's own answer, when it changed what happened (a Quick read queued Precise), comes first,
3887
+ // and the card's edge turns amber so the person notices their choice was not what ran.
3888
+ const resultNote = typeof current.result?.note === 'string' && current.result.note ? current.result.note : '';
3889
+ if (resultNote) card.classList.add('is-fallback');
3890
+ status.textContent = entry.error || resultNote || (current.next ? 'Done. Its result is ready to view.' : String(payload.doneNote || 'Done.'));
3634
3891
  if (current.next) {
3635
3892
  // What the finished action made (a run's report): opening it only shows it, it runs nothing again.
3636
3893
  const actions = document.createElement('div');
@@ -3681,7 +3938,8 @@
3681
3938
  const actions = document.createElement('div');
3682
3939
  actions.className = 'ai-chat-filter-actions';
3683
3940
  if (current.state === 'executing') {
3684
- status.textContent = actionId === 'workflows.run' || actionId === 'routines.run' ? 'Running…' : 'Working…';
3941
+ // A window step whose report did not land stays running here; what the window said (what to press) still shows.
3942
+ status.textContent = entry.error || (actionId === 'workflows.run' || actionId === 'routines.run' ? 'Running…' : 'Working…');
3685
3943
  if (actionId === 'workflows.run') {
3686
3944
  const stop = actionButton('Stop', 'shell.chat-action-stop', proposalId, summaryText);
3687
3945
  stop.dataset.tip = 'Asks the run to stop. Work already sent to the host may remain.';
@@ -4109,12 +4367,11 @@
4109
4367
  if (finished) return;
4110
4368
  finished = true;
4111
4369
  if (dialog.open) dialog.close();
4112
- dialog.remove();
4370
+ hide();
4113
4371
  if (picture) URL.revokeObjectURL(picture);
4114
4372
  if (opener?.isConnected) opener.focus({ preventScroll: true });
4115
4373
  };
4116
4374
  close.addEventListener('click', finish);
4117
- dialog.addEventListener('keydown', (event) => { if (event.key === 'Escape') { event.preventDefault(); finish(); } });
4118
4375
  dialog.addEventListener('close', finish);
4119
4376
  head.append(Object.assign(document.createElement('strong'), { textContent: title }), close);
4120
4377
  const note = Object.assign(document.createElement('span'), { className: 'ai-chat-source-viewer-note', textContent: EVIDENCE_ORIGIN[place.origin].note(place) });
@@ -4143,8 +4400,7 @@
4143
4400
  show(false);
4144
4401
  body.append(status, frame);
4145
4402
  dialog.append(head, note, views, body);
4146
- document.body.append(dialog);
4147
- dialog.showModal();
4403
+ const hide = showChatViewer(dialog, finish);
4148
4404
  close.focus({ preventScroll: true });
4149
4405
  // A place that changed or is gone says so and offers the way on: the card asked for again, never sent for the person.
4150
4406
  const offerAgain = (why) => {
@@ -4558,6 +4814,9 @@
4558
4814
  case 'create-workflow':
4559
4815
  return { title: guideText?.title || `Build a workflow: ${move.name || ''}`, action: 'Build it', detail: move.purpose,
4560
4816
  note: 'Opens New workflow with its name filled in. Nothing is built until you confirm there.' };
4817
+ // An Open card only shows a page: there is no next step to confirm.
4818
+ case 'open':
4819
+ return guideText ? { ...guideText, note: 'This only opens the page. Nothing changes.' } : null;
4561
4820
  default:
4562
4821
  return guideText ? { ...guideText, note: 'Nothing happens until you confirm in the next step.' } : null;
4563
4822
  }
@@ -4814,7 +5073,8 @@
4814
5073
  use.dataset.tip = move.kind === 'follow-up' ? 'Puts this message in the message box. Nothing is sent.'
4815
5074
  : move.kind === 'action' && move.risk === 'read' ? 'Shows the result here. Nothing changes.'
4816
5075
  : move.kind === 'action' && move.risk !== 'human-only' ? 'Opens a request below for your OK. Nothing runs from this card.'
4817
- : 'Opens the place to do this. Nothing happens until you confirm there.';
5076
+ : move.kind === 'open' ? `${text.action}. Nothing changes.`
5077
+ : 'Opens the place to do this. Nothing happens until you confirm there.';
4818
5078
  if (entry.busy === 'use') use.setAttribute('aria-busy', 'true');
4819
5079
  use.addEventListener('click', () => { void useAssistantCard(entry, text); });
4820
5080
  for (const control of [later, never, use]) control.disabled = Boolean(entry.busy);
@@ -7168,7 +7428,9 @@
7168
7428
  };
7169
7429
  const flushLinks = () => { if (links.length) { ui.feed.append(...receiptFold(links)); links = []; } };
7170
7430
  for (const event of state.events) {
7171
- if (links.length && event.turnId !== links[0].turnId) { flushAssistant(); flushLinks(); }
7431
+ // A follow-up can share its provider turn with the preceding answer. Its question still
7432
+ // starts a new visible answer group, after that answer's text and held receipts (#2505).
7433
+ if (event.type === 'user-message' || (links.length && event.turnId !== links[0].turnId)) { flushAssistant(); flushLinks(); }
7172
7434
  if (event.type === 'assistant-message' && event.payload?.delta) {
7173
7435
  // Codex keeps a stable item id while Claude's SDK may assign one per stream packet.
7174
7436
  // Same-turn deltas stay in one visible answer. Tools separate progress paragraphs;
@@ -9761,11 +10023,19 @@
9761
10023
 
9762
10024
  // The units question of a workspace conversation (#1890): asked until the person answers, then a quiet line to change
9763
10025
  // it. Never blocks Send — an unanswered question tells the AI the units are not chosen yet, and it asks.
10026
+ // The units menu's open state and its outside-click listener belong to the chip they were made for: a repaint that
10027
+ // replaces the chip drops both, so a menu never comes back open without a way to close it.
10028
+ function dropUnitsMenu() {
10029
+ if (state.workspaceUnitsMenuAway) document.removeEventListener('pointerdown', state.workspaceUnitsMenuAway, true);
10030
+ state.workspaceUnitsMenuAway = null;
10031
+ state.workspaceUnitsMenuOpen = false;
10032
+ }
10033
+
9764
10034
  function paintWorkspaceUnits() {
9765
10035
  const host = ui.workspaceUnits;
9766
10036
  if (!host) return;
9767
10037
  const chat = state.chat;
9768
- if (state.scope?.owner?.kind !== 'workspace' || !chat || chat.archivedAt) { host.hidden = true; host.replaceChildren(); delete host.dataset.painted; return; }
10038
+ if (state.scope?.owner?.kind !== 'workspace' || !chat || chat.archivedAt) { dropUnitsMenu(); host.hidden = true; host.replaceChildren(); delete host.dataset.painted; return; }
9769
10039
  // The receipts' units follow the conversation's own (chosen, else suggested) — set here, where the chat is known.
9770
10040
  state.displayUnits = workspaceUnitsOf(chat);
9771
10041
  const units = chat.workspaceUnits || {};
@@ -9776,23 +10046,77 @@
9776
10046
  if (host.dataset.painted === painted) return;
9777
10047
  host.dataset.painted = painted;
9778
10048
  host.hidden = false;
10049
+ dropUnitsMenu();
9779
10050
  host.replaceChildren();
9780
10051
  if (chosen && !state.workspaceUnitsEditing) {
9781
- const text = document.createElement('span');
9782
- text.className = 'ai-chat-units-current';
9783
- text.textContent = `Units: ${label(chosen)}`;
9784
- const change = document.createElement('button');
9785
- change.type = 'button';
9786
- change.className = 'ai-chat-units-change';
9787
- change.textContent = 'Change';
9788
- change.setAttribute('aria-label', 'Change units');
9789
- change.dataset.commandId = 'shell.chat-units-change';
9790
- change.dataset.tip = 'Choose the units AI answers in, in this conversation';
9791
- change.addEventListener('click', () => { state.workspaceUnitsEditing = true; paintWorkspaceUnits();
9792
- const entry = state.workspaceUnitsQuestions?.get(chat.chatId);
9793
- if (entry?.slotNode?.isConnected) window.FlolessQuestionCard.focusCursor(entry.slotNode);
10052
+ // A toolbar chip ("ft-in ⌄"), whose two-item menu changes the units in place.
10053
+ const chip = document.createElement('button');
10054
+ chip.type = 'button';
10055
+ chip.className = 'ai-chat-units-chip ai-chat-units-change';
10056
+ chip.setAttribute('aria-label', `Units: ${label(chosen)}. Change units`);
10057
+ chip.setAttribute('aria-haspopup', 'menu');
10058
+ chip.setAttribute('aria-expanded', String(Boolean(state.workspaceUnitsMenuOpen)));
10059
+ chip.setAttribute('aria-controls', 'chat-units-menu');
10060
+ chip.dataset.commandId = 'shell.chat-units-change';
10061
+ chip.dataset.tip = `Units: ${label(chosen)}. Choose the units AI answers in, in this conversation`;
10062
+ chip.insertAdjacentHTML('afterbegin', '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z"/><path d="m14.5 12.5 2-2"/><path d="m11.5 9.5 2-2"/><path d="m8.5 6.5 2-2"/><path d="m17.5 15.5 2-2"/></svg>');
10063
+ const value = document.createElement('span');
10064
+ value.textContent = chosen === 'mm' ? 'mm' : 'ft-in';
10065
+ const chevron = document.createElement('span');
10066
+ chevron.className = 'ai-chat-access-chevron';
10067
+ chevron.setAttribute('aria-hidden', 'true');
10068
+ chevron.textContent = '⌄';
10069
+ chip.append(value, chevron);
10070
+ const menu = document.createElement('div');
10071
+ menu.className = 'ai-chat-units-menu';
10072
+ menu.id = 'chat-units-menu';
10073
+ menu.setAttribute('role', 'menu');
10074
+ menu.setAttribute('aria-label', 'Units');
10075
+ menu.hidden = !state.workspaceUnitsMenuOpen;
10076
+ const closeMenu = (focusChip) => {
10077
+ dropUnitsMenu();
10078
+ menu.hidden = true;
10079
+ chip.setAttribute('aria-expanded', 'false');
10080
+ if (focusChip) chip.focus();
10081
+ };
10082
+ for (const option of ['ft-in', 'mm']) {
10083
+ const item = document.createElement('button');
10084
+ item.type = 'button';
10085
+ item.setAttribute('role', 'menuitemradio');
10086
+ item.setAttribute('aria-checked', String(option === chosen));
10087
+ item.dataset.commandId = `shell.chat-units-choose#${option}`;
10088
+ item.dataset.commandInstanceLabel = option === 'mm' ? 'metric (mm)' : 'feet and inches';
10089
+ item.textContent = option === 'mm' ? 'Metric (mm)' : 'Feet and inches (ft-in)';
10090
+ item.addEventListener('click', () => { closeMenu(false); if (option !== chosen) void chooseWorkspaceUnits(option); else chip.focus(); });
10091
+ menu.append(item);
10092
+ }
10093
+ // Escape closes it from the chip or the menu; focus leaving both (Tab away) closes it too.
10094
+ chip.addEventListener('keydown', (event) => {
10095
+ if (event.key === 'Escape' && state.workspaceUnitsMenuOpen) { event.preventDefault(); closeMenu(true); }
10096
+ });
10097
+ // On the chip and menu (rebuilt each paint), never the long-lived host, so listeners never pile up.
10098
+ const leave = (event) => { if (state.workspaceUnitsMenuOpen && !chip.contains(event.relatedTarget) && !menu.contains(event.relatedTarget)) closeMenu(false); };
10099
+ chip.addEventListener('focusout', leave);
10100
+ menu.addEventListener('focusout', leave);
10101
+ menu.addEventListener('keydown', (event) => {
10102
+ const items = [...menu.querySelectorAll('button')];
10103
+ const at = items.indexOf(document.activeElement);
10104
+ if (event.key === 'Escape') { event.preventDefault(); closeMenu(true); }
10105
+ else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
10106
+ event.preventDefault();
10107
+ items[(at + (event.key === 'ArrowDown' ? 1 : items.length - 1)) % items.length]?.focus();
10108
+ }
10109
+ });
10110
+ chip.addEventListener('click', () => {
10111
+ if (state.workspaceUnitsMenuOpen) { closeMenu(false); return; }
10112
+ state.workspaceUnitsMenuOpen = true;
10113
+ menu.hidden = false;
10114
+ chip.setAttribute('aria-expanded', 'true');
10115
+ state.workspaceUnitsMenuAway = (event) => { if (!host.contains(event.target)) closeMenu(false); };
10116
+ document.addEventListener('pointerdown', state.workspaceUnitsMenuAway, true);
10117
+ (menu.querySelector('[aria-checked="true"]') || menu.querySelector('button'))?.focus();
9794
10118
  });
9795
- host.append(text, change);
10119
+ host.append(chip, menu);
9796
10120
  return;
9797
10121
  }
9798
10122
  host.hidden = true;
@@ -12707,8 +13031,17 @@
12707
13031
  }
12708
13032
  const count = Array.isArray(chat.scopeExtensions) ? chat.scopeExtensions.length : 0;
12709
13033
  const home = state.scopeView?.scope?.home?.label || state.scope?.label || 'Home';
12710
- ui.scopeToggle.textContent = `Scope · ${home}${count ? ` + ${count}` : ''}`;
12711
- ui.scopeToggle.dataset.tip = 'See the conversation’s home folder and add or remove other projects and workflows.';
13034
+ // A toolbar chip: a folder icon and the home (+ how many added); the word "Scope" is in its name and tooltip.
13035
+ const scopeText = `${home}${count ? ` + ${count}` : ''}`;
13036
+ const scopeLabel = ui.scopeToggle.querySelector('span') || document.createElement('span');
13037
+ if (!scopeLabel.isConnected) {
13038
+ ui.scopeToggle.replaceChildren();
13039
+ ui.scopeToggle.insertAdjacentHTML('afterbegin', '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/></svg>');
13040
+ ui.scopeToggle.append(scopeLabel);
13041
+ }
13042
+ scopeLabel.textContent = scopeText;
13043
+ ui.scopeToggle.setAttribute('aria-label', `Scope: ${scopeText}`);
13044
+ ui.scopeToggle.dataset.tip = `Scope: ${scopeText}. See the conversation’s home folder and add or remove other projects and workflows.`;
12712
13045
  ui.scopeToggle.disabled = state.loading;
12713
13046
  if (ui.scopeToggle.disabled) ui.scopeToggle.dataset.blockedReason = 'The conversation is still loading.';
12714
13047
  else delete ui.scopeToggle.dataset.blockedReason;
@@ -13406,10 +13739,14 @@
13406
13739
  ui.input.focus();
13407
13740
  }
13408
13741
 
13742
+ // An intake creates the project and saves its drawings before the first turn's own capability check and locks, so it
13743
+ // needs longer than REQUEST_START_TIMEOUT_MS; a retry with the same submission id never makes a second project.
13744
+ const PROJECT_INTAKE_TIMEOUT_MS = 120000;
13409
13745
  async function startProjectIntake(submissionId, payload) {
13410
13746
  await ensureSession();
13747
+ // A shorter wait read "could not create" about a project that was made, on a busy computer (#2470 R6.4 E2E).
13411
13748
  return request(`/api/chat/project-intakes/${encodeURIComponent(submissionId)}/start`, {
13412
- method: 'POST', body: JSON.stringify(payload),
13749
+ method: 'POST', timeoutMs: PROJECT_INTAKE_TIMEOUT_MS, body: JSON.stringify(payload),
13413
13750
  });
13414
13751
  }
13415
13752
 
@@ -13438,7 +13775,7 @@
13438
13775
  async function resumeProjectIntake(submissionId) {
13439
13776
  await ensureSession();
13440
13777
  return request(`/api/chat/project-intakes/${encodeURIComponent(submissionId)}/resume`, {
13441
- method: 'POST', body: '{}',
13778
+ method: 'POST', timeoutMs: PROJECT_INTAKE_TIMEOUT_MS, body: '{}',
13442
13779
  });
13443
13780
  }
13444
13781