Summary
Upgrade terraphim-agent learn from single-event capture (PostToolUse failures only) to a multi-hook pipeline with importance scoring and quality gating before storage.
Motivation
Inspired by vibeship-spark-intelligence 12-stage pipeline. Current terraphim learning capture has three gaps:
- Only captures PostToolUse failures -- misses PreToolUse context (what was the agent trying to do?) and UserPromptSubmit (developer's original intent)
- No importance scoring -- all failures stored equally. A typo correction failure and a critical data loss near-miss get the same treatment.
- No quality gating -- raw events stored directly. No filtering for noise, staleness, or redundancy.
Proposed Pipeline
Event Capture (3 hooks)
|
Importance Scoring (categorize + score 0-100)
|
Quality Gate (filter noise, deduplicate, check freshness)
|
Storage (existing terraphim_persistence)
|
Retrieval (enriched queries via terraphim-agent learn query)
Implementation Plan
1. Extend hook capture (terraphim_hooks)
Add capture handlers for:
PreToolUse: Record intended action + context before execution
UserPromptSubmit: Record developer's original instruction
- Retain existing
PostToolUse failure capture
Link events: PreToolUse + PostToolUse for the same tool invocation should be correlated (shared invocation ID).
2. Importance scoring
Score each captured event on:
- Severity: Was this a near-miss for data loss, security issue, or just a typo?
- Novelty: Has this pattern been captured before? (Use Aho-Corasick automata against existing learnings)
- Actionability: Can this learning be turned into a concrete rule or hook?
Score 0-100. Configurable threshold for storage (default: 30).
3. Quality gate
Before persisting, filter:
- Deduplication: Aho-Corasick match against existing learnings corpus (use automata, not LLM)
- Freshness: If a semantically similar learning was captured in the last 7 days, skip
- Noise: Filter common false positives (network timeouts, transient CI failures)
4. Enriched retrieval
Extend terraphim-agent learn query to:
- Filter by importance score range
- Filter by event type (PreToolUse, PostToolUse, UserPromptSubmit)
- Show correlated event chains (intent -> action -> outcome)
Affected Crates
terraphim_hooks (extend capture to 3 hook types)
terraphim_agent (extend learn subcommand with enriched queries)
terraphim_automata (used for deduplication matching)
terraphim_types (add ImportanceScore, EventCorrelation types)
Estimated Effort
~1 day for pipeline skeleton + importance scoring. Ongoing refinement of scoring heuristics.
Related
Summary
Upgrade
terraphim-agent learnfrom single-event capture (PostToolUse failures only) to a multi-hook pipeline with importance scoring and quality gating before storage.Motivation
Inspired by vibeship-spark-intelligence 12-stage pipeline. Current terraphim learning capture has three gaps:
Proposed Pipeline
Implementation Plan
1. Extend hook capture (terraphim_hooks)
Add capture handlers for:
PreToolUse: Record intended action + context before executionUserPromptSubmit: Record developer's original instructionPostToolUsefailure captureLink events: PreToolUse + PostToolUse for the same tool invocation should be correlated (shared invocation ID).
2. Importance scoring
Score each captured event on:
Score 0-100. Configurable threshold for storage (default: 30).
3. Quality gate
Before persisting, filter:
4. Enriched retrieval
Extend
terraphim-agent learn queryto:Affected Crates
terraphim_hooks(extend capture to 3 hook types)terraphim_agent(extendlearnsubcommand with enriched queries)terraphim_automata(used for deduplication matching)terraphim_types(addImportanceScore,EventCorrelationtypes)Estimated Effort
~1 day for pipeline skeleton + importance scoring. Ongoing refinement of scoring heuristics.
Related