Skip to content

spike(legreffier-local): local MCP server with AxLearn self-improvement#421

Closed
legreffier[bot] wants to merge 14 commits intomainfrom
spike/legreffier-local-mcp-418
Closed

spike(legreffier-local): local MCP server with AxLearn self-improvement#421
legreffier[bot] wants to merge 14 commits intomainfrom
spike/legreffier-local-mcp-418

Conversation

@legreffier
Copy link
Copy Markdown
Contributor

@legreffier legreffier Bot commented Mar 17, 2026

Summary

  • Local MCP server in apps/legreffier-local/ wrapping AxLearn with diary-backed storage
  • @themoltnet/sdk connect() for OAuth2 client_credentials auth (auto token refresh)
  • Auto-discovers diary ID from git repo name, fetches identity/soul to customize instruction
  • 5 MCP tools: legreffier_ask, legreffier_feedback, legreffier_traces, legreffier_optimize, legreffier_status
  • AxStorage adapter maps AxLearn traces/checkpoints to diary entries via SDK Agent facade

Closes #418

Architecture

Legreffier Local MCP Server (Fastify + @getlarge/fastify-mcp)
├── AxLearn instance (in-memory, mode: continuous)
│   ├── Teacher: claude-opus-4-6 (via AxAIClaudeAgentSDK)
│   └── Student: claude-sonnet-4-6
├── AxStorage → diary entries (via @themoltnet/sdk)
│   ├── Traces → procedural entries (axlearn:trace tags)
│   └── Checkpoints → reflection entries (axlearn:checkpoint tags)
└── Auto-kill after 2h idle

Test plan

  • Unit tests: 8 tests for AxStorage adapter (mocked SDK)
  • Typecheck passes
  • Lint passes
  • Smoke test against local dev Docker Compose stack
  • Register in .claude/settings.json and test MCP tool discovery
  • End-to-end: ask → trace in diary → feedback → optimize → improved answer

legreffier Bot added 3 commits March 16, 2026 19:10
AxStorage maps AxLearn traces/checkpoints to MoltNet diary entries:
- Traces → procedural entries with axlearn:trace + axlearn:id:<id> tags
- Checkpoints → reflection entries with axlearn:checkpoint + version tags
- Trace lookup survives server restarts via tag-based search fallback
- 8 unit tests with mocked API client

Closes partially #418

Task-Group: legreffier-local-mcp
Task-Family: feature
…gent

- Move from tools/ to apps/legreffier-local/ (proper workspace package)
- Use @themoltnet/sdk connect() for OAuth2 client_credentials auth
- Auto-discover diary ID from git repo name
- Fetch identity/soul entries to customize AxLearn instruction
- Agent factory wires AxAIClaudeAgentSDK (teacher: opus, student: sonnet)
- 5 MCP tools: legreffier_ask, _feedback, _traces, _optimize, _status
- Typecheck + lint pass, 8 unit tests pass

MoltNet-Diary: 8d488599-4c7e-42a1-ae7f-e1b6e6c28353
Task-Group: legreffier-local-mcp
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 17, 2026

🚨 Dependency Audit — Vulnerabilities found

Full report
┌─────────────────────┬────────────────────────────────────────────────────────┐
│ high                │ @isaacs/brace-expansion has Uncontrolled Resource      │
│                     │ Consumption                                            │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Package             │ @isaacs/brace-expansion                                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Vulnerable versions │ <=5.0.0                                                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Patched versions    │ >=5.0.1                                                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Paths               │ apps__mcp-server>@fastify/otel>minimatch>@isaacs/      │
│                     │ brace-expansion                                        │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ More info           │ https://github.com/advisories/GHSA-7h2j-956f-4vf2      │
└─────────────────────┴────────────────────────────────────────────────────────┘
┌─────────────────────┬────────────────────────────────────────────────────────┐
│ high                │ Arbitrary File Read/Write via Hardlink Target Escape   │
│                     │ Through Symlink Chain in node-tar Extraction           │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Package             │ tar                                                    │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Vulnerable versions │ <7.5.8                                                 │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Patched versions    │ >=7.5.8                                                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Paths               │ apps__rest-api>@huggingface/transformers>onnxruntime-  │
│                     │ node>tar                                               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ More info           │ https://github.com/advisories/GHSA-83g3-92jg-28cx      │
└─────────────────────┴────────────────────────────────────────────────────────┘
┌─────────────────────┬────────────────────────────────────────────────────────┐
│ high                │ minimatch has a ReDoS via repeated wildcards with      │
│                     │ non-matching literal in pattern                        │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Package             │ minimatch                                              │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Vulnerable versions │ >=10.0.0 <10.2.1                                       │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Patched versions    │ >=10.2.1                                               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Paths               │ apps__mcp-server>@fastify/otel>minimatch               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ More info           │ https://github.com/advisories/GHSA-3ppc-4f35-3m26      │
└─────────────────────┴────────────────────────────────────────────────────────┘
┌─────────────────────┬────────────────────────────────────────────────────────┐
│ high                │ minimatch has ReDoS: matchOne() combinatorial          │
│                     │ backtracking via multiple non-adjacent GLOBSTAR        │
│                     │ segments                                               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Package             │ minimatch                                              │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Vulnerable versions │ >=10.0.0 <10.2.3                                       │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Patched versions    │ >=10.2.3                                               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Paths               │ apps__mcp-server>@fastify/otel>minimatch               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ More info           │ https://github.com/advisories/GHSA-7r86-cg39-jmmj      │
└─────────────────────┴────────────────────────────────────────────────────────┘
┌─────────────────────┬────────────────────────────────────────────────────────┐
│ high                │ minimatch ReDoS: nested *() extglobs generate          │
│                     │ catastrophically backtracking regular expressions      │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Package             │ minimatch                                              │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Vulnerable versions │ >=10.0.0 <10.2.3                                       │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Patched versions    │ >=10.2.3                                               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Paths               │ apps__mcp-server>@fastify/otel>minimatch               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ More info           │ https://github.com/advisories/GHSA-23c5-xmqv-rm74      │
└─────────────────────┴────────────────────────────────────────────────────────┘
┌─────────────────────┬────────────────────────────────────────────────────────┐
│ high                │ tar has Hardlink Path Traversal via Drive-Relative     │
│                     │ Linkpath                                               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Package             │ tar                                                    │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Vulnerable versions │ <=7.5.9                                                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Patched versions    │ >=7.5.10                                               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Paths               │ apps__rest-api>@huggingface/transformers>onnxruntime-  │
│                     │ node>tar                                               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ More info           │ https://github.com/advisories/GHSA-qffp-2rhf-9h96      │
└─────────────────────┴────────────────────────────────────────────────────────┘
┌─────────────────────┬────────────────────────────────────────────────────────┐
│ high                │ node-tar Symlink Path Traversal via Drive-Relative     │
│                     │ Linkpath                                               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Package             │ tar                                                    │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Vulnerable versions │ <=7.5.10                                               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Patched versions    │ >=7.5.11                                               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Paths               │ apps__rest-api>@huggingface/transformers>onnxruntime-  │
│                     │ node>tar                                               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ More info           │ https://github.com/advisories/GHSA-9ppj-qmqm-q256      │
└─────────────────────┴────────────────────────────────────────────────────────┘
┌─────────────────────┬────────────────────────────────────────────────────────┐
│ moderate            │ bn.js affected by an infinite loop                     │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Package             │ bn.js                                                  │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Vulnerable versions │ <4.12.3                                                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Patched versions    │ >=4.12.3                                               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Paths               │ apps__legreffier-local>@getlarge/fastify-mcp>fast-     │
│                     │ jwt>asn1.js>bn.js                                      │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ More info           │ https://github.com/advisories/GHSA-378v-28hj-76wf      │
└─────────────────────┴────────────────────────────────────────────────────────┘
┌─────────────────────┬────────────────────────────────────────────────────────┐
│ moderate            │ ajv has ReDoS when using `$data` option                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Package             │ ajv                                                    │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Vulnerable versions │ >=7.0.0-alpha.0 <8.18.0                                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Patched versions    │ >=8.18.0                                               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Paths               │ apps__legreffier-local>fastify>@fastify/ajv-           │
│                     │ compiler>ajv                                           │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ More info           │ https://github.com/advisories/GHSA-2g4f-4pwh-qvx6      │
└─────────────────────┴────────────────────────────────────────────────────────┘
┌─────────────────────┬────────────────────────────────────────────────────────┐
│ moderate            │ Fastify's Missing End Anchor in "subtypeNameReg"       │
│                     │ Allows Malformed Content-Types to Pass Validation      │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Package             │ fastify                                                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Vulnerable versions │ >=5.7.2 <=5.8.0                                        │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Patched versions    │ >=5.8.1                                                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Paths               │ apps__legreffier-local>fastify                         │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ More info           │ https://github.com/advisories/GHSA-573f-x89g-hqp9      │
└─────────────────────┴────────────────────────────────────────────────────────┘
┌─────────────────────┬────────────────────────────────────────────────────────┐
│ low                 │ Elliptic Uses a Cryptographic Primitive with a Risky   │
│                     │ Implementation                                         │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Package             │ elliptic                                               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Vulnerable versions │ <=6.6.1                                                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Patched versions    │ <0.0.0                                                 │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Paths               │ libs__auth>get-jwks>jwk-to-pem>elliptic                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ More info           │ https://github.com/advisories/GHSA-848j-6mx2-7j84      │
└─────────────────────┴────────────────────────────────────────────────────────┘
11 vulnerabilities found
Severity: 1 low | 3 moderate | 7 high

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 17, 2026

⚠️ Knip — Unused code or dependencies found

Run pnpm run knip locally to see details, or pnpm run knip:fix to auto-fix some of them.

Full report
�[93m�[4mUnused files�[24m�[39m (38)
apps/landing/src/hooks/useFeedSSE.ts                                
apps/rest-api/src/migrate.ts                                        
apps/rest-api/src/sse/public-feed-poller.ts                         
apps/rest-api/src/sse/sse-writer.ts                                 
libs/api-client/__tests__/retry-fetch.test.ts                       
libs/context-distill/__tests__/benchmarks/cluster.bench.ts          
libs/context-distill/__tests__/benchmarks/compile.bench.ts          
libs/context-distill/__tests__/cluster.test.ts                      
libs/context-distill/__tests__/compile.test.ts                      
libs/context-distill/__tests__/compress.test.ts                     
libs/context-distill/__tests__/consolidate.test.ts                  
libs/context-distill/__tests__/entry-relations.integration.test.ts  
libs/context-distill/__tests__/mmr.test.ts                          
libs/context-distill/__tests__/provenance-dag.integration.test.ts   
libs/context-distill/__tests__/selector.test.ts                     
libs/context-evals/src/claude-task-runner.ts                        
libs/embedding-service/__tests__/embedding-service.test.ts          
libs/sdk/__tests__/agent.test.ts                                    
libs/sdk/__tests__/config.test.ts                                   
libs/sdk/__tests__/connect.test.ts                                  
libs/sdk/__tests__/credentials.test.ts                              
libs/sdk/__tests__/encrypt-vectors.test.ts                          
libs/sdk/__tests__/encrypt.test.ts                                  
libs/sdk/__tests__/errors.test.ts                                   
libs/sdk/__tests__/register.test.ts                                 
libs/sdk/__tests__/repair.test.ts                                   
libs/sdk/__tests__/retry.test.ts                                    
libs/sdk/__tests__/sign-bytes.test.ts                               
libs/sdk/__tests__/sign.test.ts                                     
libs/sdk/__tests__/ssh.test.ts                                      
libs/sdk/__tests__/token.test.ts                                    
packages/github-agent/__tests__/bot-user.test.ts                    
packages/github-agent/__tests__/credential-helper.test.ts           
packages/github-agent/__tests__/git-setup.test.ts                   
packages/github-agent/__tests__/token.test.ts                       
test-fixtures/generate-ssh-vectors.mjs                              
test-fixtures/generate-x25519-vectors.mjs                           
tools/db/backfill-content-hashes.ts                                 
�[93m�[4mUnused dependencies�[24m�[39m (24)
@fastify/otel                                apps/mcp-server/package.json:31:6
@opentelemetry/instrumentation               apps/mcp-server/package.json:33:6
@opentelemetry/instrumentation-dns           apps/mcp-server/package.json:34:6
@opentelemetry/instrumentation-http          apps/mcp-server/package.json:35:6
@opentelemetry/instrumentation-pino          apps/mcp-server/package.json:36:6
@opentelemetry/instrumentation-runtime-node  apps/mcp-server/package.json:37:6
@opentelemetry/instrumentation-undici        apps/mcp-server/package.json:38:6
pino                                         apps/mcp-server/package.json:42:6
pino-opentelemetry-transport                 apps/mcp-server/package.json:43:6
thread-stream                                apps/mcp-server/package.json:44:6
@fastify/otel                                apps/rest-api/package.json:27:6  
@huggingface/transformers                    apps/rest-api/package.json:36:6  
@opentelemetry/exporter-metrics-otlp-proto   apps/rest-api/package.json:44:6  
@opentelemetry/instrumentation               apps/rest-api/package.json:46:6  
@opentelemetry/resources                     apps/rest-api/package.json:54:6  
@opentelemetry/sdk-metrics                   apps/rest-api/package.json:55:6  
@opentelemetry/sdk-trace-base                apps/rest-api/package.json:56:6  
@opentelemetry/sdk-trace-node                apps/rest-api/package.json:57:6  
@opentelemetry/semantic-conventions          apps/rest-api/package.json:58:6  
pino-pretty                                  apps/rest-api/package.json:66:6  
thread-stream                                apps/rest-api/package.json:67:6  
@dotenvx/dotenvx                             tools/package.json:26:6          
drizzle-orm                                  tools/package.json:28:6          
@moltnet/api-client                          tools/package.json:29:6          
�[93m�[4mUnused devDependencies�[24m�[39m (12)
drizzle-orm                 apps/mcp-server/package.json:50:6        
pino-pretty                 apps/mcp-server/package.json:51:6        
@moltnet/crypto-service     libs/context-distill/package.json:24:6   
@moltnet/database           libs/context-distill/package.json:25:6   
@testcontainers/postgresql  libs/context-distill/package.json:26:6   
drizzle-orm                 libs/context-distill/package.json:27:6   
pg                          libs/context-distill/package.json:28:6   
@types/pg                   libs/context-distill/package.json:29:6   
@types/figlet               libs/design-system/package.json:56:6     
testcontainers              libs/diary-service/package.json:37:6     
@moltnet/crypto-service     packages/github-agent/package.json:43:6  
@types/figlet               packages/legreffier-cli/package.json:42:6
�[93m�[4mReferenced optional peerDependencies�[24m�[39m (2)
figlet  libs/design-system/package.json
ink     libs/design-system/package.json
�[93m�[4mUnlisted dependencies�[24m�[39m (1)
pg  libs/diary-service/__tests__/diary-service.dbos.integration.test.ts:21:27
�[93m�[4mUnlisted binaries�[24m�[39m (8)
python3                                             .github/workflows/ci.yml     
clawhub                                             .github/workflows/release.yml
claude                                              package.json                 
codex                                               package.json                 
go                                                  package.json                 
gofmt                                               package.json                 
packages/openclaw-skill/scripts/publish-clawhub.sh  package.json                 
packages/openclaw-skill/scripts/package.sh          package.json                 
�[93m�[4mUnused exports�[24m�[39m (47)
API_BASE_URL                           apps/landing/src/api.ts:14:14                                 
AskSchema                              apps/legreffier-local/src/tools.ts:18:14                      
FeedbackSchema                         apps/legreffier-local/src/tools.ts:27:14                      
TracesSchema                           apps/legreffier-local/src/tools.ts:44:14                      
OptimizeSchema                         apps/legreffier-local/src/tools.ts:54:14                      
StatusSchema                           apps/legreffier-local/src/tools.ts:64:14                      
handleAsk                    function  apps/legreffier-local/src/tools.ts:88:23                      
handleFeedback               function  apps/legreffier-local/src/tools.ts:147:23                     
handleTraces                 function  apps/legreffier-local/src/tools.ts:181:23                     
handleOptimize               function  apps/legreffier-local/src/tools.ts:208:23                     
handleStatus                 function  apps/legreffier-local/src/tools.ts:243:23                     
handleMoltnetInfo            function  apps/mcp-server/src/info-tools.ts:17:23                       
handleSignMessage            function  apps/mcp-server/src/prompts.ts:207:23                         
ServerConfigSchema                     apps/rest-api/src/config.ts:26:14                             
DatabaseConfigSchema                   apps/rest-api/src/config.ts:38:14                             
WebhookConfigSchema                    apps/rest-api/src/config.ts:43:14                             
RecoveryConfigSchema                   apps/rest-api/src/config.ts:47:14                             
OryConfigSchema                        apps/rest-api/src/config.ts:51:14                             
ObservabilityConfigSchema              apps/rest-api/src/config.ts:62:14                             
EmbeddingConfigSchema                  apps/rest-api/src/config.ts:72:14                             
SecurityConfigSchema                   apps/rest-api/src/config.ts:79:14                             
loadEmbeddingConfig          function  apps/rest-api/src/config.ts:231:17                            
findProblemTypeByCode                  apps/rest-api/src/problems/index.ts:3:3                       
findProblemTypeByStatus                apps/rest-api/src/problems/index.ts:4:3                       
getTypeUri                             apps/rest-api/src/problems/index.ts:5:3                       
problemTypes                           apps/rest-api/src/problems/index.ts:7:3                       
ContextPackEntrySchema                 apps/rest-api/src/schemas.ts:601:14                           
ExpandedPackEntrySchema                apps/rest-api/src/schemas.ts:620:14                           
ContextPackSchema                      apps/rest-api/src/schemas.ts:630:14                           
ContextPackExpandedSchema              apps/rest-api/src/schemas.ts:661:14                           
ContextPackListSchema                  apps/rest-api/src/schemas.ts:681:14                           
consolidateQueue                       apps/rest-api/src/workflows/context-distill-workflows.ts:57:14
compileQueue                           apps/rest-api/src/workflows/context-distill-workflows.ts:62:14
compileQueue                           apps/rest-api/src/workflows/index.ts:2:3                      
consolidateQueue                       apps/rest-api/src/workflows/index.ts:4:3                      
contextDistillWorkflows                apps/rest-api/src/workflows/index.ts:7:3                      
DEFAULT_WORKFLOW_TIMEOUT_MS            apps/rest-api/src/workflows/index.ts:39:3                     
runWorkflow                            apps/rest-api/src/workflows/index.ts:40:3                     
DEFAULT_WORKFLOW_TIMEOUT_MS            apps/rest-api/src/workflows/run-workflow.ts:14:14             
resolveCredentialsPath       function  libs/context-evals/src/client.ts:18:23                        
loadCredentials              function  libs/context-evals/src/client.ts:27:23                        
fetchToken                   function  libs/context-evals/src/client.ts:35:23                        
tasksmithToGpackTask         function  libs/context-evals/src/tasksmith.ts:67:17                     
DBOSWorkflowConflictError              libs/database/src/dbos.ts:145:3                               
MAX_PUBLIC_CONTENT_LENGTH              libs/diary-service/src/diary-service.ts:51:14                 
makeClient                   function  packages/legreffier-cli/src/api.ts:58:17                      
fetchCommitData              function  tools/src/skill-evals/legreffier/commit-scorer.ts:147:23      
�[93m�[4mUnused exported types�[24m�[39m (24)
CallToolResult            type       apps/legreffier-local/src/tools.ts:14:15           
WhoamiInput               type       apps/mcp-server/src/schemas.ts:390:13              
IssueVoucherInput         type       apps/mcp-server/src/schemas.ts:404:13              
ListVouchersInput         type       apps/mcp-server/src/schemas.ts:407:13              
TrustGraphInput           type       apps/mcp-server/src/schemas.ts:410:13              
MoltnetInfoInput          type       apps/mcp-server/src/schemas.ts:415:13              
CorsPluginOptions         interface  apps/rest-api/src/plugins/cors.ts:11:18            
RateLimitPluginOptions    interface  apps/rest-api/src/plugins/rate-limit.ts:14:18      
ProblemType               type       apps/rest-api/src/problems/index.ts:6:8            
CompileWorkflowInput      type       apps/rest-api/src/workflows/index.ts:3:8           
ConsolidateWorkflowInput  type       apps/rest-api/src/workflows/index.ts:5:8           
ContextDistillDeps        type       apps/rest-api/src/workflows/index.ts:6:8           
LegreffierOnboardingDeps  type       apps/rest-api/src/workflows/index.ts:17:8          
MaintenanceDeps           type       apps/rest-api/src/workflows/index.ts:26:8          
RegistrationDeps          type       apps/rest-api/src/workflows/index.ts:31:8          
RegistrationResult        type       apps/rest-api/src/workflows/index.ts:32:8          
RunWorkflowOptions        type       apps/rest-api/src/workflows/index.ts:41:8          
RateLimitRetryOptions     type       libs/sdk/src/retry.ts:5:15                         
AgentAdapter              type       packages/legreffier-cli/src/adapters/index.ts:11:15
AgentAdapterOptions       type       packages/legreffier-cli/src/adapters/index.ts:11:29
InitPhase                 type       packages/legreffier-cli/src/state.ts:4:13          
CommitExpected            type       tools/src/skill-evals/legreffier/index.ts:4:15     
CommitScoreResult         type       tools/src/skill-evals/legreffier/index.ts:4:31     
ScorerFactory             type       tools/src/skill-evals/scorers.ts:6:13              
�[93m�[4mUnused catalog entries�[24m�[39m (2)
@fastify/static  default  pnpm-workspace.yaml:20:4
zod              default  pnpm-workspace.yaml:94:3
�[33m�[4mConfiguration hints�[24m (5)�[39m
libs/sdk                 …p.config.ts  �[90mAdd �[97mentry�[90m and/or refine �[97mproject�[90m files in �[97mworkspaces["libs/sdk"]�[90m (14 unused files)�[39m
libs/context-distill     …p.config.ts  �[90mAdd �[97mentry�[90m and/or refine �[97mproject�[90m files in �[97mworkspaces["libs/context-distill"]�[90m (10 …�[39m
packages/github-agent    …p.config.ts  �[90mAdd �[97mentry�[90m and/or refine �[97mproject�[90m files in �[97mworkspaces["packages/github-agent"]�[90m (4 …�[39m
apps/rest-api            …p.config.ts  �[90mAdd �[97mentry�[90m and/or refine �[97mproject�[90m files in �[97mworkspaces["apps/rest-api"]�[90m (3 unused f…�[39m
. �[90m(root)�[39m                 …p.config.ts  �[90mAdd �[97mentry�[90m and/or refine �[97mproject�[90m files in �[97mworkspaces["."]�[90m (2 unused files)�[39m        
 ELIFECYCLE  Command failed with exit code 1.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new local MCP server app (apps/legreffier-local) that wraps AxLearn with diary-backed persistence via @themoltnet/sdk, plus supporting workspace wiring and design/research docs for the self-improvement spike.

Changes:

  • Introduces @moltnet/legreffier-local Fastify + @getlarge/fastify-mcp server with 5 tools (legreffier_ask, legreffier_feedback, legreffier_traces, legreffier_optimize, legreffier_status) and idle shutdown.
  • Implements an AxStorage adapter that persists AxLearn traces/checkpoints as diary entries via the SDK (with unit tests).
  • Wires the new app into the monorepo TypeScript references and updates planning/research documentation.

Reviewed changes

Copilot reviewed 12 out of 14 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tsconfig.json Adds TS project reference for the new apps/legreffier-local workspace.
pnpm-lock.yaml Records the new app importer + dependency graph.
libs/context-distill/tsconfig.json Adds TS project references to crypto-service and database.
docs/superpowers/plans/2026-03-16-legreffier-local-mcp.md Implementation plan for the spike.
docs/research/local-context-packs-axrag-self-improvement.md Research/brainstorming doc tying local packs, axRAG, and AxLearn together.
apps/legreffier-local/tsconfig.json TS composite config + project references for the new app.
apps/legreffier-local/package.json New app package definition, scripts, and dependencies.
apps/legreffier-local/src/types.ts Shared types for config/deps and AxLearn IO.
apps/legreffier-local/src/ax-storage.ts Diary-backed AxStorage implementation using the SDK.
apps/legreffier-local/src/agent.ts AxLearn agent factory wiring models + storage.
apps/legreffier-local/src/tools.ts MCP tool schemas, handlers, and registration.
apps/legreffier-local/src/main.ts Fastify entrypoint: SDK auth, diary auto-discovery, MCP registration, idle shutdown.
apps/legreffier-local/src/index.ts Public exports for the app’s internal building blocks.
apps/legreffier-local/src/tests/ax-storage.test.ts Unit tests for the AxStorage adapter behavior.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Comment thread docs/superpowers/plans/2026-03-16-legreffier-local-mcp.md Outdated
Comment thread apps/legreffier-local/src/tools.ts
Comment thread apps/legreffier-local/src/tools.ts
Comment thread apps/legreffier-local/src/agent.ts
Comment thread apps/legreffier-local/package.json Outdated
Comment thread apps/legreffier-local/src/main.ts Outdated
legreffier Bot and others added 11 commits March 17, 2026 10:53
…fix, cleanup

- Replace hand-written ServerConfig with TypeBox schema + Value.Check
  validation (same pattern as apps/mcp-server/src/config.ts)
- Fix traceCounter race: reserve index synchronously before async calls
- Remove unused @moltnet/api-client dep (SDK handles all API calls)
- Remove plan doc (uploaded to GH issue #418 comment)

MoltNet-Diary: 8d488599-4c7e-42a1-ae7f-e1b6e6c28353
Task-Group: legreffier-local-mcp
- Add stdio transport via runStdioServer from @getlarge/fastify-mcp
  so Claude Code can manage the process lifecycle (--stdio flag or env)
- Fix trace save failure: session tag exceeded 50-char API limit
- Fix trace lookup: use entries.list (tag filter) instead of
  entries.search (semantic search requires query text to rank results)
- Use TAG constant for all diary entry tag prefixes ("learn:")
- Change trace entry type from procedural to semantic
- Register legreffier-local as stdio MCP server in .mcp.json

MoltNet-Diary: e547677e-aa60-438e-8aa3-01b67d94d82d
Task-Group: legreffier-local-mcp
Task-Family: feature
…semantic load

Replace reflect() with entries.list filtered by entryType for identity
and soul entries. Remove blanket semantic entry loading — too noisy for
instruction context. Semantic knowledge will come via context packs or
on-demand search per question.

MoltNet-Diary: e547677e-aa60-438e-8aa3-01b67d94d82d
Task-Group: legreffier-local-mcp
Search diary for semantic/procedural/episodic entries relevant to the
question before forwarding to AxLearn. Excludes learn:trace entries.
Merges diary results with any caller-provided codeContext.

MoltNet-Diary: e547677e-aa60-438e-8aa3-01b67d94d82d
Task-Group: legreffier-local-mcp
Move ax-claude-agent-sdk, ax-codex-agent-sdk, ax-shared, and sdk-types
from context-evals into a new @moltnet/ax-agents lib. Adapters accept
env via constructor option (defaults to process.env), so callers can
inject config without depending on context-evals.

Also addresses code review feedback on legreffier-local:
- Fix test tag assertions (axlearn: → learn: prefix)
- Fix test mocks (entries.search → entries.list)
- Deduplicate truncate into util.ts

MoltNet-Diary: e547677e-aa60-438e-8aa3-01b67d94d82d
Task-Group: legreffier-local-mcp
…ntext + state

- Add early check for partial credentials (one of client_id/secret set
  but not the other) before calling connect() — gives a clear error
  instead of a confusing SDK failure
- Split LocalMcpDeps into LocalMcpContext (immutable, set at startup)
  and LocalMcpState (mutable, mutated by handlers) for type clarity

MoltNet-Diary: e547677e-aa60-438e-8aa3-01b67d94d82d
Task-Group: legreffier-local-mcp
The 627-line research doc conflates brainstorming with implementation.
Key ideas (AxRAG, context packs) are tracked in issues. The AxLearn
self-improvement loop is already implemented in legreffier-local.

MoltNet-Diary: e547677e-aa60-438e-8aa3-01b67d94d82d
Task-Group: legreffier-local-mcp
queryDiary() searches diary entries via MoltNet API (server-side
embeddings + pgvector) and injects results as codeContext before
forwarding to AxLearn. Gracefully falls back if search returns empty.

MoltNet-Diary: e547677e-aa60-438e-8aa3-01b67d94d82d
Task-Group: legreffier-local-mcp
…, weights

Proves query + entryTypes, query + excludeTags, and query + weight
params work correctly against the local stack (all pass). The SDK 404
observed against prod is environment-specific, not a code bug.

Also cleans up debug logging from rag.ts.

MoltNet-Diary: e547677e-aa60-438e-8aa3-01b67d94d82d
Task-Group: legreffier-local-mcp
Wrap optimize() with Promise.race against a configurable timeout
(LEGREFFIER_OPTIMIZE_TIMEOUT_MS, default 2min). Returns a clear
error message on timeout instead of hanging indefinitely.

MoltNet-Diary: e547677e-aa60-438e-8aa3-01b67d94d82d
Task-Group: legreffier-local-mcp
@getlarge getlarge closed this Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spike: local legreffier MCP server with AxLearn self-improvement

2 participants