@crowley/rag-mcp 1.0.5 → 1.1.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 (51) hide show
  1. package/dist/annotations.d.ts +16 -0
  2. package/dist/annotations.js +158 -0
  3. package/dist/context-enrichment.js +7 -0
  4. package/dist/formatters.d.ts +2 -0
  5. package/dist/formatters.js +12 -0
  6. package/dist/index.js +99 -47
  7. package/dist/schemas.d.ts +97 -0
  8. package/dist/schemas.js +128 -0
  9. package/dist/tool-middleware.d.ts +40 -0
  10. package/dist/tool-middleware.js +216 -0
  11. package/dist/tool-registry.js +2 -1
  12. package/dist/tools/advanced.d.ts +2 -2
  13. package/dist/tools/advanced.js +200 -275
  14. package/dist/tools/agents.d.ts +2 -2
  15. package/dist/tools/agents.js +59 -78
  16. package/dist/tools/analytics.d.ts +2 -2
  17. package/dist/tools/analytics.js +170 -210
  18. package/dist/tools/architecture.d.ts +2 -2
  19. package/dist/tools/architecture.js +506 -669
  20. package/dist/tools/ask.d.ts +2 -2
  21. package/dist/tools/ask.js +164 -219
  22. package/dist/tools/cache.d.ts +2 -2
  23. package/dist/tools/cache.js +63 -82
  24. package/dist/tools/clustering.d.ts +2 -2
  25. package/dist/tools/clustering.js +154 -215
  26. package/dist/tools/confluence.d.ts +2 -2
  27. package/dist/tools/confluence.js +80 -116
  28. package/dist/tools/database.d.ts +2 -2
  29. package/dist/tools/database.js +303 -380
  30. package/dist/tools/feedback.d.ts +2 -2
  31. package/dist/tools/feedback.js +143 -184
  32. package/dist/tools/guidelines.d.ts +2 -2
  33. package/dist/tools/guidelines.js +123 -135
  34. package/dist/tools/indexing.d.ts +2 -2
  35. package/dist/tools/indexing.js +100 -108
  36. package/dist/tools/memory.d.ts +2 -2
  37. package/dist/tools/memory.js +299 -485
  38. package/dist/tools/pm.d.ts +2 -2
  39. package/dist/tools/pm.js +367 -615
  40. package/dist/tools/quality.d.ts +8 -0
  41. package/dist/tools/quality.js +60 -0
  42. package/dist/tools/review.d.ts +2 -2
  43. package/dist/tools/review.js +142 -189
  44. package/dist/tools/search.d.ts +2 -2
  45. package/dist/tools/search.js +230 -305
  46. package/dist/tools/session.d.ts +2 -2
  47. package/dist/tools/session.js +288 -345
  48. package/dist/tools/suggestions.d.ts +2 -2
  49. package/dist/tools/suggestions.js +517 -512
  50. package/dist/types.d.ts +19 -2
  51. package/package.json +4 -2
@@ -2,8 +2,8 @@
2
2
  * Feedback tools module - search feedback, memory feedback, query suggestions,
3
3
  * and quality metrics.
4
4
  */
5
- import type { ToolModule } from "../types.js";
5
+ import type { ToolSpec } from "../types.js";
6
6
  /**
7
7
  * Create the feedback tools module with project-specific descriptions.
8
8
  */
9
- export declare function createFeedbackTools(projectName: string): ToolModule;
9
+ export declare function createFeedbackTools(projectName: string): ToolSpec[];
@@ -3,218 +3,177 @@
3
3
  * and quality metrics.
4
4
  */
5
5
  import { pct } from "../formatters.js";
6
+ import { z } from "zod";
7
+ import { TOOL_ANNOTATIONS } from "../annotations.js";
6
8
  /**
7
9
  * Create the feedback tools module with project-specific descriptions.
8
10
  */
9
11
  export function createFeedbackTools(projectName) {
10
- const tools = [
12
+ return [
11
13
  {
12
14
  name: "feedback_search",
13
15
  description: `Provide feedback on a search result quality for ${projectName}. Helps improve future search results.`,
14
- inputSchema: {
15
- type: "object",
16
- properties: {
17
- query: {
18
- type: "string",
19
- description: "The original search query",
20
- },
21
- feedbackType: {
22
- type: "string",
23
- enum: ["helpful", "not_helpful", "partially"],
24
- description: "How helpful the results were",
25
- },
26
- file: {
27
- type: "string",
28
- description: "The file from results being rated",
29
- },
30
- suggestedQuery: {
31
- type: "string",
32
- description: "A better query that would have found the right results",
33
- },
34
- },
35
- required: ["query", "feedbackType"],
16
+ schema: z.object({
17
+ query: z.string().describe("The original search query"),
18
+ feedbackType: z.enum(["helpful", "not_helpful", "partially"]).describe("How helpful the results were"),
19
+ file: z.string().optional().describe("The file from results being rated"),
20
+ suggestedQuery: z.string().optional().describe("A better query that would have found the right results"),
21
+ }),
22
+ annotations: TOOL_ANNOTATIONS["feedback_search"],
23
+ handler: async (args, ctx) => {
24
+ const { query, feedbackType, file, suggestedQuery } = args;
25
+ const response = await ctx.api.post("/api/feedback/search", {
26
+ projectName: ctx.projectName,
27
+ query,
28
+ feedbackType,
29
+ file,
30
+ suggestedQuery,
31
+ });
32
+ const emojis = {
33
+ helpful: "\ud83d\udc4d",
34
+ not_helpful: "\ud83d\udc4e",
35
+ partially: "\ud83e\udd14",
36
+ };
37
+ const emoji = emojis[feedbackType] || "";
38
+ let result = `${emoji} **Search Feedback Recorded**\n\n`;
39
+ result += `- **Query:** ${query}\n`;
40
+ result += `- **Feedback:** ${feedbackType}\n`;
41
+ if (file)
42
+ result += `- **File:** ${file}\n`;
43
+ if (suggestedQuery)
44
+ result += `- **Suggested Query:** ${suggestedQuery}\n`;
45
+ return result;
36
46
  },
37
47
  },
38
48
  {
39
49
  name: "feedback_memory",
40
50
  description: `Provide feedback on a memory's accuracy for ${projectName}. Helps keep memory quality high.`,
41
- inputSchema: {
42
- type: "object",
43
- properties: {
44
- memoryId: {
45
- type: "string",
46
- description: "The memory ID to provide feedback on",
47
- },
48
- feedback: {
49
- type: "string",
50
- enum: ["accurate", "outdated", "incorrect"],
51
- description: "Feedback on the memory's accuracy",
52
- },
53
- correction: {
54
- type: "string",
55
- description: "Corrected information if the memory is wrong",
56
- },
57
- },
58
- required: ["memoryId", "feedback"],
51
+ schema: z.object({
52
+ memoryId: z.string().describe("The memory ID to provide feedback on"),
53
+ feedback: z.enum(["accurate", "outdated", "incorrect"]).describe("Feedback on the memory's accuracy"),
54
+ correction: z.string().optional().describe("Corrected information if the memory is wrong"),
55
+ }),
56
+ annotations: TOOL_ANNOTATIONS["feedback_memory"],
57
+ handler: async (args, ctx) => {
58
+ const { memoryId, feedback, correction } = args;
59
+ const response = await ctx.api.post("/api/feedback/memory", {
60
+ projectName: ctx.projectName,
61
+ memoryId,
62
+ feedback,
63
+ correction,
64
+ });
65
+ const emojis = {
66
+ accurate: "\u2705",
67
+ outdated: "\u23f0",
68
+ incorrect: "\u274c",
69
+ };
70
+ const emoji = emojis[feedback] || "";
71
+ let result = `${emoji} **Memory Feedback Recorded**\n\n`;
72
+ result += `- **Memory ID:** ${memoryId}\n`;
73
+ result += `- **Feedback:** ${feedback}\n`;
74
+ if (correction)
75
+ result += `- **Correction:** ${correction}\n`;
76
+ return result;
59
77
  },
60
78
  },
61
79
  {
62
80
  name: "suggest_better_query",
63
81
  description: `Get query improvement suggestions based on feedback patterns for ${projectName}.`,
64
- inputSchema: {
65
- type: "object",
66
- properties: {
67
- query: {
68
- type: "string",
69
- description: "The query to get suggestions for",
70
- },
71
- context: {
72
- type: "string",
73
- description: "Additional context about what you are looking for",
74
- },
75
- },
76
- required: ["query"],
77
- },
78
- },
79
- {
80
- name: "get_quality_metrics",
81
- description: `Get search and memory quality metrics for ${projectName}.`,
82
- inputSchema: {
83
- type: "object",
84
- properties: {},
85
- },
86
- },
87
- ];
88
- const handlers = {
89
- feedback_search: async (args, ctx) => {
90
- const { query, feedbackType, file, suggestedQuery } = args;
91
- const response = await ctx.api.post("/api/feedback/search", {
92
- projectName: ctx.projectName,
93
- query,
94
- feedbackType,
95
- file,
96
- suggestedQuery,
97
- });
98
- const emojis = {
99
- helpful: "\ud83d\udc4d",
100
- not_helpful: "\ud83d\udc4e",
101
- partially: "\ud83e\udd14",
102
- };
103
- const emoji = emojis[feedbackType] || "";
104
- let result = `${emoji} **Search Feedback Recorded**\n\n`;
105
- result += `- **Query:** ${query}\n`;
106
- result += `- **Feedback:** ${feedbackType}\n`;
107
- if (file)
108
- result += `- **File:** ${file}\n`;
109
- if (suggestedQuery)
110
- result += `- **Suggested Query:** ${suggestedQuery}\n`;
111
- return result;
112
- },
113
- feedback_memory: async (args, ctx) => {
114
- const { memoryId, feedback, correction } = args;
115
- const response = await ctx.api.post("/api/feedback/memory", {
116
- projectName: ctx.projectName,
117
- memoryId,
118
- feedback,
119
- correction,
120
- });
121
- const emojis = {
122
- accurate: "\u2705",
123
- outdated: "\u23f0",
124
- incorrect: "\u274c",
125
- };
126
- const emoji = emojis[feedback] || "";
127
- let result = `${emoji} **Memory Feedback Recorded**\n\n`;
128
- result += `- **Memory ID:** ${memoryId}\n`;
129
- result += `- **Feedback:** ${feedback}\n`;
130
- if (correction)
131
- result += `- **Correction:** ${correction}\n`;
132
- return result;
133
- },
134
- suggest_better_query: async (args, ctx) => {
135
- const { query, context } = args;
136
- let suggestions = [];
137
- try {
138
- const response = await ctx.api.post("/api/query/suggest", {
139
- projectName: ctx.projectName,
140
- query,
141
- context,
142
- });
143
- suggestions = response.data.suggestions || [];
144
- }
145
- catch {
146
- // Fallback to query analyze
147
- }
148
- if (!suggestions || suggestions.length === 0) {
82
+ schema: z.object({
83
+ query: z.string().describe("The query to get suggestions for"),
84
+ context: z.string().optional().describe("Additional context about what you are looking for"),
85
+ }),
86
+ annotations: TOOL_ANNOTATIONS["suggest_better_query"],
87
+ handler: async (args, ctx) => {
88
+ const { query, context } = args;
89
+ let suggestions = [];
149
90
  try {
150
- const fallback = await ctx.api.post("/api/query/analyze", {
91
+ const response = await ctx.api.post("/api/query/suggest", {
151
92
  projectName: ctx.projectName,
152
93
  query,
153
94
  context,
154
95
  });
155
- suggestions = fallback.data.suggestions || [];
96
+ suggestions = response.data.suggestions || [];
156
97
  }
157
98
  catch {
99
+ // Fallback to query analyze
100
+ }
101
+ if (!suggestions || suggestions.length === 0) {
102
+ try {
103
+ const fallback = await ctx.api.post("/api/query/analyze", {
104
+ projectName: ctx.projectName,
105
+ query,
106
+ context,
107
+ });
108
+ suggestions = fallback.data.suggestions || [];
109
+ }
110
+ catch {
111
+ return "No query suggestions available.";
112
+ }
113
+ }
114
+ if (!suggestions || suggestions.length === 0) {
158
115
  return "No query suggestions available.";
159
116
  }
160
- }
161
- if (!suggestions || suggestions.length === 0) {
162
- return "No query suggestions available.";
163
- }
164
- const sourceEmojis = {
165
- feedback: "\ud83d\udcca",
166
- pattern: "\ud83d\udd04",
167
- ai: "\ud83e\udd16",
168
- };
169
- let result = `## Query Suggestions\n\n`;
170
- for (const s of suggestions) {
171
- const emoji = sourceEmojis[s.source] || "";
172
- result += `- ${emoji} **${s.query || s.suggestion}**`;
173
- if (s.confidence)
174
- result += ` (confidence: ${pct(s.confidence)})`;
175
- result += "\n";
176
- }
177
- return result;
178
- },
179
- get_quality_metrics: async (_args, ctx) => {
180
- const response = await ctx.api.get(`/api/quality/${ctx.projectName}`);
181
- const data = response.data;
182
- let result = `## Quality Metrics: ${projectName}\n\n`;
183
- if (data.searchQuality) {
184
- const sq = data.searchQuality;
185
- result += `### Search Quality\n`;
186
- result += `- Helpful: ${pct(sq.helpfulRate || 0)}\n`;
187
- result += `- Partially Helpful: ${pct(sq.partialRate || 0)}\n`;
188
- result += `- Not Helpful: ${pct(sq.notHelpfulRate || 0)}\n\n`;
189
- }
190
- if (data.memoryQuality) {
191
- const mq = data.memoryQuality;
192
- result += `### Memory Quality\n`;
193
- result += `- Accuracy: ${pct(mq.accuracyRate || 0)}\n`;
194
- result += `- Outdated: ${pct(mq.outdatedRate || 0)}\n`;
195
- result += `- Incorrect: ${pct(mq.incorrectRate || 0)}\n\n`;
196
- }
197
- if (data.trends) {
198
- const trendEmojis = {
199
- up: "\ud83d\udcc8",
200
- down: "\ud83d\udcc9",
201
- flat: "\u27a1\ufe0f",
117
+ const sourceEmojis = {
118
+ feedback: "\ud83d\udcca",
119
+ pattern: "\ud83d\udd04",
120
+ ai: "\ud83e\udd16",
202
121
  };
203
- result += `### Trends\n`;
204
- for (const [metric, direction] of Object.entries(data.trends)) {
205
- const emoji = trendEmojis[direction] || "\u27a1\ufe0f";
206
- result += `- ${emoji} ${metric}: ${direction}\n`;
122
+ let result = `## Query Suggestions\n\n`;
123
+ for (const s of suggestions) {
124
+ const emoji = sourceEmojis[s.source] || "";
125
+ result += `- ${emoji} **${s.query || s.suggestion}**`;
126
+ if (s.confidence)
127
+ result += ` (confidence: ${pct(s.confidence)})`;
128
+ result += "\n";
129
+ }
130
+ return result;
131
+ },
132
+ },
133
+ {
134
+ name: "get_quality_metrics",
135
+ description: `Get search and memory quality metrics for ${projectName}.`,
136
+ schema: z.object({}),
137
+ annotations: TOOL_ANNOTATIONS["get_quality_metrics"],
138
+ handler: async (_args, ctx) => {
139
+ const response = await ctx.api.get(`/api/quality/${ctx.projectName}`);
140
+ const data = response.data;
141
+ let result = `## Quality Metrics: ${projectName}\n\n`;
142
+ if (data.searchQuality) {
143
+ const sq = data.searchQuality;
144
+ result += `### Search Quality\n`;
145
+ result += `- Helpful: ${pct(sq.helpfulRate || 0)}\n`;
146
+ result += `- Partially Helpful: ${pct(sq.partialRate || 0)}\n`;
147
+ result += `- Not Helpful: ${pct(sq.notHelpfulRate || 0)}\n\n`;
207
148
  }
208
- result += "\n";
209
- }
210
- if (data.problematicQueries && data.problematicQueries.length > 0) {
211
- result += `### Problematic Queries\n`;
212
- for (const q of data.problematicQueries) {
213
- result += `- "${q.query}" (${q.count || 0} times)\n`;
149
+ if (data.memoryQuality) {
150
+ const mq = data.memoryQuality;
151
+ result += `### Memory Quality\n`;
152
+ result += `- Accuracy: ${pct(mq.accuracyRate || 0)}\n`;
153
+ result += `- Outdated: ${pct(mq.outdatedRate || 0)}\n`;
154
+ result += `- Incorrect: ${pct(mq.incorrectRate || 0)}\n\n`;
214
155
  }
215
- }
216
- return result;
156
+ if (data.trends) {
157
+ const trendEmojis = {
158
+ up: "\ud83d\udcc8",
159
+ down: "\ud83d\udcc9",
160
+ flat: "\u27a1\ufe0f",
161
+ };
162
+ result += `### Trends\n`;
163
+ for (const [metric, direction] of Object.entries(data.trends)) {
164
+ const emoji = trendEmojis[direction] || "\u27a1\ufe0f";
165
+ result += `- ${emoji} ${metric}: ${direction}\n`;
166
+ }
167
+ result += "\n";
168
+ }
169
+ if (data.problematicQueries && data.problematicQueries.length > 0) {
170
+ result += `### Problematic Queries\n`;
171
+ for (const q of data.problematicQueries) {
172
+ result += `- "${q.query}" (${q.count || 0} times)\n`;
173
+ }
174
+ }
175
+ return result;
176
+ },
217
177
  },
218
- };
219
- return { tools, handlers };
178
+ ];
220
179
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * RAG Guidelines Tool
3
3
  */
4
- import type { ToolModule } from "../types.js";
5
- export declare function createGuidelinesTools(projectName: string): ToolModule;
4
+ import type { ToolSpec } from "../types.js";
5
+ export declare function createGuidelinesTools(projectName: string): ToolSpec[];
@@ -1,146 +1,134 @@
1
1
  /**
2
2
  * RAG Guidelines Tool
3
3
  */
4
+ import { z } from "zod";
5
+ import { TOOL_ANNOTATIONS } from "../annotations.js";
4
6
  export function createGuidelinesTools(projectName) {
5
- const tools = [
7
+ return [
6
8
  {
7
9
  name: "get_rag_guidelines",
8
10
  description: `Get recommended settings and best practices for working with RAG in ${projectName}. Shows optimal tool usage patterns, query strategies, and session management tips.`,
9
- inputSchema: {
10
- type: "object",
11
- properties: {
12
- focus: {
13
- type: "string",
14
- enum: ["all", "search", "memory", "session", "feedback", "performance"],
15
- description: "Focus area for guidelines (default: all)",
16
- default: "all",
17
- },
18
- context: {
19
- type: "string",
20
- enum: ["coding", "debugging", "reviewing", "learning", "documenting"],
21
- description: "Current work context for tailored recommendations",
22
- },
23
- },
11
+ schema: z.object({
12
+ focus: z.enum(["all", "search", "memory", "session", "feedback", "performance"]).optional().describe("Focus area for guidelines (default: all)"),
13
+ context: z.enum(["coding", "debugging", "reviewing", "learning", "documenting"]).optional().describe("Current work context for tailored recommendations"),
14
+ }),
15
+ annotations: TOOL_ANNOTATIONS["get_rag_guidelines"],
16
+ handler: async (args, ctx) => {
17
+ const { focus = "all", context } = args;
18
+ let result = `# 📚 RAG Guidelines for ${ctx.projectName}\n\n`;
19
+ if (context) {
20
+ const contextTips = {
21
+ coding: "🔧 **Mode: Coding** - Focus on implementation patterns and related code",
22
+ debugging: "🐛 **Mode: Debugging** - Focus on error patterns and similar issues",
23
+ reviewing: "👀 **Mode: Reviewing** - Focus on patterns, ADRs, and best practices",
24
+ learning: "📖 **Mode: Learning** - Focus on documentation and explanations",
25
+ documenting: "📝 **Mode: Documenting** - Focus on existing docs and patterns",
26
+ };
27
+ result += `${contextTips[context] || ""}\n\n`;
28
+ }
29
+ if (focus === "all" || focus === "search") {
30
+ result += `## 🔍 Search Best Practices\n\n`;
31
+ result += `### Query Formulation\n`;
32
+ result += `- **Be specific**: "authentication middleware express" > "auth code"\n`;
33
+ result += `- **Include context**: Add file types, modules, or features\n`;
34
+ result += `- **Use technical terms**: Match actual code terminology\n`;
35
+ result += `- **Combine concepts**: "error handling async database"\n\n`;
36
+ result += `### Tool Selection\n`;
37
+ result += `| Goal | Tool | When |\n`;
38
+ result += `|------|------|------|\n`;
39
+ result += `| Find code | \`search_codebase\` | General code search |\n`;
40
+ result += `| Find similar | \`search_similar\` | Have code snippet |\n`;
41
+ result += `| Understand | \`ask_codebase\` | Need explanation |\n`;
42
+ result += `| Find feature | \`find_feature\` | Know what it does |\n`;
43
+ result += `| Group by file | \`grouped_search\` | Overview needed |\n`;
44
+ result += `| Exact + semantic | \`hybrid_search\` | Specific terms |\n\n`;
45
+ }
46
+ if (focus === "all" || focus === "memory") {
47
+ result += `## 🧠 Memory Best Practices\n\n`;
48
+ result += `### What to Remember\n`;
49
+ result += `| Type | Use For | Example |\n`;
50
+ result += `|------|---------|----------|\n`;
51
+ result += `| \`decision\` | Architecture choices | "Use WebSocket for real-time" |\n`;
52
+ result += `| \`insight\` | Learned patterns | "Service X fails under load" |\n`;
53
+ result += `| \`context\` | Project knowledge | "Module Y handles payments" |\n`;
54
+ result += `| \`todo\` | Tasks to track | "Refactor auth after v2" |\n`;
55
+ result += `| \`note\` | General notes | "Config in .env.local" |\n\n`;
56
+ result += `### Architecture Knowledge\n`;
57
+ result += `- Record ADRs: \`record_adr\` for major decisions\n`;
58
+ result += `- Record patterns: \`record_pattern\` for code structures\n`;
59
+ result += `- Record tech debt: \`record_tech_debt\` for known issues\n`;
60
+ result += `- Check before coding: \`check_architecture\`\n\n`;
61
+ }
62
+ if (focus === "all" || focus === "session") {
63
+ result += `## 📋 Session Management\n\n`;
64
+ result += `### Recommended Workflow\n`;
65
+ result += `\`\`\`\n`;
66
+ result += `1. start_session # Begin with context\n`;
67
+ result += `2. warm_cache # Pre-load embeddings\n`;
68
+ result += `3. ... work ... # Tools auto-track activity\n`;
69
+ result += `4. end_session # Save learnings, get summary\n`;
70
+ result += `\`\`\`\n\n`;
71
+ }
72
+ if (focus === "all" || focus === "feedback") {
73
+ result += `## 👍 Feedback Guidelines\n\n`;
74
+ result += `| Result Quality | Action |\n`;
75
+ result += `|----------------|--------|\n`;
76
+ result += `| Found what needed | \`feedback_search\` -> helpful |\n`;
77
+ result += `| Partially useful | \`feedback_search\` -> partially_helpful |\n`;
78
+ result += `| Not relevant | \`feedback_search\` -> not_helpful + better query |\n\n`;
79
+ }
80
+ if (focus === "all" || focus === "performance") {
81
+ result += `## ⚡ Performance Optimization\n\n`;
82
+ result += `### Expected Performance\n`;
83
+ result += `| Operation | L1 Hit | L2 Hit | Miss |\n`;
84
+ result += `|-----------|--------|--------|------|\n`;
85
+ result += `| Embedding | 1-5ms | 5-15ms | 50-200ms |\n`;
86
+ result += `| Search | 20-50ms | 50-150ms | 100-500ms |\n`;
87
+ result += `| Memory recall | 10-30ms | 30-100ms | 100-300ms |\n\n`;
88
+ }
89
+ if (context) {
90
+ result += `## 🎯 Recommendations for ${context.charAt(0).toUpperCase() + context.slice(1)}\n\n`;
91
+ const contextRecs = {
92
+ coding: [
93
+ "Use `suggest_implementation` before writing new code",
94
+ "Check `suggest_related_code` for dependencies",
95
+ "Run `check_architecture` to validate patterns",
96
+ ],
97
+ debugging: [
98
+ "Search for error messages with `hybrid_search`",
99
+ "Use `ask_codebase` to understand error context",
100
+ "Record solutions as `insight` memories",
101
+ ],
102
+ reviewing: [
103
+ "Check `get_adrs` for architectural decisions",
104
+ "Use `get_patterns` for expected structures",
105
+ "Run `check_architecture` on changes",
106
+ ],
107
+ learning: [
108
+ "Start with `ask_codebase` for explanations",
109
+ "Use `explain_code` for complex snippets",
110
+ "Remember insights for future reference",
111
+ ],
112
+ documenting: [
113
+ "Use `search_docs` for existing documentation",
114
+ "Check `get_patterns` for structure templates",
115
+ "Record new patterns with `record_pattern`",
116
+ ],
117
+ };
118
+ const recs = contextRecs[context] || [];
119
+ recs.forEach((rec, i) => {
120
+ result += `${i + 1}. ${rec}\n`;
121
+ });
122
+ result += "\n";
123
+ }
124
+ result += `## 📌 Quick Reference\n\n`;
125
+ result += `- \`search_codebase\` - Find code\n`;
126
+ result += `- \`ask_codebase\` - Get explanations\n`;
127
+ result += `- \`remember\` - Save knowledge\n`;
128
+ result += `- \`recall\` - Retrieve knowledge\n`;
129
+ result += `- \`suggest_better_query\` - Improve searches\n`;
130
+ return result;
24
131
  },
25
132
  },
26
133
  ];
27
- const handlers = {
28
- get_rag_guidelines: async (args, ctx) => {
29
- const { focus = "all", context } = args;
30
- let result = `# 📚 RAG Guidelines for ${ctx.projectName}\n\n`;
31
- if (context) {
32
- const contextTips = {
33
- coding: "🔧 **Mode: Coding** - Focus on implementation patterns and related code",
34
- debugging: "🐛 **Mode: Debugging** - Focus on error patterns and similar issues",
35
- reviewing: "👀 **Mode: Reviewing** - Focus on patterns, ADRs, and best practices",
36
- learning: "📖 **Mode: Learning** - Focus on documentation and explanations",
37
- documenting: "📝 **Mode: Documenting** - Focus on existing docs and patterns",
38
- };
39
- result += `${contextTips[context] || ""}\n\n`;
40
- }
41
- if (focus === "all" || focus === "search") {
42
- result += `## 🔍 Search Best Practices\n\n`;
43
- result += `### Query Formulation\n`;
44
- result += `- **Be specific**: "authentication middleware express" > "auth code"\n`;
45
- result += `- **Include context**: Add file types, modules, or features\n`;
46
- result += `- **Use technical terms**: Match actual code terminology\n`;
47
- result += `- **Combine concepts**: "error handling async database"\n\n`;
48
- result += `### Tool Selection\n`;
49
- result += `| Goal | Tool | When |\n`;
50
- result += `|------|------|------|\n`;
51
- result += `| Find code | \`search_codebase\` | General code search |\n`;
52
- result += `| Find similar | \`search_similar\` | Have code snippet |\n`;
53
- result += `| Understand | \`ask_codebase\` | Need explanation |\n`;
54
- result += `| Find feature | \`find_feature\` | Know what it does |\n`;
55
- result += `| Group by file | \`grouped_search\` | Overview needed |\n`;
56
- result += `| Exact + semantic | \`hybrid_search\` | Specific terms |\n\n`;
57
- }
58
- if (focus === "all" || focus === "memory") {
59
- result += `## 🧠 Memory Best Practices\n\n`;
60
- result += `### What to Remember\n`;
61
- result += `| Type | Use For | Example |\n`;
62
- result += `|------|---------|----------|\n`;
63
- result += `| \`decision\` | Architecture choices | "Use WebSocket for real-time" |\n`;
64
- result += `| \`insight\` | Learned patterns | "Service X fails under load" |\n`;
65
- result += `| \`context\` | Project knowledge | "Module Y handles payments" |\n`;
66
- result += `| \`todo\` | Tasks to track | "Refactor auth after v2" |\n`;
67
- result += `| \`note\` | General notes | "Config in .env.local" |\n\n`;
68
- result += `### Architecture Knowledge\n`;
69
- result += `- Record ADRs: \`record_adr\` for major decisions\n`;
70
- result += `- Record patterns: \`record_pattern\` for code structures\n`;
71
- result += `- Record tech debt: \`record_tech_debt\` for known issues\n`;
72
- result += `- Check before coding: \`check_architecture\`\n\n`;
73
- }
74
- if (focus === "all" || focus === "session") {
75
- result += `## 📋 Session Management\n\n`;
76
- result += `### Recommended Workflow\n`;
77
- result += `\`\`\`\n`;
78
- result += `1. start_session # Begin with context\n`;
79
- result += `2. warm_cache # Pre-load embeddings\n`;
80
- result += `3. ... work ... # Tools auto-track activity\n`;
81
- result += `4. end_session # Save learnings, get summary\n`;
82
- result += `\`\`\`\n\n`;
83
- }
84
- if (focus === "all" || focus === "feedback") {
85
- result += `## 👍 Feedback Guidelines\n\n`;
86
- result += `| Result Quality | Action |\n`;
87
- result += `|----------------|--------|\n`;
88
- result += `| Found what needed | \`feedback_search\` -> helpful |\n`;
89
- result += `| Partially useful | \`feedback_search\` -> partially_helpful |\n`;
90
- result += `| Not relevant | \`feedback_search\` -> not_helpful + better query |\n\n`;
91
- }
92
- if (focus === "all" || focus === "performance") {
93
- result += `## ⚡ Performance Optimization\n\n`;
94
- result += `### Expected Performance\n`;
95
- result += `| Operation | L1 Hit | L2 Hit | Miss |\n`;
96
- result += `|-----------|--------|--------|------|\n`;
97
- result += `| Embedding | 1-5ms | 5-15ms | 50-200ms |\n`;
98
- result += `| Search | 20-50ms | 50-150ms | 100-500ms |\n`;
99
- result += `| Memory recall | 10-30ms | 30-100ms | 100-300ms |\n\n`;
100
- }
101
- if (context) {
102
- result += `## 🎯 Recommendations for ${context.charAt(0).toUpperCase() + context.slice(1)}\n\n`;
103
- const contextRecs = {
104
- coding: [
105
- "Use `suggest_implementation` before writing new code",
106
- "Check `suggest_related_code` for dependencies",
107
- "Run `check_architecture` to validate patterns",
108
- ],
109
- debugging: [
110
- "Search for error messages with `hybrid_search`",
111
- "Use `ask_codebase` to understand error context",
112
- "Record solutions as `insight` memories",
113
- ],
114
- reviewing: [
115
- "Check `get_adrs` for architectural decisions",
116
- "Use `get_patterns` for expected structures",
117
- "Run `check_architecture` on changes",
118
- ],
119
- learning: [
120
- "Start with `ask_codebase` for explanations",
121
- "Use `explain_code` for complex snippets",
122
- "Remember insights for future reference",
123
- ],
124
- documenting: [
125
- "Use `search_docs` for existing documentation",
126
- "Check `get_patterns` for structure templates",
127
- "Record new patterns with `record_pattern`",
128
- ],
129
- };
130
- const recs = contextRecs[context] || [];
131
- recs.forEach((rec, i) => {
132
- result += `${i + 1}. ${rec}\n`;
133
- });
134
- result += "\n";
135
- }
136
- result += `## 📌 Quick Reference\n\n`;
137
- result += `- \`search_codebase\` - Find code\n`;
138
- result += `- \`ask_codebase\` - Get explanations\n`;
139
- result += `- \`remember\` - Save knowledge\n`;
140
- result += `- \`recall\` - Retrieve knowledge\n`;
141
- result += `- \`suggest_better_query\` - Improve searches\n`;
142
- return result;
143
- },
144
- };
145
- return { tools, handlers };
146
134
  }