Skip to content

feat(peek): full-text/faceted session search (search_sessions + peek sessions search)#139

Merged
harry-harish merged 8 commits into
mainfrom
feat/peek-session-search
Jul 2, 2026
Merged

feat(peek): full-text/faceted session search (search_sessions + peek sessions search)#139
harry-harish merged 8 commits into
mainfrom
feat/peek-session-search

Conversation

@harry-harish

@harry-harish harry-harish commented Jul 2, 2026

Copy link
Copy Markdown
Member

Summary

Turns peek's durable local session store from a haystack into a queryable archive — you can now find "the session on app.acme.com last week that had console errors" instead of scrolling recency-ordered lists.

  • search_sessions (new, 18th MCP tool, read-only): match session title/URL/origin (free-text q) + facets — exact origin, recorded date range (createdAfter/createdBefore), status, hasConsoleErrors, hasNetworkErrors. Returns the same compact rows as list_recent_sessions (nothing new enters LLM context) and honors the same roots soft-scope.
  • peek sessions search (new CLI): --q --origin --since --until --status --errors console|network|any --limit --json, table + JSON output like sessions list.

How it's built

A searchSessions query in each package (mirroring the existing listRecentSessions / listSessionsWithCounts split), pure parameterized SELECT with AND-combined WHERE clauses. LIKE-based, no FTS5 (per the grounding) → no schema change, native host stays sole index writer (ADR-0007). LIKE wildcards escaped via escapeLike + ESCAPE '\'.

Guardrails

Read-only (SELECT only); no new egress/telemetry; fully parameterized (injection-safe); MCP tool returns the list_recent_sessions row shape + honors rootsScope; searches session metadata only — not page content or error-message text.

Docs ripple (18th tool)

Skill 17→18 + search_sessions entry, re-copied to the plugin (byte-identical; check-plugin enforces), peek-mcp/peek-cli READMEs + count sweep, new recipe find-a-past-session-by-what-happened.

Test plan

  • peek-mcp 401 + peek-cli 253 tests pass (searchSessions matrix per facet + q wildcard-escape + _/% literal + facet-AND intersection + roots-scope on the tool)
  • full recursive pnpm test + build + lint + typecheck green
  • verify-recipes (STRICT, 21/21) + verify:plugin + claude plugin validate ./plugins/peek pass; plugin SKILL.md byte-identical
  • After merge: manual peek-docs Vercel redeploy (new recipe + counts)

Changesets: @peekdev/mcp minor + @peekdev/cli minor.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added session search across the CLI, MCP toolset, and documentation.
    • Users can now find past sessions by text, origin, date range, status, and error presence.
    • Search results can be shown in a table or returned as JSON for scripting.
  • Documentation

    • Updated guides and references to include the new search command/tool.
    • Clarified that the toolset now includes 18 tools.

harry-harish and others added 7 commits July 2, 2026 11:47
Add escapeLike helper and searchSessions function to queries.ts, with a
SearchSessionsOptions interface extending ListSessionsOptions. Supports
filtering by full-text q (LIKE on title/url/origin), origin exact match,
created_at date range, status, hasConsoleErrors, and hasNetworkErrors.
All 9 unit tests pass; typecheck and biome lint clean.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: harry-harish <22562634+harry-harish@users.noreply.github.com>
Signed-off-by: harry-harish <22562634+harry-harish@users.noreply.github.com>
Signed-off-by: harry-harish <22562634+harry-harish@users.noreply.github.com>
Signed-off-by: harry-harish <22562634+harry-harish@users.noreply.github.com>
… + AND-semantics (review)

Signed-off-by: harry-harish <22562634+harry-harish@users.noreply.github.com>
Signed-off-by: harry-harish <22562634+harry-harish@users.noreply.github.com>
…unt (review)

Signed-off-by: harry-harish <22562634+harry-harish@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@harry-harish, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 35 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0c12f61f-3ea9-4c0d-a5ed-399c6f5aa573

📥 Commits

Reviewing files that changed from the base of the PR and between 0b534c0 and 87e9668.

📒 Files selected for processing (20)
  • .changeset/peek-search-sessions-mcp.md
  • .changeset/peek-sessions-search-cli.md
  • apps/peek-docs/src/content/recipes/find-a-past-session-by-what-happened.md
  • apps/peek-docs/src/content/recipes/set-up-peek-with-claude-code.md
  • apps/peek-docs/src/content/recipes/using-peek-with-your-agent.md
  • packages/peek-cli/README.md
  • packages/peek-cli/skills/peek-skill.md
  • packages/peek-cli/src/commands/sessions.ts
  • packages/peek-cli/src/lib/db.ts
  • packages/peek-cli/test/search-sessions.test.ts
  • packages/peek-cli/test/sessions-search.test.ts
  • packages/peek-mcp/README.md
  • packages/peek-mcp/src/mcp/queries.ts
  • packages/peek-mcp/src/mcp/server.ts
  • packages/peek-mcp/test/search-sessions-tool.test.ts
  • packages/peek-mcp/test/search-sessions.test.ts
  • packages/peek-mcp/test/server.test.ts
  • packages/peek-mcp/test/stdio-smoke.test.ts
  • plugins/peek/README.md
  • plugins/peek/skills/peek/SKILL.md
📝 Walkthrough

Walkthrough

This PR adds a new read-only search_sessions capability to both the MCP server and the CLI, allowing sessions to be found by text query, origin, date range, status, and console/network error facets. Supporting query builders, a new CLI sessions search command, tests, and documentation (17→18 tools) are included.

Changes

search_sessions feature

Layer / File(s) Summary
MCP query and tool implementation
packages/peek-mcp/src/mcp/queries.ts, packages/peek-mcp/src/mcp/server.ts, packages/peek-mcp/test/search-sessions.test.ts, packages/peek-mcp/test/search-sessions-tool.test.ts, packages/peek-mcp/test/server.test.ts, packages/peek-mcp/test/stdio-smoke.test.ts
Adds escapeLike, SearchSessionsOptions, and searchSessions query builder; registers search_sessions MCP tool with roots-scope origin filtering and field clipping; updates PEEK_MCP_TOOLS and test expectations to 18 tools.
CLI search db function and command
packages/peek-cli/src/lib/db.ts, packages/peek-cli/src/commands/sessions.ts, packages/peek-cli/test/search-sessions.test.ts, packages/peek-cli/test/sessions-search.test.ts
Adds escapeLike/SearchSessionsOptions/searchSessions to the CLI db layer and implements peek sessions search with --q/--origin/--since/--until/--status/--errors/--limit/--json flags, JSON/table output, and validation, with tests covering filtering, ordering, and CLI error handling.
Documentation and changesets
.changeset/*, apps/peek-docs/src/content/recipes/*, packages/peek-cli/README.md, packages/peek-cli/skills/peek-skill.md, packages/peek-mcp/README.md, plugins/peek/README.md, plugins/peek/skills/peek/SKILL.md
Adds a new recipe on finding sessions via search_sessions/peek sessions search, adds Changesets entries for minor bumps, and updates tool-count references from 17 to 18 tools across READMEs and skill docs.

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

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant PeekMcpServer
  participant searchSessions
  participant SQLiteDB
  Client->>PeekMcpServer: call search_sessions(q, origin, filters)
  PeekMcpServer->>searchSessions: searchSessions(db, options)
  searchSessions->>SQLiteDB: parameterized SELECT with LIKE/EXISTS filters
  SQLiteDB-->>searchSessions: matching session rows
  searchSessions-->>PeekMcpServer: SessionSummaryRow[]
  PeekMcpServer-->>Client: clipped JSON rows
Loading
sequenceDiagram
  participant User
  participant runSessions
  participant runSearch
  participant searchSessions
  participant SQLiteDB
  User->>runSessions: peek sessions search --q ... --json
  runSessions->>runSearch: dispatch case 'search'
  runSearch->>searchSessions: searchSessions(db, options)
  searchSessions->>SQLiteDB: parameterized query
  SQLiteDB-->>searchSessions: session rows
  searchSessions-->>runSearch: SessionRowWithCounts[]
  runSearch-->>User: JSON or table output
Loading

Possibly related PRs

  • Cubenest/rrweb-stack#133: Both PRs update packages/peek-cli/skills/peek-skill.md to adjust the documented MCP tool count and read-tool permission wording.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding faceted session search to MCP and CLI.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/peek-session-search

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

Comment @coderabbitai help to get the list of available commands.

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
packages/peek-mcp/test/search-sessions-tool.test.ts (1)

156-214: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Test doesn't actually exercise roots-scope filtering through search_sessions.

The test title claims it "filters out sessions from origins not in allowedOrigins via refreshRootsScope," but the assertions only verify resolveRootsScope's derivation in isolation (Line 190-191) and that both sessions are returned when no scope is applied to the real server (Line 198, unscoped). The peek server instance's internal rootsScope is never actually set to the fake scope, so the end-to-end filtering path inside search_sessions (Lines 364-369 in server.ts) is not covered here — only the explicit-origin-bypasses-scope behavior is. Given peek's soft-scope is a permission-adjacent boundary, a misleading test name risks false confidence that this path is covered by this file.

Consider renaming the test to reflect what it actually verifies (scope derivation + explicit-origin bypass), and pointing more explicitly to roots.test.ts for the actual end-to-end filter assertion, or finding a way to inject the scope into the peek instance under test.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/peek-mcp/test/search-sessions-tool.test.ts` around lines 156 - 214,
The test currently does not exercise the real roots-scope filtering path in
search_sessions; it only verifies resolveRootsScope derivation and the explicit
origin bypass. Update the test in search-sessions-tool.test.ts to either inject
the fake scope into the actual peek server instance so search_sessions runs with
rootsScope applied, or rename/reframe the test to match what it truly covers.
Use resolveRootsScope, refreshRootsScope, and search_sessions to locate the
relevant setup and assertions.
packages/peek-mcp/src/mcp/server.ts (1)

315-322: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Validate createdAfter / createdBefore as datetimes. These filters are accepted as plain strings, so bad timestamps just turn into empty result sets. created_at is written with new Date().toISOString(), so z.string().datetime() fits; use offset: true only if non-Z inputs should be accepted too.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/peek-mcp/src/mcp/server.ts` around lines 315 - 322, The
`createdAfter` and `createdBefore` filter definitions in `server.ts` currently
accept any string, so invalid timestamps slip through silently; update the
schema in the relevant MCP input object to use datetime validation on these
fields, matching the `created_at` ISO-8601 format produced elsewhere. Use the
existing `zod` definitions for `createdAfter` / `createdBefore` and switch from
plain `z.string()` to datetime-aware validation, adding `offset: true` only if
you want to accept non-`Z` offsets.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/peek-cli/src/commands/sessions.ts`:
- Around line 109-131: `resolveTime` in sessions.ts currently passes through any
non-duration string without validating it, so bad `--since`/`--until` values can
silently produce empty searches. Update `resolveTime` to reject invalid literal
timestamps by validating the fallback value as ISO before returning it, and keep
the duration parsing behavior via `cutoffBefore`. Then wrap the `resolveTime`
usage inside `runSearch` in a try/catch so invalid input writes a clear stderr
message and exits with status 1, consistent with the existing
`--status`/`--errors`/`--limit` validation paths.

In `@packages/peek-cli/test/sessions-search.test.ts`:
- Around line 49-53: The teardown in sessions-search.test should fully unset
PEEK_HOME when origHome was undefined instead of assigning an empty string.
Update the afterEach cleanup to use Reflect.deleteProperty(process.env,
'PEEK_HOME') in that branch, and keep restoring the original value otherwise, so
the test state is truly reset.

---

Nitpick comments:
In `@packages/peek-mcp/src/mcp/server.ts`:
- Around line 315-322: The `createdAfter` and `createdBefore` filter definitions
in `server.ts` currently accept any string, so invalid timestamps slip through
silently; update the schema in the relevant MCP input object to use datetime
validation on these fields, matching the `created_at` ISO-8601 format produced
elsewhere. Use the existing `zod` definitions for `createdAfter` /
`createdBefore` and switch from plain `z.string()` to datetime-aware validation,
adding `offset: true` only if you want to accept non-`Z` offsets.

In `@packages/peek-mcp/test/search-sessions-tool.test.ts`:
- Around line 156-214: The test currently does not exercise the real roots-scope
filtering path in search_sessions; it only verifies resolveRootsScope derivation
and the explicit origin bypass. Update the test in search-sessions-tool.test.ts
to either inject the fake scope into the actual peek server instance so
search_sessions runs with rootsScope applied, or rename/reframe the test to
match what it truly covers. Use resolveRootsScope, refreshRootsScope, and
search_sessions to locate the relevant setup and assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 04b50368-8de6-42ac-b071-e3d2d5310570

📥 Commits

Reviewing files that changed from the base of the PR and between 0b534c0 and 880a6ee.

📒 Files selected for processing (20)
  • .changeset/peek-search-sessions-mcp.md
  • .changeset/peek-sessions-search-cli.md
  • apps/peek-docs/src/content/recipes/find-a-past-session-by-what-happened.md
  • apps/peek-docs/src/content/recipes/set-up-peek-with-claude-code.md
  • apps/peek-docs/src/content/recipes/using-peek-with-your-agent.md
  • packages/peek-cli/README.md
  • packages/peek-cli/skills/peek-skill.md
  • packages/peek-cli/src/commands/sessions.ts
  • packages/peek-cli/src/lib/db.ts
  • packages/peek-cli/test/search-sessions.test.ts
  • packages/peek-cli/test/sessions-search.test.ts
  • packages/peek-mcp/README.md
  • packages/peek-mcp/src/mcp/queries.ts
  • packages/peek-mcp/src/mcp/server.ts
  • packages/peek-mcp/test/search-sessions-tool.test.ts
  • packages/peek-mcp/test/search-sessions.test.ts
  • packages/peek-mcp/test/server.test.ts
  • packages/peek-mcp/test/stdio-smoke.test.ts
  • plugins/peek/README.md
  • plugins/peek/skills/peek/SKILL.md

Comment thread packages/peek-cli/src/commands/sessions.ts
Comment thread packages/peek-cli/test/sessions-search.test.ts
…eanly (CodeRabbit)

Signed-off-by: harry-harish <22562634+harry-harish@users.noreply.github.com>
@harry-harish harry-harish merged commit 679d3cf into main Jul 2, 2026
7 checks passed
@harry-harish harry-harish deleted the feat/peek-session-search branch July 2, 2026 07:18
@harry-harish

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

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