Skip to content

feat(sessions): add structured local history search - #1

Open
ivanmilevtues wants to merge 1 commit into
mainfrom
feat/structured-session-search
Open

ivanmilevtues wants to merge 1 commit into
mainfrom
feat/structured-session-search

Conversation

@ivanmilevtues

Copy link
Copy Markdown
Member

Session history can now be narrowed with queries such as:

grok sessions search 'title:retry content:"rate limit" -title:archived'

Previously, the local index stripped punctuation and searched word prefixes, so phrases, field constraints, and exclusions could not be expressed. This change extracts query parsing and match planning from SQLite into a shared SessionQuery module. Plain keywords retain the existing AND-then-OR fallback; explicit syntax stays strict. BM25 ranking, snippets, workspace scoping, pagination, and session-ID lookup are preserved.

The CLI automatically routes structured queries to the local index, adds --local for ordinary keywords, and skips authentication refresh for local searches. The native picker uses verified deep-search hits for structured queries so literal title matches cannot bypass content constraints. The ACP extension uses the same query engine.

Useful paths to explore in CodeBoarding:

  • xai-grok-session-search/src/fts.rs → new query.rs: parsing and strict/relaxed match plans.
  • xai-grok-shell/src/session/storage/search.rs → shared query contract exported to consumers.
  • xai-grok-pager/src/sessions_cmd.rs → query-aware local/remote routing.
  • xai-grok-pager/src/views/session_picker.rs → structured-query result filtering.

Includes parser tests, real SQLite coverage for phrases/scopes/exclusions and pagination, a cold-bootstrap async integration test, picker regressions, and user documentation.

This is a CodeBoarding architecture-diff demonstration PR, similar in scope to the Pi showcase, and is not intended to merge.

Validation:

  • cargo test -p xai-grok-session-search: 80 tests pass.
  • cargo test -p xai-grok-pager --lib views::session_picker::tests::: 33 tests pass.
  • cargo check -p xai-grok-pager --lib: passes.
  • cargo clippy -p xai-grok-session-search --all-targets -- -D warnings: passes.
  • Formatting checks for the three affected crates pass.

The broader cargo check -p xai-grok-pager --tests is blocked by the existing registered_features_are_documented integration test: it includes docs/internal/25-enterprise.md and docs/internal/22-environment-variables.md, neither of which is present in the baseline export. No placeholder documents or unrelated test changes were added.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T10:27:30.439120Z 949f1a9 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Copy link
Copy Markdown

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: 949f1a95b4

ℹ️ 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 on lines +419 to +422
if !source_filter.is_content_search_disabled()
&& xai_grok_shell::session::storage::search::SessionQuery::parse(query).is_structured()
{
return vec![];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve foreign literal matches on the All page

When the picker is on SourceFilter::All, this early return suppresses foreign entries as well as native ones because is_content_search_disabled() is true only for External. For example, a Codex session titled title:rust notes previously matched title:rust on the All page but now disappears. Foreign histories are not FTS-indexed, so deep-search results cannot restore it. Apply structured-query suppression per entry to native sources while retaining literal matching for foreign entries.

Useful? React with 👍 / 👎.

Comment on lines +462 to +463
let plan = SessionQuery::parse(query);
let Some(primary) = plan.primary_match() else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Check structured syntax before taking the session-ID shortcut

A negative-only hexadecimal query can return precisely the session it appears to exclude. For example, -deadbeef passes is_session_id_like() because that helper strips hyphens, and query_session_id() returns a session such as 12345678-1234-1234-1234-deadbeef0000 before this parser runs. This violates the new negative-only query contract through both CLI and ACP search. Parse before the ID shortcut and restrict that shortcut to unstructured queries.

Useful? React with 👍 / 👎.

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