Learning Compile
learn compile closes the feedback loop between user corrections and live command rewriting.
It scans the learnings directory for captured corrections, converts ToolPreference entries
into thesaurus mappings, and writes a JSON file that the replace command loads immediately.
Source: crates/terraphim_agent/src/learnings/compile.rs
The feedback loop
user says "use bun instead of npm"
|
v
correction-*.md saved by post-tool-use hook
|
v
terraphim-agent learn compile --output compiled-corrections.json
|
v
replace command loads compiled-corrections.json
|
v
"npm install" -> "bun install" in future commandsCLI usage
Compile to a standalone file:
Merge with an existing curated thesaurus (compiled entries override curated on conflict):
Output:
Compiled 3 correction(s), merged with 12 curated entries -> 14 total entries.What gets compiled
Only ToolPreference corrections are compiled into the thesaurus. Other correction types
(Naming, CodePattern, WorkflowStep, FactCorrection) are parsed but silently skipped.
A ToolPreference correction contains:
original— the pattern to match (becomes the thesaurus key)corrected— the replacement term (becomes the nterm value)
Example: a correction captured when the user typed use bun instead of npm install produces:
Merge precedence
When --merge-with is supplied, compiled corrections take precedence over curated entries
that share the same key. This means user preferences learned from actual failures override
the defaults shipped with the knowledge graph.
Output format
The output file is a standard thesaurus JSON that terraphim_automata::load_thesaurus()
accepts:
Pass this file to terraphim-agent replace via the --thesaurus flag to activate the
compiled corrections.