Skip to content

The Library finds a passage inside its documents, cited by revision and place - #284

Merged
zlareb1 merged 25 commits into
mainfrom
feat/library-search-locators
Nov 6, 2026
Merged

zlareb1 merged 25 commits into
mainfrom
feat/library-search-locators

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Related: #157

Changelog category (leave one):

  • Improvement

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

The dashboard's Library finds a passage inside its documents. Each hit is cited as an agent cites it: the document, the revision it was read from and where the passage sits, in lines, a key, pages or slides, or a sheet's rows. A hit opens its document.

Why

The issue's plan has the dashboard's Library show locator citations. Search hits carry the revision and locator since #252. Before this PR the Library could only filter its list by title, file name or tag, so a person could not find a passage inside the documents or see where an agent's citation points. #283 moved the Library's adds onto the extractor; this is the last dashboard piece of the plan.

Design

  • lib/locator.ts turns a hit's locator into words for its format, with the field meanings taken from server/knowledge/domain/extract/artifact.py::Locator:
    • lines 10–24, line 4;
    • key server.port;
    • page 3, pages 3–5, or slides for a .pptx;
    • Orders, rows 2–40.
    • A key, a page or a row is named instead of the lines, because it places the passage more usefully. A hit with no locator (text a caller extracted) says nothing.
    • citation adds the revision: "revision 3, page 7".
  • searchKnowledge (api/knowledge.ts) calls knowledge.search for the caller's number of hits in the namespace the Library shows (a collection's namespace included, as the list reads it), with namespace_scope: "this".
  • views/LibraryPassages.tsx is the "Find a passage" panel. Its toggle sits in the Library's toolbar (on a phone, beside the sort, under the search), and the panel mounts only while open, so a folded panel adds no height above the list. The toggle is a Click UI empty button with a chevron and aria-expanded, as the Code page's disclosure toggles are, and it also sets aria-controls. docs/development/dashboard-design.md's disclosure line now names that form beside the native button. It shows once the place's list has returned a document on this visit, and stays through a later filtered or failed read. An unfiltered empty read, such as after the last document is deleted, is an empty library and takes it away; once a document is back, the toggle returns folded. A tag filter typed into an empty library does not bring it up, and neither does one carried into another namespace whose filtered first read finds nothing, until the filter is cleared. Another namespace folds it; a search still running then is aborted.
    • Opening the panel focuses its field, which brings it into view: the toolbar stays at the top as the list scrolls, so a panel opened low in the list would otherwise open out of sight.
    • A hint above the field, tied to it with aria-describedby, says the search covers every document in the library whatever the tag filter, and how hits are cited.
    • Find is a BusyButton, so it keeps focus while the search runs.
    • A query lists the best ten hits, and Show more asks for ten more of the query that was searched, up to the 100 knowledge.search lists. The op keeps one hit per section (collapse_sections), so an answer shorter than asked is no sign that nothing is left. Show more stays until a read adds no passage or the cap is reached, and the count reads "The best N passages" until a read adds none, at the cap too. A role="status" line, in the page from the start, announces the count ("The best passage", "The best 10 passages", "14 passages" once a read adds none, "No passage answers that.").
    • The hit list is memoised over the answer, with a stable open, so a keystroke in the field renders only the field.
    • The last Show more removes its button, so focus goes to the first hit that read added (lib/useLastPageFocus, as the list's Load more does). A failed search keeps the hits it would have replaced, beside the alert.
    • While a new search runs, the hits on screen are marked aria-busy.
    • Each hit is a ListRow whose open button is named by what the row shows (the document's source, its section, the citation and the matched keys), with the excerpt as its description, and shows:
      • the last segment of its source address and the whole address, so two documents whose addresses end alike tell apart;
      • its section breadcrumb;
      • the citation and any keys the query matched beyond the one the citation names (neutral badges);
      • an excerpt of up to 280 characters, clamped to two lines. truncate (lib/format.ts), which cuts it, keeps its limit in UTF-16 units: a string of max units or fewer comes back whole, which MemoryCard's cut-value mark relies on. A longer one is now cut at the last boundary between the characters a reader sees that fits, so an emoji, a flag, a skin-tone or ZWJ sequence, or a letter with a combining accent is never split. It segments lazily, with Intl.Segmenter made on first use where the browser has one, else by code point, so the module loads on any browser.
    • A failure says so in an alert; a lost connection reads through humanizeError.
    • The hits have their own row navigator (one tab stop, arrows and j/k). The arrows and j/k move through the list focus was last in, the passages or the documents, so only one of the two answers them at a time.
  • Opening a hit: in Documents.tsx, a hit and a ?doc= link open through one openByUri. It opens from the rows already loaded, or through findDocument for a document past the first page, under one abort so a newer open wins. A link to a missing document drops ?doc=; a hit whose document is gone says so in a toast.
  • Docs: the Library row of docs/features/dashboard.md, the dashboard link in docs/features/knowledge.md, and the disclosure line of docs/development/dashboard-design.md.

Alternatives considered:

  • Turning the Library's existing title filter into a passage search. It filters the list by name and tag as people expect, so the two are kept apart.
  • Showing the hits inside the document preview with the passage highlighted. That is a larger change to the preview, and the citation already says where to look.

Scope and risk

  • Dashboard only. The op, knowledge.search, is unchanged, and the reach manifest already counts the dashboard's calls to it.
  • The panel is folded by default, so the Library loads nothing more until someone opens it, and the list starts where it did.
  • knowledge.search has no cursor, so each Show more runs the whole search again with a larger top_k: another query embedding and, where the deployment's default reranker is a provider's, another reranker call, up to nine per query. The hits already shown can reorder with it.

Compatibility, rollout and rollback

  • Older server: a server that predates revisions and locators sends hits without those fields. KnowledgeHit types them as optional, and such a hit shows its document and excerpt with no citation.
  • Rollback: reverting removes the panel.

Tests

  • Unit, frontend/src/api/knowledge.test.ts: searchKnowledge posts to knowledge.search with the namespace shown, the hits asked and namespace_scope: "this", and answers its results.
  • Unit, frontend/src/lib/locator.test.ts:
    • lines (one and a range), a TOML key, a PDF's pages, a deck's slides, a sheet's rows and a CSV's row;
    • nothing for a hit with no locator;
    • the citation with a revision and a place, either alone, and neither.
  • Unit, frontend/src/views/LibraryPassages.test.tsx:
    • the hint describes the field, the field takes the focus when the panel opens, and the status line is there before any search;
    • a search still running when the panel goes is aborted, and the hits on screen are marked busy while a new search runs;
    • a long excerpt is cut between characters;
    • a full page reads "The best 10 passages", and a single hit "The best passage". From six hits for ten, Show more asks for 20 of the query searched (not text typed since), and goes once a read adds none, focusing the last hit; at the hundred it goes, the count still says "The best 100 passages" and focus is on the first hit the last read added; a failed Show more keeps the hits and the button;
    • a hit shaped like an older server's renders uncited;
    • a search in the namespace shown, with its count, each hit cited ("revision 3, page 7", "revision 1, key retention.days") with its section, matched keys and excerpt, and no axe violations;
    • a hit opens its document, and folding the panel hands the row keys back;
    • no match and a dropped connection each say so.
  • Unit, frontend/src/views/Documents.url.test.tsx: in the Library:
    • the toggle is folded until pressed, then names the panel it controls; a passage is cited and opens its document's preview, writing ?doc=;
    • a passage in a document past the first page reads that document and opens it;
    • a passage whose document is gone says so and opens nothing;
    • with hits shown, the arrows and j move through the passages while focus is there, and through the documents once focus moves to a document row (the test fails with the hand-off removed);
    • another namespace folds the panel, a later failed read of the list keeps the panel and its hits, a list that failed to load shows none, an empty library with a tag filter typed shows no toggle, and a library that became empty (an unfiltered read finding none after a filtered one) takes the panel away, keeps it away when a tag typed then finds nothing, and with a document back shows the toggle folded (the test fails without either fix).
  • npm --prefix frontend run test (1,914), run build, run budget and make lint (Biome's accessibility rules included) pass. Playwright: the full run on the rebased head passed 496 of 497. The one failure, /admin/users timing out before its heading appeared, passed alone, together with the list specs (93 passed). With E2E_PORT=<port> npm --prefix frontend run e2e -- e2e/list-pages.spec.ts, the list-pages layout budget (first row at or above y = 300 on a desktop, 360 on a phone) failed with the panel's own toggle row (335 and 427) and passes with the toggle in the toolbar.
  • Full unit suite: run on the rebased head before the merge.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. Checked: the locator wording against the server's Locator fields, the panel and the open path in the tests above, and a review at every push.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 8 commits November 6, 2026 09:13
…nd place

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…th and its row keys

Hits from a server without revisions and locators render uncited. A passage
and a ?doc= link open through one openByUri. Find is a BusyButton, hits are
ListRows with their own row navigator that takes over from the list while
they show, the panel mounts on a non-empty library keyed by place, and a full
page says it is the best ten.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… a failed list

The passages and the document list each keep their row keys while focus is in
them, the count line alone is announced, matched keys are neutral chips, the
panel is not shown above a list that failed to load, and the hit count's
default lives in one constant.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…n leaving

The panel shows once the place's list has loaded and stays through a later
failed read. A hit shows its whole source address beside its file name and a
two-line excerpt. A search still running when the panel goes is aborted, the
hint says library, and searchKnowledge takes its hit count from the caller.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…tanding status line

The folded panel took a row of its own, which pushed the first document below
the list pages' layout budget; its toggle now sits in the toolbar (on a phone,
beside the sort), with aria-expanded and aria-controls. The count is one
role=status line present from the start, the hint says a tag filter does not
narrow the search and describes the field, an excerpt is cut by code point,
and the deep-link effect lists the place it checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…its state

A hit's open button is named by its source and citation with the excerpt as
its description, the hit list is busy while a new search runs, the toggle
carries a chevron, the form no longer repeats the region's name, the toggle
waits for this place's rows, and truncate cuts by code point for every caller.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…e their own block

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…heme

listedScope clears on a new place, so a return visit whose read fails shows no
toggle; the place effect folds the panel; truncate cuts between graphemes (a
flag, a skin tone, a ZWJ sequence stay whole); tests pin j/k routing and the
busy hit list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the feat/library-search-locators branch from d532cd4 to d905800 Compare November 6, 2026 09:15
zlareb1 and others added 17 commits November 6, 2026 09:21
A tag filter typed into an empty library no longer brings it up. passagesShown
is passageHitsShown, after the prop that sets it, and truncate's accented-letter
case is tested.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… per answer

Show more asks for ten more of the query that was searched, up to the hundred
knowledge.search lists. The hit list is memoised over the answer with a stable
open, so a keystroke in the field renders only the field. A library that became
empty takes the panel away, and its comment says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…loads anywhere

The segmenter is made on first use where the browser has one, else truncate cuts
by code point, and collectionLabel uses it. The last Show more focuses the first
hit it added; a failed one leaves the hits and the button beside the alert; a key
the citation already names is not listed as matched again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… boundary

A string of max units or fewer comes back whole again, so a card value one unit
over its limit is still marked cut; the cut steps back to the last whole
grapheme that fits, segmenting lazily. collectionLabel keeps its own character
count. The passage toggle carries its chevron as Code's Advanced toggle does,
and the design guide names that form.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… wherever it sits

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
knowledge.search keeps one hit per section, so an answer shorter than asked is
no sign that nothing is left: the count reads as the best N while more may
exist, and Show more goes once a read adds none or the op's hundred is reached.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The wording follows whether a read has added nothing, not whether Show more is
offered, so a list cut at the cap is not called complete. The knowledge page's
link to the dashboard names finding a passage.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The test pins the namespace_scope the panel depends on, the hits asked and the
answer read. Two comments name the passage panel beside the deep link, and the
note on kept hits sits on the catch that keeps them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The toggle sits in a toolbar that stays at the top as the list scrolls; without
the focus, a panel opened low in the list opened out of sight.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
A library that became empty kept its scope, so a tag typed into it brought the
toggle back over a namespace with nothing to search.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…identity

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 662629c into main Nov 6, 2026
22 of 24 checks passed
@zlareb1
zlareb1 deleted the feat/library-search-locators branch November 6, 2026 12:41
@zlareb1 zlareb1 mentioned this pull request Nov 12, 2026
3 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant