yats-toolkit 0.3.2 → 0.3.4
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/README.md +4 -3
- package/package.json +1 -1
- package/src/benchmark.js +219 -38
- package/src/setup.js +32 -8
package/README.md
CHANGED
|
@@ -126,7 +126,7 @@ See the [GitHub repository](https://github.com/fvinciarelli/yats.ai) for the ful
|
|
|
126
126
|
```bash
|
|
127
127
|
yats setup
|
|
128
128
|
```
|
|
129
|
-
Runs the one-time setup wizard. Detects if YATS is already running, asks for embedding provider (Ollama/OpenAI/Mistral/Voyage), API keys if needed, batch size, docs indexing preference, optional pre-index directories, and MCP port. Generates `~/.yats/docker-compose.yml` and starts all services.
|
|
129
|
+
Runs the one-time setup wizard. Detects if YATS is already running, asks for embedding provider (Ollama/OpenAI/Mistral/Voyage), API keys if needed, batch size, docs indexing preference, optional pre-index directories, and MCP port. Generates `~/.yats/docker-compose.yml`, writes `~/.yats/.env` (embedding keys plus empty `ANTHROPIC_API_KEY` / `OPENAI_API_KEY` / `GEMINI_API_KEY` / `DEEPSEEK_API_KEY` placeholders for `yats benchmark`), and starts all services.
|
|
130
130
|
|
|
131
131
|
```bash
|
|
132
132
|
yats index <path> [--skip-docs]
|
|
@@ -176,8 +176,9 @@ codebase questions with and without YATS. Supports Claude, Codex, Copilot, Gemin
|
|
|
176
176
|
and Cursor (CLI). Clones/indexes test repos and saves results with averages.
|
|
177
177
|
|
|
178
178
|
**Where your agent's keys come from** — the benchmark runs *your* agent, which uses
|
|
179
|
-
*your* credentials with its provider. It
|
|
180
|
-
|
|
179
|
+
*your* credentials with its provider. It loads `~/.yats/.env` (written by `yats setup`,
|
|
180
|
+
which pre-fills the agent key names) and any `.env` in the current dir or repo root;
|
|
181
|
+
shell env vars take precedence.
|
|
181
182
|
|
|
182
183
|
| Agent | Credential |
|
|
183
184
|
|---|---|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yats-toolkit",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
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
|
@@ -250,7 +250,7 @@ function loadEnvFile(filePath) {
|
|
|
250
250
|
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
251
251
|
value = value.slice(1, -1);
|
|
252
252
|
}
|
|
253
|
-
if (key && !(key in process.env)) {
|
|
253
|
+
if (key && value && !(key in process.env)) {
|
|
254
254
|
process.env[key] = value;
|
|
255
255
|
count++;
|
|
256
256
|
}
|
|
@@ -315,6 +315,128 @@ function readConnect(agentDir, file) {
|
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
+
// Inline per-agent instruction files (option A: aggressive "YATS first, max 3
|
|
319
|
+
// calls"). Kept inline so the benchmark is self-contained and reproducible when
|
|
320
|
+
// run from npm — no dependency on the repo's connect/ directory.
|
|
321
|
+
const CLAUDE_SKILL_MD = `---
|
|
322
|
+
name: yats
|
|
323
|
+
description: YATS has this codebase indexed in a knowledge graph. Use when asked about the code — how something works, architecture, call chains, where something is defined. Use YATS tools first before reading files.
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
# YATS Code Intelligence
|
|
327
|
+
|
|
328
|
+
This repo is indexed by YATS (mcp__yats__* tools). Every symbol, call, and relationship is in a knowledge graph.
|
|
329
|
+
|
|
330
|
+
## Golden rule
|
|
331
|
+
|
|
332
|
+
**YATS first, Read second.** MCP tools return results in milliseconds for ~100 tokens. Reading files costs thousands of tokens and takes seconds.
|
|
333
|
+
|
|
334
|
+
## Efficient workflow
|
|
335
|
+
|
|
336
|
+
1. \`search_code\` — natural language query about the code (ALWAYS start here)
|
|
337
|
+
2. \`find_symbol\` on top 2-3 hits to get exact locations
|
|
338
|
+
3. \`find_callers\` / \`find_callees\` on 1-2 key symbols to trace the flow
|
|
339
|
+
4. \`expand_graph\` on seeds to get the full subgraph in one call
|
|
340
|
+
5. Only then \`Read\` files at the exact lines YATS gave you
|
|
341
|
+
|
|
342
|
+
## Rules
|
|
343
|
+
|
|
344
|
+
- Max 3-5 YATS tool calls per task. Synthesize what you have.
|
|
345
|
+
- Never guess symbol names — always start with \`search_code\`.
|
|
346
|
+
- Prefer \`expand_graph\` over multiple individual \`find_symbol\` calls.
|
|
347
|
+
- If YATS returns empty, try a different query before falling back to file reads.
|
|
348
|
+
- Repository name is usually the directory name. Check \`list_repositories\` if unsure.
|
|
349
|
+
`;
|
|
350
|
+
|
|
351
|
+
const CODEX_AGENTS_MD = `# YATS Code Intelligence
|
|
352
|
+
|
|
353
|
+
This repository is indexed by YATS MCP. You have these tools:
|
|
354
|
+
\`search_code\`, \`find_symbol\`, \`find_callers\`, \`find_callees\`, \`expand_graph\`,
|
|
355
|
+
\`find_references\`, \`find_implementations\`, \`find_inheritors\`, \`find_routes\`,
|
|
356
|
+
\`repository_summary\`, \`architecture_summary\`, \`list_repositories\`.
|
|
357
|
+
|
|
358
|
+
## ⚠️ ABSOLUTE HARD LIMIT: 3 TOOL CALLS TOTAL
|
|
359
|
+
|
|
360
|
+
You are allowed **AT MOST 3 YATS tool calls** for this entire task. This is a hard budget, not a suggestion.
|
|
361
|
+
|
|
362
|
+
- After your 3rd call, you MUST write your final answer immediately.
|
|
363
|
+
- Do NOT call \`find_symbol\` separately for every symbol. \`expand_graph\` returns callers + callees + neighbors in ONE call.
|
|
364
|
+
- Do NOT re-run \`search_code\` with slightly different wording.
|
|
365
|
+
- Do NOT verify each result with another call. Trust the graph.
|
|
366
|
+
- Do NOT read source files with shell commands (\`head\`, \`cat\`, \`sed\`, \`rg\`, \`grep\`). YATS already has the symbols and relationships — use the YATS tools instead.
|
|
367
|
+
- Every extra call wastes tokens and fails this task.
|
|
368
|
+
|
|
369
|
+
## Workflow (exactly 3 calls, in this order)
|
|
370
|
+
|
|
371
|
+
1. \`search_code("<your question>", repository="__REPO_NAME__")\` — call 1
|
|
372
|
+
2. \`expand_graph([top 2 symbol ids], repository="__REPO_NAME__")\` — call 2 (full subgraph)
|
|
373
|
+
3. \`find_callers("<key symbol>", repository="__REPO_NAME__")\` — call 3 (only if you still need it)
|
|
374
|
+
4. STOP. Write the answer.
|
|
375
|
+
|
|
376
|
+
## Repository
|
|
377
|
+
|
|
378
|
+
Use \`repository="__REPO_NAME__"\` for every call. Do NOT call \`list_repositories\` — the repo name is already given.
|
|
379
|
+
`;
|
|
380
|
+
|
|
381
|
+
const COPILOT_INSTRUCTIONS_MD = `# YATS Code Intelligence
|
|
382
|
+
|
|
383
|
+
This repo is indexed by YATS MCP. You have tools: search_code, find_symbol, find_callers, find_callees, expand_graph, find_references, find_implementations, find_inheritors, find_routes, repository_summary, list_repositories.
|
|
384
|
+
|
|
385
|
+
## Rules
|
|
386
|
+
- YATS first, file reads second. YATS is ~100 tokens and instant.
|
|
387
|
+
- Max 3 YATS calls per task. After call 3, answer with what you have.
|
|
388
|
+
- Start with search_code, then find_symbol on top hits, then expand_graph.
|
|
389
|
+
- Do NOT invent answers — verify with YATS or read files.
|
|
390
|
+
`;
|
|
391
|
+
|
|
392
|
+
const CURSOR_RULES_MDC = `# YATS Code Intelligence
|
|
393
|
+
|
|
394
|
+
This repo is indexed by YATS. Use these MCP tools for code questions:
|
|
395
|
+
\`search_code\`, \`find_symbol\`, \`find_callers\`, \`find_callees\`, \`expand_graph\`,
|
|
396
|
+
\`find_references\`, \`find_implementations\`, \`find_inheritors\`, \`find_routes\`.
|
|
397
|
+
|
|
398
|
+
## Rules
|
|
399
|
+
|
|
400
|
+
- Start with \`search_code\` for any codebase question.
|
|
401
|
+
- Max 3 YATS calls per task. Synthesize, don't keep searching.
|
|
402
|
+
- YATS returns results in ms. File reads cost thousands of tokens.
|
|
403
|
+
- If unsure about repo name, call \`list_repositories\` first.
|
|
404
|
+
|
|
405
|
+
## Workflow
|
|
406
|
+
|
|
407
|
+
1. \`search_code("your question", repository="<name>")\`
|
|
408
|
+
2. \`find_symbol\` on top hits
|
|
409
|
+
3. \`expand_graph\` or \`find_callers\`/\`find_callees\` to trace flow
|
|
410
|
+
4. Read files only at exact lines from YATS results
|
|
411
|
+
`;
|
|
412
|
+
|
|
413
|
+
const GEMINI_MD = `# YATS Code Intelligence
|
|
414
|
+
|
|
415
|
+
This repository is indexed by YATS MCP. You have access to a knowledge graph.
|
|
416
|
+
|
|
417
|
+
## Tools available
|
|
418
|
+
\`search_code\`, \`find_symbol\`, \`find_callers\`, \`find_callees\`, \`expand_graph\`,
|
|
419
|
+
\`find_references\`, \`find_implementations\`, \`find_inheritors\`, \`find_routes\`,
|
|
420
|
+
\`repository_summary\`, \`architecture_summary\`, \`list_repositories\`.
|
|
421
|
+
|
|
422
|
+
## GOLDEN RULE: YATS first, files second
|
|
423
|
+
- YATS queries cost ~100 tokens, return in milliseconds.
|
|
424
|
+
- Reading files costs THOUSANDS of tokens.
|
|
425
|
+
- Always try \`search_code()\` BEFORE reading any file.
|
|
426
|
+
|
|
427
|
+
## Workflow (3 steps max)
|
|
428
|
+
1. \`search_code("your question", repository="<name>")\` — ALWAYS start here
|
|
429
|
+
2. \`find_symbol(name, repository="<name>")\` on top 2-3 hits
|
|
430
|
+
3. \`expand_graph([top1, top2], repository="<name>")\` — callers+callees in one call
|
|
431
|
+
4. Only then read files at exact lines from YATS
|
|
432
|
+
|
|
433
|
+
## Rules
|
|
434
|
+
- Max 3 YATS calls per task. Synthesize and answer.
|
|
435
|
+
- NEVER guess symbol names — always start with search_code.
|
|
436
|
+
- Prefer expand_graph over multiple find_symbol calls.
|
|
437
|
+
- Repository name is usually the directory name. Check list_repositories if unsure.
|
|
438
|
+
`;
|
|
439
|
+
|
|
318
440
|
// Private/unknown repos (the LLM has never seen them) — the real proof.
|
|
319
441
|
const UNKNOWN_REPOS = [
|
|
320
442
|
{
|
|
@@ -706,16 +828,8 @@ async function ensureIndexed(repo, repoPath) {
|
|
|
706
828
|
function writeSkill(repoPath, withYats) {
|
|
707
829
|
const skillDir = path.join(repoPath, ".claude", "skills", "yats");
|
|
708
830
|
if (withYats) {
|
|
709
|
-
const content = readConnect("claude", "SKILL.md") ?? `---
|
|
710
|
-
name: yats
|
|
711
|
-
description: YATS has this codebase indexed. Use when asked about the code.
|
|
712
|
-
---
|
|
713
|
-
|
|
714
|
-
# YATS Code Intelligence
|
|
715
|
-
Use YATS MCP tools first, file reads second.
|
|
716
|
-
`;
|
|
717
831
|
fs.mkdirSync(skillDir, { recursive: true });
|
|
718
|
-
fs.writeFileSync(path.join(skillDir, "SKILL.md"),
|
|
832
|
+
fs.writeFileSync(path.join(skillDir, "SKILL.md"), CLAUDE_SKILL_MD);
|
|
719
833
|
} else {
|
|
720
834
|
fs.rmSync(skillDir, { recursive: true, force: true });
|
|
721
835
|
}
|
|
@@ -756,8 +870,8 @@ function setupAgent(agent, repoPath, withYats) {
|
|
|
756
870
|
}
|
|
757
871
|
fs.writeFileSync(path.join(home, "config.toml"), config);
|
|
758
872
|
if (withYats) {
|
|
759
|
-
const
|
|
760
|
-
|
|
873
|
+
const content = CODEX_AGENTS_MD.replaceAll("__REPO_NAME__", path.basename(repoPath));
|
|
874
|
+
fs.writeFileSync(path.join(repoPath, "AGENTS.md"), content);
|
|
761
875
|
} else {
|
|
762
876
|
fs.rmSync(path.join(repoPath, "AGENTS.md"), { force: true });
|
|
763
877
|
}
|
|
@@ -779,12 +893,9 @@ function setupAgent(agent, repoPath, withYats) {
|
|
|
779
893
|
mcpServers: { yats: { type: "local", command: "node", args: [bridge, "--stdio"] } },
|
|
780
894
|
});
|
|
781
895
|
fs.writeFileSync("/tmp/copilot-mcp.json", mcp);
|
|
782
|
-
const
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
fs.mkdirSync(ghDir, { recursive: true });
|
|
786
|
-
fs.writeFileSync(path.join(ghDir, "copilot-instructions.md"), instr);
|
|
787
|
-
}
|
|
896
|
+
const ghDir = path.join(repoPath, ".github");
|
|
897
|
+
fs.mkdirSync(ghDir, { recursive: true });
|
|
898
|
+
fs.writeFileSync(path.join(ghDir, "copilot-instructions.md"), COPILOT_INSTRUCTIONS_MD);
|
|
788
899
|
} else {
|
|
789
900
|
fs.rmSync(path.join(repoPath, ".github", "copilot-instructions.md"), { force: true });
|
|
790
901
|
}
|
|
@@ -797,12 +908,9 @@ function setupAgent(agent, repoPath, withYats) {
|
|
|
797
908
|
?? JSON.stringify({ mcpServers: { yats: { url: "http://localhost:5555/mcp" } } });
|
|
798
909
|
fs.writeFileSync("/tmp/cursor-mcp.json", mcp);
|
|
799
910
|
process.env.CURSOR_MCP_CONFIG = "/tmp/cursor-mcp.json";
|
|
800
|
-
const
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
fs.mkdirSync(rulesDir, { recursive: true });
|
|
804
|
-
fs.writeFileSync(path.join(rulesDir, "yats.mdc"), rules);
|
|
805
|
-
}
|
|
911
|
+
const rulesDir = path.join(repoPath, ".cursor", "rules");
|
|
912
|
+
fs.mkdirSync(rulesDir, { recursive: true });
|
|
913
|
+
fs.writeFileSync(path.join(rulesDir, "yats.mdc"), CURSOR_RULES_MDC);
|
|
806
914
|
} else {
|
|
807
915
|
delete process.env.CURSOR_MCP_CONFIG;
|
|
808
916
|
fs.rmSync(path.join(repoPath, ".cursor", "rules", "yats.mdc"), { force: true });
|
|
@@ -820,8 +928,7 @@ function setupAgent(agent, repoPath, withYats) {
|
|
|
820
928
|
const settingsDir = path.join(home, ".gemini");
|
|
821
929
|
fs.mkdirSync(settingsDir, { recursive: true });
|
|
822
930
|
fs.writeFileSync(path.join(settingsDir, "settings.json"), mcp);
|
|
823
|
-
|
|
824
|
-
if (gmd) fs.writeFileSync(path.join(repoPath, "GEMINI.md"), gmd);
|
|
931
|
+
fs.writeFileSync(path.join(repoPath, "GEMINI.md"), GEMINI_MD);
|
|
825
932
|
} else {
|
|
826
933
|
fs.rmSync(path.join(home, ".gemini", "settings.json"), { force: true });
|
|
827
934
|
fs.rmSync(path.join(repoPath, "GEMINI.md"), { force: true });
|
|
@@ -912,6 +1019,8 @@ function tailAgentActivity(logFile) {
|
|
|
912
1019
|
e.tool_call?.name ||
|
|
913
1020
|
e.tool_use?.name ||
|
|
914
1021
|
e.tool?.name ||
|
|
1022
|
+
e.item?.name ||
|
|
1023
|
+
e.item?.tool ||
|
|
915
1024
|
(Array.isArray(e.message?.content) &&
|
|
916
1025
|
e.message.content.find((c) => c && c.type === "tool_use")?.name);
|
|
917
1026
|
return typeof name === "string" && name ? name : null;
|
|
@@ -923,7 +1032,8 @@ function tailAgentActivity(logFile) {
|
|
|
923
1032
|
if (!name) continue;
|
|
924
1033
|
const e = events[i];
|
|
925
1034
|
const input =
|
|
926
|
-
e.input || e.arguments || e.
|
|
1035
|
+
e.input || e.arguments || e.item?.input || e.item?.arguments ||
|
|
1036
|
+
e.tool_call?.input || e.tool_call?.arguments ||
|
|
927
1037
|
e.tool_use?.input ||
|
|
928
1038
|
(Array.isArray(e.message?.content) &&
|
|
929
1039
|
e.message.content.find((c) => c && c.type === "tool_use")?.input);
|
|
@@ -954,23 +1064,42 @@ async function runWithSpinner(label, fn) {
|
|
|
954
1064
|
const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
955
1065
|
let i = 0;
|
|
956
1066
|
const start = Date.now();
|
|
957
|
-
const
|
|
1067
|
+
const width = Math.max(20, (process.stdout.columns || 80) - 1);
|
|
1068
|
+
const strip = (s) => s.replace(/\x1b\[[0-9;]*m/g, "");
|
|
1069
|
+
const draw = () => {
|
|
958
1070
|
const secs = Math.floor((Date.now() - start) / 1000);
|
|
959
|
-
|
|
1071
|
+
const prefix = ` ${A.cyan}${frames[i % frames.length]}${A.reset} ${A.dim}${label}${A.reset} ${A.gray}${secs}s${A.reset} ${A.dim}`;
|
|
1072
|
+
const suffix = `${A.reset}`;
|
|
1073
|
+
const budget = Math.max(0, width - strip(prefix).length - strip(suffix).length);
|
|
1074
|
+
const activity = agentActivity.length > budget
|
|
1075
|
+
? agentActivity.slice(0, Math.max(0, budget - 1)) + "…"
|
|
1076
|
+
: agentActivity;
|
|
1077
|
+
const line = prefix + activity + suffix;
|
|
1078
|
+
const visible = strip(line).length;
|
|
1079
|
+
readline.cursorTo(process.stdout, 0);
|
|
1080
|
+
readline.clearLine(process.stdout, 0);
|
|
1081
|
+
process.stdout.write(line + (visible < width ? " ".repeat(width - visible) : ""));
|
|
960
1082
|
i++;
|
|
961
|
-
}
|
|
1083
|
+
};
|
|
1084
|
+
draw();
|
|
1085
|
+
const id = setInterval(draw, 80);
|
|
962
1086
|
try {
|
|
963
1087
|
return await fn();
|
|
964
1088
|
} finally {
|
|
965
1089
|
clearInterval(id);
|
|
966
|
-
process.stdout
|
|
1090
|
+
readline.cursorTo(process.stdout, 0);
|
|
1091
|
+
readline.clearLine(process.stdout, 0);
|
|
967
1092
|
}
|
|
968
1093
|
}
|
|
969
1094
|
|
|
970
1095
|
function runAgent(agent, prompt, repoPath, withYats, logFile, timeoutSec = 600) {
|
|
971
1096
|
const model = selectedModel ?? agent.defaultModel;
|
|
972
|
-
|
|
973
|
-
|
|
1097
|
+
// Claude: raw question (end-user behavior). Other agents keep the neutral
|
|
1098
|
+
// "do not modify files" guard.
|
|
1099
|
+
const wrapped = agent.name === "claude"
|
|
1100
|
+
? prompt
|
|
1101
|
+
: `Do NOT create, write, edit, or delete any files, and do not run commands that modify the repository.\n\nQuestion:\n${prompt}`;
|
|
1102
|
+
const args = agent.runCmd(wrapped, repoPath, withYats, model);
|
|
974
1103
|
|
|
975
1104
|
return new Promise((resolve) => {
|
|
976
1105
|
const proc = spawn(agent.cli, args, {
|
|
@@ -998,7 +1127,52 @@ function runAgent(agent, prompt, repoPath, withYats, logFile, timeoutSec = 600)
|
|
|
998
1127
|
// Parse results
|
|
999
1128
|
// ============================================================
|
|
1000
1129
|
|
|
1001
|
-
function
|
|
1130
|
+
export function extractAnswer(events, agentName) {
|
|
1131
|
+
const parts = [];
|
|
1132
|
+
const push = (s) => { if (typeof s === "string" && s.trim()) parts.push(s.trim()); };
|
|
1133
|
+
|
|
1134
|
+
if (agentName === "codex") {
|
|
1135
|
+
for (const e of events) {
|
|
1136
|
+
if (e.type === "item.completed" && e.item?.type === "agent_message") push(e.item.text);
|
|
1137
|
+
}
|
|
1138
|
+
} else if (agentName === "claude" || agentName === "cursor") {
|
|
1139
|
+
for (const e of events) {
|
|
1140
|
+
if (e.type === "assistant" && Array.isArray(e.message?.content)) {
|
|
1141
|
+
for (const c of e.message.content) if (c?.type === "text") push(c.text);
|
|
1142
|
+
} else if (e.type === "stream_event" && e.event?.type === "content_block_delta" && e.event.delta?.type === "text_delta") {
|
|
1143
|
+
push(e.event.delta.text);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
} else if (agentName === "gemini") {
|
|
1147
|
+
for (const e of events) {
|
|
1148
|
+
if (e.type === "message" && e.role === "assistant") {
|
|
1149
|
+
if (typeof e.content === "string") push(e.content);
|
|
1150
|
+
else if (Array.isArray(e.content)) for (const c of e.content) push(typeof c === "string" ? c : c?.text);
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
} else if (agentName === "copilot") {
|
|
1154
|
+
for (const e of events) {
|
|
1155
|
+
if (e.type === "assistant.message") {
|
|
1156
|
+
const c = e.data?.content ?? e.content;
|
|
1157
|
+
if (typeof c === "string") push(c);
|
|
1158
|
+
else if (Array.isArray(c)) for (const b of c) push(typeof b === "string" ? b : b?.text);
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
return parts.join("\n\n");
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
function printAnswerPreview(answer, max = 600) {
|
|
1167
|
+
if (!answer) return;
|
|
1168
|
+
const text = answer.length > max ? answer.slice(0, max).replace(/\n+$/, "") + "\n …" : answer;
|
|
1169
|
+
console.log(` ${A.dim}— answer —${A.reset}`);
|
|
1170
|
+
for (const line of text.split("\n")) {
|
|
1171
|
+
console.log(` ${A.dim}${line}${A.reset}`);
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
function parseResult(logFile, agentName) {
|
|
1002
1176
|
try {
|
|
1003
1177
|
const content = fs.readFileSync(logFile, "utf-8");
|
|
1004
1178
|
const events = [];
|
|
@@ -1152,6 +1326,7 @@ function parseResult(logFile) {
|
|
|
1152
1326
|
return {
|
|
1153
1327
|
tokens, cost, outputTokens, cacheRead, cacheWrite, toolCalls,
|
|
1154
1328
|
fileReads, bashCmds, yatsQueries, contentChars, nanoAiu, duration,
|
|
1329
|
+
answer: extractAnswer(events, agentName),
|
|
1155
1330
|
error: errorMsg, logFile,
|
|
1156
1331
|
};
|
|
1157
1332
|
} catch (err) {
|
|
@@ -1440,7 +1615,7 @@ async function runOnce() {
|
|
|
1440
1615
|
await runWithSpinner(`Baseline ${i}/${numRuns} — ${agent.name} is reading files to answer`, () =>
|
|
1441
1616
|
runAgent(agent, question, repoPath, false, logFile));
|
|
1442
1617
|
const elapsedMs = Date.now() - t0;
|
|
1443
|
-
const result = parseResult(logFile);
|
|
1618
|
+
const result = parseResult(logFile, agent.name);
|
|
1444
1619
|
baselineResults.push({
|
|
1445
1620
|
run: i, withYats: false,
|
|
1446
1621
|
tokens: result.tokens ?? 0, cost: result.cost ?? 0,
|
|
@@ -1449,12 +1624,13 @@ async function runOnce() {
|
|
|
1449
1624
|
toolCalls: result.toolCalls ?? {},
|
|
1450
1625
|
fileReads: result.fileReads ?? 0, bashCmds: result.bashCmds ?? 0,
|
|
1451
1626
|
yatsQueries: result.yatsQueries ?? 0, contentChars: result.contentChars ?? 0,
|
|
1452
|
-
nanoAiu: result.nanoAiu ?? 0,
|
|
1627
|
+
nanoAiu: result.nanoAiu ?? 0, answer: result.answer ?? "",
|
|
1453
1628
|
duration: elapsedMs, error: result.error, logFile,
|
|
1454
1629
|
});
|
|
1455
1630
|
const r = baselineResults[baselineResults.length - 1];
|
|
1456
1631
|
if (r.error) console.log(` ${A.red}✖ ${r.error}${A.reset}`);
|
|
1457
1632
|
else console.log(` ${A.green}✓${A.reset} ${r.tokens.toLocaleString()} tokens${r.nanoAiu ? `, ${(r.nanoAiu / 1e9).toFixed(3)} AIU` : ""}, $${r.cost.toFixed(4)}, ${r.fileReads} reads, ${r.bashCmds} bash, ${fmtDuration(elapsedMs)}`);
|
|
1633
|
+
printAnswerPreview(r.answer);
|
|
1458
1634
|
}
|
|
1459
1635
|
|
|
1460
1636
|
// 6.5 — Ask before continuing to the with-YATS runs
|
|
@@ -1478,7 +1654,7 @@ async function runOnce() {
|
|
|
1478
1654
|
await runWithSpinner(`With YATS ${i}/${numRuns} — ${agent.name} is querying the knowledge graph`, () =>
|
|
1479
1655
|
runAgent(agent, question, repoPath, true, logFile));
|
|
1480
1656
|
const elapsedMs = Date.now() - t0;
|
|
1481
|
-
const result = parseResult(logFile);
|
|
1657
|
+
const result = parseResult(logFile, agent.name);
|
|
1482
1658
|
yatsResults.push({
|
|
1483
1659
|
run: i, withYats: true,
|
|
1484
1660
|
tokens: result.tokens ?? 0, cost: result.cost ?? 0,
|
|
@@ -1487,12 +1663,13 @@ async function runOnce() {
|
|
|
1487
1663
|
toolCalls: result.toolCalls ?? {},
|
|
1488
1664
|
fileReads: result.fileReads ?? 0, bashCmds: result.bashCmds ?? 0,
|
|
1489
1665
|
yatsQueries: result.yatsQueries ?? 0, contentChars: result.contentChars ?? 0,
|
|
1490
|
-
nanoAiu: result.nanoAiu ?? 0,
|
|
1666
|
+
nanoAiu: result.nanoAiu ?? 0, answer: result.answer ?? "",
|
|
1491
1667
|
duration: elapsedMs, error: result.error, logFile,
|
|
1492
1668
|
});
|
|
1493
1669
|
const r = yatsResults[yatsResults.length - 1];
|
|
1494
1670
|
if (r.error) console.log(` ${A.red}✖ ${r.error}${A.reset}`);
|
|
1495
1671
|
else console.log(` ${A.green}✓${A.reset} ${r.tokens.toLocaleString()} tokens${r.nanoAiu ? `, ${(r.nanoAiu / 1e9).toFixed(3)} AIU` : ""}, $${r.cost.toFixed(4)}, ${r.yatsQueries} yats, ${r.fileReads} reads, ${fmtDuration(elapsedMs)}`);
|
|
1672
|
+
printAnswerPreview(r.answer);
|
|
1496
1673
|
}
|
|
1497
1674
|
|
|
1498
1675
|
// 8. Results
|
|
@@ -1554,6 +1731,10 @@ async function runOnce() {
|
|
|
1554
1731
|
};
|
|
1555
1732
|
entry.savings_pct = tB > 0 ? Math.round(((tB - tY) / tB * 100) * 10) / 10 : null;
|
|
1556
1733
|
}
|
|
1734
|
+
entry.answers = {
|
|
1735
|
+
without: baselineResults.filter((r) => !r.error).map((r) => r.answer || "").join("\n\n---\n\n"),
|
|
1736
|
+
with: yatsResults.filter((r) => !r.error).map((r) => r.answer || "").join("\n\n---\n\n"),
|
|
1737
|
+
};
|
|
1557
1738
|
saveResult(entry);
|
|
1558
1739
|
|
|
1559
1740
|
console.log(`\n ${A.dim}Logs saved to: ${resultsDir}${A.reset}\n`);
|
package/src/setup.js
CHANGED
|
@@ -32,6 +32,11 @@ const MCP_CONFIG_FILE = join(YATS_DIR, "mcp-config.json");
|
|
|
32
32
|
const YATS_BIN_DIR = join(YATS_DIR, "bin");
|
|
33
33
|
const ENV_FILE = join(YATS_DIR, ".env");
|
|
34
34
|
|
|
35
|
+
// User-configurable documentation extensions (overridable via ~/.yats/.env)
|
|
36
|
+
const DEFAULT_DOC_EXTENSIONS = ".md,.mdx,.rst,.txt,.adoc,.org,.wiki,.readme";
|
|
37
|
+
const DEFAULT_SKIP_EXTENSIONS = ".exe,.dll,.so,.o,.a,.bin,.zip,.tar,.gz,.bz2,.xz,.7z,.rar,.png,.jpg,.jpeg,.gif,.ico,.webp,.bmp,.svg,.woff,.woff2,.ttf,.eot,.otf,.mp3,.mp4,.avi,.mov,.mkv,.flv,.wmv,.webm,.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.lock,.log,.map,.min.js,.min.css";
|
|
38
|
+
const DEFAULT_IGNORED_DIRS = "node_modules,.git,dist,build,.next,__pycache__,vendor,target,bin,obj,.venv,venv,.yarn,.pnpm";
|
|
39
|
+
|
|
35
40
|
const GITHUB_COMPOSE_URL =
|
|
36
41
|
"https://raw.githubusercontent.com/fvinciarelli/yats.ai/main/docker/docker-compose.yml";
|
|
37
42
|
|
|
@@ -131,6 +136,9 @@ const EMBEDDED_COMPOSE = `services:
|
|
|
131
136
|
- EMBEDDING_BATCH_SIZE=__BATCH_SIZE__
|
|
132
137
|
- INDEX_DOCS=__INDEX_DOCS__
|
|
133
138
|
- DOC_MAX_FILES=__DOC_MAX__
|
|
139
|
+
- DOC_EXTENSIONS=\${DOC_EXTENSIONS:-__DOC_EXTENSIONS__}
|
|
140
|
+
- SKIP_EXTENSIONS=\${SKIP_EXTENSIONS:-__SKIP_EXTENSIONS__}
|
|
141
|
+
- IGNORED_DIRS=\${IGNORED_DIRS:-__IGNORED_DIRS__}
|
|
134
142
|
- LOG_LEVEL=info
|
|
135
143
|
volumes:
|
|
136
144
|
- \${REPOS_PATH:-~/.yats/repos}:/repos:ro
|
|
@@ -366,6 +374,9 @@ function generateCompose(provider, mcpPort, batchSize, indexDocs, docMaxFiles) {
|
|
|
366
374
|
.replace(/__BATCH_SIZE__/g, String(batchSize))
|
|
367
375
|
.replace(/__INDEX_DOCS__/g, indexDocs ? "true" : "false")
|
|
368
376
|
.replace(/__DOC_MAX__/g, String(docMaxFiles))
|
|
377
|
+
.replace(/__DOC_EXTENSIONS__/g, DEFAULT_DOC_EXTENSIONS)
|
|
378
|
+
.replace(/__SKIP_EXTENSIONS__/g, DEFAULT_SKIP_EXTENSIONS)
|
|
379
|
+
.replace(/__IGNORED_DIRS__/g, DEFAULT_IGNORED_DIRS)
|
|
369
380
|
|
|
370
381
|
return compose;
|
|
371
382
|
}
|
|
@@ -416,6 +427,26 @@ async function loadEnv() {
|
|
|
416
427
|
return env;
|
|
417
428
|
}
|
|
418
429
|
|
|
430
|
+
// Merge embedding + benchmark keys into the env map before writing ~/.yats/.env.
|
|
431
|
+
// Benchmark agent keys are added empty (if missing) so users see exactly what to
|
|
432
|
+
// fill in for `yats benchmark`; any existing values are preserved.
|
|
433
|
+
export function applyEnvKeys(envMap, { provider, apiKey, model }) {
|
|
434
|
+
envMap.EMBEDDING_PROVIDER = provider;
|
|
435
|
+
envMap.YATS_PROVIDER = provider;
|
|
436
|
+
if (provider === "openai" && apiKey) envMap.EMBEDDING_OPENAI_API_KEY = apiKey;
|
|
437
|
+
if (provider === "mistral" && apiKey) envMap.EMBEDDING_MISTRAL_API_KEY = apiKey;
|
|
438
|
+
if (provider === "voyage" && apiKey) envMap.EMBEDDING_VOYAGE_API_KEY = apiKey;
|
|
439
|
+
const modelVar = { openai: "EMBEDDING_OPENAI_MODEL", mistral: "EMBEDDING_MISTRAL_MODEL", voyage: "EMBEDDING_VOYAGE_MODEL", ollama: "EMBEDDING_OLLAMA_MODEL" }[provider];
|
|
440
|
+
if (model && modelVar) envMap[modelVar] = model;
|
|
441
|
+
for (const k of ["ANTHROPIC_API_KEY", "OPENAI_API_KEY", "GEMINI_API_KEY", "DEEPSEEK_API_KEY"]) {
|
|
442
|
+
if (!(k in envMap)) envMap[k] = "";
|
|
443
|
+
}
|
|
444
|
+
if (!envMap.DOC_EXTENSIONS) envMap.DOC_EXTENSIONS = DEFAULT_DOC_EXTENSIONS;
|
|
445
|
+
if (!envMap.SKIP_EXTENSIONS) envMap.SKIP_EXTENSIONS = DEFAULT_SKIP_EXTENSIONS;
|
|
446
|
+
if (!envMap.IGNORED_DIRS) envMap.IGNORED_DIRS = DEFAULT_IGNORED_DIRS;
|
|
447
|
+
return envMap;
|
|
448
|
+
}
|
|
449
|
+
|
|
419
450
|
async function testApiConnection(provider, apiKey) {
|
|
420
451
|
const endpoints = {
|
|
421
452
|
openai: { url: "https://api.openai.com/v1/embeddings", key: apiKey, body: { model: "text-embedding-3-small", input: ["test"] } },
|
|
@@ -743,15 +774,8 @@ async function main(options = {}) {
|
|
|
743
774
|
writeFileSync(MCP_CONFIG_FILE, JSON.stringify(mcpConfig, null, 2));
|
|
744
775
|
|
|
745
776
|
// Persist keys to ~/.yats/.env — canonical source (embedding + benchmark keys).
|
|
746
|
-
// Merge with any keys the user already added (e.g. ANTHROPIC_API_KEY, GEMINI_API_KEY).
|
|
747
777
|
const envMap = loadEnv();
|
|
748
|
-
envMap
|
|
749
|
-
envMap.YATS_PROVIDER = provider;
|
|
750
|
-
if (provider === "openai" && apiKey) envMap.EMBEDDING_OPENAI_API_KEY = apiKey;
|
|
751
|
-
if (provider === "mistral" && apiKey) envMap.EMBEDDING_MISTRAL_API_KEY = apiKey;
|
|
752
|
-
if (provider === "voyage" && apiKey) envMap.EMBEDDING_VOYAGE_API_KEY = apiKey;
|
|
753
|
-
const modelVar = { openai: "EMBEDDING_OPENAI_MODEL", mistral: "EMBEDDING_MISTRAL_MODEL", voyage: "EMBEDDING_VOYAGE_MODEL", ollama: "EMBEDDING_OLLAMA_MODEL" }[provider];
|
|
754
|
-
if (model && modelVar) envMap[modelVar] = model;
|
|
778
|
+
applyEnvKeys(envMap, { provider, apiKey, model });
|
|
755
779
|
writeFileSync(ENV_FILE, Object.entries(envMap).map(([k, v]) => `${k}=${v}`).join("\n") + "\n");
|
|
756
780
|
|
|
757
781
|
// Pull the YATS Docker image from GitHub Container Registry
|