feat(peek): full-text/faceted session search (search_sessions + peek sessions search)#139
Conversation
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>
|
Warning Review limit reached
Next review available in: 35 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (20)
📝 WalkthroughWalkthroughThis PR adds a new read-only Changessearch_sessions feature
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
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
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
packages/peek-mcp/test/search-sessions-tool.test.ts (1)
156-214: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winTest 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). Thepeekserver instance's internalrootsScopeis never actually set to the fake scope, so the end-to-end filtering path insidesearch_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.tsfor the actual end-to-end filter assertion, or finding a way to inject the scope into thepeekinstance 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 winValidate
createdAfter/createdBeforeas datetimes. These filters are accepted as plain strings, so bad timestamps just turn into empty result sets.created_atis written withnew Date().toISOString(), soz.string().datetime()fits; useoffset: trueonly if non-Zinputs 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
📒 Files selected for processing (20)
.changeset/peek-search-sessions-mcp.md.changeset/peek-sessions-search-cli.mdapps/peek-docs/src/content/recipes/find-a-past-session-by-what-happened.mdapps/peek-docs/src/content/recipes/set-up-peek-with-claude-code.mdapps/peek-docs/src/content/recipes/using-peek-with-your-agent.mdpackages/peek-cli/README.mdpackages/peek-cli/skills/peek-skill.mdpackages/peek-cli/src/commands/sessions.tspackages/peek-cli/src/lib/db.tspackages/peek-cli/test/search-sessions.test.tspackages/peek-cli/test/sessions-search.test.tspackages/peek-mcp/README.mdpackages/peek-mcp/src/mcp/queries.tspackages/peek-mcp/src/mcp/server.tspackages/peek-mcp/test/search-sessions-tool.test.tspackages/peek-mcp/test/search-sessions.test.tspackages/peek-mcp/test/server.test.tspackages/peek-mcp/test/stdio-smoke.test.tsplugins/peek/README.mdplugins/peek/skills/peek/SKILL.md
…eanly (CodeRabbit) Signed-off-by: harry-harish <22562634+harry-harish@users.noreply.github.com>
|
@coderabbitai full review |
✅ Action performedFull review finished. |
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-textq) + facets — exactorigin, recorded date range (createdAfter/createdBefore),status,hasConsoleErrors,hasNetworkErrors. Returns the same compact rows aslist_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 likesessions list.How it's built
A
searchSessionsquery in each package (mirroring the existinglistRecentSessions/listSessionsWithCountssplit), pure parameterizedSELECTwith 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 viaescapeLike+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_sessionsentry, re-copied to the plugin (byte-identical;check-pluginenforces), peek-mcp/peek-cli READMEs + count sweep, new recipefind-a-past-session-by-what-happened.Test plan
_/%literal + facet-AND intersection + roots-scope on the tool)pnpm test+ build + lint + typecheck greenverify-recipes(STRICT, 21/21) +verify:plugin+claude plugin validate ./plugins/peekpass; plugin SKILL.md byte-identicalChangesets:
@peekdev/mcpminor +@peekdev/climinor.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation