feat: robot meta concepts_matched and wildcard_fallback fields (F1.1) #21
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 F1.1 (terraphim-agent-session-search-spec.md, lines 482-509) shows the canonical robot-mode search response with
meta.concepts_matched(array of matched KG concepts) andmeta.wildcard_fallback(boolean indicating that the query fell back to a wildcard expansion). These are how an LLM caller learns why it got the results it did and whether to refine the query. The currentResponseMetaincrates/terraphim_agent/src/robot/schema.rs(lines 63-82) exposes onlycommand,elapsed_ms,timestamp,version,auto_corrected,pagination, andtoken_budget. Neitherconcepts_matchednorwildcard_fallbackis populated anywhere, so robot-mode search consumers cannot perform the spec'd intent inspection.Acceptance Criteria
ResponseMeta:concepts_matched: Option<Vec<String>>(skip when None)wildcard_fallback: Option<bool>(skip when None)with_concepts_matched(Vec<String>)andwith_wildcard_fallback(bool)crates/terraphim_agent/src/repl/handler.rs, search path) to populateconcepts_matchedfrom the matched-concepts list already available viaterraphim_automata::find_matchesover the role thesauruswildcard_fallback = truewhen the search result count from the primary query is zero and a wildcard/relaxed retry is executed (current behaviour likely returns an empty result -- include the field asSome(false)on the success path so consumers can rely on its presence)--robot/--format jsonis active, the JSON envelope MUST include both fields whenever the underlying search produced concept matches or attempted a fallbackcrates/terraphim_agent/src/robot/schema.rsround-trips aResponseMetawith both fields throughserde_jsoncrates/terraphim_agent/tests/(or extension of an existing robot-mode test) confirms a search response includesconcepts_matchedfor a query that matches at least one KG termcargo test -p terraphim_agentpassescargo clippy -p terraphim_agent -- -D warningspassesProposed Approach
The search path already builds a
Thesaurusfor the active role and runsfind_matchesto produce ranked results. Reuse the matched-term list as the source forconcepts_matched-- collect distinctNormalizedTermValue::display()strings, sorted by frequency. Forwildcard_fallback, add a small flag on the search return type (or thread it back via the existingSearchOutcome) and set it in the handler before constructing the envelope.Crates affected:
crates/terraphim_agent--robot/schema.rs(struct fields + builders),repl/handler.rs(population)Key types/functions to modify:
ResponseMeta-- two new optional fieldsResponseMeta::with_concepts_matched,with_wildcard_fallbackRobotResponse::success/with_contextDependencies
None. Independent of #11 (route REPL output through the formatter): #11 routes the envelope; this issue enriches its
metapayload.Verification
Manual:
Output should include
meta.concepts_matched(e.g.["async", "database"]) andmeta.wildcard_fallback(boolean).Scope
Single PR, ~120-180 LOC: two struct fields, two builder methods, one populating call site, one unit test, one integration assertion. No new dependencies.