You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Upgrade terraphim-ai's learning system from defensive failure capture to a full Operational Skill Store (aka Context File System). Currently terraphim-agent learn only records failed commands. This proposal extends it to also capture successful multi-step workflows as reusable procedures, track their success rates, and auto-replay proven sequences -- transforming one-off successes into permanent organisational assets.
Inspired by Ben Lorica's Context File System analysis (Gradient Flow, March 2026) and evaluated against terraphim-ai's existing architecture.
Motivation
The Context Tax Problem
Current agent architectures treat every task as novel. The 1,000th execution costs the same as the 1st because the agent re-plans from scratch each time. In production ADF deployments, over half of token spend goes to rebuilding context from previous sessions.
Extend CapturedLearning with a success variant. When a multi-step bash/tool sequence completes with exit code 0 and matches a known task pattern, capture the full action sequence.
New type:
pubstructCapturedProcedure{pubid:String,pubtask_type:String,// e.g. "deploy-config", "fix-pipeline"pubsteps:Vec<ProcedureStep>,// ordered action sequencepubpreconditions:Vec<String>,// what must be true before replaypubpostconditions:Vec<String>,// what should be true after replaypubsource:LearningSource,pubcontext:LearningContext,pubsuccess_count:u32,// times replayed successfullypubfailure_count:u32,// times replay failedpubconfidence:f64,// derived from success/failure ratiopubtags:Vec<String>,}pubstructProcedureStep{pubcommand:String,pubexpected_exit_code:i32,pubexpected_output_pattern:Option<String>,// regex for output validationpubtimeout_secs:Option<u64>,pubenv_vars:Vec<String>,// required env vars (names only, not values)}
CLI extension:
terraphim-agent learn capture-success "deploy-config" --steps-from-session <session-id>
terraphim-agent learn procedures # list captured procedures
terraphim-agent learn procedures --task-type "deploy"# filter by type
Track confidence scores over time. When a procedure's confidence drops below threshold (e.g. 0.5 over last 10 executions), mark it as degraded and trigger re-learning.
pubstructProcedureHealthReport{pubprocedure_id:String,pubrolling_success_rate:f64,// last N executionspubtotal_executions:u32,publast_failure:Option<DateTime<Utc>>,pubfailure_pattern:Option<String>,// common error across recent failurespubstatus:ProcedureHealth,}pubenumProcedureHealth{Healthy,// > 0.8 success rateDegraded,// 0.5 - 0.8 success rateBroken,// < 0.5 success rate -- auto-pulled from replayNeedsRelearning,// broken + marked for re-capture}
CLI:
terraphim-agent learn health # show health report for all procedures
terraphim-agent learn health --degraded-only # show only degraded/broken
Integration with EIDOS (#601): Health transitions emit predictions that feed into the prediction-outcome tracking loop.
Match against existing procedures (Aho-Corasick deduplication)
Crystallise novel sequences as new CapturedProcedure entries
Run health check across all procedures
Generate daily report: new procedures captured, degraded procedures flagged
This is the automated crystallisation loop -- the missing piece that turns one-off successes into institutional memory.
Affected crates:terraphim_orchestrator (new agent config), terraphim_sessions (extraction API)
Phase 5: MCP Tool Index (terraphim_mcp_server)
Extend the MCP server to expose a tool capability index. Instead of stuffing all tool schemas into context, the index returns only relevant tool definitions for the current task -- using the existing Aho-Corasick automata to match task description against tool capability descriptions.
terraphim-agent tools relevant "fix the broken data pipeline"# Returns: ssh, systemctl, config-edit, log-search (4 of 47 available tools)
Summary
Upgrade terraphim-ai's learning system from defensive failure capture to a full Operational Skill Store (aka Context File System). Currently
terraphim-agent learnonly records failed commands. This proposal extends it to also capture successful multi-step workflows as reusable procedures, track their success rates, and auto-replay proven sequences -- transforming one-off successes into permanent organisational assets.Inspired by Ben Lorica's Context File System analysis (Gradient Flow, March 2026) and evaluated against terraphim-ai's existing architecture.
Motivation
The Context Tax Problem
Current agent architectures treat every task as novel. The 1,000th execution costs the same as the 1st because the agent re-plans from scratch each time. In production ADF deployments, over half of token spend goes to rebuilding context from previous sessions.
What We Have Today (Partial CFS)
terraphim-agent learn(failures only) + CLAUDE.md boot rules~/.config/terraphim/kg/)learn correct <id>What We Do Better Than Generic CFS
Proposed Architecture
Implementation Phases
Phase 1: Success Capture (
terraphim_agent+terraphim_agent_evolution)Extend
CapturedLearningwith a success variant. When a multi-step bash/tool sequence completes with exit code 0 and matches a known task pattern, capture the full action sequence.New type:
CLI extension:
Affected crates:
terraphim_agent(learnings module),terraphim_typesPhase 2: Procedure Replay Engine (
terraphim_agent)When
learn queryfinds a matching procedure with confidence > 0.8, offer replay instead of re-planning.Key behaviours:
Affected crates:
terraphim_agent(newreplaysubcommand)Phase 3: Success-Rate Monitoring (
terraphim_agent_evolution)Track confidence scores over time. When a procedure's confidence drops below threshold (e.g. 0.5 over last 10 executions), mark it as degraded and trigger re-learning.
CLI:
Integration with EIDOS (#601): Health transitions emit predictions that feed into the prediction-outcome tracking loop.
Affected crates:
terraphim_agent_evolution(health monitoring),terraphim_agent(health CLI)Phase 4: Nightly Extraction as ADF Agent (
terraphim_orchestrator)Add a new Core-tier ADF agent that runs nightly:
terraphim-agent sessions import)CapturedProcedureentriesThis is the automated crystallisation loop -- the missing piece that turns one-off successes into institutional memory.
Affected crates:
terraphim_orchestrator(new agent config),terraphim_sessions(extraction API)Phase 5: MCP Tool Index (
terraphim_mcp_server)Extend the MCP server to expose a tool capability index. Instead of stuffing all tool schemas into context, the index returns only relevant tool definitions for the current task -- using the existing Aho-Corasick automata to match task description against tool capability descriptions.
Affected crates:
terraphim_mcp_server,terraphim_automataDependencies on Existing Issues
Economics
Based on Lorica's analysis and our token spend patterns:
Non-Goals
terraphim_persistenceReferences
crates/terraphim_agent/src/learnings/,crates/terraphim_agent_evolution/