@floless/app 0.170.0 → 0.171.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 (53) hide show
  1. package/dist/floless-server.cjs +33000 -22928
  2. package/dist/schemas/steel.model.v2.schema.json +194 -3
  3. package/dist/skills/floless-app-bridge/SKILL.md +3 -3
  4. package/dist/skills/floless-app-knowledge/SKILL.md +4 -3
  5. package/dist/skills/floless-app-onboarding/SKILL.md +5 -4
  6. package/dist/skills/floless-app-onboarding/references/floless-surfaces.md +0 -3
  7. package/dist/skills/floless-app-queue/SKILL.md +2 -3
  8. package/dist/skills/floless-app-report-issue/SKILL.md +2 -2
  9. package/dist/skills/floless-app-steel-model/SKILL.md +35 -35
  10. package/dist/skills/floless-app-steel-model/references/custom-connections.md +47 -0
  11. package/dist/skills/floless-app-steel-model/references/custom-sections.md +32 -0
  12. package/dist/skills/floless-app-ui/SKILL.md +71 -126
  13. package/dist/web/add-ons.js +407 -0
  14. package/dist/web/analytics.js +1 -1
  15. package/dist/web/app.css +108 -189
  16. package/dist/web/app.js +11 -12
  17. package/dist/web/aware.js +49 -29
  18. package/dist/web/chat.css +6 -1
  19. package/dist/web/chat.js +133 -18
  20. package/dist/web/commands-filter.js +23 -0
  21. package/dist/web/commands-shell.js +39 -67
  22. package/dist/web/commands-steel.js +9 -1
  23. package/dist/web/commands-tekla-parser.js +23 -0
  24. package/dist/web/connections.js +14 -3
  25. package/dist/web/failure-copy.js +1 -0
  26. package/dist/web/guide.js +3 -3
  27. package/dist/web/index.html +29 -56
  28. package/dist/web/instructor.js +2 -2
  29. package/dist/web/kb-categories.js +64 -7
  30. package/dist/web/model-change-findings.js +430 -0
  31. package/dist/web/model-change-review.js +414 -0
  32. package/dist/web/model-editor-steel-adapter.js +2 -2
  33. package/dist/web/project-history.js +7 -1
  34. package/dist/web/revit-editor.css +85 -0
  35. package/dist/web/revit-editor.js +36 -1
  36. package/dist/web/sha256-sync.js +62 -0
  37. package/dist/web/steel-3d-core.js +7 -0
  38. package/dist/web/steel-3d-flo.js +127 -3
  39. package/dist/web/steel-3d-view.js +25 -2
  40. package/dist/web/steel-custom-connection.js +161 -0
  41. package/dist/web/steel-custom-sections.js +1796 -0
  42. package/dist/web/steel-editor.html +279 -41
  43. package/dist/web/steel-filter-usage.js +299 -0
  44. package/dist/web/steel-filter.html +101 -4
  45. package/dist/web/steel-model-v2-client-validation.js +3 -0
  46. package/dist/web/steel-model-v2-commands.js +95 -6
  47. package/dist/web/steel-model-v2-projection.js +1 -1
  48. package/dist/web/steel-read-confidence.js +1 -56
  49. package/dist/web/tekla-editor.html +1 -0
  50. package/dist/web/workspaces.js +263 -28
  51. package/launch.mjs +87 -9
  52. package/package.json +1 -1
  53. package/dist/web/panels.js +0 -831
@@ -0,0 +1,62 @@
1
+ /*
2
+ * Synchronous SHA-256 over a UTF-8 string, for the small identity tokens the steel model computes while it
3
+ * renders or commits an edit (endpoint lineage, custom-section ids). `crypto.subtle` is asynchronous and the
4
+ * editor's command transaction is not, so the browser and the server share this one implementation and
5
+ * therefore cannot disagree about an id. Pinned against Node's `crypto` by `server/sha256-sync.test.ts`.
6
+ */
7
+
8
+ const SHA256_K = Object.freeze([
9
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
10
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
11
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
12
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
13
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
14
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
15
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
16
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
17
+ ]);
18
+
19
+ const rotateRight = (value, bits) => (value >>> bits) | (value << (32 - bits));
20
+
21
+ /** @param {string} text @returns {string} 64 lowercase hex digits */
22
+ export function sha256Hex(text) {
23
+ const input = new TextEncoder().encode(text);
24
+ const byteLength = Math.ceil((input.length + 9) / 64) * 64;
25
+ const bytes = new Uint8Array(byteLength);
26
+ bytes.set(input);
27
+ bytes[input.length] = 0x80;
28
+ const view = new DataView(bytes.buffer);
29
+ const bitLength = input.length * 8;
30
+ view.setUint32(byteLength - 8, Math.floor(bitLength / 0x100000000));
31
+ view.setUint32(byteLength - 4, bitLength >>> 0);
32
+ const hash = new Uint32Array([
33
+ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
34
+ 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
35
+ ]);
36
+ const words = new Uint32Array(64);
37
+ for (let offset = 0; offset < byteLength; offset += 64) {
38
+ for (let i = 0; i < 16; i++) words[i] = view.getUint32(offset + i * 4);
39
+ for (let i = 16; i < 64; i++) {
40
+ const a = words[i - 15];
41
+ const b = words[i - 2];
42
+ const s0 = rotateRight(a, 7) ^ rotateRight(a, 18) ^ (a >>> 3);
43
+ const s1 = rotateRight(b, 17) ^ rotateRight(b, 19) ^ (b >>> 10);
44
+ words[i] = (words[i - 16] + s0 + words[i - 7] + s1) >>> 0;
45
+ }
46
+ let [a, b, c, d, e, f, g, h] = hash;
47
+ for (let i = 0; i < 64; i++) {
48
+ const s1 = rotateRight(e, 6) ^ rotateRight(e, 11) ^ rotateRight(e, 25);
49
+ const choice = (e & f) ^ (~e & g);
50
+ const t1 = (h + s1 + choice + SHA256_K[i] + words[i]) >>> 0;
51
+ const s0 = rotateRight(a, 2) ^ rotateRight(a, 13) ^ rotateRight(a, 22);
52
+ const majority = (a & b) ^ (a & c) ^ (b & c);
53
+ const t2 = (s0 + majority) >>> 0;
54
+ h = g; g = f; f = e; e = (d + t1) >>> 0; d = c; c = b; b = a; a = (t1 + t2) >>> 0;
55
+ }
56
+ hash[0] = (hash[0] + a) >>> 0; hash[1] = (hash[1] + b) >>> 0;
57
+ hash[2] = (hash[2] + c) >>> 0; hash[3] = (hash[3] + d) >>> 0;
58
+ hash[4] = (hash[4] + e) >>> 0; hash[5] = (hash[5] + f) >>> 0;
59
+ hash[6] = (hash[6] + g) >>> 0; hash[7] = (hash[7] + h) >>> 0;
60
+ }
61
+ return [...hash].map((word) => word.toString(16).padStart(8, '0')).join('');
62
+ }
@@ -637,6 +637,13 @@ export function sectionTopology(displaySection, w, d, fallbackKind = 'BOX') {
637
637
  const radius = od / 2;
638
638
  return [component(circle(radius), t > 0 && t < radius ? [circle(radius - t)] : [])];
639
639
  }
640
+ if (xs?.shape === 'outline') {
641
+ // A custom section (add-ons S1a): its evaluated outline, already in mm, centred on its bounding box,
642
+ // counter-clockwise, x across the width and y up the depth. Drawn exactly as evaluated, never re-fitted.
643
+ const outer = Array.isArray(xs.outer) ? xs.outer.filter((p) => Array.isArray(p) && Number.isFinite(p[0]) && Number.isFinite(p[1])) : [];
644
+ if (outer.length >= 3) return [component(polygon(outer.map(([x, y]) => [x, y])))];
645
+ return [];
646
+ }
640
647
  if (xs?.shape === 'solid-circle') {
641
648
  const diameter = Number(xs.diameter) > 0 ? Number(xs.diameter) : Math.min(w, d);
642
649
  return [component(circle(diameter / 2))];
@@ -17,7 +17,6 @@ import { createFlo3D } from './flo-3d.js';
17
17
 
18
18
  const MODEL_R_OF_DIAG = 0.011; // Flo's ring radius as a share of the model's diagonal...
19
19
  const MODEL_R_MIN = 140, MODEL_R_MAX = 900; // ...in mm: a toy on a beam, never a giant on a shed
20
- const MIN_SCREEN_R_PX = 13; // and never smaller than this on screen
21
20
  const VISIT_MAX = 10; // a big change is shown by its first ten members, not all of them
22
21
  const VISIT_DWELL_S = 1.2; // long enough on each changed member to read Flo's card about it
23
22
  const SUCCESS_S = 2.4;
@@ -28,7 +27,39 @@ const ALONG = 0.3; // a beam's perch: this far alo
28
27
  const LEAVE_S = 0.2; // Minimize: Flo shrinks away this fast (instant under reduced motion)
29
28
  const HALF_WIDTH_R = 1.5; // Flo's reach either side of its middle, in r: the hat's brim (1.25 r) widened by a hop's squash
30
29
 
31
- export function createSteelFlo({ THREE, scene, meshById, getCamera, getSceneBox, pxToWorldAt, floPose, reducedMotion, enabled: startEnabled = false, onPerch = () => {} }) {
30
+ // How big Flo is on screen (#3380): its ring radius in screen pixels follows the zoom, the way a map pin does,
31
+ // and the person's Flo size multiplies it. The zoom is read as how many pixels the model's diagonal spans on
32
+ // screen at Flo's depth (the same px-per-world scale the labels and marks use, so it means the same in the
33
+ // perspective and the orthographic camera). Zoomed in close Flo gets smaller, so it never covers the members in
34
+ // focus; zoomed out it gets bigger, so it stays visible beside a small model. Continuous: a power curve, no steps.
35
+ export const FLO_SIZE = Object.freeze({
36
+ REF_MODEL_PX: 1200, // the model's diagonal on screen at which Flo is drawn at its designed size (about "Fit")
37
+ FIT_R_PX: 22, // Flo's ring radius there, at Flo size 100 % (Flo stands about 3.3 r tall: ~73 px)
38
+ CURVE: 0.3, // how strongly the zoom changes Flo: 10x closer draws Flo half as big
39
+ MIN_R_PX: 11, // the curve stops here when zoomed in close...
40
+ MAX_R_PX: 34, // ...and here when zoomed out; both scale with Flo size, so the slider always counts
41
+ FLOOR_R_PX: 8, // never smaller than this, whatever the slider says: Flo stays recognisable
42
+ HEIGHT_R: 3.3, // Flo's height, hat included, in r
43
+ VIEW_SHARE: 0.28, // never taller than this share of the view, whatever the slider says
44
+ MEMBER_SHARE: 3, // never wider (about 3 r) than the member as drawn, so it never hides it (the floor still holds).
45
+ // Half the member was tried: in a real zoom-out it stopped Flo growing as soon as the beam got small
46
+ });
47
+
48
+ // Flo's ring radius in screen pixels. modelPx: the model's diagonal on screen; viewH: the view's height in px;
49
+ // memberPx: how long the member Flo stands on is drawn, foreshortening included (both optional); sizeK: Flo size as a factor.
50
+ // Rounded to a quarter pixel, so a still camera never shimmers.
51
+ /** @param {{ sizeK?: number, modelPx?: number, viewH?: number, memberPx?: number }} [opts] */
52
+ export function floScreenRadiusPx({ sizeK = 1, modelPx, viewH, memberPx } = {}) {
53
+ const S = FLO_SIZE;
54
+ const k = Number.isFinite(sizeK) && sizeK > 0 ? sizeK : 1;
55
+ const zoom = Number.isFinite(modelPx) && modelPx > 0 ? Math.pow(S.REF_MODEL_PX / modelPx, S.CURVE) : 1;
56
+ let r = Math.min(k * S.MAX_R_PX, Math.max(k * S.MIN_R_PX, k * S.FIT_R_PX * zoom));
57
+ if (Number.isFinite(memberPx) && memberPx > 0) r = Math.min(r, memberPx / S.MEMBER_SHARE);
58
+ if (Number.isFinite(viewH) && viewH > 0) r = Math.min(r, viewH * S.VIEW_SHARE / S.HEIGHT_R);
59
+ return Math.round(Math.max(S.FLOOR_R_PX, r) * 4) / 4;
60
+ }
61
+
62
+ export function createSteelFlo({ THREE, scene, meshById, getCamera, getSceneBox, getViewSize = () => /** @type {{ w: number, h: number } | null} */ (null), floPose, reducedMotion, enabled: startEnabled = false, onPerch = () => {} }) {
32
63
  const now = () => performance.now() / 1000;
33
64
  const flo = createFlo3D(THREE, {
34
65
  floPose, up: new THREE.Vector3(0, 0, 1), reducedMotion,
@@ -36,6 +67,9 @@ export function createSteelFlo({ THREE, scene, meshById, getCamera, getSceneBox,
36
67
  let enabled = !!startEnabled;
37
68
  let perched = null; // the member whose card is showing (onPerch), or null
38
69
  let placed = false, standingOn = null, modelR = 300, sizeK = 1; // sizeK: the person's Flo size (Labels menu), 1 = as designed
70
+ let modelDiag = 0; // the model's diagonal (mm): Flo's zoom reading (floScreenRadiusPx)
71
+ const spines = new Map(); // member id -> its spine (mm), read once per model
72
+ const pa = new THREE.Vector3(), pb = new THREE.Vector3();
39
73
  let shellMood = 'idle';
40
74
  let tour = null; // { ids, i, waitUntil }
41
75
  let successUntil = 0;
@@ -96,6 +130,8 @@ export function createSteelFlo({ THREE, scene, meshById, getCamera, getSceneBox,
96
130
  const box = getSceneBox();
97
131
  if (!box || box.isEmpty()) return;
98
132
  const diag = box.getSize(new THREE.Vector3()).length();
133
+ modelDiag = diag;
134
+ spines.clear(); // a rebuilt model: read the members again
99
135
  modelR = Math.min(MODEL_R_MAX, Math.max(MODEL_R_MIN, diag * MODEL_R_OF_DIAG));
100
136
  }
101
137
 
@@ -239,8 +275,96 @@ export function createSteelFlo({ THREE, scene, meshById, getCamera, getSceneBox,
239
275
  if (k <= 0) { leaving = null; flo.object.visible = false; return; }
240
276
  k = k * k;
241
277
  }
242
- flo.setSize(Math.max(modelR, pxToWorldAt(MIN_SCREEN_R_PX, flo.object.position)) * sizeK * k);
278
+ // Flo moves first (a hop), then takes its size where it now is, so what is drawn this frame is the size worked out
279
+ // for this frame's position, not the last one's.
243
280
  flo.tick(t, camera);
281
+ flo.setSize(worldRadius(camera) * k);
282
+ }
283
+
284
+ // A member's spine in the model (mm): the line it runs along, end to end, and how far its section reaches from that
285
+ // line, read from its own vertices once per model (a beam that runs diagonally in plan is a diagonal line, not the
286
+ // box around it). The direction is the vertices' main axis (power iteration on their spread). Null when not drawn.
287
+ function spineOf(id) {
288
+ if (!id) return null;
289
+ if (spines.has(id)) return spines.get(id);
290
+ const pts = [], v = new THREE.Vector3();
291
+ meshById.get(id)?.traverse?.((o) => {
292
+ const pos = o.isMesh && o.geometry?.attributes?.position;
293
+ if (!pos) return;
294
+ o.updateMatrixWorld(true);
295
+ const stride = Math.max(1, Math.floor(pos.count / 2000)); // a few thousand points say where a member runs
296
+ for (let i = 0; i < pos.count; i += stride) pts.push(v.fromBufferAttribute(pos, i).applyMatrix4(o.matrixWorld).clone());
297
+ });
298
+ let spine = null;
299
+ if (pts.length >= 2) {
300
+ const c = new THREE.Vector3();
301
+ for (const q of pts) c.add(q);
302
+ c.divideScalar(pts.length);
303
+ let xx = 0, xy = 0, xz = 0, yy = 0, yz = 0, zz = 0;
304
+ for (const q of pts) { const x = q.x - c.x, y = q.y - c.y, z = q.z - c.z; xx += x * x; xy += x * y; xz += x * z; yy += y * y; yz += y * z; zz += z * z; }
305
+ const box = new THREE.Box3().setFromPoints(pts), size = box.getSize(new THREE.Vector3());
306
+ const dir = size.x >= size.y && size.x >= size.z ? new THREE.Vector3(1, 0, 0) : size.y >= size.z ? new THREE.Vector3(0, 1, 0) : new THREE.Vector3(0, 0, 1);
307
+ for (let k = 0; k < 24; k++) {
308
+ const n = new THREE.Vector3(xx * dir.x + xy * dir.y + xz * dir.z, xy * dir.x + yy * dir.y + yz * dir.z, xz * dir.x + yz * dir.y + zz * dir.z);
309
+ if (!(n.lengthSq() > 0)) break;
310
+ dir.copy(n.normalize());
311
+ }
312
+ let t0 = Infinity, t1 = -Infinity, rad = 0;
313
+ for (const q of pts) {
314
+ const d = v.subVectors(q, c), t = d.dot(dir);
315
+ t0 = Math.min(t0, t); t1 = Math.max(t1, t);
316
+ rad = Math.max(rad, Math.sqrt(Math.max(0, d.lengthSq() - t * t)));
317
+ }
318
+ spine = { a: c.clone().addScaledVector(dir, t0), b: c.clone().addScaledVector(dir, t1), rad };
319
+ }
320
+ spines.set(id, spine);
321
+ return spine;
322
+ }
323
+
324
+ // How long a member is drawn, in px: its spine as projected plus its section either side (at Flo's scale), so a beam
325
+ // seen end-on, a diagonal one seen along its run, or a column seen from above counts as short. A spine running
326
+ // behind a perspective camera is cut at the near plane, never dropped, so passing the camera changes nothing in one
327
+ // step; nothing is cut at the far plane (an orthographic view's depth range has no bearing on how long it looks).
328
+ // 0 only when the whole member is behind the camera, or not drawn.
329
+ function memberPx(id, camera, w, h, scale) {
330
+ const sp = spineOf(id);
331
+ if (!sp) return 0;
332
+ pa.copy(sp.a).applyMatrix4(camera.matrixWorldInverse);
333
+ pb.copy(sp.b).applyMatrix4(camera.matrixWorldInverse);
334
+ if (!camera.isOrthographicCamera) {
335
+ const zn = -Math.max(1e-6, camera.near);
336
+ if (pa.z > zn && pb.z > zn) return 0;
337
+ if (pa.z > zn) pa.lerp(pb, (pa.z - zn) / (pa.z - pb.z));
338
+ else if (pb.z > zn) pb.lerp(pa, (pb.z - zn) / (pb.z - pa.z));
339
+ }
340
+ pa.applyMatrix4(camera.projectionMatrix); pb.applyMatrix4(camera.projectionMatrix);
341
+ const len = Math.hypot((pb.x - pa.x) * w / 2, (pb.y - pa.y) * h / 2);
342
+ return Number.isFinite(len) ? len + 2 * sp.rad * scale : 0;
343
+ }
344
+
345
+ // Screen pixels per mm at Flo, from the camera's own projection: in an orthographic view the same everywhere (depth
346
+ // plays no part, so a near or far plane passing Flo changes nothing); in perspective set by Flo's depth in front of
347
+ // the camera, which is also the scale off to the side of the view (the view's own px-per-mm helper reads the
348
+ // distance, not the depth, and so overstates Flo there). Null only with Flo behind a perspective camera, where it
349
+ // is not drawn.
350
+ function pxPerMm(camera, h) {
351
+ const m = camera.projectionMatrix.elements[5] * h / 2; // px per unit of view height, at unit depth or overall
352
+ if (camera.isOrthographicCamera) return m > 0 ? m : null;
353
+ const depth = -pa.copy(flo.object.position).applyMatrix4(camera.matrixWorldInverse).z;
354
+ const px = depth > 0 ? m / depth : NaN;
355
+ return Number.isFinite(px) && px > 0 ? px : null;
356
+ }
357
+
358
+ // Flo's radius in the model (mm) for this frame: floScreenRadiusPx turned back into model units at Flo, measured
359
+ // live from this camera, so the zoom never lags and every limit holds every frame. Hopping to a member that is
360
+ // much shorter or longer on screen, Flo takes the new member's size as it takes off: a step, owned on purpose
361
+ // (route B, #3380), because a blend over the hop kept breaking the limits it was meant to respect.
362
+ function worldRadius(camera) {
363
+ const v = getViewSize(), w = v?.w, h = v?.h;
364
+ camera.updateMatrixWorld();
365
+ const scale = w > 0 && h > 0 ? pxPerMm(camera, h) : null;
366
+ if (!scale) return modelR * sizeK; // no view yet, or Flo is behind the camera and not drawn
367
+ return floScreenRadiusPx({ sizeK, modelPx: modelDiag * scale, viewH: h, memberPx: memberPx(standingOn, camera, w, h, scale) }) / scale;
244
368
  }
245
369
 
246
370
  // Is the pointer on Flo? (The page shows its Minimize chip while it is.)
@@ -703,7 +703,8 @@ function init(canvas, theApi, options = {}) {
703
703
  // member, never in the Fit box and never a snap candidate. Needs flo.js (floPose), which the editor loads first.
704
704
  if (typeof window.floPose === 'function') {
705
705
  const reduce = window.matchMedia ? window.matchMedia('(prefers-reduced-motion: reduce)') : null;
706
- floView = createSteelFlo({ THREE, scene, meshById, getCamera: () => camera, getSceneBox: () => sceneBox, pxToWorldAt,
706
+ floView = createSteelFlo({ THREE, scene, meshById, getCamera: () => camera, getSceneBox: () => sceneBox,
707
+ getViewSize: () => canvasEl && { w: canvasEl.clientWidth, h: canvasEl.clientHeight },
707
708
  floPose: window.floPose, reducedMotion: !!reduce?.matches, enabled: floStartsShown(), onPerch: showFloCard });
708
709
  floReduceOff?.();
709
710
  const onReduce = () => floView?.setReducedMotion(reduce.matches);
@@ -1093,7 +1094,18 @@ function placePlate(mesh, el) {
1093
1094
  const w = Math.max(el.width || 10, 1), d = Math.max(el.depth || 10, 1), t = Math.max(el.thickness || 5, 0.5);
1094
1095
  const hw = w / 2, hd = d / 2;
1095
1096
  const shape = new THREE.Shape();
1096
- shape.moveTo(-hw, -hd); shape.lineTo(hw, -hd); shape.lineTo(hw, hd); shape.lineTo(-hw, hd); shape.closePath();
1097
+ // A custom connection's plate (#2303) is the polygon its definition drew — a tapered gusset, an L-shaped clip —
1098
+ // in plate-local (u, v) about `center`, the same outline the export sends. Every built-in plate has none and is
1099
+ // the centred width × depth rectangle. A degenerate outline (under 3 points, zero area, not finite) falls back to
1100
+ // the rectangle rather than drawing nothing.
1101
+ const outline = plateOutline(el.outline);
1102
+ if (outline) {
1103
+ shape.moveTo(outline[0][0], outline[0][1]);
1104
+ for (let i = 1; i < outline.length; i++) shape.lineTo(outline[i][0], outline[i][1]);
1105
+ shape.closePath();
1106
+ } else {
1107
+ shape.moveTo(-hw, -hd); shape.lineTo(hw, -hd); shape.lineTo(hw, hd); shape.lineTo(-hw, hd); shape.closePath();
1108
+ }
1097
1109
  for (const h of el.holes || []) { // bolts own the holes — punch one per fastener
1098
1110
  const r = Math.max((h.d || 0) / 2, 0.1);
1099
1111
  const hole = new THREE.Path(); hole.absarc(h.u || 0, h.v || 0, r, 0, Math.PI * 2, true);
@@ -1109,6 +1121,17 @@ function placePlate(mesh, el) {
1109
1121
  mesh.position.set(...(el.center || [0, 0, 0]));
1110
1122
  }
1111
1123
 
1124
+ // A plate's polygon outline as finite [u, v] pairs with a real area, or null to draw the rectangle.
1125
+ function plateOutline(raw) {
1126
+ if (!Array.isArray(raw) || raw.length < 3) return null;
1127
+ const pts = [];
1128
+ for (const p of raw) {
1129
+ if (!Array.isArray(p) || p.length < 2 || !Number.isFinite(p[0]) || !Number.isFinite(p[1])) return null;
1130
+ pts.push([p[0], p[1]]);
1131
+ }
1132
+ return Math.abs(shoelaceArea(pts)) > 1e-6 ? pts : null;
1133
+ }
1134
+
1112
1135
  // Signed area of a closed 2D polygon (shoelace) — used to reject a zero-area/collinear footprint.
1113
1136
  function shoelaceArea(pts) {
1114
1137
  let a = 0;
@@ -0,0 +1,161 @@
1
+ /**
2
+ * steel-custom-connection — what Inspect says about a custom connection built from standard parts (#2303 slice A).
3
+ *
4
+ * Pure: the editor hands it the joint, its definition row, the parts and fit facts the scene built, and the person's
5
+ * label switches; it returns the words and states to show. No DOM, so the server tests drive it directly.
6
+ *
7
+ * The rules it holds (owner rulings 2026-11-09, spec §4):
8
+ * - an AI-assisted connection says so ("AI-assisted"), unless the person turned the label off — then it still says
9
+ * the AI built it here, with "label off", because the switch hides the label on exports and names only;
10
+ * - a clean fit reads "Meets detailing rules · not strength-checked", never as checked: the AI never marks its own
11
+ * work, and green stays a person's sign-off;
12
+ * - a fit not met names the check; a person's acceptance is shown only while it still describes the connection
13
+ * (its identity matches what was built), and a stale one says the connection changed since.
14
+ */
15
+
16
+ /** Plain words for each fit measurement. Must equal `FIT_FACT_LABELS` in server/connection-readiness.ts (a test pins it). */
17
+ export const FIT_LABELS = Object.freeze({
18
+ 'bearing-contact': 'Bearing faces meet',
19
+ 'head-bearing': 'Bolt head bears on a ply',
20
+ 'nut-bearing': 'Nut bears on a ply',
21
+ 'clamped-grip': 'Clamped grip',
22
+ 'bolt-length': 'Bolt length',
23
+ 'clash-clearance': 'Clearance to other steel',
24
+ 'support-reach': 'Reach to the supporting member',
25
+ 'edge-distance': 'Edge distance',
26
+ 'weld-line': 'Weld on the joint line',
27
+ 'weld-size': 'Weld size against the rule minimum',
28
+ 'bolt-pitch': 'Bolt spacing against the rule minimum',
29
+ clash: 'Parts clear of each other and of the members',
30
+ });
31
+
32
+ const finite = (v) => typeof v === 'number' && Number.isFinite(v);
33
+
34
+ /** `fitFactVerdict` (server/steel-fit-rule.ts), exactly: 'within' | 'outside' | 'unmeasured'. */
35
+ export function fitVerdict(fact) {
36
+ if (!fact || !finite(fact.actualMm) || !finite(fact.limitMm) || !finite(fact.toleranceMm)) return 'unmeasured';
37
+ const within = fact.relation === 'equal'
38
+ ? Math.abs(fact.actualMm - fact.limitMm) <= fact.toleranceMm
39
+ : fact.relation === 'at-least'
40
+ ? fact.actualMm + fact.toleranceMm >= fact.limitMm
41
+ : fact.actualMm - fact.toleranceMm <= fact.limitMm;
42
+ if (within && fact.estimated === true) return 'unmeasured';
43
+ return within ? 'within' : 'outside';
44
+ }
45
+
46
+ /** Is the visible label shown for this connection? Mirrors `aiLabelShown` (server/connection-display-store.ts). */
47
+ export function labelShown(display, jointId) {
48
+ if (!display) return true;
49
+ if (display.model === 'hidden') return false;
50
+ return !(display.joints && Object.prototype.hasOwnProperty.call(display.joints, jointId));
51
+ }
52
+
53
+ const FACE_WORDS = {
54
+ 'web+': 'web', 'web-': 'web', 'flange-top-outer': 'top flange', 'flange-top-inner': 'top flange (inside face)',
55
+ 'flange-bot-outer': 'bottom flange', 'flange-bot-inner': 'bottom flange (inside face)',
56
+ 'leg-a-outer': 'leg', 'leg-a-inner': 'leg (inside face)', 'leg-b-outer': 'other leg', 'leg-b-inner': 'other leg (inside face)', end: 'end',
57
+ };
58
+
59
+ /**
60
+ * The connection's features in plain English, with lengths in the project's units (`fmt(mm)`), read from what was
61
+ * built (`parts`, the scene elements of this joint) where it built and from the definition otherwise.
62
+ */
63
+ export function describeFeatures(definition, parts, jointId, fmt) {
64
+ const features = Array.isArray(definition && definition.features) ? definition.features : [];
65
+ const list = Array.isArray(parts) ? parts : [];
66
+ const len = (mm) => (typeof fmt === 'function' ? fmt(mm) : `${Math.round(mm * 10) / 10} mm`);
67
+ const names = new Map(features.filter((f) => f && f.type === 'plate').map((f) => [f.id, f.name || 'plate']));
68
+ const ply = (p) => (p && p.role ? `the ${p.role}'s ${FACE_WORDS[p.face] || p.face}` : (names.get(p && p.feature) || (p && p.feature) || 'a part'));
69
+ const out = [];
70
+ for (const f of features) {
71
+ if (!f) continue;
72
+ if (f.type === 'plate') {
73
+ const part = list.find((p) => p.id === `${jointId}:${f.id}`);
74
+ const welds = features.filter((w) => w && w.type === 'weld' && Array.isArray(w.between) && w.between.some((b) => b && b.feature === f.id))
75
+ .map((w) => w.between.find((b) => !(b && b.feature === f.id))).filter(Boolean);
76
+ const sides = part && Array.isArray(part.outline) ? `, ${part.outline.length}-sided outline` : '';
77
+ out.push(`${part ? `${len(part.thickness)} ` : ''}${f.name || 'plate'}${sides}${welds.length ? `, welded to ${welds.map(ply).join(' and ')}` : ''}`);
78
+ } else if (f.type === 'bolt-group') {
79
+ const shanks = list.filter((p) => p.kind === 'rod' && typeof p.id === 'string' && p.id.startsWith(`${jointId}:${f.id}:bolt`));
80
+ const dia = shanks[0] && finite(shanks[0].d) ? `${len(shanks[0].d)} ` : '';
81
+ out.push(`${shanks.length ? `${shanks.length} × ` : ''}${dia}${f.grade || ''} bolts (${f.boltType === 'shop' ? 'shop' : 'site'}) through ${(f.plies || []).map(ply).join(' and ')}`);
82
+ } else if (f.type === 'weld') {
83
+ const bead = list.find((p) => p.kind === 'weld' && typeof p.id === 'string' && (p.id === `${jointId}:${f.id}` || p.id.startsWith(`${jointId}:${f.id}:`)));
84
+ out.push(`Fillet weld${bead && finite(bead.leg) ? ` ${len(bead.leg)}` : ''} between ${(f.between || []).map(ply).join(' and ')}${f.sides === 'both' ? ', both sides' : ''}`);
85
+ } else if (f.type === 'cut') {
86
+ out.push(`The ${f.member} is cut (${f.tool && f.tool.kind === 'box' ? 'a cope' : 'a round hole'})`);
87
+ } else if (f.type === 'trim') {
88
+ out.push(`The ${f.member} is cut back clear of the connection`);
89
+ }
90
+ }
91
+ return out;
92
+ }
93
+
94
+ /**
95
+ * Everything Inspect shows for one custom connection.
96
+ *
97
+ * @param {object} o
98
+ * @param {object} o.joint the `custom-parts` joint from the model
99
+ * @param {object|null} o.entry its `connection_definitions[]` row, or null when the model no longer has it
100
+ * @param {object|null} o.evidence the scene's fit evidence for this joint ({ facts, unresolved, identity }), or null
101
+ * @param {object[]} o.parts the scene elements of this joint
102
+ * @param {object|null} o.display the label switches ({ model, joints }), null = all shown
103
+ * @param {(mm:number)=>string} o.fmt project-unit length formatter
104
+ */
105
+ export function customConnectionView({ joint, entry, evidence, parts, display, fmt }) {
106
+ const def = entry && entry.definition ? entry.definition : null;
107
+ const provenance = joint && joint.provenance ? joint.provenance : null;
108
+ const aiAssisted = !!provenance && provenance.assisted === 'ai';
109
+ const shown = labelShown(display, joint && joint.id);
110
+ const modelShown = !display || display.model !== 'hidden';
111
+ const facts = evidence && Array.isArray(evidence.facts) ? evidence.facts : [];
112
+ const rows = facts.map((f) => ({ id: f.id, label: FIT_LABELS[f.kind] || f.kind, verdict: fitVerdict(f), estimated: f.estimated === true, clause: f.clause || null }));
113
+ const unmeasured = evidence && Array.isArray(evidence.unresolved) ? evidence.unresolved : [];
114
+ // What the engine could not measure is listed with the checks that are not met: it is not a pass.
115
+ const notMet = [...rows.filter((r) => r.verdict !== 'within'),
116
+ ...unmeasured.map((u) => ({ id: u, label: 'Not measured', verdict: 'unmeasured', estimated: false, clause: null, detail: u }))];
117
+ const passing = rows.filter((r) => r.verdict === 'within');
118
+ const accepted = Array.isArray(joint && joint.acceptedFailures) ? joint.acceptedFailures : [];
119
+ const identity = evidence && evidence.identity;
120
+ const current = accepted.filter((a) => a && a.identity === identity);
121
+ const keptAll = notMet.length > 0 && notMet.every((r) => current.some((a) => a.factId === r.id));
122
+ const stale = accepted.length > 0 && current.length < accepted.length;
123
+
124
+ let verdict;
125
+ if (!evidence) {
126
+ verdict = { tone: 'info', text: 'Fit not checked yet', tip: 'FloLess has not measured this connection in this view yet. It checks again when the model is rebuilt.' };
127
+ } else if (!notMet.length) {
128
+ verdict = { tone: 'neutral', text: 'Meets detailing rules · not strength-checked', tip: 'Every placement check FloLess measured is within its rule. That is not a strength check, and no one has signed it off.' };
129
+ } else if (keptAll) {
130
+ const when = current.map((a) => a.at).sort().pop();
131
+ verdict = { tone: 'neutral', text: 'Fit not met · kept by you', tip: `You chose to keep this connection built although these checks are not met: ${[...new Set(notMet.map((r) => r.label.toLowerCase()))].join('; ')}. The record and its exports say so.`,
132
+ hint: when ? `Kept built by you on ${String(when).slice(0, 10)}` : null };
133
+ } else if (stale) {
134
+ verdict = { tone: 'warn', text: 'Changed since you accepted it · fit not met', tip: 'The connection or its members changed after you kept it built, so your acceptance no longer describes it. Ask in AI Chat to check it again.' };
135
+ } else if (notMet.every((r) => r.label === 'Not measured')) {
136
+ verdict = { tone: 'warn', text: 'Some rule checks could not be measured', tip: 'FloLess could not measure every placement check on this connection, so it does not say it meets the rules. Ask in AI Chat what is missing.' };
137
+ } else {
138
+ verdict = { tone: 'warn', text: `Fit not met: ${[...new Set(notMet.filter((r) => r.label !== 'Not measured').map((r) => r.label))].join(', ')}`, tip: 'At least one placement check is outside its rule or could not be proved. Ask in AI Chat to rebuild it, or to keep it built anyway.' };
139
+ }
140
+
141
+ const assumptions = (def && def.provenance && Array.isArray(def.provenance.assumptions) ? def.provenance.assumptions : [])
142
+ .filter((a) => a && typeof a.param === 'string')
143
+ .map((a) => ({ param: a.param, value: finite(a.value) ? (typeof fmt === 'function' ? fmt(a.value) : `${a.value} mm`) : String(a.value), clause: a.clause || null,
144
+ basis: a.basis === 'rule-minimum' ? 'rule minimum' : a.basis === 'drawing' ? 'from the drawing' : 'set by a person' }));
145
+ const evidenceRef = def && def.provenance && def.provenance.evidence ? def.provenance.evidence.detailRef || def.provenance.evidence.sheetId || null : null;
146
+
147
+ return {
148
+ name: def ? def.name : 'Custom connection',
149
+ definitionMissing: !def,
150
+ aiAssisted, labelShown: shown, modelShown,
151
+ chip: aiAssisted
152
+ ? (shown
153
+ ? { text: 'AI-assisted', tip: 'The AI composed this connection from standard parts (plates, bolts, welds) because no standard connection type models the drawn detail.' }
154
+ : { text: 'AI-assisted · label off', tip: 'The AI composed this connection. You turned its label off, so exports and part names do not show it; FloLess’s record still keeps that the AI built it.' })
155
+ : null,
156
+ source: evidenceRef,
157
+ verdict, notMet, passing, unmeasured,
158
+ features: def ? describeFeatures(def, parts, joint.id, fmt) : [],
159
+ assumptions,
160
+ };
161
+ }