How zenithfoundry/slm-gate works
slm-gate is a local preprocessing and routing layer for coding assistants. Its two entry points handle different traffic: MCP tool results are distilled, grounded, and clarified, while cloud-model requests may be answered locally or compressed before forwarding. The ledger records routing and savings for CLI metrics and dashboards. README capabilities are included, but unsampled modules are connected only where the README or sampled callers support the relationship.
Main entry points: mcp-gate/pipeline.ts MCP conditioning · llm-gate/pipeline.ts LLM routing · index.ts SQLite ledger · server.ts LLM HTTP server
Components 26
Traffic gates
- MCP server
src/mcp-gate/server.ts - MCP conditioning
src/mcp-gate/pipeline.ts - LLM HTTP server
src/llm-gate/server.ts - LLM routing
src/llm-gate/pipeline.ts - Provider formats
src/llm-gate/formats/contract.ts - Cloud forwarding
src/llm-gate/forward.ts
Local intelligence
- Tool-result distillation
src/utils/elision.ts - Repository grounding
src/mcp-gate/ground.ts - Ambiguity resolver
src/resolver/index.ts - Local-first answers
src/llm-gate/local-first.ts - Context compression
src/utils/compression.ts - SLM runtime
src/models/slm.ts - Answer verifier
src/verifier/index.ts
Ledger and analytics
- SQLite ledger
src/ledger/index.ts - Semantic cache
src/cache/index.ts - Provider pricing
src/pricing/index.ts - CLI metrics
src/ledger/report.ts - Savings dashboard
src/dashboard/serve.ts
Setup and configuration
- CLI
src/cli.ts - Configuration
src/config.ts - Local model setup
src/setup/startup.ts
Other components
- Developer / client
- Downstream MCP
- Cloud model API
- Langfuse
- Ollama
Connections 29
- Developer / client → MCP server: sends MCP traffic
- MCP server → Downstream MCP: proxies tool calls
- Downstream MCP → MCP server: returns tool results
- MCP server → MCP conditioning: conditions results
- MCP conditioning → Tool-result distillation: distills results
- MCP conditioning → Repository grounding: scans repository
- MCP conditioning → Ambiguity resolver: resolves ambiguity
- MCP conditioning → Semantic cache: checks and stores
- MCP conditioning → SQLite ledger: writes events
- Ambiguity resolver → SLM runtime: generates decisions
- Developer / client → LLM HTTP server: sends model requests
- LLM HTTP server → LLM routing: routes requests
- LLM routing → Local-first answers: tries local answer
- Local-first answers → SLM runtime: queries local model
- LLM routing → Context compression: compresses context
- LLM routing → Provider formats: normalizes requests
- LLM HTTP server → Cloud forwarding: forwards upstream
- Cloud forwarding → Cloud model API: sends cloud request
- LLM HTTP server → SQLite ledger: records routing
- LLM routing → Semantic cache: checks and stores
- LLM routing → Provider pricing: calculates cost
- SQLite ledger → CLI metrics: supplies report data
- SQLite ledger → Savings dashboard: supplies dashboard data
- SQLite ledger → Langfuse: flushes traces
- Developer / client → CLI: runs commands
- CLI → Configuration: loads settings
- CLI → Local model setup: starts diagnostics
- Local model setup → Ollama: checks local models
- SLM runtime → Ollama: runs inference