claude-brain 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +157 -0
- package/VERSION +1 -0
- package/assets/CLAUDE.md +307 -0
- package/bunfig.toml +8 -0
- package/package.json +74 -0
- package/src/automation/auto-context.ts +240 -0
- package/src/automation/decision-detector.ts +452 -0
- package/src/automation/index.ts +11 -0
- package/src/automation/proactive-recall.ts +373 -0
- package/src/automation/project-detector.ts +297 -0
- package/src/cli/auto-setup.ts +74 -0
- package/src/cli/bin.ts +110 -0
- package/src/cli/commands/install-mcp.ts +50 -0
- package/src/cli/commands/serve.ts +129 -0
- package/src/cli/diagnose.ts +4 -0
- package/src/cli/health-check.ts +4 -0
- package/src/cli/migrate-chroma.ts +106 -0
- package/src/cli/setup.ts +4 -0
- package/src/config/defaults.ts +47 -0
- package/src/config/home.ts +55 -0
- package/src/config/index.ts +7 -0
- package/src/config/loader.ts +166 -0
- package/src/config/migration.ts +76 -0
- package/src/config/schema.ts +257 -0
- package/src/config/validator.ts +184 -0
- package/src/config/watcher.ts +86 -0
- package/src/context/assembler.ts +398 -0
- package/src/context/cache-manager.ts +101 -0
- package/src/context/formatter.ts +84 -0
- package/src/context/hierarchy.ts +85 -0
- package/src/context/index.ts +83 -0
- package/src/context/progress-tracker.ts +174 -0
- package/src/context/standards-manager.ts +267 -0
- package/src/context/types.ts +252 -0
- package/src/context/validator.ts +58 -0
- package/src/cross-project/affinity.ts +162 -0
- package/src/cross-project/generalizer.ts +283 -0
- package/src/cross-project/index.ts +13 -0
- package/src/cross-project/transfer.ts +201 -0
- package/src/diagnostics/index.ts +123 -0
- package/src/health/index.ts +229 -0
- package/src/index.ts +7 -0
- package/src/knowledge/entity-extractor.ts +416 -0
- package/src/knowledge/graph/builder.ts +159 -0
- package/src/knowledge/graph/linker.ts +201 -0
- package/src/knowledge/graph/memory-graph.ts +359 -0
- package/src/knowledge/graph/schema.ts +99 -0
- package/src/knowledge/graph/search.ts +168 -0
- package/src/knowledge/relationship-extractor.ts +108 -0
- package/src/memory/chroma/client.ts +169 -0
- package/src/memory/chroma/collection-manager.ts +94 -0
- package/src/memory/chroma/config.ts +46 -0
- package/src/memory/chroma/embeddings.ts +153 -0
- package/src/memory/chroma/index.ts +82 -0
- package/src/memory/chroma/migration.ts +270 -0
- package/src/memory/chroma/schemas.ts +69 -0
- package/src/memory/chroma/search.ts +315 -0
- package/src/memory/chroma/store.ts +694 -0
- package/src/memory/consolidation/archiver.ts +164 -0
- package/src/memory/consolidation/merger.ts +186 -0
- package/src/memory/consolidation/scorer.ts +138 -0
- package/src/memory/context-builder.ts +236 -0
- package/src/memory/database.ts +169 -0
- package/src/memory/embedding-utils.ts +156 -0
- package/src/memory/embeddings.ts +226 -0
- package/src/memory/episodic/detector.ts +108 -0
- package/src/memory/episodic/manager.ts +334 -0
- package/src/memory/episodic/summarizer.ts +179 -0
- package/src/memory/episodic/types.ts +52 -0
- package/src/memory/index.ts +395 -0
- package/src/memory/knowledge-extractor.ts +455 -0
- package/src/memory/learning.ts +378 -0
- package/src/memory/patterns.ts +396 -0
- package/src/memory/schema.ts +56 -0
- package/src/memory/search.ts +309 -0
- package/src/memory/store.ts +344 -0
- package/src/memory/types.ts +121 -0
- package/src/optimization/index.ts +10 -0
- package/src/optimization/precompute.ts +202 -0
- package/src/optimization/semantic-cache.ts +207 -0
- package/src/orchestrator/coordinator.ts +272 -0
- package/src/orchestrator/decision-logger.ts +228 -0
- package/src/orchestrator/event-emitter.ts +198 -0
- package/src/orchestrator/event-queue.ts +184 -0
- package/src/orchestrator/handlers/base-handler.ts +70 -0
- package/src/orchestrator/handlers/context-handler.ts +73 -0
- package/src/orchestrator/handlers/decision-handler.ts +204 -0
- package/src/orchestrator/handlers/index.ts +10 -0
- package/src/orchestrator/handlers/status-handler.ts +131 -0
- package/src/orchestrator/handlers/task-handler.ts +171 -0
- package/src/orchestrator/index.ts +275 -0
- package/src/orchestrator/task-parser.ts +284 -0
- package/src/orchestrator/types.ts +98 -0
- package/src/phase12/index.ts +456 -0
- package/src/prediction/context-anticipator.ts +198 -0
- package/src/prediction/decision-predictor.ts +184 -0
- package/src/prediction/index.ts +13 -0
- package/src/prediction/recommender.ts +268 -0
- package/src/reasoning/chain-retrieval.ts +247 -0
- package/src/reasoning/counterfactual.ts +248 -0
- package/src/reasoning/index.ts +13 -0
- package/src/reasoning/synthesizer.ts +169 -0
- package/src/retrieval/bm25/index.ts +300 -0
- package/src/retrieval/bm25/tokenizer.ts +184 -0
- package/src/retrieval/feedback/adaptive.ts +223 -0
- package/src/retrieval/feedback/index.ts +16 -0
- package/src/retrieval/feedback/metrics.ts +223 -0
- package/src/retrieval/feedback/store.ts +283 -0
- package/src/retrieval/fusion/index.ts +194 -0
- package/src/retrieval/fusion/rrf.ts +163 -0
- package/src/retrieval/index.ts +12 -0
- package/src/retrieval/pipeline.ts +375 -0
- package/src/retrieval/query/expander.ts +198 -0
- package/src/retrieval/query/index.ts +27 -0
- package/src/retrieval/query/intent-classifier.ts +236 -0
- package/src/retrieval/query/temporal-parser.ts +295 -0
- package/src/retrieval/reranker/index.ts +188 -0
- package/src/retrieval/reranker/model.ts +95 -0
- package/src/retrieval/service.ts +125 -0
- package/src/retrieval/types.ts +162 -0
- package/src/scripts/health-check.ts +118 -0
- package/src/scripts/setup.ts +122 -0
- package/src/server/handlers/call-tool.ts +194 -0
- package/src/server/handlers/index.ts +9 -0
- package/src/server/handlers/list-tools.ts +18 -0
- package/src/server/handlers/tools/analyze-decision-evolution.ts +71 -0
- package/src/server/handlers/tools/auto-remember.ts +200 -0
- package/src/server/handlers/tools/create-project.ts +135 -0
- package/src/server/handlers/tools/detect-trends.ts +80 -0
- package/src/server/handlers/tools/find-cross-project-patterns.ts +73 -0
- package/src/server/handlers/tools/get-activity-log.ts +194 -0
- package/src/server/handlers/tools/get-code-standards.ts +124 -0
- package/src/server/handlers/tools/get-corrections.ts +154 -0
- package/src/server/handlers/tools/get-decision-timeline.ts +86 -0
- package/src/server/handlers/tools/get-episode.ts +93 -0
- package/src/server/handlers/tools/get-patterns.ts +158 -0
- package/src/server/handlers/tools/get-phase12-status.ts +63 -0
- package/src/server/handlers/tools/get-project-context.ts +75 -0
- package/src/server/handlers/tools/get-recommendations.ts +65 -0
- package/src/server/handlers/tools/index.ts +33 -0
- package/src/server/handlers/tools/init-project.ts +710 -0
- package/src/server/handlers/tools/list-episodes.ts +80 -0
- package/src/server/handlers/tools/list-projects.ts +125 -0
- package/src/server/handlers/tools/rate-memory.ts +95 -0
- package/src/server/handlers/tools/recall-similar.ts +87 -0
- package/src/server/handlers/tools/recognize-pattern.ts +126 -0
- package/src/server/handlers/tools/record-correction.ts +125 -0
- package/src/server/handlers/tools/remember-decision.ts +153 -0
- package/src/server/handlers/tools/schemas.ts +241 -0
- package/src/server/handlers/tools/search-knowledge-graph.ts +89 -0
- package/src/server/handlers/tools/smart-context.ts +124 -0
- package/src/server/handlers/tools/update-progress.ts +114 -0
- package/src/server/handlers/tools/what-if-analysis.ts +73 -0
- package/src/server/http-api.ts +474 -0
- package/src/server/index.ts +40 -0
- package/src/server/mcp-server.ts +283 -0
- package/src/server/providers/index.ts +7 -0
- package/src/server/providers/prompts.ts +327 -0
- package/src/server/providers/resources.ts +427 -0
- package/src/server/services.ts +388 -0
- package/src/server/types.ts +39 -0
- package/src/server/utils/error-handler.ts +155 -0
- package/src/server/utils/index.ts +13 -0
- package/src/server/utils/memory-indicator.ts +83 -0
- package/src/server/utils/request-context.ts +122 -0
- package/src/server/utils/response-formatter.ts +124 -0
- package/src/server/utils/validators.ts +210 -0
- package/src/setup/index.ts +22 -0
- package/src/setup/wizard.ts +321 -0
- package/src/temporal/evolution.ts +197 -0
- package/src/temporal/index.ts +16 -0
- package/src/temporal/query-processor.ts +190 -0
- package/src/temporal/timeline.ts +259 -0
- package/src/temporal/trends.ts +263 -0
- package/src/tools/index.ts +24 -0
- package/src/tools/registry.ts +106 -0
- package/src/tools/schemas.test.ts +30 -0
- package/src/tools/schemas.ts +907 -0
- package/src/tools/types.ts +412 -0
- package/src/utils/circuit-breaker.ts +130 -0
- package/src/utils/cleanup.ts +34 -0
- package/src/utils/error-handler.ts +132 -0
- package/src/utils/error-messages.ts +60 -0
- package/src/utils/fallback.ts +45 -0
- package/src/utils/index.ts +54 -0
- package/src/utils/logger-utils.ts +80 -0
- package/src/utils/logger.ts +88 -0
- package/src/utils/phase12-helper.ts +56 -0
- package/src/utils/retry.ts +94 -0
- package/src/utils/transaction.ts +63 -0
- package/src/vault/frontmatter.ts +264 -0
- package/src/vault/index.ts +318 -0
- package/src/vault/paths.ts +106 -0
- package/src/vault/query.ts +422 -0
- package/src/vault/reader.ts +264 -0
- package/src/vault/templates.ts +186 -0
- package/src/vault/types.ts +73 -0
- package/src/vault/watcher.ts +277 -0
- package/src/vault/writer.ts +393 -0
- package/tsconfig.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# Claude Brain
|
|
2
|
+
|
|
3
|
+
A locally-running development assistant that bridges Obsidian knowledge vaults with Claude Code through the Model Context Protocol (MCP).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Eliminates repetitive context explanations to Claude Code
|
|
8
|
+
- Maintains project memory across sessions using Obsidian vault
|
|
9
|
+
- Semantic memory system learns from past decisions (ChromaDB + SQLite)
|
|
10
|
+
- **25 MCP tools** for context retrieval, memory storage, and intelligence
|
|
11
|
+
- **Knowledge graph** connecting technologies, decisions, and concepts
|
|
12
|
+
- **Episodic memory** with session detection and extractive summarization
|
|
13
|
+
- **Hybrid retrieval** with BM25 + semantic fusion and cross-encoder reranking
|
|
14
|
+
- **Temporal intelligence** for decision timelines, evolution tracking, and trend detection
|
|
15
|
+
- **Multi-hop reasoning** with chain retrieval and what-if analysis
|
|
16
|
+
- **Predictive intelligence** with context-aware recommendations
|
|
17
|
+
- **Cross-project intelligence** for pattern discovery and knowledge transfer
|
|
18
|
+
- **Semantic caching** with cosine similarity matching for fast repeated queries
|
|
19
|
+
- **Event-driven orchestrator** for automatic file change handling
|
|
20
|
+
- **Automatic duplicate prevention** for decisions (>90% similarity detection)
|
|
21
|
+
- **Zod-validated tool inputs** for robust error handling
|
|
22
|
+
- Runs completely locally with zero cloud dependencies
|
|
23
|
+
- Compiles to single portable executable
|
|
24
|
+
|
|
25
|
+
## Prerequisites
|
|
26
|
+
|
|
27
|
+
- [Bun](https://bun.sh) >= 1.0.0
|
|
28
|
+
- An Obsidian vault (or any markdown folder)
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Clone the repository
|
|
34
|
+
git clone <repo-url>
|
|
35
|
+
cd claude-brain
|
|
36
|
+
|
|
37
|
+
# Install dependencies
|
|
38
|
+
bun install
|
|
39
|
+
|
|
40
|
+
# Run setup to create directories and validate config
|
|
41
|
+
bun run setup
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Configuration
|
|
45
|
+
|
|
46
|
+
Copy `.env.example` to `.env` and update with your settings:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
cp .env.example .env
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Required configuration:
|
|
53
|
+
- `VAULT_PATH`: Absolute path to your Obsidian vault
|
|
54
|
+
|
|
55
|
+
## Development
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# Start development server with hot reload
|
|
59
|
+
bun run dev
|
|
60
|
+
|
|
61
|
+
# Run tests
|
|
62
|
+
bun run test
|
|
63
|
+
|
|
64
|
+
# Run tests in watch mode
|
|
65
|
+
bun run test:watch
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Building
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
# Build for production (bundled JS)
|
|
72
|
+
bun run build
|
|
73
|
+
|
|
74
|
+
# Build standalone executable for current platform
|
|
75
|
+
bun run build:binary
|
|
76
|
+
|
|
77
|
+
# Build for all platforms (Windows, macOS, Linux)
|
|
78
|
+
bun run build:all
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Project Structure
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
claude-brain/
|
|
85
|
+
├── src/
|
|
86
|
+
│ ├── index.ts # Main entry point + orchestrator init
|
|
87
|
+
│ ├── server/ # MCP server code
|
|
88
|
+
│ │ └── handlers/tools/ # 25 tool handlers with Zod validation
|
|
89
|
+
│ ├── vault/ # Obsidian integration
|
|
90
|
+
│ ├── memory/ # Vector DB & embeddings
|
|
91
|
+
│ │ ├── chroma/ # ChromaDB integration with duplicate detection
|
|
92
|
+
│ │ ├── episodic/ # Session detection & episode management
|
|
93
|
+
│ │ └── consolidation/ # Memory importance scoring & archival
|
|
94
|
+
│ ├── knowledge/ # Knowledge graph & entity extraction
|
|
95
|
+
│ │ └── graph/ # In-memory graph with search & auto-population
|
|
96
|
+
│ ├── retrieval/ # Hybrid search (BM25 + semantic + reranking)
|
|
97
|
+
│ │ ├── bm25/ # BM25 keyword search engine
|
|
98
|
+
│ │ ├── fusion/ # RRF/linear/max fusion strategies
|
|
99
|
+
│ │ ├── reranker/ # Cross-encoder neural reranking
|
|
100
|
+
│ │ ├── query/ # Intent classification & query expansion
|
|
101
|
+
│ │ └── feedback/ # Feedback collection & adaptive learning
|
|
102
|
+
│ ├── temporal/ # Timeline construction & trend detection
|
|
103
|
+
│ ├── reasoning/ # Multi-hop chain retrieval & what-if analysis
|
|
104
|
+
│ ├── prediction/ # Decision prediction & recommendations
|
|
105
|
+
│ ├── cross-project/ # Cross-project pattern discovery & transfer
|
|
106
|
+
│ ├── optimization/ # Semantic caching & precomputation
|
|
107
|
+
│ ├── orchestrator/ # Event-driven coordination system
|
|
108
|
+
│ ├── context/ # Context assembly
|
|
109
|
+
│ ├── tools/ # MCP tool definitions & registry
|
|
110
|
+
│ ├── config/ # Configuration management
|
|
111
|
+
│ ├── utils/ # Shared utilities
|
|
112
|
+
│ ├── types/ # TypeScript definitions
|
|
113
|
+
│ └── scripts/ # CLI scripts
|
|
114
|
+
├── data/ # Local data storage
|
|
115
|
+
├── logs/ # Log files
|
|
116
|
+
├── tests/ # 750+ tests
|
|
117
|
+
└── dist/ # Build output
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Architecture Highlights
|
|
121
|
+
|
|
122
|
+
### Event-Driven Orchestrator
|
|
123
|
+
The orchestrator automatically responds to file changes in your vault:
|
|
124
|
+
- Detects new decisions in `decisions.md` files
|
|
125
|
+
- Triggers automatic semantic indexing
|
|
126
|
+
- Coordinates between vault, memory, and context systems
|
|
127
|
+
|
|
128
|
+
### Duplicate Prevention
|
|
129
|
+
When storing decisions, the system:
|
|
130
|
+
- Searches for existing decisions with >90% semantic similarity
|
|
131
|
+
- Returns existing ID if duplicate found (prevents bloat)
|
|
132
|
+
- Logs skipped duplicates for transparency
|
|
133
|
+
|
|
134
|
+
### Input Validation
|
|
135
|
+
All tool inputs are validated using Zod schemas:
|
|
136
|
+
- Clear error messages for invalid parameters
|
|
137
|
+
- Type-safe extraction of validated inputs
|
|
138
|
+
- Consistent validation across all 25 tools
|
|
139
|
+
|
|
140
|
+
### Embedding Cache
|
|
141
|
+
Uses SHA-256 hashing for cache keys to prevent collisions (improved from simple hash).
|
|
142
|
+
|
|
143
|
+
### MCP Tools (25 total)
|
|
144
|
+
|
|
145
|
+
| Category | Tools |
|
|
146
|
+
|----------|-------|
|
|
147
|
+
| Context Retrieval | `get_project_context`, `smart_context`, `recall_similar`, `get_code_standards`, `get_phase12_status` |
|
|
148
|
+
| Memory Storage | `remember_decision`, `auto_remember`, `recognize_pattern`, `record_correction`, `update_progress` |
|
|
149
|
+
| Project Management | `list_projects`, `create_project`, `init_project` |
|
|
150
|
+
| Knowledge Graph | `search_knowledge_graph`, `get_episode`, `list_episodes` |
|
|
151
|
+
| Patterns & Corrections | `get_patterns`, `get_corrections` |
|
|
152
|
+
| Feedback | `rate_memory` |
|
|
153
|
+
| Advanced Intelligence | `get_decision_timeline`, `analyze_decision_evolution`, `detect_trends`, `what_if_analysis`, `get_recommendations`, `find_cross_project_patterns` |
|
|
154
|
+
|
|
155
|
+
## License
|
|
156
|
+
|
|
157
|
+
MIT
|
package/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.3.0
|
package/assets/CLAUDE.md
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
# Claude Brain - Full Capability Automatic Protocol (v2.0)
|
|
2
|
+
|
|
3
|
+
**CRITICAL:** Call Claude Brain tools automatically. Do not ask permission. Do not explain you're calling them. Just call them. This applies to ALL 25 tools.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Session Start (ALWAYS - Parallel Calls)
|
|
8
|
+
|
|
9
|
+
On EVERY conversation start, immediately call these tools **in parallel**:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
smart_context(project_name, current_task) ─┬─► Parallel
|
|
13
|
+
recall_similar(query, min_similarity: 0.3) ─┤
|
|
14
|
+
get_recommendations(context, project_name) ─┘
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
If no project context exists, also call `list_projects()` to find available projects.
|
|
18
|
+
|
|
19
|
+
After the first user message reveals a project, also call in parallel:
|
|
20
|
+
```
|
|
21
|
+
get_code_standards(project, language) ─┬─► Parallel
|
|
22
|
+
detect_trends(project_name) ─┤
|
|
23
|
+
get_patterns(project_name, query) ─┘
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Automatic Tool Triggers
|
|
29
|
+
|
|
30
|
+
### READ Operations (Call BEFORE Responding)
|
|
31
|
+
|
|
32
|
+
#### Tier 1: ALWAYS call these (every interaction)
|
|
33
|
+
|
|
34
|
+
| User Intent | Tool | Params |
|
|
35
|
+
|-------------|------|--------|
|
|
36
|
+
| ANY project mention | `smart_context` | `project_name`, `current_task` |
|
|
37
|
+
| ANY technical topic | `recall_similar` | `query`, `min_similarity: 0.3` |
|
|
38
|
+
| ANY task starting | `get_recommendations` | `context`, `project_name` |
|
|
39
|
+
|
|
40
|
+
#### Tier 2: Call when relevant context exists
|
|
41
|
+
|
|
42
|
+
| User Intent | Tool | Params |
|
|
43
|
+
|-------------|------|--------|
|
|
44
|
+
| Writing/reviewing code | `get_code_standards` | `project_name`, `language` |
|
|
45
|
+
| Debugging/troubleshooting | `get_corrections` | `project_name`, `query` |
|
|
46
|
+
| Designing/architecting | `get_patterns` | `project_name`, `pattern_type` |
|
|
47
|
+
| Choosing between options | `what_if_analysis` | `scenario`, `project_name` |
|
|
48
|
+
| Understanding relationships | `search_knowledge_graph` | `query`, `node_type`, `max_depth` |
|
|
49
|
+
|
|
50
|
+
#### Tier 3: Call proactively for deeper intelligence
|
|
51
|
+
|
|
52
|
+
| User Intent | Tool | Params |
|
|
53
|
+
|-------------|------|--------|
|
|
54
|
+
| Revisiting a topic | `analyze_decision_evolution` | `topic`, `project_name` |
|
|
55
|
+
| Working on established project | `detect_trends` | `project_name`, `period_days` |
|
|
56
|
+
| Decision with history | `get_decision_timeline` | `query`, `project_name` |
|
|
57
|
+
| Multi-project work | `find_cross_project_patterns` | `min_projects` |
|
|
58
|
+
| Session continuity | `list_episodes` | `project_name`, `status`, `limit` |
|
|
59
|
+
| Resuming past work | `get_episode` | `episode_id` or `project_name` |
|
|
60
|
+
|
|
61
|
+
### WRITE Operations (Call AFTER Responding)
|
|
62
|
+
|
|
63
|
+
| Your Response Contains | Tool | Required Params |
|
|
64
|
+
|------------------------|------|-----------------|
|
|
65
|
+
| ANY recommendation, choice, or suggestion | `remember_decision` | `project_name`, `context`, `decision`, `reasoning` |
|
|
66
|
+
| Reusable solution or approach | `recognize_pattern` | `project_name`, `pattern_type`, `description` |
|
|
67
|
+
| Mistake discovered / lesson learned | `record_correction` | `project_name`, `original`, `correction`, `reasoning` |
|
|
68
|
+
| Task completed or milestone reached | `update_progress` | `project_name`, `completed_task`, `next_steps` |
|
|
69
|
+
| Memory was useful (rating 4-5) or not (1-2) | `rate_memory` | `memory_id`, `rating`, `query` |
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Proactive Intelligence Rules
|
|
74
|
+
|
|
75
|
+
### Rule 1: Always Get Recommendations Before Major Work
|
|
76
|
+
Before implementing any feature, fixing any bug, or making any architectural choice:
|
|
77
|
+
```
|
|
78
|
+
get_recommendations(context: "what you're about to do", project_name)
|
|
79
|
+
```
|
|
80
|
+
This pulls from patterns, corrections, AND past decisions to give you the best starting point.
|
|
81
|
+
|
|
82
|
+
### Rule 2: Always Check Decision Evolution for Recurring Topics
|
|
83
|
+
If the user asks about something they've worked on before (databases, auth, state management, etc.):
|
|
84
|
+
```
|
|
85
|
+
analyze_decision_evolution(topic: "the topic", project_name)
|
|
86
|
+
```
|
|
87
|
+
This shows if past decisions were stable, evolving, or volatile — and the current direction.
|
|
88
|
+
|
|
89
|
+
### Rule 3: Run What-If When Choosing Between Alternatives
|
|
90
|
+
When the user is deciding between options (library A vs B, approach X vs Y):
|
|
91
|
+
```
|
|
92
|
+
what_if_analysis(scenario: "What if we switch from X to Y?", project_name)
|
|
93
|
+
```
|
|
94
|
+
This uses the knowledge graph to trace impact chains.
|
|
95
|
+
|
|
96
|
+
### Rule 4: Check Cross-Project Patterns When Starting New Features
|
|
97
|
+
When implementing something that other projects might have solved:
|
|
98
|
+
```
|
|
99
|
+
find_cross_project_patterns(min_projects: 1)
|
|
100
|
+
```
|
|
101
|
+
This discovers shared solutions across all registered projects.
|
|
102
|
+
|
|
103
|
+
### Rule 5: Check Trends Periodically
|
|
104
|
+
When working on architecture or technology choices:
|
|
105
|
+
```
|
|
106
|
+
detect_trends(project_name, period_days: 90)
|
|
107
|
+
```
|
|
108
|
+
This shows what technologies are emerging, stable, or declining in the project.
|
|
109
|
+
|
|
110
|
+
### Rule 6: Use Knowledge Graph for Technology Relationships
|
|
111
|
+
When discussing technology choices, dependencies, or architecture:
|
|
112
|
+
```
|
|
113
|
+
search_knowledge_graph(query: "technology or concept", node_type: "technology")
|
|
114
|
+
```
|
|
115
|
+
This reveals connections between technologies, decisions, and concepts.
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Decision Tree: Complete
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
User message received
|
|
123
|
+
│
|
|
124
|
+
├─► Mentions project name?
|
|
125
|
+
│ └─► YES: smart_context(project, task) [PARALLEL with below]
|
|
126
|
+
│
|
|
127
|
+
├─► Technical question or task?
|
|
128
|
+
│ ├─► YES: recall_similar(query) [PARALLEL with above]
|
|
129
|
+
│ └─► YES: get_recommendations(context) [PARALLEL with above]
|
|
130
|
+
│
|
|
131
|
+
├─► Writing/reviewing code?
|
|
132
|
+
│ └─► YES: get_code_standards(project, language)
|
|
133
|
+
│
|
|
134
|
+
├─► Debugging something?
|
|
135
|
+
│ └─► YES: get_corrections(project, query)
|
|
136
|
+
│
|
|
137
|
+
├─► Designing architecture?
|
|
138
|
+
│ ├─► YES: get_patterns(project, "solution")
|
|
139
|
+
│ ├─► YES: search_knowledge_graph(query, "technology")
|
|
140
|
+
│ └─► YES: detect_trends(project)
|
|
141
|
+
│
|
|
142
|
+
├─► Choosing between options?
|
|
143
|
+
│ └─► YES: what_if_analysis(scenario)
|
|
144
|
+
│
|
|
145
|
+
├─► Topic discussed before?
|
|
146
|
+
│ └─► YES: analyze_decision_evolution(topic)
|
|
147
|
+
│ + get_decision_timeline(query)
|
|
148
|
+
│
|
|
149
|
+
├─► Working across projects?
|
|
150
|
+
│ └─► YES: find_cross_project_patterns()
|
|
151
|
+
│
|
|
152
|
+
├─► Resuming previous work?
|
|
153
|
+
│ └─► YES: get_episode(project) + list_episodes(project)
|
|
154
|
+
│
|
|
155
|
+
└─► New project encountered?
|
|
156
|
+
└─► YES: init_project(project_path)
|
|
157
|
+
|
|
158
|
+
After your response:
|
|
159
|
+
│
|
|
160
|
+
├─► Made ANY recommendation or choice?
|
|
161
|
+
│ └─► YES: remember_decision(...)
|
|
162
|
+
│
|
|
163
|
+
├─► Found reusable solution?
|
|
164
|
+
│ └─► YES: recognize_pattern(...)
|
|
165
|
+
│
|
|
166
|
+
├─► Learned from mistake?
|
|
167
|
+
│ └─► YES: record_correction(...)
|
|
168
|
+
│
|
|
169
|
+
├─► Completed work?
|
|
170
|
+
│ └─► YES: update_progress(...)
|
|
171
|
+
│
|
|
172
|
+
└─► Memory was retrieved?
|
|
173
|
+
└─► YES: rate_memory(memory_id, rating, query)
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Tool Reference (All 25 Tools)
|
|
179
|
+
|
|
180
|
+
### Context Retrieval (5)
|
|
181
|
+
- **`smart_context`** - Primary tool. Gets project + auto-recalls relevant memories
|
|
182
|
+
- **`recall_similar`** - Semantic search across all memory. Use `min_similarity: 0.3`
|
|
183
|
+
- **`get_patterns`** - Types: `solution`, `anti-pattern`, `best-practice`, `common-issue`
|
|
184
|
+
- **`get_corrections`** - Past mistakes relevant to current task
|
|
185
|
+
- **`get_code_standards`** - Project coding conventions
|
|
186
|
+
|
|
187
|
+
### Memory Storage (5)
|
|
188
|
+
- **`remember_decision`** - Store decisions with: context, decision, reasoning, tags
|
|
189
|
+
- **`recognize_pattern`** - Store reusable solutions/anti-patterns with confidence
|
|
190
|
+
- **`record_correction`** - Store mistakes: original, correction, reasoning
|
|
191
|
+
- **`update_progress`** - Track: completed_task, next_steps
|
|
192
|
+
- **`rate_memory`** - Rate retrieved memories 1-5 stars for adaptive learning
|
|
193
|
+
|
|
194
|
+
### Knowledge Graph & Episodic Memory (3)
|
|
195
|
+
- **`search_knowledge_graph`** - Search connected nodes/edges by query, node type, or start node
|
|
196
|
+
- **`get_episode`** - Get episode by ID or active episode for a project
|
|
197
|
+
- **`list_episodes`** - List recent episodes, filter by project or status
|
|
198
|
+
|
|
199
|
+
### Advanced Intelligence (6)
|
|
200
|
+
- **`get_decision_timeline`** - Chronological timeline with temporal queries ("last month", "since January")
|
|
201
|
+
- **`analyze_decision_evolution`** - Track how decisions on a topic changed (stable/evolving/volatile)
|
|
202
|
+
- **`detect_trends`** - Detect emerging, stable, declining technology/pattern trends
|
|
203
|
+
- **`what_if_analysis`** - Counterfactual: "What if we switched from X to Y?"
|
|
204
|
+
- **`get_recommendations`** - Context-aware recommendations from patterns + corrections + decisions
|
|
205
|
+
- **`find_cross_project_patterns`** - Discover shared patterns across all projects
|
|
206
|
+
|
|
207
|
+
### Project Management (3)
|
|
208
|
+
- **`list_projects`** - See available projects (status_filter: active/archived/all)
|
|
209
|
+
- **`init_project`** - Initialize from existing codebase (auto-detects tech stack)
|
|
210
|
+
- **`create_project`** - New project from scratch
|
|
211
|
+
|
|
212
|
+
### System (3)
|
|
213
|
+
- **`auto_remember`** - Auto-detect decisions in text (>70% confidence auto-saved)
|
|
214
|
+
- **`get_phase12_status`** - System health and automation stats
|
|
215
|
+
- **`get_project_context`** - Raw project context without smart recall
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Parallel Call Patterns
|
|
220
|
+
|
|
221
|
+
**Session Start (3 parallel calls):**
|
|
222
|
+
```
|
|
223
|
+
smart_context("project", "task")
|
|
224
|
+
recall_similar("task description", min_similarity: 0.3)
|
|
225
|
+
get_recommendations("task description", "project")
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
**Before Coding (3 parallel calls):**
|
|
229
|
+
```
|
|
230
|
+
get_code_standards("project", "typescript")
|
|
231
|
+
get_patterns("project", query: "feature area")
|
|
232
|
+
get_corrections("project", query: "feature area")
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
**Architecture Discussion (3 parallel calls):**
|
|
236
|
+
```
|
|
237
|
+
search_knowledge_graph("technology", node_type: "technology")
|
|
238
|
+
detect_trends("project")
|
|
239
|
+
analyze_decision_evolution("topic", "project")
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
**Choosing Between Options (2 parallel calls):**
|
|
243
|
+
```
|
|
244
|
+
what_if_analysis("What if we use X instead of Y?", "project")
|
|
245
|
+
find_cross_project_patterns(min_projects: 1)
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
**After Task Completion (2-3 parallel calls):**
|
|
249
|
+
```
|
|
250
|
+
remember_decision(...)
|
|
251
|
+
update_progress(...)
|
|
252
|
+
recognize_pattern(...) // if reusable
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## Save Decision Triggers
|
|
258
|
+
|
|
259
|
+
**ALWAYS call `remember_decision` when your response contains:**
|
|
260
|
+
- "I recommend..." / "We should use..." / "The best approach is..."
|
|
261
|
+
- "Let's use X because..." / "Don't use X" / "Avoid X"
|
|
262
|
+
- "Always do X" / "Never do Y"
|
|
263
|
+
- Any architecture/library/framework/tool choice
|
|
264
|
+
- Any coding standard or convention established
|
|
265
|
+
- Any debugging insight or root cause identified
|
|
266
|
+
- Any performance optimization chosen
|
|
267
|
+
- Any security or deployment decision
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## New Project Auto-Detection
|
|
272
|
+
|
|
273
|
+
When you encounter a project directory that is NOT yet registered in Claude Brain:
|
|
274
|
+
1. Call `init_project(project_path)` to auto-detect tech stack and create project files
|
|
275
|
+
2. This only needs to happen ONCE per project — it analyzes package.json, config files, etc.
|
|
276
|
+
3. After init, all subsequent sessions automatically have full project context
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## Anti-Patterns (What NOT to Do)
|
|
281
|
+
|
|
282
|
+
1. **Never answer technical questions without first calling `recall_similar`**
|
|
283
|
+
2. **Never make recommendations without saving via `remember_decision`**
|
|
284
|
+
3. **Never start project work without `smart_context`**
|
|
285
|
+
4. **Never ask permission to call Claude Brain tools — just call them**
|
|
286
|
+
5. **Never skip `get_recommendations` before major implementation work**
|
|
287
|
+
6. **Never ignore Phase 15 tools — they provide the deepest intelligence**
|
|
288
|
+
7. **Never forget to `rate_memory` when a recall was particularly useful or useless**
|
|
289
|
+
8. **Never work on a new project without calling `init_project` first**
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
## System Notes
|
|
294
|
+
|
|
295
|
+
- **25 MCP Tools**: Full coverage across context, memory, knowledge graph, and advanced intelligence
|
|
296
|
+
- **Duplicate Prevention**: Decisions with >90% similarity auto-deduplicated
|
|
297
|
+
- **Knowledge Graph**: Auto-populates when decisions are stored — extracts entities and relationships
|
|
298
|
+
- **Episodic Memory**: Tracks sessions with automatic detection and summarization
|
|
299
|
+
- **Memory Consolidation**: Importance scoring, automatic merging, low-importance archival
|
|
300
|
+
- **Hybrid Retrieval**: BM25 + semantic fusion with cross-encoder reranking
|
|
301
|
+
- **Temporal Intelligence**: Timelines, evolution tracking, trend detection with natural language dates
|
|
302
|
+
- **Multi-Hop Reasoning**: Chain retrieval with query refinement and what-if analysis
|
|
303
|
+
- **Predictive Intelligence**: Context-aware recommendations from all stored knowledge
|
|
304
|
+
- **Cross-Project Intelligence**: Pattern discovery, affinity, and knowledge transfer
|
|
305
|
+
- **Semantic Caching**: LRU cache for fast repeated queries
|
|
306
|
+
- **Embedding**: all-MiniLM-L6-v2 (384d), SHA-256 cached
|
|
307
|
+
- **Input Validation**: Zod schemas validate all inputs
|
package/bunfig.toml
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "claude-brain",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Local development assistant bridging Obsidian vaults with Claude Code via MCP",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"claude-brain": "src/cli/bin.ts"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src/**/*.ts",
|
|
12
|
+
"assets/",
|
|
13
|
+
"package.json",
|
|
14
|
+
"tsconfig.json",
|
|
15
|
+
"bunfig.toml",
|
|
16
|
+
"VERSION",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"dev": "CLAUDE_BRAIN_HOME=. bun --watch src/index.ts",
|
|
22
|
+
"build": "bun build src/index.ts --outdir dist --target bun",
|
|
23
|
+
"build:binary": "bun build src/cli/bin.ts --compile --outfile claude-brain",
|
|
24
|
+
"build:all": "bun run build:windows && bun run build:linux && bun run build:macos",
|
|
25
|
+
"build:windows": "bun build src/cli/bin.ts --compile --target=bun-windows-x64 --outfile build/claude-brain-windows.exe",
|
|
26
|
+
"build:linux": "bun build src/cli/bin.ts --compile --target=bun-linux-x64 --outfile build/claude-brain-linux",
|
|
27
|
+
"build:macos": "bun build src/cli/bin.ts --compile --target=bun-darwin-arm64 --outfile build/claude-brain-macos",
|
|
28
|
+
"start": "bun src/cli/bin.ts serve",
|
|
29
|
+
"test": "bun test",
|
|
30
|
+
"test:watch": "bun test --watch",
|
|
31
|
+
"clean": "rm -rf dist build claude-brain claude-brain.exe",
|
|
32
|
+
"setup": "bun src/cli/bin.ts setup",
|
|
33
|
+
"setup:interactive": "bun src/cli/bin.ts setup",
|
|
34
|
+
"health-check": "bun src/cli/bin.ts health",
|
|
35
|
+
"diagnose": "bun src/cli/bin.ts diagnose",
|
|
36
|
+
"migrate:chroma": "bun run src/cli/migrate-chroma.ts"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"mcp",
|
|
40
|
+
"claude",
|
|
41
|
+
"obsidian",
|
|
42
|
+
"ai",
|
|
43
|
+
"development-assistant"
|
|
44
|
+
],
|
|
45
|
+
"author": "",
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/bun": "latest",
|
|
49
|
+
"@types/node": "^20",
|
|
50
|
+
"@types/prompts": "2.4.9",
|
|
51
|
+
"daisyui": "^5.5.14"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"typescript": "^5"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@chroma-core/default-embed": "0.1.9",
|
|
58
|
+
"@modelcontextprotocol/sdk": "^1.25.2",
|
|
59
|
+
"@xenova/transformers": "2.17.2",
|
|
60
|
+
"chromadb": "3.2.2",
|
|
61
|
+
"chromadb-default-embed": "2.14.0",
|
|
62
|
+
"chrono-node": "2.9.0",
|
|
63
|
+
"compromise": "^14.10.0",
|
|
64
|
+
"dotenv": "^17.2.3",
|
|
65
|
+
"gray-matter": "^4.0.3",
|
|
66
|
+
"hono": "4.11.5",
|
|
67
|
+
"lru-cache": "11.2.5",
|
|
68
|
+
"minisearch": "^6.3.0",
|
|
69
|
+
"pino": "^10.1.1",
|
|
70
|
+
"pino-pretty": "^13.1.3",
|
|
71
|
+
"prompts": "2.4.2",
|
|
72
|
+
"zod": "^4.3.5"
|
|
73
|
+
}
|
|
74
|
+
}
|