Server: chat:<id>-scoped find-in-chat search returning every occurrence, paged

A kind=chat search with scope chat:<id> returns one hit per text-part
occurrence (message id, part, UTF-16 offset/length), newest message first,
paged by cursor (a reply's next_cursor or a chat_messages next_cursor), with
optional case-sensitive matching. Scoped and global chat searches no longer
cancel each other on one connection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 00:25:09 +00:00
parent accb9970b6
commit 32c9c6b1df
5 changed files with 399 additions and 3 deletions
+11 -3
View File
@@ -285,8 +285,11 @@ func HandlerWithOptions(ctx context.Context, options Options, stores ...*pipelin
// A chat search runs beside the read loop so its transcript readback
// never delays the run search sent with it; a newer one cancels the
// previous, whose reply the client would discard as stale anyway.
// A newer chat search replaces an older one of the same mode: the
// chat list's search and a find-in-chat search never cancel each other.
cancelChatSearch := func() {}
defer func() { cancelChatSearch() }()
cancelScopedChatSearch := func() {}
defer func() { cancelChatSearch(); cancelScopedChatSearch() }()
// Keystrokes and sizes take their own lane (terminal_lane.go), so
// they never wait behind a slow request read before them. The lane
// is drained before the deferred detaches above run.
@@ -312,9 +315,14 @@ func HandlerWithOptions(ctx context.Context, options Options, stores ...*pipelin
continue
}
if isChatSearch(request) {
cancelChatSearch()
searchCtx, cancel := context.WithCancel(connCtx)
cancelChatSearch = cancel
if scopedChatSession(*request.Search) != "" {
cancelScopedChatSearch()
cancelScopedChatSearch = cancel
} else {
cancelChatSearch()
cancelChatSearch = cancel
}
go func(request protocol.Message) {
defer cancel()
_ = write(chatSearchReply(searchCtx, request, options.Chat, registry))