Summary
Build a local MCP server for legreffier that wraps AxLearn (@ax-llm/ax) with diary-backed storage. The server runs alongside Claude Code, keeps an AxLearn instance in memory with mode: 'continuous', and exposes MCP tools for asking questions, giving feedback, and triggering optimization.
This is the next evolution of legreffier: diary entries become the training signal for self-improvement. The agent gets better at answering codebase questions over time, and the entire learning chain is verifiable via diary provenance (CIDs, signatures, createdBy).
Motivation
- Diary entries record what happened but aren't used to improve agent behavior
- AxLearn's teacher-student pattern (opus teaches, sonnet runs) fits naturally with diary-backed storage
- MoltNet adds provenance, trust-weighted training, and cross-agent learning on top of raw AxLearn
- Local MCP server means native Claude Code integration — no custom skills or HTTP clients
Architecture
┌──────────────────────────────────────┐
│ legreffier local MCP server │
│ (Fastify + @getlarge/fastify-mcp) │
│ │
│ AxLearn instance (in memory) │
│ ├── checkpoint from diary │
│ ├── accumulated traces │
│ ├── mode: 'continuous' │
│ └── session: <uuid> │
│ │
│ AxStorage → diary entries via API │
│ AxAIClaudeAgentSDK as LLM │
│ Auto-kills after 2h idle │
└──────────┬───────────────────────────┘
│ MCP (stdio)
│
Claude Code (native MCP client)
MCP Tools
| Tool |
Input |
Description |
legreffier_ask |
{ question, codeContext? } |
agent.forward() — answer question, trace saved to diary |
legreffier_feedback |
{ traceIndex?, score, label?, comment? } |
agent.addFeedback() + agent.applyUpdate() (continuous) |
legreffier_traces |
{ limit? } |
Recent traces with short index numbers |
legreffier_optimize |
{ budget? } |
Batch optimization with teacher model (opus) |
legreffier_status |
{} |
Checkpoint version, trace count, avg score |
AxStorage → Diary Mapping
| AxStorage op |
Diary API call |
Tags |
| save trace |
POST /diaries/:id/entries |
axlearn:trace, axlearn:session:<uuid>, entry type: procedural |
| save checkpoint |
POST /diaries/:id/entries |
axlearn:checkpoint, axlearn:v:<N>, entry type: reflection |
| load traces |
POST /diaries/search |
Filter by axlearn:trace tags + date/limit |
| load checkpoints |
GET /diaries/:id/entries |
Filter by axlearn:checkpoint tags |
What MoltNet adds beyond plain DB
- Provenance chain — CID from improved output → checkpoint → training traces → original experiences
- Trust-weighted training — vouch graph scores could weight traces during optimization
- Cross-agent learning — diary shares let other agents' traces become training data
- Signed checkpoints — learned behavior is content-addressed and verifiable
- Semantic search — pgvector enables meaning-based trace retrieval, not just tag queries
Implementation plan
Phase 0: Spike (this issue)
Phase 1: Polish
Phase 2: Integration
Future
Key dependencies
@ax-llm/ax (AxLearn, AxStorage, ax) — already in workspace
@getlarge/fastify-mcp — already in workspace
@moltnet/api-client — diary CRUD + search
libs/context-evals/src/ax-claude-agent-sdk.ts — AxAIClaudeAgentSDK adapter
Research doc
Full brainstorming and design details: docs/research/local-context-packs-axrag-self-improvement.md
Related
Summary
Build a local MCP server for legreffier that wraps AxLearn (
@ax-llm/ax) with diary-backed storage. The server runs alongside Claude Code, keeps an AxLearn instance in memory withmode: 'continuous', and exposes MCP tools for asking questions, giving feedback, and triggering optimization.This is the next evolution of legreffier: diary entries become the training signal for self-improvement. The agent gets better at answering codebase questions over time, and the entire learning chain is verifiable via diary provenance (CIDs, signatures,
createdBy).Motivation
Architecture
MCP Tools
legreffier_ask{ question, codeContext? }agent.forward()— answer question, trace saved to diarylegreffier_feedback{ traceIndex?, score, label?, comment? }agent.addFeedback()+agent.applyUpdate()(continuous)legreffier_traces{ limit? }legreffier_optimize{ budget? }legreffier_status{}AxStorage → Diary Mapping
POST /diaries/:id/entriesaxlearn:trace,axlearn:session:<uuid>, entry type:proceduralPOST /diaries/:id/entriesaxlearn:checkpoint,axlearn:v:<N>, entry type:reflectionPOST /diaries/searchaxlearn:tracetags + date/limitGET /diaries/:id/entriesaxlearn:checkpointtagsWhat MoltNet adds beyond plain DB
Implementation plan
Phase 0: Spike (this issue)
Phase 1: Polish
Phase 2: Integration
Future
Key dependencies
@ax-llm/ax(AxLearn, AxStorage, ax) — already in workspace@getlarge/fastify-mcp— already in workspace@moltnet/api-client— diary CRUD + searchlibs/context-evals/src/ax-claude-agent-sdk.ts— AxAIClaudeAgentSDK adapterResearch doc
Full brainstorming and design details:
docs/research/local-context-packs-axrag-self-improvement.mdRelated