Repository navigation
AI Mode search: three-word rule, on by default, under-field hint, a settled field, and a follow-up that sends nothing - #524
Merged
Conversation
Deploying nemar-website with
|
| Latest commit: |
6fc730f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://d2d8d757.nemar-website.pages.dev |
| Branch Preview URL: | https://feature-ai-mode-three-words.nemar-website.pages.dev |
…eck tested on a fresh install)
…h; no cut inside a surrogate pair; error state excludes invalid (tested)
…omment, ADR 0032; docs only)
… is a live region present from the draw (tested)
…e it (tested: unit suite, typecheck)
Contributor
Author
|
Review round 1: every finding has an outcome. Pushed to this branch (e2f2458 to 2963608). Tested on a clean install (
Nothing rejected or filed; all of it is code this PR touched. CI should now run |
… from the summary; changelog narrowed to link, image, emphasis, code (tested: unit suite)
… failure note; a late 422 is ignored once the field was edited (tested: unit suite, typecheck)
… open AI Mode (data-ai-unavailable); ADR 0032 notes it (tested: unit suite, typecheck)
Contributor
Author
|
Review round 2: outcomes (commits c870b56, fb675c0, 46453b0; unit suite and typecheck pass).
No findings rejected or filed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The website side of the AI Mode search from #518 and #519: the three-word rule (maintainer's rule, 2026-11-11), and, on top of it, the four changes from the maintainer's test of AI Mode on test.nemar.org (#525).
Three-word rule (this PR's first commits)
countQueryWordsinsrc/lib/osa-overview.tscounts the way OSA counts (split the trimmed query on whitespace, count tokens with a letter or digit, Unicode-aware);OVERVIEW_MIN_WORDS = 3.A one-word search such as "EEG" made OSA's overview endpoint fail (Search overview: a one-word query ('EEG') returns 502 on dev, with Cloudflare's body OpenScience-Collective/osa#728).
#525
No stored choice and no
aiparameter is on; a stored off is off and survives a reload;ai=1forces on;ai=0forces off and is written back (store and address), so a copied link is honest.Storage is in try/catch; blocked storage is on.
aiinsrc/lib/filters.tsnow means on unlessai=0, and only the off is serialised, soai=0survives the filter and paging links.The page is cached for everyone, so the server renders the on state and the client switches off.
Discover's hidden
aiinput is nowai=0when the address is off, so a search submitted without scripts does not silently flip the state.How a cached no-script page behaves is in ADR 0032: it shows the on look and none of its controls, and what it submits means on.
aiHintShown(on, query, refused)insrc/lib/osa-ai-mode.tsdecides it from the live field value (input event), and from the submitted query on Discover, which the field holds at load; a 422 shows it too.Smallest helper size the site has (
--fs-xs), muted site tokens (--color-fg-mutedon Discover,--ai-try-labelon Home, both with dark values), no error colour.One polite live region announces it once per appearance: its text is set on the transition only (
aiHintAnnouncement), not per keystroke.The panel shows nothing in that state:
OVERVIEW_MIN_WORDS_NOTEand the panel's note are gone, the no-request rule,countQueryWordsand the 422 path stay.The Try row, the disclosure and the new line are slots the server renders whenever
aiEndpointis set, always laid out and drawn withvisibility(the text is in the page, so the reserved height is exact at any width); nohiddentoggling is left on them.Measured in a browser, the field was not moving on Home but the content under it jumped 147 px, and Discover's field was 47 px tall with the ring and 46 px without; Discover's field now has a set height (44 px, input 41 px inside the 1.5 px ring).
Tokens reused, no new colours.
It calls
OSAChatWidget.seed(text, {mode: "center"})only; no call to ask or open on that path (a source guard asserts it).The button is drawn only where
seedis a function, checked each time the panel is drawn; a throw fromseedshows the existing failure note.followUpTextandFOLLOW_UP_MAX_CHARSare replaced by the pureseedText(query, answer, origin): first line**AI overview** for "<query>"(the query's Markdown characters and newlines turned to spaces), the summary with each dataset id as[id](<origin>/dataset/<id>)built withoverviewDatasetHref, the picks list when the panel shows picks, at most 2000 characters (UTF-16 code units, as the widget counts), shortened by dropping the picks' reasons, then the picks, then cutting the summary at a sentence.The overview's prose cannot make a link, image or emphasis of its own either, since the widget renders the text as Markdown and the overview is a model's text about dataset descriptions.
Nothing resembling "I searched NEMAR for" remains in
src/(a test checks).Docs: CHANGELOG entry, ADR 0032 updated (default on, the cached no-script page, reserved slots, the seeded follow-up, the 2000 limit), earlier unreleased changelog lines corrected to the new
aisemantics.Closes #525
Deviations and notes
seedatRESEED_TURN_MAX_CHARS = 2000and refuses a longer text, so the message is built to at most 2000; if OSA raises its bound nothing here breaks.aiis on, and the page never writesai=1. An on state carries no parameter; only the off is written (ai=0), so links and the edge cache stay as they were for readers who never chose.ai=1still forces on.bun run test:e2eis documented inplaywright.config.tsand not wired to CI.It needs
bunx playwright install chromiumonce, andE2E_BASE_URL=https://test.nemar.orgpoints it at a deployed site.seedreaches test.nemar.org only after Widget: OSAChatWidget.seed (open with a reply, send nothing); smooth open and dock; bottom-right Move to corner icon OpenScience-Collective/osa#730 is deployed to develop, so until then the button is not drawn there (develop's widget hasopenbut noseed).After that deploy, check with an
xx0999NNid (for examplexx099904), not annmid: the dialog opens with the overview as the assistant's reply, and nothing is sent until the reader writes.The browser check below stands in for the widget with a recording object (
open,seed) and verifies the call and the text.Tests
src/lib/osa-ai-mode.test.ts:readAiModeSearch,initialAiModeSearch(nothing stored, stored on and off,ai=1over a stored off,ai=0over a stored on, odd values, blocked and throwing storage),setAiModeSearch,withAiModeParam,aiLinkHref;aiHintShownfor 0, 1, 2 and 3 words, off and a 422;aiHintAnnouncementover a typed sequence (one announcement per appearance);seedFollowUpandaiModeSeedAvailablewith a recording stand-in for the widget host object, with and withoutseed.src/lib/filters.test.ts: on by default, onlyai=0serialised and kept by paging and filter links,ai=1and odd values read as on.src/lib/ai-overview-panel.test.ts: the panel shows nothing for a short search or a 422;seedText(exact text, query neutralisation, links, no links from prose, picks, 2000 limit in UTF-16 units, the shortening order, no cut inside a link); the controller'srefusedstate;panelViewwithout a follow-up.test/ai-mode-search.test.ts: source guards (no.askinosa-ai-mode.tsor the client, nohiddenon the slots, visibility rules,--fs-xs, the live region, 44 px field, the on state rendered by the server, nothing like "I searched NEMAR for" insrc/).e2e/ai-mode-field.spec.ts(Playwright, 16 tests): on Home and Discover at 1280 px and 390 px, light and dark, the field's top and height and the content under it before and after each click, and with the line shown and hidden, equal within 0.5 px, andscrollWidth <= innerWidth; default on, off remembered across a reload,ai=1andai=0, a search from an off page keeps the off; the line for a two-word search with no request made, for a 422, and its one announcement; the follow-up callsseed(text, {mode: "center"})only and is not drawn withoutseed.Commands run (in a worktree on
feature/ai-mode-three-words)bun run lint: Checked 417 files, no fixes neededbun run typecheck: 0 errors, 0 warnings, 18 hints (486 files)bun run test: 175 files passed, 3 skipped; 4885 tests passed, 17 skipped, 0 failedbun run build: Complete (public/og-image.pngregenerated by the build and reverted)bun run test:e2e: 16 passed (Chromium, againstastro devwithPUBLIC_OSA_OVERVIEW_URLset)Refs #518, OpenScience-Collective/osa#728, OpenScience-Collective/osa#730.