@phuetz/code-buddy 0.1.20 → 0.1.23

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.
@@ -0,0 +1,142 @@
1
+ /**
2
+ * MCP Agent Tools - Expose Code Buddy's AI reasoning capabilities
3
+ *
4
+ * Tools:
5
+ * - agent_chat: Send message to agent, get response
6
+ * - agent_task: Autonomous task execution
7
+ * - agent_plan: Create plan without executing
8
+ */
9
+ import { z } from 'zod';
10
+ /**
11
+ * Promise-based queue lock to serialize agent calls (agent is not thread-safe).
12
+ */
13
+ let agentLock = Promise.resolve();
14
+ function withLock(fn) {
15
+ const result = agentLock.then(fn, fn);
16
+ agentLock = result.then(() => { }, () => { });
17
+ return result;
18
+ }
19
+ /**
20
+ * Format ChatEntry[] into readable text for MCP responses.
21
+ */
22
+ export function formatAgentResponse(entries) {
23
+ const parts = [];
24
+ for (const entry of entries) {
25
+ switch (entry.type) {
26
+ case 'assistant':
27
+ if (entry.content)
28
+ parts.push(entry.content);
29
+ break;
30
+ case 'tool_call':
31
+ if (entry.toolCall) {
32
+ parts.push(`[Tool Call: ${entry.toolCall.function?.name || 'unknown'}]`);
33
+ }
34
+ break;
35
+ case 'tool_result':
36
+ if (entry.toolResult) {
37
+ const status = entry.toolResult.success ? 'Success' : 'Error';
38
+ const output = entry.toolResult.output || entry.toolResult.error || '';
39
+ if (output) {
40
+ parts.push(`[Tool Result: ${status}]\n${output}`);
41
+ }
42
+ }
43
+ break;
44
+ case 'reasoning':
45
+ if (entry.content)
46
+ parts.push(`[Reasoning] ${entry.content}`);
47
+ break;
48
+ case 'plan_progress':
49
+ if (entry.content)
50
+ parts.push(`[Plan Progress] ${entry.content}`);
51
+ break;
52
+ }
53
+ }
54
+ return parts.join('\n\n') || 'No response generated.';
55
+ }
56
+ /**
57
+ * Register agent intelligence tools with the MCP server.
58
+ */
59
+ export function registerAgentTools(server, getAgent) {
60
+ // agent_chat - Send message to agent, get response
61
+ server.tool('agent_chat', 'Send a message to the Code Buddy AI agent and get a response with tool call results. Use for conversational interactions.', {
62
+ message: z.string().describe('The message to send to the agent'),
63
+ mode: z.enum(['code', 'ask', 'plan', 'architect']).optional()
64
+ .describe('Agent mode: code (default), ask (no tools), plan (planning only), architect (design)'),
65
+ }, async (args) => {
66
+ try {
67
+ return await withLock(async () => {
68
+ const agent = await getAgent();
69
+ if (args.mode) {
70
+ agent.agentMode = args.mode;
71
+ }
72
+ const entries = await agent.processUserMessage(args.message);
73
+ return {
74
+ content: [{ type: 'text', text: formatAgentResponse(entries) }],
75
+ };
76
+ });
77
+ }
78
+ catch (error) {
79
+ const message = error instanceof Error ? error.message : String(error);
80
+ return {
81
+ content: [{ type: 'text', text: `Agent chat error: ${message}` }],
82
+ isError: true,
83
+ };
84
+ }
85
+ });
86
+ // agent_task - Autonomous task execution
87
+ server.tool('agent_task', 'Execute an autonomous task using Code Buddy agent. For complex tasks, uses DAG-based planning; for simple tasks, processes directly. Returns all tool calls and results.', {
88
+ task: z.string().describe('The task to execute autonomously'),
89
+ working_directory: z.string().optional()
90
+ .describe('Working directory for task execution (defaults to cwd)'),
91
+ }, async (args) => {
92
+ try {
93
+ return await withLock(async () => {
94
+ const agent = await getAgent();
95
+ if (args.working_directory) {
96
+ process.chdir(args.working_directory);
97
+ }
98
+ let entries;
99
+ if (agent.needsOrchestration(args.task)) {
100
+ entries = await agent.executePlan(args.task);
101
+ }
102
+ else {
103
+ entries = await agent.processUserMessage(args.task);
104
+ }
105
+ return {
106
+ content: [{ type: 'text', text: formatAgentResponse(entries) }],
107
+ };
108
+ });
109
+ }
110
+ catch (error) {
111
+ const message = error instanceof Error ? error.message : String(error);
112
+ return {
113
+ content: [{ type: 'text', text: `Agent task error: ${message}` }],
114
+ isError: true,
115
+ };
116
+ }
117
+ });
118
+ // agent_plan - Create plan without executing
119
+ server.tool('agent_plan', 'Create an execution plan for a task without executing it. Returns the DAG-based task plan with dependencies.', {
120
+ task: z.string().describe('The task to plan'),
121
+ }, async (args) => {
122
+ try {
123
+ return await withLock(async () => {
124
+ const agent = await getAgent();
125
+ // Set plan mode so agent creates plan without executing
126
+ agent.agentMode = 'plan';
127
+ const entries = await agent.processUserMessage(args.task);
128
+ return {
129
+ content: [{ type: 'text', text: formatAgentResponse(entries) }],
130
+ };
131
+ });
132
+ }
133
+ catch (error) {
134
+ const message = error instanceof Error ? error.message : String(error);
135
+ return {
136
+ content: [{ type: 'text', text: `Agent plan error: ${message}` }],
137
+ isError: true,
138
+ };
139
+ }
140
+ });
141
+ }
142
+ //# sourceMappingURL=mcp-agent-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-agent-tools.js","sourceRoot":"","sources":["../../src/mcp/mcp-agent-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB;;GAEG;AACH,IAAI,SAAS,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;AAEjD,SAAS,QAAQ,CAAI,EAAoB;IACvC,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACtC,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAC5C,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAoB;IACtD,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;YACnB,KAAK,WAAW;gBACd,IAAI,KAAK,CAAC,OAAO;oBAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBAC7C,MAAM;YACR,KAAK,WAAW;gBACd,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;o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AC;YACH,OAAO,MAAM,QAAQ,CAAC,KAAK,IAAI,EAAE;gBAC/B,MAAM,KAAK,GAAG,MAAM,QAAQ,EAAE,CAAC;gBAC/B,wDAAwD;gBACvD,KAA4C,CAAC,SAAS,GAAG,MAAM,CAAC;gBACjE,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC1D,OAAO;oBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC,EAAE,CAAC;iBACzE,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvE,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,qBAAqB,OAAO,EAAE,EAAE,CAAC;gBAC1E,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * MCP Memory Tools - Expose Code Buddy's memory system
3
+ *
4
+ * Tools:
5
+ * - memory_search: Search semantic memory
6
+ * - memory_save: Save a memory entry
7
+ */
8
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
9
+ /**
10
+ * Register memory tools with the MCP server.
11
+ */
12
+ export declare function registerMemoryTools(server: McpServer): void;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * MCP Memory Tools - Expose Code Buddy's memory system
3
+ *
4
+ * Tools:
5
+ * - memory_search: Search semantic memory
6
+ * - memory_save: Save a memory entry
7
+ */
8
+ import { z } from 'zod';
9
+ /**
10
+ * Register memory tools with the MCP server.
11
+ */
12
+ export function registerMemoryTools(server) {
13
+ // memory_search - Search semantic memory
14
+ server.tool('memory_search', 'Search Code Buddy\'s semantic memory for relevant stored knowledge, patterns, and context.', {
15
+ query: z.string().describe('The search query to find relevant memories'),
16
+ max_results: z.number().optional().describe('Maximum results to return (default: 5)'),
17
+ }, async (args) => {
18
+ try {
19
+ const { searchAndRetrieve } = await import('../memory/semantic-memory-search.js');
20
+ const results = await searchAndRetrieve(args.query, {
21
+ maxResults: args.max_results ?? 5,
22
+ });
23
+ if (results.length === 0) {
24
+ return {
25
+ content: [{ type: 'text', text: 'No matching memories found.' }],
26
+ };
27
+ }
28
+ const formatted = results.map((r, i) => {
29
+ const { result, content } = r;
30
+ return [
31
+ `## Result ${i + 1} (score: ${result.score.toFixed(2)})`,
32
+ `**Source:** ${result.entry.metadata?.source || 'unknown'}`,
33
+ `**Snippet:** ${result.snippet}`,
34
+ content ? `**Content:**\n${content}` : '',
35
+ ].filter(Boolean).join('\n');
36
+ }).join('\n\n---\n\n');
37
+ return {
38
+ content: [{ type: 'text', text: formatted }],
39
+ };
40
+ }
41
+ catch (error) {
42
+ const message = error instanceof Error ? error.message : String(error);
43
+ return {
44
+ content: [{ type: 'text', text: `Memory search error: ${message}` }],
45
+ isError: true,
46
+ };
47
+ }
48
+ });
49
+ // memory_save - Save a memory entry
50
+ server.tool('memory_save', 'Save a piece of knowledge to Code Buddy\'s persistent memory for future reference.', {
51
+ key: z.string().describe('A short key/name for the memory entry'),
52
+ value: z.string().describe('The content to remember'),
53
+ category: z.enum(['project', 'preferences', 'decisions', 'patterns', 'context', 'custom']).optional()
54
+ .describe('Memory category (default: context)'),
55
+ scope: z.enum(['project', 'user']).optional()
56
+ .describe('Memory scope: project-specific or user-global (default: project)'),
57
+ }, async (args) => {
58
+ try {
59
+ const { getMemoryManager } = await import('../memory/persistent-memory.js');
60
+ const manager = getMemoryManager();
61
+ await manager.initialize();
62
+ await manager.remember(args.key, args.value, {
63
+ category: args.category,
64
+ scope: args.scope,
65
+ });
66
+ return {
67
+ content: [{ type: 'text', text: `Memory saved: "${args.key}" (${args.scope || 'project'} / ${args.category || 'context'})` }],
68
+ };
69
+ }
70
+ catch (error) {
71
+ const message = error instanceof Error ? error.message : String(error);
72
+ return {
73
+ content: [{ type: 'text', text: `Memory save error: ${message}` }],
74
+ isError: true,
75
+ };
76
+ }
77
+ });
78
+ }
79
+ //# sourceMappingURL=mcp-memory-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-memory-tools.js","sourceRoot":"","sources":["../../src/mcp/mcp-memory-tools.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAiB;IACnD,yCAAyC;IACzC,MAAM,CAAC,IAAI,CACT,eAAe,EACf,4FAA4F,EAC5F;QACE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4CAA4C,CAAC;QACxE,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,wCAAwC,CAAC;KACtF,EACD,KAAK,EAAE,IAAI,EAAE,EAAE;QACb,IAAI,CAAC;YACH,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,MAAM,CAAC,qCAAqC,CAAC,CAAC;YAClF,MAAM,OAAO,GAAG,MAAM,iBAAiB,CAAC,IAAI,CAAC,KAAK,EAAE;gBAClD,UAAU,EAAE,IAAI,CAAC,WAAW,IAAI,CAAC;aAClC,CAAC,CAAC;YAEH,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACzB,OAAO;oBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,6BAA6B,EAAE,CAAC;iBAC1E,CAAC;YACJ,CAAC;YAED,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,E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C"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * MCP Prompts - Workflow templates for common development tasks
3
+ *
4
+ * Prompts:
5
+ * - code_review: Review code changes
6
+ * - explain_code: Explain file/function
7
+ * - generate_tests: Generate tests
8
+ * - refactor: Refactor with strategy
9
+ * - fix_bugs: Find and fix bugs
10
+ */
11
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
12
+ /**
13
+ * Register workflow prompt templates with the MCP server.
14
+ */
15
+ export declare function registerPrompts(server: McpServer): void;
@@ -0,0 +1,170 @@
1
+ /**
2
+ * MCP Prompts - Workflow templates for common development tasks
3
+ *
4
+ * Prompts:
5
+ * - code_review: Review code changes
6
+ * - explain_code: Explain file/function
7
+ * - generate_tests: Generate tests
8
+ * - refactor: Refactor with strategy
9
+ * - fix_bugs: Find and fix bugs
10
+ */
11
+ import { z } from 'zod';
12
+ /**
13
+ * Register workflow prompt templates with the MCP server.
14
+ */
15
+ export function registerPrompts(server) {
16
+ // code_review - Review code changes
17
+ server.prompt('code_review', 'Review code changes for bugs, security issues, and best practices', {
18
+ path: z.string().optional().describe('File or directory path to review (defaults to staged changes)'),
19
+ }, (args) => {
20
+ const target = args.path
21
+ ? `the file at \`${args.path}\``
22
+ : 'the current staged git changes (run `git diff --staged`)';
23
+ return {
24
+ messages: [{
25
+ role: 'user',
26
+ content: {
27
+ type: 'text',
28
+ text: [
29
+ `Please review ${target}. Focus on:`,
30
+ '',
31
+ '1. **Bugs & Logic Errors** - Incorrect behavior, edge cases, off-by-one errors',
32
+ '2. **Security Issues** - Injection vulnerabilities, secrets exposure, unsafe operations',
33
+ '3. **Performance** - Unnecessary computations, memory leaks, N+1 queries',
34
+ '4. **Code Quality** - Readability, naming, DRY violations, missing error handling',
35
+ '5. **TypeScript** - Type safety, proper use of generics, avoiding `any`',
36
+ '',
37
+ 'For each issue found, provide:',
38
+ '- File and line number',
39
+ '- Severity (critical/warning/suggestion)',
40
+ '- Description of the issue',
41
+ '- Suggested fix with code snippet',
42
+ ].join('\n'),
43
+ },
44
+ }],
45
+ };
46
+ });
47
+ // explain_code - Explain file/function
48
+ server.prompt('explain_code', 'Explain how a file or function works in detail', {
49
+ path: z.string().describe('Path to the file to explain'),
50
+ function_name: z.string().optional().describe('Specific function to explain (explains whole file if omitted)'),
51
+ }, (args) => {
52
+ const target = args.function_name
53
+ ? `the function \`${args.function_name}\` in \`${args.path}\``
54
+ : `the file \`${args.path}\``;
55
+ return {
56
+ messages: [{
57
+ role: 'user',
58
+ content: {
59
+ type: 'text',
60
+ text: [
61
+ `Please explain ${target}. Include:`,
62
+ '',
63
+ '1. **Purpose** - What it does and why it exists',
64
+ '2. **How It Works** - Step-by-step walkthrough of the logic',
65
+ '3. **Dependencies** - What it imports/uses and why',
66
+ '4. **Data Flow** - Input → processing → output',
67
+ '5. **Key Patterns** - Design patterns, idioms, or conventions used',
68
+ '6. **Edge Cases** - Important boundary conditions handled',
69
+ '',
70
+ 'Use code snippets from the file to illustrate key points.',
71
+ ].join('\n'),
72
+ },
73
+ }],
74
+ };
75
+ });
76
+ // generate_tests - Generate tests
77
+ server.prompt('generate_tests', 'Generate comprehensive tests for a file or module', {
78
+ path: z.string().describe('Path to the file to generate tests for'),
79
+ framework: z.string().optional().describe('Test framework to use (default: jest)'),
80
+ }, (args) => {
81
+ const framework = args.framework || 'jest';
82
+ return {
83
+ messages: [{
84
+ role: 'user',
85
+ content: {
86
+ type: 'text',
87
+ text: [
88
+ `Generate comprehensive tests for \`${args.path}\` using ${framework}. Include:`,
89
+ '',
90
+ '1. **Unit tests** for each exported function/method',
91
+ '2. **Happy path** tests with typical inputs',
92
+ '3. **Error cases** - invalid inputs, edge cases, boundary conditions',
93
+ '4. **Mock setup** for external dependencies (API calls, file system, etc.)',
94
+ '5. **Integration tests** if the module interacts with other components',
95
+ '',
96
+ 'Follow these conventions:',
97
+ '- Use descriptive test names: `it(\'should return error when file not found\')`',
98
+ '- Group related tests with `describe` blocks',
99
+ '- Use `beforeEach`/`afterEach` for setup/cleanup',
100
+ `- Place the test file in the \`tests/\` directory`,
101
+ '- Match the existing test patterns in the project',
102
+ ].join('\n'),
103
+ },
104
+ }],
105
+ };
106
+ });
107
+ // refactor - Refactor with strategy
108
+ server.prompt('refactor', 'Refactor code using a specific strategy', {
109
+ path: z.string().describe('Path to the file to refactor'),
110
+ strategy: z.string().describe('Refactoring strategy (e.g., extract-function, simplify, split-module, dry, rename)'),
111
+ }, (args) => {
112
+ return {
113
+ messages: [{
114
+ role: 'user',
115
+ content: {
116
+ type: 'text',
117
+ text: [
118
+ `Refactor \`${args.path}\` using the **${args.strategy}** strategy.`,
119
+ '',
120
+ 'Guidelines:',
121
+ '1. **Read the file first** to understand current structure',
122
+ '2. **Explain what you plan to change** and why before making edits',
123
+ '3. **Preserve behavior** - refactoring should not change functionality',
124
+ '4. **Keep changes minimal** - only refactor what the strategy calls for',
125
+ '5. **Update imports** if moving or renaming things',
126
+ '6. **Run existing tests** after refactoring to verify nothing broke',
127
+ '',
128
+ 'Common strategies:',
129
+ '- `extract-function`: Pull complex logic into named functions',
130
+ '- `simplify`: Reduce complexity, flatten nesting, simplify conditionals',
131
+ '- `split-module`: Break large file into focused modules',
132
+ '- `dry`: Eliminate duplication',
133
+ '- `rename`: Improve naming for clarity',
134
+ ].join('\n'),
135
+ },
136
+ }],
137
+ };
138
+ });
139
+ // fix_bugs - Find and fix bugs
140
+ server.prompt('fix_bugs', 'Find and fix bugs in a file', {
141
+ path: z.string().describe('Path to the file to fix'),
142
+ description: z.string().optional().describe('Description of the bug or symptoms'),
143
+ }, (args) => {
144
+ const bugDesc = args.description
145
+ ? `\n\n**Reported issue:** ${args.description}`
146
+ : '';
147
+ return {
148
+ messages: [{
149
+ role: 'user',
150
+ content: {
151
+ type: 'text',
152
+ text: [
153
+ `Find and fix bugs in \`${args.path}\`.${bugDesc}`,
154
+ '',
155
+ 'Steps:',
156
+ '1. **Read the file** and understand its purpose',
157
+ '2. **Identify bugs** - logic errors, type issues, edge cases, race conditions',
158
+ '3. **For each bug found:**',
159
+ ' - Explain what\'s wrong and how it manifests',
160
+ ' - Show the fix with a code edit',
161
+ ' - Explain why the fix works',
162
+ '4. **Run tests** to verify the fixes',
163
+ '5. **Check for related issues** that might have the same root cause',
164
+ ].join('\n'),
165
+ },
166
+ }],
167
+ };
168
+ });
169
+ }
170
+ //# sourceMappingURL=mcp-prompts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-prompts.js","sourceRoot":"","sources":["../../src/mcp/mcp-prompts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,MAAiB;IAC/C,oCAAoC;IACpC,MAAM,CAAC,MAAM,CACX,aAAa,EACb,mEAAmE,EACnE;QACE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,+DAA+D,CAAC;KACtG,EACD,CAAC,IAAI,EAAE,EAAE;QACP,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI;YACtB,CAAC,CAAC,iBAAiB,IAAI,CAAC,IAAI,IAAI;YAChC,CAAC,CAAC,0DAA0D,CAAC;QAE/D,OAAO;YACL,QAAQ,EAAE,CAAC;oBACT,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE;wBACP,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE;4BACJ,iBAAiB,MAAM,aAAa;4BACpC,EAAE;4BACF,gFAAgF;4BAChF,yFAAyF;4BACzF,0EAA0E;4BAC1E,mFAAmF;4BACnF,yEAAyE;4BACzE,EAAE;4BACF,gCAAgC;4BAChC,wBAAwB;4BACxB,0CAA0C;4BAC1C,4BAA4B;4BAC5B,mCAAmC;yBACpC,CAAC,IAAI,CAAC,IAAI,CAAC;qBACb;iBACF,CAAC;SACH,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,uCAAuC;IACvC,MAAM,CA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,CAAC,QAAQ,CAAC,yBAAyB,CAAC;QACpD,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,oCAAoC,CAAC;KAClF,EACD,CAAC,IAAI,EAAE,EAAE;QACP,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW;YAC9B,CAAC,CAAC,2BAA2B,IAAI,CAAC,WAAW,EAAE;YAC/C,CAAC,CAAC,EAAE,CAAC;QAEP,OAAO;YACL,QAAQ,EAAE,CAAC;oBACT,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE;wBACP,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE;4BACJ,0BAA0B,IAAI,CAAC,IAAI,MAAM,OAAO,EAAE;4BAClD,EAAE;4BACF,QAAQ;4BACR,iDAAiD;4BACjD,+EAA+E;4BAC/E,4BAA4B;4BAC5B,iDAAiD;4BACjD,oCAAoC;4BACpC,gCAAgC;4BAChC,sCAAsC;4BACtC,qEAAqE;yBACtE,CAAC,IAAI,CAAC,IAAI,CAAC;qBACb;iBACF,CAAC;SACH,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * MCP Resources - Read-only project context exposed via URI scheme
3
+ *
4
+ * Resources (codebuddy:// URI scheme):
5
+ * - codebuddy://project/context - Project context files + git status
6
+ * - codebuddy://project/instructions - CODEBUDDY.md / CLAUDE.md custom instructions
7
+ * - codebuddy://sessions/latest - Latest session data as JSON
8
+ * - codebuddy://memory/all - All stored memories formatted as markdown
9
+ */
10
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
11
+ /**
12
+ * Register read-only resources with the MCP server.
13
+ */
14
+ export declare function registerResources(server: McpServer): void;
@@ -0,0 +1,183 @@
1
+ /**
2
+ * MCP Resources - Read-only project context exposed via URI scheme
3
+ *
4
+ * Resources (codebuddy:// URI scheme):
5
+ * - codebuddy://project/context - Project context files + git status
6
+ * - codebuddy://project/instructions - CODEBUDDY.md / CLAUDE.md custom instructions
7
+ * - codebuddy://sessions/latest - Latest session data as JSON
8
+ * - codebuddy://memory/all - All stored memories formatted as markdown
9
+ */
10
+ /**
11
+ * Register read-only resources with the MCP server.
12
+ */
13
+ export function registerResources(server) {
14
+ // codebuddy://project/context
15
+ server.resource('project_context', 'codebuddy://project/context', {
16
+ description: 'Project context files (CODEBUDDY.md, .codebuddy/config, etc.) and git status',
17
+ mimeType: 'text/markdown',
18
+ }, async () => {
19
+ try {
20
+ const { loadContext, formatContextForPrompt } = await import('../context/context-files.js');
21
+ const context = await loadContext(process.cwd());
22
+ let text = formatContextForPrompt(context);
23
+ // Append git status
24
+ try {
25
+ const { execSync } = await import('child_process');
26
+ const gitStatus = execSync('git status --short 2>/dev/null', { encoding: 'utf-8', timeout: 5000 });
27
+ if (gitStatus.trim()) {
28
+ text += `\n\n## Git Status\n\`\`\`\n${gitStatus.trim()}\n\`\`\``;
29
+ }
30
+ }
31
+ catch {
32
+ // Not a git repo or git not available
33
+ }
34
+ return {
35
+ contents: [{
36
+ uri: 'codebuddy://project/context',
37
+ mimeType: 'text/markdown',
38
+ text,
39
+ }],
40
+ };
41
+ }
42
+ catch (error) {
43
+ const message = error instanceof Error ? error.message : String(error);
44
+ return {
45
+ contents: [{
46
+ uri: 'codebuddy://project/context',
47
+ mimeType: 'text/plain',
48
+ text: `Error loading project context: ${message}`,
49
+ }],
50
+ };
51
+ }
52
+ });
53
+ // codebuddy://project/instructions
54
+ server.resource('project_instructions', 'codebuddy://project/instructions', {
55
+ description: 'Custom project instructions from CODEBUDDY.md, CLAUDE.md, or .codebuddy/instructions',
56
+ mimeType: 'text/markdown',
57
+ }, async () => {
58
+ try {
59
+ const fs = await import('fs');
60
+ const path = await import('path');
61
+ const cwd = process.cwd();
62
+ const instructionFiles = [
63
+ 'CODEBUDDY.md',
64
+ 'CLAUDE.md',
65
+ '.codebuddy/instructions.md',
66
+ '.github/copilot-instructions.md',
67
+ ];
68
+ const parts = [];
69
+ for (const file of instructionFiles) {
70
+ const fullPath = path.join(cwd, file);
71
+ try {
72
+ const content = fs.readFileSync(fullPath, 'utf-8');
73
+ parts.push(`## ${file}\n\n${content}`);
74
+ }
75
+ catch {
76
+ // File doesn't exist, skip
77
+ }
78
+ }
79
+ const text = parts.length > 0
80
+ ? parts.join('\n\n---\n\n')
81
+ : 'No custom instruction files found in this project.';
82
+ return {
83
+ contents: [{
84
+ uri: 'codebuddy://project/instructions',
85
+ mimeType: 'text/markdown',
86
+ text,
87
+ }],
88
+ };
89
+ }
90
+ catch (error) {
91
+ const message = error instanceof Error ? error.message : String(error);
92
+ return {
93
+ contents: [{
94
+ uri: 'codebuddy://project/instructions',
95
+ mimeType: 'text/plain',
96
+ text: `Error loading instructions: ${message}`,
97
+ }],
98
+ };
99
+ }
100
+ });
101
+ // codebuddy://sessions/latest
102
+ server.resource('sessions_latest', 'codebuddy://sessions/latest', {
103
+ description: 'Latest Code Buddy session data including messages and metadata',
104
+ mimeType: 'application/json',
105
+ }, async () => {
106
+ try {
107
+ const { getSessionStore } = await import('../persistence/session-store.js');
108
+ const store = getSessionStore();
109
+ const sessions = await store.getRecentSessions(1);
110
+ if (sessions.length === 0) {
111
+ return {
112
+ contents: [{
113
+ uri: 'codebuddy://sessions/latest',
114
+ mimeType: 'application/json',
115
+ text: JSON.stringify({ message: 'No sessions found' }),
116
+ }],
117
+ };
118
+ }
119
+ const session = sessions[0];
120
+ const data = {
121
+ id: session.id,
122
+ name: session.name,
123
+ model: session.model,
124
+ workingDirectory: session.workingDirectory,
125
+ messageCount: session.messages?.length ?? 0,
126
+ createdAt: session.createdAt,
127
+ lastAccessedAt: session.lastAccessedAt,
128
+ recentMessages: (session.messages || []).slice(-10).map(m => ({
129
+ type: m.type,
130
+ content: m.content.length > 500 ? m.content.slice(0, 500) + '...' : m.content,
131
+ timestamp: m.timestamp,
132
+ })),
133
+ };
134
+ return {
135
+ contents: [{
136
+ uri: 'codebuddy://sessions/latest',
137
+ mimeType: 'application/json',
138
+ text: JSON.stringify(data, null, 2),
139
+ }],
140
+ };
141
+ }
142
+ catch (error) {
143
+ const message = error instanceof Error ? error.message : String(error);
144
+ return {
145
+ contents: [{
146
+ uri: 'codebuddy://sessions/latest',
147
+ mimeType: 'application/json',
148
+ text: JSON.stringify({ error: message }),
149
+ }],
150
+ };
151
+ }
152
+ });
153
+ // codebuddy://memory/all
154
+ server.resource('memory_all', 'codebuddy://memory/all', {
155
+ description: 'All stored Code Buddy memories formatted as markdown',
156
+ mimeType: 'text/markdown',
157
+ }, async () => {
158
+ try {
159
+ const { getMemoryManager } = await import('../memory/persistent-memory.js');
160
+ const manager = getMemoryManager();
161
+ await manager.initialize();
162
+ const text = manager.formatMemories() || 'No memories stored.';
163
+ return {
164
+ contents: [{
165
+ uri: 'codebuddy://memory/all',
166
+ mimeType: 'text/markdown',
167
+ text,
168
+ }],
169
+ };
170
+ }
171
+ catch (error) {
172
+ const message = error instanceof Error ? error.message : String(error);
173
+ return {
174
+ contents: [{
175
+ uri: 'codebuddy://memory/all',
176
+ mimeType: 'text/plain',
177
+ text: `Error loading memories: ${message}`,
178
+ }],
179
+ };
180
+ }
181
+ });
182
+ }
183
+ //# sourceMappingURL=mcp-resources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-resources.js","sourceRoot":"","sources":["../../src/mcp/mcp-resources.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAiB;IACjD,8BAA8B;IAC9B,MAAM,CAAC,QAAQ,CACb,iBAAiB,EACjB,6BAA6B,EAC7B;QACE,WAAW,EAAE,8EAA8E;QAC3F,QAAQ,EAAE,eAAe;KAC1B,EACD,KAAK,IAAI,EAAE;QACT,IAAI,CAAC;YACH,MAAM,EAAE,WAAW,EAAE,sBAAsB,EAAE,GAAG,MAAM,MAAM,CAAC,6BAA6B,CAAC,CAAC;YAC5F,MAAM,OAAO,GAAG,MAAM,WAA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