Skip to content

[codex] Add chat filters to search queries#559

Merged
axisrow merged 2 commits into
mainfrom
codex/search-query-chat-filter
May 11, 2026
Merged

[codex] Add chat filters to search queries#559
axisrow merged 2 commits into
mainfrom
codex/search-query-chat-filter

Conversation

@axisrow
Copy link
Copy Markdown
Owner

@axisrow axisrow commented May 10, 2026

What changed

  • Added an optional chat filter to search queries so a query can target one or more chats instead of always matching all chats.
  • Reused the same parser/validation path across web, CLI, agent tools, repository matching, notification matching, and search-query bundles.
  • Added schema/migration/model support for chat_filter and tests covering valid filters, validation errors, persistence, search matching, and notifications.
  • Fixed Telegram preview links like https://t.me/s/<channel> so they resolve to the real channel instead of s.

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.py
  • pytest tests/test_search_queries.py tests/test_notification_matcher.py -v: 43 passed
  • pytest tests/ -v -m "not aiosqlite_serial" -n auto: 6947 passed, 2 skipped
  • pytest tests/ -v -m aiosqlite_serial: 821 passed

Copy link
Copy Markdown
Owner Author

axisrow commented May 10, 2026

@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.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/utils/search_query_chat_filter.py
Copy link
Copy Markdown
Owner Author

axisrow commented May 10, 2026

@codex review. Follow-up after fixing the /s/ Telegram preview-link handling in chat filters. 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.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

ℹ️ 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".

@axisrow axisrow marked this pull request as ready for review May 11, 2026 02:31
Copilot AI review requested due to automatic review settings May 11, 2026 02:31
@axisrow axisrow merged commit a73d2f1 into main May 11, 2026
6 of 8 checks passed
@axisrow axisrow deleted the codex/search-query-chat-filter branch May 11, 2026 02:32
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_filter on SearchQuery with 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.

Comment on lines +92 to +96
channels_by_username = {
(ch.username or "").lower(): ch
for ch in channels
if ch.username
}
Comment on lines +97 to +105
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
]
Comment thread src/telegram/collector.py
Comment on lines +1139 to +1148
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)
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.

2 participants