@timmeck/brain
v3.36.105
Published
Adaptive error memory and code intelligence system with Hebbian synapse network, hybrid search, and REST API
Maintainers
Readme
Brain
Autonomous Error Memory, Code Intelligence & Self-Improving AI for Claude Code — 280 MCP Tools, 117+ Engines
Brain is an MCP server that gives Claude Code a persistent, self-improving memory. It remembers errors, learns solutions, and runs 117+ autonomous engines in a 68-step feedback cycle. It observes itself, detects anomalies, forms and tests hypotheses, distills principles, reasons in chains, feels emotions, evolves strategies genetically, debates itself, challenges its own principles (Advocatus Diaboli), gets curious about knowledge gaps, syncs knowledge via Borg collective, loads community plugins, absorbs code from GitHub repos, extracts reusable features, recommends missing features, governs its own engine dynamics (detecting stagnation, retrigger spirals, KPI gaming), and modifies its own source code. Multi-provider LLM (Anthropic + Ollama). RAG vector search across all knowledge. Knowledge Graph with transitive inference. RLHF feedback learning. Tool-use learning. User modeling. Proactive suggestions. Code assimilation with feature extraction + recommendation. Autonomous web research missions. Live tech radar scanning. Engine Governance with 25 formal profiles, runtime influence tracking, 4 anti-pattern detectors, and active control (throttle/cooldown/isolate/escalate/restore). ChatEngine provides natural language access to all subsystems via NLU routing. SubAgentFactory creates specialized agents for focused tasks. 280 MCP tools. 603 tests.
Quick Start
npm install -g @timmeck/brain
brain setupThat's it. One command configures MCP, hooks, and starts the daemon.
Architecture
Claude Code ──MCP stdio──► Brain Daemon (:7777)
Cursor/Windsurf ─MCP SSE──► MCP HTTP Server (:7778)
Browser ────────HTTP──────► Command Center (:7790)
│
┌───────────────┼───────────────┐
▼ ▼ ▼
Error Memory Research Engine 117+ Engines
Code Intel Mission Engine ResearchOrchestrator
Synapse Net LLM Service 51-step feedback loop
Prevention Web Research │
Git Intel TechRadar ┌───┴───────────┐
│ ▼ ▼
▼ Self-Modification Dream Mode
SQLite (~/.brain) CodeGenerator Memory
SelfScanner ConsolidationCross-brain communication via IPC named pipes (trading-brain, marketing-brain).
Features
Error Memory & Code Intelligence
- Error Memory — Track errors, match against known solutions with hybrid search (TF-IDF + vector + synapse boost)
- Code Intelligence — Register and discover reusable code modules across all projects
- Proactive Prevention — Warns before errors occur when code matches known antipatterns
- Cross-Project Learning — Solutions from project A help solve errors in project B
- Auto Error Detection — PostToolUse hook catches errors in real-time
- Git Integration — Links errors to commits, tracks which changes introduced or fixed bugs
Persistent Memory
- Memory System — Remember preferences, decisions, context, facts, goals, and lessons across sessions
- Session Tracking — Auto-tracks conversation sessions with goals, summaries, and outcomes
- Decision History — Record architecture/design decisions with alternatives and rationale
- Semantic Changelog — Tracks every file change with semantic meaning, diffs, and context
- Task & Goal Tracking — Persistent tasks with priority, status, and cross-session continuity
- Semantic Search — Local all-MiniLM-L6-v2 embeddings (23MB, no cloud required)
LLM Service
- Multi-Provider — Anthropic Claude + Ollama local models with auto-routing
- Smart Caching — Content-hash cache, avoid duplicate API calls
- Rate Limiting — Per-hour and per-day token budgets with automatic throttling
- Usage Tracking — Calls, tokens, latency, cache hit rate, cost tracking
- Tier Routing — Templates mapped to tiers (critical/standard/bulk), auto-routed to best provider
Research Missions
- 5-Phase Pipeline — Decompose → Gather → Hypothesize → Analyze → Synthesize
- Web Research — Brave Search + Jina Reader + Playwright + Firecrawl fallback chain
- Autonomous — Brain decides what to research and executes independently
- Source Tracking — Every finding traced back to its original source
TechRadar
- Daily Scanning — Tracks trending repos, tech news, library updates
- Repo Watching — Monitor specific repos for changes (3 default repos configured)
- LLM Relevance Scoring — AI judges how relevant each finding is to your stack
- Digest Generation — Daily summaries of what's new and relevant
117+ Autonomous Engines
The ResearchOrchestrator runs a 51-step feedback cycle every 5 minutes:
Core Research Engines
| Engine | Purpose | |--------|---------| | SelfObserver | Monitors Brain's own performance metrics and behavior | | AnomalyDetective | Detects statistical anomalies in error patterns and metrics | | DataScout | Discovers external data sources and imports relevant data | | SignalScanner | Scans GitHub repos, HN, crypto markets for signals | | TechRadar | Daily tech landscape scanning with relevance scoring | | HypothesisEngine | Generates and statistically tests hypotheses about patterns | | ExperimentEngine | Proposes, runs, and measures controlled experiments | | AutoExperimentEngine | Autonomously discovers and runs parameter experiments | | SimulationEngine | What-if scenarios and counterfactual reasoning | | KnowledgeDistiller | Extracts principles and anti-patterns from experience |
Intelligence Engines
| Engine | Purpose | |--------|---------| | AttentionEngine | Dynamic focus allocation across topics and engines | | CausalGraph | Discovers cause-effect relationships between events | | CrossDomainEngine | Finds correlations across brain domains | | PatternExtractor | Mines recurring code and error patterns | | TransferEngine | Transfers knowledge between domains via analogies | | NarrativeEngine | Generates natural language explanations of findings | | CuriosityEngine | Detects knowledge gaps and generates exploration questions | | ResearchAgendaEngine | Prioritizes what to investigate next | | CounterfactualEngine | "What if X hadn't happened?" reasoning | | RAGEngine | Vector search across all knowledge (insights, memories, errors) | | KnowledgeGraphEngine | Typed fact relations with transitive inference | | SemanticCompressor | Deduplicates and compresses similar insights | | FeedbackEngine | RLHF reward signals from user corrections | | ToolTracker | Tool usage learning and pattern detection | | ProactiveEngine | Trigger-based improvement suggestions | | UserModel | Adaptive responses based on user skill level | | CodeHealthMonitor | Codebase quality tracking with trend analysis | | ActiveLearner | Gap identification and multi-strategy closing |
Meta-Cognition Engines
| Engine | Purpose | |--------|---------| | MetaCognitionLayer | Evaluates engine effectiveness, produces report cards | | DebateEngine | Multi-perspective reasoning with synthesis | | EmergenceEngine | Detects emergent properties from engine interactions | | ConceptAbstraction | Forms hierarchical concept taxonomies | | MemoryPalace | Builds associative knowledge graph for navigation | | ReasoningEngine | Deductive, abductive, and temporal inference chains | | EmotionalModel | Frustration, curiosity, satisfaction — influences priorities | | SelfTestEngine | Tests understanding of its own principles | | TeachEngine | Packages knowledge for transfer to other brains | | TeachingProtocol | Inter-brain knowledge transfer via IPC | | ConsensusEngine | Multi-brain voting for critical decisions |
Autonomy Engines
| Engine | Purpose | |--------|---------| | SelfModificationEngine | Generates code improvements, tests before applying | | CodeGenerator | Produces new code from learned patterns | | CodeMiner | Extracts reusable patterns from codebases | | GoalEngine | Sets, tracks, and forecasts autonomous goals | | EvolutionEngine | Genetic algorithm for strategy optimization | | AdaptiveStrategyEngine | Real-time parameter adaptation based on outcomes | | DreamEngine | Offline memory consolidation during idle | | RepoAbsorber | Absorbs external repos and indexes their knowledge | | FeatureExtractor | Extracts reusable functions, patterns, data structures | | FeatureRecommender | Detects needs, matches features, builds connections | | ResearchOrchestrator | Orchestrates the entire 51-step feedback cycle |
Self-Improvement Loop
Brain continuously improves itself through a closed-loop cycle:
- Observe — SelfObserver records performance metrics (error rates, resolution times, cache hits)
- Hypothesize — HypothesisEngine generates testable theories about what could work better
- Experiment — AutoExperimentEngine runs controlled A/B tests on parameters
- Measure — MetaCognitionLayer evaluates which experiments improved outcomes
- Adapt — AdaptiveStrategy applies winning parameters, reverts failures
- Evolve — EvolutionEngine genetically breeds the best strategy combinations
Frustration Detection: EmotionalModel tracks repeated failures. High frustration triggers more aggressive exploration via CuriosityEngine.
Dream Mode
During idle periods (no active conversations), DreamEngine performs memory consolidation:
- Replay — Re-processes important experiences to strengthen synaptic connections
- Pruning — Removes low-value memories and weak synapse connections
- Compression — Merges similar patterns into generalized principles
- Fact Extraction — Extracts typed facts, constraints, and open questions from consolidated clusters
- Decay — Time-based weight reduction on unused knowledge
- Triggers — Starts automatically after configurable idle period, or manually via
dream.start
Prediction Engine
Forecasts future metrics using statistical models:
- Holt-Winters — Triple exponential smoothing for seasonal patterns
- EWMA — Exponential weighted moving average for trend detection
- Auto-Calibration — Tracks prediction accuracy and adjusts model parameters
- Domain-Aware — Separate models per domain (errors, performance, learning)
AutoResponder
Automatic anomaly response system:
- Rule-Based — Configurable rules: "if error_rate > threshold, trigger learning cycle"
- Cooldown — Prevents response storms with per-rule cooldown periods
- Action Types — Learning cycles, notifications, parameter adjustments, dream triggers
- History — Full audit trail of what was detected and what action was taken
Code Generation & Mining
- CodeGenerator — Generates code improvements via Claude API with full diff preview
- CodeMiner — Analyzes codebases to extract reusable patterns and modules
- PatternExtractor — Identifies recurring code patterns across projects
- SignalScanner — Monitors GitHub trending, Hacker News, crypto markets for relevant signals
- Self-Improvement Proposals — Engines can propose improvements to their own source code
Self-Modification
- SelfScanner — Indexes own TypeScript source code with SHA256 change detection
- SelfModificationEngine — Generates improvements via Claude API, tests before applying
- Experiment Ledger — Tracks hypothesis, risk level, metrics before/after for every modification
- Safety — All modifications require explicit approval, automatic rollback on test failure
Notifications
- Discord, Telegram, Email — Multi-channel alert routing
- Notification Bridge — IPC-based cross-brain notification relay
- Configurable — All providers optional, graceful fallback
- Event Routing — Different events route to different channels
Command Center Dashboard (:7790)
13-page live dashboard showing the entire ecosystem:
| Page | What It Shows | |------|--------------| | Overview | All 3 brains, 117+ engines, error log, quick actions | | Entity | Consciousness orb — emotional state, thought streams, dimension ring | | Learning Cycle | 6-stage pipeline: Data → Analysis → Hypotheses → Experiments → Principles → Actions | | Trading Flow | Signals → Analysis → Trades → P&L, equity, positions, win rate | | Marketing | Content performance, platform analytics, engagement trends | | Intelligence | RAG, Knowledge Graph, tool stats, user model, proactive suggestions | | Cross-Brain & Borg | Collective sync, peer graph, Borg network | | Activity | Real-time event log, thought stream | | Debates & Challenges | Debate history, Advocatus Diaboli, resilience bars | | Desires | Desire priorities, action outcomes, cross-brain coordination | | Forge | Strategy/Content/Code forge status, pipeline metrics | | Infrastructure | Watchdog monitoring, LLM usage, plugins, self-modification | | Progress | Predictions, hypotheses, knowledge evolution, uptime tracking |
MCP Tools (280 tools)
Error & Code: brain_report_error, brain_query_error, brain_report_solution, brain_report_attempt, brain_find_reusable_code, brain_register_code, brain_check_code_similarity
Memory & Sessions: brain_remember, brain_recall, brain_session_start, brain_session_end, brain_session_history
Research Engines (5 tools each): self_observer, anomaly_detective, cross_domain, adaptive_strategy, experiment, knowledge_distiller, research_agenda, counterfactual, journal
Dream, Consciousness, Prediction, AutoResponder, Attention, Transfer, Narrative, Curiosity, Emergence, Debate, Challenge (Advocatus Diaboli), MetaCognition, Evolution, Reasoning, Emotions, Self-Modification, Ecosystem, Borg, Plugins — full tool suites for each
CLI Commands
brain setup One-command setup: MCP + hooks + daemon
brain start / stop Daemon management (with watchdog)
brain status Stats: errors, solutions, engines, synapses
brain doctor Health check: daemon, DB, MCP, hooks
brain query <text> Search for errors and solutions
brain learn Trigger a learning cycle
brain peers Show peer brains in the ecosystem
brain dashboard Generate interactive HTML dashboard
brain missions Research mission management (create, list, report)
brain watchdog Watchdog daemon status and control
brain service Windows service management (install, uninstall, status)
brain borg Borg collective sync (status, enable, disable, sync, history)
brain plugins Community plugins (list, routes, tools)
brain guardrail Guardrail status, health, rollback, circuit breaker reset
brain governance Engine governance: status, actions, throttle, cooldown, isolate, restore
brain export Export Brain data as JSONConfiguration
| Env Variable | Default | Description |
|---|---|---|
| BRAIN_DATA_DIR | ~/.brain | Data directory |
| BRAIN_LOG_LEVEL | info | Log level |
| BRAIN_API_PORT | 7777 | REST API port |
| BRAIN_MCP_HTTP_PORT | 7778 | MCP HTTP/SSE port |
| ANTHROPIC_API_KEY | — | Enables LLM features, CodeGen, Self-Mod |
| BRAVE_SEARCH_API_KEY | — | Enables web research missions |
| GITHUB_TOKEN | — | Enables CodeMiner + Signal Scanner |
| OLLAMA_HOST | http://localhost:11434 | Ollama local model endpoint |
Brain Ecosystem
| Brain | Purpose | Ports | |-------|---------|-------| | Brain (this) | Error memory, code intelligence, full autonomy & self-modification | 7777 / 7778 / 7790 | | Trading Brain | Adaptive trading intelligence with signal learning & paper trading | 7779 / 7780 | | Marketing Brain | Content strategy, social engagement & cross-platform optimization | 7781 / 7782 / 7783 | | Brain Core | Shared infrastructure — 117+ engines | — |
