@codepulse-oss/mcp 0.0.0-stage → 2.0.1
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/__tests__/phase5-mcp.test.d.ts +2 -0
- package/dist/__tests__/phase5-mcp.test.d.ts.map +1 -0
- package/dist/__tests__/phase5-mcp.test.js +192 -0
- package/dist/__tests__/phase5-mcp.test.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/installer.d.ts +47 -0
- package/dist/installer.d.ts.map +1 -0
- package/dist/installer.js +364 -0
- package/dist/installer.js.map +1 -0
- package/dist/queue.d.ts +54 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +331 -0
- package/dist/queue.js.map +1 -0
- package/dist/server.d.ts +21 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +285 -0
- package/dist/server.js.map +1 -0
- package/package.json +34 -4
- package/README.md +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phase5-mcp.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/phase5-mcp.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs/promises';
|
|
4
|
+
import http from 'node:http';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
8
|
+
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
9
|
+
import { CodePulseDatabase, runCommand } from '@codepulse-oss/core';
|
|
10
|
+
import { JobQueueManager, createCodePulseMcpServer, detectInstalledPlatforms, handleMcpHttpRequest, installAgentBridges, resolveMcpInvocation } from '../index.js';
|
|
11
|
+
test('MCP closed-loop workflow: start_scan -> wait_for_scan -> get_scan_result -> fix -> revalidate_findings -> PASS', async () => {
|
|
12
|
+
const tmpRepo = await fs.mkdtemp(path.join(os.tmpdir(), 'codepulse-mcp-e2e-'));
|
|
13
|
+
const db = new CodePulseDatabase(':memory:');
|
|
14
|
+
try {
|
|
15
|
+
await runCommand('git', ['init'], { cwd: tmpRepo });
|
|
16
|
+
await runCommand('git', ['config', 'user.email', 'test@codepulse.dev'], { cwd: tmpRepo });
|
|
17
|
+
await runCommand('git', ['config', 'user.name', 'CodePulse Test'], { cwd: tmpRepo });
|
|
18
|
+
await fs.mkdir(path.join(tmpRepo, 'src'), { recursive: true });
|
|
19
|
+
await fs.writeFile(path.join(tmpRepo, 'src', 'app.ts'), 'export const v = 1;\n', 'utf8');
|
|
20
|
+
await runCommand('git', ['add', '.'], { cwd: tmpRepo });
|
|
21
|
+
await runCommand('git', ['commit', '-m', 'init'], { cwd: tmpRepo });
|
|
22
|
+
// Agent writes vulnerable code locally
|
|
23
|
+
await fs.writeFile(path.join(tmpRepo, 'src', 'users.ts'), `export function findUser(db: any, id: string) {
|
|
24
|
+
return db.query(\`SELECT * FROM users WHERE id = \${id}\`);
|
|
25
|
+
}
|
|
26
|
+
`, 'utf8');
|
|
27
|
+
const queue = new JobQueueManager(db, 3);
|
|
28
|
+
const mcpServer = createCodePulseMcpServer({ db, queue, defaultRepoPath: tmpRepo });
|
|
29
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
30
|
+
await mcpServer.connect(serverTransport);
|
|
31
|
+
const client = new Client({ name: 'test-agent', version: '1.0.0' }, { capabilities: {} });
|
|
32
|
+
await client.connect(clientTransport);
|
|
33
|
+
const readToolText = (res) => res.content[0].text;
|
|
34
|
+
// 1. start_scan
|
|
35
|
+
const startRes = await client.callTool({
|
|
36
|
+
name: 'start_scan',
|
|
37
|
+
arguments: { target: 'local_uncommitted', mode: 'fast', repoPath: tmpRepo }
|
|
38
|
+
});
|
|
39
|
+
const startJson = JSON.parse(readToolText(startRes));
|
|
40
|
+
assert.ok(startJson.jobId);
|
|
41
|
+
// 2. wait_for_scan
|
|
42
|
+
const waitRes = await client.callTool({
|
|
43
|
+
name: 'wait_for_scan',
|
|
44
|
+
arguments: { jobId: startJson.jobId, timeoutMs: 30_000 }
|
|
45
|
+
});
|
|
46
|
+
const waitJson = JSON.parse(readToolText(waitRes));
|
|
47
|
+
assert.equal(waitJson.status, 'completed');
|
|
48
|
+
assert.equal(waitJson.merge_gate_passed, false);
|
|
49
|
+
// 3. get_scan_result
|
|
50
|
+
const resultRes = await client.callTool({
|
|
51
|
+
name: 'get_scan_result',
|
|
52
|
+
arguments: { jobId: startJson.jobId, onlyOpen: true }
|
|
53
|
+
});
|
|
54
|
+
const resultJson = JSON.parse(readToolText(resultRes));
|
|
55
|
+
assert.ok(resultJson.findings.some((f) => f.rule_id === 'CP-SQL-001'));
|
|
56
|
+
// 4. Agent fixes the SQL injection
|
|
57
|
+
await fs.writeFile(path.join(tmpRepo, 'src', 'users.ts'), `export function findUser(db: any, id: string) {
|
|
58
|
+
return db.query('SELECT * FROM users WHERE id = $1', [id]);
|
|
59
|
+
}
|
|
60
|
+
`, 'utf8');
|
|
61
|
+
// 5. revalidate_findings
|
|
62
|
+
const revalRes = await client.callTool({
|
|
63
|
+
name: 'revalidate_findings',
|
|
64
|
+
arguments: { target: 'local_uncommitted', repoPath: tmpRepo, baseScanId: startJson.jobId }
|
|
65
|
+
});
|
|
66
|
+
const revalJson = JSON.parse(readToolText(revalRes));
|
|
67
|
+
assert.ok(revalJson.verifiedFixedIds.length >= 1);
|
|
68
|
+
assert.equal(revalJson.output.merge_gate.passed, true);
|
|
69
|
+
await client.close();
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
db.close();
|
|
73
|
+
await fs.rm(tmpRepo, { recursive: true, force: true });
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
test('Universal Agent Bridge detects platforms and supports safe --dry-run installation', async () => {
|
|
77
|
+
const platforms = await detectInstalledPlatforms(process.cwd());
|
|
78
|
+
assert.ok(platforms.length >= 8);
|
|
79
|
+
assert.ok(platforms.some((p) => p.platform === 'antigravity'));
|
|
80
|
+
assert.ok(platforms.some((p) => p.platform === 'cursor'));
|
|
81
|
+
assert.ok(platforms.some((p) => p.platform === 'claude-code'));
|
|
82
|
+
const dry = await installAgentBridges({
|
|
83
|
+
platforms: ['cursor', 'antigravity'],
|
|
84
|
+
dryRun: true
|
|
85
|
+
});
|
|
86
|
+
assert.equal(dry.filter((r) => r.action === 'dry_run').length, 2);
|
|
87
|
+
// When codepulse is not on PATH, fallback resolves [process.execPath, <abs cli/dist/index.js>, "mcp", "--stdio"]
|
|
88
|
+
const fallback = await resolveMcpInvocation({ forceAbsoluteFallback: true });
|
|
89
|
+
assert.equal(fallback.command, process.execPath);
|
|
90
|
+
assert.equal(fallback.args[1], 'mcp');
|
|
91
|
+
assert.equal(fallback.args[2], '--stdio');
|
|
92
|
+
assert.ok(path.isAbsolute(fallback.args[0]));
|
|
93
|
+
});
|
|
94
|
+
test('Streamable HTTP /mcp handler serves MCP initialize and tools/list over HTTP POST', async () => {
|
|
95
|
+
const db = new CodePulseDatabase(':memory:');
|
|
96
|
+
const queue = new JobQueueManager(db, 2);
|
|
97
|
+
const srv = http.createServer(async (req, res) => {
|
|
98
|
+
const chunks = [];
|
|
99
|
+
for await (const c of req)
|
|
100
|
+
chunks.push(Buffer.from(c));
|
|
101
|
+
const parsed = chunks.length ? JSON.parse(Buffer.concat(chunks).toString('utf8')) : undefined;
|
|
102
|
+
await handleMcpHttpRequest({ db, queue }, req, res, parsed);
|
|
103
|
+
});
|
|
104
|
+
await new Promise((resolve) => srv.listen(0, '127.0.0.1', resolve));
|
|
105
|
+
const addr = srv.address();
|
|
106
|
+
const mcpUrl = `http://127.0.0.1:${addr.port}/mcp`;
|
|
107
|
+
try {
|
|
108
|
+
const initRes = await fetch(mcpUrl, {
|
|
109
|
+
method: 'POST',
|
|
110
|
+
headers: {
|
|
111
|
+
'content-type': 'application/json',
|
|
112
|
+
accept: 'application/json, text/event-stream'
|
|
113
|
+
},
|
|
114
|
+
body: JSON.stringify({
|
|
115
|
+
jsonrpc: '2.0',
|
|
116
|
+
id: 1,
|
|
117
|
+
method: 'initialize',
|
|
118
|
+
params: {
|
|
119
|
+
protocolVersion: '2025-03-26',
|
|
120
|
+
capabilities: {},
|
|
121
|
+
clientInfo: { name: 'http-test', version: '1.0.0' }
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
});
|
|
125
|
+
assert.equal(initRes.status, 200);
|
|
126
|
+
const initJson = (await initRes.json());
|
|
127
|
+
assert.equal(initJson.result?.serverInfo?.name, 'codepulse');
|
|
128
|
+
const toolsRes = await fetch(mcpUrl, {
|
|
129
|
+
method: 'POST',
|
|
130
|
+
headers: {
|
|
131
|
+
'content-type': 'application/json',
|
|
132
|
+
accept: 'application/json, text/event-stream'
|
|
133
|
+
},
|
|
134
|
+
body: JSON.stringify({
|
|
135
|
+
jsonrpc: '2.0',
|
|
136
|
+
id: 2,
|
|
137
|
+
method: 'tools/list',
|
|
138
|
+
params: {}
|
|
139
|
+
})
|
|
140
|
+
});
|
|
141
|
+
assert.equal(toolsRes.status, 200);
|
|
142
|
+
const toolsJson = (await toolsRes.json());
|
|
143
|
+
const names = (toolsJson.result?.tools ?? []).map((t) => t.name);
|
|
144
|
+
assert.ok(names.includes('start_scan'));
|
|
145
|
+
assert.ok(names.includes('get_blast_radius'));
|
|
146
|
+
assert.ok(names.includes('revalidate_findings'));
|
|
147
|
+
}
|
|
148
|
+
finally {
|
|
149
|
+
await new Promise((resolve) => srv.close(() => resolve()));
|
|
150
|
+
db.close();
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
test('JobQueueManager reconciles leftover zombie jobs on boot and deduplicates active scans', async () => {
|
|
154
|
+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'codepulse-queue-v13-'));
|
|
155
|
+
const dbPath = path.join(tmpDir, 'queue.db');
|
|
156
|
+
try {
|
|
157
|
+
await fs.writeFile(path.join(tmpDir, 'index.ts'), 'export const a = 1;\n', 'utf8');
|
|
158
|
+
const db1 = new CodePulseDatabase(dbPath);
|
|
159
|
+
const repo = db1.upsertRepo({ name: 'acme/demo', localPath: tmpDir });
|
|
160
|
+
const zombie = db1.createJob({ repoId: repo.id, target: 'branch_diff', mode: 'debate', prNumber: 9 });
|
|
161
|
+
db1.updateJobProgress(zombie.id, { status: 'running', progress: 25, currentStep: 'Updating Tree-sitter AST graph...' });
|
|
162
|
+
db1.close();
|
|
163
|
+
// Booting JobQueueManager on same SQLite DB must reconcile zombie row to cancelled
|
|
164
|
+
const db2 = new CodePulseDatabase(dbPath);
|
|
165
|
+
const queue = new JobQueueManager(db2, 1);
|
|
166
|
+
const reconciled = db2.getJob(zombie.id);
|
|
167
|
+
assert.equal(reconciled.status, 'cancelled');
|
|
168
|
+
assert.ok((reconciled.currentStep ?? '').includes('Interrupted'));
|
|
169
|
+
// Enqueueing duplicate (repoId, target, prNumber) while active/pending returns the existing jobId
|
|
170
|
+
const j1 = queue.enqueueScan({
|
|
171
|
+
repoId: repo.id,
|
|
172
|
+
repoPath: tmpDir,
|
|
173
|
+
target: 'directory',
|
|
174
|
+
mode: 'fast',
|
|
175
|
+
prNumber: 12
|
|
176
|
+
});
|
|
177
|
+
const j2 = queue.enqueueScan({
|
|
178
|
+
repoId: repo.id,
|
|
179
|
+
repoPath: tmpDir,
|
|
180
|
+
target: 'directory',
|
|
181
|
+
mode: 'fast',
|
|
182
|
+
prNumber: 12
|
|
183
|
+
});
|
|
184
|
+
assert.equal(j1.id, j2.id);
|
|
185
|
+
await queue.waitForJob(j1.id, 30_000);
|
|
186
|
+
db2.close();
|
|
187
|
+
}
|
|
188
|
+
finally {
|
|
189
|
+
await fs.rm(tmpDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
//# sourceMappingURL=phase5-mcp.test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,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export type AgentPlatform = 'antigravity' | 'claude-code' | 'cursor' | 'codex' | 'windsurf' | 'opencode' | 'gemini-cli' | 'copilot-cli' | 'zed';
|
|
2
|
+
export interface DetectedPlatform {
|
|
3
|
+
platform: AgentPlatform;
|
|
4
|
+
displayName: string;
|
|
5
|
+
detected: boolean;
|
|
6
|
+
configPath: string;
|
|
7
|
+
skillPath?: string;
|
|
8
|
+
hookPath?: string;
|
|
9
|
+
configured: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface InstallOptions {
|
|
12
|
+
platforms?: AgentPlatform[];
|
|
13
|
+
workspacePath?: string;
|
|
14
|
+
dryRun?: boolean;
|
|
15
|
+
includeHooks?: boolean;
|
|
16
|
+
codepulseCommand?: string;
|
|
17
|
+
forceAbsoluteCommandFallback?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface ResolvedMcpInvocation {
|
|
20
|
+
command: string;
|
|
21
|
+
args: string[];
|
|
22
|
+
env?: Record<string, string>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Resolve the MCP launch command safely for Windows & POSIX:
|
|
26
|
+
* - If `codepulse` exists on PATH (unless forced fallback), use `codepulse mcp --stdio`.
|
|
27
|
+
* - Otherwise fall back to `[process.execPath, <absolute cli/dist/index.js>, "mcp", "--stdio"]`
|
|
28
|
+
* so agents connect immediately on Windows without requiring `npm link`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolveMcpInvocation(options?: {
|
|
31
|
+
codepulseCommand?: string;
|
|
32
|
+
forceAbsoluteFallback?: boolean;
|
|
33
|
+
}): Promise<ResolvedMcpInvocation>;
|
|
34
|
+
export interface InstallActionResult {
|
|
35
|
+
platform: AgentPlatform;
|
|
36
|
+
action: 'installed' | 'dry_run' | 'skipped' | 'uninstalled';
|
|
37
|
+
filesWritten: string[];
|
|
38
|
+
details: string;
|
|
39
|
+
}
|
|
40
|
+
export declare const CODEPULSE_SKILL_MD = "---\nname: codepulse-closed-loop\ndescription: Autonomous closed-loop verification workflow with CodePulse MCP & CLI.\n---\n\n# CodePulse Closed-Loop Review & Verification Workflow\n\nBefore completing any code change or feature:\n1. Call `start_scan` with `target: \"local_uncommitted\"` and `mode: \"debate\"` (or `\"security\"` / `\"adversarial\"`).\n2. Call `wait_for_scan(jobId)` \u2014 do NOT poll in a loop.\n3. Call `get_scan_result(jobId, { onlyOpen: true })`.\n4. Fix all `critical` and `high` blockers directly in the workspace, respecting `blast_radius` callers and tests.\n5. Call `revalidate_findings({ target: \"local_uncommitted\", baseScanId: jobId })` to verify fixes are promoted to `verified_fixed`.\n6. Repeat until `merge_gate.passed === true`.\n";
|
|
41
|
+
export declare function detectInstalledPlatforms(workspacePath?: string): Promise<DetectedPlatform[]>;
|
|
42
|
+
export declare function installAgentBridges(options?: InstallOptions): Promise<InstallActionResult[]>;
|
|
43
|
+
export declare function uninstallAgentBridges(options?: {
|
|
44
|
+
platforms?: AgentPlatform[];
|
|
45
|
+
workspacePath?: string;
|
|
46
|
+
}): Promise<InstallActionResult[]>;
|
|
47
|
+
//# sourceMappingURL=installer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"installer.d.ts","sourceRoot":"","sources":["../src/installer.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,aAAa,GACrB,a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aAAa,SAAgB,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CA+BzG;AAED,wBAAsB,mBAAmB,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC,CA0HtG;AAED,wBAAsB,qBAAqB,CAAC,OAAO,GAAE;IACnD,SAAS,CAAC,EAAE,aAAa,EAAE,CAAC;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC,CA4CtC"}
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { commandExists, resolveSafeDirectory, safeResolveInside, writeFileAtomic, writeJsonAtomic } from '@codepulse-oss/core';
|
|
6
|
+
/**
|
|
7
|
+
* Resolve the MCP launch command safely for Windows & POSIX:
|
|
8
|
+
* - If `codepulse` exists on PATH (unless forced fallback), use `codepulse mcp --stdio`.
|
|
9
|
+
* - Otherwise fall back to `[process.execPath, <absolute cli/dist/index.js>, "mcp", "--stdio"]`
|
|
10
|
+
* so agents connect immediately on Windows without requiring `npm link`.
|
|
11
|
+
*/
|
|
12
|
+
export async function resolveMcpInvocation(options = {}) {
|
|
13
|
+
if (options.codepulseCommand && !options.forceAbsoluteFallback) {
|
|
14
|
+
return { command: options.codepulseCommand, args: ['mcp', '--stdio'] };
|
|
15
|
+
}
|
|
16
|
+
if (!options.forceAbsoluteFallback && (await commandExists('codepulse'))) {
|
|
17
|
+
return { command: 'codepulse', args: ['mcp', '--stdio'] };
|
|
18
|
+
}
|
|
19
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
20
|
+
const candidates = [
|
|
21
|
+
path.resolve(__dirname, '../../cli/dist/index.js'),
|
|
22
|
+
path.resolve(__dirname, '../../../packages/cli/dist/index.js'),
|
|
23
|
+
path.resolve(process.cwd(), 'packages/cli/dist/index.js')
|
|
24
|
+
];
|
|
25
|
+
let cliEntry = candidates[0];
|
|
26
|
+
for (const cand of candidates) {
|
|
27
|
+
try {
|
|
28
|
+
await fs.access(cand);
|
|
29
|
+
cliEntry = cand;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// try next
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const isElectron = Boolean(process.versions.electron);
|
|
37
|
+
return {
|
|
38
|
+
command: process.execPath,
|
|
39
|
+
args: [cliEntry, 'mcp', '--stdio'],
|
|
40
|
+
...(isElectron ? { env: { ELECTRON_RUN_AS_NODE: '1' } } : {})
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export const CODEPULSE_SKILL_MD = `---
|
|
44
|
+
name: codepulse-closed-loop
|
|
45
|
+
description: Autonomous closed-loop verification workflow with CodePulse MCP & CLI.
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
# CodePulse Closed-Loop Review & Verification Workflow
|
|
49
|
+
|
|
50
|
+
Before completing any code change or feature:
|
|
51
|
+
1. Call \`start_scan\` with \`target: "local_uncommitted"\` and \`mode: "debate"\` (or \`"security"\` / \`"adversarial"\`).
|
|
52
|
+
2. Call \`wait_for_scan(jobId)\` — do NOT poll in a loop.
|
|
53
|
+
3. Call \`get_scan_result(jobId, { onlyOpen: true })\`.
|
|
54
|
+
4. Fix all \`critical\` and \`high\` blockers directly in the workspace, respecting \`blast_radius\` callers and tests.
|
|
55
|
+
5. Call \`revalidate_findings({ target: "local_uncommitted", baseScanId: jobId })\` to verify fixes are promoted to \`verified_fixed\`.
|
|
56
|
+
6. Repeat until \`merge_gate.passed === true\`.
|
|
57
|
+
`;
|
|
58
|
+
function getHomeDir() {
|
|
59
|
+
return os.homedir();
|
|
60
|
+
}
|
|
61
|
+
function getPlatformDescriptors(workspacePath = process.cwd()) {
|
|
62
|
+
const home = getHomeDir();
|
|
63
|
+
const appData = process.env.APPDATA ?? path.join(home, 'AppData', 'Roaming');
|
|
64
|
+
return [
|
|
65
|
+
{
|
|
66
|
+
platform: 'antigravity',
|
|
67
|
+
displayName: 'Antigravity',
|
|
68
|
+
detectPaths: [path.join(home, '.gemini', 'antigravity')],
|
|
69
|
+
configPath: path.join(home, '.gemini', 'antigravity', 'mcp_config.json'),
|
|
70
|
+
format: 'mcpServers',
|
|
71
|
+
skillPath: path.join(home, '.gemini', 'antigravity', 'skills', 'codepulse', 'SKILL.md')
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
platform: 'claude-code',
|
|
75
|
+
displayName: 'Claude Code',
|
|
76
|
+
detectPaths: [path.join(home, '.claude'), path.join(home, '.claude.json')],
|
|
77
|
+
configPath: path.join(home, '.claude.json'),
|
|
78
|
+
format: 'mcpServers',
|
|
79
|
+
skillPath: path.join(workspacePath, '.claude', 'skills', 'codepulse', 'SKILL.md'),
|
|
80
|
+
hookPath: path.join(workspacePath, '.claude', 'settings.local.json')
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
platform: 'cursor',
|
|
84
|
+
displayName: 'Cursor',
|
|
85
|
+
detectPaths: [path.join(home, '.cursor'), path.join(appData, 'Cursor')],
|
|
86
|
+
configPath: path.join(home, '.cursor', 'mcp.json'),
|
|
87
|
+
format: 'mcpServers',
|
|
88
|
+
skillPath: path.join(workspacePath, '.cursor', 'rules', 'codepulse.mdc')
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
platform: 'codex',
|
|
92
|
+
displayName: 'OpenAI Codex CLI',
|
|
93
|
+
detectPaths: [path.join(home, '.codex')],
|
|
94
|
+
configPath: path.join(home, '.codex', 'config.toml'),
|
|
95
|
+
format: 'codex_toml',
|
|
96
|
+
skillPath: path.join(workspacePath, 'AGENTS.md')
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
platform: 'windsurf',
|
|
100
|
+
displayName: 'Windsurf',
|
|
101
|
+
detectPaths: [path.join(home, '.codeium', 'windsurf')],
|
|
102
|
+
configPath: path.join(home, '.codeium', 'windsurf', 'mcp_config.json'),
|
|
103
|
+
format: 'mcpServers'
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
platform: 'opencode',
|
|
107
|
+
displayName: 'OpenCode',
|
|
108
|
+
detectPaths: [path.join(home, '.config', 'opencode')],
|
|
109
|
+
configPath: path.join(home, '.config', 'opencode', 'opencode.json'),
|
|
110
|
+
format: 'opencode'
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
platform: 'gemini-cli',
|
|
114
|
+
displayName: 'Gemini CLI',
|
|
115
|
+
detectPaths: [path.join(home, '.gemini', 'settings.json'), path.join(home, '.gemini')],
|
|
116
|
+
configPath: path.join(home, '.gemini', 'settings.json'),
|
|
117
|
+
format: 'mcpServers'
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
platform: 'copilot-cli',
|
|
121
|
+
displayName: 'GitHub Copilot CLI',
|
|
122
|
+
detectPaths: [path.join(home, '.copilot')],
|
|
123
|
+
configPath: path.join(home, '.copilot', 'mcp-config.json'),
|
|
124
|
+
format: 'mcpServers'
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
platform: 'zed',
|
|
128
|
+
displayName: 'Zed Editor',
|
|
129
|
+
detectPaths: [path.join(appData, 'Zed'), path.join(home, '.config', 'zed')],
|
|
130
|
+
configPath: process.platform === 'win32'
|
|
131
|
+
? path.join(appData, 'Zed', 'settings.json')
|
|
132
|
+
: path.join(home, '.config', 'zed', 'settings.json'),
|
|
133
|
+
format: 'zed'
|
|
134
|
+
}
|
|
135
|
+
];
|
|
136
|
+
}
|
|
137
|
+
function resolveAllowedBridgePath(targetPath, workspacePath) {
|
|
138
|
+
const candidates = [
|
|
139
|
+
resolveSafeDirectory(workspacePath),
|
|
140
|
+
os.homedir(),
|
|
141
|
+
process.env.APPDATA,
|
|
142
|
+
process.env.XDG_CONFIG_HOME
|
|
143
|
+
]
|
|
144
|
+
.filter((v) => Boolean(v && v.trim()))
|
|
145
|
+
.map((v) => path.resolve(v));
|
|
146
|
+
const resolvedTarget = path.resolve(targetPath);
|
|
147
|
+
for (const base of candidates) {
|
|
148
|
+
try {
|
|
149
|
+
const checked = safeResolveInside(base, resolvedTarget);
|
|
150
|
+
return { root: base, path: checked };
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
// try next allowed root
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
throw new Error(`Refusing to access bridge path outside user/workspace boundaries: "${resolvedTarget}"`);
|
|
157
|
+
}
|
|
158
|
+
async function exists(p) {
|
|
159
|
+
try {
|
|
160
|
+
await fs.access(p);
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async function readJsonSafe(p, workspacePath = process.cwd()) {
|
|
168
|
+
try {
|
|
169
|
+
const safe = resolveAllowedBridgePath(p, workspacePath);
|
|
170
|
+
const raw = await fs.readFile(safe.path, 'utf8');
|
|
171
|
+
const parsed = JSON.parse(raw);
|
|
172
|
+
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return {};
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
export async function detectInstalledPlatforms(workspacePath = process.cwd()) {
|
|
179
|
+
const descriptors = getPlatformDescriptors(workspacePath);
|
|
180
|
+
const results = [];
|
|
181
|
+
for (const desc of descriptors) {
|
|
182
|
+
let detected = false;
|
|
183
|
+
for (const dp of desc.detectPaths) {
|
|
184
|
+
if (await exists(dp)) {
|
|
185
|
+
detected = true;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
let configured = false;
|
|
190
|
+
if (await exists(desc.configPath)) {
|
|
191
|
+
const text = await fs.readFile(desc.configPath, 'utf8').catch(() => '');
|
|
192
|
+
configured = text.includes('codepulse');
|
|
193
|
+
}
|
|
194
|
+
results.push({
|
|
195
|
+
platform: desc.platform,
|
|
196
|
+
displayName: desc.displayName,
|
|
197
|
+
detected,
|
|
198
|
+
configPath: desc.configPath,
|
|
199
|
+
skillPath: desc.skillPath,
|
|
200
|
+
hookPath: desc.hookPath,
|
|
201
|
+
configured
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
return results;
|
|
205
|
+
}
|
|
206
|
+
export async function installAgentBridges(options = {}) {
|
|
207
|
+
const workspacePath = options.workspacePath ?? process.cwd();
|
|
208
|
+
const dryRun = options.dryRun ?? false;
|
|
209
|
+
const includeHooks = options.includeHooks ?? true;
|
|
210
|
+
const invocation = await resolveMcpInvocation({
|
|
211
|
+
codepulseCommand: options.codepulseCommand,
|
|
212
|
+
forceAbsoluteFallback: options.forceAbsoluteCommandFallback
|
|
213
|
+
});
|
|
214
|
+
const descriptors = getPlatformDescriptors(workspacePath);
|
|
215
|
+
const detected = await detectInstalledPlatforms(workspacePath);
|
|
216
|
+
const selectedSet = options.platforms
|
|
217
|
+
? new Set(options.platforms)
|
|
218
|
+
: new Set(detected.filter((d) => d.detected).map((d) => d.platform));
|
|
219
|
+
const results = [];
|
|
220
|
+
for (const desc of descriptors) {
|
|
221
|
+
if (!selectedSet.has(desc.platform)) {
|
|
222
|
+
results.push({
|
|
223
|
+
platform: desc.platform,
|
|
224
|
+
action: 'skipped',
|
|
225
|
+
filesWritten: [],
|
|
226
|
+
details: 'Not detected or not selected'
|
|
227
|
+
});
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
const filesWritten = [];
|
|
231
|
+
if (!dryRun) {
|
|
232
|
+
const safeConfig = resolveAllowedBridgePath(desc.configPath, workspacePath);
|
|
233
|
+
if (desc.format === 'codex_toml') {
|
|
234
|
+
const existing = await fs.readFile(safeConfig.path, 'utf8').catch(() => '');
|
|
235
|
+
const tomlArgs = invocation.args.map((a) => JSON.stringify(a)).join(', ');
|
|
236
|
+
const tomlBlock = `\n[mcp_servers.codepulse]\ncommand = ${JSON.stringify(invocation.command)}\nargs = [${tomlArgs}]\n`;
|
|
237
|
+
if (!existing.includes('[mcp_servers.codepulse]')) {
|
|
238
|
+
await writeFileAtomic(safeConfig.path, existing + tomlBlock, safeConfig.root);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
const updated = existing.replace(/\n?\[mcp_servers\.codepulse\][\s\S]*?(?=\n\[|$)/g, tomlBlock);
|
|
242
|
+
await writeFileAtomic(safeConfig.path, updated, safeConfig.root);
|
|
243
|
+
}
|
|
244
|
+
filesWritten.push(safeConfig.path);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
const json = await readJsonSafe(safeConfig.path, workspacePath);
|
|
248
|
+
if (desc.format === 'mcpServers') {
|
|
249
|
+
const servers = json.mcpServers ?? {};
|
|
250
|
+
servers.codepulse = {
|
|
251
|
+
command: invocation.command,
|
|
252
|
+
args: invocation.args,
|
|
253
|
+
...(invocation.env ? { env: invocation.env } : {})
|
|
254
|
+
};
|
|
255
|
+
json.mcpServers = servers;
|
|
256
|
+
}
|
|
257
|
+
else if (desc.format === 'opencode') {
|
|
258
|
+
const mcp = json.mcp ?? {};
|
|
259
|
+
mcp.codepulse = {
|
|
260
|
+
type: 'local',
|
|
261
|
+
command: [invocation.command, ...invocation.args],
|
|
262
|
+
enabled: true
|
|
263
|
+
};
|
|
264
|
+
json.mcp = mcp;
|
|
265
|
+
}
|
|
266
|
+
else if (desc.format === 'zed') {
|
|
267
|
+
const ctx = json.context_servers ?? {};
|
|
268
|
+
ctx.codepulse = { command: { path: invocation.command, args: invocation.args } };
|
|
269
|
+
json.context_servers = ctx;
|
|
270
|
+
}
|
|
271
|
+
await writeJsonAtomic(safeConfig.path, json, safeConfig.root);
|
|
272
|
+
filesWritten.push(safeConfig.path);
|
|
273
|
+
}
|
|
274
|
+
if (desc.skillPath) {
|
|
275
|
+
const safeSkill = resolveAllowedBridgePath(desc.skillPath, workspacePath);
|
|
276
|
+
if (safeSkill.path.endsWith('AGENTS.md')) {
|
|
277
|
+
const existingAgents = await fs.readFile(safeSkill.path, 'utf8').catch(() => '');
|
|
278
|
+
if (!existingAgents.includes('CodePulse Closed-Loop')) {
|
|
279
|
+
await writeFileAtomic(safeSkill.path, `${existingAgents}\n\n${CODEPULSE_SKILL_MD}`.trim() + '\n', safeSkill.root);
|
|
280
|
+
filesWritten.push(safeSkill.path);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
await writeFileAtomic(safeSkill.path, CODEPULSE_SKILL_MD, safeSkill.root);
|
|
285
|
+
filesWritten.push(safeSkill.path);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (includeHooks && desc.hookPath && desc.platform === 'claude-code') {
|
|
289
|
+
const safeHook = resolveAllowedBridgePath(desc.hookPath, workspacePath);
|
|
290
|
+
const hookJson = await readJsonSafe(safeHook.path, workspacePath);
|
|
291
|
+
const hooks = hookJson.hooks ?? {};
|
|
292
|
+
const gateCmdPrefix = invocation.args.length === 3
|
|
293
|
+
? `"${invocation.command}" "${invocation.args[0]}"`
|
|
294
|
+
: `"${invocation.command}"`;
|
|
295
|
+
hooks.Stop = [
|
|
296
|
+
{
|
|
297
|
+
matcher: '',
|
|
298
|
+
hooks: [
|
|
299
|
+
{
|
|
300
|
+
type: 'command',
|
|
301
|
+
command: `${gateCmdPrefix} stop-gate --repo "${workspacePath}"`
|
|
302
|
+
}
|
|
303
|
+
]
|
|
304
|
+
}
|
|
305
|
+
];
|
|
306
|
+
hookJson.hooks = hooks;
|
|
307
|
+
await writeJsonAtomic(safeHook.path, hookJson, safeHook.root);
|
|
308
|
+
filesWritten.push(safeHook.path);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
results.push({
|
|
312
|
+
platform: desc.platform,
|
|
313
|
+
action: dryRun ? 'dry_run' : 'installed',
|
|
314
|
+
filesWritten: dryRun ? [desc.configPath, ...(desc.skillPath ? [desc.skillPath] : [])] : filesWritten,
|
|
315
|
+
details: dryRun ? 'Would configure CodePulse MCP + closed-loop skill' : 'Configured CodePulse MCP + closed-loop skill'
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
return results;
|
|
319
|
+
}
|
|
320
|
+
export async function uninstallAgentBridges(options = {}) {
|
|
321
|
+
const workspacePath = options.workspacePath ?? process.cwd();
|
|
322
|
+
const descriptors = getPlatformDescriptors(workspacePath);
|
|
323
|
+
const selected = options.platforms ? new Set(options.platforms) : null;
|
|
324
|
+
const results = [];
|
|
325
|
+
for (const desc of descriptors) {
|
|
326
|
+
if (selected && !selected.has(desc.platform))
|
|
327
|
+
continue;
|
|
328
|
+
if (!(await exists(desc.configPath)))
|
|
329
|
+
continue;
|
|
330
|
+
const filesModified = [];
|
|
331
|
+
const safeCfg = resolveAllowedBridgePath(desc.configPath, workspacePath);
|
|
332
|
+
if (desc.format === 'codex_toml') {
|
|
333
|
+
const text = await fs.readFile(safeCfg.path, 'utf8');
|
|
334
|
+
const cleaned = text.replace(/\n?\[mcp_servers\.codepulse\][\s\S]*?(?=\n\[|$)/g, '');
|
|
335
|
+
if (cleaned !== text) {
|
|
336
|
+
await writeFileAtomic(safeCfg.path, cleaned, safeCfg.root);
|
|
337
|
+
filesModified.push(safeCfg.path);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
const json = await readJsonSafe(safeCfg.path, workspacePath);
|
|
342
|
+
let changed = false;
|
|
343
|
+
for (const key of ['mcpServers', 'mcp', 'context_servers']) {
|
|
344
|
+
const obj = json[key];
|
|
345
|
+
if (obj && 'codepulse' in obj) {
|
|
346
|
+
delete obj.codepulse;
|
|
347
|
+
changed = true;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (changed) {
|
|
351
|
+
await writeJsonAtomic(safeCfg.path, json, safeCfg.root);
|
|
352
|
+
filesModified.push(safeCfg.path);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
results.push({
|
|
356
|
+
platform: desc.platform,
|
|
357
|
+
action: 'uninstalled',
|
|
358
|
+
filesWritten: filesModified,
|
|
359
|
+
details: filesModified.length > 0 ? 'Removed CodePulse MCP entry' : 'No CodePulse entry found'
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
return results;
|
|
363
|
+
}
|
|
364
|
+
//# sourceMappingURL=installer.js.map
|