[codex] Add chat filters to search queries#559
Conversation
|
@codex review. Focus on critical issues: bugs, security vulnerabilities, logical errors, data loss risks, performance problems. Do NOT nitpick style, naming conventions, minor formatting, or subjective preferences — only flag issues that could break functionality or cause real harm in production. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 750f13b6bc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review. Follow-up after fixing the |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
There was a problem hiding this comment.
Pull request overview
Adds optional per-query chat scoping for search queries (DB + service + web/CLI/agent surfaces) so a query can match only selected chats instead of always searching across all collected content. The change centralizes parsing/validation for chat filter strings and propagates the filter into FTS stats/search and live notification matching.
Changes:
- Introduced
chat_filteronSearchQuerywith DB schema + migration + repository persistence. - Added shared chat-filter parsing/validation + applied it to FTS query constraints, web/CLI/agent UX, and notification matching.
- Added tests for filter parsing/validation behavior, persistence, FTS matching/stats scoping, and notification matching.
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_search_query_service.py | Asserts chat_filter is saved/updated via SearchQueryService. |
| tests/test_search_queries.py | Adds helpers/tests for chat-filtered FTS stats and t.me/s/... resolution. |
| tests/test_notification_matcher.py | Verifies notification matching respects chat filters (numeric/url/unknown). |
| tests/test_migrations_worker_bootstrap_paths.py | Ensures migrations add chat_filter column. |
| tests/test_cli_process_database_repository_paths.py | Ensures CLI migration path includes chat_filter column. |
| tests/test_agent_tools_search_queries.py | Ensures agent tools show chat_filter and warn on unresolved tokens. |
| tests/routes/test_search_queries_routes.py | Ensures web route saves chat_filter and emits warning redirect param. |
| tests/repositories/test_search_queries_repository.py | Covers chat_filter persistence in repository add/update. |
| tests/repositories/test_messages_repository.py | Covers FTS count/stats respecting chat_filter. |
| src/web/templates/search_queries.html | Adds chat filter input + displays filter/warnings + passes resolved channel_id to search link when unambiguous. |
| src/web/static/js/app.js | Adds support for warning flash messages from query string. |
| src/web/routes/search_queries.py | Accepts chat_filter, validates after save, and redirects with warning. |
| src/web/bootstrap.py | Wires SearchQueryBundle with channels repository. |
| src/utils/search_query_chat_filter.py | New shared parsing/validation/matching utilities for chat filters (incl. t.me/s/...). |
| src/telegram/collector.py | Passes channels list into NotificationMatcher for chat-filter evaluation. |
| src/services/search_query_service.py | Thread chat_filter through add/update + expose validation + include warnings/resolution in get_with_stats. |
| src/services/notification_matcher.py | Applies chat-filter matching before other per-query checks. |
| src/models.py | Adds chat_filter field to SearchQuery model. |
| src/database/schema.py | Adds chat_filter column to search_queries schema. |
| src/database/repositories/search_queries.py | Persists chat_filter in INSERT/UPDATE and row mapping. |
| src/database/repositories/messages.py | Adds chat-filter SQL constraints into FTS query condition builder. |
| src/database/migrations.py | Adds chat_filter column to migrations map. |
| src/database/bundles.py | Extends SearchQueryBundle to provide channels for validation/resolution. |
| src/cli/parser_domains/search_query.py | Adds --chats/--clear-chats CLI flags for chat filters. |
| src/cli/commands/search_query.py | Displays chat filter + prints warnings on add/edit/get. |
| src/agent/tools/search_queries.py | Shows chat_filter and warnings in agent tool responses; accepts chat_filter input. |
| docs/features/search.md | Documents chat filter usage in CLI and web. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| channels_by_username = { | ||
| (ch.username or "").lower(): ch | ||
| for ch in channels | ||
| if ch.username | ||
| } |
| for entry in parsed.entries: | ||
| if entry.kind == "invalid": | ||
| continue | ||
| if entry.kind == "numeric" and isinstance(entry.value, int): | ||
| matches = [ | ||
| ch | ||
| for ch in channels | ||
| if ch.channel_id == entry.value or ch.id == entry.value | ||
| ] |
| get_channels = getattr(self._db, "get_channels", None) | ||
| channels = [] | ||
| if get_channels: | ||
| import inspect | ||
|
|
||
| maybe_channels = get_channels() | ||
| channels = await maybe_channels if inspect.isawaitable(maybe_channels) else maybe_channels | ||
| if not isinstance(channels, list): | ||
| channels = [] | ||
| matcher = NotificationMatcher(self._notifier, channels=channels) |
What changed
chat_filterand tests covering valid filters, validation errors, persistence, search matching, and notifications.https://t.me/s/<channel>so they resolve to the real channel instead ofs.Behavior
Validation reports errors to the user but does not block saving/search-query execution. Invalid chat tokens are ignored for matching, preserving the requested non-blocking behavior.
Validation
ruff check src/ tests/ conftest.pypytest tests/test_search_queries.py tests/test_notification_matcher.py -v: 43 passedpytest tests/ -v -m "not aiosqlite_serial" -n auto: 6947 passed, 2 skippedpytest tests/ -v -m aiosqlite_serial: 821 passed