yats-toolkit 0.1.22 → 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 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.1.22",
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 main() {
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
@@ -432,14 +482,19 @@ async function main() {
432
482
  }
433
483
 
434
484
  // Step 1: Embedding provider
435
- step("Step 1 — Embedding provider");
436
-
437
- const provider = await choose("How should I generate embeddings for your code?", [
438
- { label: "Ollama (local, private, included) — recommended", value: "ollama" },
439
- { label: "OpenAI (cloud, needs API key)", value: "openai" },
440
- { label: "Mistral (cloud, needs API key)", value: "mistral" },
441
- { label: "Voyage AI (cloud, optimized for code, needs API key)", value: "voyage" },
442
- ]);
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
+ }
443
498
 
444
499
  let apiKey = "";
445
500
  let ollamaModel = "nomic-embed-text";
@@ -453,104 +508,152 @@ async function main() {
453
508
  } else {
454
509
  const providerNames = { openai: "OpenAI", mistral: "Mistral", voyage: "Voyage AI" };
455
510
  step(`Step 2 — ${providerNames[provider]} API key`);
456
- const rl2 = createInterface({ input: process.stdin, output: process.stdout });
457
- apiKey = await ask(rl2, ` ${B}Your ${providerNames[provider]} API key:${R} `);
458
- rl2.close();
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
+
459
526
  console.log("");
460
527
  console.log(` ${Y}⚠${R} This is a paid service — you may be charged for API usage.`);
461
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
+ }
462
562
  console.log("");
463
563
  }
464
564
 
465
565
  // Step 3: Embedding batch size
466
- const BATCH_DEFAULTS = {
467
- openai: 200,
468
- mistral: 200,
469
- voyage: 100,
470
- ollama: 4,
471
- };
472
- const BATCH_MAX = {
473
- openai: 2048,
474
- mistral: 1024,
475
- voyage: 128,
476
- ollama: 4,
477
- };
478
- 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];
479
569
  const maxBatch = BATCH_MAX[provider];
480
-
481
- step(`Step 3 — Embedding batch size`);
482
- console.log(` ${D}How many texts to embed per API request.${R}`);
483
- console.log(` ${D}Higher = faster indexing, lower = safer for rate limits.${R}`);
484
- console.log(` ${D}Provider max: ${maxBatch}${R}`);
485
- console.log("");
486
-
487
- const rlBatch = createInterface({ input: process.stdin, output: process.stdout });
488
- const batchAnswer = await ask(rlBatch, ` ${B}Batch size${R} [${defaultBatch}]: `);
489
- rlBatch.close();
490
570
  let batchSize = defaultBatch;
491
- const batchTrimmed = batchAnswer.trim();
492
- if (batchTrimmed) {
493
- const num = parseInt(batchTrimmed, 10);
494
- if (num >= 1 && num <= maxBatch) {
495
- batchSize = num;
496
- } else {
497
- console.log(` ${Y}⚠${R} Must be 1–${maxBatch}. Using default ${defaultBatch}.`);
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}.`);
498
588
  }
589
+ console.log(` ${G}✓${R} Batch size: ${batchSize}`);
590
+ console.log("");
499
591
  }
500
- console.log(` ${G}✓${R} Batch size: ${batchSize}`);
501
- console.log("");
502
592
 
503
593
  // Step 4: Documentation indexing
504
594
  const docMaxFiles = 300;
505
- let indexDocs = true;
595
+ let indexDocs = !prefill.noDocs;
506
596
 
507
- step("Step 4 — Documentation indexing");
508
- console.log(` ${D}Index README, ARCHITECTURE, AI/ docs, and docs/ directory.${R}`);
509
- console.log(` ${D}Patterns (edit via DOC_PATTERNS env): AI/*.md, README.md, docs/${R}`);
510
- console.log(` ${D}If docs/ has >${docMaxFiles} .md files, you'll get a warning.${R}`);
511
- console.log("");
512
-
513
- const rlDocs = createInterface({ input: process.stdin, output: process.stdout });
514
- const docsAnswer = await ask(rlDocs, ` ${B}Index documentation? [Y/n]${R} `);
515
- rlDocs.close();
516
- if (docsAnswer.toLowerCase() === "n") {
517
- indexDocs = false;
518
- console.log(` ${Y}⚠${R} Documentation indexing disabled. Set INDEX_DOCS=true to re-enable.`);
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("");
519
613
  } else {
520
- console.log(` ${G}✓${R} Documentation will be indexed.`);
614
+ console.log(` Index docs: ${indexDocs ? "Yes" : "No"}`);
521
615
  }
522
- console.log("");
523
616
 
524
617
  // Optional: pre-index directories
525
- step("Step 5 — Pre-index (optional)");
526
- console.log(` ${D}Indexing happens automatically on first search.${R}`);
527
- console.log(` ${D}Want to pre-index some directories now to skip the wait later?${R}`);
528
- console.log("");
529
- console.log(` ${D}Tip: type a path or drag-n-drop a folder from your file manager.${R}`);
530
-
531
- const rl3 = createInterface({ input: process.stdin, output: process.stdout });
532
618
  const pathsToIndex = [];
533
- while (true) {
534
- const p = await ask(rl3, ` ${B}Directory path (Enter to skip):${R} `);
535
- const trimmed = p.trim();
536
- if (!trimmed) break;
537
- if (existsSync(trimmed)) {
538
- pathsToIndex.push(trimmed);
539
- console.log(` ${G}✓${R} Added: ${trimmed}`);
540
- } else {
541
- console.log(` ${RED}✗${R} Not found: ${trimmed}`);
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
+ }
542
645
  }
646
+ rl3.close();
543
647
  }
544
- rl3.close();
545
648
  console.log("");
546
649
 
547
650
  // Port selection
548
- let mcpPort = 5555;
549
- {
651
+ let mcpPort = prefill.port || 5555;
652
+ if (!nonInteractive) {
550
653
  const rlPort = createInterface({ input: process.stdin, output: process.stdout });
551
654
  const inUse = await checkPort(mcpPort);
552
- const suggested = inUse ? 5556 : mcpPort;
553
- const hint = inUse ? ` ${Y}(default 5555 is in use)${R}` : "";
655
+ const suggested = inUse ? (mcpPort + 1) : mcpPort;
656
+ const hint = inUse ? ` ${Y}(default ${mcpPort} is in use)${R}` : "";
554
657
  const answer = await ask(rlPort, ` ${B}MCP server port${R} [${suggested}]:${hint} `);
555
658
  const trimmed = answer.trim();
556
659
  if (trimmed) {
@@ -560,36 +663,36 @@ async function main() {
560
663
  mcpPort = suggested;
561
664
  }
562
665
  rlPort.close();
666
+ console.log(` ${G}✓${R} MCP server on ${C}http://localhost:${mcpPort}/mcp/sse${R}`);
667
+ console.log("");
563
668
  }
564
- console.log(` ${G}✓${R} MCP server on ${C}http://localhost:${mcpPort}/mcp/sse${R}`);
565
- console.log("");
566
-
567
- // Step 5: Confirm
568
- step(`Step ${pathsToIndex.length ? "6" : "5"} — Confirm`);
569
- const providerName = provider === "ollama"
570
- ? `Ollama (${ollamaModel})`
571
- : { openai: "OpenAI", mistral: "Mistral", voyage: "Voyage AI" }[provider];
572
-
573
- box([
574
- `${B}Provider:${R} ${providerName}`,
575
- `${B}Port:${R} ${String(mcpPort)}`,
576
- ...(pathsToIndex.length ? [`${B}Pre-index:${R} ${String(pathsToIndex.length + " directorie(s)")}`] : []),
577
- `${B}Batch:${R} ${String(batchSize)}`,
578
- `${B}Index docs:${R} ${indexDocs ? "Yes (max " + docMaxFiles + " files)" : "No"}`,
579
- `${B}API calls:${R} ${provider === "ollama" ? "None (runs locally)" : `To ${provider} API`}`,
580
- `${B}Disk needed:${R} ${provider === "ollama" ? "~3GB" : "~1GB"}`,
581
- ]);
582
- console.log("");
583
669
 
584
- const proceed = await (() => {
585
- const rl4 = createInterface({ input: process.stdin, output: process.stdout });
586
- return ask(rl4, ` ${B}Proceed? [Y/n]${R} `).then((a) => { rl4.close(); return a; });
587
- })();
588
- if (proceed.toLowerCase() === "n") {
589
- console.log("");
590
- 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
+ ]);
591
685
  console.log("");
592
- process.exit(0);
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
+ }
593
696
  }
594
697
 
595
698
  // Install
@@ -668,9 +771,8 @@ async function main() {
668
771
  console.log(` ✅ ${G}YATS is ready!${R}`);
669
772
  divider();
670
773
  console.log("");
671
- console.log(` ${B}MCP configuration for your AI agent:${R}`);
774
+ console.log(` ${B}Next step — connect your AI agent:${R}`);
672
775
  console.log("");
673
-
674
776
  box([
675
777
  `${B}For Cursor, Zed, Cline, Continue.dev, Roo Code:${R}`,
676
778
  `{ "url": "http://localhost:${mcpPort}/mcp/sse" }`,
@@ -682,15 +784,14 @@ async function main() {
682
784
  console.log(` Config saved to ${C}${MCP_CONFIG_FILE}${R}`);
683
785
  divider();
684
786
  console.log("");
685
- console.log(` ${B}How it works:${R}`);
787
+ console.log(` ${B}Try it now:${R}`);
686
788
  console.log("");
687
- console.log(` Just ask your AI agent about your code.`);
688
- console.log(` The index builds automatically on the first search.`);
789
+ console.log(` Open your project in your AI agent and ask:`);
790
+ console.log(` ${C}"how does authentication work in this project?"${R}`);
689
791
  console.log("");
690
- console.log(` Example: "${D}how does authentication work in my project?${R}"`);
792
+ console.log(` YATS will auto-index on the first search.`);
691
793
  console.log("");
692
794
  console.log(` ${B}Commands:${R}`);
693
- console.log(` yats add ~/work/project Add a repo to index`);
694
795
  console.log(` yats status Check what's indexed`);
695
796
  console.log(` yats clear <repo> Delete index by name`);
696
797
  console.log(` yats remove <path> Delete index by path`);
@@ -698,6 +799,7 @@ async function main() {
698
799
  console.log(` yats start Start all services`);
699
800
  console.log(` yats update Update CLI to latest`);
700
801
  console.log(` yats update-base Update Docker images`);
802
+ console.log(` yats connect Set up your AI agent`);
701
803
  console.log("");
702
804
  console.log(` Docs: ${C}https://yats.site${R}`);
703
805
  console.log("");