@floless/app 0.152.1 → 0.153.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/chat.js CHANGED
@@ -2716,7 +2716,17 @@
2716
2716
  label.textContent = looked ? 'Looked at' : 'Could not look at';
2717
2717
  const what = typeof payload.label === 'string' && payload.label ? payload.label : 'a file';
2718
2718
  const reason = !looked && typeof payload.reason === 'string' && payload.reason ? ` · ${payload.reason}` : '';
2719
- item.append(label, document.createTextNode(` ${what}${reason}`));
2719
+ // #2168: a long label (a picture's name plus the question it answers) is cut at a word, with an ellipsis,
2720
+ // and the whole text stays one hover away in the shared themed tooltip - never a mid-word cut.
2721
+ const EVIDENCE_LABEL_MAX = 110;
2722
+ let shown = what;
2723
+ if ([...what].length > EVIDENCE_LABEL_MAX) {
2724
+ const head = [...what].slice(0, EVIDENCE_LABEL_MAX).join('');
2725
+ const cut = head.search(/\s\S*$/);
2726
+ shown = `${(cut > EVIDENCE_LABEL_MAX / 2 ? head.slice(0, cut) : head).replace(/[\s,;:.-]+$/, '')}…`;
2727
+ item.dataset.tip = what;
2728
+ }
2729
+ item.append(label, document.createTextNode(` ${shown}${reason}`));
2720
2730
  return item;
2721
2731
  }
2722
2732
  label.textContent = event.type === 'error' && payload.outcome === 'not-sent' ? 'Not sent' : labels[event.type] || event.type;
@@ -2775,6 +2785,39 @@
2775
2785
  load(entry);
2776
2786
  }
2777
2787
 
2788
+ /*
2789
+ * #2163 / #2166 — A CARD THAT HAS NOT CHANGED IS NOT REBUILT. The feed is rebuilt on every streamed word and every
2790
+ * 5 s poll; rebuilding a card each time dropped the caret and focus of the field the person was typing in and
2791
+ * sent its inner list back to the top. So each card remembers the node it painted and the signature of the data
2792
+ * it was painted from; the next feed repaint hands back the SAME node while the signature holds (a node keeps its
2793
+ * input values, its caret and its pictures), and builds a new one only when something the card shows changed.
2794
+ * Typed text is not in the signature on purpose: it lives in the field and in `drafts`, and a keystroke is not a
2795
+ * reason to rebuild. Everything else a card paints from belongs in it.
2796
+ */
2797
+ const CARD_SIGNATURE_SKIP = new Set(['node', 'nodeSig', 'drafts', 'bulkDraft', 'rowsScroll', 'bodyScroll', 'reloadPending', 'loading']);
2798
+ function cardSignature(entry, eventId, sequence) {
2799
+ settleNotSent(entry);
2800
+ const sources = [];
2801
+ for (const [scope, source] of answerSources) {
2802
+ if (scope.split(':')[1] !== entry.questionId) continue;
2803
+ sources.push([scope, source.open, Boolean(source.note), source.files.map((file) => file.attachmentId), source.uploading, source.error]);
2804
+ }
2805
+ return JSON.stringify([eventId, sequence, sources, entry], (key, value) => {
2806
+ if (CARD_SIGNATURE_SKIP.has(key)) return undefined;
2807
+ if (value instanceof Map) return [...value];
2808
+ if (value instanceof Set) return [...value];
2809
+ return value;
2810
+ });
2811
+ }
2812
+ function rememberCard(entry, node, eventId, sequence) {
2813
+ entry.node = node;
2814
+ entry.nodeSig = cardSignature(entry, String(eventId || ''), String(sequence || ''));
2815
+ return node;
2816
+ }
2817
+ function reusableCard(entry, eventId, sequence) {
2818
+ return entry.node && entry.nodeSig === cardSignature(entry, String(eventId || ''), String(sequence || '')) ? entry.node : null;
2819
+ }
2820
+
2778
2821
  function heightCardState(requestId, questionId, chatId) {
2779
2822
  const key = `${requestId}/${questionId}`;
2780
2823
  let entry = heightCards.get(key);
@@ -2841,17 +2884,32 @@
2841
2884
  const old = ui.feed?.querySelector(`[data-height-question="${CSS.escape(entry.key)}"]`);
2842
2885
  if (!old) return;
2843
2886
  const focused = old.contains(document.activeElement) ? document.activeElement.dataset.commandId : null;
2844
- const next = paintHeightCard(entry, old.dataset.eventId, old.dataset.eventSequence);
2887
+ const caret = focused ? textCaret(document.activeElement) : null;
2888
+ const next = rememberCard(entry, paintHeightCard(entry, old.dataset.eventId, old.dataset.eventSequence), old.dataset.eventId, old.dataset.eventSequence);
2845
2889
  old.replaceWith(next);
2846
- if (focused) focusHeightControl(next, focused);
2890
+ if (focused) focusHeightControl(next, focused, caret);
2847
2891
  }
2848
2892
 
2849
- function focusHeightControl(card, commandId) {
2893
+ /** The caret of a focused text field, or null (a radio or checkbox has none, and reading it can throw). */
2894
+ function textCaret(control) {
2895
+ try {
2896
+ if (control?.tagName === 'INPUT' && (control.type === 'text' || !control.type) && typeof control.selectionStart === 'number') {
2897
+ return { start: control.selectionStart, end: control.selectionEnd, direction: control.selectionDirection || 'none' };
2898
+ }
2899
+ } catch { /* no caret */ }
2900
+ return null;
2901
+ }
2902
+
2903
+ function focusHeightControl(card, commandId, caret) {
2850
2904
  const control = [...card.querySelectorAll('[data-command-id]')].find((node) => node.dataset.commandId === commandId);
2851
2905
  if (!control) return false;
2852
2906
  control.focus({ preventScroll: true });
2853
2907
  // Text fields only: a radio or checkbox has no caret, and setSelectionRange on one throws (#1906).
2854
- if (control.tagName === 'INPUT' && (control.type === 'text' || !control.type)) control.setSelectionRange?.(control.value.length, control.value.length);
2908
+ if (control.tagName === 'INPUT' && (control.type === 'text' || !control.type)) {
2909
+ // Where the person's caret was, not the end: a repaint mid-word must not move it (#2163).
2910
+ if (caret) control.setSelectionRange?.(Math.min(caret.start, control.value.length), Math.min(caret.end, control.value.length), caret.direction);
2911
+ else control.setSelectionRange?.(control.value.length, control.value.length);
2912
+ }
2855
2913
  return true;
2856
2914
  }
2857
2915
 
@@ -2862,7 +2920,8 @@
2862
2920
  if (!entry.loading) refreshEarlierCards(heightCards, entry, loadHeightQuestion);
2863
2921
  loadHeightQuestion(entry);
2864
2922
  }
2865
- return paintHeightCard(entry, event.eventId, String(event.sequence));
2923
+ return reusableCard(entry, event.eventId, String(event.sequence))
2924
+ || rememberCard(entry, paintHeightCard(entry, event.eventId, String(event.sequence)), event.eventId, String(event.sequence));
2866
2925
  }
2867
2926
 
2868
2927
  function heightActionButton(label, commandId, instanceLabel, className, blockedReason) {
@@ -2971,11 +3030,13 @@
2971
3030
  const done = document.createElement('p'); done.className = 'ai-chat-height-done';
2972
3031
  // No paint-time state about the composer: it changes without this card repainting, so anything
2973
3032
  // painted here about it would go stale. The click decides (owner ruling 2026-10-02).
2974
- done.textContent = 'All answered. Press Tell the read, then Send, so the AI can carry on.';
3033
+ done.textContent = 'All answered. Tell the read puts the message in the box so you can add to it; Send to the read sends it now.';
2975
3034
  card.append(done);
2976
3035
  const tell = heightActionButton('Tell the read', `shell.chat-height-tell-read#${entry.questionId}`, questionLabel, 'ai-chat-filter-apply', null);
2977
3036
  tell.addEventListener('click', () => tellReadHeightsAnswered(entry));
2978
- actions.append(tell);
3037
+ const send = heightActionButton('Send to the read', `shell.chat-height-send-read#${entry.questionId}`, questionLabel, '', null);
3038
+ send.addEventListener('click', () => { void sendToReadAnswered(entry, heightTellText(entry), repaintHeightCard); });
3039
+ actions.append(tell, send);
2979
3040
  }
2980
3041
  actions.hidden = !actions.childNodes.length;
2981
3042
  card.append(actions);
@@ -3056,7 +3117,14 @@
3056
3117
  const submit = () => {
3057
3118
  if (use.getAttribute('aria-disabled') === 'true') return;
3058
3119
  const typed = input.value.trim();
3059
- if (!typed) { entry.cardError = 'Type a height first.'; repaintHeightCard(entry); return; }
3120
+ if (!typed) {
3121
+ // #2167: no height, but a note or a picture, is an honest answer: "I don't know it, look here".
3122
+ if (hasAnswerSource(`hb:${entry.questionId}`)) {
3123
+ submitHeightAnswers(entry, chosen.map((row) => ({ memberId: row.memberId, end: row.end, action: 'evidence' })), null, `hb:${entry.questionId}`);
3124
+ return;
3125
+ }
3126
+ entry.cardError = NO_HEIGHT_NO_SOURCE; repaintHeightCard(entry); return;
3127
+ }
3060
3128
  submitHeightAnswers(entry, chosen.map((row) => ({ memberId: row.memberId, end: row.end, action: 'type', typed })), null, `hb:${entry.questionId}`);
3061
3129
  };
3062
3130
  input.addEventListener('keydown', (event) => { if (event.key === 'Enter' && !event.isComposing) { event.preventDefault(); submit(); } });
@@ -3108,7 +3176,10 @@
3108
3176
  const done = document.createElement('div'); done.className = 'ai-chat-height-answered';
3109
3177
  const picture = row.status === 'evidence';
3110
3178
  const glyph = document.createElement('span'); glyph.className = 'ai-chat-height-glyph'; glyph.textContent = picture ? '…' : '✓'; glyph.setAttribute('aria-hidden', 'true');
3111
- const text = document.createElement('span'); text.textContent = picture ? 'Waiting for the read to read your picture' : heightAnswerText(row.answer);
3179
+ // #2167: a note with no picture and no height is honest about it: no height is claimed, the AI is asked to find it.
3180
+ const noteOnly = picture && !row.answer.evidence?.length;
3181
+ const text = document.createElement('span');
3182
+ text.textContent = noteOnly ? 'Note sent. The read will look for the height.' : picture ? 'Waiting for the read to read your picture' : heightAnswerText(row.answer);
3112
3183
  done.append(glyph, text);
3113
3184
  if (open) {
3114
3185
  const change = heightActionButton(picture ? 'Answer now' : 'Change', idFor('change'), instance, 'ai-chat-height-change', entry.busy ? 'A height is still being saved — wait for it to finish' : null);
@@ -3148,7 +3219,8 @@
3148
3219
  if (row.fromEvidence) {
3149
3220
  // #1906 "see snap": the proposal is the READ's reading of the person's picture, said as such.
3150
3221
  const tag = document.createElement('div'); tag.className = 'ai-chat-setup-evidence';
3151
- const t = document.createElement('span'); t.className = 'ai-chat-setup-tag'; t.textContent = 'THE READ’S READING OF YOUR PICTURE';
3222
+ const t = document.createElement('span'); t.className = 'ai-chat-setup-tag';
3223
+ t.textContent = !row.inherited?.length ? 'THE READ’S READING OF YOUR NOTE' : 'THE READ’S READING OF YOUR PICTURE';
3152
3224
  tag.append(t, document.createTextNode(' Check it before you confirm.'));
3153
3225
  item.append(tag);
3154
3226
  }
@@ -3168,7 +3240,11 @@
3168
3240
  const submitTyped = () => {
3169
3241
  if (use.getAttribute('aria-disabled') === 'true') return;
3170
3242
  const typed = input.value.trim();
3171
- if (!typed) { entry.rowErrors.set(key, 'Type a height first.'); repaintHeightCard(entry); return; }
3243
+ if (!typed) {
3244
+ // #2167: a note or a picture without a height is an answer too; the AI works the height out from it.
3245
+ if (hasAnswerSource(`h:${entry.questionId}:${key}`)) { submitHeightAnswers(entry, [{ memberId: row.memberId, end: row.end, action: 'evidence' }], key); return; }
3246
+ entry.rowErrors.set(key, NO_HEIGHT_NO_SOURCE); repaintHeightCard(entry); return;
3247
+ }
3172
3248
  submitHeightAnswers(entry, [{ memberId: row.memberId, end: row.end, action: 'type', typed }], key);
3173
3249
  };
3174
3250
  input.addEventListener('keydown', (event) => { if (event.key === 'Enter' && !event.isComposing) { event.preventDefault(); submitTyped(); } });
@@ -3285,6 +3361,13 @@
3285
3361
  return { ...(note ? { note } : {}), ...(source.files.length ? { evidence: source.files.map((file) => file.attachmentId) } : {}) };
3286
3362
  }
3287
3363
  const MAX_ANSWER_NOTE = 160;
3364
+ // #2167: asked for nothing at all. Said plainly, with the three things that would count.
3365
+ const NO_HEIGHT_NO_SOURCE = 'Type a height, or add a note or a picture and the AI will work it out.';
3366
+ /** True when the source box holds a note or an attached picture the person could send instead of a height. */
3367
+ function hasAnswerSource(scope) {
3368
+ const payload = answerSourcePayload(scope);
3369
+ return Boolean(payload.note || payload.evidence);
3370
+ }
3288
3371
  /**
3289
3372
  * An answer plus its source box. A "No single level" / "None of these" answer carries the person's
3290
3373
  * REQUIRED reason in `note`; a source note never replaces it (Codex review #1906) — both are kept, the
@@ -3541,8 +3624,8 @@
3541
3624
  function tellReadAnswered(entry, text, repaint) {
3542
3625
  if (!ui.input) return;
3543
3626
  const held = ui.input.value.trim();
3544
- if (held === text && !state.attachments.length) {
3545
- if (entry.cardError) { entry.cardError = ''; repaint(entry); }
3627
+ if (held.includes(text) && !state.attachments.length) {
3628
+ if (entry.cardError) { entry.cardError = ''; entry.notSent = ''; repaint(entry); }
3546
3629
  ui.send?.focus({ preventScroll: true });
3547
3630
  return;
3548
3631
  }
@@ -3559,6 +3642,44 @@
3559
3642
  ui.send?.focus({ preventScroll: true });
3560
3643
  }
3561
3644
 
3645
+ /*
3646
+ * SEND TO THE READ (#2169), beside Tell the read on both cards: the same message, sent at once through the chat's own
3647
+ * Send, for the person who has nothing to add. It never throws away what the person has already written: words
3648
+ * waiting in the box are kept and the card's message follows them, so ONE message goes with both (Tell the read, which
3649
+ * only fills an empty box, refuses instead). Files waiting in the box go too, as they do on any Send. If the chat will
3650
+ * not take a message right now (it is busy, or signed out) nothing is lost: the message is in the box and the card says so.
3651
+ */
3652
+ async function sendToReadAnswered(entry, text, repaint) {
3653
+ if (!ui.input) return;
3654
+ const held = ui.input.value.trim();
3655
+ // The box may already hold the card's message inside the person's own (they pressed Tell the read, then added words):
3656
+ // it is not appended a second time.
3657
+ const message = !held ? text : held.includes(text) ? held : `${held}\n\n${text}`;
3658
+ entry.cardError = ''; entry.notSent = '';
3659
+ ui.input.value = message;
3660
+ saveDraftSoon();
3661
+ updateSendState();
3662
+ if (ui.send?.disabled) {
3663
+ // sendTurn returns without a word when Send is disabled: say why, rather than point at a Send that cannot be pressed.
3664
+ entry.cardError = 'The chat cannot take a message right now (it may be busy, still starting or signed out). The message is waiting in the box below: Send becomes available when the chat is ready.';
3665
+ entry.notSent = message;
3666
+ repaint(entry);
3667
+ return;
3668
+ }
3669
+ await sendTurn();
3670
+ // Still there after Send returned: the chat did not take it.
3671
+ if (ui.input.value.trim() === message) { entry.cardError = 'Not sent yet. The message is in the box below: press Send when you are ready.'; entry.notSent = message; }
3672
+ repaint(entry);
3673
+ }
3674
+
3675
+ /*
3676
+ * A "not sent yet" notice describes the composer, so it lasts only while the composer still holds that message. Once
3677
+ * the person sends it with the composer's own Send (or clears it) the notice is stale, and the next paint drops it.
3678
+ */
3679
+ function settleNotSent(entry) {
3680
+ if (entry.notSent && !(ui.input?.value || '').includes(entry.notSent)) { entry.notSent = ''; entry.cardError = ''; }
3681
+ }
3682
+
3562
3683
  /*
3563
3684
  * #1906 — THE READ SETUP CARD: each plan view's scale, the model origin and each plan view's level,
3564
3685
  * answered by the person on one card. Painted from the server's own record (the chat event carries
@@ -3596,9 +3717,10 @@
3596
3717
  const old = ui.feed?.querySelector(`[data-setup-question="${CSS.escape(entry.key)}"]`);
3597
3718
  if (!old) return;
3598
3719
  const focused = old.contains(document.activeElement) ? document.activeElement.dataset.commandId : null;
3599
- const next = paintSetupCard(entry, old.dataset.eventId, old.dataset.eventSequence);
3720
+ const caret = focused ? textCaret(document.activeElement) : null;
3721
+ const next = rememberCard(entry, paintSetupCard(entry, old.dataset.eventId, old.dataset.eventSequence), old.dataset.eventId, old.dataset.eventSequence);
3600
3722
  old.replaceWith(next);
3601
- if (focused) focusHeightControl(next, focused);
3723
+ if (focused) focusHeightControl(next, focused, caret);
3602
3724
  }
3603
3725
 
3604
3726
  function renderSetupQuestion(event) {
@@ -3608,7 +3730,8 @@
3608
3730
  if (!entry.loading) refreshEarlierCards(setupCards, entry, loadSetupQuestion);
3609
3731
  loadSetupQuestion(entry);
3610
3732
  }
3611
- return paintSetupCard(entry, event.eventId, String(event.sequence));
3733
+ return reusableCard(entry, event.eventId, String(event.sequence))
3734
+ || rememberCard(entry, paintSetupCard(entry, event.eventId, String(event.sequence)), event.eventId, String(event.sequence));
3612
3735
  }
3613
3736
 
3614
3737
  const setupSettled = (row) => row.status === 'settled';
@@ -3627,7 +3750,7 @@
3627
3750
  }
3628
3751
  if (a.how === 'none') return `No single level: ${a.note}`;
3629
3752
  if (a.how === 'typed') return `You typed ${a.typed}`;
3630
- return `Confirmed ${a.shownAs}${a.basis === 'read-of-your-picture' ? ', the read’s reading of your picture' : ''}`;
3753
+ return `Confirmed ${a.shownAs}${a.basis === 'read-of-your-picture' ? ', the read’s reading of your picture' : a.basis === 'read-of-your-note' ? ', the read’s reading of your note' : ''}`;
3631
3754
  }
3632
3755
 
3633
3756
  function paintSetupCard(entry, eventId, sequence) {
@@ -3696,12 +3819,14 @@
3696
3819
  if (open && (allSettled || allAnswered)) {
3697
3820
  const done = document.createElement('p'); done.className = 'ai-chat-height-done';
3698
3821
  done.textContent = allSettled
3699
- ? 'All settled. Press Tell the read, then Send, so the AI can carry on.'
3700
- : 'All answered. Press Tell the read, then Send: the read looks at what you sent and asks you to confirm its reading here.';
3822
+ ? 'All settled. Tell the read puts the message in the box so you can add to it; Send to the read sends it now.'
3823
+ : 'All answered. Tell the read puts the message in the box so you can add to it; Send to the read sends it now. The read then looks at what you sent and asks you to confirm its reading here.';
3701
3824
  card.append(done);
3702
3825
  const tell = heightActionButton('Tell the read', `shell.chat-setup-tell-read#${entry.questionId}`, questionLabel, 'ai-chat-filter-apply', null);
3703
3826
  tell.addEventListener('click', () => tellReadAnswered(entry, setupTellText(entry), repaintSetupCard));
3704
- actions.append(tell);
3827
+ const send = heightActionButton('Send to the read', `shell.chat-setup-send-read#${entry.questionId}`, questionLabel, '', null);
3828
+ send.addEventListener('click', () => { void sendToReadAnswered(entry, setupTellText(entry), repaintSetupCard); });
3829
+ actions.append(tell, send);
3705
3830
  }
3706
3831
  actions.hidden = !actions.childNodes.length;
3707
3832
  card.append(actions);
@@ -4552,9 +4677,11 @@
4552
4677
  if (!focusedCommand?.startsWith('shell.chat-followup-') && !focusedCommand?.startsWith('shell.chat-filter-')
4553
4678
  && !focusedCommand?.startsWith('shell.chat-question') && !focusedCommand?.startsWith('shell.chat-height-')
4554
4679
  && !focusedCommand?.startsWith('shell.chat-setup-') && !focusedCommand?.startsWith('shell.chat-answer-')
4555
- && focusedCommand !== 'shell.chat-sign-in') return;
4556
- [...ui.feed.querySelectorAll('[data-command-id]')]
4557
- .find(control => control.dataset.commandId === focusedCommand && !control.disabled)?.focus({ preventScroll: true });
4680
+ && focusedCommand !== 'shell.chat-sign-in') return null;
4681
+ const control = [...ui.feed.querySelectorAll('[data-command-id]')]
4682
+ .find(control => control.dataset.commandId === focusedCommand && !control.disabled);
4683
+ control?.focus({ preventScroll: true });
4684
+ return control || null;
4558
4685
  }
4559
4686
 
4560
4687
  function paintEvents(options = {}) {
@@ -4565,6 +4692,16 @@
4565
4692
  const focusedNode = ui.feed.contains(document.activeElement) ? document.activeElement : null;
4566
4693
  const nearBottom = ui.feed.scrollHeight - ui.feed.scrollTop - ui.feed.clientHeight < 56;
4567
4694
  const scrollTop = ui.feed.scrollTop;
4695
+ // #2163 / #2166: the rebuild below forgets two things only a detach loses: the caret of the field being typed in
4696
+ // and each card list's scroll position. A card that did not change is the very same node (see `cardSignature`),
4697
+ // so noting both here and putting them back after is enough. (Inline: this function is lifted whole by tests.)
4698
+ let caret = null;
4699
+ try {
4700
+ if (focusedNode && typeof focusedNode.selectionStart === 'number' && typeof focusedNode.selectionEnd === 'number') {
4701
+ caret = { start: focusedNode.selectionStart, end: focusedNode.selectionEnd, direction: focusedNode.selectionDirection || 'none' };
4702
+ }
4703
+ } catch { caret = null; } // a checkbox or radio has no caret, and some engines throw on reading it
4704
+ for (const list of ui.feed.querySelectorAll('.ai-chat-height-rows')) list.keptScrollTop = list.scrollTop;
4568
4705
  ui.feed.replaceChildren();
4569
4706
  if (!state.events.length) {
4570
4707
  ui.feed.append(emptyFeedNotice());
@@ -4632,9 +4769,17 @@
4632
4769
  // never looks like a failed response. Recovery deliberately has no live indicator.
4633
4770
  if (turnIsVisiblyActive()) ui.feed.append(renderLiveStatus());
4634
4771
  }
4772
+ let refocused = null;
4635
4773
  if (focusedNode?.isConnected && ui.feed.contains(focusedNode)) {
4636
4774
  if (document.activeElement !== focusedNode) focusedNode.focus({ preventScroll: true });
4637
- } else restoreFeedFocus(focusedCommand);
4775
+ refocused = focusedNode;
4776
+ } else refocused = restoreFeedFocus(focusedCommand);
4777
+ if (refocused && caret) {
4778
+ try { refocused.setSelectionRange(caret.start, caret.end, caret.direction); } catch { /* no caret on this control */ }
4779
+ }
4780
+ for (const list of ui.feed.querySelectorAll('.ai-chat-height-rows')) {
4781
+ if (typeof list.keptScrollTop === 'number' && list.scrollTop !== list.keptScrollTop) list.scrollTop = list.keptScrollTop;
4782
+ }
4638
4783
  // Removing a focused control makes the browser lay out the half-built feed, which clamps its scroll near the top.
4639
4784
  // Scrolled up, the reader stays where they were.
4640
4785
  if (!nearBottom) ui.feed.scrollTop = scrollTop;
@@ -4813,6 +4958,10 @@
4813
4958
  // A Tekla read is never covered by a request-wide grant; it may instead be allowed for the whole chat (below).
4814
4959
  const explicitOnly = approvalIsExplicitOnly(approval) || Boolean(connectionCheck);
4815
4960
  const allowRequest = explicitOnly ? null : button('Approve for this request', 'shell.chat-approval-request', 'allow');
4961
+ // #2162: the same coverage as "Approve for this request", held for the rest of the conversation. Never on a card
4962
+ // that must ask every time (the same test that hides the request grant), nor in the Guide, which only reads.
4963
+ const allowSession = explicitOnly || state.chat?.initiator?.kind === 'guide' ? null
4964
+ : button('Approve for this conversation', 'shell.chat-approval-session', 'allow');
4816
4965
  const scope = document.createElement('span');
4817
4966
  scope.className = 'sr-only';
4818
4967
  scope.id = `chat-approval-request-help-${approval.approvalId}`;
@@ -4824,6 +4973,16 @@
4824
4973
  allowRequest.setAttribute('aria-describedby', scope.id);
4825
4974
  allowRequest.addEventListener('click', () => decideApproval('allow-request'));
4826
4975
  actions.append(deny, allow, allowRequest); card.append(heading, copy, actions, scope);
4976
+ if (allowSession) {
4977
+ const sessionScope = document.createElement('span');
4978
+ sessionScope.className = 'sr-only';
4979
+ sessionScope.id = `chat-approval-session-help-${approval.approvalId}`;
4980
+ sessionScope.textContent = 'Approve access actions for the rest of this conversation, not only this response, until you press Revoke. Your permission setting stays unchanged. Review checkpoints, Tekla reads and connector calls still ask, and so do file changes in a workspace conversation. Revoke it above the message box.';
4981
+ allowSession.dataset.tip = sessionScope.textContent;
4982
+ allowSession.setAttribute('aria-describedby', sessionScope.id);
4983
+ allowSession.addEventListener('click', () => decideApproval('allow-session'));
4984
+ actions.append(allowSession); card.append(sessionScope);
4985
+ }
4827
4986
  } else if (connectionCheck) {
4828
4987
  paintConnectionCheckApproval(card, approval, connectionCheck, { heading, copy, actions, deny, allow }, Number(allowanceRevision));
4829
4988
  ui.approvalTray.append(card);
@@ -5132,6 +5291,10 @@
5132
5291
  function paintApprovalScope() {
5133
5292
  const existing = shell.querySelector('.ai-chat-approval-scope');
5134
5293
  const turn = state.chat?.activeTurn;
5294
+ // #2162: a session grant belongs to the conversation, so it shows whatever the turn is doing, and instead of the
5295
+ // request strip, which it contains.
5296
+ const session = state.chat?.sessionApproval;
5297
+ if (session) { paintSessionApprovalScope(existing, session); return; }
5135
5298
  if (!turn?.accessApprovalGranted || !['running', 'awaiting-approval'].includes(state.chat?.state)) {
5136
5299
  existing?.remove(); return;
5137
5300
  }
@@ -5162,6 +5325,35 @@
5162
5325
  ui.approvalTray.prepend(card);
5163
5326
  }
5164
5327
 
5328
+ /** #2162: "Auto-approval on - this conversation" with its Revoke, kept while the grant stands (idle or running). */
5329
+ function paintSessionApprovalScope(existing, session) {
5330
+ const busy = state.revokingApprovalTurns.has('session');
5331
+ if (existing?.dataset.session === session.approvalId) {
5332
+ const revoke = existing.querySelector('button');
5333
+ revoke.disabled = busy;
5334
+ revoke.setAttribute('aria-busy', String(busy));
5335
+ return;
5336
+ }
5337
+ existing?.remove();
5338
+ const card = document.createElement('section');
5339
+ card.className = 'ai-chat-approval ai-chat-approval-scope';
5340
+ card.dataset.session = session.approvalId;
5341
+ const heading = document.createElement('strong');
5342
+ heading.textContent = 'Auto-approval on · this conversation';
5343
+ const explanation = document.createElement('span');
5344
+ explanation.className = 'sr-only';
5345
+ explanation.id = `chat-approval-session-help-${session.approvalId}`;
5346
+ explanation.textContent = 'Your permission setting is unchanged. Review checkpoints still ask every time, and Tekla reads, connector calls and file changes in a workspace conversation ask unless you allow them for this chat. Revoke asks before future access actions in this conversation; actions already approved may finish.';
5347
+ const revoke = button('Revoke', 'shell.chat-session-revoke');
5348
+ revoke.dataset.tip = explanation.textContent;
5349
+ revoke.setAttribute('aria-describedby', explanation.id);
5350
+ revoke.disabled = busy;
5351
+ revoke.setAttribute('aria-busy', String(busy));
5352
+ revoke.addEventListener('click', revokeSessionApproval);
5353
+ card.append(heading, revoke, explanation);
5354
+ ui.approvalTray.prepend(card);
5355
+ }
5356
+
5165
5357
  // FloLess installs its own tested copy of Claude Code / Codex. While that copy is being set up (or
5166
5358
  // could not be), the server reports it on the capability as `runtime`; this card renders that state
5167
5359
  // and relays the two user intents. The server owns every state and decision.
@@ -8182,6 +8374,7 @@
8182
8374
  // The request ended before the choice reached the AI (it was stopped or withdrawn): claim nothing about it.
8183
8375
  : outcome?.delivered === false ? 'This request ended before your choice reached the AI.'
8184
8376
  : decision === 'allow-request' ? 'Access auto-approval is on for this request.'
8377
+ : decision === 'allow-session' ? 'Access auto-approval is on for this conversation until you press Revoke, above the message box.'
8185
8378
  : decision === 'allow-chat' && approval.change ? 'File changes in this conversation’s scope are allowed for this chat. Commands and tools still ask. Revoke above the message box.'
8186
8379
  : decision === 'allow-chat' && approval.connectionCheck ? `Checks of ${approval.connectionCheck.name || 'this tool'} are allowed for this chat. Revoke them above the message box.`
8187
8380
  : decision === 'allow-chat' && approval.connector ? `${connectorLabel(approval.connector)} is allowed for this chat. Revoke it above the message box.`
@@ -8198,6 +8391,32 @@
8198
8391
  }
8199
8392
  }
8200
8393
 
8394
+ async function revokeSessionApproval() {
8395
+ const snapshot = captureChat();
8396
+ if (!snapshot || !state.chat?.sessionApproval || state.revokingApprovalTurns.has('session')) return;
8397
+ state.revokingApprovalTurns.add('session');
8398
+ paintApprovalScope();
8399
+ try {
8400
+ const result = await request(`/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/session-approval/revoke`, {
8401
+ method: 'POST', body: JSON.stringify({ owner: snapshot.scope.owner }),
8402
+ });
8403
+ if (!sameChat(snapshot)) return;
8404
+ // Say what is really left: a request-level grant still approves until that response finishes.
8405
+ const requestGrantLeft = result?.chat?.activeTurn?.accessApprovalGranted === true;
8406
+ announce(requestGrantLeft
8407
+ ? 'Auto-approval for this conversation is off. This request still auto-approves until it finishes, then access actions ask again.'
8408
+ : 'Auto-approval for this conversation is off. Future access actions will ask again. Actions already approved may finish.');
8409
+ await refreshConversation(snapshot.chatId, false);
8410
+ } catch (error) {
8411
+ if (!sameChat(snapshot)) return;
8412
+ report(error, 'Could not revoke auto-approval');
8413
+ await refreshConversation(snapshot.chatId, false);
8414
+ } finally {
8415
+ state.revokingApprovalTurns.delete('session');
8416
+ if (sameChat(snapshot)) paintApprovalScope();
8417
+ }
8418
+ }
8419
+
8201
8420
  async function revokeApprovalScope() {
8202
8421
  const turn = state.chat?.activeTurn;
8203
8422
  const snapshot = captureChat();
@@ -608,7 +608,7 @@
608
608
  /* ── the stop / sign-out question (web/leave-guard.js) ───────────────────── */
609
609
 
610
610
  def('leave.confirm', {
611
- label: 'Stop FloLess or Sign out',
611
+ label: 'Stop FloLess, Sign out or Leave the project',
612
612
  actsOn: 'Goes ahead — shown only when nothing is left unsaved',
613
613
  group: 'In the FloLess dialogs',
614
614
  persistence: 'external',
@@ -619,7 +619,7 @@
619
619
 
620
620
  def('leave.save', {
621
621
  label: 'Save and continue',
622
- actsOn: 'Saves everything listed, then stops FloLess or signs out',
622
+ actsOn: 'Saves everything listed, then stops FloLess, signs out or leaves the project',
623
623
  group: 'In the FloLess dialogs',
624
624
  persistence: 'working',
625
625
  interaction: 'instant',
@@ -630,7 +630,7 @@
630
630
 
631
631
  def('leave.discard', {
632
632
  label: 'Continue without saving',
633
- actsOn: 'Stops FloLess or signs out, leaving the listed changes unsaved',
633
+ actsOn: 'Stops FloLess, signs out or leaves the project, leaving the listed changes unsaved',
634
634
  group: 'In the FloLess dialogs',
635
635
  persistence: 'working',
636
636
  interaction: 'instant',
@@ -1327,20 +1327,41 @@
1327
1327
 
1328
1328
  def('shell.left-section-reorder', {
1329
1329
  label: 'Move panel',
1330
- actsOn: 'Moves the {instance} section above or below the other left-panel section',
1330
+ actsOn: 'Moves the {instance} section above, below or beside the other left-panel section — drag its header onto the other panel to stack them, or onto the strip beside the panel to place them in two columns',
1331
1331
  group: 'In the left panel',
1332
- key: 'Also: Alt + Arrow Up / Down',
1332
+ key: 'Also: Alt + Arrow keys (Left or Right places the panels in two columns)',
1333
1333
  persistence: 'local',
1334
1334
  interaction: 'gesture',
1335
1335
  risk: [],
1336
1336
  guidance: 'on-demand',
1337
1337
  });
1338
1338
 
1339
+ def('shell.left-section-drag', {
1340
+ label: 'Drag panel header',
1341
+ actsOn: 'Drag the {instance} section by its header onto the other panel to stack them, or onto the strip that opens beside the panel to place them in two columns',
1342
+ group: 'In the left panel',
1343
+ key: 'Keyboard: focus the ⠿ grip and press Alt + Arrow keys',
1344
+ persistence: 'local',
1345
+ interaction: 'gesture',
1346
+ risk: [],
1347
+ guidance: 'on-demand',
1348
+ });
1349
+
1350
+ def('shell.left-layout', {
1351
+ label: 'Side by side',
1352
+ actsOn: 'Places AI Chat and Model side by side as two columns, or stacks them again',
1353
+ group: 'In the left panel',
1354
+ persistence: 'local',
1355
+ interaction: 'instant',
1356
+ risk: [],
1357
+ guidance: 'on-demand',
1358
+ });
1359
+
1339
1360
  def('shell.left-panel-split', {
1340
1361
  label: 'Resize left-panel sections',
1341
- actsOn: 'Changes the height shared by AI Chat and Model',
1362
+ actsOn: 'Changes the height shared by AI Chat and Model, or their widths when they sit in two columns',
1342
1363
  group: 'Between AI Chat and Model',
1343
- key: 'Also: Arrow Up / Down · hold Shift for a larger step · Enter resets',
1364
+ key: 'Also: Arrow Up / Down (Left / Right in two columns) · hold Shift for a larger step · Enter resets',
1344
1365
  persistence: 'local',
1345
1366
  interaction: 'gesture',
1346
1367
  risk: [],
@@ -1513,12 +1534,13 @@
1513
1534
 
1514
1535
  def('shell.workspace-back', {
1515
1536
  label: 'Back to projects',
1516
- actsOn: 'Leaves this project for the project list',
1537
+ actsOn: 'Leaves this project for the project list — asks first if the Drawing Filter or model editor has changes not saved yet',
1517
1538
  group: 'In the project workspace',
1518
1539
  persistence: 'local',
1519
1540
  interaction: 'instant',
1520
1541
  risk: [],
1521
1542
  guidance: 'on-demand',
1543
+ why: 'Nothing is asked when everything is saved. Otherwise you can save and leave, leave without saving, or stay.',
1522
1544
  });
1523
1545
 
1524
1546
  def('shell.workspace-step', {
@@ -2251,6 +2273,10 @@
2251
2273
  label: 'Tell the read', actsOn: 'Puts a short message saying {instance} is answered in the message box and moves to Send; you send it', anyInstance: 'a height question',
2252
2274
  group: 'In AI Chat', persistence: 'none', interaction: 'instant', risk: [], guidance: 'on-demand',
2253
2275
  });
2276
+ def('shell.chat-height-send-read', {
2277
+ label: 'Send to the read', actsOn: 'Sends a short message saying {instance} is answered to the AI now, after anything already in the message box', anyInstance: 'a height question',
2278
+ group: 'In AI Chat', persistence: 'external', interaction: 'instant', risk: ['costs-time', 'costs-money'], guidance: 'on-demand',
2279
+ });
2254
2280
  def('shell.chat-height-retry', {
2255
2281
  label: 'Load the height question again', actsOn: 'Reads {instance} from FloLess again', anyInstance: 'a height question',
2256
2282
  group: 'In AI Chat', persistence: 'none', interaction: 'instant', risk: [], guidance: 'on-demand',
@@ -2365,6 +2391,10 @@
2365
2391
  label: 'Tell the read', actsOn: 'Puts a short message saying {instance} is answered in the message box and moves to Send; you send it', anyInstance: 'a setup question',
2366
2392
  group: 'In AI Chat', persistence: 'none', interaction: 'instant', risk: [], guidance: 'on-demand',
2367
2393
  });
2394
+ def('shell.chat-setup-send-read', {
2395
+ label: 'Send to the read', actsOn: 'Sends a short message saying {instance} is answered to the AI now, after anything already in the message box', anyInstance: 'a setup question',
2396
+ group: 'In AI Chat', persistence: 'external', interaction: 'instant', risk: ['costs-time', 'costs-money'], guidance: 'on-demand',
2397
+ });
2368
2398
  def('shell.chat-setup-retry', {
2369
2399
  label: 'Load the read setup again', actsOn: 'Reads {instance} from FloLess again', anyInstance: 'a setup question',
2370
2400
  group: 'In AI Chat', persistence: 'none', interaction: 'instant', risk: [], guidance: 'on-demand',
@@ -2417,6 +2447,11 @@
2417
2447
  group: 'In AI Chat', persistence: 'external', interaction: 'instant', risk: ['destructive'], guidance: 'on-demand',
2418
2448
  why: 'Saves approving each access action one by one during this response. A Tekla read is not covered: it has its own Allow for this chat.',
2419
2449
  });
2450
+ def('shell.chat-approval-session', {
2451
+ label: 'Approve for this conversation', actsOn: 'Allows this access action and every later access action in this conversation, not only this response, until you press Revoke (it stays on if you close the chat or restart FloLess); keeps your permission setting and review checkpoints unchanged; Tekla reads, connector calls and file changes in a workspace conversation still ask',
2452
+ group: 'In AI Chat', persistence: 'external', interaction: 'instant', risk: ['destructive'], guidance: 'on-demand',
2453
+ why: 'Saves approving each access action one by one for the rest of this conversation, for example during a long drawing read. Revoke it above the message box at any time.',
2454
+ });
2420
2455
  def('shell.chat-tekla-allow-chat', {
2421
2456
  label: 'Allow Tekla reads for this chat', actsOn: 'Allows this Tekla read and every later read this chat may ask for, of the open model name or the parts you have selected, without asking again in this conversation until you revoke it',
2422
2457
  group: 'In AI Chat', persistence: 'external', interaction: 'instant', risk: [], guidance: 'on-demand',
@@ -2554,6 +2589,10 @@
2554
2589
  label: 'Revoke request auto-approval', actsOn: 'Asks before future access actions in this request; actions already approved may finish',
2555
2590
  group: 'In AI Chat', persistence: 'working', interaction: 'instant', risk: [], guidance: 'on-demand',
2556
2591
  });
2592
+ def('shell.chat-session-revoke', {
2593
+ label: 'Revoke conversation auto-approval', actsOn: 'Asks before future access actions in this conversation; actions already approved may finish',
2594
+ group: 'In AI Chat', persistence: 'working', interaction: 'instant', risk: [], guidance: 'on-demand',
2595
+ });
2557
2596
  def('shell.chat-runtime-retry', {
2558
2597
  label: 'Try setting up again', actsOn: 'Starts installing the AI tool version FloLess was tested with again after setup failed',
2559
2598
  group: 'In AI Chat', persistence: 'external', interaction: 'instant', risk: ['costs-time'], guidance: 'on-demand',