feat: sessions search --source/--limit/--after filters (Task 2.6.2 completion) #19
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem Statement
Task 2.6.2 of
terraphim-agent-session-search-tasks.mdrequires/sessions searchto support query + source filter + result display, but the currentSessionsSubcommand::Searchincrates/terraphim_agent/src/repl/commands.rsonly accepts a singlequery: Stringwith no way to narrow results by connector (Claude / Cursor / Aider / Cline), cap the number of results for an LLM-friendly response, or filter by recency. This forces callers to pipe through external tools or read-all-and-filter, defeating the purpose of an indexed session store for agent workflows.This complements #14 (
/sessions import --source/--sincefor ingestion) by delivering the equivalent read-path filters needed for--robotmode consumers.Acceptance Criteria
/sessions search "<query>"accepts--source <claude|cursor|aider|cline>(repeatable or comma-separated) to filter by connector source_id--limit <N>caps the number of returned sessions (default 20; hard max 200)--after <ISO-date|duration>filters to sessions with activity after that point (--after 7dor--after 2026-01-01)--before <ISO-date|duration>symmetric upper bound--robotor--format jsonis active, output flows through the existing RobotOutput envelope and includes afilters_appliedfield so agents can echo the effective query/sessions search <query>behaviour unchanged (flags are additive)cargo test -p terraphim_agent sessionspassescargo test -p terraphim_sessionspassescargo clippy -p terraphim_agent -p terraphim_sessions -- -D warningspassesProposed Approach
SessionsSubcommand::Searchincrates/terraphim_agent/src/repl/commands.rsfromSearch { query: String }toSearch { query: String, sources: Vec<String>, limit: Option<usize>, after: Option<String>, before: Option<String> }. TeachForgivingParserto accept the new flags (aliases already handle--source).crates/terraphim_sessions/src/search.rs, add aSearchOptions { sources, limit, after, before }struct and an overload (or extra method) onSessionService::search_sessionsthat applies the filters after the Tantivy query (or push down into the TantivyBooleanQueryif index is active — otherwise post-filter on the cachedSessionlist).crates/terraphim_agent/src/repl/handler.rsincluding--robotJSON output that includesfilters_applied.parse_relative_or_iso(&str) -> Result<DateTime<Utc>>helper interraphim_sessions::search(reuses chrono; supportsNd/Nw/Nm/Nyand ISO-8601).Affected crates:
terraphim_agent,terraphim_sessions. No changes to connectors. No index schema changes (filters operate on already-indexed metadata).Dependencies
None strictly blocking. Related but independent from #14 (import filters) and #5 (Tantivy index build). Works against the current in-memory cache even without Tantivy, and will transparently use Tantivy once #5 merges.
Verification
Scope
~250 lines across the two crates (enum widening + options struct + handler wiring + parser updates + ~7 tests). Single PR. Additive; preserves existing command ergonomics.