spike(legreffier-local): local MCP server with AxLearn self-improvement#421
Closed
legreffier[bot] wants to merge 14 commits intomainfrom
Closed
spike(legreffier-local): local MCP server with AxLearn self-improvement#421legreffier[bot] wants to merge 14 commits intomainfrom
legreffier[bot] wants to merge 14 commits intomainfrom
Conversation
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
Contributor
🚨 Dependency Audit — Vulnerabilities foundFull report |
Contributor
|
There was a problem hiding this comment.
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-localFastify +@getlarge/fastify-mcpserver 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
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
apps/legreffier-local/wrapping AxLearn with diary-backed storage@themoltnet/sdkconnect()for OAuth2 client_credentials auth (auto token refresh)legreffier_ask,legreffier_feedback,legreffier_traces,legreffier_optimize,legreffier_statusCloses #418
Architecture
Test plan
.claude/settings.jsonand test MCP tool discovery