@floless/app 0.133.2 → 0.134.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.
package/dist/web/aware.js CHANGED
@@ -171,6 +171,15 @@
171
171
  const readInstructorAnswerIds = storedAnswerIds(ANSWER_READ_KEY);
172
172
  let answerGlowTimer = null;
173
173
  let leftPaneTab = 'narrative';
174
+ // Per-id collapse state (session only, never persisted): a card is collapsed iff its id is here.
175
+ // Keyed by id, never position — cards insert at the TOP, so an index would drift under new arrivals.
176
+ const collapsedAnswerIds = new Set();
177
+ // Deferred-commit removal. `×` hides the card immediately and starts a timer; the DELETE fires only
178
+ // when the timer elapses, so an Undo within the window is a pure client-side restore with no server
179
+ // round-trip. The id stays in `pendingDeleteAnswerIds` (filtered out of every render) until then.
180
+ const pendingDeleteAnswerIds = new Set();
181
+ const answerDeleteTimers = new Map();
182
+ const ANSWER_UNDO_MS = 6000;
174
183
 
175
184
  function selectLeftPaneTab(tab, { focus = false, explicit = false } = {}) {
176
185
  leftPaneTab = tab === 'answers' ? 'answers' : 'narrative';
@@ -289,7 +298,8 @@
289
298
  }
290
299
 
291
300
  function answerCard(answer, isNew) {
292
- const subject = escapeHtml(answer.instructorContext.subject || 'this context');
301
+ const subjectText = answer.instructorContext.subject || 'this context';
302
+ const subject = escapeHtml(subjectText);
293
303
  const prose = answerProse(answer.answer);
294
304
  const runtime = answer.runtime === 'claude' ? 'Claude' : answer.runtime === 'codex' ? 'Codex' : 'terminal AI';
295
305
  const card = msgEl(`aware instructor-answer${isNew ? ' instructor-answer-new' : ''}`,
@@ -297,9 +307,226 @@
297
307
  `<span class="answer-new-badge">New answer</span>${prose}`,
298
308
  answer.finishedAt);
299
309
  card.dataset.answerId = answer.id;
310
+
311
+ // A fresh arrival always renders expanded — the glow-and-scroll is meant to reveal its content, so
312
+ // a card that lit up and then hid its own body would be actively confusing. Otherwise honour the
313
+ // per-id collapse the user set.
314
+ const collapsed = !isNew && collapsedAnswerIds.has(answer.id);
315
+ if (collapsed) card.classList.add('answer-collapsed');
316
+ const body = card.querySelector('.body');
317
+ const bodyId = `answer-body-${answer.id}`;
318
+ if (body) body.id = bodyId;
319
+ const who = card.querySelector('.who');
320
+ if (who) who.classList.add('answer-who');
321
+
322
+ // The chevron owns the disclosure and the × owns the removal — two independent buttons, never one
323
+ // nested in the other. A header that wraps a nested × steals the delete button's hit box the moment
324
+ // closest() routes a click (see reference_nested_control_in_role_button_card.md).
325
+ const chevron = document.createElement('button');
326
+ chevron.type = 'button';
327
+ chevron.className = 'answer-collapse-toggle';
328
+ chevron.textContent = '▸';
329
+ chevron.setAttribute('aria-controls', bodyId);
330
+ setCollapseToggleState(chevron, collapsed, `${runtime} · ${subjectText}`);
331
+ chevron.onclick = () => toggleAnswerCollapse(answer.id);
332
+
333
+ const del = document.createElement('button');
334
+ del.type = 'button';
335
+ del.className = 'answer-del';
336
+ del.textContent = '×';
337
+ del.setAttribute('aria-label', `Remove this answer, ${runtime} · ${subjectText}`);
338
+ del.setAttribute('data-tip', 'Remove this answer');
339
+ del.onclick = () => removeAnswerWithUndo(answer.id);
340
+
341
+ if (who) {
342
+ who.insertBefore(chevron, who.firstChild); // chevron | name … time | ×
343
+ who.appendChild(del);
344
+ }
300
345
  return card;
301
346
  }
302
347
 
348
+ // One place that writes the chevron's per-state ARIA/tooltip, so the toggle and the card class can
349
+ // never drift. `expanded` name folds the subject in so a screen reader tells the per-card toggles
350
+ // apart from each other and from the bulk one.
351
+ function setCollapseToggleState(chevron, collapsed, name) {
352
+ chevron.setAttribute('aria-expanded', String(!collapsed));
353
+ chevron.setAttribute('aria-label', `${collapsed ? 'Expand' : 'Collapse'} this answer, ${name}`);
354
+ chevron.setAttribute('data-tip', collapsed ? 'Expand this answer' : 'Collapse this answer');
355
+ }
356
+
357
+ function announceAnswers(message) {
358
+ const status = document.getElementById('narrative-answer-status');
359
+ if (status) status.textContent = message;
360
+ }
361
+
362
+ // Toggle one card in place (no full re-render): flip the class + the chevron's ARIA, then re-derive
363
+ // the bulk button's aggregate label from what is now on screen.
364
+ function toggleAnswerCollapse(id) {
365
+ const willCollapse = !collapsedAnswerIds.has(id);
366
+ if (willCollapse) collapsedAnswerIds.add(id); else collapsedAnswerIds.delete(id);
367
+ const card = document.querySelector(`#ai-answers [data-answer-id="${CSS.escape(id)}"]`);
368
+ if (card) {
369
+ card.classList.toggle('answer-collapsed', willCollapse);
370
+ const chevron = card.querySelector('.answer-collapse-toggle');
371
+ const name = card.querySelector('.who-name')?.textContent || 'this context';
372
+ if (chevron) setCollapseToggleState(chevron, willCollapse, name);
373
+ }
374
+ syncAnswerBulkToggle();
375
+ }
376
+
377
+ // The bulk toggle's label is DERIVED, never stored: any card expanded → it offers "Collapse all";
378
+ // none expanded → "Expand all". A fresh arrival (always expanded) naturally returns it to the mixed
379
+ // state with no special-casing. Reads the live DOM so a single-card toggle keeps it honest too.
380
+ function syncAnswerBulkToggle() {
381
+ const button = document.getElementById('answers-collapse-all');
382
+ if (!button) return;
383
+ const cards = [...document.querySelectorAll('#ai-answers [data-answer-id]')];
384
+ const anyExpanded = cards.some((card) => !card.classList.contains('answer-collapsed'));
385
+ button.textContent = anyExpanded ? 'Collapse all' : 'Expand all';
386
+ button.setAttribute('aria-expanded', String(anyExpanded));
387
+ button.setAttribute('data-tip', anyExpanded ? 'Collapse every answer shown here' : 'Expand every answer shown here');
388
+ }
389
+
390
+ function toggleAllAnswers(visible) {
391
+ const anyExpanded = visible.some((answer) => !collapsedAnswerIds.has(answer.id));
392
+ for (const answer of visible) {
393
+ if (anyExpanded) collapsedAnswerIds.add(answer.id); else collapsedAnswerIds.delete(answer.id);
394
+ }
395
+ renderInstructorAnswers({ revealNew: false });
396
+ announceAnswers(`${anyExpanded ? 'Collapsed' : 'Expanded'} ${visible.length} answer${visible.length === 1 ? '' : 's'}`);
397
+ }
398
+
399
+ // The bulk row: a count on the left, the two actions on the right — the same shape as the Requests
400
+ // scope row. Built fresh each render (its handlers close over THIS paint's `visible`), which is also
401
+ // why "Clear all" acts on the snapshot the user is looking at, never a freshly re-derived scope.
402
+ function answersToolbar(visible) {
403
+ const bar = document.createElement('div');
404
+ bar.className = 'answers-toolbar';
405
+ bar.id = 'answers-toolbar';
406
+
407
+ const count = document.createElement('span');
408
+ count.className = 'answers-count';
409
+ count.textContent = `${visible.length} answer${visible.length === 1 ? '' : 's'}`;
410
+
411
+ const spacer = document.createElement('span');
412
+ spacer.className = 'answers-toolbar-spacer';
413
+ spacer.setAttribute('aria-hidden', 'true');
414
+
415
+ const collapseAll = document.createElement('button');
416
+ collapseAll.type = 'button';
417
+ collapseAll.id = 'answers-collapse-all';
418
+ collapseAll.className = 'answers-bulk';
419
+ collapseAll.setAttribute('data-command-id', 'shell.answers-collapse-all');
420
+ collapseAll.setAttribute('aria-label', 'Collapse or expand all answers');
421
+ collapseAll.textContent = 'Collapse all';
422
+ collapseAll.onclick = () => toggleAllAnswers(visible);
423
+
424
+ const clearAll = document.createElement('button');
425
+ clearAll.type = 'button';
426
+ clearAll.id = 'answers-clear-all';
427
+ clearAll.className = 'answers-bulk answers-clear';
428
+ clearAll.setAttribute('data-command-id', 'shell.answers-clear');
429
+ clearAll.textContent = 'Clear all';
430
+ clearAll.setAttribute('data-tip', visible.length === 1 ? 'Remove this answer' : `Remove all ${visible.length} answers shown here`);
431
+ clearAll.onclick = () => clearAllAnswers(visible);
432
+
433
+ bar.append(count, spacer, collapseAll, clearAll);
434
+ return bar;
435
+ }
436
+
437
+ // `×` on a card: hide it now, offer Undo, and only commit the (permanent) server delete once the
438
+ // window elapses. Keyed by id throughout so a card arriving mid-window can't shift what a timer or a
439
+ // focus target points at.
440
+ function removeAnswerWithUndo(id) {
441
+ if (pendingDeleteAnswerIds.has(id)) return;
442
+ // The card that will take this one's on-screen slot, captured BEFORE the re-render, so focus never
443
+ // falls to <body>. nextElementSibling first (the one just below), else the one above — a heuristic
444
+ // that holds whatever the sort order is.
445
+ const removing = document.querySelector(`#ai-answers [data-answer-id="${CSS.escape(id)}"]`);
446
+ const neighbourId = removing?.nextElementSibling?.dataset?.answerId
447
+ || removing?.previousElementSibling?.dataset?.answerId
448
+ || null;
449
+
450
+ pendingDeleteAnswerIds.add(id);
451
+ renderInstructorAnswers({ revealNew: false });
452
+ const focusTarget = neighbourId
453
+ ? document.querySelector(`#ai-answers [data-answer-id="${CSS.escape(neighbourId)}"] .answer-collapse-toggle`)
454
+ : (document.getElementById('answers-collapse-all') || document.querySelector('.ai-answers-empty'));
455
+ focusTarget?.focus?.({ preventScroll: true });
456
+ announceAnswers('Answer removed');
457
+
458
+ const commit = async () => {
459
+ answerDeleteTimers.delete(id);
460
+ // The reload is INSIDE the guard: a blip on loadRequests() after the DELETE already landed would
461
+ // otherwise reject this setTimeout-fired async fn as an unhandled rejection (no toast, no log) and
462
+ // strand the id in pendingDeleteAnswerIds forever. `finally` drops the pending id and repaints on
463
+ // every path, matching how deleteOneRequest wraps DELETE + reload + render in one try.
464
+ try {
465
+ await api(`/api/requests/${encodeURIComponent(id)}`, { method: 'DELETE' });
466
+ await loadRequests(); // refreshes instructorAnswers (the row is gone server-side now)
467
+ } catch (error) {
468
+ reportErr(error);
469
+ } finally {
470
+ pendingDeleteAnswerIds.delete(id);
471
+ renderInstructorAnswers({ revealNew: false });
472
+ }
473
+ };
474
+ answerDeleteTimers.set(id, setTimeout(commit, ANSWER_UNDO_MS));
475
+
476
+ // Pass ANSWER_UNDO_MS so the visible toast and the commit window are ONE number, not two literals
477
+ // that happen to match — bump the constant and the toast follows.
478
+ showUndoToast('Answer removed', () => {
479
+ const timer = answerDeleteTimers.get(id);
480
+ if (!timer) return; // already committed — a late Undo is a safe no-op
481
+ clearTimeout(timer);
482
+ answerDeleteTimers.delete(id);
483
+ pendingDeleteAnswerIds.delete(id);
484
+ renderInstructorAnswers({ revealNew: false });
485
+ document.querySelector(`#ai-answers [data-answer-id="${CSS.escape(id)}"] .answer-collapse-toggle`)?.focus?.({ preventScroll: true });
486
+ announceAnswers('Removal undone');
487
+ }, ANSWER_UNDO_MS);
488
+ }
489
+
490
+ // "Clear all" removes every answer in the SHOWN scope, confirmed once. No undo here (that was the
491
+ // deliberate split: undo for a single mis-click, a confirm for the bulk wipe). Per-id DELETE in a
492
+ // loop, exactly how the Requests dialog clears a scoped set — an answer's id IS its request id.
493
+ async function clearAllAnswers(visible) {
494
+ const ids = visible.map((answer) => answer.id);
495
+ if (!ids.length) return;
496
+ if (!(await confirmClearAnswers(ids.length))) return;
497
+ try {
498
+ for (const id of ids) await api(`/api/requests/${encodeURIComponent(id)}`, { method: 'DELETE' });
499
+ await loadRequests();
500
+ renderInstructorAnswers({ revealNew: false });
501
+ announceAnswers(`Cleared ${ids.length} answer${ids.length === 1 ? '' : 's'}`);
502
+ showToast(`Cleared ${ids.length} answer${ids.length === 1 ? '' : 's'}`, 'ok');
503
+ } catch (error) { reportErr(error); }
504
+ }
505
+
506
+ function confirmClearAnswers(count) {
507
+ return new Promise((resolve) => {
508
+ const modal = document.getElementById('answers-clear-modal');
509
+ const sub = document.getElementById('answers-clear-sub');
510
+ const confirm = document.getElementById('answers-clear-confirm');
511
+ const cancel = document.getElementById('answers-clear-cancel');
512
+ if (!modal || !confirm || !cancel) { resolve(false); return; }
513
+ if (sub) sub.textContent = `Remove ${count === 1 ? 'this answer' : `all ${count} answers`} shown here? This can’t be undone.`;
514
+ showModal(modal);
515
+ setTimeout(() => cancel.focus(), 0); // Cancel holds default focus, mirroring the routine delete
516
+ const done = (result) => {
517
+ hideModal(modal);
518
+ confirm.onclick = cancel.onclick = modal.onclick = null;
519
+ document.removeEventListener('keydown', onKey, true);
520
+ resolve(result);
521
+ };
522
+ const onKey = (event) => { if (event.key === 'Escape') { event.preventDefault(); done(false); } };
523
+ confirm.onclick = () => done(true);
524
+ cancel.onclick = () => done(false);
525
+ onBackdropDismiss(modal, () => done(false));
526
+ document.addEventListener('keydown', onKey, true);
527
+ });
528
+ }
529
+
303
530
  function acceptInstructorAnswers(answers, { initial = false } = {}) {
304
531
  instructorAnswers = answers;
305
532
  if (initial) {
@@ -327,8 +554,13 @@
327
554
  function renderInstructorAnswers({ revealNew = true } = {}) {
328
555
  const feed = document.getElementById('ai-answers');
329
556
  if (!feed) return;
330
- const visible = instructorAnswers.filter(answerInVisibleScope);
331
- const wasNearBottom = feed.scrollHeight - feed.scrollTop - feed.clientHeight < 72;
557
+ // A card mid-way through the deferred-delete window is filtered out of every render, so a poll
558
+ // that refreshes the feed can't flash it back into view before its Undo window closes.
559
+ const visible = instructorAnswers.filter(answerInVisibleScope).filter((answer) => !pendingDeleteAnswerIds.has(answer.id));
560
+ // Newest-first: the latest answer sits at the top. A blind reverse of the stored order would ride
561
+ // on filesystem read order; sorting on finishedAt is the ordering the user actually asked for.
562
+ const ordered = [...visible].sort((a, b) => String(b.finishedAt || '').localeCompare(String(a.finishedAt || '')));
563
+ const wasNearTop = feed.scrollTop < 72;
332
564
  const unseen = revealNew ? visible.filter((answer) => arrivedInstructorAnswerIds.has(answer.id)) : [];
333
565
  const unreadCount = visible.filter((answer) => !readInstructorAnswerIds.has(answer.id)).length;
334
566
  const unreadBadge = document.getElementById('answer-unread');
@@ -341,12 +573,14 @@
341
573
  else answersTab?.removeAttribute('aria-label');
342
574
  const newAnswer = unseen.length ? unseen[unseen.length - 1] : null;
343
575
  feed.innerHTML = '';
344
- if (!visible.length) {
576
+ if (!ordered.length) {
345
577
  const scope = wsRequestScope?.kind === 'project' ? 'this project' : wsRequestScope ? 'Workspaces' : 'this workflow';
346
- feed.innerHTML = `<div class="ai-answers-empty">No AI answers for ${scope} yet. Direct answers you start from Instructor will appear here.</div>`;
578
+ feed.innerHTML = `<div class="ai-answers-empty" tabindex="-1">No AI answers for ${scope} yet. Direct answers you start from Instructor will appear here.</div>`;
347
579
  } else {
348
- visible.forEach((answer) => feed.appendChild(answerCard(answer, answer === newAnswer)));
580
+ feed.appendChild(answersToolbar(ordered)); // sticky bulk row — first child, hidden with an empty feed by simply not existing
581
+ ordered.forEach((answer) => feed.appendChild(answerCard(answer, answer === newAnswer)));
349
582
  }
583
+ syncAnswerBulkToggle();
350
584
  if (!newAnswer) {
351
585
  return;
352
586
  }
@@ -369,7 +603,9 @@
369
603
  document.getElementById('ai-answers-tab')?.classList.add('instructor-answer-new');
370
604
  }
371
605
  const card = feed.querySelector(`[data-answer-id="${CSS.escape(newAnswer.id)}"]`);
372
- if (card && !obscured && (wasCollapsed || (paneAlreadyOpenOnAnswers && wasNearBottom))) requestAnimationFrame(() => card.scrollIntoView({ block: 'nearest' }));
606
+ // Newest-first puts the arrival at the TOP, so the auto-scroll follows a reader sitting near the
607
+ // top — not the bottom, which now holds the oldest answers someone may be mid-read of.
608
+ if (card && !obscured && (wasCollapsed || (paneAlreadyOpenOnAnswers && wasNearTop))) requestAnimationFrame(() => card.scrollIntoView({ block: 'nearest' }));
373
609
  const status = document.getElementById('narrative-answer-status');
374
610
  if (status) status.textContent = wasCollapsed && !obscured
375
611
  ? `Terminal AI answered about ${newAnswer.instructorContext.subject}. AI answers opened.`
@@ -1089,6 +1089,38 @@
1089
1089
  guidance: 'on-demand',
1090
1090
  });
1091
1091
 
1092
+ def('shell.answers-collapse-all', {
1093
+ label: 'Collapse or expand all answers',
1094
+ actsOn: 'Folds every answer down to its header, or opens them all back up',
1095
+ group: 'In the AI answers tab',
1096
+ persistence: 'none',
1097
+ interaction: 'instant',
1098
+ risk: [],
1099
+ guidance: 'on-demand',
1100
+ why: 'A long answer you have read can get out of the way without being removed.',
1101
+ });
1102
+
1103
+ def('shell.answers-clear', {
1104
+ label: 'Clear all answers',
1105
+ actsOn: 'Removes every answer shown here after you confirm',
1106
+ group: 'In the AI answers tab',
1107
+ persistence: 'working',
1108
+ interaction: 'dialog',
1109
+ risk: ['destructive'],
1110
+ guidance: 'on-demand',
1111
+ why: 'Answers are durable records, so the bulk wipe asks first — a single one has an Undo instead.',
1112
+ });
1113
+
1114
+ def('shell.answers-clear-confirm', {
1115
+ label: 'Clear the AI answers',
1116
+ actsOn: 'Removes the answers for good',
1117
+ group: 'In the AI answers tab',
1118
+ persistence: 'working',
1119
+ interaction: 'instant',
1120
+ risk: ['destructive'],
1121
+ guidance: 'on-demand',
1122
+ });
1123
+
1092
1124
  def('shell.request-help-copy', {
1093
1125
  label: 'Copy the request',
1094
1126
  actsOn: 'Puts this request on your clipboard',
@@ -877,6 +877,17 @@
877
877
  guidance: 'on-demand',
878
878
  });
879
879
 
880
+ def('steel.position-gizmo', {
881
+ label: 'Position handle',
882
+ actsOn: 'Shows a drag handle on the selected member for setting its Profile Position in 3D',
883
+ group: 'In the ⋯ menu — Display',
884
+ persistence: 'local',
885
+ interaction: 'instant',
886
+ risk: [],
887
+ guidance: 'on-demand',
888
+ why: 'Turns on a Tekla-style handle at the selected member’s start point: drag the blue arrow to set the depth offset, the green arrow to set the width offset, and the red arc to set the rotation — all read in the Edit frame shown above Profile Position, the same values the Inspect panel sets, here by hand in the 3D view. Double-click a handle to type an exact value instead (it bypasses the snap). The handle works whatever coordinate system is active, and it hides the coordinate-system gizmo while it is up (and vice-versa) so their blue/green axes never clash. The reference line never moves; ¼" and 5° snaps apply unless you hold Shift, and Esc cancels a drag.',
889
+ });
890
+
880
891
  def('steel.show-property-labels', {
881
892
  label: 'Show property labels',
882
893
  actsOn: 'Shows or hides the property labels on the plan',
@@ -1971,4 +1982,15 @@
1971
1982
  guidance: 'on-demand',
1972
1983
  why: 'Looks along the member from its start point with the work-line marked — the quickest way to see whether a face and an offset put the steel where you meant.',
1973
1984
  });
1985
+
1986
+ def('steel.position-from-member', {
1987
+ label: 'From member',
1988
+ actsOn: 'Sets the coordinate system to this member’s own axes',
1989
+ group: 'In the Inspect panel',
1990
+ persistence: 'working',
1991
+ interaction: 'instant',
1992
+ risk: [],
1993
+ guidance: 'on-demand',
1994
+ why: 'Adopts the selected member’s own axes — including its roll — as the 3D coordinate system, so its Rotation then reads 0 and Depth/Width read against its own faces. The steel does not move; only the frame the numbers are read against changes, and adopting again is a no-op. 3D view only.',
1995
+ });
1974
1996
  })();
@@ -1095,6 +1095,19 @@
1095
1095
  </div>
1096
1096
  </div>
1097
1097
 
1098
+ <!-- Confirm bulk-clearing the AI answers. Answers are durable result records, not queue rows, so the
1099
+ bulk wipe confirms (individual × has an Undo instead — the two safety nets are deliberately split). -->
1100
+ <div class="modal-backdrop" id="answers-clear-modal">
1101
+ <div class="modal">
1102
+ <div class="modal-title">Clear AI answers</div>
1103
+ <div class="modal-sub" id="answers-clear-sub"></div>
1104
+ <div class="modal-actions">
1105
+ <button data-command-id="shell.dialog-cancel#clearing the AI answers" id="answers-clear-cancel">Cancel</button>
1106
+ <button data-command-id="shell.answers-clear-confirm" id="answers-clear-confirm">Clear all</button>
1107
+ </div>
1108
+ </div>
1109
+ </div>
1110
+
1098
1111
  <!-- Graft into agent — build an agent from a foreign tool (DLL / C# source /
1099
1112
  NuGet / OpenAPI / …). The wizard body (#graft-body) is built per-step in
1100
1113
  aware.js. AWARE reads the source + builds the agent (incl. its Tekla
@@ -533,7 +533,7 @@
533
533
  // the shell
534
534
  'In the header', 'In the workflow picker', 'In the project picker',
535
535
  'In the project workspace', 'On the workflow canvas',
536
- 'In the Narrative panel', 'In the node Inspect panel', 'In the Instructor strip',
536
+ 'In the Narrative panel', 'In the AI answers tab', 'In the node Inspect panel', 'In the Instructor strip',
537
537
  'In the ≡ menu', 'In the footer',
538
538
  'In the contract editor', 'In the report viewer', 'In the guide',
539
539
  'In the agent library', 'In the requests list', 'In the run request dialog', 'In the Routines dialog',
@@ -1542,6 +1542,31 @@ function cross3(a, b) {
1542
1542
  return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
1543
1543
  }
1544
1544
 
1545
+ /**
1546
+ * The world part frame the Profile Position gizmo (slice 3a) draws its arrows in, for a given authoring
1547
+ * basis. It is the SAME frame the bake and the inspector read (`partFrame`), so a dragged handle moves
1548
+ * the steel exactly where a typed offset would: width = `frame.y`, depth = `frame.z`, member axis =
1549
+ * `frame.x` (basis-independent). The coordinate system's normal `up` is derived from the basis
1550
+ * (`x × y` for a canonical orthonormal basis), never stored — global uses world Z.
1551
+ *
1552
+ * Returns null (the gizmo then shows nothing) for a zero-length member or a basis that is not a usable
1553
+ * frame, so a caller never has to guard `partFrame`'s throw on a degenerate `up`/`upX`.
1554
+ *
1555
+ * @param {number[]} refFrom the authored reference-line start (the gizmo anchor)
1556
+ * @param {number[]} refTo the authored reference-line end
1557
+ * @param {{kind?:string, x?:number[], y?:number[]}} basis a `positionAuthoringBasis()` snapshot
1558
+ * @returns {{x:number[], y:number[], z:number[], degenerate:boolean}|null}
1559
+ */
1560
+ export function positionGizmoFrame(refFrom, refTo, basis) {
1561
+ let up, upX;
1562
+ if (!basis || basis.kind === 'global') { up = [0, 0, 1]; upX = [1, 0, 0]; }
1563
+ else {
1564
+ if (!finiteVec3(basis.x) || !finiteVec3(basis.y)) return null;
1565
+ up = cross3(basis.x, basis.y); upX = [basis.x[0], basis.x[1], basis.x[2]];
1566
+ }
1567
+ try { return partFrame(refFrom, refTo, up, upX); } catch (_) { return null; }
1568
+ }
1569
+
1545
1570
  /**
1546
1571
  * `partFrame` with its axes reordered into the MESH's local order — the one place that says which frame
1547
1572
  * axis each of a member geometry's local axes becomes. `orientMember` (`web/steel-3d-view.js`) feeds the
@@ -1626,6 +1651,68 @@ export function positionOffsetVector(frame, ex, depthFace, widthFace, rotDeg, wi
1626
1651
  ];
1627
1652
  }
1628
1653
 
1654
+ // The ¼" / 5° snaps the 3D Profile Position gizmo applies to a dragged offset / roll (Shift = free).
1655
+ export const POSITION_OFFSET_SNAP_MM = 25.4 / 4;
1656
+ export const POSITION_ROT_SNAP_DEG = 5;
1657
+
1658
+ /** Round `value` to the nearest multiple of `step` (the gizmo's ¼"/5° drag snap); `step<=0` = free. */
1659
+ export function snapToStep(value, step) {
1660
+ return step > 0 ? Math.round(value / step) * step : value;
1661
+ }
1662
+
1663
+ /**
1664
+ * The fold applied to a roll (deg) before it is COMMITTED to storage — the SAME `r % 360` (signed) the
1665
+ * Inspect panel commit already uses (`steel-editor.html:6755`/`:7053`). One shared helper so the 3D gizmo's
1666
+ * drag/type commit and the panel can never store two different conventions: a re-expressed base is generically
1667
+ * off-grid, and a cross-seam arc drag accumulates a continuous angle that can run past ±360, so the raw value
1668
+ * must be folded — but signed, because a detailer reads "−5°", not "355°". A non-finite roll reads as 0.
1669
+ */
1670
+ export function rollCommitNorm(deg) {
1671
+ return (typeof deg === 'number' && isFinite(deg) ? deg : 0) % 360;
1672
+ }
1673
+
1674
+ /**
1675
+ * The shortest-arc increment (rad) from `prevRad` to `curRad`, folded into (−π, π]. Used to CONTINUOUSLY
1676
+ * unwrap the roll arc during a drag: summing these steps tracks the true swept angle, so crossing the ±180°
1677
+ * seam adds a small step instead of the ~2π jump a bare `cur − start` produces (which moved a beam ~360° in one
1678
+ * tick). Both `atan2` outputs live in (−π, π]; this returns their signed shortest difference.
1679
+ */
1680
+ export function unwrapAngleStep(prevRad, curRad) {
1681
+ let d = curRad - prevRad;
1682
+ while (d > Math.PI) d -= 2 * Math.PI;
1683
+ while (d <= -Math.PI) d += 2 * Math.PI;
1684
+ return d;
1685
+ }
1686
+
1687
+ /**
1688
+ * The world translation the steel undergoes when ONE numeric Profile Position offset changes by
1689
+ * `deltaMm` (the depth offset for `axis:'depth'`, the width offset for `'width'`), holding the other
1690
+ * offset, the named faces and the roll fixed. This is exactly `positionOffsetVector`'s linear response
1691
+ * to that offset — factored out so the 3D gizmo's live preview and the bake CANNOT drift apart. A
1692
+ * hand-copied second copy of this sign/swing convention is precisely the class of silent error the
1693
+ * clash-and-exact-placement rule exists to catch, so the gizmo's preview MUST call this, never re-derive
1694
+ * it. `frame` is a `partFrame` triple; the delta is measured on the section's own (unrotated) axis and
1695
+ * then swung by `rotDeg`, matching §1.3's position-then-rotate order.
1696
+ *
1697
+ * @param {{y:number[], z:number[]}} frame
1698
+ * @param {'depth'|'width'} axis
1699
+ * @param {number} deltaMm
1700
+ * @param {number} rotDeg
1701
+ * @returns {[number, number, number]}
1702
+ */
1703
+ export function positionSwingDelta(frame, axis, deltaMm, rotDeg) {
1704
+ const th = ((typeof rotDeg === 'number' && isFinite(rotDeg) ? rotDeg : 0) * Math.PI) / 180;
1705
+ const c = Math.cos(th), s = Math.sin(th), d = typeof deltaMm === 'number' && isFinite(deltaMm) ? deltaMm : 0;
1706
+ // width offset (oy) swings to c·y + s·z ; depth offset (oz) swings to −s·y + c·z — the exact partial
1707
+ // derivatives of positionOffsetVector w.r.t. widthOffMm / depthOffMm.
1708
+ const wy = axis === 'depth' ? -s : c, wz = axis === 'depth' ? c : s;
1709
+ return [
1710
+ d * (wy * frame.y[0] + wz * frame.z[0]),
1711
+ d * (wy * frame.y[1] + wz * frame.z[1]),
1712
+ d * (wy * frame.y[2] + wz * frame.z[2]),
1713
+ ];
1714
+ }
1715
+
1629
1716
  /**
1630
1717
  * Reversing a member's two work points must leave the STEEL exactly where it is — and it takes TWO
1631
1718
  * transforms, one per branch of `partFrame`. An earlier draft had one rule and it was wrong for a column.