Skip to content

feat(cli): search past 100 results, by date and by kind of chat - #17

Merged
RealDoc06 merged 4 commits into
mainfrom
feat/search-paging
Nov 21, 2026
Merged

RealDoc06 merged 4 commits into
mainfrom
feat/search-paging

Conversation

@RealDoc06

@RealDoc06 RealDoc06 commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

An agent searching deal channels asked for -n 300 and silently got 100 results, with no way to narrow by date or by kind of chat. It ended up running ~80 per-channel searches to cover them.

tg search now pages until --limit. Global search follows Telegram's (rate, chat, ID) cursor, using next_rate or, without one, the last message's date. Search in one chat follows the last message ID. Paging stops when a page is empty, repeats the last one, or ends the exact count Telegram gave, so it never loops or takes a message twice.

New flags:

  • --since / --until: a day (counted in full), an RFC 3339 time, or an age like 7d or 12h. Telegram's date bounds leave out the second they name, so they are widened by one.
  • --kind user|group|channel: a search everywhere limited to one kind of chat, in a single request (broadcasts_only, groups_only, users_only). Bots count as users, as Telegram does not tell them apart there.

The demo backend now names the chat of each result and sorts results by date, like Telegram (visible in the before shot). guide.txt and --help cover the flags.

Proved with go test ./...: a fake MTProto invoker drives real paging (cursor, fallback rate, date bounds, kind flag, repeated page, exact count), plus parseWhen and usage error cases. go vet, gofmt, and the demo output below. Not run against a real account.

Before

search-before

After

search-after

Council review

Rounds: 4

Delegate Round 1 Round 2 Round 3 Round 4
Claude Opus 5.5 7.5/10 9/10 9.5/10 not asked
GPT 6.2 Sol 6/10 8/10 8/10 9.5/10
Gemini 4 Neon 6/10 9/10 9.5/10 not asked
Muse Wonder 1.0 no score no score no score no score

Muse Wonder was unavailable (quota exhausted). Round 4 checked the one remaining blocker. Dismissed: pacing sleeps and a --limit cap (flood waits up to 30s are already waited out, longer ones return "rate limited by Telegram, retry in Ns"), and following a new next_rate on a page that made no progress (risks paging forever).

Created with Claude Opus 5.5 in Claude Code (T3 Code); council reviews by Claude Opus 5.5, GPT 6.2 Sol and Gemini 4 Neon.

🤖 Generated with Claude Code

Note

Add date-bound and chat-kind filters to CLI search, with results past 100

  • Adds start, end, and kind flags to cli.search in cli.go. The parseWhen helper accepts calendar dates, RFC 3339 timestamps, and day/Go-duration ages; an end-bound date includes the whole day. Usage errors cover unsupported kinds, combining a kind with a specific chat, invalid dates, and reversed bounds.
  • Extends core.SearchQuery in core.go with optional start/end times and a chat-kind field.
  • Reworks mtp.backend.Search in backend.go to page through Telegram results until the limit is reached, applying date bounds (clamped to Telegram's 32-bit range) and global chat-kind filters, stopping on empty, repeated, or complete pages. Larger limits are no longer capped at one page.
  • Updates demo.Backend.Search to apply the same filters and return results with chat titles in chronological order, keeping the newest messages when the limit is exceeded.
  • Behavioral Change: searches with limits over the page size now return more results than before; nonpositive limits default to the page size.

Macroscope summarized 24cf8c7.

Summary by CodeRabbit

  • New Features
    • Search can now be narrowed by chat type: users, groups, or channels. User searches also include bots.
    • Add start and end date filters to search across chats. Date bounds support relative ages, calendar dates, and RFC 3339 timestamps; calendar end dates include the full day.
    • Search results honor the selected filters and are ordered by date.
  • Documentation
    • The search guide now includes examples and explains the available filters.

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The search command adds date-bound and chat-kind filters. Search queries carry the new options. The demo and MTProto backends apply the filters, and the MTProto backend paginates results beyond a single page.

Changes: Search filters and results

Layer / File(s) Summary
Search query and CLI options
internal/core/core.go, internal/cli/cli.go, internal/cli/cli_test.go, internal/cli/guide.txt
SearchQuery adds Since, Until, and Kind. The CLI parses and validates the options, and the tests and guide cover supported values and usage.
Filtered and paginated search
internal/demo/demo.go, internal/mtp/backend.go, internal/mtp/mtp_test.go
The demo backend filters and sorts matching messages. The MTProto backend applies date and chat-kind filters, paginates results, and stops when it reaches a completion condition. Tests cover pagination requests and stopping conditions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant SearchQuery
  participant backend.Search
  participant Telegram
  CLI->>SearchQuery: Set date bounds and chat kind
  SearchQuery->>backend.Search: Pass search query
  backend.Search->>Telegram: Send filtered search request
  Telegram-->>backend.Search: Return a page of messages
  backend.Search->>Telegram: Request next page when needed
  Telegram-->>backend.Search: Return next page
  backend.Search-->>CLI: Return collected results
Loading
Merge Risk: Low · up to 24cf8

Search can omit older matches when previously fetched messages are deleted during pagination. This narrow, read-only edge case leaves low merge risk, with a targeted correction and regression test recommended.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@macroscopeapp

macroscopeapp Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Approvability

Verdict: Approved at 24cf8c7

Macroscope's review found this PR approvable — Adds date and chat-kind filters plus pagination for searches exceeding 100 results. Default searches remain limited to 30 results, and the changes retrieve messages without modifying Telegram data or permissions.

Notes:

  • All code in this push has already been reviewed. Approvability was decided on eligibility alone.

You can add or adjust custom eligibility rules. Learn more.

macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Nov 21, 2026
RealDoc06 and others added 4 commits November 21, 2026 06:19
Search silently stopped at 100 results. It now pages until --limit:
global search with Telegram's (rate, peer, ID) cursor, search in one
chat with the last message ID, stopping when a page is empty, when no
next rate is given, or when the cursor does not move on.

--since and --until bound message dates (a day, an RFC 3339 time or an
age like 7d). --kind keeps a search everywhere to users, groups or
channels. The demo backend now names the chat of each result and sorts
them by date, like Telegram.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Check that the cursor moved before taking a page, stop at the exact
count Telegram gives, fall back to the last message's date without a
next rate, and widen Telegram's exclusive date bounds by a second.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@macroscopeapp
macroscopeapp Bot dismissed their stale review November 21, 2026 05:19

Dismissing prior approval to re-evaluate 24cf8c7

@RealDoc06
RealDoc06 merged commit c1a2983 into main Nov 21, 2026
3 of 4 checks passed
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