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.
Files changed (200) hide show
  1. package/README.md +157 -0
  2. package/VERSION +1 -0
  3. package/assets/CLAUDE.md +307 -0
  4. package/bunfig.toml +8 -0
  5. package/package.json +74 -0
  6. package/src/automation/auto-context.ts +240 -0
  7. package/src/automation/decision-detector.ts +452 -0
  8. package/src/automation/index.ts +11 -0
  9. package/src/automation/proactive-recall.ts +373 -0
  10. package/src/automation/project-detector.ts +297 -0
  11. package/src/cli/auto-setup.ts +74 -0
  12. package/src/cli/bin.ts +110 -0
  13. package/src/cli/commands/install-mcp.ts +50 -0
  14. package/src/cli/commands/serve.ts +129 -0
  15. package/src/cli/diagnose.ts +4 -0
  16. package/src/cli/health-check.ts +4 -0
  17. package/src/cli/migrate-chroma.ts +106 -0
  18. package/src/cli/setup.ts +4 -0
  19. package/src/config/defaults.ts +47 -0
  20. package/src/config/home.ts +55 -0
  21. package/src/config/index.ts +7 -0
  22. package/src/config/loader.ts +166 -0
  23. package/src/config/migration.ts +76 -0
  24. package/src/config/schema.ts +257 -0
  25. package/src/config/validator.ts +184 -0
  26. package/src/config/watcher.ts +86 -0
  27. package/src/context/assembler.ts +398 -0
  28. package/src/context/cache-manager.ts +101 -0
  29. package/src/context/formatter.ts +84 -0
  30. package/src/context/hierarchy.ts +85 -0
  31. package/src/context/index.ts +83 -0
  32. package/src/context/progress-tracker.ts +174 -0
  33. package/src/context/standards-manager.ts +267 -0
  34. package/src/context/types.ts +252 -0
  35. package/src/context/validator.ts +58 -0
  36. package/src/cross-project/affinity.ts +162 -0
  37. package/src/cross-project/generalizer.ts +283 -0
  38. package/src/cross-project/index.ts +13 -0
  39. package/src/cross-project/transfer.ts +201 -0
  40. package/src/diagnostics/index.ts +123 -0
  41. package/src/health/index.ts +229 -0
  42. package/src/index.ts +7 -0
  43. package/src/knowledge/entity-extractor.ts +416 -0
  44. package/src/knowledge/graph/builder.ts +159 -0
  45. package/src/knowledge/graph/linker.ts +201 -0
  46. package/src/knowledge/graph/memory-graph.ts +359 -0
  47. package/src/knowledge/graph/schema.ts +99 -0
  48. package/src/knowledge/graph/search.ts +168 -0
  49. package/src/knowledge/relationship-extractor.ts +108 -0
  50. package/src/memory/chroma/client.ts +169 -0
  51. package/src/memory/chroma/collection-manager.ts +94 -0
  52. package/src/memory/chroma/config.ts +46 -0
  53. package/src/memory/chroma/embeddings.ts +153 -0
  54. package/src/memory/chroma/index.ts +82 -0
  55. package/src/memory/chroma/migration.ts +270 -0
  56. package/src/memory/chroma/schemas.ts +69 -0
  57. package/src/memory/chroma/search.ts +315 -0
  58. package/src/memory/chroma/store.ts +694 -0
  59. package/src/memory/consolidation/archiver.ts +164 -0
  60. package/src/memory/consolidation/merger.ts +186 -0
  61. package/src/memory/consolidation/scorer.ts +138 -0
  62. package/src/memory/context-builder.ts +236 -0
  63. package/src/memory/database.ts +169 -0
  64. package/src/memory/embedding-utils.ts +156 -0
  65. package/src/memory/embeddings.ts +226 -0
  66. package/src/memory/episodic/detector.ts +108 -0
  67. package/src/memory/episodic/manager.ts +334 -0
  68. package/src/memory/episodic/summarizer.ts +179 -0
  69. package/src/memory/episodic/types.ts +52 -0
  70. package/src/memory/index.ts +395 -0
  71. package/src/memory/knowledge-extractor.ts +455 -0
  72. package/src/memory/learning.ts +378 -0
  73. package/src/memory/patterns.ts +396 -0
  74. package/src/memory/schema.ts +56 -0
  75. package/src/memory/search.ts +309 -0
  76. package/src/memory/store.ts +344 -0
  77. package/src/memory/types.ts +121 -0
  78. package/src/optimization/index.ts +10 -0
  79. package/src/optimization/precompute.ts +202 -0
  80. package/src/optimization/semantic-cache.ts +207 -0
  81. package/src/orchestrator/coordinator.ts +272 -0
  82. package/src/orchestrator/decision-logger.ts +228 -0
  83. package/src/orchestrator/event-emitter.ts +198 -0
  84. package/src/orchestrator/event-queue.ts +184 -0
  85. package/src/orchestrator/handlers/base-handler.ts +70 -0
  86. package/src/orchestrator/handlers/context-handler.ts +73 -0
  87. package/src/orchestrator/handlers/decision-handler.ts +204 -0
  88. package/src/orchestrator/handlers/index.ts +10 -0
  89. package/src/orchestrator/handlers/status-handler.ts +131 -0
  90. package/src/orchestrator/handlers/task-handler.ts +171 -0
  91. package/src/orchestrator/index.ts +275 -0
  92. package/src/orchestrator/task-parser.ts +284 -0
  93. package/src/orchestrator/types.ts +98 -0
  94. package/src/phase12/index.ts +456 -0
  95. package/src/prediction/context-anticipator.ts +198 -0
  96. package/src/prediction/decision-predictor.ts +184 -0
  97. package/src/prediction/index.ts +13 -0
  98. package/src/prediction/recommender.ts +268 -0
  99. package/src/reasoning/chain-retrieval.ts +247 -0
  100. package/src/reasoning/counterfactual.ts +248 -0
  101. package/src/reasoning/index.ts +13 -0
  102. package/src/reasoning/synthesizer.ts +169 -0
  103. package/src/retrieval/bm25/index.ts +300 -0
  104. package/src/retrieval/bm25/tokenizer.ts +184 -0
  105. package/src/retrieval/feedback/adaptive.ts +223 -0
  106. package/src/retrieval/feedback/index.ts +16 -0
  107. package/src/retrieval/feedback/metrics.ts +223 -0
  108. package/src/retrieval/feedback/store.ts +283 -0
  109. package/src/retrieval/fusion/index.ts +194 -0
  110. package/src/retrieval/fusion/rrf.ts +163 -0
  111. package/src/retrieval/index.ts +12 -0
  112. package/src/retrieval/pipeline.ts +375 -0
  113. package/src/retrieval/query/expander.ts +198 -0
  114. package/src/retrieval/query/index.ts +27 -0
  115. package/src/retrieval/query/intent-classifier.ts +236 -0
  116. package/src/retrieval/query/temporal-parser.ts +295 -0
  117. package/src/retrieval/reranker/index.ts +188 -0
  118. package/src/retrieval/reranker/model.ts +95 -0
  119. package/src/retrieval/service.ts +125 -0
  120. package/src/retrieval/types.ts +162 -0
  121. package/src/scripts/health-check.ts +118 -0
  122. package/src/scripts/setup.ts +122 -0
  123. package/src/server/handlers/call-tool.ts +194 -0
  124. package/src/server/handlers/index.ts +9 -0
  125. package/src/server/handlers/list-tools.ts +18 -0
  126. package/src/server/handlers/tools/analyze-decision-evolution.ts +71 -0
  127. package/src/server/handlers/tools/auto-remember.ts +200 -0
  128. package/src/server/handlers/tools/create-project.ts +135 -0
  129. package/src/server/handlers/tools/detect-trends.ts +80 -0
  130. package/src/server/handlers/tools/find-cross-project-patterns.ts +73 -0
  131. package/src/server/handlers/tools/get-activity-log.ts +194 -0
  132. package/src/server/handlers/tools/get-code-standards.ts +124 -0
  133. package/src/server/handlers/tools/get-corrections.ts +154 -0
  134. package/src/server/handlers/tools/get-decision-timeline.ts +86 -0
  135. package/src/server/handlers/tools/get-episode.ts +93 -0
  136. package/src/server/handlers/tools/get-patterns.ts +158 -0
  137. package/src/server/handlers/tools/get-phase12-status.ts +63 -0
  138. package/src/server/handlers/tools/get-project-context.ts +75 -0
  139. package/src/server/handlers/tools/get-recommendations.ts +65 -0
  140. package/src/server/handlers/tools/index.ts +33 -0
  141. package/src/server/handlers/tools/init-project.ts +710 -0
  142. package/src/server/handlers/tools/list-episodes.ts +80 -0
  143. package/src/server/handlers/tools/list-projects.ts +125 -0
  144. package/src/server/handlers/tools/rate-memory.ts +95 -0
  145. package/src/server/handlers/tools/recall-similar.ts +87 -0
  146. package/src/server/handlers/tools/recognize-pattern.ts +126 -0
  147. package/src/server/handlers/tools/record-correction.ts +125 -0
  148. package/src/server/handlers/tools/remember-decision.ts +153 -0
  149. package/src/server/handlers/tools/schemas.ts +241 -0
  150. package/src/server/handlers/tools/search-knowledge-graph.ts +89 -0
  151. package/src/server/handlers/tools/smart-context.ts +124 -0
  152. package/src/server/handlers/tools/update-progress.ts +114 -0
  153. package/src/server/handlers/tools/what-if-analysis.ts +73 -0
  154. package/src/server/http-api.ts +474 -0
  155. package/src/server/index.ts +40 -0
  156. package/src/server/mcp-server.ts +283 -0
  157. package/src/server/providers/index.ts +7 -0
  158. package/src/server/providers/prompts.ts +327 -0
  159. package/src/server/providers/resources.ts +427 -0
  160. package/src/server/services.ts +388 -0
  161. package/src/server/types.ts +39 -0
  162. package/src/server/utils/error-handler.ts +155 -0
  163. package/src/server/utils/index.ts +13 -0
  164. package/src/server/utils/memory-indicator.ts +83 -0
  165. package/src/server/utils/request-context.ts +122 -0
  166. package/src/server/utils/response-formatter.ts +124 -0
  167. package/src/server/utils/validators.ts +210 -0
  168. package/src/setup/index.ts +22 -0
  169. package/src/setup/wizard.ts +321 -0
  170. package/src/temporal/evolution.ts +197 -0
  171. package/src/temporal/index.ts +16 -0
  172. package/src/temporal/query-processor.ts +190 -0
  173. package/src/temporal/timeline.ts +259 -0
  174. package/src/temporal/trends.ts +263 -0
  175. package/src/tools/index.ts +24 -0
  176. package/src/tools/registry.ts +106 -0
  177. package/src/tools/schemas.test.ts +30 -0
  178. package/src/tools/schemas.ts +907 -0
  179. package/src/tools/types.ts +412 -0
  180. package/src/utils/circuit-breaker.ts +130 -0
  181. package/src/utils/cleanup.ts +34 -0
  182. package/src/utils/error-handler.ts +132 -0
  183. package/src/utils/error-messages.ts +60 -0
  184. package/src/utils/fallback.ts +45 -0
  185. package/src/utils/index.ts +54 -0
  186. package/src/utils/logger-utils.ts +80 -0
  187. package/src/utils/logger.ts +88 -0
  188. package/src/utils/phase12-helper.ts +56 -0
  189. package/src/utils/retry.ts +94 -0
  190. package/src/utils/transaction.ts +63 -0
  191. package/src/vault/frontmatter.ts +264 -0
  192. package/src/vault/index.ts +318 -0
  193. package/src/vault/paths.ts +106 -0
  194. package/src/vault/query.ts +422 -0
  195. package/src/vault/reader.ts +264 -0
  196. package/src/vault/templates.ts +186 -0
  197. package/src/vault/types.ts +73 -0
  198. package/src/vault/watcher.ts +277 -0
  199. package/src/vault/writer.ts +393 -0
  200. package/tsconfig.json +30 -0
@@ -0,0 +1,907 @@
1
+ /**
2
+ * MCP Tool Schemas
3
+ * Defines all available tools that Claude Code can call
4
+ *
5
+ * Each tool has:
6
+ * - name: Unique identifier for the tool
7
+ * - description: Explains when and how to use the tool
8
+ * - inputSchema: JSON Schema for validating input parameters
9
+ */
10
+
11
+ /** Tool definition type */
12
+ interface ToolDefinition {
13
+ name: string
14
+ description: string
15
+ inputSchema: {
16
+ type: 'object'
17
+ properties: Record<string, unknown>
18
+ required?: string[]
19
+ }
20
+ }
21
+
22
+ /**
23
+ * All available tools for Claude Brain MCP server
24
+ */
25
+ export const TOOLS = {
26
+ /**
27
+ * GET_PROJECT_CONTEXT
28
+ * Primary tool for retrieving complete project context
29
+ *
30
+ * Use this when:
31
+ * - Starting work on a project
32
+ * - Need to understand project standards and conventions
33
+ * - Want to see recent decisions and progress
34
+ *
35
+ * Returns: Project description, standards, progress, and optionally relevant memories
36
+ */
37
+ GET_PROJECT_CONTEXT: {
38
+ name: 'get_project_context',
39
+ description: 'Retrieves complete project context including standards, progress, past decisions, and relevant memories. This is the primary tool for getting context about a project.',
40
+ inputSchema: {
41
+ type: 'object' as const,
42
+ properties: {
43
+ project_name: {
44
+ type: 'string',
45
+ description: 'Name of the project to get context for'
46
+ },
47
+ include_memories: {
48
+ type: 'boolean',
49
+ description: 'Whether to include similar past decisions from semantic memory',
50
+ default: true
51
+ },
52
+ memory_limit: {
53
+ type: 'number',
54
+ description: 'Maximum number of relevant memories to include',
55
+ default: 5
56
+ }
57
+ },
58
+ required: ['project_name']
59
+ }
60
+ },
61
+
62
+ /**
63
+ * UPDATE_PROGRESS
64
+ * Track project progress and completed work
65
+ *
66
+ * Use this when:
67
+ * - Completing a task or milestone
68
+ * - Making significant progress
69
+ * - Updating what should happen next
70
+ *
71
+ * Returns: Confirmation of progress update
72
+ */
73
+ UPDATE_PROGRESS: {
74
+ name: 'update_progress',
75
+ description: 'Updates project progress tracking with completed tasks and next steps. Use this when you complete a task or make significant progress.',
76
+ inputSchema: {
77
+ type: 'object' as const,
78
+ properties: {
79
+ project_name: {
80
+ type: 'string',
81
+ description: 'Name of the project'
82
+ },
83
+ completed_task: {
84
+ type: 'string',
85
+ description: 'Description of what was just completed'
86
+ },
87
+ next_steps: {
88
+ type: 'string',
89
+ description: 'What should be done next'
90
+ },
91
+ notes: {
92
+ type: 'string',
93
+ description: 'Optional additional notes or context'
94
+ }
95
+ },
96
+ required: ['project_name', 'completed_task', 'next_steps']
97
+ }
98
+ },
99
+
100
+ /**
101
+ * REMEMBER_DECISION
102
+ * Store important decisions in long-term memory
103
+ *
104
+ * Use this when:
105
+ * - Making architectural decisions
106
+ * - Choosing between alternatives
107
+ * - Establishing patterns that should persist
108
+ *
109
+ * Returns: Confirmation with memory ID
110
+ */
111
+ REMEMBER_DECISION: {
112
+ name: 'remember_decision',
113
+ description: 'Stores an important architectural or technical decision in long-term memory. Use this for decisions that should influence future development.',
114
+ inputSchema: {
115
+ type: 'object' as const,
116
+ properties: {
117
+ project_name: {
118
+ type: 'string',
119
+ description: 'Project this decision relates to'
120
+ },
121
+ context: {
122
+ type: 'string',
123
+ description: 'What situation or problem led to this decision'
124
+ },
125
+ decision: {
126
+ type: 'string',
127
+ description: 'The decision that was made'
128
+ },
129
+ reasoning: {
130
+ type: 'string',
131
+ description: 'Why this decision was made'
132
+ },
133
+ alternatives_considered: {
134
+ type: 'string',
135
+ description: 'Other options that were considered'
136
+ },
137
+ tags: {
138
+ type: 'array',
139
+ items: { type: 'string' },
140
+ description: 'Tags for categorizing this decision (e.g., "architecture", "performance", "security")'
141
+ }
142
+ },
143
+ required: ['project_name', 'context', 'decision', 'reasoning']
144
+ }
145
+ },
146
+
147
+ /**
148
+ * RECALL_SIMILAR
149
+ * Semantic search through past decisions and context
150
+ *
151
+ * Use this when:
152
+ * - Facing a similar situation to past work
153
+ * - Want to learn from previous decisions
154
+ * - Need context from related work
155
+ *
156
+ * Returns: Array of similar decisions with similarity scores
157
+ */
158
+ RECALL_SIMILAR: {
159
+ name: 'recall_similar',
160
+ description: 'Finds past decisions and context similar to the current situation using semantic search. Helps learn from past experience.',
161
+ inputSchema: {
162
+ type: 'object' as const,
163
+ properties: {
164
+ query: {
165
+ type: 'string',
166
+ description: 'Description of current situation or question'
167
+ },
168
+ project_filter: {
169
+ type: 'string',
170
+ description: 'Optional: only search within specific project'
171
+ },
172
+ limit: {
173
+ type: 'number',
174
+ description: 'Maximum number of results to return',
175
+ default: 5
176
+ },
177
+ min_similarity: {
178
+ type: 'number',
179
+ description: 'Minimum similarity score (0-1)',
180
+ default: 0.7
181
+ }
182
+ },
183
+ required: ['query']
184
+ }
185
+ },
186
+
187
+ /**
188
+ * GET_CODE_STANDARDS
189
+ * Retrieve coding standards and conventions
190
+ *
191
+ * Use this when:
192
+ * - Need to follow project coding style
193
+ * - Want to ensure consistency
194
+ * - Starting to write new code
195
+ *
196
+ * Returns: Merged global and project-specific standards
197
+ */
198
+ GET_CODE_STANDARDS: {
199
+ name: 'get_code_standards',
200
+ description: 'Retrieves coding standards, patterns, and conventions for a project. Includes global standards merged with project-specific rules.',
201
+ inputSchema: {
202
+ type: 'object' as const,
203
+ properties: {
204
+ project_name: {
205
+ type: 'string',
206
+ description: 'Name of the project'
207
+ },
208
+ language: {
209
+ type: 'string',
210
+ description: 'Optional: filter standards by programming language (e.g., "typescript", "python")'
211
+ }
212
+ },
213
+ required: ['project_name']
214
+ }
215
+ },
216
+
217
+ /**
218
+ * LIST_PROJECTS
219
+ * Get available projects from the vault
220
+ *
221
+ * Use this when:
222
+ * - Need to see what projects exist
223
+ * - Want project metadata and status
224
+ * - Looking for active vs archived projects
225
+ *
226
+ * Returns: Array of project summaries with metadata
227
+ */
228
+ LIST_PROJECTS: {
229
+ name: 'list_projects',
230
+ description: 'Lists all available projects in the Obsidian vault with their metadata and status.',
231
+ inputSchema: {
232
+ type: 'object' as const,
233
+ properties: {
234
+ status_filter: {
235
+ type: 'string',
236
+ enum: ['active', 'archived', 'planning', 'all'],
237
+ description: 'Filter projects by status',
238
+ default: 'active'
239
+ }
240
+ }
241
+ }
242
+ },
243
+
244
+ /**
245
+ * SMART_CONTEXT
246
+ * Intelligent context with proactive memory recall
247
+ *
248
+ * Use this when:
249
+ * - Starting work and want automatic relevant memory recall
250
+ * - Asking a question and want past decisions automatically searched
251
+ * - Need context + relevant memories in one call
252
+ */
253
+ SMART_CONTEXT: {
254
+ name: 'smart_context',
255
+ description: 'Gets project context AND automatically searches for relevant past decisions based on your current question or task. More intelligent than get_project_context - use this when you have a specific question or task.',
256
+ inputSchema: {
257
+ type: 'object' as const,
258
+ properties: {
259
+ project_name: {
260
+ type: 'string',
261
+ description: 'Name of the project'
262
+ },
263
+ current_task: {
264
+ type: 'string',
265
+ description: 'What you are currently working on or asking about. This triggers proactive memory recall.'
266
+ },
267
+ min_similarity: {
268
+ type: 'number',
269
+ description: 'Minimum similarity for memory recall (0-1). Lower = more results.',
270
+ default: 0.3
271
+ }
272
+ },
273
+ required: ['project_name', 'current_task']
274
+ }
275
+ },
276
+
277
+ /**
278
+ * AUTO_REMEMBER
279
+ * Automatically detects and saves decisions from text
280
+ *
281
+ * Use this when:
282
+ * - Claude made a recommendation and wants to auto-save it
283
+ * - Processing a response that might contain decisions
284
+ * - Want Claude Brain to detect decisions automatically
285
+ */
286
+ AUTO_REMEMBER: {
287
+ name: 'auto_remember',
288
+ description: 'Automatically detects decisions in text and saves them. Pass any text containing recommendations like "I recommend X because Y" or "We should use X". Decisions with >70% confidence are auto-saved.',
289
+ inputSchema: {
290
+ type: 'object' as const,
291
+ properties: {
292
+ project_name: {
293
+ type: 'string',
294
+ description: 'Project to associate the decision with'
295
+ },
296
+ text: {
297
+ type: 'string',
298
+ description: 'Text to analyze for decisions (e.g., Claude\'s response containing recommendations)'
299
+ },
300
+ confidence_threshold: {
301
+ type: 'number',
302
+ description: 'Minimum confidence to auto-save (0-1)',
303
+ default: 0.7
304
+ }
305
+ },
306
+ required: ['project_name', 'text']
307
+ }
308
+ },
309
+
310
+ /**
311
+ * GET_PHASE12_STATUS
312
+ * Get status of intelligent automation features
313
+ */
314
+ GET_PHASE12_STATUS: {
315
+ name: 'get_phase12_status',
316
+ description: 'Shows status of Claude Brain\'s intelligent automation: current project, patterns detected, learning insights, and recall statistics.',
317
+ inputSchema: {
318
+ type: 'object' as const,
319
+ properties: {}
320
+ }
321
+ },
322
+
323
+ /**
324
+ * CREATE_PROJECT
325
+ * Create a new project in the vault with all necessary files
326
+ *
327
+ * Use this when:
328
+ * - Starting a brand new project
329
+ * - User wants to track a project with Claude Brain
330
+ * - Need to set up project structure automatically
331
+ */
332
+ CREATE_PROJECT: {
333
+ name: 'create_project',
334
+ description: 'Creates a new project in the Obsidian vault with all necessary files (context.md, progress.md, decisions.md, standards.md). Use this when starting a new project.',
335
+ inputSchema: {
336
+ type: 'object' as const,
337
+ properties: {
338
+ project_name: {
339
+ type: 'string',
340
+ description: 'Name of the project (lowercase with hyphens, e.g., "my-awesome-app")'
341
+ },
342
+ description: {
343
+ type: 'string',
344
+ description: 'Brief description of the project'
345
+ },
346
+ tech_stack: {
347
+ type: 'array',
348
+ items: { type: 'string' },
349
+ description: 'Technologies used (e.g., ["typescript", "react", "node"])'
350
+ },
351
+ status: {
352
+ type: 'string',
353
+ enum: ['planning', 'active', 'on-hold', 'completed'],
354
+ description: 'Initial project status',
355
+ default: 'planning'
356
+ },
357
+ tags: {
358
+ type: 'array',
359
+ items: { type: 'string' },
360
+ description: 'Tags for categorizing the project (e.g., ["web", "frontend", "personal"])'
361
+ }
362
+ },
363
+ required: ['project_name']
364
+ }
365
+ },
366
+
367
+ /**
368
+ * INIT_PROJECT
369
+ * Analyze existing codebase and initialize in Claude Brain
370
+ *
371
+ * Use this when:
372
+ * - Opening Claude Code in an existing project
373
+ * - Want to auto-detect tech stack, structure, conventions
374
+ * - Similar to `claude init` but for Claude Brain
375
+ *
376
+ * LOW USAGE: Pure file reading, no LLM calls
377
+ */
378
+ INIT_PROJECT: {
379
+ name: 'init_project',
380
+ description: 'Analyzes an existing codebase and creates/updates project in Claude Brain. Reads package.json, config files, and structure to auto-detect tech stack, frameworks, and conventions. Similar to `claude init`. Use this when starting work on an existing project.',
381
+ inputSchema: {
382
+ type: 'object' as const,
383
+ properties: {
384
+ project_path: {
385
+ type: 'string',
386
+ description: 'Path to be project directory. Defaults to current working directory.'
387
+ },
388
+ project_name: {
389
+ type: 'string',
390
+ description: 'Override project name (otherwise detected from package.json or folder name)'
391
+ },
392
+ save_to_memory: {
393
+ type: 'boolean',
394
+ description: 'Whether to save project context to semantic memory for future recall',
395
+ default: true
396
+ }
397
+ }
398
+ }
399
+ },
400
+
401
+ /**
402
+ * RECOGNIZE_PATTERN
403
+ * Save a recognized pattern to ChromaDB
404
+ *
405
+ * Use this when:
406
+ * - You notice a recurring solution approach
407
+ * - You identify an anti-pattern
408
+ * - You find a best practice that should be documented
409
+ *
410
+ * Patterns are stored in ChromaDB patterns collection for semantic recall
411
+ */
412
+ RECOGNIZE_PATTERN: {
413
+ name: 'recognize_pattern',
414
+ description: 'Saves a recognized pattern (solution, anti-pattern, best-practice, or common-issue) to ChromaDB semantic memory. Patterns help identify recurring approaches and avoid mistakes.',
415
+ inputSchema: {
416
+ type: 'object' as const,
417
+ properties: {
418
+ project_name: {
419
+ type: 'string',
420
+ description: 'Project this pattern relates to'
421
+ },
422
+ pattern_type: {
423
+ type: 'string',
424
+ enum: ['solution', 'anti-pattern', 'best-practice', 'common-issue'],
425
+ description: 'Type of pattern'
426
+ },
427
+ description: {
428
+ type: 'string',
429
+ description: 'Detailed description of the pattern'
430
+ },
431
+ example: {
432
+ type: 'string',
433
+ description: 'Code example illustrating the pattern (optional)'
434
+ },
435
+ confidence: {
436
+ type: 'number',
437
+ minimum: 0,
438
+ maximum: 1,
439
+ description: 'Confidence in this pattern (0-1, default 0.8)'
440
+ },
441
+ context: {
442
+ type: 'string',
443
+ description: 'When this pattern was observed or applicable'
444
+ }
445
+ },
446
+ required: ['project_name', 'pattern_type', 'description']
447
+ }
448
+ },
449
+
450
+ /**
451
+ * RECORD_CORRECTION
452
+ * Save a correction/lesson learned to ChromaDB
453
+ *
454
+ * Use this when:
455
+ * - You made a mistake that should be documented
456
+ * - You learned a better approach after an error
457
+ * - You want to track lessons learned
458
+ *
459
+ * Corrections are stored in ChromaDB corrections collection for learning from mistakes
460
+ */
461
+ RECORD_CORRECTION: {
462
+ name: 'record_correction',
463
+ description: 'Saves a correction or lesson learned to ChromaDB semantic memory. Use this when you made a mistake, learned something new, or want to document what NOT to do.',
464
+ inputSchema: {
465
+ type: 'object' as const,
466
+ properties: {
467
+ project_name: {
468
+ type: 'string',
469
+ description: 'Project this correction relates to'
470
+ },
471
+ original: {
472
+ type: 'string',
473
+ description: 'What was wrong or the mistake that was made'
474
+ },
475
+ correction: {
476
+ type: 'string',
477
+ description: 'What should have been done instead'
478
+ },
479
+ reasoning: {
480
+ type: 'string',
481
+ description: 'Why the correction is better than the original approach'
482
+ },
483
+ context: {
484
+ type: 'string',
485
+ description: 'When this correction was identified or applicable'
486
+ },
487
+ confidence: {
488
+ type: 'number',
489
+ minimum: 0,
490
+ maximum: 1,
491
+ description: 'Confidence in this correction (0-1, default 0.9)'
492
+ }
493
+ },
494
+ required: ['project_name', 'original', 'correction', 'reasoning']
495
+ }
496
+ },
497
+
498
+ /**
499
+ * GET_PATTERNS
500
+ * Retrieve recognized patterns from ChromaDB
501
+ *
502
+ * Use this when:
503
+ * - You want to review documented patterns
504
+ * - You need to know what solutions have worked before
505
+ * - You want to avoid known anti-patterns
506
+ *
507
+ * Results are ranked by similarity to your query
508
+ */
509
+ GET_PATTERNS: {
510
+ name: 'get_patterns',
511
+ description: 'Retrieves recognized patterns from ChromaDB semantic memory. Use this to review documented solutions, best practices, anti-patterns, and common issues. Patterns are returned ranked by semantic similarity.',
512
+ inputSchema: {
513
+ type: 'object' as const,
514
+ properties: {
515
+ project_name: {
516
+ type: 'string',
517
+ description: 'Project to retrieve patterns from (optional, returns all projects if not specified)'
518
+ },
519
+ pattern_type: {
520
+ type: 'string',
521
+ enum: ['solution', 'anti-pattern', 'best-practice', 'common-issue'],
522
+ description: 'Filter by pattern type (optional)'
523
+ },
524
+ limit: {
525
+ type: 'number',
526
+ minimum: 1,
527
+ description: 'Maximum number of patterns to return (default 10)'
528
+ },
529
+ query: {
530
+ type: 'string',
531
+ description: 'Search query to find relevant patterns (optional, uses semantic search if not provided)'
532
+ }
533
+ }
534
+ }
535
+ },
536
+
537
+ /**
538
+ * GET_CORRECTIONS
539
+ * Retrieve corrections/lessons learned from ChromaDB
540
+ *
541
+ * Use this when:
542
+ * - You want to review past mistakes and lessons learned
543
+ * - You need to know what corrections have been documented
544
+ * - You want to avoid repeating previous errors
545
+ *
546
+ * Results are ranked by similarity to your query
547
+ */
548
+ GET_CORRECTIONS: {
549
+ name: 'get_corrections',
550
+ description: 'Retrieves corrections and lessons learned from ChromaDB semantic memory. Use this to review past mistakes, what was fixed, and why it was better. Corrections are returned ranked by semantic similarity.',
551
+ inputSchema: {
552
+ type: 'object' as const,
553
+ properties: {
554
+ project_name: {
555
+ type: 'string',
556
+ description: 'Project to retrieve corrections from (optional, returns all projects if not specified)'
557
+ },
558
+ limit: {
559
+ type: 'number',
560
+ minimum: 1,
561
+ description: 'Maximum number of corrections to return (default 10)'
562
+ },
563
+ query: {
564
+ type: 'string',
565
+ description: 'Search query to find relevant corrections (optional, uses semantic search if not provided)'
566
+ }
567
+ }
568
+ }
569
+ },
570
+
571
+ /**
572
+ * RATE_MEMORY
573
+ * Provide feedback on retrieved memories for adaptive learning
574
+ *
575
+ * Use this when:
576
+ * - A retrieved memory was helpful or not helpful
577
+ * - You want to improve future retrieval quality
578
+ * - The system should learn from retrieval feedback
579
+ *
580
+ * Feedback is used to adapt retrieval thresholds and weights
581
+ */
582
+ RATE_MEMORY: {
583
+ name: 'rate_memory',
584
+ description: 'Rate how helpful a retrieved memory was. This feedback helps improve future retrieval quality through adaptive learning. Rate 1-5 where 1=not helpful and 5=very helpful.',
585
+ inputSchema: {
586
+ type: 'object' as const,
587
+ properties: {
588
+ memory_id: {
589
+ type: 'string',
590
+ description: 'ID of the memory to rate (from recall_similar or smart_context results)'
591
+ },
592
+ rating: {
593
+ type: 'number',
594
+ enum: [1, 2, 3, 4, 5],
595
+ description: 'Rating from 1 (not helpful) to 5 (very helpful)'
596
+ },
597
+ query: {
598
+ type: 'string',
599
+ description: 'The original query that retrieved this memory'
600
+ },
601
+ was_used: {
602
+ type: 'boolean',
603
+ description: 'Whether you actually used this memory in your response',
604
+ default: true
605
+ },
606
+ feedback_text: {
607
+ type: 'string',
608
+ description: 'Optional text explaining why this rating was given'
609
+ },
610
+ project_name: {
611
+ type: 'string',
612
+ description: 'Project this feedback relates to (optional)'
613
+ }
614
+ },
615
+ required: ['memory_id', 'rating', 'query']
616
+ }
617
+ },
618
+
619
+ /**
620
+ * SEARCH_KNOWLEDGE_GRAPH
621
+ * Search the knowledge graph for related entities, decisions, and relationships
622
+ *
623
+ * Use this when:
624
+ * - You want to find how technologies/decisions are connected
625
+ * - You need to explore relationships between entities
626
+ * - You want to find related decisions for a technology
627
+ */
628
+ SEARCH_KNOWLEDGE_GRAPH: {
629
+ name: 'search_knowledge_graph',
630
+ description: 'Searches the knowledge graph for related nodes and edges. Use this to explore relationships between technologies, decisions, and concepts.',
631
+ inputSchema: {
632
+ type: 'object' as const,
633
+ properties: {
634
+ query: {
635
+ type: 'string',
636
+ description: 'Search query (technology name, concept, etc.)'
637
+ },
638
+ node_type: {
639
+ type: 'string',
640
+ enum: ['project', 'technology', 'concept', 'person', 'file', 'decision', 'pattern', 'correction', 'date'],
641
+ description: 'Filter by node type (optional)'
642
+ },
643
+ start_node_id: {
644
+ type: 'string',
645
+ description: 'Start from a specific node ID for graph expansion (optional)'
646
+ },
647
+ hops: {
648
+ type: 'number',
649
+ description: 'Number of hops to expand from matching nodes (default 2)',
650
+ default: 2
651
+ },
652
+ limit: {
653
+ type: 'number',
654
+ description: 'Maximum number of results (default 20)',
655
+ default: 20
656
+ }
657
+ }
658
+ }
659
+ },
660
+
661
+ /**
662
+ * GET_EPISODE
663
+ * Get a specific episode or the active episode for a project
664
+ *
665
+ * Use this when:
666
+ * - You want to review a past conversation session
667
+ * - You need to find what was discussed in an episode
668
+ * - You want to see the active episode for a project
669
+ */
670
+ GET_EPISODE: {
671
+ name: 'get_episode',
672
+ description: 'Get episode by ID or get active episode for project. Episodes represent conversation sessions with summaries and linked decisions.',
673
+ inputSchema: {
674
+ type: 'object' as const,
675
+ properties: {
676
+ episode_id: {
677
+ type: 'string',
678
+ description: 'Specific episode ID to retrieve'
679
+ },
680
+ project_name: {
681
+ type: 'string',
682
+ description: 'Get active episode for this project'
683
+ }
684
+ }
685
+ }
686
+ },
687
+
688
+ /**
689
+ * LIST_EPISODES
690
+ * List recent episodes, filtered by project or status
691
+ *
692
+ * Use this when:
693
+ * - You want to see recent conversation sessions
694
+ * - You need to find past episodes for a project
695
+ * - You want to review episode summaries
696
+ */
697
+ LIST_EPISODES: {
698
+ name: 'list_episodes',
699
+ description: 'List recent episodes with summaries. Filter by project or status to find past conversation sessions.',
700
+ inputSchema: {
701
+ type: 'object' as const,
702
+ properties: {
703
+ project_name: {
704
+ type: 'string',
705
+ description: 'Filter episodes by project (optional)'
706
+ },
707
+ limit: {
708
+ type: 'number',
709
+ description: 'Maximum number of episodes to return (default 10)',
710
+ default: 10
711
+ },
712
+ status: {
713
+ type: 'string',
714
+ enum: ['active', 'completed'],
715
+ description: 'Filter by episode status (optional)'
716
+ }
717
+ }
718
+ }
719
+ },
720
+ // =========================================================================
721
+ // Phase 15 - Advanced Intelligence & Temporal Reasoning
722
+ // =========================================================================
723
+
724
+ /**
725
+ * GET_DECISION_TIMELINE
726
+ * Build a chronological timeline of decisions
727
+ */
728
+ GET_DECISION_TIMELINE: {
729
+ name: 'get_decision_timeline',
730
+ description: 'Builds a chronological timeline of decisions, patterns, and corrections. Supports temporal expressions like "last month", "since January", etc. Use this to see how a project or topic has evolved over time.',
731
+ inputSchema: {
732
+ type: 'object' as const,
733
+ properties: {
734
+ project_name: {
735
+ type: 'string',
736
+ description: 'Filter timeline by project (optional)'
737
+ },
738
+ topic: {
739
+ type: 'string',
740
+ description: 'Filter timeline by topic via semantic search (optional)'
741
+ },
742
+ time_range: {
743
+ type: 'string',
744
+ description: 'Natural language time range, e.g. "last month", "since January 2025", "this week" (optional)'
745
+ },
746
+ limit: {
747
+ type: 'number',
748
+ description: 'Maximum number of entries (default 50)',
749
+ default: 50
750
+ }
751
+ }
752
+ }
753
+ },
754
+
755
+ /**
756
+ * ANALYZE_DECISION_EVOLUTION
757
+ * Track how decisions on a topic change over time
758
+ */
759
+ ANALYZE_DECISION_EVOLUTION: {
760
+ name: 'analyze_decision_evolution',
761
+ description: 'Tracks how decisions on a specific topic have evolved over time. Shows changes, stability assessment, and current state. Use this to understand decision drift or consistency.',
762
+ inputSchema: {
763
+ type: 'object' as const,
764
+ properties: {
765
+ topic: {
766
+ type: 'string',
767
+ description: 'The topic to analyze evolution for (e.g., "database choice", "authentication")'
768
+ },
769
+ project_name: {
770
+ type: 'string',
771
+ description: 'Filter by project (optional)'
772
+ },
773
+ limit: {
774
+ type: 'number',
775
+ description: 'Maximum decisions to analyze (default 20)',
776
+ default: 20
777
+ }
778
+ },
779
+ required: ['topic']
780
+ }
781
+ },
782
+
783
+ /**
784
+ * DETECT_TRENDS
785
+ * Detect emerging and declining technology/pattern trends
786
+ */
787
+ DETECT_TRENDS: {
788
+ name: 'detect_trends',
789
+ description: 'Detects emerging, stable, and declining trends across decisions. Identifies frequently mentioned technologies, concepts, and approaches, and whether they are gaining or losing momentum.',
790
+ inputSchema: {
791
+ type: 'object' as const,
792
+ properties: {
793
+ project_name: {
794
+ type: 'string',
795
+ description: 'Filter by project (optional, analyzes all projects if omitted)'
796
+ },
797
+ period_days: {
798
+ type: 'number',
799
+ description: 'Analysis period in days (default 90)',
800
+ default: 90
801
+ },
802
+ min_occurrences: {
803
+ type: 'number',
804
+ description: 'Minimum occurrences to include (default 2)',
805
+ default: 2
806
+ },
807
+ limit: {
808
+ type: 'number',
809
+ description: 'Maximum trends to return (default 20)',
810
+ default: 20
811
+ }
812
+ }
813
+ }
814
+ },
815
+
816
+ /**
817
+ * WHAT_IF_ANALYSIS
818
+ * Counterfactual what-if analysis
819
+ */
820
+ WHAT_IF_ANALYSIS: {
821
+ name: 'what_if_analysis',
822
+ description: 'Performs what-if analysis: "What would happen if we changed X?" Finds all affected decisions, connected technologies, and assesses risk level. Uses knowledge graph for impact analysis.',
823
+ inputSchema: {
824
+ type: 'object' as const,
825
+ properties: {
826
+ change: {
827
+ type: 'string',
828
+ description: 'The hypothetical change to analyze (e.g., "switch from React to Vue", "remove TypeScript")'
829
+ },
830
+ project_name: {
831
+ type: 'string',
832
+ description: 'Filter by project (optional)'
833
+ },
834
+ max_results: {
835
+ type: 'number',
836
+ description: 'Maximum affected decisions to return (default 20)',
837
+ default: 20
838
+ }
839
+ },
840
+ required: ['change']
841
+ }
842
+ },
843
+
844
+ /**
845
+ * GET_RECOMMENDATIONS
846
+ * Get intelligent recommendations based on history
847
+ */
848
+ GET_RECOMMENDATIONS: {
849
+ name: 'get_recommendations',
850
+ description: 'Provides intelligent recommendations based on past decisions, patterns, and corrections. Combines multiple knowledge sources to suggest best approaches for a given situation.',
851
+ inputSchema: {
852
+ type: 'object' as const,
853
+ properties: {
854
+ query: {
855
+ type: 'string',
856
+ description: 'What you need recommendations for (e.g., "how to implement caching", "error handling approach")'
857
+ },
858
+ project_name: {
859
+ type: 'string',
860
+ description: 'Filter by project (optional)'
861
+ },
862
+ limit: {
863
+ type: 'number',
864
+ description: 'Maximum recommendations (default 10)',
865
+ default: 10
866
+ }
867
+ },
868
+ required: ['query']
869
+ }
870
+ },
871
+
872
+ /**
873
+ * FIND_CROSS_PROJECT_PATTERNS
874
+ * Find patterns common across multiple projects
875
+ */
876
+ FIND_CROSS_PROJECT_PATTERNS: {
877
+ name: 'find_cross_project_patterns',
878
+ description: 'Finds patterns and approaches that appear across multiple projects. Identifies shared technologies, common decisions, and transferable knowledge between projects.',
879
+ inputSchema: {
880
+ type: 'object' as const,
881
+ properties: {
882
+ min_projects: {
883
+ type: 'number',
884
+ description: 'Minimum number of projects a pattern must appear in (default 2)',
885
+ default: 2
886
+ },
887
+ limit: {
888
+ type: 'number',
889
+ description: 'Maximum patterns to return (default 20)',
890
+ default: 20
891
+ },
892
+ query: {
893
+ type: 'string',
894
+ description: 'Optional query to focus the search (e.g., "authentication", "deployment")'
895
+ }
896
+ }
897
+ }
898
+ }
899
+ } as const satisfies Record<string, ToolDefinition>
900
+
901
+ /** Tool names as a union type */
902
+ export type ToolName = typeof TOOLS[keyof typeof TOOLS]['name']
903
+
904
+ /** Get all tool names as an array */
905
+ export function getToolNames(): ToolName[] {
906
+ return Object.values(TOOLS).map(tool => tool.name)
907
+ }