claude-conversation-memory-mcp 0.6.0 → 1.0.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 (45) hide show
  1. package/dist/ConversationMemory.d.ts +151 -10
  2. package/dist/ConversationMemory.d.ts.map +1 -1
  3. package/dist/ConversationMemory.js +127 -10
  4. package/dist/ConversationMemory.js.map +1 -1
  5. package/dist/cache/QueryCache.d.ts +215 -0
  6. package/dist/cache/QueryCache.d.ts.map +1 -0
  7. package/dist/cache/QueryCache.js +294 -0
  8. package/dist/cache/QueryCache.js.map +1 -0
  9. package/dist/parsers/ConversationParser.d.ts +62 -3
  10. package/dist/parsers/ConversationParser.d.ts.map +1 -1
  11. package/dist/parsers/ConversationParser.js +50 -3
  12. package/dist/parsers/ConversationParser.js.map +1 -1
  13. package/dist/parsers/DecisionExtractor.d.ts +61 -3
  14. package/dist/parsers/DecisionExtractor.d.ts.map +1 -1
  15. package/dist/parsers/DecisionExtractor.js +47 -3
  16. package/dist/parsers/DecisionExtractor.js.map +1 -1
  17. package/dist/parsers/GitIntegrator.d.ts +88 -3
  18. package/dist/parsers/GitIntegrator.d.ts.map +1 -1
  19. package/dist/parsers/GitIntegrator.js +68 -3
  20. package/dist/parsers/GitIntegrator.js.map +1 -1
  21. package/dist/parsers/MistakeExtractor.d.ts +62 -3
  22. package/dist/parsers/MistakeExtractor.d.ts.map +1 -1
  23. package/dist/parsers/MistakeExtractor.js +50 -3
  24. package/dist/parsers/MistakeExtractor.js.map +1 -1
  25. package/dist/parsers/RequirementsExtractor.d.ts +95 -4
  26. package/dist/parsers/RequirementsExtractor.d.ts.map +1 -1
  27. package/dist/parsers/RequirementsExtractor.js +73 -4
  28. package/dist/parsers/RequirementsExtractor.js.map +1 -1
  29. package/dist/storage/ConversationStorage.d.ts +271 -2
  30. package/dist/storage/ConversationStorage.d.ts.map +1 -1
  31. package/dist/storage/ConversationStorage.js +356 -7
  32. package/dist/storage/ConversationStorage.js.map +1 -1
  33. package/dist/tools/ToolHandlers.d.ts +525 -16
  34. package/dist/tools/ToolHandlers.d.ts.map +1 -1
  35. package/dist/tools/ToolHandlers.js +533 -24
  36. package/dist/tools/ToolHandlers.js.map +1 -1
  37. package/dist/utils/Logger.d.ts +67 -0
  38. package/dist/utils/Logger.d.ts.map +1 -0
  39. package/dist/utils/Logger.js +119 -0
  40. package/dist/utils/Logger.js.map +1 -0
  41. package/dist/utils/constants.d.ts +75 -0
  42. package/dist/utils/constants.d.ts.map +1 -0
  43. package/dist/utils/constants.js +105 -0
  44. package/dist/utils/constants.js.map +1 -0
  45. package/package.json +1 -1
@@ -1,5 +1,26 @@
1
1
  /**
2
- * MCP Tool Handlers - Implementation of all 13 tools (including migration)
2
+ * MCP Tool Handlers - Implementation of all 13 tools for the conversation-memory MCP server.
3
+ *
4
+ * This class provides the implementation for all MCP (Model Context Protocol) tools
5
+ * that allow Claude to interact with conversation history and memory.
6
+ *
7
+ * Tools are organized into categories:
8
+ * - Indexing: index_conversations
9
+ * - Search: search_conversations, searchDecisions, search_mistakes
10
+ * - File Context: check_before_modify, get_file_evolution
11
+ * - History: get_tool_history, link_commits_to_conversations
12
+ * - Discovery: find_similar_sessions, get_requirements
13
+ * - Recall: recall_and_apply
14
+ * - Documentation: generate_documentation
15
+ * - Migration: discover_old_conversations, migrate_project
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const handlers = new ToolHandlers(memory, db, '/path/to/projects');
20
+ * const result = await handlers.indexConversations({
21
+ * project_path: '/Users/me/my-project'
22
+ * });
23
+ * ```
3
24
  */
4
25
  import { sanitizeForLike } from "../utils/sanitization.js";
5
26
  import { DocumentationGenerator } from "../documentation/DocumentationGenerator.js";
@@ -7,17 +28,60 @@ import { ProjectMigration } from "../utils/ProjectMigration.js";
7
28
  import { pathToProjectFolderName } from "../utils/sanitization.js";
8
29
  import { readdirSync } from "fs";
9
30
  import { join } from "path";
31
+ /**
32
+ * Tool handlers for the conversation-memory MCP server.
33
+ *
34
+ * Provides methods for indexing, searching, and managing conversation history.
35
+ */
10
36
  export class ToolHandlers {
11
37
  memory;
12
38
  db;
13
39
  migration;
40
+ /**
41
+ * Create a new ToolHandlers instance.
42
+ *
43
+ * @param memory - ConversationMemory instance for core operations
44
+ * @param db - SQLiteManager for database access
45
+ * @param projectsDir - Optional directory for storing project data
46
+ */
14
47
  constructor(memory, db, projectsDir) {
15
48
  this.memory = memory;
16
49
  this.db = db;
17
50
  this.migration = new ProjectMigration(db, projectsDir);
18
51
  }
19
52
  /**
20
- * Tool 1: index_conversations
53
+ * Index conversation history for a project.
54
+ *
55
+ * Parses conversation files from Claude Code's conversation history, extracts
56
+ * decisions, mistakes, and requirements, links git commits, and generates
57
+ * semantic embeddings for search.
58
+ *
59
+ * @param args - Indexing arguments:
60
+ * - `project_path`: Path to the project (defaults to cwd)
61
+ * - `session_id`: Optional specific session to index
62
+ * - `include_thinking`: Include thinking blocks (default: false)
63
+ * - `enable_git`: Enable git integration (default: true)
64
+ * - `exclude_mcp_conversations`: Exclude MCP tool conversations (default: 'self-only')
65
+ * - `exclude_mcp_servers`: List of specific MCP servers to exclude
66
+ *
67
+ * @returns Result containing:
68
+ * - `success`: Whether indexing succeeded
69
+ * - `stats`: Counts of conversations, messages, decisions, etc.
70
+ * - `indexed_folders`: List of folders that were indexed
71
+ * - `database_path`: Path to the SQLite database
72
+ * - `embeddings_generated`: Whether embeddings were created
73
+ * - `embedding_error`: Error message if embeddings failed
74
+ * - `message`: Human-readable status message
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const result = await handlers.indexConversations({
79
+ * project_path: '/Users/me/my-project',
80
+ * enable_git: true,
81
+ * exclude_mcp_conversations: 'self-only'
82
+ * });
83
+ * console.log(result.message); // "Indexed 5 conversation(s) with 245 messages..."
84
+ * ```
21
85
  */
22
86
  async indexConversations(args) {
23
87
  const typedArgs = args;
@@ -66,7 +130,39 @@ export class ToolHandlers {
66
130
  };
67
131
  }
68
132
  /**
69
- * Tool 2: search_conversations
133
+ * Search conversation history using natural language queries.
134
+ *
135
+ * Uses semantic search with embeddings if available, otherwise falls back
136
+ * to full-text search. Returns relevant messages with context and similarity scores.
137
+ *
138
+ * @param args - Search arguments:
139
+ * - `query`: Natural language search query (required)
140
+ * - `limit`: Maximum number of results (default: 10)
141
+ * - `date_range`: Optional [start_timestamp, end_timestamp] filter
142
+ *
143
+ * @returns Search results containing:
144
+ * - `query`: The search query used
145
+ * - `results`: Array of matching messages with:
146
+ * - `conversation_id`: Conversation containing the message
147
+ * - `message_id`: Message identifier
148
+ * - `timestamp`: When the message was created
149
+ * - `similarity`: Relevance score (0-1)
150
+ * - `snippet`: Text excerpt from the message
151
+ * - `git_branch`: Git branch at the time
152
+ * - `message_type`: Type of message
153
+ * - `role`: Message role (user/assistant)
154
+ * - `total_found`: Number of results returned
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * const result = await handlers.searchConversations({
159
+ * query: 'authentication bug fix',
160
+ * limit: 5
161
+ * });
162
+ * result.results.forEach(r => {
163
+ * console.log(`${r.similarity.toFixed(2)}: ${r.snippet}`);
164
+ * });
165
+ * ```
70
166
  */
71
167
  async searchConversations(args) {
72
168
  const typedArgs = args;
@@ -92,7 +188,45 @@ export class ToolHandlers {
92
188
  };
93
189
  }
94
190
  /**
95
- * Tool 3: get_decisions
191
+ * Find decisions made about a specific topic, file, or component.
192
+ *
193
+ * Searches through extracted decisions to find relevant architectural choices,
194
+ * technical decisions, and their rationale. Shows alternatives considered and
195
+ * rejected approaches.
196
+ *
197
+ * @param args - Decision search arguments:
198
+ * - `query`: Topic or keyword to search for (required)
199
+ * - `file_path`: Optional filter for decisions related to a specific file
200
+ * - `limit`: Maximum number of results (default: 10)
201
+ *
202
+ * @returns Decision search results containing:
203
+ * - `query`: The search query used
204
+ * - `file_path`: File filter if applied
205
+ * - `decisions`: Array of matching decisions with:
206
+ * - `decision_id`: Decision identifier
207
+ * - `decision_text`: The decision that was made
208
+ * - `rationale`: Why this decision was made
209
+ * - `alternatives_considered`: Other options that were considered
210
+ * - `rejected_reasons`: Why alternatives were rejected
211
+ * - `context`: Context in which the decision was made
212
+ * - `related_files`: Files affected by this decision
213
+ * - `related_commits`: Git commits implementing this decision
214
+ * - `timestamp`: When the decision was made
215
+ * - `similarity`: Relevance score
216
+ * - `total_found`: Number of decisions returned
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * const result = await handlers.getDecisions({
221
+ * query: 'database',
222
+ * file_path: 'src/storage/SQLiteManager.ts',
223
+ * limit: 5
224
+ * });
225
+ * result.decisions.forEach(d => {
226
+ * console.log(`Decision: ${d.decision_text}`);
227
+ * console.log(`Rationale: ${d.rationale}`);
228
+ * });
229
+ * ```
96
230
  */
97
231
  async getDecisions(args) {
98
232
  const typedArgs = args;
@@ -122,7 +256,33 @@ export class ToolHandlers {
122
256
  };
123
257
  }
124
258
  /**
125
- * Tool 4: check_before_modify
259
+ * Check important context before modifying a file.
260
+ *
261
+ * Shows recent changes, related decisions, commits, and past mistakes to avoid
262
+ * when working on a file. Use this before making significant changes to understand
263
+ * the file's history and context.
264
+ *
265
+ * @param args - Check arguments:
266
+ * - `file_path`: Path to the file you want to modify (required)
267
+ *
268
+ * @returns Context information containing:
269
+ * - `file_path`: The file being checked
270
+ * - `warning`: Warning message if important context found
271
+ * - `recent_changes`: Recent edits and commits to this file
272
+ * - `edits`: Recent file edits with timestamps and conversation IDs
273
+ * - `commits`: Recent git commits affecting this file
274
+ * - `related_decisions`: Decisions that affect this file
275
+ * - `mistakes_to_avoid`: Past mistakes related to this file
276
+ *
277
+ * @example
278
+ * ```typescript
279
+ * const context = await handlers.checkBeforeModify({
280
+ * file_path: 'src/storage/SQLiteManager.ts'
281
+ * });
282
+ * console.log(context.warning);
283
+ * console.log(`${context.related_decisions.length} decisions affect this file`);
284
+ * console.log(`${context.mistakes_to_avoid.length} mistakes to avoid`);
285
+ * ```
126
286
  */
127
287
  async checkBeforeModify(args) {
128
288
  const typedArgs = args;
@@ -162,7 +322,36 @@ export class ToolHandlers {
162
322
  };
163
323
  }
164
324
  /**
165
- * Tool 5: get_file_evolution
325
+ * Show complete timeline of changes to a file.
326
+ *
327
+ * Returns a chronological timeline of all edits, commits, and related decisions
328
+ * for a specific file across all conversations and git history.
329
+ *
330
+ * @param args - Evolution arguments:
331
+ * - `file_path`: Path to the file (required)
332
+ * - `include_decisions`: Include related decisions (default: true)
333
+ * - `include_commits`: Include git commits (default: true)
334
+ *
335
+ * @returns File evolution timeline containing:
336
+ * - `file_path`: The file being analyzed
337
+ * - `total_edits`: Total number of edits to this file
338
+ * - `timeline`: Chronological array of events (most recent first):
339
+ * - `type`: Event type ('edit', 'commit', or 'decision')
340
+ * - `timestamp`: When the event occurred
341
+ * - `data`: Event-specific data (conversation_id, commit hash, decision text, etc.)
342
+ *
343
+ * @example
344
+ * ```typescript
345
+ * const evolution = await handlers.getFileEvolution({
346
+ * file_path: 'src/index.ts',
347
+ * include_decisions: true,
348
+ * include_commits: true
349
+ * });
350
+ * console.log(`${evolution.total_edits} edits across ${evolution.timeline.length} events`);
351
+ * evolution.timeline.forEach(event => {
352
+ * console.log(`${event.timestamp}: ${event.type}`);
353
+ * });
354
+ * ```
166
355
  */
167
356
  async getFileEvolution(args) {
168
357
  const typedArgs = args;
@@ -213,7 +402,42 @@ export class ToolHandlers {
213
402
  };
214
403
  }
215
404
  /**
216
- * Tool 6: link_commits_to_conversations
405
+ * Link git commits to the conversations where they were made or discussed.
406
+ *
407
+ * Finds git commits that are associated with specific conversations, showing
408
+ * which code changes were made during which conversations. Helps answer "WHY
409
+ * was this code changed?"
410
+ *
411
+ * @param args - Link arguments:
412
+ * - `query`: Optional search query for commit messages
413
+ * - `conversation_id`: Optional filter for specific conversation
414
+ * - `limit`: Maximum number of commits (default: 20)
415
+ *
416
+ * @returns Commit links containing:
417
+ * - `query`: Search query if provided
418
+ * - `conversation_id`: Conversation filter if provided
419
+ * - `commits`: Array of linked commits with:
420
+ * - `hash`: Short commit hash (7 chars)
421
+ * - `full_hash`: Full commit hash
422
+ * - `message`: Commit message
423
+ * - `author`: Commit author
424
+ * - `timestamp`: When commit was made
425
+ * - `branch`: Git branch
426
+ * - `files_changed`: List of files changed
427
+ * - `conversation_id`: Conversation where this was discussed/made
428
+ * - `total_found`: Number of commits returned
429
+ *
430
+ * @example
431
+ * ```typescript
432
+ * const links = await handlers.linkCommitsToConversations({
433
+ * query: 'fix authentication',
434
+ * limit: 10
435
+ * });
436
+ * links.commits.forEach(c => {
437
+ * console.log(`${c.hash}: ${c.message}`);
438
+ * console.log(` Conversation: ${c.conversation_id}`);
439
+ * });
440
+ * ```
217
441
  */
218
442
  async linkCommitsToConversations(args) {
219
443
  const typedArgs = args;
@@ -248,7 +472,41 @@ export class ToolHandlers {
248
472
  };
249
473
  }
250
474
  /**
251
- * Tool 7: search_mistakes
475
+ * Find past mistakes to avoid repeating them.
476
+ *
477
+ * Searches through extracted mistakes to find documented errors, bugs, and
478
+ * wrong approaches. Shows what went wrong and how it was corrected.
479
+ *
480
+ * @param args - Mistake search arguments:
481
+ * - `query`: Search query for mistakes (required)
482
+ * - `mistake_type`: Optional filter by type (logic_error, wrong_approach, misunderstanding, tool_error, syntax_error)
483
+ * - `limit`: Maximum number of results (default: 10)
484
+ *
485
+ * @returns Mistake search results containing:
486
+ * - `query`: Search query used
487
+ * - `mistake_type`: Type filter if applied
488
+ * - `mistakes`: Array of matching mistakes with:
489
+ * - `mistake_id`: Mistake identifier
490
+ * - `mistake_type`: Type of mistake
491
+ * - `what_went_wrong`: Description of the mistake
492
+ * - `correction`: How it was fixed
493
+ * - `user_correction_message`: User's correction message if available
494
+ * - `files_affected`: List of files involved
495
+ * - `timestamp`: When the mistake occurred
496
+ * - `total_found`: Number of mistakes returned
497
+ *
498
+ * @example
499
+ * ```typescript
500
+ * const mistakes = await handlers.searchMistakes({
501
+ * query: 'database transaction',
502
+ * mistake_type: 'logic_error',
503
+ * limit: 5
504
+ * });
505
+ * mistakes.mistakes.forEach(m => {
506
+ * console.log(`${m.mistake_type}: ${m.what_went_wrong}`);
507
+ * console.log(`Fix: ${m.correction}`);
508
+ * });
509
+ * ```
252
510
  */
253
511
  async searchMistakes(args) {
254
512
  const typedArgs = args;
@@ -279,7 +537,38 @@ export class ToolHandlers {
279
537
  };
280
538
  }
281
539
  /**
282
- * Tool 8: get_requirements
540
+ * Look up requirements and constraints for a component or feature.
541
+ *
542
+ * Finds documented requirements, dependencies, performance constraints, and
543
+ * compatibility requirements that affect a component or feature.
544
+ *
545
+ * @param args - Requirements search arguments:
546
+ * - `component`: Component or feature name (required)
547
+ * - `type`: Optional filter by requirement type (dependency, performance, compatibility, business)
548
+ *
549
+ * @returns Requirements results containing:
550
+ * - `component`: Component searched
551
+ * - `type`: Type filter if applied
552
+ * - `requirements`: Array of matching requirements with:
553
+ * - `requirement_id`: Requirement identifier
554
+ * - `type`: Requirement type
555
+ * - `description`: Requirement description
556
+ * - `rationale`: Why this requirement exists
557
+ * - `affects_components`: List of affected components
558
+ * - `timestamp`: When requirement was documented
559
+ * - `total_found`: Number of requirements returned
560
+ *
561
+ * @example
562
+ * ```typescript
563
+ * const reqs = await handlers.getRequirements({
564
+ * component: 'authentication',
565
+ * type: 'security'
566
+ * });
567
+ * reqs.requirements.forEach(r => {
568
+ * console.log(`${r.type}: ${r.description}`);
569
+ * console.log(`Rationale: ${r.rationale}`);
570
+ * });
571
+ * ```
283
572
  */
284
573
  async getRequirements(args) {
285
574
  const typedArgs = args;
@@ -308,7 +597,43 @@ export class ToolHandlers {
308
597
  };
309
598
  }
310
599
  /**
311
- * Tool 9: get_tool_history
600
+ * Query history of tool uses (bash commands, file edits, reads, etc.).
601
+ *
602
+ * Shows what tools were used during conversations and their results. Useful
603
+ * for understanding what commands were run, what files were edited, and
604
+ * whether operations succeeded or failed.
605
+ *
606
+ * @param args - Tool history arguments:
607
+ * - `tool_name`: Optional filter by tool name (Bash, Edit, Write, Read)
608
+ * - `file_path`: Optional filter by file path
609
+ * - `limit`: Maximum number of results (default: 20)
610
+ *
611
+ * @returns Tool history containing:
612
+ * - `tool_name`: Tool filter if applied
613
+ * - `file_path`: File filter if applied
614
+ * - `tool_uses`: Array of tool uses with:
615
+ * - `tool_use_id`: Tool use identifier
616
+ * - `tool_name`: Name of the tool used
617
+ * - `tool_input`: Input parameters to the tool
618
+ * - `result`: Tool execution result with:
619
+ * - `content`: Result content
620
+ * - `is_error`: Whether the tool failed
621
+ * - `stdout`: Standard output (for Bash)
622
+ * - `stderr`: Standard error (for Bash)
623
+ * - `timestamp`: When the tool was used
624
+ * - `total_found`: Number of tool uses returned
625
+ *
626
+ * @example
627
+ * ```typescript
628
+ * const history = await handlers.getToolHistory({
629
+ * tool_name: 'Bash',
630
+ * limit: 10
631
+ * });
632
+ * history.tool_uses.forEach(t => {
633
+ * console.log(`${t.tool_name}: ${JSON.stringify(t.tool_input)}`);
634
+ * console.log(`Success: ${!t.result.is_error}`);
635
+ * });
636
+ * ```
312
637
  */
313
638
  async getToolHistory(args) {
314
639
  const typedArgs = args;
@@ -351,7 +676,39 @@ export class ToolHandlers {
351
676
  };
352
677
  }
353
678
  /**
354
- * Tool 10: find_similar_sessions
679
+ * Find conversations that dealt with similar topics or problems.
680
+ *
681
+ * Searches across all conversations to find ones that discussed similar topics,
682
+ * allowing you to learn from past work on similar problems.
683
+ *
684
+ * @param args - Similarity search arguments:
685
+ * - `query`: Description of the topic or problem (required)
686
+ * - `limit`: Maximum number of sessions (default: 5)
687
+ *
688
+ * @returns Similar sessions containing:
689
+ * - `query`: Search query used
690
+ * - `sessions`: Array of similar conversation sessions with:
691
+ * - `conversation_id`: Session identifier
692
+ * - `project_path`: Project path for this session
693
+ * - `first_message_at`: When the conversation started
694
+ * - `message_count`: Number of messages in the conversation
695
+ * - `git_branch`: Git branch at the time
696
+ * - `relevance_score`: Similarity score to the query
697
+ * - `relevant_messages`: Sample of relevant messages from this session
698
+ * - `total_found`: Number of sessions returned
699
+ *
700
+ * @example
701
+ * ```typescript
702
+ * const similar = await handlers.findSimilarSessions({
703
+ * query: 'implementing user authentication with JWT',
704
+ * limit: 3
705
+ * });
706
+ * similar.sessions.forEach(s => {
707
+ * console.log(`Session ${s.conversation_id} (${s.message_count} messages)`);
708
+ * console.log(`Relevance: ${s.relevance_score.toFixed(2)}`);
709
+ * console.log(`Messages: ${s.relevant_messages.length} relevant`);
710
+ * });
711
+ * ```
355
712
  */
356
713
  async findSimilarSessions(args) {
357
714
  const typedArgs = args;
@@ -391,8 +748,43 @@ export class ToolHandlers {
391
748
  };
392
749
  }
393
750
  /**
394
- * Tool 11: recall_and_apply
395
- * Recall relevant context and format for application to current work
751
+ * Recall relevant context and format for application to current work.
752
+ *
753
+ * This is a comprehensive context retrieval tool that searches across multiple
754
+ * data sources (conversations, decisions, mistakes, file changes, commits) and
755
+ * returns actionable suggestions for applying historical context to current work.
756
+ *
757
+ * @param args - Recall arguments:
758
+ * - `query`: What you're working on or need context for (required)
759
+ * - `context_types`: Types to recall (default: all types)
760
+ * - Options: "conversations", "decisions", "mistakes", "file_changes", "commits"
761
+ * - `file_path`: Optional filter for file-specific context
762
+ * - `date_range`: Optional [start_timestamp, end_timestamp] filter
763
+ * - `limit`: Maximum items per context type (default: 5)
764
+ *
765
+ * @returns Recalled context containing:
766
+ * - `query`: Search query used
767
+ * - `context_summary`: High-level summary of what was found
768
+ * - `recalled_context`: Structured context data:
769
+ * - `conversations`: Relevant past conversations
770
+ * - `decisions`: Related decisions with rationale
771
+ * - `mistakes`: Past mistakes to avoid
772
+ * - `file_changes`: File modification history
773
+ * - `commits`: Related git commits
774
+ * - `application_suggestions`: Actionable suggestions for applying this context
775
+ * - `total_items_found`: Total number of context items found
776
+ *
777
+ * @example
778
+ * ```typescript
779
+ * const context = await handlers.recallAndApply({
780
+ * query: 'refactoring database connection pooling',
781
+ * context_types: ['decisions', 'mistakes', 'commits'],
782
+ * file_path: 'src/database/pool.ts',
783
+ * limit: 5
784
+ * });
785
+ * console.log(context.context_summary);
786
+ * context.application_suggestions.forEach(s => console.log(`- ${s}`));
787
+ * ```
396
788
  */
397
789
  async recallAndApply(args) {
398
790
  const typedArgs = args;
@@ -422,22 +814,22 @@ export class ToolHandlers {
422
814
  if (context_types.includes("decisions")) {
423
815
  const decisions = this.db.getDatabase()
424
816
  .prepare(`
425
- SELECT decision_id, type, description, rationale, alternatives, rejected_approaches, affects_components, timestamp
817
+ SELECT id, decision_text, rationale, alternatives_considered, rejected_reasons, context, related_files, timestamp
426
818
  FROM decisions
427
- WHERE description LIKE ? ${file_path ? 'AND affects_components LIKE ?' : ''}
819
+ WHERE decision_text LIKE ? ${file_path ? 'AND related_files LIKE ?' : ''}
428
820
  ${date_range ? 'AND timestamp BETWEEN ? AND ?' : ''}
429
821
  ORDER BY timestamp DESC
430
822
  LIMIT ?
431
823
  `)
432
824
  .all(`%${sanitizeForLike(query)}%`, ...(file_path ? [`%${sanitizeForLike(file_path)}%`] : []), ...(date_range ? [date_range[0], date_range[1]] : []), limit);
433
825
  recalled.decisions = decisions.map(d => ({
434
- decision_id: d.decision_id,
435
- type: d.type,
436
- description: d.description,
826
+ decision_id: d.id,
827
+ type: d.context,
828
+ description: d.decision_text,
437
829
  rationale: d.rationale || undefined,
438
- alternatives: d.alternatives ? JSON.parse(d.alternatives) : undefined,
439
- rejected_approaches: d.rejected_approaches ? JSON.parse(d.rejected_approaches) : undefined,
440
- affects_components: JSON.parse(d.affects_components),
830
+ alternatives: d.alternatives_considered ? JSON.parse(d.alternatives_considered) : undefined,
831
+ rejected_approaches: d.rejected_reasons ? JSON.parse(d.rejected_reasons) : undefined,
832
+ affects_components: JSON.parse(d.related_files),
441
833
  timestamp: new Date(d.timestamp).toISOString(),
442
834
  }));
443
835
  totalItems += recalled.decisions.length;
@@ -559,7 +951,44 @@ export class ToolHandlers {
559
951
  };
560
952
  }
561
953
  /**
562
- * Tool 12: generate_documentation
954
+ * Generate comprehensive project documentation by combining codebase analysis
955
+ * with conversation history.
956
+ *
957
+ * Creates documentation that shows WHAT exists in the code (via CODE-GRAPH-RAG-MCP)
958
+ * and WHY it was built that way (via conversation history). Requires CODE-GRAPH-RAG-MCP
959
+ * to be indexed first.
960
+ *
961
+ * @param args - Documentation generation arguments:
962
+ * - `project_path`: Path to the project (defaults to cwd)
963
+ * - `session_id`: Optional specific session to include
964
+ * - `scope`: Documentation scope (default: 'full')
965
+ * - 'full': Everything (architecture, decisions, quality)
966
+ * - 'architecture': Module structure and dependencies
967
+ * - 'decisions': Decision log with rationale
968
+ * - 'quality': Code quality insights
969
+ * - `module_filter`: Optional filter for specific module path (e.g., 'src/auth')
970
+ *
971
+ * @returns Documentation result containing:
972
+ * - `success`: Whether generation succeeded
973
+ * - `project_path`: Project that was documented
974
+ * - `scope`: Scope of documentation generated
975
+ * - `documentation`: Generated markdown documentation
976
+ * - `statistics`: Summary statistics:
977
+ * - `modules`: Number of modules documented
978
+ * - `decisions`: Number of decisions included
979
+ * - `mistakes`: Number of mistakes documented
980
+ * - `commits`: Number of commits referenced
981
+ *
982
+ * @example
983
+ * ```typescript
984
+ * const doc = await handlers.generateDocumentation({
985
+ * project_path: '/Users/me/my-project',
986
+ * scope: 'full',
987
+ * module_filter: 'src/auth'
988
+ * });
989
+ * console.log(doc.documentation); // Markdown documentation
990
+ * console.log(`Documented ${doc.statistics.modules} modules`);
991
+ * ```
563
992
  */
564
993
  async generateDocumentation(args) {
565
994
  const typedArgs = args;
@@ -612,7 +1041,43 @@ export class ToolHandlers {
612
1041
  };
613
1042
  }
614
1043
  /**
615
- * Tool 12: discover_old_conversations
1044
+ * Discover old conversation folders that might contain conversation history
1045
+ * for the current project.
1046
+ *
1047
+ * Searches through stored conversation folders to find potential matches for
1048
+ * the current project path. Useful when project paths have changed (e.g., after
1049
+ * moving or renaming a project directory).
1050
+ *
1051
+ * @param args - Discovery arguments:
1052
+ * - `current_project_path`: Current project path (defaults to cwd)
1053
+ *
1054
+ * @returns Discovery results containing:
1055
+ * - `success`: Whether discovery succeeded
1056
+ * - `current_project_path`: Current project path searched for
1057
+ * - `candidates`: Array of potential matches sorted by score:
1058
+ * - `folder_name`: Name of the conversation folder
1059
+ * - `folder_path`: Full path to the folder
1060
+ * - `stored_project_path`: Original project path stored in conversations
1061
+ * - `score`: Match score (higher is better match)
1062
+ * - `stats`: Folder statistics:
1063
+ * - `conversations`: Number of conversations in folder
1064
+ * - `messages`: Number of messages in folder
1065
+ * - `files`: Number of .jsonl files
1066
+ * - `last_activity`: Timestamp of last activity
1067
+ * - `message`: Human-readable status message
1068
+ *
1069
+ * @example
1070
+ * ```typescript
1071
+ * const discovery = await handlers.discoverOldConversations({
1072
+ * current_project_path: '/Users/me/projects/my-app'
1073
+ * });
1074
+ * console.log(discovery.message);
1075
+ * discovery.candidates.forEach(c => {
1076
+ * console.log(`Score ${c.score}: ${c.folder_name}`);
1077
+ * console.log(` Original path: ${c.stored_project_path}`);
1078
+ * console.log(` Stats: ${c.stats.conversations} conversations, ${c.stats.files} files`);
1079
+ * });
1080
+ * ```
616
1081
  */
617
1082
  async discoverOldConversations(args) {
618
1083
  const typedArgs = args;
@@ -652,7 +1117,51 @@ export class ToolHandlers {
652
1117
  };
653
1118
  }
654
1119
  /**
655
- * Tool 13: migrate_project
1120
+ * Migrate or merge conversation history from an old project path to a new one.
1121
+ *
1122
+ * Use this when a project has been moved or renamed to bring the conversation
1123
+ * history along. Supports two modes: 'migrate' (move all files) or 'merge'
1124
+ * (combine with existing files).
1125
+ *
1126
+ * @param args - Migration arguments:
1127
+ * - `source_folder`: Source folder containing old conversations (required)
1128
+ * - `old_project_path`: Original project path in the conversations (required)
1129
+ * - `new_project_path`: New project path to update to (required)
1130
+ * - `dry_run`: Preview changes without applying them (default: false)
1131
+ * - `mode`: Migration mode (default: 'migrate')
1132
+ * - 'migrate': Move all files from source to target
1133
+ * - 'merge': Combine source files with existing target files
1134
+ *
1135
+ * @returns Migration result containing:
1136
+ * - `success`: Whether migration succeeded
1137
+ * - `source_folder`: Source folder path
1138
+ * - `target_folder`: Target folder path (where files were copied)
1139
+ * - `files_copied`: Number of files copied/migrated
1140
+ * - `database_updated`: Whether database was updated with new paths
1141
+ * - `backup_created`: Whether backup was created (always true for non-dry-run)
1142
+ * - `message`: Human-readable status message
1143
+ *
1144
+ * @example
1145
+ * ```typescript
1146
+ * // First, preview with dry run
1147
+ * const preview = await handlers.migrateProject({
1148
+ * source_folder: '/path/to/old/conversations',
1149
+ * old_project_path: '/old/path/to/project',
1150
+ * new_project_path: '/new/path/to/project',
1151
+ * dry_run: true
1152
+ * });
1153
+ * console.log(preview.message); // "Dry run: Would migrate X files..."
1154
+ *
1155
+ * // Then, execute the migration
1156
+ * const result = await handlers.migrateProject({
1157
+ * source_folder: '/path/to/old/conversations',
1158
+ * old_project_path: '/old/path/to/project',
1159
+ * new_project_path: '/new/path/to/project',
1160
+ * dry_run: false,
1161
+ * mode: 'migrate'
1162
+ * });
1163
+ * console.log(`Migrated ${result.files_copied} files`);
1164
+ * ```
656
1165
  */
657
1166
  async migrateProject(args) {
658
1167
  const typedArgs = args;