Repository navigation
feat(sidebar): list each search result's matches and find them in the chat #369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
andrebrait
merged 10 commits into
ompweb-dev:main
from
andrebrait:feat/session-search-matches
Nov 2, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5c93108
feat(sidebar): list each search result's matches and find them in the…
andrebrait 260b514
fix(sidebar): drop stale search jumps and page matches by ranked prefix
andrebrait 34364d8
fix(sidebar): end the current hit on any query change; phrases stop a…
andrebrait 1a91fb2
fix(sidebar): skip table charts when counting chat hits; centre the h…
andrebrait 2cf4216
fix(sidebar): skip code line numbers and Mermaid notes when counting …
andrebrait 1461d31
fix(sidebar): skip generated footnote labels when counting chat hits
andrebrait 3e3a6aa
fix(sidebar): count hits like the chat across hard breaks and footnot…
andrebrait 3447742
fix(sidebar): keep footnote-looking text inside code as chat hits
andrebrait 61cf478
perf(sidebar): mask footnote syntax in one linear pass
andrebrait 8bd026c
fix(sidebar): count search hits in the rendered text, as the chat does
andrebrait File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { apiErrorResponse, opErrorResponse, resolveSessionHostOr404 } from "@/lib/api-utils"; | ||
| import { listSessionMatches } from "@/lib/session-match-listing"; | ||
| import { MAX_SEARCH_MATCHES, SEARCH_MATCH_PAGE_SIZE } from "@/lib/session-search-matches"; | ||
| import type { SessionContext } from "@/lib/types"; | ||
|
|
||
| const MAX_QUERY_LENGTH = 500; | ||
|
|
||
| // GET /api/sessions/[id]/matches?q=&limit= — the query's best `limit` hits in the | ||
| // session's active conversation (what the chat shows), best match first. "Load more" | ||
| // asks for a longer prefix rather than the next offset: a running session re-ranks | ||
| // between requests, and an offset would then repeat or skip hits. | ||
| // shortcut: re-reads and re-ranks the whole session per request; cache per (session, query) if that gets slow. | ||
| export async function GET(req: Request, { params }: { params: Promise<{ id: string }> }) { | ||
| const { id } = await params; | ||
| const url = new URL(req.url); | ||
| const q = url.searchParams.get("q") ?? ""; | ||
| if (q.length > MAX_QUERY_LENGTH) { | ||
| return Response.json({ error: "Query too long", code: "query_too_long" }, { status: 400 }); | ||
| } | ||
| const rawLimit = url.searchParams.get("limit") ?? String(SEARCH_MATCH_PAGE_SIZE); | ||
| const limit = Number(rawLimit); | ||
| if (!/^[1-9]\d{0,3}$/.test(rawLimit) || limit > MAX_SEARCH_MATCHES) { | ||
| return Response.json({ error: "Invalid limit", code: "invalid_limit" }, { status: 400 }); | ||
| } | ||
| try { | ||
| const resolved = await resolveSessionHostOr404(id); | ||
| if ("response" in resolved) return resolved.response; | ||
| const result = await resolved.host.sessionOps.readContext(id, undefined, { | ||
| deferThinking: true, | ||
| deferMedia: true, | ||
| includePreCompaction: false, | ||
| boundary: false, | ||
| sync: null, | ||
| }); | ||
| if (!result.ok) return opErrorResponse(result); | ||
| const { context } = result.value as { context: SessionContext }; | ||
| return Response.json(listSessionMatches(context.messages, context.entryIds, q, limit), { headers: { "Cache-Control": "no-store" } }); | ||
| } catch (error) { | ||
| return apiErrorResponse(error); | ||
| } | ||
| } |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.