yats-toolkit 0.3.0 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yats-toolkit",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
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/benchmark.js CHANGED
@@ -263,9 +263,11 @@ function loadEnvFile(filePath) {
263
263
 
264
264
  function loadEnv() {
265
265
  const candidates = [];
266
+ // Canonical: ~/.yats/.env (setup writes embedding + benchmark keys there)
267
+ candidates.push(path.join(process.env.HOME ?? "/tmp", ".yats", ".env"));
266
268
  candidates.push(path.join(process.cwd(), ".env"));
267
269
 
268
- // walk up from this module (src/) to find a repo-root .env
270
+ // walk up from this module (src/) to find a repo-root .env (legacy fallback)
269
271
  let dir = path.dirname(fileURLToPath(import.meta.url));
270
272
  for (let i = 0; i < 6; i++) {
271
273
  const p = path.join(dir, ".env");
@@ -275,16 +277,19 @@ function loadEnv() {
275
277
  dir = parent;
276
278
  }
277
279
 
280
+ // Load ALL candidates so keys accumulate (first one wins per key).
281
+ let loaded = null;
278
282
  for (const c of candidates) {
279
- if (loadEnvFile(c) > 0) return c;
283
+ if (loadEnvFile(c) > 0 && !loaded) loaded = c;
280
284
  }
281
- return null;
285
+ return loaded;
282
286
  }
283
287
 
284
288
  const LOADED_ENV = loadEnv();
285
289
  if (LOADED_ENV) logger.info(`Loaded ${LOADED_ENV}`);
286
290
 
287
291
  let selectedModel = null;
292
+ let copilotConsent = false;
288
293
  let workDir = path.join(process.cwd(), "repos");
289
294
 
290
295
  // ============================================================
@@ -384,7 +389,7 @@ const KNOWN_AGENTS = [
384
389
  { name: "sonnet", hint: "balanced" },
385
390
  { name: "opus", hint: "most powerful" },
386
391
  ],
387
- authLabel: "ANTHROPIC_API_KEY or `claude` login (~/.claude)",
392
+ authLabel: "ANTHROPIC_API_KEY (in ~/.yats/.env)",
388
393
  needsSkill: true,
389
394
  mcpKind: "stdio",
390
395
  runCmd: (prompt, repoDir, hasMcp, model) => [
@@ -401,14 +406,14 @@ const KNOWN_AGENTS = [
401
406
  cli: "codex",
402
407
  checkCmd: "which codex",
403
408
  installHint: "npm install -g @openai/codex",
404
- needsApiKey: "",
409
+ needsApiKey: "OPENAI_API_KEY",
405
410
  defaultModel: "gpt-4.1-mini",
406
411
  models: [
407
412
  { name: "gpt-4.1-mini", hint: "fastest & cheapest" },
408
413
  { name: "gpt-4.1", hint: "balanced" },
409
414
  { name: "gpt-5.4", hint: "most powerful" },
410
415
  ],
411
- authLabel: "codex login (~/.codex/auth.json)",
416
+ authLabel: "OPENAI_API_KEY (in ~/.yats/.env)",
412
417
  needsSkill: false,
413
418
  mcpKind: "codex-config",
414
419
  runCmd: (prompt, repoDir, hasMcp, model) => ["exec", "--json", "--skip-git-repo-check", "--dangerously-bypass-approvals-and-sandbox", prompt],
@@ -423,7 +428,7 @@ const KNOWN_AGENTS = [
423
428
  models: [
424
429
  { name: "default", hint: "Copilot-managed model" },
425
430
  ],
426
- authLabel: "copilot CLI login",
431
+ authLabel: "copilot auth (consent asked at start)",
427
432
  needsSkill: false,
428
433
  mcpKind: "copilot-config",
429
434
  runCmd: (prompt, repoDir, hasMcp, model) => [
@@ -466,7 +471,7 @@ const KNOWN_AGENTS = [
466
471
  { name: "gemini-2.5-pro", hint: "most powerful" },
467
472
  { name: "gemini-pro-latest", hint: "balanced" },
468
473
  ],
469
- authLabel: "GEMINI_API_KEY",
474
+ authLabel: "GEMINI_API_KEY (in ~/.yats/.env)",
470
475
  needsSkill: false,
471
476
  mcpKind: "gemini-config",
472
477
  runCmd: (prompt, repoDir, hasMcp, model) => [
@@ -483,12 +488,13 @@ const KNOWN_AGENTS = [
483
488
  // ============================================================
484
489
 
485
490
  async function selectAgent() {
486
- const opts = KNOWN_AGENTS.map((a) => ({
487
- label: a.name,
488
- hint: isInstalled(a.cli) ? "installed" : "not installed",
489
- ok: isInstalled(a.cli),
490
- value: a,
491
- }));
491
+ const opts = KNOWN_AGENTS.map((a) => {
492
+ const installed = isInstalled(a.cli);
493
+ const hasKey = !a.needsApiKey || hasApiKey(a.needsApiKey);
494
+ let hint = installed ? "installed" : "not installed";
495
+ if (installed && a.needsApiKey && !hasKey) hint = `missing ${a.needsApiKey} in ~/.yats/.env`;
496
+ return { label: a.name, hint, ok: installed && hasKey, value: a };
497
+ });
492
498
  return select("Select your AI agent", opts);
493
499
  }
494
500
 
@@ -760,12 +766,12 @@ function setupAgent(agent, repoPath, withYats) {
760
766
 
761
767
  case "copilot-config": { // Copilot
762
768
  process.env.COPILOT_HOME = home;
763
- // Copilot 1.x stores its auth metadata in ~/.copilot/config.json (the token
764
- // itself lives in the OS keyring). Copy it into the isolated home so auth
765
- // keeps working while we control the MCP config per run.
766
- const realConfig = path.join(os.homedir(), ".copilot", "config.json");
767
- if (fs.existsSync(realConfig)) {
768
- fs.copyFileSync(realConfig, path.join(home, "config.json"));
769
+ // Only copy the user's auth metadata if they explicitly consented in checkAgent().
770
+ if (copilotConsent) {
771
+ const realConfig = path.join(os.homedir(), ".copilot", "config.json");
772
+ if (fs.existsSync(realConfig)) {
773
+ fs.copyFileSync(realConfig, path.join(home, "config.json"));
774
+ }
769
775
  }
770
776
  if (withYats) {
771
777
  const bridge = path.join(BENCH_DIR, "adapters", "mcp-bridge-stdio.cjs");
@@ -825,7 +831,7 @@ function setupAgent(agent, repoPath, withYats) {
825
831
  }
826
832
  }
827
833
 
828
- function checkAgent(agent) {
834
+ async function checkAgent(agent) {
829
835
  console.log(`\n ${A.dim}Checking ${agent.name}...${A.reset}`);
830
836
  if (!isInstalled(agent.cli)) {
831
837
  console.log(` ${A.red}✖ ${agent.cli} is not installed.${A.reset}`);
@@ -833,10 +839,41 @@ function checkAgent(agent) {
833
839
  return false;
834
840
  }
835
841
  console.log(` ${A.green}✓${A.reset} ${agent.cli} found`);
836
- console.log(` ${A.dim}Auth: ${agent.authLabel}${A.reset}`);
837
- if (!hasApiKey(agent.needsApiKey)) {
838
- console.log(` ${A.yellow}⚠${A.reset} ${agent.needsApiKey} not set (agent may use its own auth)`);
842
+
843
+ // API-key agents (claude/codex/gemini) read keys from ~/.yats/.env
844
+ if (agent.needsApiKey) {
845
+ if (!hasApiKey(agent.needsApiKey)) {
846
+ console.log(` ${A.red}✖ ${agent.needsApiKey} not set.${A.reset}`);
847
+ console.log(` Add it to ${A.bold}~/.yats/.env${A.reset} to use ${agent.name}.`);
848
+ return false;
849
+ }
850
+ console.log(` ${A.green}✓${A.reset} ${agent.needsApiKey} found in ~/.yats/.env`);
851
+ return true;
839
852
  }
853
+
854
+ // copilot / cursor use their own OAuth login (no API key in .env)
855
+ if (agent.name === "copilot") {
856
+ const realConfig = path.join(os.homedir(), ".copilot", "config.json");
857
+ if (fs.existsSync(realConfig)) {
858
+ const use = await select("Copilot login", [
859
+ { label: "Use my existing Copilot login (copy ~/.copilot/config.json)", value: true },
860
+ { label: "No — cancel", value: false },
861
+ ]);
862
+ if (!use) {
863
+ console.log(` ${A.yellow}✖ Cancelled${A.reset}`);
864
+ return false;
865
+ }
866
+ copilotConsent = true;
867
+ console.log(` ${A.green}✓${A.reset} Will use your existing Copilot login`);
868
+ } else {
869
+ console.log(` ${A.red}✖ No ~/.copilot/config.json found.${A.reset}`);
870
+ console.log(` Run ${A.bold}copilot auth${A.reset} first.`);
871
+ return false;
872
+ }
873
+ return true;
874
+ }
875
+
876
+ console.log(` ${A.dim}Auth: ${agent.authLabel}${A.reset}`);
840
877
  return true;
841
878
  }
842
879
 
@@ -1357,7 +1394,7 @@ async function runOnce() {
1357
1394
 
1358
1395
  // 1. Agent
1359
1396
  const agent = await selectAgent();
1360
- if (!checkAgent(agent)) {
1397
+ if (!(await checkAgent(agent))) {
1361
1398
  restoreTerminal();
1362
1399
  process.exit(1);
1363
1400
  }
package/src/setup.js CHANGED
@@ -30,6 +30,7 @@ const REPOS_DIR = join(YATS_DIR, "repos");
30
30
  const COMPOSE_FILE = join(YATS_DIR, "docker-compose.yml");
31
31
  const MCP_CONFIG_FILE = join(YATS_DIR, "mcp-config.json");
32
32
  const YATS_BIN_DIR = join(YATS_DIR, "bin");
33
+ const ENV_FILE = join(YATS_DIR, ".env");
33
34
 
34
35
  const GITHUB_COMPOSE_URL =
35
36
  "https://raw.githubusercontent.com/fvinciarelli/yats.ai/main/docker/docker-compose.yml";
@@ -89,12 +90,12 @@ const EMBEDDED_COMPOSE = `services:
89
90
  - NEO4J_USER=neo4j
90
91
  - NEO4J_PASSWORD=\${NEO4J_PASSWORD:-password}
91
92
  - QDRANT_URL=http://qdrant:6333
92
- - EMBEDDING_PROVIDER=__PROVIDER__
93
+ - EMBEDDING_PROVIDER=\${EMBEDDING_PROVIDER:-ollama}
93
94
  - OLLAMA_URL=http://ollama:11434
94
95
  - OLLAMA_MODEL=__OLLAMA_MODEL__
95
- - OPENAI_API_KEY=__OPENAI_KEY__
96
- - MISTRAL_API_KEY=__MISTRAL_KEY__
97
- - VOYAGE_API_KEY=__VOYAGE_KEY__
96
+ - OPENAI_API_KEY=\${EMBEDDING_OPENAI_API_KEY:-}
97
+ - MISTRAL_API_KEY=\${EMBEDDING_MISTRAL_API_KEY:-}
98
+ - VOYAGE_API_KEY=\${EMBEDDING_VOYAGE_API_KEY:-}
98
99
  - REPOSITORIES_PATH=/repos
99
100
  - YATS_PORT=__MCP_PORT__
100
101
  - EMBEDDING_BATCH_SIZE=__BATCH_SIZE__
@@ -331,11 +332,7 @@ function generateCompose(provider, ollamaModel, apiKey, mcpPort, batchSize, inde
331
332
  }
332
333
 
333
334
  compose = compose
334
- .replace(/__PROVIDER__/g, provider)
335
335
  .replace(/__OLLAMA_MODEL__/g, ollamaModel)
336
- .replace(/__OPENAI_KEY__/g, provider === "openai" ? apiKey : "")
337
- .replace(/__MISTRAL_KEY__/g, provider === "mistral" ? apiKey : "")
338
- .replace(/__VOYAGE_KEY__/g, provider === "voyage" ? apiKey : "")
339
336
  .replace(/__MCP_PORT__/g, String(mcpPort))
340
337
  .replace(/__BATCH_SIZE__/g, String(batchSize))
341
338
  .replace(/__INDEX_DOCS__/g, indexDocs ? "true" : "false")
@@ -418,8 +415,8 @@ async function main(options = {}) {
418
415
  const env = loadEnv();
419
416
  const nonInteractive = options.nonInteractive || false;
420
417
  const prefill = {
421
- provider: options.provider || env.YATS_PROVIDER || null,
422
- apiKey: options.apiKey || env.OPENAI_API_KEY || env.MISTRAL_API_KEY || env.VOYAGE_API_KEY || null,
418
+ provider: options.provider || env.YATS_PROVIDER || env.EMBEDDING_PROVIDER || null,
419
+ apiKey: options.apiKey || env.EMBEDDING_OPENAI_API_KEY || env.EMBEDDING_MISTRAL_API_KEY || env.EMBEDDING_VOYAGE_API_KEY || null,
423
420
  port: options.port ? parseInt(options.port, 10) : null,
424
421
  batch: options.batch ? parseInt(options.batch, 10) : null,
425
422
  noDocs: options.noDocs || false,
@@ -713,6 +710,16 @@ async function main(options = {}) {
713
710
  const mcpConfig = { mcpServers: { yats: { url: `http://localhost:${mcpPort}/mcp/sse` } } };
714
711
  writeFileSync(MCP_CONFIG_FILE, JSON.stringify(mcpConfig, null, 2));
715
712
 
713
+ // Persist keys to ~/.yats/.env — canonical source (embedding + benchmark keys).
714
+ // Merge with any keys the user already added (e.g. ANTHROPIC_API_KEY, GEMINI_API_KEY).
715
+ const envMap = loadEnv();
716
+ envMap.EMBEDDING_PROVIDER = provider;
717
+ envMap.YATS_PROVIDER = provider;
718
+ if (provider === "openai" && apiKey) envMap.EMBEDDING_OPENAI_API_KEY = apiKey;
719
+ if (provider === "mistral" && apiKey) envMap.EMBEDDING_MISTRAL_API_KEY = apiKey;
720
+ if (provider === "voyage" && apiKey) envMap.EMBEDDING_VOYAGE_API_KEY = apiKey;
721
+ writeFileSync(ENV_FILE, Object.entries(envMap).map(([k, v]) => `${k}=${v}`).join("\n") + "\n");
722
+
716
723
  // Pull the YATS Docker image from GitHub Container Registry
717
724
  const sPull = spinner("Pulling YATS image from registry...");
718
725
  try {
@@ -827,6 +834,7 @@ async function main(options = {}) {
827
834
  console.log(` ✅ ${G}YATS is ready!${R} → ${C}http://localhost:${mcpPort}/mcp/sse${R}`);
828
835
  console.log("");
829
836
  console.log(` Config saved to ${C}~/.yats/.env${R}`);
837
+ console.log(` ${D}Benchmark agent keys (ANTHROPIC_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY) go there too.${R}`);
830
838
  console.log("");
831
839
  box([
832
840
  `${B}Copy this URL into your AI agent:${R}`,