@agentbrain/mcp-server 1.4.37 → 1.4.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tools/save-context.d.ts +1 -0
- package/dist/tools/save-context.d.ts.map +1 -1
- package/dist/tools/save-context.js +159 -15
- package/dist/tools/save-context.js.map +1 -1
- package/dist/tools/setup-repo.d.ts +1 -0
- package/dist/tools/setup-repo.d.ts.map +1 -1
- package/dist/tools/setup-repo.js +19 -3
- package/dist/tools/setup-repo.js.map +1 -1
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@ export interface SaveContextInput {
|
|
|
7
7
|
export interface SaveContextOutput {
|
|
8
8
|
success: boolean;
|
|
9
9
|
files_written: string[];
|
|
10
|
+
agent_detected: 'cursor' | 'windsurf' | 'claude' | 'unknown';
|
|
10
11
|
message: string;
|
|
11
12
|
}
|
|
12
13
|
export declare function saveContext(input: SaveContextInput): Promise<SaveContextOutput>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save-context.d.ts","sourceRoot":"","sources":["../../src/tools/save-context.ts"],"names":[],"mappings":"AAkBA,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,cAAc,EAAE,MAAM,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAA;IAChB,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB,OAAO,EAAE,MAAM,CAAA;CAChB;
|
|
1
|
+
{"version":3,"file":"save-context.d.ts","sourceRoot":"","sources":["../../src/tools/save-context.ts"],"names":[],"mappings":"AAkBA,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,cAAc,EAAE,MAAM,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAA;IAChB,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB,cAAc,EAAE,QAAQ,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAA;IAC5D,OAAO,EAAE,MAAM,CAAA;CAChB;AAgGD,wBAAsB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CA4HrF;AAED,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;CA0B7B,CAAA"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// MCP tool: save_context - save agent-generated context to disk
|
|
2
|
-
import { writeFile, mkdir } from 'node:fs/promises';
|
|
2
|
+
import { writeFile, mkdir, readFile } from 'node:fs/promises';
|
|
3
3
|
import { existsSync } from 'node:fs';
|
|
4
4
|
import { join, resolve } from 'node:path';
|
|
5
5
|
import { homedir } from 'node:os';
|
|
6
|
-
import { getGitHash,
|
|
6
|
+
import { getGitHash, ensureGitignore } from '@agentbrain/core';
|
|
7
7
|
/**
|
|
8
8
|
* Expand path: handles ~, relative paths, etc.
|
|
9
9
|
*/
|
|
@@ -13,25 +13,109 @@ function expandPath(path) {
|
|
|
13
13
|
}
|
|
14
14
|
return resolve(path);
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Detect agent type from filesystem
|
|
18
|
+
*/
|
|
19
|
+
function detectAgentType(repoPath) {
|
|
20
|
+
if (existsSync(join(repoPath, '.cursor'))) {
|
|
21
|
+
return 'cursor';
|
|
22
|
+
}
|
|
23
|
+
if (existsSync(join(repoPath, '.windsurf'))) {
|
|
24
|
+
return 'windsurf';
|
|
25
|
+
}
|
|
26
|
+
if (existsSync(join(repoPath, 'CLAUDE.md'))) {
|
|
27
|
+
return 'claude';
|
|
28
|
+
}
|
|
29
|
+
return 'unknown';
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get agent file content
|
|
33
|
+
*/
|
|
34
|
+
function getAgentFileContent(isModernFormat) {
|
|
35
|
+
const baseContent = `## AgentBrain Context
|
|
36
|
+
@.agentbrain/context.md
|
|
37
|
+
@.agentbrain/patterns.md
|
|
38
|
+
@.agentbrain/dependency-map.md
|
|
39
|
+
|
|
40
|
+
## Workflow
|
|
41
|
+
- Always read context at session start via load_context()
|
|
42
|
+
- Before any task: load_spec() or agentbrain spec "task"
|
|
43
|
+
- After commits: context auto-updates via git hook
|
|
44
|
+
- If stuck in a loop: detect_doom_loop() or agentbrain doom
|
|
45
|
+
- End of session: save_handoff() or agentbrain handoff
|
|
46
|
+
- If context feels stale: agentbrain init
|
|
47
|
+
|
|
48
|
+
## MCP Tools
|
|
49
|
+
- load_context() — full codebase context
|
|
50
|
+
- load_spec() — spec for current task
|
|
51
|
+
- detect_doom_loop() — check for stuck patterns
|
|
52
|
+
- save_handoff() — end of session handoff
|
|
53
|
+
- setup_repo() — first time MCP setup
|
|
54
|
+
- save_context() — save agent-generated context`;
|
|
55
|
+
if (isModernFormat) {
|
|
56
|
+
return `---
|
|
57
|
+
description: AgentBrain codebase context and workflow
|
|
58
|
+
alwaysApply: true
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
${baseContent}`;
|
|
62
|
+
}
|
|
63
|
+
return baseContent;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Check if agent file already contains AgentBrain section
|
|
67
|
+
*/
|
|
68
|
+
async function hasAgentBrainSection(filePath) {
|
|
69
|
+
if (!existsSync(filePath)) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
const content = await readFile(filePath, 'utf-8');
|
|
73
|
+
return content.includes('── AgentBrain ──');
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Update or append AgentBrain section to agent file
|
|
77
|
+
*/
|
|
78
|
+
async function updateOrAppendAgentSection(filePath, content) {
|
|
79
|
+
const marker = '# ── AgentBrain ──────────────────────────────';
|
|
80
|
+
const endMarker = '# ── End AgentBrain ──────────────────────────';
|
|
81
|
+
let existingContent = '';
|
|
82
|
+
if (existsSync(filePath)) {
|
|
83
|
+
existingContent = await readFile(filePath, 'utf-8');
|
|
84
|
+
}
|
|
85
|
+
// Check if AgentBrain section already exists
|
|
86
|
+
if (existingContent.includes(marker)) {
|
|
87
|
+
// Replace existing section
|
|
88
|
+
const beforeMarker = existingContent.substring(0, existingContent.indexOf(marker));
|
|
89
|
+
const afterMarker = existingContent.substring(existingContent.indexOf(endMarker) + endMarker.length);
|
|
90
|
+
const newContent = `${beforeMarker}${marker}\n${content}\n${endMarker}${afterMarker}`;
|
|
91
|
+
await writeFile(filePath, newContent, 'utf-8');
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
// Append new section
|
|
95
|
+
const agentBrainSection = `\n${marker}\n${content}\n${endMarker}\n`;
|
|
96
|
+
await writeFile(filePath, existingContent + agentBrainSection, 'utf-8');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
16
99
|
export async function saveContext(input) {
|
|
17
100
|
const { repo_path, context, dependency_map, patterns } = input;
|
|
18
101
|
// Expand path to handle ~, relative paths, etc.
|
|
19
102
|
const expandedPath = expandPath(repo_path);
|
|
20
103
|
const contextDir = join(expandedPath, '.agentbrain');
|
|
21
|
-
|
|
104
|
+
const filesWritten = [];
|
|
105
|
+
// Step 1: Create .agentbrain directory if it doesn't exist
|
|
22
106
|
if (!existsSync(contextDir)) {
|
|
23
107
|
await mkdir(contextDir, { recursive: true });
|
|
24
108
|
}
|
|
25
|
-
// Write the three context files
|
|
109
|
+
// Step 2: Write the three context files
|
|
26
110
|
const contextPath = join(contextDir, 'context.md');
|
|
27
111
|
const depMapPath = join(contextDir, 'dependency-map.md');
|
|
28
112
|
const patternsPath = join(contextDir, 'patterns.md');
|
|
29
113
|
await writeFile(contextPath, context, 'utf-8');
|
|
30
114
|
await writeFile(depMapPath, dependency_map, 'utf-8');
|
|
31
115
|
await writeFile(patternsPath, patterns, 'utf-8');
|
|
32
|
-
|
|
116
|
+
filesWritten.push('.agentbrain/context.md', '.agentbrain/dependency-map.md', '.agentbrain/patterns.md');
|
|
117
|
+
// Step 3: Get current git hash and write cache.json
|
|
33
118
|
const gitHash = await getGitHash(expandedPath);
|
|
34
|
-
// Create basic cache.json with git hash
|
|
35
119
|
const cachePath = join(contextDir, 'cache.json');
|
|
36
120
|
const cache = {
|
|
37
121
|
gitHash,
|
|
@@ -55,17 +139,77 @@ export async function saveContext(input) {
|
|
|
55
139
|
savedAt: new Date().toISOString(),
|
|
56
140
|
};
|
|
57
141
|
await writeFile(cachePath, JSON.stringify(cache, null, 2), 'utf-8');
|
|
58
|
-
|
|
59
|
-
|
|
142
|
+
filesWritten.push('.agentbrain/cache.json');
|
|
143
|
+
// Step 4: Update .gitignore
|
|
144
|
+
await ensureGitignore(expandedPath);
|
|
145
|
+
// Step 5 & 6: Create agent files based on directory detection
|
|
146
|
+
const modernContent = getAgentFileContent(true);
|
|
147
|
+
const legacyContent = getAgentFileContent(false);
|
|
148
|
+
let message = '';
|
|
149
|
+
// CURSOR: Check if .cursor/ directory exists
|
|
150
|
+
const cursorDirExists = existsSync(join(expandedPath, '.cursor'));
|
|
151
|
+
if (cursorDirExists) {
|
|
152
|
+
// Modern Cursor: ONLY create .cursor/rules/agentbrain.mdc
|
|
153
|
+
const modernPath = join(expandedPath, '.cursor', 'rules', 'agentbrain.mdc');
|
|
154
|
+
const modernDir = join(expandedPath, '.cursor', 'rules');
|
|
155
|
+
if (!existsSync(modernDir)) {
|
|
156
|
+
await mkdir(modernDir, { recursive: true });
|
|
157
|
+
}
|
|
158
|
+
await updateOrAppendAgentSection(modernPath, modernContent);
|
|
159
|
+
filesWritten.push('.cursor/rules/agentbrain.mdc');
|
|
160
|
+
message = 'Detected Cursor (.cursor/ directory found). Created/updated .cursor/rules/agentbrain.mdc';
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
// Legacy Cursor: ONLY create .cursorrules
|
|
164
|
+
const legacyPath = join(expandedPath, '.cursorrules');
|
|
165
|
+
await updateOrAppendAgentSection(legacyPath, legacyContent);
|
|
166
|
+
filesWritten.push('.cursorrules');
|
|
167
|
+
message = 'Created/updated .cursorrules';
|
|
168
|
+
}
|
|
169
|
+
// WINDSURF: Check if .windsurf/ directory exists
|
|
170
|
+
const windsurfDirExists = existsSync(join(expandedPath, '.windsurf'));
|
|
171
|
+
if (windsurfDirExists) {
|
|
172
|
+
// Modern Windsurf: ONLY create .windsurf/rules/agentbrain.md
|
|
173
|
+
const modernPath = join(expandedPath, '.windsurf', 'rules', 'agentbrain.md');
|
|
174
|
+
const modernDir = join(expandedPath, '.windsurf', 'rules');
|
|
175
|
+
if (!existsSync(modernDir)) {
|
|
176
|
+
await mkdir(modernDir, { recursive: true });
|
|
177
|
+
}
|
|
178
|
+
await updateOrAppendAgentSection(modernPath, legacyContent); // Windsurf uses plain markdown
|
|
179
|
+
filesWritten.push('.windsurf/rules/agentbrain.md');
|
|
180
|
+
if (message)
|
|
181
|
+
message += '; ';
|
|
182
|
+
message += 'Detected Windsurf (.windsurf/ directory found). Created/updated .windsurf/rules/agentbrain.md';
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
// Legacy Windsurf: ONLY create .windsurfrules
|
|
186
|
+
const legacyPath = join(expandedPath, '.windsurfrules');
|
|
187
|
+
await updateOrAppendAgentSection(legacyPath, legacyContent);
|
|
188
|
+
filesWritten.push('.windsurfrules');
|
|
189
|
+
if (message)
|
|
190
|
+
message += '; ';
|
|
191
|
+
message += 'Created/updated .windsurfrules';
|
|
192
|
+
}
|
|
193
|
+
// CLAUDE: Always create/update CLAUDE.md
|
|
194
|
+
const claudePath = join(expandedPath, 'CLAUDE.md');
|
|
195
|
+
await updateOrAppendAgentSection(claudePath, legacyContent);
|
|
196
|
+
filesWritten.push('CLAUDE.md');
|
|
197
|
+
if (message)
|
|
198
|
+
message += '; ';
|
|
199
|
+
message += 'Created/updated CLAUDE.md';
|
|
200
|
+
// Determine agent type for response
|
|
201
|
+
let detectedAgent = 'unknown';
|
|
202
|
+
if (cursorDirExists)
|
|
203
|
+
detectedAgent = 'cursor';
|
|
204
|
+
else if (windsurfDirExists)
|
|
205
|
+
detectedAgent = 'windsurf';
|
|
206
|
+
else if (existsSync(join(expandedPath, 'CLAUDE.md')))
|
|
207
|
+
detectedAgent = 'claude';
|
|
60
208
|
return {
|
|
61
209
|
success: true,
|
|
62
|
-
files_written:
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
'.agentbrain/patterns.md',
|
|
66
|
-
'.agentbrain/cache.json',
|
|
67
|
-
],
|
|
68
|
-
message: 'Context saved successfully. load_context will now work without an API key.',
|
|
210
|
+
files_written: filesWritten,
|
|
211
|
+
agent_detected: detectedAgent,
|
|
212
|
+
message: `Context saved successfully. ${message}`,
|
|
69
213
|
};
|
|
70
214
|
}
|
|
71
215
|
export const saveContextSchema = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save-context.js","sourceRoot":"","sources":["../../src/tools/save-context.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"save-context.js","sourceRoot":"","sources":["../../src/tools/save-context.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAE9D;;GAEG;AACH,SAAS,UAAU,CAAC,IAAY;IAC9B,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,GAAG,E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AAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,KAAK,CAAC;QACf,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;KAChB,CAAC,CAAA;IACF,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,wBAAsB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,
|
|
1
|
+
{"version":3,"file":"setup-repo.d.ts","sourceRoot":"","sources":["../../src/tools/setup-repo.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,KAAK,CAAC;QACf,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;KAChB,CAAC,CAAA;IACF,cAAc,EAAE,OAAO,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,wBAAsB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAoE/E;AAED,eAAO,MAAM,eAAe;;;;;;;;;;;;;CAc3B,CAAA"}
|
package/dist/tools/setup-repo.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// MCP tool: setup_repo - scan repo and return data for agent to generate context
|
|
2
|
-
import { scanRepository, readFileContent } from '@agentbrain/core';
|
|
2
|
+
import { scanRepository, readFileContent, installPostCommitHook, isGitRepository } from '@agentbrain/core';
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
5
|
/**
|
|
@@ -32,7 +32,22 @@ export async function setupRepo(input) {
|
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
//
|
|
35
|
+
// Install git hook if in a git repository
|
|
36
|
+
let hookInstalled = false;
|
|
37
|
+
if (isGitRepository(expandedPath)) {
|
|
38
|
+
try {
|
|
39
|
+
await installPostCommitHook(expandedPath);
|
|
40
|
+
hookInstalled = true;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// Hook installation failed silently — not critical
|
|
44
|
+
hookInstalled = false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Instructions for the agent - vary based on hook installation
|
|
48
|
+
const hookNote = hookInstalled
|
|
49
|
+
? '\n\nGit hook installed. Context will auto-refresh after every commit — no manual updates needed.'
|
|
50
|
+
: '\n\nGit hook could not be installed. You can manually refresh context by calling setup_repo() again.';
|
|
36
51
|
const instructions = `Based on the file tree and key files above, generate:
|
|
37
52
|
|
|
38
53
|
1. context.md — Architecture overview, key modules, entry points, what the codebase does, tech stack
|
|
@@ -48,11 +63,12 @@ Guidelines:
|
|
|
48
63
|
- Focus on what's unique to this codebase
|
|
49
64
|
- Include specific file paths and module names
|
|
50
65
|
- Identify the main entry points and core business logic
|
|
51
|
-
- Note any important patterns or conventions used consistently`;
|
|
66
|
+
- Note any important patterns or conventions used consistently${hookNote}`;
|
|
52
67
|
return {
|
|
53
68
|
repo_path: expandedPath,
|
|
54
69
|
file_tree: fileTree,
|
|
55
70
|
key_files: keyFiles,
|
|
71
|
+
hook_installed: hookInstalled,
|
|
56
72
|
instructions,
|
|
57
73
|
};
|
|
58
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-repo.js","sourceRoot":"","sources":["../../src/tools/setup-repo.ts"],"names":[],"mappings":"AAAA,iFAAiF;AAEjF,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"setup-repo.js","sourceRoot":"","sources":["../../src/tools/setup-repo.ts"],"names":[],"mappings":"AAAA,iFAAiF;AAEjF,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA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