feat: auto-suggest correction from KG thesaurus during capture #40
Notifications
Due Date
No due date set.
Depends on
#42 feat: lesson extractor for F5.3 cross-session learning bullet 1
terraphim/agent-tasks
Reference: terraphim/agent-tasks#40
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
The learning-capture spec (
docs/specifications/learning-capture-specification-interview.md, "Auto-suggest before store") mandates a specific capture-pipeline ordering:The pipeline diagram in
crates/terraphim_agent/src/learnings/mod.rsreflects this:In practice the auto-suggest step is missing.
capture_failed_command(capture.rs:933) goes redact -> annotate-with-entities -> write file. There is no call intoterraphim_automata::find_matches()against the project thesaurus, so:npm install->bun installis indocs/src/kg/bun.md)terraphim-agent learn correct <id>manually for corrections that the KG already encodes~/.cargo/bin/terraphim-agent learn queryreturns the failure with no suggested correction, defeating the "Don't repeat past mistakes" loopcrates/terraphim_agent/src/learnings/suggest.rsexists but is gated behind#[cfg(feature = "shared-learning")]and only wraps shared-learning lookups -- it does not consult the local KG thesaurus during capture.Acceptance Criteria
pub fn suggest_correction_from_kg(command: &str, thesaurus: &Thesaurus) -> Option<String>inlearnings/suggest.rs(always-on, not feature-gated)capture_failed_commandafter redaction and before storage; populateCapturedLearning.correctionwith the resultCorrectionType::AutoSuggested(new variant) so the markdown file records it as "auto-suggested" vs "user-corrected"find_kg_dir()+build_kg_thesaurus_from_dir()(already incapture.rs) to load the thesaurus once per capture; cache viaOnceLockfor the process lifetimedocs/src/kg/), the function returnsNoneand capture proceeds withcorrection: None(no error)terraphim-agent learn listdisplaysauto-suggested: <correction>for entries that have onecargo test -p terraphim_agent learnings::capture::auto_suggestpassescargo test -p terraphim_agentpasses;cargo clippy -p terraphim_agent -- -D warningspassesProposed Approach
Crates affected:
crates/terraphim_agentonly.Files to add/modify:
crates/terraphim_agent/src/learnings/suggest.rs-- add the new always-on function (the existing shared-learning code stays under its feature gate)crates/terraphim_agent/src/learnings/capture.rs-- (1) extendCorrectionTypewithAutoSuggested, (2) callsuggest_correction_from_kgbetweenredact_secretsand the markdown writer, (3) includecorrectionin the markdown frontmattercrates/terraphim_agent/src/learnings/mod.rs-- re-export the new functionKey types:
Thesaurusaccess patterns are already used by the hook validation pipeline inkg_validation.rs-- reuse the same loader.Dependencies
None. Independent PR.
Verification
Scope
Single PR, ~200-300 lines including tests. Add the suggester, wire it into capture, extend
CorrectionType, add tests. Do not change the markdown schema beyond adding one frontmatter field, do not refactor the existing capture flow ordering.