Files
chatkit/src/audit.ts
T
CatoandClaude Sonnet 5.5 ae14b9fee0 feat(audit): findBrokenWords, exported for every product's browser checks (0.14.2) (#27)
* feat(feedback): thumbs under every answer, and the chat-review contract (0.14.0)

The feedback loop between a chat and the people improving it, as a package:

- Under every answer a thumb up and a thumb down (`onFeedback` on ChatThread,
  or `messageId` + `onFeedback` on AnswerActions). A thumb down opens a sheet
  that asks why — one tap on a reason from FEEDBACK_REASONS, words optional,
  then Send — so the product learns what the person wanted, not only that
  it failed. Nothing is sent until they send it. Every label is translatable.
- The nightly judge's contract in core: CHAT_REVIEW_INSTRUCTION, the
  ChatTranscript a product exports (turns with the assistant's steps, plus
  the thumbs), reviewPrompt(scope, transcript), and parseChatReview reading
  the verdicts back strictly (score 1–5, gaps from REVIEW_GAPS — dead_end,
  wrong_tool, no_web, misread, vague, no_next_step… — and one concrete fix).
  Loki runs the judge and files each gap into its feedback inbox.
- Icon-only actions are a full 44px wide, not only tall.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE

* fix(thread): the "Thought for" summary is a 44px target on a phone

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE

* fix(table): words are never cut — tables and stack tiles keep every word whole (0.14.1)

Substrata's answer table at 390px read "Te / rm" and "Di / re / ct / or / y"
(2026-10-22): .ck-md sets overflow-wrap: anywhere so a long URL cannot push
the thread wider, but `anywhere` also lowers a table cell's minimum width to
one letter, so a three-column table squeezed its first column to nothing.

- Tables: overflow-wrap normal inside the table, so a word is the smallest a
  column can be; columns share the width by wrapping at spaces; when even
  the words do not fit the wrapper scrolls, with a shadow on the edge that
  has more.
- Stack figure: tiles are a wrapping flex row that asks for its share of the
  width but never less than its longest word, so "three across" becomes "two
  and one" on a narrow screen instead of cutting "Manufacture" (320px).
- test/browser.mjs: every word of every answer is measured in a Range at 320,
  390 and 1280px and must sit on one line. The demo carries the table from
  the screenshot; the check fails on the old stylesheet (Term, Directory,
  Finding, Humans, Engineers, specialists, Manufacture).
- The "thumb down asks why" check measured a button mid-way through the sheet's
  opening animation (43.9px); it now waits for the animations to finish.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE

* feat(audit): findBrokenWords, exported for every product's browser checks

The check that caught "Te / rm" and "Di / re / ct / or / y" is now
@bitbaum/chatkit/audit: findBrokenWords(root) lays every word out in a Range
and reports any drawn across two lines, and BROKEN_WORDS_SOURCE is its source
for page.evaluate. The browser test uses the exported function over the whole
page and proves it can fail (a squeezed word is reported, a wrapped sentence
is not).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE

* chore(release): 0.14.2

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-23 10:16:54 +02:00

60 lines
2.4 KiB
TypeScript

/**
* Layout audits for a real browser — the part no unit test can see.
*
* Import this from a Playwright script, never from app code. `findBrokenWords`
* runs INSIDE the page: it is self-contained on purpose (no imports, no
* closures), so its source can be handed to `page.evaluate`:
*
* import { BROKEN_WORDS_SOURCE } from "@bitbaum/chatkit/audit";
* const broken = await page.evaluate(`(${BROKEN_WORDS_SOURCE})(document.body)`);
* if (broken.length) throw new Error(`words cut across lines: ${broken}`);
*
* Why it exists: Substrata's answer table at 390px read "Te / rm" and
* "Di / re / ct / or / y" (2026-10-22). Reading the CSS finds none of it; only
* laying the words out does.
*/
/**
* Every word under `root` that is drawn across two lines. A word may wrap onto
* the next line; it may never be cut in two. Measured, not inferred: each word
* is laid out in a `Range` and must sit on one line.
*
* Exempt, because a break there is legal: a word beside a hyphen, slash, dot,
* at-sign, colon or underscore, and anything over `maxWord` characters (a URL
* or an identifier has to break somewhere). Hidden text has no boxes and is
* skipped.
*/
export function findBrokenWords(
root: ParentNode = document,
options: { maxWord?: number } = {},
): string[] {
const maxWord = options.maxWord ?? 24;
const found: string[] = [];
const near = /[-‐‑–—/_.@:]/;
const walker = document.createTreeWalker(
root instanceof Document ? root.body : (root as Node),
NodeFilter.SHOW_TEXT,
);
for (let n = walker.nextNode(); n; n = walker.nextNode()) {
const text = n.nodeValue ?? "";
const re = /[\p{L}\p{N}']+/gu;
for (let m = re.exec(text); m; m = re.exec(text)) {
const word = m[0];
if (word.length > maxWord) continue;
if (near.test(text[m.index - 1] ?? "") || near.test(text[m.index + word.length] ?? ""))
continue;
const range = document.createRange();
range.setStart(n, m.index);
range.setEnd(n, m.index + word.length);
const tops = Array.from(range.getClientRects())
.filter((r) => r.width > 0)
.map((r) => Math.round(r.top));
if (tops.length > 1 && Math.max(...tops) - Math.min(...tops) > 6) found.push(word);
}
}
return found;
}
/** `findBrokenWords` as source text, for `page.evaluate`. */
export const BROKEN_WORDS_SOURCE: string = findBrokenWords.toString();