@floless/app 0.157.0 → 0.158.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/web/chat.js CHANGED
@@ -1708,8 +1708,12 @@
1708
1708
  } finally { trigger.disabled = false; }
1709
1709
  }
1710
1710
 
1711
+ // Today's messages need only the time. Anything older carries its full date too: scrolling back through a chat
1712
+ // from days ago, a bare "14:02" says nothing about when it happened.
1711
1713
  function eventTime(event) {
1712
- return new Intl.DateTimeFormat(undefined, { hour: '2-digit', minute: '2-digit' }).format(new Date(event.createdAt));
1714
+ const today = formatDay(event.createdAt) === 'Today';
1715
+ return new Intl.DateTimeFormat(undefined, today ? { hour: '2-digit', minute: '2-digit' }
1716
+ : { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' }).format(new Date(event.createdAt));
1713
1717
  }
1714
1718
 
1715
1719
  function beginRename() {
@@ -2170,7 +2174,7 @@
2170
2174
  // The conversation and owner are taken now, from what is being rendered: a chip clicked later opens THIS
2171
2175
  // conversation's source even while the app is between conversations (QA #2437: after Open in Knowledge).
2172
2176
  byAnchor.set(entry.anchor, { anchor: entry.anchor, entry, citationId: event.eventId, index, number: 0,
2173
- chatId: state.chat?.chatId ?? null, owner: ownerQuery() });
2177
+ chatId: state.chat?.chatId ?? null, owner: ownerQuery(), ownerObject: state.scope?.owner ?? null });
2174
2178
  });
2175
2179
  }
2176
2180
  let n = 0;
@@ -2178,8 +2182,37 @@
2178
2182
  return { byAnchor, order };
2179
2183
  }
2180
2184
 
2181
- function citationProvenance(read) {
2182
- return `Found: yes · Read by AI: ${CITATION_READ[read] || CITATION_READ.no} · Checked: no`;
2185
+ /**
2186
+ * #2471: what "Read by AI" says, by kind — each kind has its own receipts. A member counts only by its @-mention line in
2187
+ * the person's message; a file only by a look that showed it, and one that merely went with the question says so.
2188
+ */
2189
+ function citationReadWords(entry) {
2190
+ if (entry.kind === 'member') return entry.read === 'mentioned' ? 'yes, its @-mention was in your message' : 'not recorded';
2191
+ if (entry.kind === 'attachment') {
2192
+ if (entry.read === 'looked') {
2193
+ const pages = Array.isArray(entry.ref?.pagesLooked) ? entry.ref.pagesLooked : [];
2194
+ return pages.length ? `yes, ${pages.length === 1 ? 'page' : 'pages'} ${pages.join(', ')}` : 'yes';
2195
+ }
2196
+ // In the message itself: a data file as its text, checked against the attached file and cut at 16,000 characters.
2197
+ if (entry.read === 'in-message') return 'yes, its text was in your message (up to the first 16,000 characters)';
2198
+ return entry.read === 'sent' ? 'not recorded, it went with your question' : 'not recorded';
2199
+ }
2200
+ return CITATION_READ[entry.read] || CITATION_READ.no;
2201
+ }
2202
+
2203
+ function citationProvenance(entry) {
2204
+ return `Found: yes · Read by AI: ${citationReadWords(entry)} · Checked: no`;
2205
+ }
2206
+
2207
+ /** The chip's tag, in words: never a colour or a tick. */
2208
+ function citationMarks(entry) {
2209
+ if (entry.kind === 'attachment' && entry.read === 'sent') return 'FOUND · SENT WITH QUESTION';
2210
+ return ['whole-sheet', 'tiles', 'yes', 'mentioned', 'looked', 'in-message'].includes(entry.read) ? 'FOUND · READ BY AI' : 'FOUND';
2211
+ }
2212
+
2213
+ /** A member is named with its profile, which is what tells it from a member with a like mark. */
2214
+ function citationLabel(entry) {
2215
+ return entry.kind === 'member' && entry.status === 'resolved' && entry.ref?.profile ? `${entry.label} · ${entry.ref.profile}` : entry.label;
2183
2216
  }
2184
2217
 
2185
2218
  function citationUrl(row, what, extra = '') {
@@ -2214,13 +2247,13 @@
2214
2247
  const marker = button(resolved ? String(row.number) : '?', 'shell.chat-cite-anchor', `ai-chat-cite${resolved ? '' : ' unresolved'}`);
2215
2248
  marker.dataset.turnId = turnId || '';
2216
2249
  marker.dataset.anchor = spec.anchor;
2217
- const label = resolved ? row.entry.label : 'no source';
2250
+ const label = resolved ? citationLabel(row.entry) : 'no source';
2218
2251
  // No citation for this anchor on this page is "none recorded", not "none found": the AI may have given none, or the
2219
2252
  // record has not reached this page yet.
2220
2253
  const missing = row ? 'No source was found for this claim' : 'No source is recorded for this claim';
2221
2254
  marker.dataset.commandInstanceLabel = label;
2222
2255
  marker.setAttribute('aria-label', resolved ? `Source ${row.number}: ${label}` : missing);
2223
- marker.dataset.tip = resolved ? `${label} · ${citationProvenance(row.entry.read)}` : missing;
2256
+ marker.dataset.tip = resolved ? `${label} · ${citationProvenance(row.entry)}` : missing;
2224
2257
  marker.addEventListener('click', () => {
2225
2258
  const chip = [...ui.feed.querySelectorAll('.ai-chat-source')].find((node) => node.dataset.turnId === turnId && node.dataset.anchor === spec.anchor);
2226
2259
  if (!chip) { announce(resolved ? 'Its source is listed under the answer.' : 'The AI gave no source for this claim.'); return; }
@@ -2248,7 +2281,7 @@
2248
2281
  why.textContent = `No source: ${entry.reason}`;
2249
2282
  const ask = button('Ask for the source', 'shell.chat-cite-ask', 'ai-chat-source-action');
2250
2283
  ask.dataset.tip = 'Puts a question in the message box asking where this comes from. Nothing is sent until you press Send';
2251
- ask.addEventListener('click', () => addToMessageBox(`${unsourcedClaim(turnId, row.anchor)}: which sheet or Knowledge page does it come from? Cite it, or say plainly that it is an assumption.`));
2284
+ ask.addEventListener('click', () => addToMessageBox(`${unsourcedClaim(turnId, row.anchor)}: which sheet, model member, attached file or Knowledge page does it come from? Cite it, or say plainly that it is an assumption.`));
2252
2285
  const assume = button('Go on with this as an assumption', 'shell.chat-cite-assume', 'ai-chat-source-action');
2253
2286
  assume.dataset.tip = 'Puts a message in the message box asking the AI to carry on with it as a labelled assumption. Nothing is sent until you press Send';
2254
2287
  assume.addEventListener('click', () => addToMessageBox(`${unsourcedClaim(turnId, row.anchor)}: go on with it as an assumption, and label it as an assumption wherever you use it.`));
@@ -2265,13 +2298,14 @@
2265
2298
  chip.append(thumb);
2266
2299
  }
2267
2300
  }
2268
- const open = button(entry.label, 'shell.chat-cite-open', 'ai-chat-answer-open ai-chat-source-open');
2269
- open.dataset.commandInstanceLabel = entry.label;
2270
- open.setAttribute('aria-label', `Open ${entry.label}`);
2271
- open.dataset.tip = citationProvenance(entry.read);
2301
+ const label = citationLabel(entry);
2302
+ const open = button(label, 'shell.chat-cite-open', 'ai-chat-answer-open ai-chat-source-open');
2303
+ open.dataset.commandInstanceLabel = label;
2304
+ open.setAttribute('aria-label', `Open ${label}`);
2305
+ open.dataset.tip = citationProvenance(entry);
2272
2306
  open.addEventListener('click', () => openCitedSource(row, turnId));
2273
2307
  const marks = document.createElement('span'); marks.className = 'ai-chat-source-marks';
2274
- marks.textContent = entry.read === 'no' ? 'FOUND' : 'FOUND · READ BY AI';
2308
+ marks.textContent = citationMarks(entry);
2275
2309
  chip.append(open, marks);
2276
2310
  return chip;
2277
2311
  }
@@ -2296,7 +2330,7 @@
2296
2330
  const open = button(label, 'shell.chat-cite-open-knowledge', 'ai-chat-answer-open ai-chat-source-open');
2297
2331
  open.dataset.commandInstanceLabel = label;
2298
2332
  open.setAttribute('aria-label', `Open ${label}`);
2299
- open.dataset.tip = citationProvenance('unknown');
2333
+ open.dataset.tip = citationProvenance({ kind: 'kb-page', read: 'unknown' });
2300
2334
  open.addEventListener('click', () => {
2301
2335
  if (window.flolessWorkspaces?.openKnowledgePage) window.flolessWorkspaces.openKnowledgePage(event.payload.projectId, page.slug, event.payload.generationId);
2302
2336
  else announce('Knowledge is not available on this page.');
@@ -2367,9 +2401,9 @@
2367
2401
  async function openCitedSource(row, turnId) {
2368
2402
  const entry = row.entry;
2369
2403
  const dialog = document.createElement('dialog'); dialog.className = 'ai-chat-source-viewer';
2370
- dialog.setAttribute('aria-label', entry.label);
2404
+ dialog.setAttribute('aria-label', citationLabel(entry));
2371
2405
  const head = document.createElement('div'); head.className = 'ai-chat-source-viewer-head';
2372
- const title = Object.assign(document.createElement('strong'), { textContent: entry.label });
2406
+ const title = Object.assign(document.createElement('strong'), { textContent: citationLabel(entry) });
2373
2407
  const close = button('Close', 'shell.chat-cite-close', 'ai-chat-source-viewer-close');
2374
2408
  // Closing is done here, not left to the dialog's own `close` event, which an embedding browser may never fire: the
2375
2409
  // viewer is removed, its picture released and focus handed back to the chip, once, whichever way it closes.
@@ -2387,7 +2421,7 @@
2387
2421
  dialog.addEventListener('keydown', (event) => { if (event.key === 'Escape') { event.preventDefault(); finish(); } });
2388
2422
  dialog.addEventListener('close', finish);
2389
2423
  head.append(title, close);
2390
- const note = Object.assign(document.createElement('span'), { className: 'ai-chat-source-viewer-note', textContent: citationProvenance(entry.read) });
2424
+ const note = Object.assign(document.createElement('span'), { className: 'ai-chat-source-viewer-note', textContent: citationProvenance(entry) });
2391
2425
  const body = document.createElement('div'); body.className = 'ai-chat-source-viewer-body';
2392
2426
  const status = Object.assign(document.createElement('p'), { className: 'ai-chat-source-viewer-status', textContent: 'Opening…' });
2393
2427
  status.setAttribute('role', 'status');
@@ -2397,7 +2431,12 @@
2397
2431
  dialog.showModal();
2398
2432
  const refused = async (response) => {
2399
2433
  if (response.status === 404) return 'FloLess no longer holds this source, or its project is no longer part of this conversation.';
2400
- if (response.status === 410) return 'This Knowledge page has changed since the answer, so FloLess does not show it as the page the answer cited.';
2434
+ if (response.status === 410) {
2435
+ if (entry.kind !== 'attachment') return 'This Knowledge page has changed since the answer, so FloLess does not show it as the page the answer cited.';
2436
+ // Changed bytes, or no longer the plain file that was attached: the server says which.
2437
+ const said = await response.json().catch(() => null);
2438
+ return typeof said?.message === 'string' && said.message ? said.message : 'This file has changed since the answer cited it, so FloLess does not show it as the cited file.';
2439
+ }
2401
2440
  // 503: FloLess could not check it just now; anything else is said as "try again", never as "gone".
2402
2441
  const said = await response.json().catch(() => null);
2403
2442
  return typeof said?.message === 'string' && said.message ? said.message : 'FloLess could not open this source right now. Try again in a moment.';
@@ -2427,6 +2466,57 @@
2427
2466
  body.append(image);
2428
2467
  return;
2429
2468
  }
2469
+ if (entry.kind === 'member') { await showCitedMember(row, { dialog, body, status, finish, refused, done: () => finished }); return; }
2470
+ if (entry.kind === 'attachment') {
2471
+ const response = await fetch(citationUrl(row, 'attachment'), { credentials: 'same-origin', cache: 'no-store' });
2472
+ if (!response.ok) { const why = await refused(response); if (!finished) status.textContent = why; return; }
2473
+ const type = (response.headers.get('Content-Type') || '').split(';')[0].trim().toLowerCase();
2474
+ if (type.startsWith('image/')) {
2475
+ const bytes = await response.blob();
2476
+ if (finished) return;
2477
+ picture = URL.createObjectURL(bytes);
2478
+ status.textContent = 'The file as it was attached.';
2479
+ body.append(Object.assign(document.createElement('img'), { src: picture, alt: entry.label }));
2480
+ } else if (type === 'text/plain') {
2481
+ const text = await response.text();
2482
+ if (finished) return;
2483
+ // A data file reaches the AI cut to its first 16,000 characters (attachment-text.ts MAX_TEXT_CHARS): said, never hidden.
2484
+ status.textContent = 'The file as it was attached. The AI is given at most the first 16,000 characters of a data file.';
2485
+ const shown = [...text];
2486
+ const pre = Object.assign(document.createElement('pre'), { className: 'ai-chat-source-viewer-text', tabIndex: 0,
2487
+ textContent: shown.length > 16000 ? shown.slice(0, 16000).join('') : text });
2488
+ pre.setAttribute('aria-label', `Text of ${entry.label}`);
2489
+ body.append(pre);
2490
+ if (shown.length > 16000) {
2491
+ body.append(Object.assign(document.createElement('p'), { className: 'ai-chat-source-viewer-status',
2492
+ textContent: `Showing the first 16,000 of ${shown.length.toLocaleString()} characters. Open it in its default app to see all of it.` }));
2493
+ }
2494
+ } else {
2495
+ await response.body?.cancel().catch(() => {});
2496
+ if (finished) return;
2497
+ status.textContent = 'FloLess does not show this kind of file here. Open it in its default app.';
2498
+ }
2499
+ const external = button('Open in its default app', 'shell.chat-cite-open-file', 'ai-chat-source-viewer-knowledge');
2500
+ external.addEventListener('click', async () => {
2501
+ try {
2502
+ await request(citationUrl(row, 'attachment/open'), { method: 'POST', body: JSON.stringify({ owner: row.ownerObject }) });
2503
+ announce(`Opened ${entry.label} in its default app.`);
2504
+ } catch (error) {
2505
+ // Why, by what the server answered (its code), or why it could not be asked.
2506
+ const why = {
2507
+ 'chat-page-closed': 'This conversation is no longer the one open here. Open it again, then press Open in its default app.',
2508
+ 'citation-source-unavailable': 'FloLess no longer holds this file in this conversation, so there is nothing to open.',
2509
+ 'citation-source-changed': 'This file has changed since the answer cited it, so FloLess does not open it as the cited file.',
2510
+ 'citation-source-not-as-attached': 'This file is no longer the plain file that was attached, so FloLess does not open it as the cited file. Attach the file again if you still need it.',
2511
+ 'citation-source-unreadable': 'FloLess could not check this file just now. Try again in a moment.',
2512
+ }[error?.code] || '';
2513
+ if (!why) console.error('[chat] a cited file could not be opened in its app', error);
2514
+ announce(why || `FloLess could not open ${entry.label} in its default app. Try again in a moment, or open the file from the message it was attached to.`);
2515
+ }
2516
+ });
2517
+ dialog.append(external);
2518
+ return;
2519
+ }
2430
2520
  const response = await fetch(citationUrl(row, 'page'), { credentials: 'same-origin', cache: 'no-store' });
2431
2521
  if (!response.ok) { const why = await refused(response); if (!finished) status.textContent = why; return; }
2432
2522
  const { page } = await response.json();
@@ -2448,6 +2538,61 @@
2448
2538
  }
2449
2539
  }
2450
2540
 
2541
+ /**
2542
+ * #2471: a cited member in the source viewer — first as it was cited (FloLess's snapshot), then where the model stands
2543
+ * now, then the way to it. "Show current in the model" whenever the model changed: what is framed is the member as it
2544
+ * is now, not as the answer described it. The member's route is asked again right before moving, so a project that
2545
+ * left the conversation since is never opened.
2546
+ */
2547
+ async function showCitedMember(row, view) {
2548
+ const { dialog, body, status, finish, refused, done } = view;
2549
+ const response = await fetch(citationUrl(row, 'member'), { credentials: 'same-origin', cache: 'no-store' });
2550
+ if (!response.ok) { const why = await refused(response); if (!done()) status.textContent = why; return; }
2551
+ const { member } = await response.json();
2552
+ if (done()) return;
2553
+ const facts = document.createElement('dl'); facts.className = 'ai-chat-source-viewer-facts';
2554
+ const fact = (term, value) => facts.append(Object.assign(document.createElement('dt'), { textContent: term }),
2555
+ Object.assign(document.createElement('dd'), { textContent: value }));
2556
+ fact('Mark', member.mark ?? 'No mark');
2557
+ fact('Profile', member.profile ?? 'Not recorded');
2558
+ const views = Array.isArray(member.views) ? member.views : [];
2559
+ fact('Read on', views.length ? views.map((v) => (v.title ? `${v.sheet} (${v.title})` : v.sheet)).join(', ') : 'No sheet recorded');
2560
+ body.insertBefore(Object.assign(document.createElement('p'), { className: 'ai-chat-source-viewer-sub', textContent: 'As the answer cited it' }), status);
2561
+ body.insertBefore(facts, status);
2562
+ status.textContent = member.model === 'same' ? 'The model is the same version as when the answer cited it.'
2563
+ : member.model === 'changed' ? 'The model has changed since this answer; the member is still in it. Its size or position may differ from what the answer described.'
2564
+ : member.model === 'no-model' ? 'This project has no steel model FloLess can show now, so the member cannot be shown in it.'
2565
+ : 'This member is no longer in the model.';
2566
+ if (member.model === 'gone' || member.model === 'no-model') return;
2567
+ const show = button(member.model === 'same' ? 'Show in the model' : 'Show current in the model', 'shell.chat-cite-show-member', 'ai-chat-source-viewer-knowledge');
2568
+ show.dataset.tip = 'Opens the project\'s model with this member selected and framed. Nothing changes';
2569
+ show.addEventListener('click', async () => {
2570
+ const unreachable = 'FloLess could not open the model from here. Open the project from Workspaces, then try again.';
2571
+ let said;
2572
+ try {
2573
+ const again = await fetch(citationUrl(row, 'member'), { credentials: 'same-origin', cache: 'no-store' });
2574
+ if (!again.ok) { status.textContent = await refused(again); return; }
2575
+ const now = (await again.json()).member;
2576
+ if (now.model === 'gone' || now.model === 'no-model') {
2577
+ status.textContent = now.model === 'gone' ? 'This member is no longer in the model.' : 'This project has no steel model FloLess can show now, so the member cannot be shown in it.';
2578
+ show.remove(); return;
2579
+ }
2580
+ finish();
2581
+ if (typeof window.flolessWorkspaces?.openConnection !== 'function') { announce(unreachable); return; }
2582
+ const outcome = await window.flolessWorkspaces.openConnection({ projectId: now.projectId, projectUuid: now.projectUuid, memberId: now.memberId });
2583
+ if (outcome?.superseded) return;
2584
+ const name = now.mark ? `member ${now.mark}` : `member ${now.memberId}`;
2585
+ said = !outcome ? unreachable : outcome.ok !== true ? (outcome.said || `The ${name} was not shown. Open the Model step, then press Show in the model again.`)
2586
+ : `Showing ${name} in the model.`;
2587
+ } catch (error) {
2588
+ if (error?.plain !== true) console.error('[chat] Show in the model failed', error);
2589
+ said = error?.plain === true && error.message ? error.message : unreachable;
2590
+ }
2591
+ if (said) announce(said);
2592
+ });
2593
+ dialog.append(show);
2594
+ }
2595
+
2451
2596
  function openChatAttachment(attachment) {
2452
2597
  return request(`/api/chat/conversations/${encodeURIComponent(state.chat.chatId)}/attachments/${encodeURIComponent(attachment.attachmentId)}/open`, {
2453
2598
  method: 'POST', body: JSON.stringify({ owner: state.scope.owner }),
@@ -3440,7 +3585,10 @@
3440
3585
  return false;
3441
3586
  }
3442
3587
 
3443
- /** Take a confirmed step FloLess's own window must take (#2290). Returns a plain failure sentence, or '' when it went. */
3588
+ /**
3589
+ * Take a confirmed step FloLess's own window must take (#2290). Returns a plain failure sentence, or '' when it went,
3590
+ * or { handedOver: sentence } when it went as far as it may and the last click is the person's (#2427).
3591
+ */
3444
3592
  async function runBrowserStep(step) {
3445
3593
  if (step?.flow === 'stop-app') {
3446
3594
  // The menu's own Stop FloLess: it asks about anything not saved, then closes FloLess and shows the stopped screen.
@@ -3471,13 +3619,13 @@
3471
3619
  // #2363: the project's own Source step presses its own Replace / Try again / Cancel control, so the real call
3472
3620
  // runs with this window's editor session. It answers a plain sentence when it could not, or when the person must act.
3473
3621
  if (typeof window.flolessWorkspaces?.modelSourceStep !== 'function') return 'FloLess could not open the project from here. Open it from Workspaces and use its Source step.';
3474
- try { return String((await window.flolessWorkspaces.modelSourceStep(step)) || ''); }
3622
+ try { return stepAnswer(await window.flolessWorkspaces.modelSourceStep(step)); }
3475
3623
  catch { return 'FloLess could not open the project’s Source step from here. Open it from Workspaces.'; }
3476
3624
  }
3477
3625
  if (step?.flow === 'knowledge-pick') {
3478
3626
  // #2399 slice 0b: the project's Knowledge step opens its own file picker; what the person picks there is added.
3479
3627
  if (typeof window.flolessWorkspaces?.knowledgePickStep !== 'function') return 'FloLess could not open the project from here. Open it from Workspaces and use its Knowledge step.';
3480
- try { return String((await window.flolessWorkspaces.knowledgePickStep(step)) || ''); }
3628
+ try { return stepAnswer(await window.flolessWorkspaces.knowledgePickStep(step)); }
3481
3629
  catch { return 'FloLess could not open the project’s Knowledge step from here. Open it from Workspaces.'; }
3482
3630
  }
3483
3631
  if (step?.flow === 'parser-setup') {
@@ -3492,16 +3640,25 @@
3492
3640
  }
3493
3641
  return 'FloLess did not recognise the step this card asked its window to take, so it did nothing. Try it from the screen instead.';
3494
3642
  }
3643
+ /** A step's own answer: a failure sentence, '' when it went, or a hand-over to the person with the sentence it showed. */
3644
+ function stepAnswer(said) {
3645
+ if (said && typeof said === 'object' && typeof said.handedOver === 'string' && said.handedOver) {
3646
+ return { handedOver: said.handedOver, ...(said.focus && typeof said.focus.focus === 'function' ? { focus: said.focus } : {}) };
3647
+ }
3648
+ return String(said || '');
3649
+ }
3495
3650
  /**
3496
3651
  * Tell FloLess how a step this window took for a confirmed card went: done, or not done with the sentence shown here.
3497
3652
  * Until it is told, the card stays running (a restart marks it "not known"), so a failed report only leaves it
3498
3653
  * honest, never "done". Returns the settled proposal, or null when the report did not land.
3499
3654
  */
3500
- async function reportBrowserStep(proposalId, failed) {
3655
+ async function reportBrowserStep(proposalId, outcome) {
3656
+ const handed = outcome && typeof outcome === 'object' && outcome.handedOver ? String(outcome.handedOver) : '';
3657
+ const failed = handed ? '' : outcome;
3501
3658
  try {
3502
3659
  const response = await fetch(`/api/actions/proposals/${encodeURIComponent(proposalId)}/step`, {
3503
3660
  method: 'POST', credentials: 'same-origin', headers: { 'content-type': 'application/json' },
3504
- body: JSON.stringify(failed ? { done: false, note: String(failed) } : { done: true }),
3661
+ body: JSON.stringify(handed ? { done: true, handedOver: true, note: handed } : failed ? { done: false, note: String(failed) } : { done: true }),
3505
3662
  });
3506
3663
  const body = await response.json().catch(() => null);
3507
3664
  return response.ok && body?.ok === true ? body.proposal || null : null;
@@ -3535,13 +3692,16 @@
3535
3692
  // #2290: a step only this window may take (its route checks the window's own origin) is taken here, now that the
3536
3693
  // person confirmed it: the same flow the menu or the Requests button runs.
3537
3694
  if (verb === 'confirm' && event.payload?.browserStep) {
3538
- const failed = await runBrowserStep(event.payload.browserStep);
3695
+ const outcome = await runBrowserStep(event.payload.browserStep);
3696
+ const failed = typeof outcome === 'string' ? outcome : '';
3539
3697
  if (failed) entry.error = failed;
3540
3698
  // The record says how the step went, so neither the card nor the AI calls it done when it was not. A Stop FloLess
3541
3699
  // that went ahead is settled by the server when it accepts the stop: this window's requests are already stopped.
3542
3700
  const stopped = event.payload.browserStep.flow === 'stop-app' && !failed;
3543
- const settled = stopped ? null : await reportBrowserStep(proposalId, failed);
3701
+ const settled = stopped ? null : await reportBrowserStep(proposalId, outcome);
3544
3702
  if (settled) entry.local = { state: settled.state || entry.local.state, result: settled.result || null, supersededBy: null };
3703
+ // #2427: the report did not land, so the card stays running: still show the person what to press.
3704
+ else if (outcome && typeof outcome === 'object' && outcome.handedOver) entry.error = String(outcome.handedOver);
3545
3705
  }
3546
3706
  } else if (body.fresh) {
3547
3707
  // The target changed or the offer ended: the old card says so, and a fresh card shows the current state.
@@ -3600,7 +3760,10 @@
3600
3760
  const eyebrow = document.createElement('span');
3601
3761
  eyebrow.className = 'guide-move-eyebrow';
3602
3762
  // A request that has been answered no longer "needs your OK": the eyebrow says where it ended up.
3603
- eyebrow.textContent = { executing: actionId === 'workflows.run' || actionId === 'routines.run' ? 'Running' : 'Working', done: 'Finished', failed: 'Could not finish', unknown: 'Outcome unknown' }[current.state] || ACTION_EYEBROWS[risk];
3763
+ // #2427: a step that left the last click to the person is theirs to finish, not a failure and not yet done.
3764
+ const handedOver = current.state === 'done' && current.result?.code === 'step-handed-over';
3765
+ eyebrow.textContent = handedOver ? 'Waiting for you'
3766
+ : { executing: actionId === 'workflows.run' || actionId === 'routines.run' ? 'Running' : 'Working', done: 'Finished', failed: 'Could not finish', unknown: 'Outcome unknown' }[current.state] || ACTION_EYEBROWS[risk];
3604
3767
  const strong = document.createElement('strong');
3605
3768
  strong.id = titleId;
3606
3769
  strong.textContent = title;
@@ -3608,7 +3771,7 @@
3608
3771
  named.className = 'ai-chat-action-named';
3609
3772
  named.append(eyebrow, strong);
3610
3773
  head.append(named);
3611
- const badgeText = { executing: 'Running', done: 'Done', failed: 'Not done', unknown: 'Unknown' }[current.state];
3774
+ const badgeText = handedOver ? 'Your turn' : { executing: 'Running', done: 'Done', failed: 'Not done', unknown: 'Unknown' }[current.state];
3612
3775
  if (badgeText) {
3613
3776
  const badge = document.createElement('span');
3614
3777
  badge.className = 'ai-chat-filter-state';
@@ -3626,11 +3789,33 @@
3626
3789
  summary.className = 'ai-chat-action-summary';
3627
3790
  summary.textContent = summaryText;
3628
3791
  card.append(summary);
3629
-
3792
+ // #2521 row 3a: what confirming agrees to (a Quick model read), whole and on its own line: the summary is cut to its
3793
+ // limit, terms never are.
3794
+ if (payload.terms) {
3795
+ const terms = document.createElement('p');
3796
+ terms.className = 'ai-chat-action-summary ai-chat-action-terms';
3797
+ // A real element, not CSS content, so a screen reader announces it with the terms.
3798
+ const label = document.createElement('strong');
3799
+ label.className = 'ai-chat-action-terms-label';
3800
+ label.textContent = 'What you agree to';
3801
+ terms.append(label, document.createTextNode(String(payload.terms)));
3802
+ card.append(terms);
3803
+ }
3804
+
3805
+ if (handedOver) {
3806
+ card.classList.add('is-handed-over');
3807
+ status.textContent = entry.error || String(current.result?.message || 'It is ready for you. Press it to finish.');
3808
+ card.append(status);
3809
+ return card;
3810
+ }
3630
3811
  if (current.state === 'done') {
3631
3812
  card.classList.add('is-done');
3632
3813
  // A step this window took after the confirm (#2290) can still fail here; that is said, never "Done." over it.
3633
- status.textContent = entry.error || (current.next ? 'Done. Its result is ready to view.' : String(payload.doneNote || 'Done.'));
3814
+ // #2521 row 3a: the route's own answer, when it changed what happened (a Quick read queued Precise), comes first,
3815
+ // and the card's edge turns amber so the person notices their choice was not what ran.
3816
+ const resultNote = typeof current.result?.note === 'string' && current.result.note ? current.result.note : '';
3817
+ if (resultNote) card.classList.add('is-fallback');
3818
+ status.textContent = entry.error || resultNote || (current.next ? 'Done. Its result is ready to view.' : String(payload.doneNote || 'Done.'));
3634
3819
  if (current.next) {
3635
3820
  // What the finished action made (a run's report): opening it only shows it, it runs nothing again.
3636
3821
  const actions = document.createElement('div');
@@ -3681,7 +3866,8 @@
3681
3866
  const actions = document.createElement('div');
3682
3867
  actions.className = 'ai-chat-filter-actions';
3683
3868
  if (current.state === 'executing') {
3684
- status.textContent = actionId === 'workflows.run' || actionId === 'routines.run' ? 'Running…' : 'Working…';
3869
+ // A window step whose report did not land stays running here; what the window said (what to press) still shows.
3870
+ status.textContent = entry.error || (actionId === 'workflows.run' || actionId === 'routines.run' ? 'Running…' : 'Working…');
3685
3871
  if (actionId === 'workflows.run') {
3686
3872
  const stop = actionButton('Stop', 'shell.chat-action-stop', proposalId, summaryText);
3687
3873
  stop.dataset.tip = 'Asks the run to stop. Work already sent to the host may remain.';