@floless/app 0.151.0 → 0.152.1

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
@@ -54,7 +54,7 @@
54
54
  instructorAnswers: [], historyLoading: false, historyRequestGeneration: 0, picker: null, loading: false,
55
55
  draftTimer: null, localDraft: null, backgroundDrafts: new Map(), draftWrites: new Map(), draftVersions: new Map(), unknownFollowups: new Map(), refreshTimer: null, scopeGeneration: 0, selectionGeneration: 0, openInGeneration: 0, choosingProvider: false,
56
56
  answerJump: null, answerJumpTimer: null, scopeInitialized: false, renaming: null, historyRename: null, pendingSubmissionId: null, recoveryMessage: null, recoveryCanEnd: false,
57
- stream: null, liveStatusTurnId: null, decidingApprovalIds: new Set(), revokingApprovalTurns: new Set(), uploadingChatIds: new Set(),
57
+ stream: null, liveStatusTurnId: null, liveFlo: null, decidingApprovalIds: new Set(), revokingApprovalTurns: new Set(), uploadingChatIds: new Set(),
58
58
  // #1653 stage 4: this chat owner's (project or workflow, #1890) questions linked to live Tekla parts, the card's open lists, and the receipt showing it.
59
59
  teklaLinks: { ownerKey: '', state: 'idle', links: [], partial: false, inflight: false, again: false }, teklaHistoryUi: {}, teklaHistoryHost: null,
60
60
  // Latched so the 5 s account poll logs an outage once instead of twelve times a minute; cleared
@@ -103,7 +103,7 @@
103
103
  // runtime problem happened and WHICH command to run by hand. errorMessage() would flatten it.
104
104
  const SERVER_WORDED_SIGN_IN_CODES = new Set(['runtime-unavailable', 'launch-failed', 'launch-unsafe', 'sign-in-active', 'sign-out-failed']);
105
105
  const requestTypeLabels = { 'drawing-intake': 'Initial drawing read', 'initial-drawing-read': 'Initial drawing read', 'tweak-contract': 'Workflow change', guide: 'Question' };
106
- const requestStatusLabels = { pending: 'Queued', queued: 'Queued', running: 'Running', ready: 'Ready', completed: 'Complete', failed: 'Failed', stopped: 'Stopped' };
106
+ const requestStatusLabels = { pending: 'Queued', queued: 'Queued', running: 'Running', ready: 'Ready', completed: 'Complete', failed: 'Failed', stopped: 'Stopped', finished: 'Finished', 'left-queue': 'Left the queue' };
107
107
  // Pictures and PDFs upload as the browser names them. Any other file is a DATA file (#1853): its
108
108
  // bytes decide whether FloLess can read it (sniffDataFile), never its name or declared type.
109
109
  const allowedTypes = new Set(['image/png', 'image/jpeg', 'image/webp', 'application/pdf']);
@@ -156,6 +156,8 @@
156
156
  error.code = body?.code || null;
157
157
  error.reason = body?.reason || null;
158
158
  error.recovery = Array.isArray(body?.recovery) ? body.recovery : null;
159
+ // #2061: who holds a busy project, so the person can be asked: wait, stop it, or open it.
160
+ error.holder = body?.holder && typeof body.holder === 'object' ? body.holder : null;
159
161
  error.status = response.status;
160
162
  // #1890 PR 3b: the conversation moved — wherever this was asked from, the open tab follows it.
161
163
  if (error.code === 'chat-moved' && body?.to?.chatId) {
@@ -235,6 +237,10 @@
235
237
  'chat-followup-not-found': 'This message is no longer in this conversation. Refresh the conversation.',
236
238
  'chat-attachment-scope': 'An attached file is no longer available to this message. Add the file again in a new message.',
237
239
  'chat-initiator-unknown': 'FloLess could not identify what started this conversation. Reload the conversation and try again.',
240
+ // #2059: an Instructor answer uses no tools until the person confirms a wider Access.
241
+ 'chat-instructor-answer-access': 'This chat is an Instructor answer, so the AI uses no tools. Confirm the Access change to turn it into an ordinary chat.',
242
+ 'chat-instructor-answer-accounts': 'An Instructor answer uses no tools, so it cannot use a connected account. Start a new chat to use one.',
243
+ 'chat-guide-read-only': 'The Guide only reads, so its Access stays Read only. To let the AI change things, use a regular conversation.',
238
244
  // Damage the user can act on, unlike the refusals below it: the conversation history lists this
239
245
  // same record as a row offering Discard, so the sentence sends them there (#1629). Without an
240
246
  // entry here the code fell through to the generic "could not complete this chat action", which
@@ -260,6 +266,8 @@
260
266
  'chat-provider-identity-changed': 'The connected AI account changed while this response was running. Refresh the conversation and try again.',
261
267
  'chat-integration-unavailable': 'Connected accounts are unavailable right now. Open Integrations and try again.',
262
268
  'chat-integration-input-invalid': 'The connected account request was not valid. Check Integrations and try again.',
269
+ // #2153: the same words the server gives the AI (AWARE's 2,048-byte limit on a text input).
270
+ 'chat-integration-input-too-long': 'The search text is too long for this account read: it can be at most 2,048 bytes. Shorten it and try again.',
263
271
  'chat-integration-limit-invalid': 'The connected account request was too large. Remove some items and try again.',
264
272
  'chat-integration-stale': 'This connected account needs attention. Reconnect it in Integrations, then try again.',
265
273
  'chat-integration-not-runnable': 'This connected account cannot be used right now. Check Integrations and try again.',
@@ -304,6 +312,12 @@
304
312
  if (code === 'chat-owner-busy' || /project or workflow already has a modifying chat turn/i.test(raw)) {
305
313
  return 'Another AI Chat is changing this project or workflow. Wait for it to finish or stop it before sending here.';
306
314
  }
315
+ if (code === 'chat-project-run-busy') {
316
+ return 'A background request is changing this project. Wait for it to finish, or stop it, before sending here.';
317
+ }
318
+ if (code === 'chat-project-waiting') {
319
+ return 'A background request is already waiting to change this project. Let it go first, or send your message now.';
320
+ }
307
321
  if (code === 'chat-host-busy' || /host application instance already has a modifying owner/i.test(raw)) {
308
322
  return 'Another task is using the connected design application. Wait for it to finish or stop it before trying again.';
309
323
  }
@@ -2223,11 +2237,13 @@
2223
2237
  const review = event.payload?.tool === 'auto-review' ? event.payload.decision : null;
2224
2238
  // #2035: a step declined because nobody was watching a scheduled run is a notice the person reads later, not an error.
2225
2239
  const unattended = event.payload?.tool === 'unattended-decline';
2226
- item.className = review === 'approved' ? 'ai-chat-event auto-review' : review || unattended ? 'ai-chat-event auto-review held' : 'ai-chat-event error';
2240
+ // #2058: an account command Codex ran without asking FloLess already ran; its line says the result is unchecked.
2241
+ const unchecked = event.payload?.tool === 'unchecked-command';
2242
+ item.className = review === 'approved' ? 'ai-chat-event auto-review' : review || unattended || unchecked ? 'ai-chat-event auto-review held' : 'ai-chat-event error';
2227
2243
  item.dataset.eventSequence = String(event.sequence);
2228
2244
  item.dataset.eventId = event.eventId;
2229
2245
  const label = document.createElement('strong');
2230
- label.textContent = review === 'approved' ? 'Auto-approved' : review ? 'Held back' : unattended ? 'Declined' : 'Not done';
2246
+ label.textContent = review === 'approved' ? 'Auto-approved' : review ? 'Held back' : unattended ? 'Declined' : unchecked ? 'Not checked' : 'Not done';
2231
2247
  item.append(label, document.createTextNode(` · ${event.payload.message}`));
2232
2248
  return item;
2233
2249
  }
@@ -2239,7 +2255,7 @@
2239
2255
  item.dataset.eventSequence = String(event.sequence);
2240
2256
  item.dataset.eventId = event.eventId;
2241
2257
  const label = document.createElement('strong');
2242
- label.textContent = event.payload.tool === 'guide' ? 'FloLess' : 'Agent run';
2258
+ label.textContent = event.payload.tool === 'guide' || event.payload.tool === 'instructor' ? 'FloLess' : 'Agent run';
2243
2259
  item.append(label, document.createTextNode(` · ${String(event.payload.message || '')}`));
2244
2260
  return item;
2245
2261
  }
@@ -2333,8 +2349,12 @@
2333
2349
  const service = payload.targetKind === 'host' || !services ? null : services.find((row) => row.id === payload.target) || null;
2334
2350
  const alias = payload.targetKind === 'host' ? null : service?.choice?.source === 'floless' ? (service.choice.alias ?? null) : undefined;
2335
2351
  const receipt = payload.checkAgent && alias !== undefined ? connectionsApi()?.cachedReceipt(payload.checkAgent, alias) : null;
2352
+ // #2056: a card for a service used through the person's own connector follows this chat's switch, and its reply.
2353
+ const chat = state.chat;
2336
2354
  const signature = JSON.stringify([event.eventId, dismissed, service, Boolean(services?.choicesUnreadable), Boolean(services),
2337
- connectionLive.error, receipt?.probedAt || null, receipt?.state || null, entry.error, entry.busy]);
2355
+ connectionLive.error, receipt?.probedAt || null, receipt?.state || null, entry.error, entry.busy,
2356
+ chat?.provider || null, chat?.settings?.useOwnConnectors === true, Boolean(chat?.activeTurn), chat?.integrationBindings?.length || 0,
2357
+ Boolean(chat?.archivedAt), state.ownConnectorsSaving === true]);
2338
2358
  if (entry.node && entry.signature === signature) return entry.node;
2339
2359
  // A check running, or its inline question open, lives in this node: keep it until it settles.
2340
2360
  if (entry.node && entry.node.querySelector('[aria-busy="true"], [aria-expanded="true"]')) return entry.node;
@@ -2466,7 +2486,32 @@
2466
2486
  } else if (!services.choicesUnreadable && service.choice?.source === 'native') {
2467
2487
  // Their own Claude/Codex connection is the choice, whatever FloLess's own accounts look like (#1900 review): the
2468
2488
  // way out is Change account, never Connect or Reconnect of an account FloLess was told not to use.
2469
- stateLine.textContent = `FloLess uses your Claude or Codex connection for ${name}. FloLess can’t see or check that connection.`;
2489
+ // #2056: and the choice leads somewhere: this conversation's own-connectors switch, offered in place.
2490
+ const chat = state.chat;
2491
+ const provider = providerLabels[chat?.provider] || 'Claude or Codex';
2492
+ const heldOff = Boolean(chat?.integrationBindings?.length);
2493
+ const on = !heldOff && chat?.settings?.useOwnConnectors === true;
2494
+ const chosen = `You chose your own Claude or Codex connection for ${name}, so FloLess won’t use one of its own accounts for it.`;
2495
+ // FloLess cannot see whether a connector for it exists (it never sees Claude's), so the card says "can use … if".
2496
+ title.textContent = heldOff ? `Your own connector for ${name} is off in this chat`
2497
+ : on ? `Your ${provider} connectors are on for ${name}` : `Use your own ${provider} connector for ${name}?`;
2498
+ stateLine.textContent = heldOff ? `${chosen} This chat uses a FloLess connected account, so your own connectors stay off here. To use your own, stop using that account in this chat’s Connected accounts (chat settings ⚙).`
2499
+ : on ? `${chosen} Your ${provider} connectors are on in this chat, so the AI can use yours for it if you have one. Every call asks you first.`
2500
+ : `${chosen} Your ${provider} connectors are off in this chat; turn them on so the AI can use yours for it if you have one. Every call still asks you first.`;
2501
+ if (!heldOff && !on) {
2502
+ const turnOn = connectionButton('Use my connectors in this chat', 'shell.chat-connection-own-connectors', target, name, 'ai-chat-filter-apply');
2503
+ // The accessible name starts with the visible words (WCAG 2.5.3), so a voice command that says them works.
2504
+ turnOn.setAttribute('aria-label', `Use my connectors in this chat, for ${name} (${provider})`);
2505
+ const blocked = !chat ? 'Open a conversation first.'
2506
+ : chat.archivedAt ? 'This conversation is archived, so its settings can’t change.'
2507
+ : chat.activeTurn ? 'Wait for the current AI reply to finish before changing this.'
2508
+ : state.ownConnectorsSaving === true ? 'Turning your connectors on…' : '';
2509
+ turnOn.disabled = Boolean(blocked);
2510
+ turnOn.dataset.tip = blocked || `Turns on the connectors you added to ${provider} for this conversation only. Each call still asks you first.`;
2511
+ if (blocked) turnOn.dataset.blockedReason = blocked;
2512
+ turnOn.addEventListener('click', () => { void turnOnOwnConnectorsFromCard(); });
2513
+ actions.append(turnOn);
2514
+ }
2470
2515
  actions.append(integrations('Change account', 'shell.chat-connection-change-account', `Opens Integrations at ${name}, where you choose the account FloLess uses.`));
2471
2516
  } else if (api.signInExpired(service)) {
2472
2517
  stateLine.textContent = `The sign-in for ${name} expired. Reconnect it in Integrations, then check it works.`;
@@ -2639,7 +2684,7 @@
2639
2684
  // #1890 PR 3a: a decided workflow create stays visible as one line, so a reload never shows it as pending.
2640
2685
  if (event.type === 'approval-decided' && event.payload?.create) return renderCreateReceipt(event);
2641
2686
  if (event.type === 'approval-requested' || event.type === 'approval-decided' || event.type === 'state' || event.type === 'followup-status') return null;
2642
- if (event.type === 'tool' && (event.payload?.tool === 'agent' || event.payload?.tool === 'guide') && typeof event.payload?.message === 'string') return renderAgentRunLine(event);
2687
+ if (event.type === 'tool' && ['agent', 'guide', 'instructor'].includes(event.payload?.tool) && typeof event.payload?.message === 'string') return renderAgentRunLine(event);
2643
2688
  if (event.type === 'tekla-read') return renderTeklaReadEvent(event);
2644
2689
  if (event.type === 'height-question') return renderHeightQuestion(event);
2645
2690
  if (event.type === 'setup-question') return renderSetupQuestion(event);
@@ -4396,19 +4441,46 @@
4396
4441
  return time;
4397
4442
  }
4398
4443
 
4399
- function animatedDots() {
4400
- const dots = document.createElement('span'); dots.className = 'ai-chat-live-dots'; dots.setAttribute('aria-hidden', 'true');
4401
- dots.append(document.createElement('i'), document.createElement('i'), document.createElement('i'));
4402
- return dots;
4444
+ // #2079: Flo shows what the AI is doing in this turn, from the events the feed already has. Working, with its hat
4445
+ // on, while a tool it started has not reported an end; Thinking otherwise. FloLess's own receipts (plain lines, an
4446
+ // agent run's or the Guide's opening line) are not the AI's tools. While the AI waits for the person to answer an
4447
+ // approval it is doing nothing: Flo idles, and the approval card's Flo asks. Claude never reports a tool's end, so
4448
+ // writing again ends it, and so does a declined approval (it never will run). Codex ends each tool by its own item
4449
+ // id (#2102), so one finishing does not end another running beside it.
4450
+ const TOOL_ENDED = new Set(['completed', 'failed', 'denied', 'declined', 'error']);
4451
+ function liveFloMood() {
4452
+ if (state.chat?.state === 'awaiting-approval' || state.chat?.pendingApproval) return 'idle';
4453
+ const turnId = state.chat?.activeTurn?.turnId;
4454
+ // Codex ends every tool itself, by its item id; Claude never does, so for Claude writing again or a declined
4455
+ // approval is what ends it.
4456
+ const endsItsOwnTools = state.chat?.provider === 'codex';
4457
+ const running = new Set();
4458
+ for (const event of state.events) {
4459
+ if (event.turnId !== turnId) continue;
4460
+ if (event.type === 'assistant-message') { if (!endsItsOwnTools) running.clear(); }
4461
+ else if (event.type === 'approval-decided') { if (event.payload?.decision !== 'allow' && !endsItsOwnTools) running.clear(); }
4462
+ else if (event.type === 'tool' && event.payload?.plain !== true && event.payload?.tool !== 'agent' && event.payload?.tool !== 'guide') {
4463
+ const key = event.providerItemId || event.eventId || event.payload?.tool;
4464
+ if (TOOL_ENDED.has(event.payload?.status)) running.delete(key); else running.add(key);
4465
+ }
4466
+ }
4467
+ return running.size ? 'working' : 'thinking';
4403
4468
  }
4404
4469
 
4405
- function renderLiveStatus(event) {
4406
- const item = document.createElement('div'); item.className = 'ai-chat-live-status';
4407
- item.classList.add('dots-only');
4408
- item.setAttribute('aria-hidden', 'true');
4409
- const label = document.createElement('span'); label.className = 'ai-chat-live-label';
4410
- const dots = animatedDots();
4411
- item.append(label, dots); return item;
4470
+ // The feed is rebuilt on every event, so the live row is one kept node: Flo carries on instead of restarting
4471
+ // on every streamed word. The row is decoration; announceLiveResponseOnce speaks for it.
4472
+ function renderLiveStatus() {
4473
+ if (!state.liveFlo) {
4474
+ const item = document.createElement('div'); item.className = 'ai-chat-live-status';
4475
+ item.setAttribute('aria-hidden', 'true');
4476
+ const label = document.createElement('span'); label.className = 'ai-chat-live-label';
4477
+ item.append(label);
4478
+ state.liveFlo = { item, flo: typeof floAvatar === 'function' ? floAvatar(item, { size: 22, mood: 'thinking', hatRoom: true }) : null };
4479
+ }
4480
+ const mood = liveFloMood();
4481
+ state.liveFlo.item.dataset.mood = mood;
4482
+ state.liveFlo.flo?.setMood(mood, mood === 'working');
4483
+ return state.liveFlo.item;
4412
4484
  }
4413
4485
 
4414
4486
  function announceLiveResponseOnce() {
@@ -4463,7 +4535,7 @@
4463
4535
  }
4464
4536
 
4465
4537
  function updateOffscreenActivity() {
4466
- const liveDots = ui.feed.querySelector('.ai-chat-live-status .ai-chat-live-dots');
4538
+ const liveDots = ui.feed.querySelector('.ai-chat-live-status');
4467
4539
  // Showing the badge claims a row below the feed. Require enough room for that row before
4468
4540
  // showing it, otherwise ResizeObserver could alternate between show and hide in a short pane.
4469
4541
  const minimumFeedHeight = ui.offscreenActivity.hidden ? 88 : 48;
@@ -4525,7 +4597,7 @@
4525
4597
  }
4526
4598
  // Something FloLess itself refused during the answer (a file change it declined, a connector it turned away,
4527
4599
  // #1890 PR 2b / #1907), written for the person: held and shown under the answer, like the receipts below.
4528
- if (event.type === 'tool' && event.payload?.plain === true && event.payload?.tool !== 'agent' && event.payload?.tool !== 'guide'
4600
+ if (event.type === 'tool' && event.payload?.plain === true && !['agent', 'guide', 'instructor'].includes(event.payload?.tool)
4529
4601
  && typeof event.payload?.message === 'string' && event.payload.message) {
4530
4602
  links.push({ turnId: event.turnId, node: renderPlainNotice(event) });
4531
4603
  continue;
@@ -4536,7 +4608,7 @@
4536
4608
  // the suggestion and a check's result are receipts like the ones below, held under the answer they were written during.
4537
4609
  // #2007: an agent run's first line (who started it, its scope) is a tool event too, but it is the conversation's
4538
4610
  // opening line, not a tool: shown where it was written, before the instructions.
4539
- if (event.type === 'tool' && (event.payload?.tool === 'agent' || event.payload?.tool === 'guide') && typeof event.payload?.message === 'string') {
4611
+ if (event.type === 'tool' && ['agent', 'guide', 'instructor'].includes(event.payload?.tool) && typeof event.payload?.message === 'string') {
4540
4612
  flushAssistant();
4541
4613
  ui.feed.append(renderAgentRunLine(event));
4542
4614
  continue;
@@ -4683,6 +4755,12 @@
4683
4755
  existing?.remove();
4684
4756
  const card = document.createElement('section'); card.className = 'ai-chat-approval';
4685
4757
  card.dataset.approvalId = approval.approvalId;
4758
+ // #2079: Flo, hat on, faces the person: the AI is asking, and the person decides. Still, and never beside Allow.
4759
+ if (typeof floAvatar === 'function') {
4760
+ const flo = document.createElement('span'); flo.className = 'ai-chat-approval-flo';
4761
+ card.classList.add('has-flo'); card.append(flo);
4762
+ floAvatar(flo, { size: 28, mood: 'yourcall', hat: true });
4763
+ }
4686
4764
  if (teklaBinding || connector || change || connectionCheck) card.dataset.allowanceRevision = allowanceRevision;
4687
4765
  // #1890 PR 3a: the AI asking to create a workflow, with where it would go.
4688
4766
  const create = approval.create && typeof approval.create === 'object' ? approval.create : null;
@@ -5551,12 +5629,18 @@
5551
5629
  ui.model.querySelector('strong').textContent = chat?.settings.model ? (model?.label || chat.settings.model) : (model?.label || 'Choose model');
5552
5630
  const medium = (model?.efforts || []).find((effort) => effort.toLowerCase() === 'medium');
5553
5631
  ui.effort.querySelector('strong').textContent = effortLabel(chat?.settings.effort || medium || model?.efforts?.[0]) || 'Choose effort';
5554
- ui.permission.querySelector('strong').textContent = permissionLabel(chat?.settings.permissionProfile);
5555
- ui.permission.dataset.tip = permissionTip(chat?.settings.permissionProfile);
5632
+ // #2059: an Instructor answer's AI has no tools. Its Access says so; choosing one asks first (confirmInstructorRelease).
5633
+ const instructorChat = isInstructorAnswer(chat);
5634
+ ui.permission.querySelector('strong').textContent = instructorChat ? 'No tools' : permissionLabel(chat?.settings.permissionProfile);
5635
+ ui.permission.dataset.tip = instructorChat
5636
+ ? 'This chat answers an Instructor question, so the AI can’t read files, run commands, search the web or use your connectors. Choose an Access to turn it into an ordinary chat. FloLess asks first.'
5637
+ : permissionTip(chat?.settings.permissionProfile);
5556
5638
  // #2046: the Guide always reads only; its Access is said, not chosen, beside its Turn off and Delete.
5557
5639
  const guideChat = chat?.initiator?.kind === 'guide';
5558
5640
  ui.permission.hidden = guideChat;
5559
5641
  if (ui.guideAccess) ui.guideAccess.hidden = !guideChat;
5642
+ // #2053: the Guide's morning briefing lives here too; web/guide.js paints it (only when something changed).
5643
+ if (guideChat) window.flolessGuide?.paintBriefing?.();
5560
5644
  paintWorkspaceUnits();
5561
5645
  const bindings = chat?.integrationBindings || [];
5562
5646
  ui.integrations.querySelector('strong').textContent = bindings.length
@@ -5564,8 +5648,10 @@
5564
5648
  : 'Not using one';
5565
5649
  const frozen = !chat || Boolean(chat.activeTurn) || !state.capability?.available;
5566
5650
  ui.model.disabled = frozen; ui.effort.disabled = frozen; ui.permission.disabled = frozen;
5567
- ui.integrations.disabled = frozen || Boolean(chat?.nativeSessionId);
5568
- const integrationBlocked = chat?.nativeSessionId
5651
+ ui.integrations.disabled = frozen || Boolean(chat?.nativeSessionId) || instructorChat;
5652
+ const integrationBlocked = instructorChat
5653
+ ? 'An Instructor answer uses no tools, so it cannot use a connected account. Start a new chat to use one.'
5654
+ : chat?.nativeSessionId
5569
5655
  ? 'Connected accounts are fixed after the first message. Start a new chat to use another account.'
5570
5656
  : !chat ? 'Open a conversation first.'
5571
5657
  : chat.activeTurn ? 'Connected accounts cannot change during an active turn.'
@@ -6398,6 +6484,7 @@
6398
6484
 
6399
6485
  function closePicker() {
6400
6486
  state.picker = null; state.pickerOpener = null; ui.picker.hidden = true; ui.picker.replaceChildren();
6487
+ ui.picker.removeAttribute('aria-describedby');
6401
6488
  for (const control of [ui.model, ui.effort, ui.permission, ui.integrations]) control.setAttribute('aria-expanded', 'false');
6402
6489
  }
6403
6490
 
@@ -6409,7 +6496,7 @@
6409
6496
  if (opener?.isConnected && !opener.disabled) opener.focus();
6410
6497
  }
6411
6498
 
6412
- function openPicker(kind, anchor, choices) {
6499
+ function openPicker(kind, anchor, choices, note) {
6413
6500
  if (anchor.disabled) return;
6414
6501
  if (state.picker === kind) { closePicker(); return; }
6415
6502
  toggleHistory(false); closePicker(); state.picker = kind; state.pickerOpener = anchor;
@@ -6424,23 +6511,103 @@
6424
6511
  row.addEventListener('click', async () => { closePicker(); await saveSettings(choice.patch); anchor.focus(); });
6425
6512
  ui.picker.append(row);
6426
6513
  }
6514
+ // A quiet line after the choices says why one is missing; it is not an option, so the list is described by it.
6515
+ if (note) {
6516
+ const line = document.createElement('div'); line.className = 'ai-chat-picker-note'; line.id = 'chat-picker-note'; line.textContent = note;
6517
+ ui.picker.append(line); ui.picker.setAttribute('aria-describedby', line.id);
6518
+ }
6427
6519
  ui.picker.hidden = false; anchor.setAttribute('aria-expanded', 'true');
6428
6520
  const selected = ui.picker.querySelector('[aria-selected="true"]') || ui.picker.querySelector('button');
6429
6521
  selected?.focus();
6430
6522
  }
6431
6523
 
6524
+ /** #2059: an Instructor-started conversation the person has not widened: its AI answers with no tools. */
6525
+ function isInstructorAnswer(chat) {
6526
+ // The server's rule (chatIsInstructorAnswer): durable facts only, never the stored settings.
6527
+ return chat?.initiator?.kind === 'instructor' && !chat.instructorReleasedAt;
6528
+ }
6529
+
6530
+ /** #2059: does this settings change give an Instructor answer's AI tools (any Access choice, or the person's connectors)? */
6531
+ function widensInstructorAnswer(patch) {
6532
+ return isInstructorAnswer(state.chat) && ('permissionProfile' in patch || patch.useOwnConnectors === true);
6533
+ }
6534
+
6535
+ /**
6536
+ * #2059: asks before an Instructor answer becomes an ordinary chat. Resolves true only on "Change…"; Escape, the
6537
+ * backdrop and "Keep as Instructor answer" all keep it as it is. Focus returns to whatever opened it.
6538
+ */
6539
+ function confirmInstructorRelease(patch) {
6540
+ return new Promise((resolve) => {
6541
+ const modal = document.getElementById('chat-instructor-access-modal');
6542
+ const keep = document.getElementById('chat-instructor-access-keep');
6543
+ const go = document.getElementById('chat-instructor-access-confirm');
6544
+ const sub = document.getElementById('chat-instructor-access-sub');
6545
+ if (!modal || !keep || !go || !sub) { resolve(false); return; }
6546
+ const back = document.activeElement instanceof HTMLElement ? document.activeElement : null;
6547
+ const connectors = patch.useOwnConnectors === true && !('permissionProfile' in patch);
6548
+ const chosen = connectors ? '' : permissionLabel(patch.permissionProfile);
6549
+ const provider = providerLabels[state.chat?.provider] || 'Claude or Codex';
6550
+ sub.textContent = 'This chat is an Instructor answer, so the AI used no tools. '
6551
+ + (connectors
6552
+ ? `If you turn on your ${provider} connectors, it becomes an ordinary chat, and its next replies can use the tools its Access allows as well as your connectors (each call still asks you first).`
6553
+ : `If you change Access to ${chosen}, it becomes an ordinary chat, and its next replies can use the tools ${chosen} allows.`)
6554
+ + ' Earlier answers stay as they were. You can’t switch it back to no tools: ask the Instructor again for that.';
6555
+ go.textContent = connectors ? 'Turn on connectors' : `Change to ${chosen}`;
6556
+ const done = (value) => {
6557
+ modal.classList.remove('show');
6558
+ modal.removeEventListener('keydown', onKey); modal.removeEventListener('click', onBackdrop);
6559
+ keep.removeEventListener('click', onKeep); go.removeEventListener('click', onGo);
6560
+ if (back?.isConnected) back.focus();
6561
+ resolve(value);
6562
+ };
6563
+ const onKey = (event) => {
6564
+ if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); done(false); return; }
6565
+ if (event.key === 'Tab') {
6566
+ // Keep focus inside the two choices while the question is open.
6567
+ const order = [keep, go];
6568
+ const at = order.indexOf(document.activeElement);
6569
+ event.preventDefault();
6570
+ order[(at + (event.shiftKey ? order.length - 1 : 1)) % order.length].focus();
6571
+ }
6572
+ };
6573
+ const onBackdrop = (event) => { if (event.target === modal) done(false); };
6574
+ const onKeep = () => done(false);
6575
+ const onGo = () => done(true);
6576
+ modal.addEventListener('keydown', onKey); modal.addEventListener('click', onBackdrop);
6577
+ keep.addEventListener('click', onKeep); go.addEventListener('click', onGo);
6578
+ modal.classList.add('show');
6579
+ keep.focus();
6580
+ });
6581
+ }
6582
+
6432
6583
  async function saveSettings(patch, options = {}) {
6433
- const snapshot = captureChat();
6584
+ let snapshot = captureChat();
6434
6585
  if (!snapshot) return;
6586
+ // #2059: giving an Instructor answer tools asks first; the server refuses it without this confirmation.
6587
+ let release = false;
6588
+ if (widensInstructorAnswer(patch)) {
6589
+ if (!await confirmInstructorRelease(patch)) return;
6590
+ if (!sameChat(snapshot)) return;
6591
+ // The settings may have moved on while the question was open: apply the choice to what is current now.
6592
+ snapshot = captureChat();
6593
+ if (!snapshot) return;
6594
+ release = true;
6595
+ }
6435
6596
  const settings = { ...state.chat.settings, ...patch };
6436
6597
  if ('model' in patch && !('effort' in patch)) settings.effort = null;
6437
6598
  try {
6438
6599
  const chat = await request(`/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/settings`, {
6439
- method: 'PUT', body: JSON.stringify({ owner: snapshot.scope.owner, ...settings }),
6600
+ method: 'PUT', body: JSON.stringify({ owner: snapshot.scope.owner, ...settings, ...(release ? { releaseInstructorAnswer: true } : {}) }),
6440
6601
  });
6441
6602
  if (!sameChat(snapshot)) return;
6442
6603
  state.chat = chat;
6443
- paintConversation(); if (options.announce !== false) announce('Chat settings updated.');
6604
+ paintConversation();
6605
+ if (release) {
6606
+ announce(patch.useOwnConnectors === true && !('permissionProfile' in patch)
6607
+ ? 'Connectors on. This is now an ordinary chat.' : `Access changed to ${permissionLabel(chat.settings.permissionProfile)}. This is now an ordinary chat.`);
6608
+ // The transcript line the server wrote is shown now, not on the next poll.
6609
+ void refreshConversation(snapshot.chatId, false);
6610
+ } else if (options.announce !== false) announce('Chat settings updated.');
6444
6611
  } catch (error) { if (sameChat(snapshot)) report(error, 'Could not update settings'); }
6445
6612
  }
6446
6613
 
@@ -6504,10 +6671,16 @@
6504
6671
  : Object.keys(permissionLabels);
6505
6672
  return offered.map((value) => ({
6506
6673
  id: `permission:${value}`, label: permissionLabel(value), meta: permissionMeta(value, workspace),
6507
- selected: state.chat.settings.permissionProfile === value, patch: { permissionProfile: value },
6674
+ // #2059: an Instructor answer has none of these yet ("No tools" is a state, not a choice).
6675
+ selected: !isInstructorAnswer(state.chat) && state.chat.settings.permissionProfile === value, patch: { permissionProfile: value },
6508
6676
  }));
6509
6677
  }
6510
6678
 
6679
+ /** Why the workspace's Access list has no Auto or Full access; the same test permissionChoices uses to leave them out. */
6680
+ function permissionPickerNote() {
6681
+ return state.scope?.owner?.kind === 'workspace' ? 'Auto and Full access are offered inside a project or workflow.' : '';
6682
+ }
6683
+
6511
6684
  /** #2037: what Auto means in this conversation's Scope view; Codex's review may approve a change outside the folder. */
6512
6685
  function autoScopeNote() {
6513
6686
  const why = autoUnavailable();
@@ -6538,7 +6711,21 @@
6538
6711
  || row.alias || 'Provider account';
6539
6712
  }
6540
6713
 
6714
+ // #2154: AWARE's machine reason (AWARE >= 0.157) says exactly what is wrong with a connected account; each maps to the
6715
+ // one thing the person can do. Older AWAREs send none, and the word matching below stays the fallback.
6716
+ const INTEGRATION_REASON_COPY = Object.freeze({
6717
+ 'auth-invalid': 'Sign in again to this connected account in Integrations.',
6718
+ 'credential-expired': 'This account’s sign-in has expired. Sign in again in Integrations.',
6719
+ 'credential-missing': 'This account has no saved sign-in on this computer. Connect it again in Integrations.',
6720
+ 'scope-missing': 'This account was connected without permission to read these files. Connect it again in Integrations and allow file access.',
6721
+ 'identity-unverified': 'FloLess could not confirm which account this is. Verify it in Integrations, then try again.',
6722
+ 'generation-unavailable': 'FloLess could not check this account’s sign-in just now. Try again in a moment.',
6723
+ 'command-planned': 'This service is not available in FloLess Chat yet.',
6724
+ });
6725
+
6541
6726
  function integrationReason(row) {
6727
+ const code = typeof row?.reasonCode === 'string' ? row.reasonCode : '';
6728
+ if (Object.hasOwn(INTEGRATION_REASON_COPY, code)) return INTEGRATION_REASON_COPY[code];
6542
6729
  const raw = String(row?.reason || '');
6543
6730
  if (!raw) return 'This connected account is unavailable.';
6544
6731
  if (/expired|sign in|auth|token/i.test(raw)) return 'Sign in again to this connected account in Integrations.';
@@ -6770,7 +6957,7 @@
6770
6957
  // tell the two apart. Handing the text back then would send it twice; losing it from the
6771
6958
  // composer, which is what a torn record has always done, only costs the retype.
6772
6959
  || ['chat-provider-unavailable', 'chat-turn-active', 'chat-turn-settling', 'chat-followup-queued', 'chat-followup-unconfirmed',
6773
- 'chat-owner-busy', 'chat-host-busy', 'chat-attachment-scope',
6960
+ 'chat-owner-busy', 'chat-project-run-busy', 'chat-project-knowledge-busy', 'chat-project-waiting', 'chat-host-busy', 'chat-attachment-scope',
6774
6961
  'chat-root-stale', 'chat-archived'].includes(String(error?.code || ''));
6775
6962
  }
6776
6963
 
@@ -7205,7 +7392,9 @@
7205
7392
  if (reason) state.filterNotShared.set(clientSubmissionId, reason);
7206
7393
  }
7207
7394
 
7208
- async function sendTurn() {
7395
+ async function sendTurn(options) {
7396
+ // #2061: `override` — the person chose to send now over a background request that was waiting first.
7397
+ const sendOverride = options?.override === true;
7209
7398
  if (!state.chat || ui.send.disabled) return;
7210
7399
  // ONE AI CHAT (#1859, owner ruling 2026-10-01/02): the open Drawing Filter never changes where a message goes.
7211
7400
  // It is a turn, or a follow-up to a running reply (a drawing read included), exactly as anywhere else; the
@@ -7231,6 +7420,13 @@
7231
7420
  const uiContext = currentFloLessContext();
7232
7421
  const chatId = snapshot.chatId;
7233
7422
  const attachmentIds = state.attachments.map((item) => item.attachmentId);
7423
+ // #2061: the message as it was asked about, should the project turn out to be busy (see askIfProjectBusy).
7424
+ const busyMessage = { chatId, text, attachmentIds, subjectsField, filterField: filterContext.field };
7425
+ const askedBusy = !sendOverride && await projectBusyBeforeSend(snapshot, busyMessage);
7426
+ if (askedBusy || !sameChat(snapshot)) return;
7427
+ // Edited while FloLess checked — or already sent by an earlier click, which empties the box — nothing is sent over
7428
+ // the box's text now; it stays for the next Send.
7429
+ if (ui.input.value.trim() !== text || JSON.stringify(state.attachments.map((item) => item.attachmentId)) !== JSON.stringify(attachmentIds)) return;
7234
7430
  const clientSubmissionId = crypto.randomUUID();
7235
7431
  const previousChat = state.chat;
7236
7432
  const previousAttachments = state.attachments;
@@ -7257,8 +7453,11 @@
7257
7453
  // durable transcript must remain exactly what the user typed.
7258
7454
  owner: snapshot.scope.owner, clientSubmissionId, text, displayText: text, uiContext, attachmentIds,
7259
7455
  modifying: previousChat.settings.permissionProfile !== 'read-only', ...subjectsField, ...filterContext.field,
7456
+ // #2061: the person chose "Send my message now" over a request that was waiting first.
7457
+ ...(sendOverride ? { overrideWaiting: true } : {}),
7260
7458
  }),
7261
7459
  });
7460
+ if (sameChat(snapshot)) endProjectBusy();
7262
7461
  if (!sameChat(snapshot)) {
7263
7462
  noteFilterContext(clientSubmissionId, filterContext, result?.filterContext);
7264
7463
  return void subjectLinksSaved(subjects);
@@ -7282,10 +7481,317 @@
7282
7481
  state.chat = previousChat;
7283
7482
  state.attachments = previousAttachments;
7284
7483
  ui.input.value = text; autosize(); paintAttachments(); saveDraftSoon(); paintConversation();
7285
- report(error, 'Message was not sent');
7484
+ // #2061: the project is busy — ask (wait / open it / stop it) instead of only saying it failed. Nothing was sent.
7485
+ if (!askIfProjectBusy(error, busyMessage)) report(error, 'Message was not sent');
7286
7486
  } finally { if (sameChat(snapshot)) { setBusy(false); updateSendState(); } }
7287
7487
  }
7288
7488
 
7489
+ // ── #2061: a project another piece of work is changing ─────────────────────────────────────────────────────────
7490
+ // Asked, never refused (owner ruling 2026-10-07): wait and send by itself when the project is free, open the other
7491
+ // work, or stop it. The wait lives in this tab only — the message stays in the composer, which is what is sent — and it
7492
+ // sends only the message that was asked about: a changed text, file, selection or sheet stops it, saying why.
7493
+
7494
+ const PROJECT_BUSY_CODES = new Set(['chat-owner-busy', 'chat-project-run-busy', 'chat-project-knowledge-busy', 'chat-project-waiting', 'chat-host-busy']);
7495
+ const PROJECT_WAIT_POLL_MS = 4000;
7496
+ const PROJECT_WAIT_FAILURE_LIMIT = 5;
7497
+ const PROJECT_WAIT_CAP_MS = 30 * 60 * 1000;
7498
+ // #2106: the same remedy every waiter gives once organizing has held the project for the whole wait (server copy:
7499
+ // knowledgeStuckRemedy in project-wait-clock.ts).
7500
+ const KNOWLEDGE_STUCK_REMEDY = 'If organizing has stopped, restart FloLess — that clears an organize that already finished. If it still shows as organizing after that, open a terminal outside FloLess (Claude Code or Codex) and ask it to check and recover the stuck knowledge organize for this project, then send again.';
7501
+
7502
+ /** What a message means beyond its words: the selected objects and the open Drawing Filter's context. */
7503
+ function projectWaitContext(subjectsField, filterField) {
7504
+ try { return JSON.stringify({ subjects: subjectsField?.subjects ?? null, filter: filterField ?? {} }); }
7505
+ catch { return ''; }
7506
+ }
7507
+
7508
+ function currentProjectWaitContext() {
7509
+ const subjects = subjectsPayload(composerSelection());
7510
+ return projectWaitContext(subjects ? { subjects } : {}, filterContextForSend().field);
7511
+ }
7512
+
7513
+ function holderTitle(holder) {
7514
+ if (holder?.kind === 'knowledge') return 'FloLess’s knowledge organizing';
7515
+ const title = String(holder?.title || (holder?.kind === 'chat' ? 'another AI Chat conversation' : 'another background request'));
7516
+ return holder?.kind === 'chat' ? `“${title}”` : title;
7517
+ }
7518
+
7519
+ /** A holder named at the start of a sentence ("the background request …" → "The background request …"). */
7520
+ function sentenceCase(text) {
7521
+ return text ? text.charAt(0).toUpperCase() + text.slice(1) : text;
7522
+ }
7523
+
7524
+ function endProjectBusy() {
7525
+ const busy = state.projectBusy;
7526
+ if (busy?.timer) clearInterval(busy.timer);
7527
+ state.projectBusy = null;
7528
+ shell.querySelector('.ai-chat-busy-ask')?.remove();
7529
+ }
7530
+
7531
+ /** The pending-message record the wait compares against before it sends by itself. */
7532
+ function busyMessageRecord(message) {
7533
+ return { chatId: message.chatId, text: message.text, attachmentIds: JSON.stringify(message.attachmentIds),
7534
+ context: projectWaitContext(message.subjectsField, message.filterField) };
7535
+ }
7536
+
7537
+ /**
7538
+ * A message that may change files first asks whether the project is free (a read; nothing is sent), so a busy
7539
+ * project is asked about at once instead of after a refused send. The send itself still re-checks. True when it
7540
+ * asked; the caller still checks the person is in the same conversation before sending.
7541
+ */
7542
+ async function projectBusyBeforeSend(snapshot, message) {
7543
+ if (state.chat?.settings?.permissionProfile === 'read-only' || snapshot.scope?.owner?.kind === 'workspace') return false;
7544
+ let holder = null;
7545
+ try {
7546
+ holder = (await request(`/api/chat/conversations/${encodeURIComponent(message.chatId)}/project-holder?${ownerQuery(snapshot.scope.owner)}`))?.holder || null;
7547
+ } catch (error) { console.warn('[chat] could not check whether the project is free; sending anyway:', error); }
7548
+ if (!holder || !sameChat(snapshot)) return false;
7549
+ askProjectBusy(holder, busyMessageRecord(message));
7550
+ return true;
7551
+ }
7552
+
7553
+ /** A send refused because the project is busy is asked about; true when it was. Any other refusal ends a wait. */
7554
+ function askIfProjectBusy(error, message) {
7555
+ if (PROJECT_BUSY_CODES.has(String(error?.code || '')) && error?.holder) {
7556
+ askProjectBusy(error.holder, busyMessageRecord(message));
7557
+ return true;
7558
+ }
7559
+ endProjectBusy(); // a wait never retries a message refused for another reason
7560
+ return false;
7561
+ }
7562
+
7563
+ /** The project is busy: ask what to do. */
7564
+ function askProjectBusy(holder, message) {
7565
+ const waitingBefore = state.projectBusy?.mode === 'waiting' && state.projectBusy.message.chatId === message.chatId;
7566
+ if (waitingBefore) {
7567
+ // Still busy when the wait tried to send (another piece of work got there first): keep waiting, name the new holder.
7568
+ state.projectBusy.holder = holder;
7569
+ paintProjectBusy();
7570
+ return;
7571
+ }
7572
+ endProjectBusy();
7573
+ state.projectBusy = { mode: holder.waiting ? 'queued-request' : 'ask', holder, message, since: Date.now(), timer: null };
7574
+ paintProjectBusy({ focus: true });
7575
+ }
7576
+
7577
+ function startProjectWait() {
7578
+ const busy = state.projectBusy;
7579
+ if (!busy) return;
7580
+ busy.mode = 'waiting';
7581
+ busy.since = Date.now();
7582
+ if (busy.timer) clearInterval(busy.timer);
7583
+ busy.timer = setInterval(() => void checkProjectWait(), PROJECT_WAIT_POLL_MS);
7584
+ paintProjectBusy();
7585
+ ui.input.focus();
7586
+ void checkProjectWait();
7587
+ }
7588
+
7589
+ async function checkProjectWait() {
7590
+ const busy = state.projectBusy;
7591
+ if (!busy || busy.mode !== 'waiting' || busy.checking) return;
7592
+ // The wait belongs to the conversation it was asked in; leaving it ends the wait (the draft stays there).
7593
+ if (state.chat?.chatId !== busy.message.chatId) { endProjectBusy(); return; }
7594
+ if (Date.now() - busy.since >= PROJECT_WAIT_CAP_MS) {
7595
+ clearInterval(busy.timer); busy.timer = null; busy.mode = 'cap';
7596
+ paintProjectBusy({ focus: true });
7597
+ return;
7598
+ }
7599
+ busy.checking = true;
7600
+ try {
7601
+ const owner = state.scope?.owner;
7602
+ const found = await request(`/api/chat/conversations/${encodeURIComponent(busy.message.chatId)}/project-holder?${ownerQuery(owner)}${busy.override ? '&overrideWaiting=1' : ''}`);
7603
+ if (state.projectBusy !== busy || busy.mode !== 'waiting') return;
7604
+ busy.failures = 0;
7605
+ if (found?.holder) {
7606
+ busy.sendNotReady = false;
7607
+ if (found.holder.title !== busy.holder.title) { busy.holder = found.holder; paintProjectBusy(); }
7608
+ paintProjectBusyElapsed();
7609
+ return;
7610
+ }
7611
+ // Free. Send only the message that was asked about.
7612
+ const sameMessage = ui.input.value.trim() === busy.message.text
7613
+ && JSON.stringify(state.attachments.map((item) => item.attachmentId)) === busy.message.attachmentIds
7614
+ && currentProjectWaitContext() === busy.message.context;
7615
+ if (!sameMessage) {
7616
+ clearInterval(busy.timer); busy.timer = null; busy.mode = 'changed';
7617
+ paintProjectBusy({ focus: true });
7618
+ return;
7619
+ }
7620
+ // Free, but this conversation can't send yet (still answering, or not ready): try again on the next check.
7621
+ if (ui.send.disabled || turnIsVisiblyActive()) { busy.sendNotReady = true; return; }
7622
+ clearInterval(busy.timer); busy.timer = null;
7623
+ busy.sending = true;
7624
+ await sendTurn({ override: Boolean(busy.override) });
7625
+ } catch (error) {
7626
+ // A check that failed is tried again a few times; one the server refused outright (the conversation moved or was
7627
+ // archived), or several in a row, end the wait and say so — never later blamed on the other work.
7628
+ console.warn('[chat] could not check whether the project is free:', error);
7629
+ busy.failures = (busy.failures || 0) + 1;
7630
+ const refused = Number(error?.status) >= 400 && Number(error?.status) < 500;
7631
+ if (state.projectBusy === busy && (refused || busy.failures >= PROJECT_WAIT_FAILURE_LIMIT)) {
7632
+ clearInterval(busy.timer); busy.timer = null; busy.mode = 'check-failed';
7633
+ paintProjectBusy({ focus: true });
7634
+ }
7635
+ } finally {
7636
+ busy.checking = false;
7637
+ busy.sending = false;
7638
+ // A send refused again as busy resumed the wait (askProjectBusy); anything else ended it.
7639
+ if (state.projectBusy === busy && busy.mode === 'waiting' && !busy.timer) {
7640
+ busy.timer = setInterval(() => void checkProjectWait(), PROJECT_WAIT_POLL_MS);
7641
+ }
7642
+ }
7643
+ }
7644
+
7645
+ /**
7646
+ * #2104: the design program a holder is using, by the name a person knows it ("Revit"), or `fallback` when FloLess
7647
+ * cannot name it (SketchUp/AutoCAD/ArchiCAD share one claim, and older records carry no key).
7648
+ */
7649
+ function hostProgramLabel(holder, fallback) {
7650
+ const kind = String(holder?.hostKey || '').split(':', 1)[0];
7651
+ return ({ tekla: 'Tekla', revit: 'Revit', rhino: 'Rhino' })[kind] || fallback;
7652
+ }
7653
+
7654
+ async function stopProjectHolder() {
7655
+ const busy = state.projectBusy;
7656
+ const holder = busy?.holder;
7657
+ // #2106: organizing carries a request id but is never a background run: there is nothing here to stop.
7658
+ if (!holder || holder.kind === 'knowledge') return;
7659
+ try {
7660
+ if (holder.kind === 'chat' && holder.chatId && holder.owner) {
7661
+ await request(`/api/chat/conversations/${encodeURIComponent(holder.chatId)}/stop`, { method: 'POST',
7662
+ body: JSON.stringify({ owner: holder.owner, expectTurnId: holder.turnId || undefined }) });
7663
+ } else if (holder.requestId) {
7664
+ await request(`/api/requests/${encodeURIComponent(holder.requestId)}/run/stop`, { method: 'POST',
7665
+ body: JSON.stringify(holder.leaseId ? { expectLeaseId: holder.leaseId } : {}) });
7666
+ }
7667
+ announce(`Stopped ${holderTitle(holder)}. Your message sends as soon as ${holder.reason === 'host' ? hostProgramLabel(holder, 'the design program') : 'the project'} is free.`);
7668
+ } catch (error) {
7669
+ // Already finished, or could not be stopped: say so, and still wait — the message goes once the project is free.
7670
+ announce(error?.code === 'stop-stale' ? 'That work had already finished, so nothing was stopped.' : `FloLess couldn’t stop ${holderTitle(holder)}. It keeps waiting instead.`);
7671
+ }
7672
+ if (state.projectBusy === busy) startProjectWait();
7673
+ }
7674
+
7675
+ /** Whether "Open it" has somewhere to go: a conversation, a request, or (#2106) the project's Knowledge step. */
7676
+ function canOpenHolder(holder) {
7677
+ if (holder?.kind === 'knowledge') return Boolean(holder.projectId);
7678
+ return Boolean(holder?.kind === 'chat' ? holder.owner : holder?.requestId);
7679
+ }
7680
+
7681
+ /** #2106: a project's Knowledge step. A missing Workspaces bridge is said, never a silent no-op. */
7682
+ async function openKnowledgeStepOf(projectId) {
7683
+ const open = window.flolessWorkspaces?.openKnowledgeStep;
7684
+ if (typeof open !== 'function') throw new Error('FloLess couldn’t open that project’s Knowledge step. Open it from Workspaces.');
7685
+ await open(projectId);
7686
+ }
7687
+
7688
+ async function openProjectHolder() {
7689
+ const holder = state.projectBusy?.holder;
7690
+ if (!holder) return;
7691
+ if (holder.kind === 'knowledge') {
7692
+ // The wait keeps going: opening the Knowledge step only shows the organizing this message waits for.
7693
+ try { await openKnowledgeStepOf(holder.projectId); }
7694
+ catch (error) { announce(error?.message || 'FloLess couldn’t open that project’s Knowledge step. Open it from Workspaces.'); }
7695
+ return;
7696
+ }
7697
+ if (holder.kind === 'chat' && holder.chatId && holder.owner) {
7698
+ endProjectBusy(); // the wait belongs to this conversation; opening the other one ends it (the draft is kept)
7699
+ const opened = await openConversationIn({ owner: holder.owner }, holder.chatId).catch(() => false);
7700
+ if (!opened) announce('FloLess couldn’t open that conversation. It may have finished or moved.');
7701
+ return;
7702
+ }
7703
+ if (holder.requestId && typeof window.flolessBridge?.openRequest === 'function') {
7704
+ await window.flolessBridge.openRequest(holder.requestId);
7705
+ }
7706
+ }
7707
+
7708
+ function paintProjectBusyElapsed() {
7709
+ const line = shell.querySelector('.ai-chat-busy-ask .ai-chat-busy-elapsed');
7710
+ const busy = state.projectBusy;
7711
+ if (!line || !busy) return;
7712
+ const minutes = Math.floor((Date.now() - busy.since) / 60000);
7713
+ line.textContent = minutes < 1 ? 'Waiting less than a minute' : `Waiting ${minutes} min`;
7714
+ }
7715
+
7716
+ function paintProjectBusy({ focus = false } = {}) {
7717
+ shell.querySelector('.ai-chat-busy-ask')?.remove();
7718
+ const busy = state.projectBusy;
7719
+ if (!busy) return;
7720
+ const who = holderTitle(busy.holder);
7721
+ const knowledge = busy.holder.kind === 'knowledge';
7722
+ const card = document.createElement('section');
7723
+ const neutral = busy.mode === 'waiting';
7724
+ // Its own class, never .ai-chat-runtime: the setup card's painter removes any element carrying that one.
7725
+ card.className = `ai-chat-busy-ask${neutral ? '' : ' is-asking'}`;
7726
+ card.setAttribute('role', neutral ? 'status' : 'alert');
7727
+ if (neutral) card.setAttribute('aria-live', 'polite');
7728
+ const heading = document.createElement('strong');
7729
+ const copy = document.createElement('p');
7730
+ const actions = document.createElement('div'); actions.className = 'ai-chat-approval-actions';
7731
+ const add = (label, commandId, onClick, cls = '') => {
7732
+ const control = button(label, commandId, cls);
7733
+ control.addEventListener('click', onClick);
7734
+ actions.append(control);
7735
+ return control;
7736
+ };
7737
+ let primary = null;
7738
+ if (busy.mode === 'ask') {
7739
+ heading.textContent = knowledge ? 'FloLess is organizing this project’s knowledge right now' : busy.holder.reason === 'host'
7740
+ ? `${sentenceCase(who)} is using ${hostProgramLabel(busy.holder, 'the same design program')} on this computer right now`
7741
+ : `${sentenceCase(who)} is changing this project right now`;
7742
+ copy.textContent = 'Your message hasn’t been sent. It’s still in the box below.';
7743
+ primary = add('Wait and send when it’s free', 'shell.chat-busy-wait', () => startProjectWait(), 'allow');
7744
+ if (canOpenHolder(busy.holder)) add('Open it', 'shell.chat-busy-open', () => void openProjectHolder());
7745
+ // #2106: organizing is driven from outside FloLess (start/finish by the AI organizing it), so it is never stopped here.
7746
+ if (!knowledge && (busy.holder.kind === 'chat' ? busy.holder.owner : busy.holder.requestId)) add('Stop it', 'shell.chat-busy-stop', () => void stopProjectHolder(), 'ai-chat-busy-stop');
7747
+ } else if (busy.mode === 'queued-request') {
7748
+ heading.textContent = 'A background request is already waiting for this project';
7749
+ copy.textContent = 'It asked first. Let it go first and your message sends by itself after it finishes, or send your message now and the request waits.';
7750
+ primary = add('Let it go first', 'shell.chat-busy-let-first', () => startProjectWait(), 'allow');
7751
+ add('Send my message now', 'shell.chat-busy-send-now', () => { const current = state.projectBusy; if (current) current.override = true; void sendTurn({ override: true }); });
7752
+ if (busy.holder.requestId) add('Open it', 'shell.chat-busy-open', () => void openProjectHolder());
7753
+ } else if (busy.mode === 'waiting') {
7754
+ heading.textContent = knowledge ? 'Waiting for FloLess to finish organizing this project’s knowledge' : `Waiting for ${who} to finish`;
7755
+ const dots = document.createElement('span'); dots.className = 'ai-chat-live-dots'; dots.setAttribute('aria-hidden', 'true');
7756
+ dots.append(document.createElement('i'), document.createElement('i'), document.createElement('i'));
7757
+ heading.append(dots);
7758
+ copy.textContent = `Your message sends by itself when ${busy.holder.reason === 'host' ? hostProgramLabel(busy.holder, 'the design program') : 'this project'} is free. Keep this conversation open.`;
7759
+ const elapsed = document.createElement('p'); elapsed.className = 'ai-chat-busy-elapsed'; elapsed.setAttribute('aria-hidden', 'true');
7760
+ card.append(heading, copy, elapsed);
7761
+ if (canOpenHolder(busy.holder)) add('Open it', 'shell.chat-busy-open', () => void openProjectHolder());
7762
+ add('Cancel waiting', 'shell.chat-busy-cancel', () => { endProjectBusy(); announce('Stopped waiting. Your message is still in the box.'); ui.input.focus(); });
7763
+ } else if (busy.mode === 'cap') {
7764
+ heading.textContent = 'Still waiting after 30 minutes';
7765
+ copy.textContent = busy.sendNotReady
7766
+ ? 'Your message hasn’t been sent. This conversation wasn’t ready to send it. Check it, then press Send.'
7767
+ : knowledge
7768
+ ? `Your message hasn’t been sent. FloLess has been organizing this project’s knowledge for over 30 minutes. ${KNOWLEDGE_STUCK_REMEDY}`
7769
+ : `Your message hasn’t been sent. ${sentenceCase(who)} is still ${busy.holder.reason === 'host' ? `using ${hostProgramLabel(busy.holder, 'the same design program')}` : 'changing this project'}.`;
7770
+ primary = add('Keep waiting', 'shell.chat-busy-keep-waiting', () => startProjectWait(), 'allow');
7771
+ add('Cancel', 'shell.chat-busy-cancel', () => { endProjectBusy(); ui.input.focus(); });
7772
+ } else if (busy.mode === 'check-failed') {
7773
+ heading.textContent = `FloLess couldn’t check whether ${busy.holder.reason === 'host' ? hostProgramLabel(busy.holder, 'the design program') : 'the project'} is free`;
7774
+ copy.textContent = 'Your message hasn’t been sent. It’s still in the box below. Press Send to try again.';
7775
+ primary = add('OK', 'shell.chat-busy-dismiss', () => { endProjectBusy(); ui.input.focus(); }, 'allow');
7776
+ } else {
7777
+ heading.textContent = 'Your message wasn’t sent';
7778
+ copy.textContent = 'You changed the message or selection while waiting, so it wasn’t sent. Check it, then press Send.';
7779
+ primary = add('OK', 'shell.chat-busy-dismiss', () => { endProjectBusy(); ui.input.focus(); }, 'allow');
7780
+ }
7781
+ if (busy.mode !== 'waiting') card.append(heading, copy);
7782
+ if (busy.mode !== 'changed' && busy.mode !== 'waiting' && busy.mode !== 'check-failed') {
7783
+ const dismiss = button('×', 'shell.chat-busy-dismiss', 'ai-chat-busy-dismiss');
7784
+ dismiss.setAttribute('aria-label', 'Dismiss'); dismiss.dataset.tip = 'Dismiss — your message stays in the box';
7785
+ dismiss.addEventListener('click', () => { endProjectBusy(); ui.input.focus(); });
7786
+ card.prepend(dismiss);
7787
+ }
7788
+ card.append(actions);
7789
+ shell.insertBefore(card, ui.recovery);
7790
+ paintProjectBusyElapsed();
7791
+ if (busy.mode !== 'waiting') announce(`${heading.textContent}. ${copy.textContent}`);
7792
+ if (focus && primary) primary.focus();
7793
+ }
7794
+
7289
7795
  /**
7290
7796
  * A follow-up refused with `chat-turn-stale` was never saved (the route answers `chat-followup-unknown`
7291
7797
  * for anything it did save), so sending the same text as a new turn cannot duplicate it. Send stays
@@ -8650,6 +9156,15 @@
8650
9156
  }
8651
9157
  }
8652
9158
 
9159
+ /** #2056: the card's "Use my connectors in this chat" — the same switch as chat settings, for this conversation only. */
9160
+ async function turnOnOwnConnectorsFromCard() {
9161
+ if (state.ownConnectorsSaving === true || !state.chat) return;
9162
+ state.ownConnectorsSaving = true;
9163
+ repaintConnectionCards(); paintConnectorAllowance();
9164
+ try { await setOwnConnectors(true, { focusInput: true }); }
9165
+ finally { state.ownConnectorsSaving = false; repaintConnectionCards(); paintConnectorAllowance(); }
9166
+ }
9167
+
8653
9168
  async function turnOffOwnConnectors() {
8654
9169
  state.ownConnectorsSaving = true;
8655
9170
  paintConnectorAllowance();
@@ -8942,7 +9457,7 @@
8942
9457
  ui.model.addEventListener('click', () => openPicker('model', ui.model, modelChoices()));
8943
9458
  ui.switchAccount.addEventListener('click', () => { void switchAccount(); });
8944
9459
  ui.effort.addEventListener('click', () => openPicker('effort', ui.effort, effortChoices()));
8945
- ui.permission.addEventListener('click', () => openPicker('permission', ui.permission, permissionChoices()));
9460
+ ui.permission.addEventListener('click', () => openPicker('permission', ui.permission, permissionChoices(), permissionPickerNote()));
8946
9461
  // #2046: the Guide's own controls (web/guide.js does the work and says what happened).
8947
9462
  el('chat-guide-off')?.addEventListener('click', () => { void window.flolessGuide?.turnOff?.(); });
8948
9463
  el('chat-guide-delete')?.addEventListener('click', () => { void window.flolessGuide?.deleteHistory?.(); });