@floless/app 0.165.0 → 0.166.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
@@ -210,6 +210,8 @@
210
210
  if (response.status === 402 && body && typeof body === 'object') error.body = body;
211
211
  // #2061: who holds a busy project, so the person can be asked: wait, stop it, or open it.
212
212
  error.holder = body?.holder && typeof body.holder === 'object' ? body.holder : null;
213
+ // #2470 R6.7b: a project intake from Add a module whose link the General project can't take is a choice, not a refusal.
214
+ error.linkChoice = body?.linkChoice === true;
213
215
  error.status = response.status;
214
216
  // #1890 PR 3b: the conversation moved — wherever this was asked from, the open tab follows it.
215
217
  if (error.code === 'chat-moved' && body?.to?.chatId) {
@@ -2204,6 +2206,58 @@
2204
2206
  return out.join('');
2205
2207
  }
2206
2208
 
2209
+ /**
2210
+ * #3003: a Knowledge page as a person reads it: its markdown rendered, and each `[[slug]]` link shown as the linked
2211
+ * page's title (`links`, read by the server from the same version), a button that opens it. A link to a page that
2212
+ * version does not hold reads as plain words, never as brackets and a slug. Links in code stay as written.
2213
+ */
2214
+ function knowledgePageHtml(body, links, commandId = 'shell.knowledge-page-link') {
2215
+ const titles = links && typeof links === 'object' ? links : {};
2216
+ const host = document.createElement('div');
2217
+ host.innerHTML = markdownHtml(String(body ?? ''));
2218
+ const walker = document.createTreeWalker(host, NodeFilter.SHOW_TEXT);
2219
+ const texts = [];
2220
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
2221
+ if (/\[\[[^\]]+\]\]/.test(node.nodeValue) && !node.parentElement?.closest('code, pre, a, button')) texts.push(node);
2222
+ }
2223
+ for (const node of texts) {
2224
+ const parts = [];
2225
+ let last = 0;
2226
+ for (const match of node.nodeValue.matchAll(/(!?)\[\[([^\]]+)\]\]/g)) {
2227
+ parts.push(document.createTextNode(node.nodeValue.slice(last, match.index)));
2228
+ const [target, alias] = match[2].split('|');
2229
+ const slug = (target.split('#')[0] ?? '').trim();
2230
+ // A title: the page, by name. null: the server looked, and this version has no such page. No entry: not
2231
+ // looked at (past its cap, or unreadable), so it stays a link and nothing is said about whether the page exists.
2232
+ const known = slug && Object.prototype.hasOwnProperty.call(titles, slug);
2233
+ const title = known && typeof titles[slug] === 'string' ? titles[slug] : '';
2234
+ const words = (alias ?? '').trim() || title || slug.replace(/-/g, ' ');
2235
+ if (!slug) {
2236
+ // A link to a heading of the same page ([[#detail]]) names no other page: its words, with no claim either way.
2237
+ parts.push(document.createTextNode((alias ?? '').trim() || target.replace(/^#/, '').trim()));
2238
+ } else if (!(known && titles[slug] === null)) {
2239
+ const link = button(words, commandId, 'kb-wikilink');
2240
+ link.dataset.kbLink = slug;
2241
+ link.dataset.commandInstanceLabel = title || words;
2242
+ link.dataset.tip = title ? `Open the page “${title}”` : 'Open the linked page';
2243
+ // A link shown by another name still says which page it opens; its own words come first.
2244
+ if (title && words !== title) link.setAttribute('aria-label', `${words}, opens the page ${title}`);
2245
+ parts.push(link);
2246
+ } else {
2247
+ const missing = Object.assign(document.createElement('span'), { className: 'kb-wikilink missing', textContent: words });
2248
+ missing.dataset.tip = 'This page is not in this version of the Knowledge';
2249
+ missing.setAttribute('aria-label', `${words} (not in this version of the Knowledge)`);
2250
+ missing.setAttribute('role', 'note');
2251
+ parts.push(missing);
2252
+ }
2253
+ last = match.index + match[0].length;
2254
+ }
2255
+ parts.push(document.createTextNode(node.nodeValue.slice(last)));
2256
+ node.replaceWith(...parts);
2257
+ }
2258
+ return host.innerHTML;
2259
+ }
2260
+
2207
2261
  function markdownHtml(value, depth = 0) {
2208
2262
  const source = String(value ?? '').replace(/\r\n?/g, '\n');
2209
2263
  // A quote or a list item re-enters this renderer for its own content, one level down. Past a
@@ -2340,6 +2394,16 @@
2340
2394
  chatId: state.chat?.chatId ?? null, owner: ownerQuery(), ownerObject: state.scope?.owner ?? null });
2341
2395
  });
2342
2396
  }
2397
+ // #2999: a claim the answer marks that no citation entry holds is a claim with no source, never dropped. Recorded
2398
+ // against the answer itself, it gets the same three ways on as an entry FloLess could not match.
2399
+ const claims = answerClaims(turnId);
2400
+ for (const anchor of claims?.anchors ?? []) {
2401
+ if (byAnchor.has(anchor)) continue;
2402
+ order.push(anchor);
2403
+ byAnchor.set(anchor, { anchor, entry: { anchor, kind: null, status: 'unresolved', label: 'No source given', read: 'no', bare: true,
2404
+ reason: 'the AI marked this claim but named no source for it' },
2405
+ citationId: claims.answerId, index: -1, number: 0, chatId: state.chat?.chatId ?? null, owner: ownerQuery(), ownerObject: state.scope?.owner ?? null });
2406
+ }
2343
2407
  for (const record of citationAssumptions(turnId)) { const row = byAnchor.get(record.anchor); if (row) row.assumption = record; }
2344
2408
  // #2643: the sources the person chose. The latest is the claim's current one while the AI has given it none; the
2345
2409
  // earlier ones are its history. A chosen source is numbered like a cited one: the "?" becomes a number.
@@ -2349,15 +2413,107 @@
2349
2413
  row.choices = made;
2350
2414
  if (row.entry.status !== 'resolved') row.choice = made[made.length - 1];
2351
2415
  }
2416
+ // #3000: an entry the answer never marks is not a claim: it is listed apart as "Also consulted", unnumbered, and
2417
+ // never offered as an assumption. Without answer text (none recorded yet) nothing tells the two apart. One the
2418
+ // person already decided on stays with the claims: their recorded decision is never hidden.
2419
+ const claimed = (anchor) => claims.anchors.includes(anchor) || Boolean(byAnchor.get(anchor).assumption || byAnchor.get(anchor).choices?.length);
2420
+ const used = claims ? order.filter(claimed) : order;
2421
+ const unused = claims ? order.filter((anchor) => !claimed(anchor)) : [];
2352
2422
  let n = 0;
2353
- for (const anchor of order) { const row = byAnchor.get(anchor); row.number = row.entry.status === 'resolved' || row.choice ? ++n : 0; }
2354
- return { byAnchor, order };
2423
+ for (const anchor of order) { const row = byAnchor.get(anchor); row.number = used.includes(anchor) && (row.entry.status === 'resolved' || row.choice) ? ++n : 0; }
2424
+ return { byAnchor, order: used, unused };
2425
+ }
2426
+
2427
+ /**
2428
+ * #2999/#3000: the claims an answer marks, read with the same parse that puts its markers in it (so a directive in code
2429
+ * marks nothing), and the answer event a claim with no citation entry is recorded against. Null when the turn has no
2430
+ * answer text.
2431
+ */
2432
+ function answerClaims(turnId) {
2433
+ const answer = answerText(turnId);
2434
+ if (!answer) return null;
2435
+ const held = inlineSlots;
2436
+ let slots = [];
2437
+ inlineSlots = [];
2438
+ try { for (const block of answer.blocks) markdownHtml(block); slots = inlineSlots; }
2439
+ finally { inlineSlots = held; }
2440
+ const anchors = [];
2441
+ for (const slot of slots) if (slot.kind === 'cite' && !anchors.includes(slot.anchor)) anchors.push(slot.anchor);
2442
+ return { anchors, answerId: answer.answerId };
2443
+ }
2444
+
2445
+ /** #2999: an answer's text as the feed shows it, block by block (`answerBlocks`). Null when the turn has no answer text. */
2446
+ function answerText(turnId) {
2447
+ const answer = turnId ? answerBlocks(state.events, turnId, payloadText) : null;
2448
+ return answer?.blocks.length ? answer : null;
2449
+ }
2450
+
2451
+ /**
2452
+ * #2999: the blocks of text a turn's answer shows as, grouped exactly as paintEvents groups them: streamed pieces of
2453
+ * one turn joined (a marker split across two pieces is one marker), a paragraph break after a tool between them, and
2454
+ * a block ended by whatever the feed shows in the answer's place (a question, a whole message, a run's first line,
2455
+ * anything it does not hold under the answer) or by a held receipt of another turn. A whole message is its own block.
2456
+ * The server reads claims with the same function (`answerBlocks` in server/chat-store.ts); a test keeps the two equal
2457
+ * and both equal to what paintEvents draws. Pure: `words` reads an event's text. Where a receipt turns out to draw
2458
+ * nothing (a hidden card, an empty row, a claims row) it is still read as held: that only matters when another
2459
+ * turn's event falls between two pieces of one answer.
2460
+ */
2461
+ function answerBlocks(events, turnId, words) {
2462
+ const runLine = (event) => event.type === 'tool' && ['agent', 'guide', 'instructor'].includes(event.payload?.tool);
2463
+ const blocks = [];
2464
+ let answerId = null; let assistant = null; let held = false; let heldTurn;
2465
+ const flush = () => { if (assistant && assistant.turnId === turnId && assistant.text) blocks.push(assistant.text); assistant = null; };
2466
+ const hold = (event) => { if (!held) { held = true; heldTurn = event.turnId; } };
2467
+ // A turn's Sources row is drawn at its last citation only; an earlier one holds nothing.
2468
+ const lastCitation = new Map();
2469
+ for (const event of events) if (event.type === 'citation') lastCitation.set(event.turnId, event);
2470
+ for (const event of events) {
2471
+ if (event.type === 'citation-assumption' || event.type === 'citation-choice') continue;
2472
+ if (event.type === 'user-message' || (held && event.turnId !== heldTurn)) { flush(); held = false; }
2473
+ const text = words(event);
2474
+ if (event.type === 'assistant-message' && event.payload?.delta) {
2475
+ if (assistant && assistant.turnId === event.turnId) {
2476
+ if (assistant.afterTool && text) {
2477
+ if (assistant.text && !/\n\s*$/.test(assistant.text) && !/^\s*\n/.test(text)) assistant.text += '\n\n';
2478
+ assistant.afterTool = false;
2479
+ }
2480
+ assistant.text += text;
2481
+ } else { flush(); assistant = { turnId: event.turnId, text, afterTool: false }; }
2482
+ if (event.turnId === turnId && text) answerId = event.eventId;
2483
+ continue;
2484
+ }
2485
+ if (assistant && event.turnId === assistant.turnId && event.type === 'tool' && !event.payload?.plain && !runLine(event)) assistant.afterTool = true;
2486
+ if (event.type === 'tool' && event.payload?.plain === true && !runLine(event) && typeof event.payload?.message === 'string' && event.payload.message) { hold(event); continue; }
2487
+ if (runLine(event) && typeof event.payload?.message === 'string') { flush(); continue; }
2488
+ if (ANSWER_UPDATES.has(event.type)) continue;
2489
+ if (ANSWER_RECEIPTS.has(event.type)) { if (event.type !== 'citation' || lastCitation.get(event.turnId) === event) hold(event); continue; }
2490
+ if (['tool', 'usage', 'attachment', 'compaction', 'state'].includes(event.type)) continue;
2491
+ flush();
2492
+ if (event.type === 'assistant-message' && event.turnId === turnId && text) { blocks.push(text); answerId = event.eventId; }
2493
+ }
2494
+ flush();
2495
+ return { blocks, answerId };
2496
+ }
2497
+ // What paintEvents holds under an answer (receipts) or skips (updates to a card it already drew).
2498
+ const ANSWER_RECEIPTS = new Set(['connection-proposal', 'connection-check', 'next-move', 'action-proposal', 'action-call', 'view-command',
2499
+ 'citation', 'knowledge-citation', 'place', 'chat-subjects', 'evidence-read', 'filter-proposal']);
2500
+ const ANSWER_UPDATES = new Set(['connection-proposal-update', 'view-command-update', 'next-move-update', 'action-proposal-update']);
2501
+
2502
+ /**
2503
+ * #2999: whether a person's record names this claim: a citation of the answer's turn holding the anchor, or (a claim the
2504
+ * AI cited nothing for) one of that turn's answer events, whose text marks the anchor. The server's rule (`claimHolder`).
2505
+ */
2506
+ function claimHeld(citationId, turnId, anchor) {
2507
+ const held = state.events.find((row) => row.eventId === citationId);
2508
+ if (!held || held.turnId !== turnId) return false;
2509
+ if (held.type === 'citation') return (held.payload?.entries ?? []).some((entry) => entry?.anchor === anchor);
2510
+ return held.type === 'assistant-message' && (answerText(turnId)?.blocks ?? []).some((block) => block.includes(`:cite[${anchor}]`));
2355
2511
  }
2356
2512
 
2357
2513
  /**
2358
2514
  * #2643: the sources the person chose for this answer's claims, by anchor, in the order made — the server's validity
2359
- * rule (`validCitationChoices`): every field the route writes, through the same checks, and the citation it names is
2360
- * this turn's and holds the anchor. An invalid row is skipped, so it can never stand in for the person's choice.
2515
+ * rule (`validCitationChoices`): every field the route writes, through the same checks, and what it names holds the
2516
+ * claim (`claimHeld`). An invalid row is skipped, so it can never stand in for the person's choice.
2361
2517
  */
2362
2518
  function citationChoices(turnId) {
2363
2519
  const out = new Map();
@@ -2371,8 +2527,7 @@
2371
2527
  || !citeText(p.chosenBy, 200) || !citeText(p.chosenAt, 40) || Number.isNaN(Date.parse(p.chosenAt)) || p.via !== 'chip') continue;
2372
2528
  const source = chosenSourceOf(p.source);
2373
2529
  if (!source) continue;
2374
- const cited = state.events.find((row) => row.type === 'citation' && row.eventId === p.citationId);
2375
- if (!cited || cited.turnId !== turnId || !(cited.payload?.entries ?? []).some((entry) => entry?.anchor === p.anchor)) continue;
2530
+ if (!claimHeld(p.citationId, turnId, p.anchor)) continue;
2376
2531
  const made = out.get(p.anchor) ?? [];
2377
2532
  made.push({ eventId: event.eventId, anchor: p.anchor, chosenBy: p.chosenBy, chosenAt: p.chosenAt, source });
2378
2533
  out.set(p.anchor, made);
@@ -2430,7 +2585,7 @@
2430
2585
 
2431
2586
  /**
2432
2587
  * #2642: the person's "go on with this as an assumption" on this answer's claims — the server's validity rule
2433
- * (`liveCitationAssumptions`): the citation it names is this turn's and holds the anchor; the first record per claim wins.
2588
+ * (`liveCitationAssumptions`): what it names holds the claim (`claimHeld`); the first record per claim wins.
2434
2589
  */
2435
2590
  function citationAssumptions(turnId) {
2436
2591
  const out = new Map();
@@ -2444,9 +2599,9 @@
2444
2599
  if (p.turnId !== turnId || typeof p.turnId !== 'string' || !uuid.test(p.turnId) || typeof p.citationId !== 'string' || !uuid.test(p.citationId)
2445
2600
  || typeof p.anchor !== 'string' || !CITE_ANCHOR.test(p.anchor) || out.has(p.anchor) || !(p.claim === null || text(p.claim, 300))
2446
2601
  || !text(p.assumedBy, 200) || !text(p.assumedAt, 40) || Number.isNaN(Date.parse(p.assumedAt)) || p.via !== 'chip') continue;
2447
- const cited = state.events.find((row) => row.type === 'citation' && row.eventId === p.citationId);
2448
- if (!cited || cited.turnId !== turnId || !(cited.payload?.entries ?? []).some((entry) => entry?.anchor === p.anchor)) continue;
2449
- out.set(p.anchor, { anchor: p.anchor, assumedBy: p.assumedBy, assumedAt: p.assumedAt });
2602
+ if (!claimHeld(p.citationId, turnId, p.anchor)) continue;
2603
+ // #3000: the claim's own words are kept with it, so the record always says which claim it is about.
2604
+ out.set(p.anchor, { anchor: p.anchor, claim: p.claim, assumedBy: p.assumedBy, assumedAt: p.assumedAt });
2450
2605
  }
2451
2606
  return [...out.values()];
2452
2607
  }
@@ -2545,6 +2700,7 @@
2545
2700
  // record has not reached this page yet.
2546
2701
  const missing = assumed ? `No source. Assumed by ${assumedWho(assumed)} on ${assumedWhen(assumed)}`
2547
2702
  : misnamed ? 'Source needs correcting: the member exists, but the AI named it wrongly'
2703
+ : row?.entry.bare ? 'The AI gave no source for this claim'
2548
2704
  : row ? 'No source was found for this claim' : 'No source is recorded for this claim';
2549
2705
  if (assumed) marker.classList.add('assumed');
2550
2706
  if (chosen) marker.classList.add('chosen');
@@ -2709,6 +2865,7 @@
2709
2865
  chip.className = 'ai-chat-attachment ai-chat-source';
2710
2866
  chip.dataset.turnId = turnId || '';
2711
2867
  chip.dataset.anchor = row.anchor;
2868
+ if (row.entry.bare) chip.dataset.bare = 'true';
2712
2869
  const number = document.createElement('span'); number.className = 'ai-chat-source-n';
2713
2870
  number.textContent = row.number ? String(row.number) : '?';
2714
2871
  chip.append(number);
@@ -2733,17 +2890,20 @@
2733
2890
  const marks = document.createElement('span'); marks.className = 'ai-chat-source-marks';
2734
2891
  marks.textContent = 'ASSUMPTION';
2735
2892
  marks.dataset.tip = 'Your decision to go on without a source. Nothing was found or checked for this claim. The AI is reminded of it with each message you send';
2736
- chip.append(why, marks, sourceActions(ask, choose));
2893
+ // #3000: which claim was assumed, in the answer's words as they were when it was recorded.
2894
+ const claimed = row.assumption.claim ? claimCited(`“${row.assumption.claim}”`, 'The claim you recorded as an assumption')
2895
+ : claimCited(entry.bare ? '' : entry.label, 'What the AI cited');
2896
+ chip.append(...(claimed ? [claimed] : []), why, marks, sourceActions(ask, choose));
2737
2897
  const saved = citationNote(row, turnId);
2738
2898
  if (saved) chip.append(saved);
2739
2899
  return chip;
2740
2900
  }
2741
2901
  if (referenceProblem(entry)) return referenceChip(chip, turnId, row, choose);
2742
2902
  chip.classList.add('unresolved');
2743
- // What was cited, in the AI's own words, so the person knows which source FloLess could not match.
2744
- const cited = document.createElement('span'); cited.className = 'ai-chat-source-cited';
2745
- cited.textContent = entry.label;
2746
- cited.dataset.tip = 'What the AI cited';
2903
+ // What was cited, in the AI's own words, so the person knows which source FloLess could not match. #2999: a claim
2904
+ // the AI cited nothing for is named by its own words instead.
2905
+ const words = entry.bare ? unsourcedClaimWords(turnId, row.anchor) : '';
2906
+ const cited = entry.bare ? claimCited(words ? `“${words}”` : entry.label, 'The claim with no source') : claimCited(entry.label, 'What the AI cited');
2747
2907
  why.textContent = `No source: ${entry.reason}`;
2748
2908
  // #2930: it only saves the person's decision, so it says so; nothing starts and nothing is sent now.
2749
2909
  const assume = button(ASSUME_LABEL, 'shell.chat-cite-assume', 'ai-chat-source-action');
@@ -2785,6 +2945,43 @@
2785
2945
  return chip;
2786
2946
  }
2787
2947
 
2948
+ function claimCited(text, tip) {
2949
+ if (!text) return null;
2950
+ const cited = document.createElement('span'); cited.className = 'ai-chat-source-cited';
2951
+ cited.textContent = text;
2952
+ cited.dataset.tip = tip;
2953
+ return cited;
2954
+ }
2955
+
2956
+ /**
2957
+ * #3000: a source the AI cited that the answer never marks. It supports no claim on the page, so it is listed under
2958
+ * "Also consulted" with no number; one FloLess could not find is said quietly, never as a claim to assume.
2959
+ */
2960
+ function consultedChip(turnId, row) {
2961
+ const chip = document.createElement('span');
2962
+ chip.className = 'ai-chat-attachment ai-chat-source consulted';
2963
+ chip.dataset.turnId = turnId || '';
2964
+ chip.dataset.anchor = row.anchor;
2965
+ const entry = row.entry;
2966
+ if (entry.status !== 'resolved') {
2967
+ chip.classList.add('not-found');
2968
+ const why = document.createElement('span'); why.className = 'ai-chat-source-why';
2969
+ why.textContent = referenceProblem(entry) ? 'The AI named this member wrongly. Not used in the answer.' : `Not found: ${entry.reason}. Not used in the answer.`;
2970
+ chip.append(claimCited(entry.label, 'What the AI cited'), why);
2971
+ return chip;
2972
+ }
2973
+ const label = citationLabel(entry);
2974
+ const open = button(label, 'shell.chat-cite-open', 'ai-chat-answer-open ai-chat-source-open');
2975
+ open.dataset.commandInstanceLabel = label;
2976
+ open.setAttribute('aria-label', `Open ${label}`);
2977
+ open.dataset.tip = `${citationProvenance(entry)} · The answer does not cite it for any claim`;
2978
+ open.addEventListener('click', () => openCitedSource(row, turnId));
2979
+ const marks = document.createElement('span'); marks.className = 'ai-chat-source-marks';
2980
+ marks.textContent = citationMarks(entry);
2981
+ chip.append(open, marks);
2982
+ return chip;
2983
+ }
2984
+
2788
2985
  /** The person's ways on from a claim with no source, in one row that wraps between buttons, never inside one. */
2789
2986
  function sourceActions(...buttons) {
2790
2987
  const actions = document.createElement('span'); actions.className = 'ai-chat-source-actions';
@@ -3294,9 +3491,20 @@
3294
3491
  function renderCitationSources(event) {
3295
3492
  const last = state.events.filter((candidate) => candidate.type === 'citation' && candidate.turnId === event.turnId).at(-1);
3296
3493
  if (last !== event) return null;
3297
- const index = citationIndex(event.turnId);
3298
- if (!index.order.length) return null;
3299
- return citationRow(index.order.map((anchor) => citationChip(event.turnId, index.byAnchor.get(anchor))));
3494
+ return turnSources(event.turnId);
3495
+ }
3496
+
3497
+ /** #2999: the Sources row of an answer that marks claims but cited nothing: there is no citation event to hold it. */
3498
+ function renderUncitedClaims(turnId) {
3499
+ if (!turnId || state.events.some((candidate) => candidate.type === 'citation' && candidate.turnId === turnId)) return null;
3500
+ return turnSources(turnId);
3501
+ }
3502
+
3503
+ function turnSources(turnId) {
3504
+ const index = citationIndex(turnId);
3505
+ if (!index.order.length && !index.unused.length) return null;
3506
+ return citationRow(index.order.map((anchor) => citationChip(turnId, index.byAnchor.get(anchor))),
3507
+ index.unused.map((anchor) => consultedChip(turnId, index.byAnchor.get(anchor))));
3300
3508
  }
3301
3509
 
3302
3510
  /** #2436: a Knowledge citation written before #2437 — its pages as chips; whether the AI read them was never recorded. */
@@ -3321,15 +3529,34 @@
3321
3529
  }));
3322
3530
  }
3323
3531
 
3324
- function citationRow(chips) {
3532
+ let alsoHeads = 0;
3533
+ function citationRow(chips, consulted = []) {
3325
3534
  const wrap = document.createElement('div'); wrap.className = 'ai-chat-sources';
3535
+ if (consulted.length) {
3536
+ // #3000: sources the AI gave that no claim on the page uses, after the ones that do.
3537
+ const also = document.createElement('span'); also.className = 'ai-chat-sources-head also';
3538
+ also.id = `ai-chat-also-${++alsoHeads}`;
3539
+ also.textContent = 'Also consulted';
3540
+ also.dataset.tip = 'Sources the AI cited that the answer does not use for any claim. They are not claims, so there is nothing to assume';
3541
+ const list = document.createElement('div'); list.className = 'ai-chat-sources-list also';
3542
+ list.setAttribute('role', 'list'); list.setAttribute('aria-labelledby', also.id);
3543
+ for (const chip of consulted) chip.setAttribute('role', 'listitem');
3544
+ list.append(...consulted);
3545
+ if (chips.length) wrap.append(...citationRow(chips).childNodes);
3546
+ wrap.append(also, list);
3547
+ return wrap;
3548
+ }
3326
3549
  const head = document.createElement('span'); head.className = 'ai-chat-sources-head';
3327
3550
  // #2643: a source a person chose is not one the AI gave, so a row holding one says neither.
3328
3551
  const chosen = chips.some((chip) => chip.classList.contains('chosen'));
3329
- head.textContent = chosen ? 'Sources for this answer' : 'Sources the AI gave for this answer';
3330
- head.dataset.tip = chosen
3331
- ? 'FloLess found each source. It says whether the AI was shown one it cited, and marks one a person chose as chosen. It does not check that a source supports the claim.'
3332
- : 'FloLess found each source and says whether the AI was shown it. It does not check that a source supports the claim.';
3552
+ // #2999: a row of claims the AI named no source for says so, never that the AI gave sources.
3553
+ const none = !chosen && chips.every((chip) => chip.dataset.bare === 'true');
3554
+ head.textContent = none ? 'Claims with no source' : chosen ? 'Sources for this answer' : 'Sources the AI gave for this answer';
3555
+ head.dataset.tip = none
3556
+ ? 'The AI marked these claims but named no source for any of them. Ask for one, choose one, or record the claim as an assumption.'
3557
+ : chosen
3558
+ ? 'FloLess found each source. It says whether the AI was shown one it cited, and marks one a person chose as chosen. It does not check that a source supports the claim.'
3559
+ : 'FloLess found each source and says whether the AI was shown it. It does not check that a source supports the claim.';
3333
3560
  const list = document.createElement('div'); list.className = 'ai-chat-sources-list';
3334
3561
  list.append(...chips);
3335
3562
  wrap.append(head, list);
@@ -3353,7 +3580,8 @@
3353
3580
 
3354
3581
  /** The words just before a claim's "?" marker (the last 90 characters), or '' when the answer shows no marker for it. */
3355
3582
  function unsourcedClaimWords(turnId, anchor) {
3356
- const marker = [...ui.feed.querySelectorAll('button.ai-chat-cite')].find((node) => node.dataset.turnId === (turnId || '') && node.dataset.anchor === anchor);
3583
+ const marker = [...ui.feed.querySelectorAll('button.ai-chat-cite')].find((node) => node.dataset.turnId === (turnId || '') && node.dataset.anchor === anchor)
3584
+ ?? answerMarker(turnId, anchor);
3357
3585
  const block = marker?.closest('p, li, h1, h2, h3, blockquote');
3358
3586
  let before = '';
3359
3587
  if (block && marker) {
@@ -3372,6 +3600,28 @@
3372
3600
  return words.length > 90 ? `…${words.slice(-90).join('').trimStart()}` : before;
3373
3601
  }
3374
3602
 
3603
+ /**
3604
+ * #2999: the claim's marker in its answer as FloLess renders it, off the page: a Sources row is built before its
3605
+ * answer is on the page when the answer also cited something, and its chips still name their claims.
3606
+ */
3607
+ let answerMarkers = null;
3608
+ function answerMarker(turnId, anchor) {
3609
+ const answer = answerText(turnId);
3610
+ if (!answer) return null;
3611
+ // The answer is rendered off the page once for all its claims, and again only when its text changes.
3612
+ const key = `${turnId}\u0000${answer.blocks.join('\u0000')}`;
3613
+ if (answerMarkers?.key !== key) {
3614
+ const markers = new Map();
3615
+ for (const block of answer.blocks) {
3616
+ const scratch = document.createElement('div');
3617
+ renderAnswerBody(scratch, block, turnId);
3618
+ for (const node of scratch.querySelectorAll('button.ai-chat-cite')) if (!markers.has(node.dataset.anchor)) markers.set(node.dataset.anchor, node);
3619
+ }
3620
+ answerMarkers = { key, markers };
3621
+ }
3622
+ return answerMarkers.markers.get(anchor) ?? null;
3623
+ }
3624
+
3375
3625
  /** Never overwrites what the person is writing: the text goes after it. */
3376
3626
  function addToMessageBox(text) {
3377
3627
  const held = ui.input.value.trim();
@@ -3712,7 +3962,15 @@
3712
3962
  if (finished) return;
3713
3963
  status.textContent = entry.chosen ? 'The Knowledge page as it was when you chose it.' : 'The Knowledge page as it was when the answer cited it.';
3714
3964
  const article = document.createElement('div'); article.className = 'ai-chat-message-body ai-chat-source-viewer-page';
3715
- article.innerHTML = markdownHtml(page.body);
3965
+ article.innerHTML = knowledgePageHtml(page.body, page.links);
3966
+ // #3003: a page a link names opens in Knowledge at this same version.
3967
+ article.addEventListener('click', (event) => {
3968
+ const link = event.target.closest?.('button[data-kb-link]');
3969
+ if (!link) return;
3970
+ finish();
3971
+ if (window.flolessWorkspaces?.openKnowledgePage) window.flolessWorkspaces.openKnowledgePage(page.projectId, link.dataset.kbLink, page.generationId);
3972
+ else announce('Knowledge is not available on this page.');
3973
+ });
3716
3974
  const knowledge = button('Open in Knowledge', 'shell.chat-cite-open-knowledge', 'ai-chat-source-viewer-knowledge');
3717
3975
  knowledge.addEventListener('click', () => {
3718
3976
  finish();
@@ -4881,11 +5139,21 @@
4881
5139
  if (screen?.view === 'requests' && screen.requestId && typeof window.flolessBridge?.openRequest === 'function') {
4882
5140
  await window.flolessBridge.openRequest(screen.requestId); return true;
4883
5141
  }
4884
- // #2450: one connection, selected and framed in the project's model editor. Like every screen here it
4885
- // answers only whether it opened; the readiness card reads the editor's full outcome itself.
5142
+ // #2450: one connection, selected and framed in the project's model editor. A later request taking over
5143
+ // counts as opened (it reports for itself). #2520: when the editor says why it could not show it, that
5144
+ // sentence reaches the card as a `plain` error, never replaced by the card's generic line.
4886
5145
  if (screen?.view === 'connection' && screen.projectId && screen.jointId) {
4887
5146
  const outcome = await openConnectionInModel(screen.projectId, screen.jointId);
4888
- return outcome?.ok === true || outcome?.superseded === true;
5147
+ if (outcome?.ok === true || outcome?.superseded === true) return true;
5148
+ if (typeof outcome?.said === 'string' && outcome.said) throw Object.assign(new Error(outcome.said), { plain: true });
5149
+ return false;
5150
+ }
5151
+ // #2521 row 9: Make precise itself, in the project's model editor, where the person confirms each AI decision.
5152
+ if (screen?.view === 'project' && screen.panel === 'make-precise' && screen.projectId && typeof window.flolessWorkspaces?.openConnection === 'function') {
5153
+ const outcome = await window.flolessWorkspaces.openConnection({ projectId: screen.projectId, makePrecise: true });
5154
+ if (outcome?.ok === true || outcome?.superseded === true) return true;
5155
+ if (typeof outcome?.said === 'string' && outcome.said) throw Object.assign(new Error(outcome.said), { plain: true });
5156
+ return false;
4889
5157
  }
4890
5158
  if (screen?.view === 'project' && screen.step === 'drawings' && screen.projectId && typeof window.flolessWorkspaces?.openDrawingsStep === 'function') {
4891
5159
  await window.flolessWorkspaces.openDrawingsStep(screen.projectId); return true;
@@ -6595,6 +6863,8 @@
6595
6863
  }
6596
6864
  // Open the place: a human-only action's screen, or the flow for a tool, workflow, agent, routine or page.
6597
6865
  let opened = false;
6866
+ // #2520: a screen that refuses in its own words (a connection no longer in the model) says that, not the generic line.
6867
+ let refused = '';
6598
6868
  try {
6599
6869
  if (answer.outcome === 'screen') opened = await openActionScreen(answer.screen);
6600
6870
  else if (answer.move?.kind === 'create-workflow' && typeof window.flolessBridge?.newWorkflow === 'function') {
@@ -6602,12 +6872,13 @@
6602
6872
  void window.flolessBridge.newWorkflow({ name: answer.move.name });
6603
6873
  } else if (answer.move) opened = Boolean(await window.flolessGuide?.openFlow?.(answer.move));
6604
6874
  } catch (error) {
6605
- console.warn('[assistant] a suggestion could not open its place:', error);
6875
+ if (error?.plain === true && error.message) refused = error.message;
6876
+ else console.warn('[assistant] a suggestion could not open its place:', error);
6606
6877
  opened = false;
6607
6878
  }
6608
6879
  if (!opened) {
6609
6880
  entry.fold = { opened: false };
6610
- entry.error = 'FloLess couldn’t open that from here. Open it from the ≡ menu instead.';
6881
+ entry.error = refused || 'FloLess couldn’t open that from here. Open it from the ≡ menu instead.';
6611
6882
  entry.focus = 'status'; repaintAssistantCard(entry); return;
6612
6883
  }
6613
6884
  entry.fold = null;
@@ -7818,7 +8089,6 @@
7818
8089
  const note = scope.startsWith('h:') ? (source.note.trim() ? source.note : '') : source.note.trim();
7819
8090
  return { ...(note ? { note } : {}), ...(source.files.length ? { evidence: source.files.map((file) => file.attachmentId) } : {}) };
7820
8091
  }
7821
- const MAX_ANSWER_NOTE = 160;
7822
8092
  const MAX_HEIGHT_CLARIFICATION = 8000;
7823
8093
  // #2167: asked for nothing at all. Said plainly, with the three things that would count.
7824
8094
  const NO_HEIGHT_NO_SOURCE = 'Type a height, or add a note or a picture and the AI will work it out.';
@@ -8022,7 +8292,7 @@
8022
8292
  if (ctx.clarification) { note.rows = 4; wrap.classList.add('ai-chat-answer-clarification'); }
8023
8293
  else { note.type = 'text'; note.maxLength = 160; }
8024
8294
  note.className = `ai-chat-height-input ai-chat-answer-note${ctx.clarification ? ' ai-chat-answer-clarification' : ''}`; note.autocomplete = 'off';
8025
- note.placeholder = ctx.clarification ? 'Use the stair landing level shown in this detail; the hanger sits on it.' : 'Source, e.g. per 7/S-502 (optional)';
8295
+ note.placeholder = ctx.clarification ? (ctx.clarificationPlaceholder || 'Use the stair landing level shown in this detail; the hanger sits on it.') : 'Source, e.g. per 7/S-502 (optional)';
8026
8296
  note.dataset.commandId = ctx.idFor('note'); note.dataset.commandInstanceLabel = ctx.instance;
8027
8297
  note.setAttribute('aria-label', `${ctx.clarification ? 'Explain what to use' : 'Source note'} for ${ctx.label}`);
8028
8298
  note.value = source.note;
@@ -8033,7 +8303,7 @@
8033
8303
  note.id = `clarification-${encodeURIComponent(scope)}`; heading.htmlFor = note.id; box.append(heading);
8034
8304
  counter = Object.assign(document.createElement('p'), { className: 'ai-chat-answer-lead' });
8035
8305
  note.setAttribute('aria-describedby', `${note.id}-limit`); counter.id = `${note.id}-limit`;
8036
- const count = () => { counter.textContent = `${note.value.length.toLocaleString()} / 8,000 characters. Without a Height, this saves clarification for the read; the height stays unresolved.`; note.setAttribute('aria-invalid', String(note.value.length > MAX_HEIGHT_CLARIFICATION)); };
8306
+ const count = () => { counter.textContent = `${note.value.length.toLocaleString()} / 8,000 characters. ${ctx.clarificationHint || 'Without a Height, this saves clarification for the read; the height stays unresolved.'}`; note.setAttribute('aria-invalid', String(note.value.length > MAX_HEIGHT_CLARIFICATION)); };
8037
8307
  note.addEventListener('input', count); count();
8038
8308
  }
8039
8309
  note.addEventListener('input', () => { source.note = note.value; ctx.onDraftChange?.(); });
@@ -8320,7 +8590,7 @@
8320
8590
  if (kind === 'height' && ['resolved-from-drawings', 'no-longer-needed'].includes(heightResponsibility(row))) return;
8321
8591
  showDrawingSlot(entry.chatId);
8322
8592
  entry.changing.add(key); entry.activeItem = key; entry.finishActive = false; entry.reopenedAt = (state.drawingActivationOrder = (state.drawingActivationOrder || 0) + 1);
8323
- if (kind === 'setup' && row.answer?.note && row.answer.how !== 'none') { const source = answerSource((kind === 'setup' ? `s:${entry.questionId}:${key}` : heightSourceScope(entry, key))); source.open = true; source.note ||= row.answer.note; }
8593
+ if (kind === 'setup' && row.answer?.note && row.answer.how !== 'none') { const source = answerSource((kind === 'setup' ? `s:${entry.questionId}:${key}` : heightSourceScope(entry, key))); source.open = true; }
8324
8594
  entry.slotPhase = 'row';
8325
8595
  (kind === 'setup' ? repaintSetupCard : repaintHeightCard)(entry);
8326
8596
  drawingSlotRepaint();
@@ -8474,7 +8744,8 @@
8474
8744
  function drawingSource(kind, entry, scope, label, idFor, row, onDraftChange) {
8475
8745
  return paintAnswerSource(scope, { requestId: entry.requestId, chatId: entry.chatId, repaint: () => { (kind === 'setup' ? repaintSetupCard : repaintHeightCard)(entry); drawingSlotRepaint(); },
8476
8746
  removeFile: (file) => request(`/api/chat/answer-evidence/${encodeURIComponent(entry.requestId)}/${encodeURIComponent(file.attachmentId)}`, { method: 'DELETE', body: JSON.stringify({ chatId: entry.chatId }) }),
8477
- label, instance: label, idFor, inherited: row?.inherited, inheritedNote: (kind === 'height' ? row?.answer?.note : null) || row?.inheritedNote, clarification: kind === 'height', busyReason: entry.busy ? 'An answer is still being saved — wait for it to finish' : null,
8747
+ label, instance: label, idFor, inherited: row?.inherited, inheritedNote: (row?.answer?.how !== 'none' ? row?.answer?.note : null) || row?.inheritedNote, clarification: true,
8748
+ ...(kind === 'setup' ? { clarificationHint: 'Without a value above, this saves your explanation for the read; nothing is confirmed.', clarificationPlaceholder: 'Tell the read what to use and where it comes from, e.g. per 7/S-502.' } : {}), busyReason: entry.busy ? 'An answer is still being saved — wait for it to finish' : null,
8478
8749
  allowPictureOnly: false, onDraftChange, alwaysOpen: Boolean(entry.slotDrafts?.get(entry.slotQuestionKey)?.rows[0]?.otherOpen) });
8479
8750
  }
8480
8751
  function retainedHeightPicture(entry, file, commandId, instance) {
@@ -8564,22 +8835,25 @@
8564
8835
  q.figure = () => heightPlaceFigure(entry, row);
8565
8836
  if (row.fromEvidence) q.context.push(row.inherited?.length ? 'The read’s reading of your picture. Check it before you confirm.' : 'The read’s reading of your note. Check it before you confirm.');
8566
8837
  } else if (row.kind === 'origin') {
8838
+ q.otherInputLabel = 'Grid crossing (optional)'; q.otherPlaceholder = 'A/1'; q.otherUncapped = true;
8567
8839
  q.question = 'Which grid crossing is the model’s origin (0, 0)?'; q.layout = 'grid'; q.confirmSelection = true;
8568
8840
  row.choices.forEach((choice, index) => { q.options.push({ shown: originText(choice), description: 'A straight grid crossing in the model', confirmLabel: `Confirm ${originText(choice)} as the model origin`, tag: row.proposed === index ? 'THE READ SUGGESTS' : '' }); choices.push({ key, action: 'confirm', choice: `c${index}`, shown: originText(choice) }); });
8569
8841
  row.offGrid.forEach((point, index) => { const target = row.choices[point.same]; q.options.push({ shown: point.as, description: 'Not a straight grid line; check the read’s mapping', confirmLabel: `Confirm ${originText(target)} as the model origin`, statement: `${point.as} is not a straight grid line in the model. The read says it is the same point as ${originText(target)} (${point.why}). This is the read’s claim; FloLess has not checked it.` }); choices.push({ key, action: 'confirm', choice: `o${index}`, shown: originText(target) }); });
8570
8842
  q.recommended = Number.isInteger(row.proposed) ? row.proposed : null;
8571
- if (row.fromEvidence) q.context.push('The read’s reading of your picture. Check it before you confirm.');
8843
+ if (row.fromEvidence) q.context.push(row.inherited?.length ? 'The read’s reading of your picture. Check it before you confirm.' : 'The read’s reading of your note. Check it before you confirm.');
8572
8844
  } else {
8845
+ q.otherInputLabel = row.kind === 'scale' ? 'Scale (optional)' : 'Level (optional)'; q.otherUncapped = true;
8846
+ q.otherPlaceholder = row.kind === 'scale' ? `1/4" = 1'-0", or 1:100` : entry.view.units === 'mm' ? '4870 mm, or 4.87 for metres' : `15'-11 3/4"; a bare number is inches`;
8573
8847
  if (row.clue) q.context.push(row.clue);
8574
8848
  if (row.noSingleLevel) q.context.push(`No single level on the drawings: ${row.noSingleLevel.why}`);
8575
8849
  // Options follow row.proposals in order, so the selected option's index names its proposal.
8576
8850
  // A choice past the proposals ("No single level") has no place of its own, so it gets no picture.
8577
8851
  if (row.kind === 'level') q.figure = (choice) => setupPlaceFigure(entry, row, Number.isInteger(choice) ? (row.proposals[choice] ?? SETUP_NO_PROPOSAL) : null);
8578
8852
  row.proposals.forEach((proposal) => { q.options.push({ shown: row.kind === 'scale' ? `${proposal.pageFit ? 'Use for this plan' : 'Confirm'}: ${proposal.standard} · ${proposal.mmPerPx} mm per drawing point` : `Confirm ${proposal.asRead}`,
8579
- description: row.kind === 'scale' ? proposal.evidence : levelEvidence(proposal), tag: (row.kind === 'scale' ? scaleTag : levelTag)[proposal.source] || 'PROPOSED' }); choices.push({ key, action: 'confirm', choice: proposal.id, shown: row.kind === 'scale' ? proposal.mmPerPx : proposal.value }); });
8853
+ description: row.kind === 'scale' ? proposal.evidence : levelEvidence(proposal), tag: proposal.source === 'read-of-picture' && !row.inherited?.length ? 'THE READ’S READING OF YOUR NOTE' : (row.kind === 'scale' ? scaleTag : levelTag)[proposal.source] || 'PROPOSED' }); choices.push({ key, action: 'confirm', choice: proposal.id, shown: row.kind === 'scale' ? proposal.mmPerPx : proposal.value }); });
8580
8854
  }
8581
8855
  if (kind === 'setup' && (row.kind === 'origin' || row.kind === 'scale')) q.context.push('This setup question has no saved drawing location. Inspect the drawing set in Drawing Filter, or ask the read to point out the context.');
8582
- if (kind === 'setup' && row.kind !== 'scale') { q.options.push({ shown: row.kind === 'origin' ? 'None of these' : 'No single level', description: 'Tell the read what to use instead', requiresNote: { placeholder: 'Add a short reason', max: MAX_ANSWER_NOTE } }); choices.push({ key, action: 'none' }); }
8856
+ if (kind === 'setup' && row.kind !== 'scale') { q.options.push({ shown: row.kind === 'origin' ? 'None of these' : 'No single level', description: 'Tell the read what to use instead', requiresNote: { placeholder: 'Say why, and what to use instead', max: MAX_HEIGHT_CLARIFICATION } }); choices.push({ key, action: 'none' }); }
8583
8857
  if (kind === 'setup') { const banner = setupConflictBanner(row); if (banner) q.context.push(banner.textContent); }
8584
8858
  const controlKey = kind === 'height' ? `${row.memberId} ${row.endWord}` : key;
8585
8859
  const idFor = (what, extra) => `shell.chat-answer-${what}#${entry.questionId} ${controlKey}${extra === undefined ? '' : ` ${extra}`}`;
@@ -8590,9 +8864,8 @@
8590
8864
  source: (_index, onDraftChange) => drawingSource(kind, entry, scope, label, idFor, row, onDraftChange),
8591
8865
  validate: (_step, draft) => {
8592
8866
  const answer = draft.rows[0]; if (answer.choices.length) return '';
8593
- if (answer.other.trim()) return '';
8594
- if (kind === 'height' && hasAnswerSource(scope)) return '';
8595
- return answerSource(scope).files.length ? '' : kind === 'setup' ? 'Type a value, or attach a picture first.' : NO_HEIGHT_NO_SOURCE;
8867
+ if (answer.other.trim() || hasAnswerSource(scope)) return '';
8868
+ return kind === 'setup' ? 'Type a value, explain what to use, or attach a picture.' : NO_HEIGHT_NO_SOURCE;
8596
8869
  },
8597
8870
  commit: async (answer) => {
8598
8871
  let payload;
@@ -9022,7 +9295,9 @@
9022
9295
  if (row.status === 'picture' && !changing) {
9023
9296
  const wait = document.createElement('div'); wait.className = 'ai-chat-height-answered';
9024
9297
  const glyph = document.createElement('span'); glyph.className = 'ai-chat-height-glyph'; glyph.textContent = '…'; glyph.setAttribute('aria-hidden', 'true');
9025
- const text = document.createElement('span'); text.textContent = 'Waiting for the read to read your picture';
9298
+ const unread = entry.unreadValue?.has(row.key) ? `FloLess could not read what you typed as ${row.kind === 'origin' ? 'one of the grid crossings on this card' : row.kind === 'scale' ? 'a scale' : 'a level'}, so it kept your words as a note. ` : '';
9299
+ const text = document.createElement('span'); text.textContent = !row.answer?.note ? 'Waiting for the read to read your picture'
9300
+ : `${unread}Saved as a note${row.answer.evidence?.length ? ' with your picture' : ''} for the read. Nothing is confirmed; this row stays open until you confirm a value.`;
9026
9301
  wait.append(glyph, text);
9027
9302
  if (open) {
9028
9303
  const change = heightActionButton('Answer now', idFor('change'), instance, 'ai-chat-height-change', null);
@@ -9076,13 +9351,13 @@
9076
9351
  let saved = false;
9077
9352
  const withSource = answers.map((answer) => withAnswerSource(answer, answerSourcePayload(`s:${entry.questionId}:${answer.key}`)));
9078
9353
  try {
9079
- const tooLong = withSource.find((answer) => answer.note && answer.note.length > MAX_ANSWER_NOTE);
9080
- if (tooLong) {
9081
- entry.rowErrors.set(rowKey, `Your reason and your source note together are longer than ${MAX_ANSWER_NOTE} characters. Shorten one of them.`);
9354
+ // Measured as the server joins them when the value is not one it can read: typed, a blank line, the note.
9355
+ if (withSource.some((answer) => [answer.typed?.trim(), answer.note].filter(Boolean).join('\n\n').length > MAX_HEIGHT_CLARIFICATION)) {
9356
+ entry.rowErrors.set(rowKey, 'Your answer and explanation together are longer than 8,000 characters. Your full draft is kept. Shorten it, or send the rest in chat.');
9082
9357
  return false;
9083
9358
  }
9084
- if (withSource.some((answer) => answer.action === 'evidence' && !answer.evidence?.length)) {
9085
- entry.rowErrors.set(rowKey, 'Attach a picture first.'); return false;
9359
+ if (withSource.some((answer) => answer.action === 'evidence' && !answer.evidence?.length && !answer.note)) {
9360
+ entry.rowErrors.set(rowKey, 'Explain what to use, or attach a picture first.'); return false;
9086
9361
  }
9087
9362
  entry.busy = true; entry.cardError = ''; if (rowKey) entry.rowErrors.delete(rowKey);
9088
9363
  repaintSetupCard(entry);
@@ -9092,7 +9367,13 @@
9092
9367
  entry.view = result.question;
9093
9368
  saved = true; entry.failedSubmission = null; entry.saveFailed = false; if (seenAtAnswer) drawingMessagesSeen(entry.chatId, seenAtAnswer);
9094
9369
  for (const answer of answers) {
9095
- entry.changing.delete(answer.key); entry.drafts.delete(answer.key); entry.drafts.delete(`${answer.key}\u0000none`);
9370
+ // A saved row starts its next edit from the record, not the old typing: a note saved from the value field lives in
9371
+ // the explanation box when it is reopened, and must not also come back in the value field (#2840).
9372
+ entry.changing.delete(answer.key); entry.drafts.delete(answer.key); entry.drafts.delete(`${answer.key}\u0000none`); entry.slotDrafts?.delete(answer.key);
9373
+ // A value FloLess could not read is kept as the person's note; the row says so rather than leaving them to wonder.
9374
+ entry.unreadValue ??= new Set();
9375
+ if (answer.action === 'type' && entry.view?.items?.find((item) => item.key === answer.key)?.answer?.how === 'evidence') entry.unreadValue.add(answer.key);
9376
+ else entry.unreadValue.delete(answer.key);
9096
9377
  if (entry.activeItem === answer.key) { entry.activeItem = null; entry.reopenedAt = 0; }
9097
9378
  entry.noneOpen.delete(answer.key);
9098
9379
  if (answer.key === 'origin') entry.originPick = null;
@@ -9735,8 +10016,17 @@
9735
10016
  if (!assistant) return;
9736
10017
  const rendered = renderedLiveAssistantText(assistant.event, assistant.text);
9737
10018
  ui.feed.append(renderMessage(assistant.event, 'assistant', rendered.text, rendered.streaming));
10019
+ holdUncitedClaims(assistant.event.turnId);
9738
10020
  assistant = null;
9739
10021
  };
10022
+ // #2999: an answer that cited nothing still lists the claims it marked, once, under the answer, streamed or whole.
10023
+ const uncitedTurns = new Set();
10024
+ const holdUncitedClaims = (turnId) => {
10025
+ if (!turnId || uncitedTurns.has(turnId)) return;
10026
+ uncitedTurns.add(turnId);
10027
+ const node = renderUncitedClaims(turnId);
10028
+ if (node) { if (links.length && links[0].turnId !== turnId) flushLinks(); links.push({ turnId, node }); }
10029
+ };
9740
10030
  const flushLinks = () => { if (links.length) { ui.feed.append(...receiptFold(links)); links = []; } };
9741
10031
  for (const event of state.events) {
9742
10032
  // #2642/#2643: the person's assumption or chosen source is painted on its claim's chip; it never starts or ends an answer group (it has no turn).
@@ -9810,6 +10100,7 @@
9810
10100
  // as it is).
9811
10101
  const node = feedCard(renderEvent(event), event);
9812
10102
  if (node) ui.feed.append(node);
10103
+ if (event.type === 'assistant-message') holdUncitedClaims(event.turnId);
9813
10104
  }
9814
10105
  flushAssistant();
9815
10106
  flushLinks();
@@ -11424,7 +11715,15 @@
11424
11715
  if (finished) return;
11425
11716
  status.textContent = 'The Knowledge page at the version you mentioned.';
11426
11717
  const article = document.createElement('div'); article.className = 'ai-chat-message-body ai-chat-source-viewer-page';
11427
- article.innerHTML = markdownHtml(page.body);
11718
+ article.innerHTML = knowledgePageHtml(page.body, page.links);
11719
+ // #3003: a page a link names opens in Knowledge at this same version.
11720
+ article.addEventListener('click', (event) => {
11721
+ const link = event.target.closest?.('button[data-kb-link]');
11722
+ if (!link) return;
11723
+ finish();
11724
+ if (window.flolessWorkspaces?.openKnowledgePage) window.flolessWorkspaces.openKnowledgePage(page.projectId, link.dataset.kbLink, page.generationId);
11725
+ else announce('Knowledge is not available on this page.');
11726
+ });
11428
11727
  const knowledge = button('Open in Knowledge', 'shell.chat-cite-open-knowledge', 'ai-chat-source-viewer-knowledge');
11429
11728
  knowledge.addEventListener('click', () => {
11430
11729
  finish();
@@ -13369,7 +13668,7 @@
13369
13668
  // changing the attachments themselves.
13370
13669
  paintAttachControl();
13371
13670
  const unknownReason = state.followupUnknownId || hasUnknownFollowup()
13372
- ? 'FloLess could not confirm a follow-up. Review that message before sending or attaching another file.' : null;
13671
+ ? 'FloLess could not confirm your last message reached the AI. Review that message before sending or attaching another file.' : null;
13373
13672
  const sendingReason = state.followupSubmitting
13374
13673
  ? 'FloLess is saving this message. Wait for its delivery status before sending another.' : null;
13375
13674
  for (const control of [ui.send, ui.attach]) {
@@ -14203,7 +14502,20 @@
14203
14502
  if (!providerReady()) void loadCapability().then(() => { if (sameChat(snapshot)) { paintSettings(); updateSendState(); } });
14204
14503
  if (given) return { sent: true };
14205
14504
  } catch (error) {
14505
+ const unconfirmedAnswer = 'FloLess is busy and hasn’t confirmed your answer reached the AI yet. Check the conversation before you answer again.';
14206
14506
  if (!sameChat(snapshot)) {
14507
+ // #2957: a timed-out send is as unconfirmed after the person moved on; it waits as unconfirmed in its own
14508
+ // conversation (reconcileUnknownFollowupOnSelection), and is settled there if that conversation is open again.
14509
+ if (error?.code === 'local-timeout') {
14510
+ optimisticEvent.payload.deliveryState = 'unknown';
14511
+ state.unknownFollowups.set(chatId, { submissionId: clientSubmissionId, text, event: optimisticEvent });
14512
+ // Open again through another project counts too (a new scope generation, the same owner): by owner, not generation.
14513
+ if (scopeKey(snapshot.scope) === scopeKey(state.scope) && state.chat?.chatId === chatId) {
14514
+ reconcileUnknownFollowupOnSelection(state.chat);
14515
+ paintEvents(); updateSendState();
14516
+ }
14517
+ return given ? givenNotSent(unconfirmedAnswer) : undefined;
14518
+ }
14207
14519
  if (given) return givenNotSent();
14208
14520
  if (initialTurnDefinitelyRefused(error)) {
14209
14521
  await restoreBackgroundDraft(snapshot, text, clientSubmissionId);
@@ -14213,6 +14525,33 @@
14213
14525
  return;
14214
14526
  }
14215
14527
  state.pendingSubmissionId = null;
14528
+ // #2957: the browser stopped waiting, but the server keeps working on the message, so it may already be in the
14529
+ // conversation. A timed-out send is unconfirmed, never "not sent": the message stays visible as unconfirmed, and
14530
+ // its user-message event or the person's "Review draft and continue" settles it, as for an uncertain follow-up.
14531
+ if (error?.code === 'local-timeout') {
14532
+ const arrived = state.events.some((event) => !event.optimistic && event.type === 'user-message'
14533
+ && event.clientSubmissionId === clientSubmissionId);
14534
+ state.chat = previousChat;
14535
+ if (arrived) {
14536
+ state.events = state.events.filter((event) => event.eventId !== optimisticEvent.eventId);
14537
+ paintConversation();
14538
+ refreshConversation(chatId, false);
14539
+ announce('FloLess was slow to answer, but your message went through.');
14540
+ return given ? { sent: true } : undefined;
14541
+ }
14542
+ optimisticEvent.payload.deliveryState = 'unknown';
14543
+ state.followupUnknownId = clientSubmissionId;
14544
+ state.unknownFollowups.set(chatId, { submissionId: clientSubmissionId, text, event: optimisticEvent });
14545
+ if (given) {
14546
+ paintConversation();
14547
+ return givenNotSent(unconfirmedAnswer);
14548
+ }
14549
+ // The words come back so nothing is lost, but are not saved as a draft: the message may already be on its way.
14550
+ // Its files and mentions stay with the message that may have gone.
14551
+ ui.input.value = text; autosize(); state.localDraft = { chatId, text }; paintConversation();
14552
+ report(error, '', { 'local-timeout': 'FloLess is busy and hasn’t confirmed your message yet. It will appear here if it went through. Check before sending it again.' });
14553
+ return;
14554
+ }
14216
14555
  state.events = state.events.filter((event) => event.eventId !== optimisticEvent.eventId);
14217
14556
  state.chat = previousChat;
14218
14557
  if (given) { paintConversation(); return givenNotSent(givenRefusal(error)); }
@@ -14645,8 +14984,9 @@
14645
14984
  optimisticEvent.payload.deliveryState = 'unknown';
14646
14985
  state.unknownFollowups.set(snapshot.chatId, { submissionId: clientSubmissionId, text, event: optimisticEvent });
14647
14986
  // The user may have selected A → B → A while this request was in flight.
14648
- // The second A snapshot ran before the uncertain result existed, so reconcile it now.
14649
- if (sameScope(snapshot.scope, snapshot.generation) && state.chat?.chatId === snapshot.chatId) {
14987
+ // The second A snapshot ran before the uncertain result existed, so reconcile it now. By owner, not scope
14988
+ // generation: A reopened through another project is a new generation of the same owner (#2957).
14989
+ if (scopeKey(snapshot.scope) === scopeKey(state.scope) && state.chat?.chatId === snapshot.chatId) {
14650
14990
  reconcileUnknownFollowupOnSelection(state.chat);
14651
14991
  paintEvents(); updateSendState();
14652
14992
  }
@@ -16479,10 +16819,11 @@
16479
16819
  return result;
16480
16820
  }
16481
16821
 
16482
- async function resumeProjectIntake(submissionId) {
16822
+ // #2470 R6.7b: `withoutLink` is the person's answer to a link to a General project that could not be made.
16823
+ async function resumeProjectIntake(submissionId, { withoutLink = false } = {}) {
16483
16824
  await ensureSession();
16484
16825
  return request(`/api/chat/project-intakes/${encodeURIComponent(submissionId)}/resume`, {
16485
- method: 'POST', timeoutMs: PROJECT_INTAKE_TIMEOUT_MS, body: '{}',
16826
+ method: 'POST', timeoutMs: PROJECT_INTAKE_TIMEOUT_MS, body: withoutLink ? JSON.stringify({ withoutLink: true }) : '{}',
16486
16827
  });
16487
16828
  }
16488
16829
 
@@ -16676,6 +17017,8 @@
16676
17017
  currentChatId: () => state.chat?.chatId ?? null,
16677
17018
  // The project this panel's conversations belong to; an object card offers Show in chat only for it (#1653).
16678
17019
  scopeProjectId: () => (state.scope?.owner?.kind === 'project' ? state.scope.owner.projectId : null),
17020
+ // #3003: a Knowledge page rendered the way the chat viewers show it, for the Knowledge step's page panel.
17021
+ knowledgePageHtml,
16679
17022
  // The Knowledge step's "Ask AI to index" (#2399 slice 0b): the person's own draft in the message box; never sent.
16680
17023
  fillMessageBox: (text) => putInMessageBox(String(text || '')),
16681
17024
  // The New project dialog's AI choice (#1605) words each provider's sign-in the way this