yats-toolkit 0.1.21 → 0.2.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.
- package/bin/setup.js +21 -1
- package/package.json +1 -1
- package/src/connect.js +306 -0
- package/src/setup.js +241 -116
package/bin/setup.js
CHANGED
|
@@ -18,14 +18,30 @@
|
|
|
18
18
|
* yats bridge # MCP stdio ↔ HTTP proxy (for Copilot, Claude)
|
|
19
19
|
* yats benchmark # AI agent token comparison
|
|
20
20
|
* yats watch <path> # Watch a repo and keep the index live
|
|
21
|
+
* yats connect [agent] # Show or install agent config
|
|
21
22
|
*/
|
|
22
23
|
|
|
23
24
|
const cmd = process.argv[2] || "setup";
|
|
24
25
|
const args = process.argv.slice(3);
|
|
25
26
|
|
|
27
|
+
function parseFlags(arr) {
|
|
28
|
+
const flags = {};
|
|
29
|
+
for (let i = 0; i < arr.length; i++) {
|
|
30
|
+
const a = arr[i];
|
|
31
|
+
if (a === "--provider" && arr[i + 1]) flags.provider = arr[++i];
|
|
32
|
+
else if (a === "--api-key" && arr[i + 1]) flags.apiKey = arr[++i];
|
|
33
|
+
else if (a === "--port" && arr[i + 1]) flags.port = arr[++i];
|
|
34
|
+
else if (a === "--batch" && arr[i + 1]) flags.batch = arr[++i];
|
|
35
|
+
else if (a === "--no-docs") flags.noDocs = true;
|
|
36
|
+
else if (a === "--yes") flags.skipConfirm = true;
|
|
37
|
+
}
|
|
38
|
+
flags.nonInteractive = !!(flags.provider && flags.apiKey);
|
|
39
|
+
return flags;
|
|
40
|
+
}
|
|
41
|
+
|
|
26
42
|
switch (cmd) {
|
|
27
43
|
case "setup":
|
|
28
|
-
import("../src/setup.js").then(m => m.default());
|
|
44
|
+
import("../src/setup.js").then(m => m.default(parseFlags(args)));
|
|
29
45
|
break;
|
|
30
46
|
case "index":
|
|
31
47
|
case "add": {
|
|
@@ -73,6 +89,9 @@ switch (cmd) {
|
|
|
73
89
|
case "watch":
|
|
74
90
|
import("../src/watch.js");
|
|
75
91
|
break;
|
|
92
|
+
case "connect":
|
|
93
|
+
import("../src/connect.js").then(m => m.default(args));
|
|
94
|
+
break;
|
|
76
95
|
case "--version":
|
|
77
96
|
case "-v":
|
|
78
97
|
try {
|
|
@@ -101,5 +120,6 @@ switch (cmd) {
|
|
|
101
120
|
console.log(` yats bridge Stdio proxy for Copilot/Claude`);
|
|
102
121
|
console.log(` yats benchmark AI agent token comparison`);
|
|
103
122
|
console.log(` yats watch <path> Keep index in sync with live edits`);
|
|
123
|
+
console.log(` yats connect [agent] Show agent setup config`);
|
|
104
124
|
break;
|
|
105
125
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yats-toolkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "YATS — Yet Another Token Saver. One-command MCP server that indexes your codebase into a knowledge graph so AI agents (Claude, Cursor, Copilot) can search and navigate it without burning tokens.",
|
|
5
5
|
"author": "Franco Vinciarelli <vinciarellifranco@gmail.com>",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
package/src/connect.js
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* yats connect — Set up YATS MCP config for your AI agent.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* yats connect Pick agent interactively, show config
|
|
6
|
+
* yats connect <agent> Show config for specific agent
|
|
7
|
+
* yats connect --install Place files in current directory
|
|
8
|
+
* yats connect --link Show GitHub links
|
|
9
|
+
*/
|
|
10
|
+
import { writeFileSync, readFileSync, existsSync, mkdirSync } from "node:fs";
|
|
11
|
+
import { join, dirname } from "node:path";
|
|
12
|
+
import { createInterface } from "node:readline";
|
|
13
|
+
import { homedir } from "node:os";
|
|
14
|
+
|
|
15
|
+
const B = "\x1b[1m";
|
|
16
|
+
const D = "\x1b[2m";
|
|
17
|
+
const R = "\x1b[0m";
|
|
18
|
+
const G = "\x1b[32m";
|
|
19
|
+
const Y = "\x1b[33m";
|
|
20
|
+
const C = "\x1b[36m";
|
|
21
|
+
const RED = "\x1b[31m";
|
|
22
|
+
|
|
23
|
+
const YATS_DIR = join(homedir(), ".yats");
|
|
24
|
+
const MCP_CONFIG_FILE = join(YATS_DIR, "mcp-config.json");
|
|
25
|
+
|
|
26
|
+
const AGENTS = {
|
|
27
|
+
claude: {
|
|
28
|
+
name: "Claude Code",
|
|
29
|
+
transport: "stdio bridge",
|
|
30
|
+
files: [
|
|
31
|
+
{ src: "connect/claude/yats/SKILL.md", dest: ".claude/skills/yats/SKILL.md", type: "skill" },
|
|
32
|
+
{ src: "connect/claude/.mcp.json", dest: ".mcp.json", type: "json" },
|
|
33
|
+
],
|
|
34
|
+
url: "https://github.com/fvinciarelli/yats.ai/tree/main/connect/claude",
|
|
35
|
+
},
|
|
36
|
+
cursor: {
|
|
37
|
+
name: "Cursor",
|
|
38
|
+
transport: "HTTP",
|
|
39
|
+
files: [
|
|
40
|
+
{ src: "connect/cursor/rules.mdc", dest: ".cursor/rules/rules.mdc", type: "text" },
|
|
41
|
+
{ src: "connect/cursor/mcp.json", dest: ".cursor/mcp.json", type: "json" },
|
|
42
|
+
],
|
|
43
|
+
url: "https://github.com/fvinciarelli/yats.ai/tree/main/connect/cursor",
|
|
44
|
+
},
|
|
45
|
+
copilot: {
|
|
46
|
+
name: "GitHub Copilot",
|
|
47
|
+
transport: "stdio bridge",
|
|
48
|
+
files: [
|
|
49
|
+
{ src: "connect/copilot/instructions.md", dest: ".github/instructions.md", type: "text" },
|
|
50
|
+
{ src: "connect/copilot/mcp.json", dest: ".copilot/mcp.json", type: "json" },
|
|
51
|
+
],
|
|
52
|
+
url: "https://github.com/fvinciarelli/yats.ai/tree/main/connect/copilot",
|
|
53
|
+
},
|
|
54
|
+
gemini: {
|
|
55
|
+
name: "Gemini CLI",
|
|
56
|
+
transport: "stdio bridge",
|
|
57
|
+
files: [
|
|
58
|
+
{ src: "connect/gemini/GEMINI.md", dest: "GEMINI.md", type: "text" },
|
|
59
|
+
{ src: "connect/gemini/mcp.json", dest: ".gemini/settings.json", type: "json" },
|
|
60
|
+
],
|
|
61
|
+
url: "https://github.com/fvinciarelli/yats.ai/tree/main/connect/gemini",
|
|
62
|
+
},
|
|
63
|
+
codex: {
|
|
64
|
+
name: "Codex CLI",
|
|
65
|
+
transport: "stdio bridge",
|
|
66
|
+
files: [
|
|
67
|
+
{ src: "connect/codex/AGENTS.md", dest: "AGENTS.md", type: "text" },
|
|
68
|
+
{ src: "connect/codex/config.toml", dest: ".codex/config.toml", type: "toml" },
|
|
69
|
+
],
|
|
70
|
+
url: "https://github.com/fvinciarelli/yats.ai/tree/main/connect/codex",
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
function getYatsMcpConfig() {
|
|
75
|
+
try {
|
|
76
|
+
return JSON.parse(readFileSync(MCP_CONFIG_FILE, "utf-8"));
|
|
77
|
+
} catch {
|
|
78
|
+
return { mcpServers: { yats: { url: "http://localhost:5555/mcp/sse" } } };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ============================================================
|
|
83
|
+
// Install helpers
|
|
84
|
+
// ============================================================
|
|
85
|
+
|
|
86
|
+
function safeMergeJson(existingPath, newEntry) {
|
|
87
|
+
let obj = {};
|
|
88
|
+
try {
|
|
89
|
+
obj = JSON.parse(readFileSync(existingPath, "utf-8"));
|
|
90
|
+
} catch { /* file doesn't exist or invalid, start fresh */ }
|
|
91
|
+
if (!obj.mcpServers) obj.mcpServers = {};
|
|
92
|
+
obj.mcpServers = { ...obj.mcpServers, ...newEntry.mcpServers };
|
|
93
|
+
return JSON.stringify(obj, null, 2) + "\n";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function installFiles(agentKey) {
|
|
97
|
+
const agent = AGENTS[agentKey];
|
|
98
|
+
if (!agent) {
|
|
99
|
+
console.error(`Unknown agent: ${agentKey}`);
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
console.log("");
|
|
104
|
+
console.log(` ${Y}${B}⚠️ Before installing, back up your existing config files.${R}`);
|
|
105
|
+
console.log(` ${D}This will modify or create files in your current directory.${R}`);
|
|
106
|
+
console.log("");
|
|
107
|
+
|
|
108
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
109
|
+
const answer = await new Promise((resolve) => {
|
|
110
|
+
rl.question(` ${B}Proceed with install for ${agent.name}? [y/N]${R} `, resolve);
|
|
111
|
+
});
|
|
112
|
+
rl.close();
|
|
113
|
+
|
|
114
|
+
if (answer.toLowerCase() !== "y") {
|
|
115
|
+
console.log("");
|
|
116
|
+
console.log(" Cancelled.");
|
|
117
|
+
console.log("");
|
|
118
|
+
process.exit(0);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
console.log("");
|
|
122
|
+
let installed = 0;
|
|
123
|
+
let skipped = 0;
|
|
124
|
+
|
|
125
|
+
for (const file of agent.files) {
|
|
126
|
+
const destPath = file.dest;
|
|
127
|
+
const mcpConfig = getYatsMcpConfig();
|
|
128
|
+
|
|
129
|
+
if (file.type === "json") {
|
|
130
|
+
const merged = safeMergeJson(destPath, mcpConfig);
|
|
131
|
+
const exists = existsSync(destPath);
|
|
132
|
+
mkdirSync(dirname(destPath), { recursive: true });
|
|
133
|
+
writeFileSync(destPath, merged);
|
|
134
|
+
if (exists) {
|
|
135
|
+
console.log(` ${Y}↻${R} Merged YATS into existing ${destPath}`);
|
|
136
|
+
} else {
|
|
137
|
+
console.log(` ${G}✓${R} Created ${destPath}`);
|
|
138
|
+
}
|
|
139
|
+
installed++;
|
|
140
|
+
} else if (file.type === "text" || file.type === "skill") {
|
|
141
|
+
if (existsSync(destPath)) {
|
|
142
|
+
console.log(` ${Y}⚠${R} ${destPath} already exists — skipped (backup and remove to replace)`);
|
|
143
|
+
skipped++;
|
|
144
|
+
} else {
|
|
145
|
+
const content = getFileContent(file.src);
|
|
146
|
+
if (content) {
|
|
147
|
+
mkdirSync(dirname(destPath), { recursive: true });
|
|
148
|
+
writeFileSync(destPath, content);
|
|
149
|
+
console.log(` ${G}✓${R} Created ${destPath}`);
|
|
150
|
+
installed++;
|
|
151
|
+
} else {
|
|
152
|
+
console.log(` ${RED}✗${R} Could not read ${file.src} — download from GitHub`);
|
|
153
|
+
skipped++;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
} else if (file.type === "toml") {
|
|
157
|
+
if (existsSync(destPath)) {
|
|
158
|
+
console.log(` ${Y}⚠${R} ${destPath} already exists — skipped (backup and remove to replace)`);
|
|
159
|
+
skipped++;
|
|
160
|
+
} else {
|
|
161
|
+
const content = getFileContent(file.src);
|
|
162
|
+
if (content) {
|
|
163
|
+
mkdirSync(dirname(destPath), { recursive: true });
|
|
164
|
+
writeFileSync(destPath, content);
|
|
165
|
+
console.log(` ${G}✓${R} Created ${destPath}`);
|
|
166
|
+
installed++;
|
|
167
|
+
} else {
|
|
168
|
+
console.log(` ${RED}✗${R} Could not read ${file.src} — download from GitHub`);
|
|
169
|
+
skipped++;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
console.log("");
|
|
176
|
+
console.log(` Done: ${installed} installed, ${skipped} skipped.`);
|
|
177
|
+
console.log(` Full instructions: ${C}${agent.url}${R}`);
|
|
178
|
+
console.log("");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function getFileContent(srcPath) {
|
|
182
|
+
// Try from node_modules first (when installed via npm)
|
|
183
|
+
try {
|
|
184
|
+
const pkgDir = dirname(new URL(import.meta.url).pathname);
|
|
185
|
+
const installedPath = join(pkgDir, "..", srcPath);
|
|
186
|
+
if (existsSync(installedPath)) {
|
|
187
|
+
return readFileSync(installedPath, "utf-8");
|
|
188
|
+
}
|
|
189
|
+
} catch { /* not installed as npm package */ }
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// ============================================================
|
|
194
|
+
// Display helpers
|
|
195
|
+
// ============================================================
|
|
196
|
+
|
|
197
|
+
function showConfig(agentKey) {
|
|
198
|
+
const agent = AGENTS[agentKey];
|
|
199
|
+
if (!agent) {
|
|
200
|
+
console.error(`Unknown agent: ${agentKey}`);
|
|
201
|
+
console.log("");
|
|
202
|
+
console.log(`Available: ${Object.keys(AGENTS).join(", ")}`);
|
|
203
|
+
process.exit(1);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const mcpConfig = getYatsMcpConfig();
|
|
207
|
+
|
|
208
|
+
console.log("");
|
|
209
|
+
console.log(` ${B}${agent.name}${R} — via ${agent.transport}`);
|
|
210
|
+
console.log("");
|
|
211
|
+
|
|
212
|
+
for (const file of agent.files) {
|
|
213
|
+
console.log(` ${B}${file.dest}${R}`);
|
|
214
|
+
if (file.type === "json") {
|
|
215
|
+
console.log(` ${D}${safeMergeJson("", mcpConfig).replace(/\n/g, "\n ")}${R}`);
|
|
216
|
+
} else {
|
|
217
|
+
const content = getFileContent(file.src);
|
|
218
|
+
if (content) {
|
|
219
|
+
const preview = content.split("\n").slice(0, 8).join("\n");
|
|
220
|
+
console.log(` ${D}${preview}${D}...${R}`);
|
|
221
|
+
} else {
|
|
222
|
+
console.log(` ${D}(download from GitHub)${R}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
console.log("");
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
console.log(` ${B}GitHub:${R} ${C}${agent.url}${R}`);
|
|
229
|
+
console.log("");
|
|
230
|
+
console.log(` Run ${B}yats connect --install${R} to auto-place these files.`);
|
|
231
|
+
console.log("");
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function showLink(agentKey) {
|
|
235
|
+
if (agentKey && AGENTS[agentKey]) {
|
|
236
|
+
console.log(AGENTS[agentKey].url);
|
|
237
|
+
} else if (agentKey) {
|
|
238
|
+
console.error(`Unknown agent: ${agentKey}`);
|
|
239
|
+
process.exit(1);
|
|
240
|
+
} else {
|
|
241
|
+
console.log("https://github.com/fvinciarelli/yats.ai/tree/main/connect");
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async function ask(question) {
|
|
246
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
247
|
+
const answer = await new Promise((resolve) => rl.question(question, resolve));
|
|
248
|
+
rl.close();
|
|
249
|
+
return answer;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
async function choose(prompt, options) {
|
|
253
|
+
console.log(` ${prompt}`);
|
|
254
|
+
for (let i = 0; i < options.length; i++) {
|
|
255
|
+
console.log(` ${B}${i + 1}${R}. ${options[i].label}`);
|
|
256
|
+
}
|
|
257
|
+
console.log("");
|
|
258
|
+
const answer = await ask(` ${B}Pick [1-${options.length}]:${R} `);
|
|
259
|
+
const num = parseInt(answer.trim(), 10);
|
|
260
|
+
if (num >= 1 && num <= options.length) {
|
|
261
|
+
return options[num - 1].value;
|
|
262
|
+
}
|
|
263
|
+
console.log(` ${RED}Invalid.${R}`);
|
|
264
|
+
process.exit(1);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// ============================================================
|
|
268
|
+
// Main
|
|
269
|
+
// ============================================================
|
|
270
|
+
|
|
271
|
+
export default async function connect(args) {
|
|
272
|
+
const agentKey = args.find(a => !a.startsWith("--"));
|
|
273
|
+
const isInstall = args.includes("--install");
|
|
274
|
+
const isLink = args.includes("--link");
|
|
275
|
+
|
|
276
|
+
if (isLink) {
|
|
277
|
+
showLink(agentKey);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (isInstall) {
|
|
282
|
+
if (!agentKey) {
|
|
283
|
+
console.error("Usage: yats connect --install <agent>");
|
|
284
|
+
console.error(` Agents: ${Object.keys(AGENTS).join(", ")}`);
|
|
285
|
+
process.exit(1);
|
|
286
|
+
}
|
|
287
|
+
await installFiles(agentKey);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (agentKey) {
|
|
292
|
+
showConfig(agentKey);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Interactive picker
|
|
297
|
+
const picked = await choose("Which AI agent are you using?", [
|
|
298
|
+
{ label: "Claude Code", value: "claude" },
|
|
299
|
+
{ label: "Cursor", value: "cursor" },
|
|
300
|
+
{ label: "GitHub Copilot", value: "copilot" },
|
|
301
|
+
{ label: "Gemini CLI", value: "gemini" },
|
|
302
|
+
{ label: "Codex CLI", value: "codex" },
|
|
303
|
+
]);
|
|
304
|
+
|
|
305
|
+
showConfig(picked);
|
|
306
|
+
}
|
package/src/setup.js
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { spawn } from "node:child_process";
|
|
12
|
-
import { writeFileSync, mkdirSync, existsSync, readFileSync } from "node:fs";
|
|
12
|
+
import { writeFileSync, mkdirSync, existsSync, readFileSync, statSync } from "node:fs";
|
|
13
13
|
import { homedir } from "node:os";
|
|
14
|
-
import { join } from "node:path";
|
|
14
|
+
import { join, resolve } from "node:path";
|
|
15
15
|
import { createInterface } from "node:readline";
|
|
16
16
|
|
|
17
17
|
// ============================================================
|
|
@@ -373,7 +373,57 @@ async function waitForHealth(url, retries = 30, delay = 2000) {
|
|
|
373
373
|
// Main
|
|
374
374
|
// ============================================================
|
|
375
375
|
|
|
376
|
-
async function
|
|
376
|
+
async function loadEnv() {
|
|
377
|
+
const env = {};
|
|
378
|
+
try {
|
|
379
|
+
const content = readFileSync(ENV_FILE, "utf-8");
|
|
380
|
+
for (const line of content.split("\n")) {
|
|
381
|
+
const trimmed = line.trim();
|
|
382
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
383
|
+
const eq = trimmed.indexOf("=");
|
|
384
|
+
if (eq === -1) continue;
|
|
385
|
+
env[trimmed.slice(0, eq).trim()] = trimmed.slice(eq + 1).trim();
|
|
386
|
+
}
|
|
387
|
+
} catch { /* no .env file yet */ }
|
|
388
|
+
return env;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
async function testApiConnection(provider, apiKey) {
|
|
392
|
+
const endpoints = {
|
|
393
|
+
openai: { url: "https://api.openai.com/v1/embeddings", key: apiKey, body: { model: "text-embedding-3-small", input: ["test"] } },
|
|
394
|
+
mistral: { url: "https://api.mistral.ai/v1/embeddings", key: apiKey, body: { model: "mistral-embed", input: ["test"] } },
|
|
395
|
+
voyage: { url: "https://api.voyageai.com/v1/embeddings", key: apiKey, body: { model: "voyage-3-lite", input: ["test"] } },
|
|
396
|
+
};
|
|
397
|
+
const cfg = endpoints[provider];
|
|
398
|
+
if (!cfg) return { ok: false, error: "Unknown provider" };
|
|
399
|
+
try {
|
|
400
|
+
const res = await fetch(cfg.url, {
|
|
401
|
+
method: "POST",
|
|
402
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${cfg.key}` },
|
|
403
|
+
body: JSON.stringify(cfg.body),
|
|
404
|
+
signal: AbortSignal.timeout(15000),
|
|
405
|
+
});
|
|
406
|
+
if (res.ok) return { ok: true };
|
|
407
|
+
const err = await res.text();
|
|
408
|
+
return { ok: false, error: `HTTP ${res.status}: ${err.slice(0, 200)}` };
|
|
409
|
+
} catch (e) {
|
|
410
|
+
return { ok: false, error: e.message };
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
async function main(options = {}) {
|
|
415
|
+
// Load pre-filled values from .env (if exists) or CLI flags
|
|
416
|
+
const env = loadEnv();
|
|
417
|
+
const nonInteractive = options.nonInteractive || false;
|
|
418
|
+
const prefill = {
|
|
419
|
+
provider: options.provider || env.YATS_PROVIDER || null,
|
|
420
|
+
apiKey: options.apiKey || env.OPENAI_API_KEY || env.MISTRAL_API_KEY || env.VOYAGE_API_KEY || null,
|
|
421
|
+
port: options.port ? parseInt(options.port, 10) : null,
|
|
422
|
+
batch: options.batch ? parseInt(options.batch, 10) : null,
|
|
423
|
+
noDocs: options.noDocs || false,
|
|
424
|
+
skipConfirm: options.skipConfirm || false,
|
|
425
|
+
};
|
|
426
|
+
|
|
377
427
|
header();
|
|
378
428
|
|
|
379
429
|
// Check Docker
|
|
@@ -408,15 +458,43 @@ async function main() {
|
|
|
408
458
|
process.exit(0);
|
|
409
459
|
}
|
|
410
460
|
|
|
411
|
-
//
|
|
412
|
-
|
|
461
|
+
// Check for existing stopped install (compose file exists but containers not running)
|
|
462
|
+
if (existsSync(COMPOSE_FILE)) {
|
|
463
|
+
console.log(` ${Y}⚠${R} Found existing YATS installation (containers not running).`);
|
|
464
|
+
console.log("");
|
|
465
|
+
const rlStopped = createInterface({ input: process.stdin, output: process.stdout });
|
|
466
|
+
const cleanAnswer = await ask(rlStopped, ` ${B}Start fresh (deletes all indexed data)? [y/N]${R} `);
|
|
467
|
+
rlStopped.close();
|
|
468
|
+
if (cleanAnswer.toLowerCase() === "y") {
|
|
469
|
+
console.log("");
|
|
470
|
+
const sClean = spinner("Cleaning up previous installation...");
|
|
471
|
+
try {
|
|
472
|
+
await runCmd("docker", ["compose", "-f", COMPOSE_FILE, "down", "-v"]);
|
|
473
|
+
sClean.done(true);
|
|
474
|
+
} catch {
|
|
475
|
+
sClean.done(false);
|
|
476
|
+
}
|
|
477
|
+
} else {
|
|
478
|
+
console.log("");
|
|
479
|
+
console.log(` ${G}✓${R} Keeping existing data. Proceeding with reconfiguration.`);
|
|
480
|
+
}
|
|
481
|
+
console.log("");
|
|
482
|
+
}
|
|
413
483
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
484
|
+
// Step 1: Embedding provider
|
|
485
|
+
let provider;
|
|
486
|
+
if (nonInteractive && prefill.provider) {
|
|
487
|
+
provider = prefill.provider;
|
|
488
|
+
console.log(` Provider: ${provider}`);
|
|
489
|
+
} else {
|
|
490
|
+
step("Step 1 — Embedding provider");
|
|
491
|
+
provider = await choose("How should I generate embeddings for your code?", [
|
|
492
|
+
{ label: "Ollama (local, private, included) — recommended", value: "ollama" },
|
|
493
|
+
{ label: "OpenAI (cloud, needs API key)", value: "openai" },
|
|
494
|
+
{ label: "Mistral (cloud, needs API key)", value: "mistral" },
|
|
495
|
+
{ label: "Voyage AI (cloud, optimized for code, needs API key)", value: "voyage" },
|
|
496
|
+
]);
|
|
497
|
+
}
|
|
420
498
|
|
|
421
499
|
let apiKey = "";
|
|
422
500
|
let ollamaModel = "nomic-embed-text";
|
|
@@ -430,104 +508,152 @@ async function main() {
|
|
|
430
508
|
} else {
|
|
431
509
|
const providerNames = { openai: "OpenAI", mistral: "Mistral", voyage: "Voyage AI" };
|
|
432
510
|
step(`Step 2 — ${providerNames[provider]} API key`);
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
511
|
+
|
|
512
|
+
if (nonInteractive && prefill.apiKey) {
|
|
513
|
+
apiKey = prefill.apiKey;
|
|
514
|
+
console.log(` API key: ${apiKey.slice(0, 8)}...`);
|
|
515
|
+
} else {
|
|
516
|
+
const rl2 = createInterface({ input: process.stdin, output: process.stdout });
|
|
517
|
+
const defaultKey = prefill.apiKey || "";
|
|
518
|
+
const prompt = defaultKey
|
|
519
|
+
? ` ${B}Your ${providerNames[provider]} API key${R} [${defaultKey.slice(0, 8)}...]: `
|
|
520
|
+
: ` ${B}Your ${providerNames[provider]} API key:${R} `;
|
|
521
|
+
apiKey = await ask(rl2, prompt);
|
|
522
|
+
if (!apiKey && defaultKey) apiKey = defaultKey;
|
|
523
|
+
rl2.close();
|
|
524
|
+
}
|
|
525
|
+
|
|
436
526
|
console.log("");
|
|
437
527
|
console.log(` ${Y}⚠${R} This is a paid service — you may be charged for API usage.`);
|
|
438
528
|
console.log("");
|
|
529
|
+
|
|
530
|
+
// Optional: test connection
|
|
531
|
+
if (!nonInteractive) {
|
|
532
|
+
const rlTest = createInterface({ input: process.stdin, output: process.stdout });
|
|
533
|
+
const testAnswer = await ask(rlTest, ` ${B}Test connection? [Y/n]${R} `);
|
|
534
|
+
rlTest.close();
|
|
535
|
+
if (testAnswer.toLowerCase() !== "n") {
|
|
536
|
+
const sTest = spinner("Testing API connection...");
|
|
537
|
+
const result = await testApiConnection(provider, apiKey);
|
|
538
|
+
if (result.ok) {
|
|
539
|
+
sTest.done(true);
|
|
540
|
+
console.log("");
|
|
541
|
+
} else {
|
|
542
|
+
sTest.done(false);
|
|
543
|
+
console.log(` ${RED}✗${R} Connection failed: ${result.error}`);
|
|
544
|
+
console.log(` ${Y}⚠${R} You can change the API key later in ${C}~/.yats/.env${R}`);
|
|
545
|
+
console.log("");
|
|
546
|
+
if (!nonInteractive) {
|
|
547
|
+
const rlRetry = createInterface({ input: process.stdin, output: process.stdout });
|
|
548
|
+
const retryAnswer = await ask(rlRetry, ` ${B}Re-enter API key? [Y/n]${R} `);
|
|
549
|
+
rlRetry.close();
|
|
550
|
+
if (retryAnswer.toLowerCase() !== "n") {
|
|
551
|
+
const rl2b = createInterface({ input: process.stdin, output: process.stdout });
|
|
552
|
+
apiKey = await ask(rl2b, ` ${B}Your ${providerNames[provider]} API key:${R} `);
|
|
553
|
+
rl2b.close();
|
|
554
|
+
console.log("");
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
} else {
|
|
559
|
+
console.log("");
|
|
560
|
+
}
|
|
561
|
+
}
|
|
439
562
|
console.log("");
|
|
440
563
|
}
|
|
441
564
|
|
|
442
565
|
// Step 3: Embedding batch size
|
|
443
|
-
const BATCH_DEFAULTS = {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
voyage: 100,
|
|
447
|
-
ollama: 4,
|
|
448
|
-
};
|
|
449
|
-
const BATCH_MAX = {
|
|
450
|
-
openai: 2048,
|
|
451
|
-
mistral: 1024,
|
|
452
|
-
voyage: 128,
|
|
453
|
-
ollama: 4,
|
|
454
|
-
};
|
|
455
|
-
const defaultBatch = BATCH_DEFAULTS[provider];
|
|
566
|
+
const BATCH_DEFAULTS = { openai: 200, mistral: 200, voyage: 100, ollama: 4 };
|
|
567
|
+
const BATCH_MAX = { openai: 2048, mistral: 1024, voyage: 128, ollama: 4 };
|
|
568
|
+
const defaultBatch = prefill.batch || BATCH_DEFAULTS[provider];
|
|
456
569
|
const maxBatch = BATCH_MAX[provider];
|
|
457
|
-
|
|
458
|
-
step(`Step 3 — Embedding batch size`);
|
|
459
|
-
console.log(` ${D}How many texts to embed per API request.${R}`);
|
|
460
|
-
console.log(` ${D}Higher = faster indexing, lower = safer for rate limits.${R}`);
|
|
461
|
-
console.log(` ${D}Provider max: ${maxBatch}${R}`);
|
|
462
|
-
console.log("");
|
|
463
|
-
|
|
464
|
-
const rlBatch = createInterface({ input: process.stdin, output: process.stdout });
|
|
465
|
-
const batchAnswer = await ask(rlBatch, ` ${B}Batch size${R} [${defaultBatch}]: `);
|
|
466
|
-
rlBatch.close();
|
|
467
570
|
let batchSize = defaultBatch;
|
|
468
|
-
|
|
469
|
-
if (
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}
|
|
474
|
-
|
|
571
|
+
|
|
572
|
+
if (nonInteractive) {
|
|
573
|
+
console.log(` Batch size: ${batchSize}`);
|
|
574
|
+
} else {
|
|
575
|
+
step(`Step 3 — Embedding batch size`);
|
|
576
|
+
console.log(` ${D}How many texts to embed per API request.${R}`);
|
|
577
|
+
console.log(` ${D}Higher = faster indexing, lower = safer for rate limits.${R}`);
|
|
578
|
+
console.log(` ${D}Provider max: ${maxBatch}${R}`);
|
|
579
|
+
console.log("");
|
|
580
|
+
const rlBatch = createInterface({ input: process.stdin, output: process.stdout });
|
|
581
|
+
const batchAnswer = await ask(rlBatch, ` ${B}Batch size${R} [${defaultBatch}]: `);
|
|
582
|
+
rlBatch.close();
|
|
583
|
+
const batchTrimmed = batchAnswer.trim();
|
|
584
|
+
if (batchTrimmed) {
|
|
585
|
+
const num = parseInt(batchTrimmed, 10);
|
|
586
|
+
if (num >= 1 && num <= maxBatch) batchSize = num;
|
|
587
|
+
else console.log(` ${Y}⚠${R} Must be 1–${maxBatch}. Using default ${defaultBatch}.`);
|
|
475
588
|
}
|
|
589
|
+
console.log(` ${G}✓${R} Batch size: ${batchSize}`);
|
|
590
|
+
console.log("");
|
|
476
591
|
}
|
|
477
|
-
console.log(` ${G}✓${R} Batch size: ${batchSize}`);
|
|
478
|
-
console.log("");
|
|
479
592
|
|
|
480
593
|
// Step 4: Documentation indexing
|
|
481
594
|
const docMaxFiles = 300;
|
|
482
|
-
let indexDocs =
|
|
595
|
+
let indexDocs = !prefill.noDocs;
|
|
483
596
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
597
|
+
if (!nonInteractive) {
|
|
598
|
+
step("Step 4 — Documentation indexing");
|
|
599
|
+
console.log(` ${D}Index README, ARCHITECTURE, AI/ docs, and docs/ directory.${R}`);
|
|
600
|
+
console.log(` ${D}Patterns (edit via DOC_PATTERNS env): AI/*.md, README.md, docs/${R}`);
|
|
601
|
+
console.log(` ${D}If docs/ has >${docMaxFiles} .md files, you'll get a warning.${R}`);
|
|
602
|
+
console.log("");
|
|
603
|
+
const rlDocs = createInterface({ input: process.stdin, output: process.stdout });
|
|
604
|
+
const docsAnswer = await ask(rlDocs, ` ${B}Index documentation? [Y/n]${R} `);
|
|
605
|
+
rlDocs.close();
|
|
606
|
+
if (docsAnswer.toLowerCase() === "n") {
|
|
607
|
+
indexDocs = false;
|
|
608
|
+
console.log(` ${Y}⚠${R} Documentation indexing disabled. Set INDEX_DOCS=true to re-enable.`);
|
|
609
|
+
} else {
|
|
610
|
+
console.log(` ${G}✓${R} Documentation will be indexed.`);
|
|
611
|
+
}
|
|
612
|
+
console.log("");
|
|
496
613
|
} else {
|
|
497
|
-
console.log(` ${
|
|
614
|
+
console.log(` Index docs: ${indexDocs ? "Yes" : "No"}`);
|
|
498
615
|
}
|
|
499
|
-
console.log("");
|
|
500
616
|
|
|
501
617
|
// Optional: pre-index directories
|
|
502
|
-
step("Step 5 — Pre-index (optional)");
|
|
503
|
-
console.log(` ${D}Indexing happens automatically on first search.${R}`);
|
|
504
|
-
console.log(` ${D}Want to pre-index some directories now to skip the wait later?${R}`);
|
|
505
|
-
console.log("");
|
|
506
|
-
console.log(` ${D}Tip: type a path or drag-n-drop a folder from your file manager.${R}`);
|
|
507
|
-
|
|
508
|
-
const rl3 = createInterface({ input: process.stdin, output: process.stdout });
|
|
509
618
|
const pathsToIndex = [];
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
619
|
+
if (!nonInteractive) {
|
|
620
|
+
step("Step 5 — Pre-index (optional)");
|
|
621
|
+
console.log(` ${D}Indexing happens automatically on first search.${R}`);
|
|
622
|
+
console.log(` ${D}Want to pre-index some directories now to skip the wait later?${R}`);
|
|
623
|
+
console.log("");
|
|
624
|
+
console.log(` ${D}Tip: type a path or drag-n-drop a folder from your file manager.${R}`);
|
|
625
|
+
const rl3 = createInterface({ input: process.stdin, output: process.stdout });
|
|
626
|
+
while (true) {
|
|
627
|
+
const p = await ask(rl3, ` ${B}Directory path (Enter to skip):${R} `);
|
|
628
|
+
const trimmed = p.trim();
|
|
629
|
+
if (!trimmed) break;
|
|
630
|
+
const resolved = resolve(trimmed);
|
|
631
|
+
if (existsSync(resolved)) {
|
|
632
|
+
try {
|
|
633
|
+
if (statSync(resolved).isDirectory()) {
|
|
634
|
+
pathsToIndex.push(resolved);
|
|
635
|
+
console.log(` ${G}✓${R} Added: ${resolved}`);
|
|
636
|
+
} else {
|
|
637
|
+
console.log(` ${RED}✗${R} Not a directory: ${resolved}`);
|
|
638
|
+
}
|
|
639
|
+
} catch {
|
|
640
|
+
console.log(` ${RED}✗${R} Cannot access: ${resolved}`);
|
|
641
|
+
}
|
|
642
|
+
} else {
|
|
643
|
+
console.log(` ${RED}✗${R} Not found: ${resolved}`);
|
|
644
|
+
}
|
|
519
645
|
}
|
|
646
|
+
rl3.close();
|
|
520
647
|
}
|
|
521
|
-
rl3.close();
|
|
522
648
|
console.log("");
|
|
523
649
|
|
|
524
650
|
// Port selection
|
|
525
|
-
let mcpPort = 5555;
|
|
526
|
-
{
|
|
651
|
+
let mcpPort = prefill.port || 5555;
|
|
652
|
+
if (!nonInteractive) {
|
|
527
653
|
const rlPort = createInterface({ input: process.stdin, output: process.stdout });
|
|
528
654
|
const inUse = await checkPort(mcpPort);
|
|
529
|
-
const suggested = inUse ?
|
|
530
|
-
const hint = inUse ? ` ${Y}(default
|
|
655
|
+
const suggested = inUse ? (mcpPort + 1) : mcpPort;
|
|
656
|
+
const hint = inUse ? ` ${Y}(default ${mcpPort} is in use)${R}` : "";
|
|
531
657
|
const answer = await ask(rlPort, ` ${B}MCP server port${R} [${suggested}]:${hint} `);
|
|
532
658
|
const trimmed = answer.trim();
|
|
533
659
|
if (trimmed) {
|
|
@@ -537,36 +663,36 @@ async function main() {
|
|
|
537
663
|
mcpPort = suggested;
|
|
538
664
|
}
|
|
539
665
|
rlPort.close();
|
|
666
|
+
console.log(` ${G}✓${R} MCP server on ${C}http://localhost:${mcpPort}/mcp/sse${R}`);
|
|
667
|
+
console.log("");
|
|
540
668
|
}
|
|
541
|
-
console.log(` ${G}✓${R} MCP server on ${C}http://localhost:${mcpPort}/mcp/sse${R}`);
|
|
542
|
-
console.log("");
|
|
543
669
|
|
|
544
|
-
//
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
console.log("");
|
|
560
|
-
|
|
561
|
-
const proceed = await (() => {
|
|
562
|
-
const rl4 = createInterface({ input: process.stdin, output: process.stdout });
|
|
563
|
-
return ask(rl4, ` ${B}Proceed? [Y/n]${R} `).then((a) => { rl4.close(); return a; });
|
|
564
|
-
})();
|
|
565
|
-
if (proceed.toLowerCase() === "n") {
|
|
566
|
-
console.log("");
|
|
567
|
-
console.log(` Setup cancelled. Run ${B}npx yats-toolkit${R} anytime to try again.`);
|
|
670
|
+
// Confirm
|
|
671
|
+
if (!nonInteractive && !prefill.skipConfirm) {
|
|
672
|
+
step(`Step ${pathsToIndex.length ? "6" : "5"} — Confirm`);
|
|
673
|
+
const providerName = provider === "ollama"
|
|
674
|
+
? `Ollama (${ollamaModel})`
|
|
675
|
+
: { openai: "OpenAI", mistral: "Mistral", voyage: "Voyage AI" }[provider];
|
|
676
|
+
box([
|
|
677
|
+
`${B}Provider:${R} ${providerName}`,
|
|
678
|
+
`${B}Port:${R} ${String(mcpPort)}`,
|
|
679
|
+
...(pathsToIndex.length ? [`${B}Pre-index:${R} ${String(pathsToIndex.length + " directorie(s)")}`] : []),
|
|
680
|
+
`${B}Batch:${R} ${String(batchSize)}`,
|
|
681
|
+
`${B}Index docs:${R} ${indexDocs ? "Yes (max " + docMaxFiles + " files)" : "No"}`,
|
|
682
|
+
`${B}API calls:${R} ${provider === "ollama" ? "None (runs locally)" : `To ${provider} API`}`,
|
|
683
|
+
`${B}Disk needed:${R} ${provider === "ollama" ? "~3GB" : "~1GB"}`,
|
|
684
|
+
]);
|
|
568
685
|
console.log("");
|
|
569
|
-
|
|
686
|
+
const proceed = await (() => {
|
|
687
|
+
const rl4 = createInterface({ input: process.stdin, output: process.stdout });
|
|
688
|
+
return ask(rl4, ` ${B}Proceed? [Y/n]${R} `).then((a) => { rl4.close(); return a; });
|
|
689
|
+
})();
|
|
690
|
+
if (proceed.toLowerCase() === "n") {
|
|
691
|
+
console.log("");
|
|
692
|
+
console.log(` Setup cancelled. Run ${B}npx yats-toolkit${R} anytime to try again.`);
|
|
693
|
+
console.log("");
|
|
694
|
+
process.exit(0);
|
|
695
|
+
}
|
|
570
696
|
}
|
|
571
697
|
|
|
572
698
|
// Install
|
|
@@ -645,9 +771,8 @@ async function main() {
|
|
|
645
771
|
console.log(` ✅ ${G}YATS is ready!${R}`);
|
|
646
772
|
divider();
|
|
647
773
|
console.log("");
|
|
648
|
-
console.log(` ${B}
|
|
774
|
+
console.log(` ${B}Next step — connect your AI agent:${R}`);
|
|
649
775
|
console.log("");
|
|
650
|
-
|
|
651
776
|
box([
|
|
652
777
|
`${B}For Cursor, Zed, Cline, Continue.dev, Roo Code:${R}`,
|
|
653
778
|
`{ "url": "http://localhost:${mcpPort}/mcp/sse" }`,
|
|
@@ -659,15 +784,14 @@ async function main() {
|
|
|
659
784
|
console.log(` Config saved to ${C}${MCP_CONFIG_FILE}${R}`);
|
|
660
785
|
divider();
|
|
661
786
|
console.log("");
|
|
662
|
-
console.log(` ${B}
|
|
787
|
+
console.log(` ${B}Try it now:${R}`);
|
|
663
788
|
console.log("");
|
|
664
|
-
console.log(`
|
|
665
|
-
console.log(`
|
|
789
|
+
console.log(` Open your project in your AI agent and ask:`);
|
|
790
|
+
console.log(` ${C}"how does authentication work in this project?"${R}`);
|
|
666
791
|
console.log("");
|
|
667
|
-
console.log(`
|
|
792
|
+
console.log(` YATS will auto-index on the first search.`);
|
|
668
793
|
console.log("");
|
|
669
794
|
console.log(` ${B}Commands:${R}`);
|
|
670
|
-
console.log(` yats add ~/work/project Add a repo to index`);
|
|
671
795
|
console.log(` yats status Check what's indexed`);
|
|
672
796
|
console.log(` yats clear <repo> Delete index by name`);
|
|
673
797
|
console.log(` yats remove <path> Delete index by path`);
|
|
@@ -675,6 +799,7 @@ async function main() {
|
|
|
675
799
|
console.log(` yats start Start all services`);
|
|
676
800
|
console.log(` yats update Update CLI to latest`);
|
|
677
801
|
console.log(` yats update-base Update Docker images`);
|
|
802
|
+
console.log(` yats connect Set up your AI agent`);
|
|
678
803
|
console.log("");
|
|
679
804
|
console.log(` Docs: ${C}https://yats.site${R}`);
|
|
680
805
|
console.log("");
|