@floless/app 0.141.0 → 0.142.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.
@@ -319,6 +319,12 @@
319
319
  model: document.getElementById('ws-frame-model'),
320
320
  drawings: document.getElementById('ws-frame-drawings'),
321
321
  };
322
+ // A project's editors autosave, but a Stop FloLess / Sign Out mid-save would still lose the last
323
+ // change — let the leave guard see (and flush) them. See web/leave-guard.js.
324
+ if (window.flolessLeaveGuard) {
325
+ window.flolessLeaveGuard.registerFrame(frames.model, 'workspace-model');
326
+ window.flolessLeaveGuard.registerFrame(frames.drawings, 'workspace-drawings');
327
+ }
322
328
  let lastModelDisposeReceipt = null;
323
329
  function disposeModelEditorFrame(reason) {
324
330
  // The left Model section drops the departing editor's tree now, not at the next load event, so a
@@ -2413,7 +2419,6 @@
2413
2419
  const assertProjectSourceReadable = (file) => file.slice(0, Math.min(file.size, 1)).arrayBuffer();
2414
2420
 
2415
2421
  const $projectSetup = document.getElementById('project-setup-modal');
2416
- const $projectSetupDialog = $projectSetup && $projectSetup.querySelector('.project-setup-dialog');
2417
2422
  const $projectSetupTitle = document.getElementById('project-setup-title');
2418
2423
  const $projectSetupSourceName = document.getElementById('project-setup-source-name');
2419
2424
  const $projectSetupSourceCount = document.getElementById('project-setup-source-count');
@@ -2423,7 +2428,7 @@
2423
2428
  const $projectSetupName = document.getElementById('project-setup-name');
2424
2429
  const $projectSetupStandard = document.getElementById('project-setup-standard');
2425
2430
  const $projectSetupError = document.getElementById('project-setup-error');
2426
- const $projectSetupChatMeta = document.getElementById('project-setup-chat-meta');
2431
+ const $projectSetupProvider = document.getElementById('project-setup-provider');
2427
2432
  const $projectSetupCancel = document.getElementById('project-setup-cancel');
2428
2433
  const $projectSetupCreateOnly = document.getElementById('project-setup-create-only');
2429
2434
  const $projectSetupCreate = document.getElementById('project-setup-create');
@@ -2493,24 +2498,152 @@
2493
2498
  projectSetupState.busy = !!busy;
2494
2499
  $projectSetup.setAttribute('aria-busy', String(!!busy));
2495
2500
  for (const control of $projectSetup.querySelectorAll('button, input')) control.disabled = !!busy;
2501
+ // Waiting for FloLess to set an AI up creates nothing yet, so Cancel stays usable (#1607).
2502
+ if (busy && projectSetupState.settingUp) $projectSetupCancel.disabled = false;
2496
2503
  $projectSetupCreate.textContent = label || 'Create project & start chat';
2497
- $projectSetupCreateOnly.textContent = busy ? 'Creating…' : (projectSetupState.kind === 'rvt' ? 'Create project' : 'Create project only');
2504
+ $projectSetupCreateOnly.textContent = busy && !projectSetupState.settingUp ? 'Creating…' : (projectSetupState.kind === 'rvt' ? 'Create project' : 'Create project only');
2498
2505
  if (!busy) {
2499
2506
  $projectSetupCreate.disabled = !projectSetupReady();
2500
2507
  $projectSetupCreateOnly.disabled = !projectSetupReady();
2501
2508
  }
2502
2509
  }
2503
2510
 
2511
+ const PROJECT_CHAT_PROVIDER_NAMES = { claude: 'Claude', codex: 'Codex' };
2512
+
2513
+ // Whether this dialog may start the conversation with this AI (#1607): the one answer the default
2514
+ // (preferredChatProvider), the Requests Start affordances and the AI Chat empty state share —
2515
+ // 'ready', 'setup' (FloLess sets up its own copy when the conversation opens) or 'unavailable'.
2516
+ function projectSetupProviderReadiness(runtime) {
2517
+ return runtime ? (bridge.chatRuntimeReadiness?.(runtime) || 'unavailable') : 'unavailable';
2518
+ }
2519
+
2520
+ // Which AI "Create project & start chat" starts the conversation with (#1605): the person's own
2521
+ // pick while it can still start, otherwise the AI FloLess would pick anyway — so the one-click
2522
+ // path still works for anyone who does not care. A Revit project starts no chat, so it has none.
2523
+ // Every answer is checked against what can start now: preferredChatProvider() prefers the open
2524
+ // conversation's AI, which may since have been uninstalled, and a choice that cannot start must
2525
+ // never be the one shown as chosen and sent.
2526
+ function projectSetupProvider(state) {
2527
+ if (!state || state.kind === 'rvt') return null;
2528
+ const runtimes = bridge.chatProviderRuntimes?.() || [];
2529
+ const readiness = (id) => (id ? projectSetupProviderReadiness(runtimes.find((runtime) => runtime.id === id)) : 'unavailable');
2530
+ const canStart = (id) => readiness(id) !== 'unavailable';
2531
+ if (canStart(state.chatProvider)) return state.chatProvider;
2532
+ const preferred = bridge.preferredChatProvider?.() || null;
2533
+ if (canStart(preferred)) return preferred;
2534
+ // An AI that is ready now before one FloLess still has to set up (#1607).
2535
+ const ids = Object.keys(PROJECT_CHAT_PROVIDER_NAMES);
2536
+ return ids.find((id) => readiness(id) === 'ready') || ids.find(canStart) || null;
2537
+ }
2538
+
2539
+ // The per-AI line under the choice (#1607). A copy FloLess sets up itself is offered, and its line
2540
+ // says it is not set up yet, so the wait after Create is no surprise.
2541
+ function projectSetupProviderLine(id, runtime, readiness, state, accountLabel) {
2542
+ const name = PROJECT_CHAT_PROVIDER_NAMES[id] || id;
2543
+ const managed = runtime && runtime.managed && typeof runtime.managed === 'object' ? runtime.managed : null;
2544
+ if (readiness === 'ready') {
2545
+ return typeof accountLabel !== 'function' ? name
2546
+ : accountLabel(id, state.providersRead ? runtime.account : { state: 'checking' });
2547
+ }
2548
+ if (readiness === 'setup') {
2549
+ if (managed?.state === 'preparing') return `${name} · setting up…`;
2550
+ // Nothing retries on its own here: pressing Create is what tries the setup again.
2551
+ if (managed?.state === 'failed') return `${name} · setup failed, Create tries again`;
2552
+ return `${name} · not set up yet`;
2553
+ }
2554
+ return managed ? `${name} · couldn’t be set up` : `${name} · not found`;
2555
+ }
2556
+
2557
+ // Why an AI that cannot start cannot be chosen here, and where to go instead.
2558
+ function projectSetupBlockedReason(id, runtime) {
2559
+ const name = PROJECT_CHAT_PROVIDER_NAMES[id] || id;
2560
+ const other = PROJECT_CHAT_PROVIDER_NAMES[id === 'claude' ? 'codex' : 'claude'];
2561
+ // FloLess runs its own copy here, and that copy failed in a way it cannot retry by itself.
2562
+ if (runtime && runtime.managed && typeof runtime.managed === 'object') {
2563
+ return `FloLess could not set up ${name} on this computer. Choose ${other} here, or open AI Chat with ${name} to see why.`;
2564
+ }
2565
+ // "Did not find", not "not installed": the sentence says only what is known.
2566
+ return `FloLess did not find ${name} on this computer. Choose ${other} here, or open AI Chat to set ${name} up.`;
2567
+ }
2568
+
2569
+ // The Claude / Codex choice, in the same shape as the AI Chat empty state: two buttons, and each
2570
+ // one's own sign-in underneath. With no AI able to start, the whole choice is hidden together with
2571
+ // Create project & start chat, rather than offering buttons that cannot be pressed. An AI that
2572
+ // cannot start next to one that can stays visible and focusable, and says why it cannot be chosen.
2573
+ function paintProjectSetupProviders(state, provider) {
2574
+ if (!$projectSetupProvider) return;
2575
+ $projectSetupProvider.hidden = !provider;
2576
+ if (!provider) return;
2577
+ const runtimes = bridge.chatProviderRuntimes?.() || [];
2578
+ const accountLabel = window.flolessChat?.providerAccountLabel;
2579
+ for (const button of $projectSetupProvider.querySelectorAll('[data-chat-provider]')) {
2580
+ const id = button.dataset.chatProvider;
2581
+ const runtime = runtimes.find((row) => row.id === id);
2582
+ const readiness = projectSetupProviderReadiness(runtime);
2583
+ button.setAttribute('aria-pressed', String(id === provider));
2584
+ if (readiness !== 'unavailable') {
2585
+ button.removeAttribute('aria-disabled');
2586
+ delete button.dataset.tip;
2587
+ delete button.dataset.blockedReason;
2588
+ } else {
2589
+ const why = projectSetupBlockedReason(id, runtime);
2590
+ button.setAttribute('aria-disabled', 'true');
2591
+ button.dataset.tip = why;
2592
+ button.dataset.blockedReason = why;
2593
+ }
2594
+ const status = $projectSetupProvider.querySelector(`[data-chat-provider-status="${id}"]`);
2595
+ if (!status) continue;
2596
+ // While FloLess sets this AI up for the dialog, its line carries the AI Chat panel's own
2597
+ // sentence for that setup (a polite region, so it is read once per change).
2598
+ const text = state.settingUp && state.settingUp.provider === id && state.settingUp.text
2599
+ ? state.settingUp.text
2600
+ : projectSetupProviderLine(id, runtime, readiness, state, accountLabel);
2601
+ // The row is a polite live region: an unchanged line must not be read out again.
2602
+ if (status.textContent !== text) status.textContent = text;
2603
+ }
2604
+ }
2605
+
2606
+ // Pressing Claude or Codex. An AI that cannot start is aria-disabled (focusable, so its reason can
2607
+ // be read) and pressing it changes nothing; nor does a press while the project is being created.
2608
+ function chooseProjectSetupProvider(button) {
2609
+ if (!button || !projectSetupState || projectSetupState.busy) return;
2610
+ if (button.getAttribute('aria-disabled') === 'true') return;
2611
+ projectSetupState.chatProvider = button.dataset.chatProvider;
2612
+ renderProjectSetup();
2613
+ }
2614
+
2615
+ // Reads which AIs can start and who each is signed in as, when the dialog opens. A read that
2616
+ // failed, or a sign-in the server could not settle (a slow or failed CLI status read), is
2617
+ // transient, so it is asked again a few times while the dialog stays open instead of leaving
2618
+ // "could not check" — or no choice at all — as the only basis for the choice.
2619
+ async function refreshProjectSetupProviders(state, attempt = 0) {
2620
+ const read = await bridge.refreshChatProviders?.();
2621
+ if (projectSetupState !== state) return;
2622
+ state.providersRead = true;
2623
+ renderProjectSetup();
2624
+ // Only a READY AI's sign-in can settle: a copy FloLess has not set up yet answers "unknown" by
2625
+ // construction, and asking again would never change that (#1607).
2626
+ const unsettled = read === false || (bridge.chatProviderRuntimes?.() || []).some((runtime) => projectSetupProviderReadiness(runtime) === 'ready'
2627
+ && !['signed-in', 'signed-out', 'no-identity'].includes(runtime.account?.state));
2628
+ if (unsettled && attempt < 3) {
2629
+ setTimeout(() => {
2630
+ if (projectSetupState === state) void refreshProjectSetupProviders(state, attempt + 1);
2631
+ }, 4000);
2632
+ }
2633
+ }
2634
+
2635
+ // Repaint only the AI lines while the dialog waits for a setup; a full render would re-enable the
2636
+ // create buttons under the wait.
2637
+ function renderProjectSetupWhileBusy(state) {
2638
+ if (projectSetupState !== state) return;
2639
+ paintProjectSetupProviders(state, projectSetupProvider(state));
2640
+ }
2641
+
2504
2642
  function renderProjectSetup() {
2505
2643
  const state = projectSetupState;
2506
2644
  if (!state) return;
2507
- const provider = state.kind === 'rvt' ? null : (bridge.preferredChatProvider?.() || null);
2508
- if ($projectSetupChatMeta) {
2509
- $projectSetupChatMeta.hidden = !provider;
2510
- $projectSetupChatMeta.textContent = provider
2511
- ? `Starts with ${provider === 'claude' ? 'Claude Code' : provider === 'codex' ? 'Codex' : provider} · can edit this project folder`
2512
- : '';
2513
- }
2645
+ const provider = projectSetupProvider(state);
2646
+ paintProjectSetupProviders(state, provider);
2514
2647
  $projectSetupCreate.hidden = !provider;
2515
2648
  $projectSetupCreateOnly.classList.toggle('primary', !provider);
2516
2649
  $projectSetupTitle.textContent = `New ${descDisplayName(state.templateId)} project`;
@@ -2540,7 +2673,11 @@
2540
2673
 
2541
2674
  function closeProjectSetup({ restoreFocus = true } = {}) {
2542
2675
  const state = projectSetupState;
2543
- if (!state || state.busy) return;
2676
+ // Busy refuses a close, except while FloLess is only setting an AI up: nothing exists yet, and
2677
+ // clearing projectSetupState is what tells that wait to stop (the install itself carries on).
2678
+ if (!state || (state.busy && !state.settingUp)) return;
2679
+ // Leave no control disabled behind for the next time the dialog opens.
2680
+ if (state.busy) { state.settingUp = null; setProjectSetupBusy(false); }
2544
2681
  projectSetupState = null;
2545
2682
  $projectSetup.classList.remove('show');
2546
2683
  $projectSetup.removeAttribute('aria-busy');
@@ -2585,11 +2722,41 @@
2585
2722
  async function createProjectFromSetup(startChat = true) {
2586
2723
  const state = projectSetupState;
2587
2724
  if (!projectSetupReady(state) || state.busy) return;
2588
- if (startChat && !bridge.preferredChatProvider?.()) {
2725
+ const provider = startChat ? projectSetupProvider(state) : null;
2726
+ if (startChat && !provider) {
2589
2727
  setProjectSetupError('Sign in to Claude or Codex before starting this project in AI Chat. You can still create the project only.');
2590
2728
  return;
2591
2729
  }
2592
2730
  setProjectSetupError('');
2731
+ if (startChat && projectSetupProviderReadiness((bridge.chatProviderRuntimes?.() || []).find((row) => row.id === provider)) === 'setup') {
2732
+ // FloLess has to set its own copy of this AI up before the conversation's first message can be
2733
+ // sent (#1607). Wait for that here, before anything is created, so a failed or cancelled setup
2734
+ // leaves no project and no dead conversation behind.
2735
+ const name = PROJECT_CHAT_PROVIDER_NAMES[provider] || provider;
2736
+ state.settingUp = { provider, text: '' };
2737
+ setProjectSetupBusy(true, `Setting up ${name}…`);
2738
+ renderProjectSetupWhileBusy(state);
2739
+ // The pressed button is now disabled; keep keyboard focus on the one control that still acts.
2740
+ $projectSetupCancel.focus();
2741
+ const ready = await bridge.ensureChatRuntimeReady(provider, {
2742
+ isCancelled: () => projectSetupState !== state,
2743
+ onProgress: (status) => {
2744
+ if (projectSetupState !== state || !state.settingUp) return;
2745
+ const notice = window.flolessChat?.runtimeNotice?.(provider, status);
2746
+ state.settingUp.text = notice?.body || `FloLess is setting ${name} up. This happens once per FloLess update.`;
2747
+ renderProjectSetupWhileBusy(state);
2748
+ },
2749
+ });
2750
+ if (projectSetupState !== state) return;
2751
+ state.settingUp = null;
2752
+ renderProjectSetupWhileBusy(state);
2753
+ if (!ready.ok) {
2754
+ setProjectSetupBusy(false);
2755
+ renderProjectSetup();
2756
+ setProjectSetupError(ready.reason);
2757
+ return;
2758
+ }
2759
+ }
2593
2760
  setProjectSetupBusy(true, startChat ? 'Preparing chat…' : 'Creating…');
2594
2761
  try {
2595
2762
  if (!startChat) {
@@ -2627,7 +2794,7 @@
2627
2794
  ...(state.askCatalogue ? { environment: state.environment } : {}),
2628
2795
  directorySelectionId: state.directory.selectionId,
2629
2796
  snapshots,
2630
- provider: bridge.preferredChatProvider(),
2797
+ provider,
2631
2798
  });
2632
2799
  const project = result.project;
2633
2800
  state.project = project;
@@ -2703,6 +2870,8 @@
2703
2870
  templateId,
2704
2871
  files,
2705
2872
  kind,
2873
+ chatProvider: null,
2874
+ providersRead: false,
2706
2875
  askCatalogue: kind === 'drawings' && templateId === 'steel-model',
2707
2876
  environment: null,
2708
2877
  directory: null,
@@ -2718,6 +2887,7 @@
2718
2887
  renderProjectSetup();
2719
2888
  $projectSetup.classList.add('show');
2720
2889
  $projectSetupFolderChoose.focus();
2890
+ if (kind !== 'rvt') void refreshProjectSetupProviders(state);
2721
2891
  try {
2722
2892
  await Promise.all(files.map(assertProjectSourceReadable));
2723
2893
  if (projectSetupState !== state) return;
@@ -2755,13 +2925,16 @@
2755
2925
  projectSetupState.environment = button.dataset.environment;
2756
2926
  renderProjectSetup();
2757
2927
  });
2928
+ $projectSetupProvider?.addEventListener('click', (event) => {
2929
+ chooseProjectSetupProvider(event.target.closest('[data-chat-provider]'));
2930
+ });
2758
2931
  $projectSetupCancel.addEventListener('click', () => closeProjectSetup());
2759
2932
  $projectSetupCreate.addEventListener('click', () => createProjectFromSetup(true));
2760
2933
  $projectSetupCreateOnly.addEventListener('click', () => createProjectFromSetup(false));
2761
2934
  onBackdropDismiss($projectSetup, () => closeProjectSetup(), () => !!projectSetupState && !projectSetupState.busy);
2762
2935
  $projectSetup.addEventListener('keydown', (event) => {
2763
2936
  if (!projectSetupState) return;
2764
- if (event.key === 'Escape' && !projectSetupState.busy) {
2937
+ if (event.key === 'Escape' && (!projectSetupState.busy || projectSetupState.settingUp)) {
2765
2938
  event.preventDefault();
2766
2939
  closeProjectSetup();
2767
2940
  return;
@@ -3515,11 +3688,15 @@
3515
3688
  if (continuation?.state === 'continuing') return 'FloLess sent the saved filter to the linked AI Chat. Follow that conversation for the drawing read.';
3516
3689
  if (continuation?.state === 'completed') return 'The linked AI Chat finished its response. Review its result in that conversation.';
3517
3690
  if (continuation?.nextAction) return continuation.nextAction;
3518
- return 'Return to the same terminal AI session that prepared this Drawing Filter and tell it to continue the drawing read.';
3691
+ // No continuation record: nothing has said FloLess will carry this on, so the user must. Name
3692
+ // the session they actually have to go back to — "the terminal AI" is wrong for a read AI Chat
3693
+ // started, and sending someone to a terminal that is not doing the work is the same defect as
3694
+ // telling them to start a read that is already running.
3695
+ return `Return to the same ${readSessionName(req)} that prepared this Drawing Filter and tell it to continue the drawing read.`;
3519
3696
  }
3520
3697
 
3521
3698
  function readyFilterNextStep(req) {
3522
- return req?.chatConversation?.executionOwner === 'chat'
3699
+ return readRunsInChat(req)
3523
3700
  ? 'Then press Save filter in the top-right corner. FloLess will continue the drawing read in the linked AI Chat.'
3524
3701
  : 'Then press Save filter in the top-right corner. After Save, return to the terminal AI that prepared it and tell it to continue.';
3525
3702
  }
@@ -3544,12 +3721,12 @@
3544
3721
  if (projectContractLifecycle === 'unknown') return '';
3545
3722
  if (step === 'model') {
3546
3723
  if (waitingForInitial && revCardReq?.preparationState === 'blocked') return 'FloLess could not finish drawing preparation. Restart FloLess, then open Requests and follow the detailed instructions if it remains blocked.';
3547
- if (waitingForInitial && revCardReq?.preparationState === 'manifest-published' && !revCardReq?.prepassReady) return 'Drawing preparation is complete and saved. Return to the same terminal AI session and tell it to continue creating the Drawing Filter.';
3724
+ if (waitingForInitial && revCardReq?.preparationState === 'manifest-published' && !revCardReq?.prepassReady) return `Drawing preparation is complete and saved. Return to the same ${readSessionName(revCardReq)} and tell it to continue creating the Drawing Filter.`;
3548
3725
  if (waitingForInitial && revCardReq?.filterSaveContinuation?.state === 'recovery-needed') return `The Drawing Filter needs attention. ${savedFilterNextStep(revCardReq)}`;
3549
3726
  if (waitingForInitial && revCardReq?.filterCheckpointCurrent) return `The Drawing Filter is saved. ${savedFilterNextStep(revCardReq)}`;
3550
3727
  if (waitingForInitial && revCardReq?.prepassReady) return `Check steel, member marks, grids, dimensions, and relevant callouts. Ask in AI Chat on the left if you need help. ${readyFilterNextStep(revCardReq)}`;
3551
- if (waitingForInitial && revCardReq?.preparationRetryable) return 'Steel Filter preparation was interrupted. Your drawings are still attached. Return to the same terminal AI and retry preparation for this same request.';
3552
- if (waitingForInitial) return 'The initial drawing read is waiting for your terminal AI. The model unlocks after you review the Drawing Filter and press Save filter.';
3728
+ if (waitingForInitial && revCardReq?.preparationRetryable) return `Steel Filter preparation was interrupted. Your drawings are still attached. Return to the same ${readSessionName(revCardReq)} and retry preparation for this same request.`;
3729
+ if (waitingForInitial) return `The initial drawing read is waiting for ${readRunsInChat(revCardReq) ? 'AI Chat' : 'your terminal AI'}. The model unlocks after you review the Drawing Filter and press Save filter.`;
3553
3730
  if (projectContractLifecycle === 'filter-checkpoint') return 'Attach the drawing set again in Drawing Filter to restart the read. The earlier request is no longer available to receive a saved filter.';
3554
3731
  return 'Read and save a Drawing Filter first. The model will unlock after the first drawing read.';
3555
3732
  }
@@ -3646,7 +3823,7 @@
3646
3823
  : waitingForInitial && revCardReq?.preparationState === 'blocked'
3647
3824
  ? 'FloLess could not finish drawing preparation · Restart FloLess, then open Requests and follow the detailed instructions if it remains blocked. Your drawings are still attached.'
3648
3825
  : waitingForInitial && revCardReq?.preparationState === 'manifest-published' && !revCardReq?.prepassReady
3649
- ? 'Drawing preparation is complete and saved · Return to the same terminal AI session and tell it to continue creating the Drawing Filter. Do not start or copy this request again.'
3826
+ ? `Drawing preparation is complete and saved · Return to the same ${readSessionName(revCardReq)} and tell it to continue creating the Drawing Filter. Do not start or copy this request again.`
3650
3827
  : waitingForInitial && revCardReq?.filterSaveContinuation?.state === 'recovery-needed'
3651
3828
  ? `Drawing Filter needs attention · ${savedFilterNextStep(revCardReq)}`
3652
3829
  : waitingForInitial && revCardReq?.filterCheckpointCurrent
@@ -3654,9 +3831,25 @@
3654
3831
  : waitingForInitial && revCardReq?.prepassReady
3655
3832
  ? 'Drawing Filter ready for review · ' + (window.FilterGuidance?.scope || 'Check what this steel read may use — not only the steel. Keep the steel plus member labels and sizes, grid references, scale or location dimensions, and relevant detail or section callouts.') + ' Ask in AI Chat on the left if you are unsure. ' + readyFilterNextStep(revCardReq)
3656
3833
  : waitingForInitial && revCardReq?.preparationRetryable
3657
- ? 'Steel Filter preparation was interrupted · Your drawings are still attached. Return to the same terminal AI and retry preparation for this same request.'
3834
+ ? `Steel Filter preparation was interrupted · Your drawings are still attached. Return to the same ${readSessionName(revCardReq)} and retry preparation for this same request.`
3835
+ : waitingForInitial && readWorkingInChat(revCardReq)
3836
+ ? 'Drawing read is running in AI Chat · Follow it in AI Chat on the left (expand that panel if it is collapsed). Nothing to do here — FloLess updates this when the Drawing Filter is ready for your review.'
3837
+ : waitingForInitial && readChatBlockedAction(revCardReq)
3838
+ ? `Drawing read is waiting for you in AI Chat · ${OPEN_AI_CHAT} and ${readChatBlockedAction(revCardReq)}. The read continues once you do.`
3839
+ : waitingForInitial && readChatUnreadable(revCardReq)
3840
+ ? `FloLess cannot read this drawing read’s AI Chat conversation · ${OPEN_AI_CHAT} to check it. If it will not open, use Report an issue.`
3841
+ : waitingForInitial && readChatArchived(revCardReq)
3842
+ ? `Drawing read is in an archived AI Chat conversation · ${OPEN_AI_CHAT} and restore that conversation — its composer stays disabled until you do. Then tell it to continue the drawing read.`
3843
+ : waitingForInitial && readChatBusyElsewhere(revCardReq)
3844
+ ? 'Drawing read is waiting on a reply in AI Chat · If you told AI Chat to continue the drawing read, this updates as it goes. If not, tell it to continue once that reply is done — the read will not resume on its own.'
3845
+ : waitingForInitial && readChatFailed(revCardReq)
3846
+ ? `Drawing read stopped with an error in AI Chat · AI Chat’s last reply ended with an error. ${OPEN_AI_CHAT} to see what went wrong, then ask it to try the drawing read again.`
3847
+ : waitingForInitial && readChatInterrupted(revCardReq)
3848
+ ? `Drawing read was interrupted in AI Chat · AI Chat’s reply stopped before it finished. ${OPEN_AI_CHAT} and tell it to continue the drawing read.`
3849
+ : waitingForInitial && readRunsInChat(revCardReq)
3850
+ ? `Drawing read is paused in AI Chat · ${OPEN_AI_CHAT} and tell it to continue the drawing read.`
3658
3851
  : waitingForInitial
3659
- ? 'Drawing read not started · Open Requests, copy it into Claude Code, Codex, or OpenCode, then return to review and save the Drawing Filter.'
3852
+ ? 'Drawing read not started · Open Requests — if Start in AI Chat is shown, choose it; otherwise copy the request into Claude Code or Codex. Then return to review and save the Drawing Filter.'
3660
3853
  : projectContractLifecycle === 'filter-checkpoint'
3661
3854
  ? 'Drawing read needs restarting · The earlier drawing request is no longer available. Attach the drawing set again in Drawing Filter to restart the read.'
3662
3855
  : 'Start in Drawing Filter by attaching a PDF or image. The Model, Exports, and History stages unlock after the first steel model is created.';
@@ -3700,6 +3893,22 @@
3700
3893
  return true;
3701
3894
  }
3702
3895
 
3896
+ /**
3897
+ * A step the PERSON picked (a tab or a "go to" link), as opposed to one the shell restores. While a
3898
+ * project opens, `pendingPresenceStep` holds the step to restore once the lifecycle probe answers;
3899
+ * any pick replaces that intent, so the probe can never move the person off the tab they chose
3900
+ * (#1669 — a Drawing Filter click was not deferred, so nothing cleared the held Model and the probe
3901
+ * yanked them there). A pick of Model/Exports/History re-queues itself in `deferStageUntilLifecycle`.
3902
+ * Its checking toast promised a destination that is no longer wanted, so it goes too — dismissing
3903
+ * it also tells the older probe waiter it no longer owns the feedback, so no retry warning follows.
3904
+ */
3905
+ function chooseStep(s) {
3906
+ pendingPresenceStep = null;
3907
+ if (pendingPresenceToast) pendingPresenceToast();
3908
+ pendingPresenceToast = null;
3909
+ setStep(s);
3910
+ }
3911
+
3703
3912
  function setStep(s) {
3704
3913
  // Keep the tab visually available while the routine open-project check runs, but do not cross
3705
3914
  // the model boundary speculatively. The existing request is reused and this destination opens
@@ -3729,6 +3938,13 @@
3729
3938
  if (window.flolessLeftPane) {
3730
3939
  window.flolessLeftPane.setWorkspaceModelVisible(s === 'model');
3731
3940
  }
3941
+ // The visible step IS the surface AI Chat reads, and what may be attached depends on it (a
3942
+ // Drawing Filter message takes pictures only). Nothing else told the chat pane, so its paperclip
3943
+ // kept the previous step's wording until some unrelated repaint happened to run — caught by the
3944
+ // independent QA switching Drawing Filter → Model. `try` because this function is also evaluated
3945
+ // on its own by workspace-instructor-handoff.test.ts, where no event constructor exists.
3946
+ try { window.dispatchEvent(new CustomEvent('floless:workspace-step-changed', { detail: { step: s } })); }
3947
+ catch { /* a harness without CustomEvent; the real shell always has one */ }
3732
3948
  if ($sourcePlaceholder) $sourcePlaceholder.hidden = !(s === 'drawings' && !drawingsHasFrame);
3733
3949
  // Queried here rather than through the module const, the way master's own call sites do: setStep is
3734
3950
  // extracted and evaluated on its own by workspace-instructor-handoff.test.ts, and a closure
@@ -3767,7 +3983,7 @@
3767
3983
  if (reason) showToast(reason, 'warn');
3768
3984
  return;
3769
3985
  }
3770
- if (b) setStep(b.dataset.step);
3986
+ if (b) chooseStep(b.dataset.step);
3771
3987
  });
3772
3988
 
3773
3989
  // ── Approve (per-project) ───────────────────────────────────────────────────
@@ -4411,6 +4627,7 @@
4411
4627
  const KB_LOCK_STALE_MS = 10 * 60 * 1000; // = knowledge-store.ts LOCK_STALE_MS; when to warn "taking longer"
4412
4628
  const KB_MB = (n) => Math.round(n / (1024 * 1024));
4413
4629
  let knowledgePoll = null;
4630
+ let knowledgePollInFlight = false;
4414
4631
  let knowledgeState = null;
4415
4632
  let companyKnowledgeState = null;
4416
4633
  let companyKnowledgePromotion = null; // { sourceId, filename }
@@ -4506,7 +4723,10 @@
4506
4723
  if (knowledgePoll) return; // already ticking — don't stack intervals across re-renders
4507
4724
  knowledgePoll = setInterval(() => {
4508
4725
  if (!current || $wsKnowledge.hidden) { stopKnowledgePoll(); return; }
4509
- renderKnowledge();
4726
+ // Skip, don't stack (#1604): each render reads /api/requests, which can outlast this interval.
4727
+ if (knowledgePollInFlight) return;
4728
+ knowledgePollInFlight = true;
4729
+ renderKnowledge().finally(() => { knowledgePollInFlight = false; });
4510
4730
  }, 3000);
4511
4731
  }
4512
4732
 
@@ -4514,10 +4734,13 @@
4514
4734
  // (the store writes organize.json at `start`), so "pending" must be the UNION of both reads — never
4515
4735
  // /status alone. The request queue is advisory: a blip there must not blank the sources column.
4516
4736
  async function loadKnowledgeState(proj) {
4737
+ // Each read is bounded (#1604): the 3-second poll skips its ticks while a render is out, so a
4738
+ // request that never answered would stop the column refreshing for good.
4739
+ const bounded = () => ({ signal: AbortSignal.timeout(90_000) });
4517
4740
  const [status, reqs, company] = await Promise.all([
4518
- api(kbUrl(proj.id, '/status')),
4519
- api('/api/requests').catch(() => []),
4520
- api(`/api/company-knowledge?projectId=${encodeURIComponent(proj.id)}`)
4741
+ api(kbUrl(proj.id, '/status'), bounded()),
4742
+ api('/api/requests', bounded()).catch(() => []),
4743
+ api(`/api/company-knowledge?projectId=${encodeURIComponent(proj.id)}`, bounded())
4521
4744
  .catch((error) => ({ configured: false, loadError: String((error && error.message) || error) })),
4522
4745
  ]);
4523
4746
  const list = Array.isArray(reqs) ? reqs : (reqs.requests || []);
@@ -5822,12 +6045,12 @@
5822
6045
  // under the in-flight POST, so `ta`/`btn` stay valid throughout.
5823
6046
  kbAdjustBusy = proj.id;
5824
6047
  ta.disabled = true; btn.disabled = true; btn.textContent = '✎ Queuing…';
5825
- let ok = false, msg = '';
6048
+ let ok = false;
5826
6049
  try {
5827
6050
  await api(kbUrl(proj.id, '/request'), { method: 'POST', body: JSON.stringify({ prompt }) });
5828
6051
  ok = true;
5829
6052
  if (bridge.loadRequests) await bridge.loadRequests(); // bump the footer Requests counter (nothing else moves it here)
5830
- } catch (err) { msg = (err && err.message) || String(err); }
6053
+ } catch { /* the failure is reported through `ok` below — the message was never shown */ }
5831
6054
  kbAdjustBusy = null;
5832
6055
  // Re-check by ID after every await: the user may have switched — or renamed — the project mid-flight
5833
6056
  // (rename replaces the `current` object, so an identity check would false-mismatch). Bail without
@@ -8109,7 +8332,6 @@
8109
8332
  approvedAt = r.approvedAt || undefined;
8110
8333
  units = r.units === 'mm' ? 'mm' : 'ft-in';
8111
8334
  } else {
8112
- const err = exportResult.reason;
8113
8335
  // Surface the load failure — don't let it read as "nothing exported yet" (a lie).
8114
8336
  showToast('We couldn’t load the export status because FloLess could not reach it. Try again.', 'warn');
8115
8337
  state = null;
@@ -8556,7 +8778,7 @@
8556
8778
  if (e.target.closest('[data-export-raw]')) { exportRawSelectedSource(); return; }
8557
8779
  if (e.target.closest('#ws-exports-approve')) { approveProject(); return; }
8558
8780
  // The no-model gate's real next step — mirrors History's #hist-go-drawings.
8559
- if (e.target.closest('#ws-exports-go-drawings')) { setStep('drawings'); return; }
8781
+ if (e.target.closest('#ws-exports-go-drawings')) { chooseStep('drawings'); return; }
8560
8782
  if (e.target.closest('[data-open-exports-folder]')) { openExportsFolder(); return; }
8561
8783
  const details = e.target.closest('[data-export-details]');
8562
8784
  if (details) { showExportReceiptDetails(details.dataset.exportDetails, details); return; }
@@ -8680,6 +8902,66 @@
8680
8902
  $revisionCard.replaceChildren();
8681
8903
  }
8682
8904
  const isInitialRevisionRead = (req) => !req || !req.baseVersion || req.baseVersion <= 0;
8905
+ // ── Who is actually driving this drawing read ───────────────────────────────────────────────
8906
+ // `chatConversation` is server-owned (request-list-route). `executionOwner: 'chat'` is stamped
8907
+ // only when the read was really STARTED in the built-in AI Chat panel — which is what the
8908
+ // "Create project & start chat" flow does for you the moment a drawing set is uploaded.
8909
+ // 'discussion' means a conversation is merely open, so the handoff is still the user's to make.
8910
+ const readRunsInChat = (req) => req?.chatConversation?.executionOwner === 'chat';
8911
+ // …and ownership NEVER expires, so it cannot answer "is it working right now". A conversation
8912
+ // that finished, failed or was interrupted still owns its request, and a card reading ownership
8913
+ // alone would go on claiming motion nothing can see — the same misleading-instruction defect this
8914
+ // wording exists to remove, just relocated. The conversation's own state is the part that moves.
8915
+ // An unrecognised state (an older or newer build) counts as NOT working: the paused wording is
8916
+ // always safe to show, the running wording is not.
8917
+ // WORKING means the conversation is moving on its own. `awaiting-approval` and `recovery` are NOT
8918
+ // that, and putting them here was the same defect this wording exists to remove: a chat that has
8919
+ // STOPPED and is waiting on the person, described to that person as "nothing to do here".
8920
+ // awaiting-approval — the turn is parked on an approval only they can answer (chat-coordinator
8921
+ // patches the active turn to it and renders a decision card); the Tekla model read always
8922
+ // raises one, so this is the common case, not the exotic one.
8923
+ // recovery — the turn broke. AI Chat disables its own composer, shows a recovery control, and
8924
+ // `turnIsVisiblyActive` returns false for it; ensureRequestChatLink refuses to link a Request
8925
+ // to a chat in this state at all. Nothing will ever move it except the user.
8926
+ // They get their own wording because their ACTIONS differ, so they cannot share a sentence.
8927
+ const CHAT_WORKING_STATES = ['starting', 'running'];
8928
+ const CHAT_BLOCKED_ACTIONS = { 'awaiting-approval': 'answer the question it is waiting on', recovery: 'use its recovery control' };
8929
+ const readChatState = (req) => (readRunsInChat(req) ? req?.chatConversation?.chatState ?? null : null);
8930
+ const readWorkingInChat = (req) => CHAT_WORKING_STATES.includes(readChatState(req));
8931
+ const readChatBlockedAction = (req) => CHAT_BLOCKED_ACTIONS[readChatState(req)] || '';
8932
+ // The conversation exists but the server could not read it. Saying "it is paused, go continue it"
8933
+ // here sends the user to open the very conversation the server just failed to read.
8934
+ const readChatUnreadable = (req) => readChatState(req) === 'unreadable';
8935
+ // BUSY WITH SOMETHING ELSE is a third honest answer, and it exists because one conversation can
8936
+ // hold several Requests (`startRequest` reuses the selected chat when it is idle) and the person
8937
+ // can ask it anything else at any time. The conversation is moving, but not on THIS read, so
8938
+ // neither of the other two answers is true — "running" claims motion this request is not getting,
8939
+ // and "tell it to continue" cannot be done yet: Send is disabled while any reply is in flight. Nor
8940
+ // is the read QUEUED behind that reply — a read's own turn never waits in line (acceptTurn refuses
8941
+ // a second active turn), so when the other reply finishes nothing picks the read up. The person
8942
+ // has to wait for it, then tell AI Chat to continue (#1610). And FloLess cannot tell WHAT that
8943
+ // reply is about: a message the person typed — including "continue the drawing read", the very
8944
+ // instruction these cards give — is not provably this read's, so the wording must hold for both
8945
+ // a reply that is continuing the read and one about something else.
8946
+ const readChatBusyElsewhere = (req) => readChatState(req) === 'busy-elsewhere';
8947
+ // ARCHIVED IS NOT PAUSED: AI Chat disables an archived conversation's composer, so "tell it to
8948
+ // continue" cannot be carried out until the user restores it. The guidance names the restore.
8949
+ const readChatArchived = (req) => readChatState(req) === 'archived';
8950
+ // FAILED AND INTERRUPTED ARE NOT "PAUSED" (#1611). Both used to fall into the stopped bucket and
8951
+ // read as "paused … tell it to continue", which is softer than the truth: a failed reply ended with
8952
+ // an error the person should look at before asking again, and an interrupted one stopped before it
8953
+ // finished. The composer stays usable after either, so each names its own next step.
8954
+ const readChatFailed = (req) => readChatState(req) === 'failed';
8955
+ const readChatInterrupted = (req) => readChatState(req) === 'interrupted';
8956
+ // WHERE AI CHAT IS. The left panel can be collapsed (persisted, and the default on touch), and then
8957
+ // no panel called AI Chat is on screen — "open the AI Chat panel on the left and …" was an
8958
+ // instruction a person could not follow without first doing a step it never named (#1611). One
8959
+ // phrase, true in both layouts, used by every instruction that sends someone to AI Chat.
8960
+ const OPEN_AI_CHAT = 'Open AI Chat on the left (expand that panel if it is collapsed)';
8961
+ // Name the session the user has to go back to. Every "return to the terminal AI that prepared
8962
+ // it" line is wrong for a read AI Chat started, and sending someone to a terminal that is not
8963
+ // doing the work is the same defect as telling them to start a read that is already running.
8964
+ const readSessionName = (req) => readRunsInChat(req) ? 'AI Chat conversation' : 'terminal AI session';
8683
8965
  function isRevisionStale(req) {
8684
8966
  return !!req && Number.isInteger(req.baseVersion) && Number.isInteger(req.headVersion)
8685
8967
  && req.baseVersion !== req.headVersion;
@@ -8693,9 +8975,20 @@
8693
8975
  return req.status === 'staged' && req.steelAuditPolicy === 1;
8694
8976
  }
8695
8977
  function stopRevisionPoll() { if (revisionPoll) { clearInterval(revisionPoll); revisionPoll = null; } }
8978
+ // A tick is SKIPPED while the previous poll is still out, never stacked behind it (#1604). Each render
8979
+ // reads /api/requests, which can outlast this 3-second interval on a busy machine; stacking one per
8980
+ // tick held more and more of the browser's ~6 connections to this server until AI Chat and every
8981
+ // other request queued behind them. Only the poll is gated: a render started by a user action still
8982
+ // runs at once.
8983
+ let revisionPollInFlight = false;
8696
8984
  function startRevisionPoll() {
8697
8985
  stopRevisionPoll();
8698
- revisionPoll = setInterval(() => { if (current) renderRevisionCard(); else stopRevisionPoll(); }, 3000);
8986
+ revisionPoll = setInterval(() => {
8987
+ if (!current) { stopRevisionPoll(); return; }
8988
+ if (revisionPollInFlight) return;
8989
+ revisionPollInFlight = true;
8990
+ renderRevisionCard().finally(() => { revisionPollInFlight = false; });
8991
+ }, 3000);
8699
8992
  }
8700
8993
  const revEl = (tag, cls, text) => {
8701
8994
  const e = document.createElement(tag);
@@ -8785,7 +9078,7 @@
8785
9078
  const dot = revEl('span', 'wrc-dot'); dot.setAttribute('aria-hidden', 'true');
8786
9079
  const txt = revEl('span', 'wrc-text');
8787
9080
  txt.appendChild(revEl('b', null, 'Drawing preparation is complete and saved.'));
8788
- txt.appendChild(document.createTextNode(' Return to the same terminal AI session and tell it to continue creating the Drawing Filter. Do not start or copy this request again.'));
9081
+ txt.appendChild(document.createTextNode(` Return to the same ${readSessionName(req)} and tell it to continue creating the Drawing Filter. Do not start or copy this request again.`));
8789
9082
  return [dot, txt];
8790
9083
  }
8791
9084
  if (req.filterSaveContinuation?.state === 'recovery-needed') {
@@ -8823,12 +9116,31 @@
8823
9116
  const txt = revEl('span', 'wrc-text');
8824
9117
  const active = runState === 'queued' || runState === 'running';
8825
9118
  txt.appendChild(revEl('b', null, active ? 'Retrying Steel Filter preparation.' : 'Steel Filter preparation was interrupted.'));
9119
+ // CHAT OWNERSHIP IS CHECKED FIRST, ahead of `canRun`. `canRun` is server policy about whether
9120
+ // FloLess *could* start a headless retry; it stays true while AI Chat holds the request, and
9121
+ // the Requests row withholds Retry preparation from a chat-owned row exactly as it withholds
9122
+ // Copy. Reading `canRun` first therefore named a button that is not on screen — the one class
9123
+ // of instruction this work exists to remove.
9124
+ //
9125
+ // And a conversation stalled on the person, or one FloLess cannot read, cannot be asked to
9126
+ // retry: "ask that conversation to retry" is unfollowable until the user unblocks it. Those
9127
+ // two states name their own action instead, the same three buckets the rest of this file uses.
9128
+ const chatBlocked = readChatBlockedAction(req);
8826
9129
  txt.appendChild(document.createTextNode(active
8827
9130
  ? ' FloLess is continuing this same request with the attached drawings.'
9131
+ : readChatUnreadable(req)
9132
+ ? ` Your drawings are still attached, but FloLess cannot read the AI Chat conversation that holds this request. ${OPEN_AI_CHAT} to check it. If it will not open, use Report an issue.`
9133
+ : chatBlocked
9134
+ ? ` Your drawings are still attached. The AI Chat conversation that holds this request is waiting for you. ${OPEN_AI_CHAT} and ${chatBlocked}, then ask it to retry preparation.`
9135
+ : readRunsInChat(req)
9136
+ ? ` Your drawings are still attached. ${OPEN_AI_CHAT} and ask that conversation to retry preparation for this same request.`
8828
9137
  : req.canRun
8829
9138
  ? ' Your drawings are still attached. Open Requests and choose Retry preparation to continue this same request.'
8830
- : ' Your drawings are still attached. Return to the same terminal AI and retry preparation for this same request, or copy the retry request from here.'));
8831
- if (!active && !req.canRun) {
9139
+ : ` Your drawings are still attached. Return to the same ${readSessionName(req)} and retry preparation for this same request, or copy the retry request from here.`));
9140
+ // No Copy when AI Chat owns the request, for the same reason the pending branch withholds it:
9141
+ // a second handoff cannot help while the first one holds the request, and pasting it into a
9142
+ // terminal is how two writers end up in one project folder.
9143
+ if (!active && !req.canRun && !readRunsInChat(req)) {
8832
9144
  const copy = revEl('button', 'btn-mini', '⧉ Copy retry');
8833
9145
  copy.type = 'button'; copy.dataset.revcopy = ''; copy.dataset.commandId = 'shell.revision-request-copy';
8834
9146
  copy.setAttribute('data-tip', 'Copy the retained request to retry preparation');
@@ -8849,17 +9161,58 @@
8849
9161
  txt.appendChild(document.createTextNode(` Your terminal AI is preparing ${n} file${n > 1 ? 's' : ''}. Leave FloLess open — you can keep working elsewhere in it. Progress and what to do next appear here. Open Requests if you need to stop it.`));
8850
9162
  return [dot, txt];
8851
9163
  }
9164
+ // AI CHAT ALREADY HAS IT. The "Create project & start chat" flow hands the first read straight to
9165
+ // the AI Chat panel on the left, so the handoff copy below — the whole point of which is to tell
9166
+ // someone to start a read — describes work that is already happening. Like the background-run
9167
+ // branch above, this offers NO Copy: a second handoff is not a useful fallback while the first
9168
+ // one is active, and here it would also try to take a request AI Chat owns. Ownership alone does
9169
+ // not prove motion (readWorkingInChat), so a stopped conversation gets the wording that asks the
9170
+ // user to continue it rather than a claim of progress nothing can see.
9171
+ if (readRunsInChat(req)) {
9172
+ const dot = revEl('span', 'wrc-dot'); dot.setAttribute('aria-hidden', 'true');
9173
+ const txt = revEl('span', 'wrc-text');
9174
+ const blockedAction = readChatBlockedAction(req);
9175
+ const lead = readWorkingInChat(req) ? 'running in AI Chat'
9176
+ : blockedAction ? 'waiting for you in AI Chat'
9177
+ : readChatUnreadable(req) ? 'in an AI Chat conversation FloLess cannot read'
9178
+ : readChatArchived(req) ? 'in an archived AI Chat conversation'
9179
+ : readChatBusyElsewhere(req) ? 'waiting on a reply in AI Chat'
9180
+ : readChatFailed(req) ? 'stopped by an error in AI Chat'
9181
+ : readChatInterrupted(req) ? 'interrupted in AI Chat'
9182
+ : 'paused in AI Chat';
9183
+ txt.appendChild(revEl('b', null, `${isInitialRevisionRead(req) ? 'Initial' : 'Updated'} drawing read is ${lead}.`));
9184
+ txt.appendChild(document.createTextNode(readWorkingInChat(req)
9185
+ ? ` AI Chat on the left is reading ${n} file${n > 1 ? 's' : ''}. There is nothing to do here — leave FloLess open. Larger drawing sets take longer; FloLess updates this card when the Drawing Filter is ready for your review.`
9186
+ : blockedAction
9187
+ ? ` Your drawings are still attached. ${OPEN_AI_CHAT} and ${blockedAction}; the read continues once you do.`
9188
+ : readChatUnreadable(req)
9189
+ ? ` Your drawings are still attached. ${OPEN_AI_CHAT} to check that conversation. If it will not open, use Report an issue — FloLess could not read it.`
9190
+ : readChatArchived(req)
9191
+ ? ` Your drawings are still attached. ${OPEN_AI_CHAT} and restore that conversation — its composer stays disabled while it is archived — then tell it to continue the drawing read.`
9192
+ : readChatBusyElsewhere(req)
9193
+ ? ' Your drawings are still attached. If you already asked AI Chat to continue, this card updates as the read moves forward. If not, tell it to continue once the current reply is done — the read will not resume on its own.'
9194
+ : readChatFailed(req)
9195
+ ? ` Your drawings are still attached, but AI Chat’s last reply ended with an error. ${OPEN_AI_CHAT} to see what went wrong, then ask it to try the drawing read again.`
9196
+ : readChatInterrupted(req)
9197
+ ? ` Your drawings are still attached, but AI Chat’s reply stopped before it finished. ${OPEN_AI_CHAT} and tell it to continue the drawing read.`
9198
+ : ` Your drawings are still attached, but AI Chat is not working on them right now. ${OPEN_AI_CHAT} and tell it to continue the drawing read.`));
9199
+ return [dot, txt];
9200
+ }
8852
9201
  // `pending` means the request is waiting for the terminal AI handoff; it does not prove that an
8853
9202
  // AI is actively reading. A spinner made a pasted instruction look like an already-running job.
8854
9203
  const dot = revEl('span', 'wrc-dot'); dot.setAttribute('aria-hidden', 'true');
8855
9204
  const txt = revEl('span', 'wrc-text');
8856
9205
  txt.appendChild(revEl('b', null, `${isInitialRevisionRead(req) ? 'Initial' : 'Updated'} drawing read is waiting for your terminal AI.`));
8857
9206
  // Runtime discovery belongs to the Requests surface, not this workspace card. `canRun` is only
8858
- // server policy; it does not prove that a supported terminal AI is installed on this machine.
8859
- // Phrase the optional shortcut conditionally so the card never points to a hidden control.
9207
+ // server policy; it does not prove that a supported terminal AI is installed on this machine, and
9208
+ // Start in AI Chat needs a signed-in chat provider plus a request in chat scope. So BOTH halves
9209
+ // name their control conditionally — "if it is shown, choose it" is true either way and never
9210
+ // points at a hidden one. The terminal is one route among them, not the only instruction.
9211
+ // OpenCode is deliberately absent: FloLess cannot run it, so naming it as a destination sends
9212
+ // people to a terminal that will not be able to finish the read.
8860
9213
  const handoff = !isInitialRevisionRead(req) && req.canRun
8861
- ? 'Open Requests. If Start automatically is shown, choose it; otherwise copy the request into Claude Code, Codex, or OpenCode.'
8862
- : 'Open Requests and copy the request into Claude Code, Codex, or OpenCode.';
9214
+ ? 'Open Requests. If Start automatically is shown, choose it; otherwise copy the request into Claude Code or Codex.'
9215
+ : 'Open Requests. If Start in AI Chat is shown, choose it; otherwise copy the request into Claude Code or Codex.';
8863
9216
  // No numeric cap. "up to 30 minutes" was a promise this card cannot keep: the read runs in
8864
9217
  // someone else's terminal AI over a drawing set whose size we do not bound, and a stated
8865
9218
  // ceiling that is routinely blown past reads as a stall or a hang rather than as normal work.
@@ -8988,7 +9341,10 @@
8988
9341
  // to remove, and enough to fail the console-clean bar every E2E is held to. Silence was still
8989
9342
  // wrong (a stuck card had no trace at all), so the first failure speaks and the recovery resets it.
8990
9343
  try {
8991
- const b = await api('/api/requests');
9344
+ // Bounded (#1604): the poll skips its ticks while this is out, so a read that never answered
9345
+ // would stop the card for good. 90 s, like the Requests window: the route's own lock waits
9346
+ // give up after 60 s.
9347
+ const b = await api('/api/requests', { signal: AbortSignal.timeout(90_000) });
8992
9348
  reqs = Array.isArray(b) ? b : (b.requests || []);
8993
9349
  // Every owned success is fresh evidence of server contact, even if a later-started poll is in
8994
9350
  // flight or has failed. The route can legitimately outlast the 3-second polling interval.
@@ -9132,6 +9488,14 @@
9132
9488
  if (retireRevisionCardForStrip(pending)) return;
9133
9489
  const cardKey = `${state}:${revCardReq ? revCardReq.id : ''}:${pending && pending.filterCheckpointCurrent ? 'filter-saved' : pending && pending.prepassReady ? 'filter-ready' : 'read-pending'}:${pending && pending.run ? pending.run.state || '' : ''}`
9134
9490
  + (pending ? `:${pending.preparationState || ''}:${pending.preparationRetryable === true}:${pending.canRun === true}:${pending.canCopy === true}:${pending.canClear === true}:${pending.clearWhy || ''}:${pending.filterSaveContinuation?.state || ''}:${pending.filterSaveContinuation?.nextAction || ''}` : '')
9491
+ // WHO IS DRIVING THE READ, and whether that conversation is working, both change the card's
9492
+ // words AND whether it offers Copy — and neither is implied by any field above. Without them
9493
+ // the three-second poll short-circuits on an unchanged key, so a read that AI Chat picks up
9494
+ // keeps its "… drawing read is waiting for your terminal AI." card indefinitely while the
9495
+ // banner two lines up already says the read is running in AI Chat. Measured in a real browser.
9496
+ // (`applyStageGating()` still runs on the short-circuit path, which is why only one of the two
9497
+ // surfaces went stale — and why the contradiction was visible at all.)
9498
+ + `:${revCardReq?.chatConversation?.executionOwner || ''}:${revCardReq?.chatConversation?.chatState || ''}`
9135
9499
  + (staged ? `:${staged.baseVersion}:${staged.headVersion}:${staged.stageId || ''}:${staged.canDiscardRevision === true}:${staged.discardState || ''}:${staged.discardWhy || ''}:${staged.canClear === true}:${staged.clearWhy || ''}:${unavailableRevisionReviewStages.has(staged.stageId)}` : '');
9136
9500
  // The key below exists to preserve focus in the card across the three-second poll. It says
9137
9501
  // nothing about the strip, whose progress record advances on its own revision, so the strip is
@@ -11567,7 +11931,7 @@
11567
11931
  $wsHistory.addEventListener('click', (e) => {
11568
11932
  // The no-model empty state's real next step: go read a drawing. Same handler shape as the
11569
11933
  // Approve it replaces, so the pane keeps owning its own inline actions.
11570
- if (e.target.closest('#hist-go-drawings')) { setStep('drawings'); return; }
11934
+ if (e.target.closest('#hist-go-drawings')) { chooseStep('drawings'); return; }
11571
11935
  if (e.target.closest('.hc-cancel')) { closeRollbackConfirm(); return; }
11572
11936
  const go = e.target.closest('[data-hc-go]');
11573
11937
  if (go) { rollbackTo(Number(go.dataset.hcGo)); return; }