Summary
Enhance the learning capture system to annotate failed command error messages with entities from the knowledge graph using existing terraphim_automata Aho-Corasick matching. This makes learn query semantically aware -- enabling searches by entity type/label, not just raw text.
Context
- Plan:
plans/quickner-terraphim-learning-integration.md (Phase 1)
- The learning system (
terraphim_github_runner::learning) already captures FailureTracker, SuccessPattern, and ApplicableLesson records
terraphim_automata::matcher::find_matches() already provides fast Aho-Corasick matching against KG terms
- These two systems are not yet connected
Current Behaviour
learn capture records failed command + error output as plain text
learn query "pattern" does basic text matching against stored failures
- No entity-level annotation on error messages
- No ability to filter by entity type (e.g. "show all failures involving
cargo clippy" requires exact string match)
Proposed Behaviour
- When
learn capture records a failed command + error output, run terraphim_automata::find_matches() against the error text using the active role's thesaurus
- Store matched entities (term, normalised_term, positions) alongside
FailureTracker records
- Enhance
learn query to support entity-based filtering:
learn query --entity "cargo" -- find failures where "cargo" was matched as a KG entity
learn query --label "CLI Tool" -- find failures annotated with a specific entity label
- Existing plain-text
learn query "pattern" continues to work unchanged
Implementation Notes
Data Model Changes
Add to FailureTracker:
pub struct AnnotatedFailure {
// existing fields...
pub matched_entities: Vec<MatchedEntity>,
}
pub struct MatchedEntity {
pub term: String,
pub label: String, // from NormalizedTerm
pub positions: Vec<(usize, usize)>,
}
Integration Points
learn capture / learn hook: After recording failure, call find_matches(error_text, thesaurus, true) to annotate
learn query: Add --entity and --label filter flags
learn list: Optionally display matched entities alongside each entry
- Thesaurus loading: Use the command thesaurus from
learning/thesaurus.rs plus the active role's KG thesaurus
Pre-seeded Command Thesaurus
The existing learning/thesaurus.rs already contains normalised command patterns (cargo, git, npm, docker, etc.). These become the entity dictionary for annotation -- no additional KG setup required.
Acceptance Criteria
Estimated Effort
2-3 days
Relates To
- Quickner evaluation: https://github.com/terraphim/quickner (Phase 2 would use this for spaCy/CoNLL export)
- Knowledge base entry:
knowledge/external/learning-rust/quickner-fast-ner-annotator-rust.md
Summary
Enhance the learning capture system to annotate failed command error messages with entities from the knowledge graph using existing
terraphim_automataAho-Corasick matching. This makeslearn querysemantically aware -- enabling searches by entity type/label, not just raw text.Context
plans/quickner-terraphim-learning-integration.md(Phase 1)terraphim_github_runner::learning) already capturesFailureTracker,SuccessPattern, andApplicableLessonrecordsterraphim_automata::matcher::find_matches()already provides fast Aho-Corasick matching against KG termsCurrent Behaviour
learn capturerecords failed command + error output as plain textlearn query "pattern"does basic text matching against stored failurescargo clippy" requires exact string match)Proposed Behaviour
learn capturerecords a failed command + error output, runterraphim_automata::find_matches()against the error text using the active role's thesaurusFailureTrackerrecordslearn queryto support entity-based filtering:learn query --entity "cargo"-- find failures where "cargo" was matched as a KG entitylearn query --label "CLI Tool"-- find failures annotated with a specific entity labellearn query "pattern"continues to work unchangedImplementation Notes
Data Model Changes
Add to
FailureTracker:Integration Points
learn capture/learn hook: After recording failure, callfind_matches(error_text, thesaurus, true)to annotatelearn query: Add--entityand--labelfilter flagslearn list: Optionally display matched entities alongside each entrylearning/thesaurus.rsplus the active role's KG thesaurusPre-seeded Command Thesaurus
The existing
learning/thesaurus.rsalready contains normalised command patterns (cargo, git, npm, docker, etc.). These become the entity dictionary for annotation -- no additional KG setup required.Acceptance Criteria
learn captureannotates error messages with matched KG entitieslearn hook(PostToolUse integration) also annotateslearn query --entity <term>filters by matched entitylearn query --label <label>filters by entity label/typelearn query "text"behaviour unchangedlearn listshows entity annotations when presentEstimated Effort
2-3 days
Relates To
knowledge/external/learning-rust/quickner-fast-ner-annotator-rust.md