feat: /sessions by-concept with --connected-to filter (F5.2) #22
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
Spec F5.2 (terraphim-agent-session-search-spec.md, lines 432-444) defines two distinct entry points for concept-based discovery:
The repository already implements
/sessions concepts <concept>(REPLSessionsSubcommand::Conceptsincrates/terraphim_agent/src/repl/commands.rs:171) and/sessions related <id>, but neither supports the spec's--connected-to <other-concept>filter, which is the whole point of F5.2: surface sessions where two concepts co-occur, leveraging the rolegraph'sconcept_connectionsdata already produced by the enrichment pipeline (crates/terraphim_sessions/src/enrichment/). Without this filter, users cannot ask "show me sessions where OAuth is discussed alongside JWT" -- a key knowledge-graph query.Acceptance Criteria
SessionsSubcommand::ByConcept { concept: String, connected_to: Option<String>, limit: Option<usize> }parsed from/sessions by-concept "<concept>" [--connected-to "<other>"] [--limit N]SessionService::sessions_by_concept(&self, concept: &str, connected_to: Option<&str>, limit: Option<usize>) -> Vec<&Session>incrates/terraphim_sessions/src/service.rsthat:connected_to: returns sessions whoseSessionConcepts.conceptscontains the given concept (case-insensitive equality on the normalised form)connected_to: returns sessions whoseSessionConcepts.concept_connectionscontains the unordered pair(concept, connected_to)(already computed by the enricher)updated_atdesc/sessions conceptsoutput style--robot --format json) returns aRobotResponsewhosedata.results[]carries the same fields plusconcept,connected_to, and the matchingconcept_connectionslist/sessions byconcept(no hyphen) is treated as a typo and auto-corrected by the existingForgivingParser(no separate aliasing required if Jaro-Winkler covers it)crates/terraphim_sessions/src/service.rscover: (a) unfiltered concept lookup, (b)connected_tofilter with at least one match, (c)connected_tofilter with no match -> empty resultcargo test -p terraphim_sessionspassescargo test -p terraphim_agentpassescargo clippy -p terraphim_sessions -p terraphim_agent -- -D warningspassesProposed Approach
The enrichment pipeline already populates
SessionConcepts { concepts, concept_connections, dominant_topics }. The service method becomes a straightforward filter over the in-memory cache. Normalise input concepts viaNormalizedTermValue::from(...)so casing and whitespace differences do not cause misses. Reuse the existing renderer from/sessions conceptsand add a single conditional column whenconnected_tois set. For robot mode, extend the existingSessionConceptsResponse(or introduceSessionsByConceptResponsealongside it).Crates affected:
crates/terraphim_sessions--SessionServicefilter + testscrates/terraphim_agent-- REPL command parsing, handler dispatch, robot serialisationKey types/functions to add:
SessionsSubcommand::ByConceptSessionService::sessions_by_conceptrepl::handler::handle_sessions_by_conceptSessionsByConceptResponsefor robot envelopeDependencies
None. Independent of #12 (
/sessions path, concept traversal) and #16 (/sessions analyze). Builds on the already-shipped enrichment pipeline (Phase 3.1).Verification
Manual REPL:
Both should return ranked sessions; the second should only list sessions whose enrichment recorded the OAuth-JWT pair.
Scope
Single PR, ~250-350 LOC: one new service method, one new REPL subcommand variant + parser, one handler, three unit tests, one robot-mode integration assertion. No new external dependencies.