@floless/app 0.174.1 → 0.175.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 (85) hide show
  1. package/autostart.mjs +117 -10
  2. package/dist/floless-server.cjs +2 -2
  3. package/dist/pdf-engine/floless_pdf/__init__.py +7 -3
  4. package/dist/pdf-engine/floless_pdf/backend_pdfium.py +292 -13
  5. package/dist/pdf-engine/floless_pdf/backend_pymupdf.py +25 -3
  6. package/dist/pdf-engine/floless_pdf/images.py +4 -3
  7. package/dist/pdf-engine/floless_pdf/pages.py +136 -0
  8. package/dist/schemas/steel.model.v2.schema.json +44 -1
  9. package/dist/skills/floless-app-approval/SKILL.md +28 -3
  10. package/dist/skills/floless-app-knowledge/SKILL.md +3 -2
  11. package/dist/skills/floless-app-sketches/SKILL.md +71 -0
  12. package/dist/skills/floless-app-sketches/references/steel-plate.md +15 -0
  13. package/dist/skills/floless-app-steel-model/SKILL.md +11 -1
  14. package/dist/skills/floless-app-steel-model/references/elements.md +90 -23
  15. package/dist/skills/floless-app-steel-takeoff/SKILL.md +11 -6
  16. package/dist/web/agents.js +1 -1
  17. package/dist/web/app.css +120 -15
  18. package/dist/web/app.js +89 -38
  19. package/dist/web/aware-hold.js +10 -0
  20. package/dist/web/aware.js +405 -51
  21. package/dist/web/boot-watchdog.js +249 -0
  22. package/dist/web/card-details.js +88 -0
  23. package/dist/web/chat.css +29 -0
  24. package/dist/web/chat.js +430 -128
  25. package/dist/web/commands-connection-design.js +23 -0
  26. package/dist/web/commands-revit.js +3 -0
  27. package/dist/web/commands-shell.js +226 -10
  28. package/dist/web/commands-steel.js +93 -4
  29. package/dist/web/commands-tekla-parser.js +21 -1
  30. package/dist/web/connection-design-editor.html +71 -0
  31. package/dist/web/connection-design-editor.js +794 -61
  32. package/dist/web/connection-design-handles.js +9 -3
  33. package/dist/web/element-approval.js +74 -0
  34. package/dist/web/element-context.js +76 -6
  35. package/dist/web/element-geometry.js +8 -2
  36. package/dist/web/element-holds.js +68 -5
  37. package/dist/web/element-type-actions.js +22 -3
  38. package/dist/web/element-types.js +12 -5
  39. package/dist/web/element-words.js +15 -11
  40. package/dist/web/grid-place.js +51 -0
  41. package/dist/web/guide.js +2 -0
  42. package/dist/web/index.html +13 -16
  43. package/dist/web/instructor.js +5 -2
  44. package/dist/web/missed-routines.js +6 -1
  45. package/dist/web/model-change-findings.js +100 -30
  46. package/dist/web/model-change-review.js +411 -27
  47. package/dist/web/model-clash-check.css +100 -0
  48. package/dist/web/model-clash-check.js +681 -0
  49. package/dist/web/model-clip-box.js +204 -0
  50. package/dist/web/model-clip-list.js +153 -3
  51. package/dist/web/model-clip-session.js +3 -3
  52. package/dist/web/model-clip-three-overlay.js +135 -25
  53. package/dist/web/model-editor.css +2 -0
  54. package/dist/web/model-elements.js +273 -18
  55. package/dist/web/model-fit-checks.js +354 -0
  56. package/dist/web/model-spatial-panel.js +9 -3
  57. package/dist/web/model-spatial-tools.js +12 -3
  58. package/dist/web/model-tekla-selection.js +74 -0
  59. package/dist/web/model-view-query.js +70 -14
  60. package/dist/web/model-viewport-revit-adapter.js +8 -7
  61. package/dist/web/model-viewport-toolbar.js +8 -4
  62. package/dist/web/pages.js +78 -1
  63. package/dist/web/project-history.js +31 -1
  64. package/dist/web/revit-editor.css +34 -1
  65. package/dist/web/revit-editor.js +174 -55
  66. package/dist/web/run-history.js +8 -0
  67. package/dist/web/sketch-editor.js +141 -2
  68. package/dist/web/sketches.js +192 -6
  69. package/dist/web/start-place.js +46 -0
  70. package/dist/web/steel-3d-core.js +70 -0
  71. package/dist/web/steel-3d-view.js +288 -47
  72. package/dist/web/steel-change-review.css +28 -0
  73. package/dist/web/steel-custom-connection.js +6 -0
  74. package/dist/web/steel-editor.html +532 -33
  75. package/dist/web/steel-filter.html +8 -3
  76. package/dist/web/steel-model-checks.css +76 -0
  77. package/dist/web/steel-model-v2-commands.js +17 -0
  78. package/dist/web/steel-view-generation.js +6 -2
  79. package/dist/web/teams.js +259 -19
  80. package/dist/web/tekla-editor.html +1 -0
  81. package/dist/web/terminal-requests.js +6 -0
  82. package/dist/web/vendor/connection-engine.js +886 -91
  83. package/dist/web/workspaces.js +630 -48
  84. package/package.json +2 -1
  85. package/preferences-file.mjs +27 -0
@@ -237,6 +237,10 @@ export function mountSketchEditor(ctx) {
237
237
  const locks = ctx.locks === undefined ? (globalThis.navigator?.locks ?? null) : ctx.locks;
238
238
  const history = createHistoryCoordinator({ onChange: () => changed(), onPush: (entry) => ctx.onHistoryPush?.(entry) });
239
239
  const docs = new Map(); // id → the last read: { id, name, rev, sha, sketch, versions, read }
240
+ // S1c (#3643, plan §7.5): each sketch's conversion states, as the server worked them out on its last read. A shape
241
+ // whose plate is in the model unchanged is hidden in the 3D view unless the person turned on Show converted.
242
+ const conversions = new Map(); // id → { readable, entities: { [entityId]: { state, hidden, ... } }, history } | null
243
+ let reattach = null; // Re-attach to another face: { id, rev, name } while the face pick is armed for it
240
244
  let list = []; // the server's summaries
241
245
  let viewState = { rev: 0, hidden: [], hiddenEntities: {}, showConverted: false, seen: {} };
242
246
  let generation = null;
@@ -275,6 +279,23 @@ export function mountSketchEditor(ctx) {
275
279
  /** The create new drawing joins: none once a plane change left it behind (its sketch stays on its own plane). */
276
280
  const liveCreate = () => (creating && ownsDrawing(creating.token, creating.plane) ? creating : null);
277
281
  function working(id) { const h = holders.get(id); return h ? h.sync.working : docs.get(id)?.sketch ?? null; }
282
+ /** Key-sorted JSON: the same shape reads the same however its object was built. */
283
+ function canonical(v) {
284
+ if (Array.isArray(v)) return `[${v.map(canonical).join(',')}]`;
285
+ if (v && typeof v === 'object') return `{${Object.keys(v).sort().map((k) => `${JSON.stringify(k)}:${canonical(v[k])}`).join(',')}}`;
286
+ return JSON.stringify(v ?? null);
287
+ }
288
+ /** A sketch's conversion states, with the plane and shapes they were read against (S1c Codex review). */
289
+ function setConversions(id, conv, doc) {
290
+ if (!conv) { conversions.set(id, null); return; }
291
+ const seen = { plane: canonical(doc?.plane ?? null), entities: Object.fromEntries((doc?.entities ?? []).map((e) => [e.id, canonical(e)])) };
292
+ conversions.set(id, { ...conv, seen });
293
+ }
294
+ /** Hide a converted shape only while it, and its plane, are exactly as they were when its state was read. */
295
+ function stillAsConverted(conv, doc, e) {
296
+ const seen = conv?.seen;
297
+ return !!seen && seen.plane === canonical(doc.plane) && seen.entities[e.id] === canonical(e);
298
+ }
278
299
  function revOf(id) { const h = holders.get(id); return h ? h.sync.state().baseRev : docs.get(id)?.rev ?? 0; }
279
300
 
280
301
  // ── the ownership queue (§4.2) ──
@@ -296,6 +317,14 @@ export function mountSketchEditor(ctx) {
296
317
  const doc = working(summary.id);
297
318
  if (!doc) continue;
298
319
  const hideShapes = new Set(viewState.hiddenEntities[summary.id] ?? []);
320
+ if (!viewState.showConverted) {
321
+ const conv = conversions.get(summary.id);
322
+ const byId = new Map(doc.entities.map((e) => [e.id, e]));
323
+ for (const [entityId, c] of Object.entries(conv?.entities ?? {})) {
324
+ const e = byId.get(entityId);
325
+ if (c.hidden && e && stillAsConverted(conv, doc, e)) hideShapes.add(entityId);
326
+ }
327
+ }
299
328
  // `editable`: only the open sketch, while editing is not paused, shows handles to drag.
300
329
  const editable = summary.id === activeId && !holders.get(summary.id)?.sync.choosing;
301
330
  out.push({ id: summary.id, plane: doc.plane, entities: doc.entities.filter((e) => !hideShapes.has(e.id)), selected: [...(selection.get(summary.id) ?? [])], editable });
@@ -307,9 +336,31 @@ export function mountSketchEditor(ctx) {
307
336
  const r = await fetchJson('GET', `${base}/sketches/${encodeURIComponent(id)}`);
308
337
  if (r.status !== 200) { const e = new Error(READ_FAILED_TEXT); e.status = r.status; throw e; }
309
338
  docs.set(id, { id, name: r.json.sketch.name, rev: r.json.rev, sha: r.json.sha, sketch: r.json.sketch, versions: r.json.versions, read: r.json });
339
+ setConversions(id, r.json.conversions ?? null, r.json.sketch);
310
340
  return r.json;
311
341
  }
312
342
 
343
+ /** Read one sketch's conversion states again (a conversion landed, or the model changed), leaving its document alone. */
344
+ async function refreshConversions(id) {
345
+ const r = await fetchJson('GET', `${base}/sketches/${encodeURIComponent(id)}`).catch(() => null);
346
+ if (r?.status === 200) { setConversions(id, r.json.conversions ?? null, r.json.sketch); return; }
347
+ // Unread: nothing is hidden on a state FloLess could not check just now (a shown shape is never wrongly gone).
348
+ const prev = conversions.get(id);
349
+ if (prev) conversions.set(id, { ...prev, seen: null });
350
+ }
351
+ let modelChangedTimer = null;
352
+ /** The model changed: the sketches that have conversions are asked again, once the burst of changes has settled. */
353
+ function onModelChanged() {
354
+ modelChangedTimer?.();
355
+ modelChangedTimer = schedule(async () => {
356
+ modelChangedTimer = null;
357
+ const ids = list.filter((x) => !x.damaged && ((x.conversions ?? 0) > 0 || conversions.get(x.id))).map((x) => x.id);
358
+ if (!ids.length) return;
359
+ await Promise.all(ids.map((id) => refreshConversions(id)));
360
+ paint(); changed();
361
+ }, 300);
362
+ }
363
+
313
364
  /** Read the list, the view and every sketch, then scan for drafts. Runs inside a queued job; never enqueues. */
314
365
  async function loadNow() {
315
366
  try {
@@ -535,6 +586,13 @@ export function mountSketchEditor(ctx) {
535
586
  }
536
587
 
537
588
  function planeChanged({ cornerDropped = false } = {}) {
589
+ if (reattach) {
590
+ // Only a picked member face answers an armed Re-attach. Any other plane (another ◇ Plane option, a cleared plane)
591
+ // means the person moved on: the pick is cancelled, nothing is written, and the change is handled as usual.
592
+ const picked = ctx.view()?.sketchWorkPlane?.() ?? null;
593
+ if (picked?.ref?.kind === 'face') { void reattachTo(picked); return; }
594
+ cancelReattach();
595
+ }
538
596
  if (!on) return;
539
597
  ++planeToken;
540
598
  const v = ctx.view();
@@ -1427,7 +1485,7 @@ export function mountSketchEditor(ctx) {
1427
1485
  on = next;
1428
1486
  step = null;
1429
1487
  // Leaving the mode clears the axis lock and its last point (S2b §3.2); a pause (setSketchTool(null)) never does.
1430
- if (!on) { syncTool(); ctx.view()?.setSketchLock?.('reset'); await closeNow(); }
1488
+ if (!on) { cancelReattach(); syncTool(); ctx.view()?.setSketchLock?.('reset'); await closeNow(); }
1431
1489
  // Turning the mode on starts with no lock, whatever a view kept from before (S2b §3.2).
1432
1490
  else { if (!loaded) { await loadNow(); } ctx.view()?.setSketchLock?.('reset'); syncTool(); }
1433
1491
  paint(); changed();
@@ -1435,6 +1493,7 @@ export function mountSketchEditor(ctx) {
1435
1493
 
1436
1494
  function setTool(next) {
1437
1495
  const want = isSketchTool(next) ? next : 'rect';
1496
+ if (want !== tool) cancelReattach();
1438
1497
  if (want !== tool) {
1439
1498
  // A polyline of 2 or more points is kept as drawn (its finish arrives through onSketchShape first); a lone first
1440
1499
  // point is removed, and the chip says so.
@@ -1538,6 +1597,7 @@ export function mountSketchEditor(ctx) {
1538
1597
  const h = holders.get(event.id);
1539
1598
  if (h) {
1540
1599
  if (event.rev !== undefined) h.sync.observe(event);
1600
+ if (event.conversion) await refreshConversions(event.id);
1541
1601
  syncDoc(event.id); paint(); changed();
1542
1602
  return;
1543
1603
  }
@@ -1551,6 +1611,67 @@ export function mountSketchEditor(ctx) {
1551
1611
  paint(); changed();
1552
1612
  }
1553
1613
 
1614
+ /**
1615
+ * Re-attach to another face (S1c plan §3): Sketch mode on, the ◇ Plane menu's Pick face armed, and the next face the
1616
+ * person picks re-attaches this sketch to it, saved as its own version. Esc cancels with nothing written.
1617
+ */
1618
+ async function reattachFace(id, rev) {
1619
+ const name = list.find((x) => x.id === id)?.name ?? docs.get(id)?.name ?? 'the sketch';
1620
+ await enqueue(() => setModeNow(true));
1621
+ reattach = { id, rev, name };
1622
+ if (!ctx.pickFace?.()) { reattach = null; ctx.toast('The face pick is not available here. Open the model in 3D and try again.'); return false; }
1623
+ ctx.toast(`Pick the face to attach “${name}” to. Esc cancels.`);
1624
+ changed();
1625
+ return true;
1626
+ }
1627
+ /** An armed Re-attach that the person left another way (Sketch mode off, another tool or plane): nothing is written. */
1628
+ function cancelReattach() {
1629
+ if (!reattach) return;
1630
+ const r = reattach;
1631
+ reattach = null;
1632
+ ctx.toast(`Re-attaching “${r.name}” was cancelled. Nothing was changed.`);
1633
+ changed();
1634
+ }
1635
+ async function reattachTo(plane) {
1636
+ const r = reattach;
1637
+ reattach = null;
1638
+ if (!plane || plane.ref?.kind !== 'face') { ctx.toast(`That is not a member face, so “${r.name}” was not re-attached. Choose Re-attach again and pick a face.`); changed(); return; }
1639
+ const res = await fetchJson('POST', `${base}/sketches/${encodeURIComponent(r.id)}/reattach`, { body: { choice: 'face', plane }, ifMatch: String(r.rev) }).catch(() => null);
1640
+ if (res?.status === 200) ctx.toast(`“${r.name}” is attached to the face you picked. The earlier placement is kept as a version.`);
1641
+ else if (res?.status === 412) ctx.toast(`“${r.name}” changed meanwhile, so it was not re-attached. Open Sketches and choose again.`);
1642
+ else ctx.toast(res?.json?.error ?? `FloLess could not re-attach “${r.name}” just now. Try again in a moment.`);
1643
+ await onEvent({ projectId: ctx.projectId, id: r.id });
1644
+ }
1645
+
1646
+ /**
1647
+ * Convert with AI (S1c plan §8): like Ask AI, but the sketch AND the model are saved first, so the AI converts what is
1648
+ * on screen. Returns what saved; `go(anyway)` then fills the chat box and publishes the shapes. It never sends.
1649
+ */
1650
+ async function prepareConvert(id, entityIds = null) {
1651
+ const h = holders.get(id);
1652
+ const sketch = h ? await h.sync.flush() : null;
1653
+ // The snapshot the sketch save answered for, taken before anything else is awaited: an edit made while the model
1654
+ // saves is not in it, so what is published always matches what `sketchSaved` describes (Codex review).
1655
+ const doc = (() => { const d = working(id) ?? docs.get(id)?.sketch ?? null; return d ? JSON.parse(JSON.stringify(d)) : null; })();
1656
+ const rev = revOf(id);
1657
+ const ackSha = h?.sync.state().ackSha;
1658
+ const known = h && ackSha ? h.sync.snapshot().known[ackSha] : null;
1659
+ const model = ctx.flushModel ? await ctx.flushModel() : { ok: true };
1660
+ const sketchSaved = !sketch || sketch.outcome === 'saved';
1661
+ const go = () => {
1662
+ if (!doc) return false;
1663
+ const acked = known ? JSON.parse(known) : docs.get(id)?.sketch ?? null;
1664
+ const ackedIds = new Set((acked?.entities ?? []).map((e) => e.id));
1665
+ const want = entityIds ? new Set(entityIds) : null;
1666
+ const items = doc.entities.filter((e) => (want ? want.has(e.id) : e.kind !== 'text'))
1667
+ .map((e) => ({ kind: 'sketch', id: `${id}@${rev}/${e.id}`, label: `${subjectShape(e)} · ${doc.name}`, ...(!sketchSaved && !ackedIds.has(e.id) ? { unsaved: true } : {}) }));
1668
+ ctx.publishSelection?.(items);
1669
+ const unsavedNote = sketchSaved && model.ok ? '' : ` (${!sketchSaved ? 'the sketch' : 'the model'} was not saved, so the AI sees the copy saved last)`;
1670
+ return !!ctx.askChat?.(`Convert “${doc.name}” into a plate${unsavedNote}: `);
1671
+ };
1672
+ return { sketchSaved, modelSaved: !!model.ok, name: doc?.name ?? '', go };
1673
+ }
1674
+
1554
1675
  function subjectItems() {
1555
1676
  const sketches = list.filter((s) => !s.damaged).map((s) => ({ id: s.id, name: s.name, rev: revOf(s.id), entities: working(s.id)?.entities ?? [] }));
1556
1677
  return sketchSubjectItems(sketches, selection);
@@ -1614,6 +1735,15 @@ export function mountSketchEditor(ctx) {
1614
1735
  keepMine,
1615
1736
  onEvent,
1616
1737
  onViewChanged,
1738
+ onModelChanged,
1739
+ reattachFace,
1740
+ prepareConvert,
1741
+ /** The conversion states of one sketch, as last read (the Sketches dialog and Inspect read them). */
1742
+ conversionsOf: (id) => conversions.get(id) ?? null,
1743
+ /** A sketch's name; null once the list is read and the sketch is not in it (deleted), undefined before that. */
1744
+ sketchName: (id) => { const x = list.find((s) => s.id === id); return x ? (x.name ?? '') : loaded ? null : undefined; },
1745
+ /** Select the connection a conversion built (the Sketches dialog's Show in model on a Conversions row). */
1746
+ showObject: (jointId) => !!ctx.view()?.selectWholeConn?.(jointId),
1617
1747
  subjectItems,
1618
1748
  ask,
1619
1749
  cardAction,
@@ -1677,7 +1807,16 @@ export function mountSketchEditor(ctx) {
1677
1807
  /** The Text tool's input answered (Enter): the note goes in at the point clicked, sized by the view. */
1678
1808
  commitText(text) { return !!ctx.view()?.commitSketchText?.(text); },
1679
1809
  /** Esc, Enter or Backspace for the 3D view first (S2a §3.6): whether it answered (a plane pick, a note input, the shape in progress, a drag). */
1680
- viewKey(key) { return !!ctx.view()?.sketchKey?.(key); },
1810
+ viewKey(key) {
1811
+ if (key === 'Escape' && reattach) {
1812
+ const r = reattach;
1813
+ reattach = null;
1814
+ ctx.view()?.sketchKey?.(key);
1815
+ ctx.toast(`Re-attaching “${r.name}” was cancelled. Nothing was changed.`);
1816
+ return true;
1817
+ }
1818
+ return !!ctx.view()?.sketchKey?.(key);
1819
+ },
1681
1820
  /** S2b: an axis-lock key ('x' | 'y' | 'f' | 'z') for the 3D view's sketch lock. Whether a view took it. */
1682
1821
  setLock(key) { const v = ctx.view(); if (!v?.setSketchLock) return false; v.setSketchLock(key); changed(); return true; },
1683
1822
  /** S2b: Shift went down or up, so ortho is on while it is held. */
@@ -12,6 +12,7 @@
12
12
  const statusEl = document.getElementById('sketches-status');
13
13
  const subEl = document.getElementById('sketches-sub');
14
14
  const closeBtn = document.getElementById('sketches-close');
15
+ const convertedEl = document.getElementById('sketches-converted');
15
16
  const Session = window.flolessSketchesSession;
16
17
  const sessions = Session.createSessions();
17
18
  const emptyView = () => ({ rev: 0, hidden: [], hiddenEntities: {}, showConverted: false, seen: {} });
@@ -256,6 +257,30 @@
256
257
  if (!s.damaged) row.append(onSwitch(s));
257
258
  listEl.append(row);
258
259
  }
260
+ paintConvertedSwitch();
261
+ }
262
+
263
+ /** S1c (#3643, plan §8): Show converted shapes. Only where it means something: some sketch here was converted. */
264
+ function paintConvertedSwitch() {
265
+ if (!convertedEl) return;
266
+ const any = sketches.some((x) => !x.damaged && (x.conversions ?? 0) > 0);
267
+ convertedEl.hidden = !any && !view.showConverted;
268
+ convertedEl.replaceChildren();
269
+ if (convertedEl.hidden) return;
270
+ const on = !!view.showConverted;
271
+ const sw = button('', 'shell.sketches-show-converted', { className: 'sketches-switch', tip: 'Converted shapes are hidden in the 3D view once their plate is in the model. Turn this on to see them again. Only your view changes.' });
272
+ sw.setAttribute('role', 'switch');
273
+ sw.setAttribute('aria-checked', String(on));
274
+ sw.setAttribute('aria-labelledby', 'sketches-converted-label');
275
+ sw.append(make('span', 'sketches-knob'));
276
+ sw.addEventListener('click', () => {
277
+ if (isBusy() || !session) return;
278
+ const token = session;
279
+ void writer.write(token, (v) => ({ ...v, showConverted: !on }), { keep: true }).then((ok) => { if (ok && sessions.live(token)) { paintConvertedSwitch(); paintDetail(); } });
280
+ });
281
+ const label = make('span', 'sketches-converted-label', 'Show converted shapes');
282
+ label.id = 'sketches-converted-label';
283
+ convertedEl.append(label, waitsWhileBusy(sw));
259
284
  }
260
285
 
261
286
  function onSwitch(s) {
@@ -312,7 +337,7 @@
312
337
  button('Try again', 'shell.sketches-retry', { onClick: () => { void refresh(); } }));
313
338
  return;
314
339
  }
315
- current = { id, rev: data.rev, sketch: data.sketch, versions: data.versions || [], latest: data.latest, reference: data.reference };
340
+ current = { id, rev: data.rev, sketch: data.sketch, versions: data.versions || [], latest: data.latest, reference: data.reference, conversions: data.conversions || null };
316
341
  paintDetail();
317
342
  markSeen(token, id, data.rev);
318
343
  }
@@ -432,13 +457,26 @@
432
457
  else say(`Open AI Chat and ask: “${text}”`);
433
458
  },
434
459
  }));
460
+ const convertible = s.entities.filter((e) => CLOSED.has(e.kind));
461
+ const allConverted = convertible.length > 0 && convertible.every((e) => current.conversions?.entities?.[e.id]?.state === 'converted');
462
+ actions.append(button(allConverted ? 'Convert again with AI' : 'Convert with AI', 'shell.sketches-convert', {
463
+ tip: convertible.length
464
+ ? 'Save this sketch and the model, then ask the AI to turn the closed shapes into plates. You confirm what it builds on a card; nothing is sent.'
465
+ : 'Only a closed shape (a rectangle, polygon, closed polyline or circle) becomes a plate. The AI can still read this sketch with you.',
466
+ onClick: () => { void convertWithAi(shown.id); },
467
+ }));
435
468
  head.append(actions);
436
469
  detailEl.append(head);
470
+ const convertNote = make('div', 'sketches-convert-note');
471
+ convertNote.hidden = true;
472
+ detailEl.append(convertNote);
437
473
 
438
474
  const ref = current.reference;
439
- if (ref && ref.verdict && ref.verdict !== 'unchanged') {
440
- const callout = make('div', 'add-ons-callout');
475
+ if (ref && ref.verdict && ref.verdict !== 'unchanged' && !summary?.frozen) {
476
+ const callout = make('div', 'add-ons-callout sketches-reference');
477
+ callout.dataset.verdict = ref.verdict;
441
478
  callout.append(make('span', '', referenceText(ref)));
479
+ callout.append(referenceChoices(ref, shown));
442
480
  detailEl.append(callout);
443
481
  }
444
482
 
@@ -446,11 +484,13 @@
446
484
  shapes.append(make('h4', '', s.entities.length === 1 ? '1 shape' : `${s.entities.length} shapes`));
447
485
  if (!s.entities.length) shapes.append(make('p', 'add-ons-muted', 'Nothing drawn yet. Turn on Sketch in the model and draw a shape.'));
448
486
  else {
449
- const ul = make('ul', 'add-ons-changes');
450
- for (const e of s.entities) ul.append(make('li', '', shapeLine(e)));
487
+ const ul = make('ul', 'add-ons-changes sketches-shapes');
488
+ for (const e of s.entities) ul.append(shapeItem(e, shown));
451
489
  shapes.append(ul);
452
490
  }
453
491
  detailEl.append(shapes);
492
+ const history = conversionsSection(shown);
493
+ if (history) detailEl.append(history);
454
494
 
455
495
  const versions = make('div', 'add-ons-section');
456
496
  versions.append(make('h4', '', 'Versions'));
@@ -479,6 +519,152 @@
479
519
  detailEl.append(foot);
480
520
  }
481
521
 
522
+ // ── S1c: stale-reference choices (plan §3) ────────────────────────────
523
+ function referenceChoices(ref, shown) {
524
+ const row = make('div', 'sketches-choices');
525
+ const reattach = (choice, done) => (hold) => act(async (token) => {
526
+ await call(token, 'POST', `/sketches/${encodeURIComponent(shown.id)}/reattach`, { choice }, shown.rev);
527
+ }, done, hold);
528
+ const choice = (label, id, tip, fn, primary = false) => {
529
+ const b = waitsWhileBusy(button(label, id, { className: primary ? 'primary' : '', tip, instance: shown.id, instanceLabel: current.sketch.name }));
530
+ b.addEventListener('click', () => { if (!isBusy()) void fn(newHold()); });
531
+ return b;
532
+ };
533
+ if (ref.verdict === 'moved') {
534
+ row.append(choice('Move with the member', 'shell.sketches-move-with', 'Move the sketch with its member, so it stays on the same face. The earlier placement is kept as a version.',
535
+ reattach('move-with', 'Moved with the member. The earlier placement is kept as a version.'), true));
536
+ }
537
+ if (ref.verdict === 'unknown') {
538
+ row.append(choice('Check again', 'shell.sketches-check-again', 'Read the model again and check the member this sketch is on.', async () => { await refresh(); say('Checked again.'); }));
539
+ } else {
540
+ row.append(choice('Re-attach to another face', 'shell.sketches-reattach-face', 'Pick a face in the 3D view to attach this sketch to. Esc cancels; nothing is changed until you pick.', async () => {
541
+ const ed = editor();
542
+ if (!ed?.reattachFace) { say('Open this project’s model in 3D, then choose Re-attach again.', 'warn'); return; }
543
+ const { id, rev } = shown;
544
+ close();
545
+ await ed.reattachFace(id, rev);
546
+ }));
547
+ }
548
+ row.append(choice('Keep where drawn', 'shell.sketches-keep-where-drawn', 'Keep the sketch where it was drawn and stop checking its member. Saved as a version.',
549
+ reattach('keep-where-drawn', 'Kept where it was drawn. FloLess no longer checks its member.')));
550
+ return row;
551
+ }
552
+
553
+ // ── S1c: conversion states (plan §7.5, §8) ────────────────────────────
554
+ const CLOSED = new Set(['rect', 'polygon', 'circle', 'polyline']);
555
+ // Pill, its tone and the sentence for each state. Present tense: what the model holds now, never what happened once.
556
+ const STATE = {
557
+ checking: ['Checking', '', () => 'FloLess is checking whether this conversion is in the model.'],
558
+ 'model-unreadable': ['Can’t check', 'off', () => 'FloLess can’t read the model just now, so it can’t say whether this is built.'],
559
+ 'edited-since': ['Edited since', 'off', (c) => `Changed after it was converted. The plate${c.objectId ? ` ${c.objectId}` : ''} in the model is from the earlier shape.`],
560
+ 'converted-unbuildable': ['Can’t be built', 'off', (c) => `Converted, but the connection can no longer be built${c.why ? `: ${c.why}` : '.'}`],
561
+ converted: ['Converted', 'on', (c) => `Built as ${c.objectId ?? 'a plate'}.`],
562
+ 'converted-changed': ['Converted, edited', 'on', (c) => `Built as ${c.objectId ?? 'a plate'}; the plate was changed in the model since.`],
563
+ 'link-dropped': ['Link lost', 'off', (c) => `${c.objectId ?? 'The plate'} is still in the model but no longer linked to this sketch.`],
564
+ unlinked: ['Not in model', 'off', () => 'No plate in the model comes from this conversion now.'],
565
+ 'not-in-version': ['Not in sketch', '', () => 'This shape is no longer in the sketch.'],
566
+ };
567
+ const AGAIN = new Set(['edited-since', 'link-dropped', 'unlinked']);
568
+ function shapeItem(e, shown) {
569
+ const li = make('li', 'sketches-shape');
570
+ li.append(make('span', 'sketches-shape-line', shapeLine(e)));
571
+ const c = current.conversions?.entities?.[e.id];
572
+ const st = c && STATE[c.state];
573
+ if (st) {
574
+ li.dataset.state = c.state;
575
+ const pill = make('span', `add-ons-pill${st[1] ? ` ${st[1]}` : ''}`, st[0]);
576
+ pill.dataset.tip = st[2](c) + (c.hidden && !view.showConverted ? ' Hidden in the 3D view; turn on Show converted shapes to see it.' : '');
577
+ li.append(pill);
578
+ li.append(make('span', 'add-ons-muted sketches-shape-state', st[2](c)));
579
+ if (AGAIN.has(c.state)) {
580
+ li.append(button('Convert again', 'shell.sketches-convert-again', {
581
+ className: 'add-ons-link', instance: `${shown.id}/${e.id}`, instanceLabel: shapeLine(e),
582
+ tip: 'Save and ask the AI to convert this shape again. You confirm what it builds on a card; nothing is sent.',
583
+ onClick: () => { void convertWithAi(shown.id, [e.id]); },
584
+ }));
585
+ }
586
+ }
587
+ return li;
588
+ }
589
+ function conversionsSection(shown) {
590
+ if (current.conversions?.damaged) {
591
+ const box = make('div', 'add-ons-section sketches-conversions');
592
+ box.append(make('p', 'add-ons-muted', 'Part of this sketch’s conversion record is damaged, so FloLess can’t say which shapes were built. The sketch itself is fine. Report an issue if this stays.'));
593
+ return box;
594
+ }
595
+ const h = current.conversions?.history;
596
+ if (!h?.length) return null;
597
+ const box = make('details', 'add-ons-section sketches-conversions');
598
+ const attention = Object.values(current.conversions.entities ?? {}).some((c) => !['converted', 'converted-changed'].includes(c.state));
599
+ box.open = h.length <= 2 || attention;
600
+ const latest = STATE[h[0].entities[0]?.state]?.[0];
601
+ const sum = make('summary', '', `Conversions (${h.length})${latest ? ` · last: ${latest}` : ''}`);
602
+ sum.dataset.commandId = 'shell.sketches-conversions';
603
+ box.append(sum);
604
+ if (!current.conversions.readable) box.append(make('p', 'add-ons-muted', 'FloLess can’t read the model just now, so these states may be out of date.'));
605
+ const ol = make('ol', 'add-ons-versions sketches-conversion-list');
606
+ for (const c of h) {
607
+ const li = make('li', 'add-ons-version');
608
+ li.append(make('span', 'add-ons-version-label', `Version ${c.version}${c.objectId ? ` · ${c.objectId}` : ''}`));
609
+ const states = [...new Set(c.entities.map((x) => x.state))];
610
+ const notes = make('span', 'add-ons-version-notes', `${when(c.at)}${c.mode === 'another' ? ' · another plate' : ''} · ${c.entities.length === 1 ? '1 shape' : `${c.entities.length} shapes`}`);
611
+ li.append(notes);
612
+ for (const st of states) {
613
+ const t = STATE[st];
614
+ if (t) li.append(make('span', `add-ons-pill${t[1] ? ` ${t[1]}` : ''}`, t[0]));
615
+ }
616
+ if (c.objectId && states.some((x) => x === 'converted' || x === 'converted-changed' || x === 'link-dropped' || x === 'edited-since')) {
617
+ li.append(button('Show in model', 'shell.sketches-show-conversion', {
618
+ className: 'add-ons-link', instance: c.conversionId, instanceLabel: `${c.objectId}, version ${c.version}`,
619
+ tip: `Select ${c.objectId} in the 3D view.`,
620
+ onClick: () => {
621
+ const ed = editor();
622
+ if (!ed?.showObject) { say('Open this project’s model in 3D to see it.', 'warn'); return; }
623
+ if (!ed.showObject(c.objectId)) { say(`${c.objectId} could not be selected in the 3D view. A filter may hide it.`, 'warn'); return; }
624
+ close();
625
+ },
626
+ }));
627
+ }
628
+ ol.append(li);
629
+ }
630
+ box.append(ol);
631
+ return box;
632
+ }
633
+
634
+ /**
635
+ * Convert with AI (plan §8): the sketch and the model are saved first (by the open model editor), then the chat box is
636
+ * filled. A save that did not land is said, with Resolve it first (recommended) or Ask anyway. Nothing is sent.
637
+ */
638
+ async function convertWithAi(id, entityIds = null) {
639
+ const ed = editor();
640
+ const note = detailEl.querySelector('.sketches-convert-note');
641
+ const chat = window.flolessChat;
642
+ if (!ed?.prepareConvert) {
643
+ // No model open here: the server holds the last save of both, and that is what the AI reads.
644
+ const name = sketches.find((x) => x.id === id)?.name ?? 'my sketch';
645
+ const text = `Convert “${name}” into a plate: `;
646
+ if (chat && typeof chat.fillMessageBox === 'function') { close(); chat.fillMessageBox(text); } else say(`Open AI Chat and ask: “${text}”`);
647
+ return;
648
+ }
649
+ say('Saving the sketch and the model…');
650
+ const token = session;
651
+ const ready = await ed.prepareConvert(id, entityIds);
652
+ // Closed, or opened again on something else, while it saved: that later dialog is not this one's to close or fill.
653
+ if (!token || !sessions.live(token) || current?.id !== id) return;
654
+ say('');
655
+ // The chat box must be there to fill: if it is not, the dialog stays open and says what to ask, instead of closing on nothing.
656
+ if (!ready.name || typeof chat?.fillMessageBox !== 'function') { say(`Open AI Chat and ask it to convert ${ready.name ? `“${ready.name}”` : 'this sketch'} into a plate.`, 'warn'); return; }
657
+ if (ready.sketchSaved && ready.modelSaved) { close(); ready.go(); return; }
658
+ if (!note) { close(); ready.go(); return; }
659
+ const what = !ready.sketchSaved && !ready.modelSaved ? 'The sketch and the model didn’t save' : !ready.sketchSaved ? 'The sketch didn’t save' : 'The model didn’t save';
660
+ note.hidden = false;
661
+ note.replaceChildren(make('span', '', `${what}, so the AI would see the copy saved last.`));
662
+ const row = make('div', 'sketches-choices');
663
+ row.append(button('Resolve it first', 'shell.sketches-convert-resolve', { className: 'primary', tip: 'Open the sketch in the model to see what did not save, then convert.', onClick: () => { close(); void ed.focus(id); } }));
664
+ row.append(button('Ask anyway', 'shell.sketches-convert-anyway', { tip: 'Ask the AI now. The shapes that did not save are marked unsaved for it.', onClick: () => { close(); ready.go(); } }));
665
+ note.append(row);
666
+ }
667
+
482
668
  function reasonText(reason) {
483
669
  return ({
484
670
  'leave-mode': 'Saved when you left Sketch mode', 'ai-edit': 'Before an AI change', overwrite: 'The other side of a conflict',
@@ -563,7 +749,7 @@
563
749
  if (!session || !modal.classList.contains('show')) return;
564
750
  const d = event.detail || {};
565
751
  if (d.projectId && d.projectId !== session.projectId) return;
566
- if (current && d.id === current.id && d.rev === current.rev) return;
752
+ if (current && d.id === current.id && d.rev === current.rev && !d.conversion) return;
567
753
  void refresh();
568
754
  });
569
755
 
@@ -0,0 +1,46 @@
1
+ // The desktop host carries this URL across restarts. A fresh window has no place to restore.
2
+ (function () {
3
+ 'use strict';
4
+
5
+ const projectId = /^[a-z0-9][a-z0-9-]{0,127}$/;
6
+ const workflowId = /^[a-z0-9][a-z0-9._-]{0,127}$/i;
7
+ const landing = () => ({ mode: 'workspaces', project: null, workflow: null });
8
+ const isId = (id, pattern) => typeof id === 'string' && pattern.test(id);
9
+
10
+ function read(hash) {
11
+ const match = /^#mode=(workspaces|workflows|agents)(?:&(project|workflow)=([^&=]+))?$/.exec(hash);
12
+ if (!match) return landing();
13
+ const [, mode, key, id] = match;
14
+ if (key === 'project' && (mode !== 'workspaces' || !isId(id, projectId))) return landing();
15
+ if (key === 'workflow' && (mode !== 'workflows' || !isId(id, workflowId))) return landing();
16
+ return { mode, project: key === 'project' ? id : null, workflow: key === 'workflow' ? id : null };
17
+ }
18
+
19
+ function remember(place, search = location.search) {
20
+ let hash = '';
21
+ if (place.mode === 'workspaces' && isId(place.project, projectId)) hash = '#mode=workspaces&project=' + place.project;
22
+ if (place.mode === 'workflows') hash = '#mode=workflows' + (isId(place.workflow, workflowId) ? '&workflow=' + place.workflow : '');
23
+ if (place.mode === 'agents') hash = '#mode=agents';
24
+ if (hash === location.hash && search === location.search) return;
25
+ try { history.replaceState(history.state, '', location.pathname + search + hash); }
26
+ catch { /* a browser that cannot update its history can still navigate inside FloLess */ }
27
+ }
28
+
29
+ const launchHash = location.hash;
30
+ const parts = launchHash.slice(1).split('&');
31
+ const marked = parts.includes('resume=1');
32
+ const initial = marked ? read('#' + parts.filter((part) => part !== 'resume=1').join('&')) : landing();
33
+ const resumed = marked && (initial.mode !== 'workspaces' || initial.project !== null);
34
+ if (marked) {
35
+ const query = location.search.slice(1).split('&').filter((part) => part && part !== 'floless-resume-load=1').join('&');
36
+ remember(initial, query ? '?' + query : '');
37
+ }
38
+ // Hide the old workflow chrome before CSS paints the Workspaces or Agents shell.
39
+ if (initial.mode !== 'workflows') document.documentElement.classList.add('mode-' + initial.mode + '-boot');
40
+ function markRetry() {
41
+ if (!marked) return;
42
+ try { history.replaceState(history.state, '', location.pathname + location.search + launchHash); }
43
+ catch { /* reload can still proceed if history is unavailable */ }
44
+ }
45
+ window.flolessStartPlace = { initial, resumed, read, remember, markRetry };
46
+ })();
@@ -2542,3 +2542,73 @@ export function declutterLabelRects(items, gap = 0) {
2542
2542
  return hidden;
2543
2543
  }
2544
2544
  const MAX_CELLS = 16;
2545
+
2546
+ // ---- member hole + opening tools for the 3D view (#4027) ----
2547
+ /** How far a drilled tool runs past each BEARING face it is bounded by — enough that CSG never leaves a
2548
+ * coplanar sliver, small enough that a flange bolt's hole never reaches the other flange. The far side is
2549
+ * bounded by the grip (head face to nut face), never by the member's depth. */
2550
+ export const HOLE_TOOL_PAD_MM = 0.6;
2551
+
2552
+ const finite3 = (p) => Array.isArray(p) && p.length >= 3 && p.every((v, i) => i > 2 || (typeof v === 'number' && Number.isFinite(v))); // `sub3` is this module's (above)
2553
+
2554
+ /**
2555
+ * The cylinder tools that drill one member's bolt holes and round openings, from the /scene reply's top-level
2556
+ * `operations` (bolt arrays + `boolean-cut` ops), plus the holes that cannot be bounded and so cannot be drawn.
2557
+ *
2558
+ * - A HOLE is one per (bolt instance, member), however many hole effects the instance lists for that member: it runs
2559
+ * from the instance's head part `from` to its first nut part `from` (both are the BEARING faces — the plies the bolt
2560
+ * clamps lie between them), padded `HOLE_TOOL_PAD_MM` past each face only. Its axis is therefore the bolt line.
2561
+ * - An OPENING is a `boolean-cut` whose tool is a `cylinder` on this member: its own axis `from`→`to`, unpadded (the
2562
+ * producer already sized it to pass through).
2563
+ * - A hole whose head or nut is missing, not a nut part, or coincident has nothing to bound it: it goes into
2564
+ * `notDrawable` as `{ memberId, kind: 'hole', label, at, diameterMm, cutId }` — never a guessed through-member tool.
2565
+ * A cylinder opening with a degenerate axis is reported the same way (`kind: 'opening'`).
2566
+ *
2567
+ * Pure (no three): `elementsById` is a Map or a plain object of scene elements by id.
2568
+ * @returns {{ tools: { id: string, kind: 'hole'|'opening', from: number[], to: number[], diameterMm: number, at: number[], label: string }[],
2569
+ * notDrawable: { memberId: string, kind: 'hole'|'opening', label: string, at: number[]|null, diameterMm: number|null, cutId: string }[] }}
2570
+ */
2571
+ export function holeToolsForMember(memberId, cutOperations, elementsById) {
2572
+ const tools = [], notDrawable = [];
2573
+ if (memberId == null || !Array.isArray(cutOperations)) return { tools, notDrawable };
2574
+ const id = String(memberId);
2575
+ const get = (k) => (k == null ? undefined : (elementsById instanceof Map ? elementsById.get(k) : elementsById && elementsById[k]));
2576
+ const seen = new Set();
2577
+ for (const op of cutOperations) {
2578
+ if (!op || typeof op !== 'object') continue;
2579
+ if (op.kind === 'bolt-array' && Array.isArray(op.instances)) {
2580
+ for (const inst of op.instances) {
2581
+ if (!inst || !Array.isArray(inst.holeEffects)) continue;
2582
+ const effect = inst.holeEffects.find((h) => h && String(h.targetId) === id);
2583
+ if (!effect) continue;
2584
+ const key = 'hole|' + String(inst.id) + '|' + id;
2585
+ if (seen.has(key)) continue;
2586
+ seen.add(key);
2587
+ // The LARGEST hole any effect gives this member on this bolt — the same rule as the bill's cutToolsFromBuild, so
2588
+ // the picture and the net weight agree on one hole size.
2589
+ const dMax = Math.max(0, ...inst.holeEffects.filter((h) => h && String(h.targetId) === id).map((h) => Number(h.diameterMm)).filter((v) => v > 0));
2590
+ const d = dMax > 0 ? dMax : (Number(op.diameterMm) > 0 ? Number(op.diameterMm) : null);
2591
+ const at = finite3(effect.center) ? effect.center.slice(0, 3).map(Number) : (finite3(inst.point) ? inst.point.slice(0, 3).map(Number) : null);
2592
+ const cutId = String(inst.id);
2593
+ const head = get(inst.headId), nut = get(Array.isArray(inst.nutIds) ? inst.nutIds[0] : undefined);
2594
+ const a = head && head.kind === 'nut' && finite3(head.from) ? head.from.slice(0, 3).map(Number) : null;
2595
+ const b = nut && nut.kind === 'nut' && finite3(nut.from) ? nut.from.slice(0, 3).map(Number) : null;
2596
+ const axis = a && b ? sub3(b, a) : null, len = axis ? Math.hypot(axis[0], axis[1], axis[2]) : 0;
2597
+ if (!a || !b || !(len > 1e-6) || !(d > 0)) { notDrawable.push({ memberId: id, kind: 'hole', label: 'a bolt hole', at, diameterMm: d, cutId }); continue; }
2598
+ const u = axis.map((v) => v / len), pad = HOLE_TOOL_PAD_MM;
2599
+ tools.push({ id: cutId, kind: 'hole', from: a.map((v, i) => v - u[i] * pad), to: b.map((v, i) => v + u[i] * pad), diameterMm: d, at: at || a.map((v, i) => (v + b[i]) / 2), label: 'a bolt hole' });
2600
+ }
2601
+ } else if (op.kind === 'boolean-cut' && String(op.targetId) === id && op.tool && op.tool.kind === 'cylinder') {
2602
+ const key = 'opening|' + String(op.id);
2603
+ if (seen.has(key)) continue;
2604
+ seen.add(key);
2605
+ const ax = op.tool.axis || {}, d = Number(op.tool.diameterMm);
2606
+ const a = finite3(ax.from) ? ax.from.slice(0, 3).map(Number) : null, b = finite3(ax.to) ? ax.to.slice(0, 3).map(Number) : null;
2607
+ const mid = a && b ? a.map((v, i) => (v + b[i]) / 2) : (a || b);
2608
+ const len = a && b ? Math.hypot(...sub3(b, a)) : 0;
2609
+ if (!(len > 1e-6) || !(d > 0)) { notDrawable.push({ memberId: id, kind: 'opening', label: 'an opening', at: mid || null, diameterMm: d > 0 ? d : null, cutId: String(op.id) }); continue; }
2610
+ tools.push({ id: String(op.id), kind: 'opening', from: a, to: b, diameterMm: d, at: mid, label: 'an opening' });
2611
+ }
2612
+ }
2613
+ return { tools, notDrawable };
2614
+ }