codesearch-mcp 0.0.2-alpha → 0.0.4-alpha
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/src/setup.js +60 -9
- package/package.json +1 -1
package/dist/src/setup.js
CHANGED
|
@@ -41,7 +41,7 @@ const os = __importStar(require("os"));
|
|
|
41
41
|
const child_process_1 = require("child_process");
|
|
42
42
|
const CONFIG_DIR = path.join(os.homedir(), '.config', 'codesearch-mcp');
|
|
43
43
|
const CONFIG_FILE = path.join(CONFIG_DIR, '.env');
|
|
44
|
-
const DOCKER_COMPOSE_SRC = path.join(__dirname, '..', 'docker', 'docker-compose.yml');
|
|
44
|
+
const DOCKER_COMPOSE_SRC = path.join(__dirname, '..', '..', 'docker', 'docker-compose.yml');
|
|
45
45
|
const DOCKER_COMPOSE_DST = path.join(CONFIG_DIR, 'docker-compose.yml');
|
|
46
46
|
function ask(rl, question) {
|
|
47
47
|
return new Promise(resolve => rl.question(question, resolve));
|
|
@@ -50,6 +50,11 @@ async function prompt(rl, label, defaultVal) {
|
|
|
50
50
|
const answer = await ask(rl, `${label} (${defaultVal}): `);
|
|
51
51
|
return answer.trim() || defaultVal;
|
|
52
52
|
}
|
|
53
|
+
function expandHome(p) {
|
|
54
|
+
if (p.startsWith('~/') || p === '~')
|
|
55
|
+
return path.join(os.homedir(), p.slice(2));
|
|
56
|
+
return p;
|
|
57
|
+
}
|
|
53
58
|
function writeEnv(vars) {
|
|
54
59
|
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
55
60
|
const content = Object.entries(vars)
|
|
@@ -58,6 +63,51 @@ function writeEnv(vars) {
|
|
|
58
63
|
fs.writeFileSync(CONFIG_FILE, content, { mode: 0o600 });
|
|
59
64
|
console.log(`\nConfig saved to ${CONFIG_FILE}`);
|
|
60
65
|
}
|
|
66
|
+
async function waitForDb(host, port, user, pass, db, maxWaitSec = 60) {
|
|
67
|
+
const { Client } = await Promise.resolve().then(() => __importStar(require('pg')));
|
|
68
|
+
const deadline = Date.now() + maxWaitSec * 1000;
|
|
69
|
+
process.stdout.write('Waiting for PostgreSQL to be ready');
|
|
70
|
+
while (Date.now() < deadline) {
|
|
71
|
+
try {
|
|
72
|
+
const client = new Client({ host, port, user, password: pass, database: db, connectionTimeoutMillis: 2000 });
|
|
73
|
+
await client.connect();
|
|
74
|
+
await client.end();
|
|
75
|
+
console.log(' ready.');
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
process.stdout.write('.');
|
|
80
|
+
await new Promise(r => setTimeout(r, 2000));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
console.error('\nPostgreSQL did not become ready in time.');
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
async function waitForOllama(host, maxWaitSec = 60) {
|
|
87
|
+
const deadline = Date.now() + maxWaitSec * 1000;
|
|
88
|
+
process.stdout.write('Waiting for Ollama to be ready');
|
|
89
|
+
while (Date.now() < deadline) {
|
|
90
|
+
try {
|
|
91
|
+
const http = await Promise.resolve().then(() => __importStar(require('http')));
|
|
92
|
+
await new Promise((resolve, reject) => {
|
|
93
|
+
const req = http.get(`${host}/api/tags`, res => {
|
|
94
|
+
res.resume();
|
|
95
|
+
res.statusCode === 200 ? resolve() : reject(new Error(`status ${res.statusCode}`));
|
|
96
|
+
});
|
|
97
|
+
req.on('error', reject);
|
|
98
|
+
req.setTimeout(2000, () => { req.destroy(); reject(new Error('timeout')); });
|
|
99
|
+
});
|
|
100
|
+
console.log(' ready.');
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
process.stdout.write('.');
|
|
105
|
+
await new Promise(r => setTimeout(r, 2000));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
console.error('\nOllama did not become ready in time.');
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
61
111
|
async function checkRemoteDb(host, port, user, pass, db) {
|
|
62
112
|
try {
|
|
63
113
|
const { Client } = await Promise.resolve().then(() => __importStar(require('pg')));
|
|
@@ -71,7 +121,7 @@ async function checkRemoteDb(host, port, user, pass, db) {
|
|
|
71
121
|
return false;
|
|
72
122
|
}
|
|
73
123
|
}
|
|
74
|
-
async function setupLocalDocker(
|
|
124
|
+
async function setupLocalDocker(ollamaHost) {
|
|
75
125
|
console.log('\nCopying docker-compose.yml to', DOCKER_COMPOSE_DST);
|
|
76
126
|
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
77
127
|
fs.copyFileSync(DOCKER_COMPOSE_SRC, DOCKER_COMPOSE_DST);
|
|
@@ -81,8 +131,8 @@ async function setupLocalDocker(rl) {
|
|
|
81
131
|
console.error('Failed to start Docker containers. Make sure Docker is running.');
|
|
82
132
|
process.exit(1);
|
|
83
133
|
}
|
|
84
|
-
|
|
85
|
-
await
|
|
134
|
+
await waitForDb('localhost', 5433, 'dev', 'dev', 'rag');
|
|
135
|
+
await waitForOllama(ollamaHost);
|
|
86
136
|
console.log('Pulling bge-m3 model (this may take a while)...');
|
|
87
137
|
(0, child_process_1.spawnSync)('docker', ['exec', 'codesearch-mcp-ollama-1', 'ollama', 'pull', 'bge-m3'], { stdio: 'inherit' });
|
|
88
138
|
return {
|
|
@@ -118,12 +168,14 @@ async function runSetup() {
|
|
|
118
168
|
console.log('=== codesearch-mcp setup ===\n');
|
|
119
169
|
const dbChoice = await ask(rl, 'Database type:\n 1. Local Docker (auto-start)\n 2. Remote (Supabase, Railway, self-hosted)\n\nEnter choice (1): ');
|
|
120
170
|
const useDocker = (dbChoice.trim() || '1') === '1';
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const workspaceRoot = await prompt(rl, 'Workspace root path', path.join(os.homedir(), 'Projects'));
|
|
171
|
+
const defaultWorkspace = path.join(os.homedir(), 'Projects');
|
|
172
|
+
const workspaceInput = await ask(rl, `\nWorkspace root — directory that contains all your projects\n Example: ${os.homedir()}/WebstormProjects\n Path (${defaultWorkspace}): `);
|
|
173
|
+
const workspaceRoot = expandHome(workspaceInput.trim() || defaultWorkspace);
|
|
125
174
|
const ollamaHost = await prompt(rl, 'Ollama API URL', 'http://localhost:11434');
|
|
126
175
|
const ollamaModel = await prompt(rl, 'Embedding model', 'bge-m3');
|
|
176
|
+
const dbVars = useDocker
|
|
177
|
+
? await setupLocalDocker(ollamaHost)
|
|
178
|
+
: await setupRemoteDb(rl);
|
|
127
179
|
writeEnv({
|
|
128
180
|
...dbVars,
|
|
129
181
|
WORKSPACE_ROOT: workspaceRoot,
|
|
@@ -132,7 +184,6 @@ async function runSetup() {
|
|
|
132
184
|
});
|
|
133
185
|
rl.close();
|
|
134
186
|
console.log('\nInitializing database schema...');
|
|
135
|
-
// Re-apply env from the file we just wrote so initDbWithSchema picks up the new values
|
|
136
187
|
const dotenv = await Promise.resolve().then(() => __importStar(require('dotenv')));
|
|
137
188
|
dotenv.config({ path: CONFIG_FILE, override: true });
|
|
138
189
|
const { initDbWithSchema } = await Promise.resolve().then(() => __importStar(require('./db')));
|
package/package.json
CHANGED