yats-toolkit 0.3.3 → 0.4.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/README.md +2 -2
- package/bin/setup.js +1 -1
- package/package.json +1 -1
- package/src/benchmark.js +220 -40
- package/src/indexer.js +17 -0
- package/src/setup.js +14 -0
- package/src/watch.js +104 -100
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ yats index ~/work/frontend
|
|
|
56
56
|
```
|
|
57
57
|
"index /home/user/my-project"
|
|
58
58
|
```
|
|
59
|
-
The agent
|
|
59
|
+
The agent runs `yats index` on your machine (the only way to index — the server never walks your filesystem) and then polls `repository_summary` until complete.
|
|
60
60
|
|
|
61
61
|
## MCP Configuration
|
|
62
62
|
|
|
@@ -89,7 +89,7 @@ Add this to your AI agent's MCP config:
|
|
|
89
89
|
| Inheritance | `find_implementations`, `find_inheritors` |
|
|
90
90
|
| Graph | `expand_graph`, `related_symbols` |
|
|
91
91
|
| Discovery | `list_symbols`, `find_routes`, `find_configuration`, `find_tests` |
|
|
92
|
-
| Repository | `list_repositories`, `
|
|
92
|
+
| Repository | `list_repositories`, `delete_repository` |
|
|
93
93
|
| Analysis | `repository_summary`, `architecture_summary` |
|
|
94
94
|
|
|
95
95
|
## Commands
|
package/bin/setup.js
CHANGED
|
@@ -90,7 +90,7 @@ switch (cmd) {
|
|
|
90
90
|
import("../src/benchmark.js").then(m => m.runBenchmark());
|
|
91
91
|
break;
|
|
92
92
|
case "watch":
|
|
93
|
-
import("../src/watch.js");
|
|
93
|
+
import("../src/watch.js").then(m => m.default(args));
|
|
94
94
|
break;
|
|
95
95
|
case "connect":
|
|
96
96
|
import("../src/connect.js").then(m => m.default(args));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yats-toolkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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/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 = [];
|
|
@@ -1127,8 +1301,7 @@ function parseResult(logFile) {
|
|
|
1127
1301
|
"find_implementations", "find_inheritors", "find_tests",
|
|
1128
1302
|
"find_routes", "find_configuration", "expand_graph", "related_symbols",
|
|
1129
1303
|
"list_symbols", "list_repositories", "repository_summary",
|
|
1130
|
-
"architecture_summary", "
|
|
1131
|
-
"reindex", "index_file", "remove_file",
|
|
1304
|
+
"architecture_summary", "delete_repository",
|
|
1132
1305
|
]);
|
|
1133
1306
|
const yatsQueries = Object.entries(toolCalls)
|
|
1134
1307
|
.filter(([k]) => /yats|mcp__/i.test(k) || YATS_TOOLS.has(k))
|
|
@@ -1152,6 +1325,7 @@ function parseResult(logFile) {
|
|
|
1152
1325
|
return {
|
|
1153
1326
|
tokens, cost, outputTokens, cacheRead, cacheWrite, toolCalls,
|
|
1154
1327
|
fileReads, bashCmds, yatsQueries, contentChars, nanoAiu, duration,
|
|
1328
|
+
answer: extractAnswer(events, agentName),
|
|
1155
1329
|
error: errorMsg, logFile,
|
|
1156
1330
|
};
|
|
1157
1331
|
} catch (err) {
|
|
@@ -1440,7 +1614,7 @@ async function runOnce() {
|
|
|
1440
1614
|
await runWithSpinner(`Baseline ${i}/${numRuns} — ${agent.name} is reading files to answer`, () =>
|
|
1441
1615
|
runAgent(agent, question, repoPath, false, logFile));
|
|
1442
1616
|
const elapsedMs = Date.now() - t0;
|
|
1443
|
-
const result = parseResult(logFile);
|
|
1617
|
+
const result = parseResult(logFile, agent.name);
|
|
1444
1618
|
baselineResults.push({
|
|
1445
1619
|
run: i, withYats: false,
|
|
1446
1620
|
tokens: result.tokens ?? 0, cost: result.cost ?? 0,
|
|
@@ -1449,12 +1623,13 @@ async function runOnce() {
|
|
|
1449
1623
|
toolCalls: result.toolCalls ?? {},
|
|
1450
1624
|
fileReads: result.fileReads ?? 0, bashCmds: result.bashCmds ?? 0,
|
|
1451
1625
|
yatsQueries: result.yatsQueries ?? 0, contentChars: result.contentChars ?? 0,
|
|
1452
|
-
nanoAiu: result.nanoAiu ?? 0,
|
|
1626
|
+
nanoAiu: result.nanoAiu ?? 0, answer: result.answer ?? "",
|
|
1453
1627
|
duration: elapsedMs, error: result.error, logFile,
|
|
1454
1628
|
});
|
|
1455
1629
|
const r = baselineResults[baselineResults.length - 1];
|
|
1456
1630
|
if (r.error) console.log(` ${A.red}✖ ${r.error}${A.reset}`);
|
|
1457
1631
|
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)}`);
|
|
1632
|
+
printAnswerPreview(r.answer);
|
|
1458
1633
|
}
|
|
1459
1634
|
|
|
1460
1635
|
// 6.5 — Ask before continuing to the with-YATS runs
|
|
@@ -1478,7 +1653,7 @@ async function runOnce() {
|
|
|
1478
1653
|
await runWithSpinner(`With YATS ${i}/${numRuns} — ${agent.name} is querying the knowledge graph`, () =>
|
|
1479
1654
|
runAgent(agent, question, repoPath, true, logFile));
|
|
1480
1655
|
const elapsedMs = Date.now() - t0;
|
|
1481
|
-
const result = parseResult(logFile);
|
|
1656
|
+
const result = parseResult(logFile, agent.name);
|
|
1482
1657
|
yatsResults.push({
|
|
1483
1658
|
run: i, withYats: true,
|
|
1484
1659
|
tokens: result.tokens ?? 0, cost: result.cost ?? 0,
|
|
@@ -1487,12 +1662,13 @@ async function runOnce() {
|
|
|
1487
1662
|
toolCalls: result.toolCalls ?? {},
|
|
1488
1663
|
fileReads: result.fileReads ?? 0, bashCmds: result.bashCmds ?? 0,
|
|
1489
1664
|
yatsQueries: result.yatsQueries ?? 0, contentChars: result.contentChars ?? 0,
|
|
1490
|
-
nanoAiu: result.nanoAiu ?? 0,
|
|
1665
|
+
nanoAiu: result.nanoAiu ?? 0, answer: result.answer ?? "",
|
|
1491
1666
|
duration: elapsedMs, error: result.error, logFile,
|
|
1492
1667
|
});
|
|
1493
1668
|
const r = yatsResults[yatsResults.length - 1];
|
|
1494
1669
|
if (r.error) console.log(` ${A.red}✖ ${r.error}${A.reset}`);
|
|
1495
1670
|
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)}`);
|
|
1671
|
+
printAnswerPreview(r.answer);
|
|
1496
1672
|
}
|
|
1497
1673
|
|
|
1498
1674
|
// 8. Results
|
|
@@ -1554,6 +1730,10 @@ async function runOnce() {
|
|
|
1554
1730
|
};
|
|
1555
1731
|
entry.savings_pct = tB > 0 ? Math.round(((tB - tY) / tB * 100) * 10) / 10 : null;
|
|
1556
1732
|
}
|
|
1733
|
+
entry.answers = {
|
|
1734
|
+
without: baselineResults.filter((r) => !r.error).map((r) => r.answer || "").join("\n\n---\n\n"),
|
|
1735
|
+
with: yatsResults.filter((r) => !r.error).map((r) => r.answer || "").join("\n\n---\n\n"),
|
|
1736
|
+
};
|
|
1557
1737
|
saveResult(entry);
|
|
1558
1738
|
|
|
1559
1739
|
console.log(`\n ${A.dim}Logs saved to: ${resultsDir}${A.reset}\n`);
|
package/src/indexer.js
CHANGED
|
@@ -96,5 +96,22 @@ export default async function indexRepo(args, options = {}) {
|
|
|
96
96
|
process.stdout.write(`\r ${sent + errors}/${total} files`);
|
|
97
97
|
}
|
|
98
98
|
console.log(`\r ✓ ${sent} files indexed${errors > 0 ? `, ${errors} skipped` : ""}`);
|
|
99
|
+
|
|
100
|
+
// Finalize: resolve cross-file references and store relationships.
|
|
101
|
+
// The server also flushes automatically after a quiet period, but an
|
|
102
|
+
// explicit call makes the graph available immediately.
|
|
103
|
+
try {
|
|
104
|
+
const res = await fetch(`${YATS_URL}/index/complete`, {
|
|
105
|
+
method: "POST",
|
|
106
|
+
headers: { "Content-Type": "application/json" },
|
|
107
|
+
body: JSON.stringify({ repository: repoName }),
|
|
108
|
+
});
|
|
109
|
+
const data = await res.json();
|
|
110
|
+
if (res.ok) {
|
|
111
|
+
console.log(` ✓ Graph finalized: ${data.stored} relationships (${data.rewritten} cross-file resolved)`);
|
|
112
|
+
}
|
|
113
|
+
} catch {
|
|
114
|
+
// Non-fatal — the server flushes on its own debounce timer.
|
|
115
|
+
}
|
|
99
116
|
console.log(``);
|
|
100
117
|
}
|
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
|
}
|
|
@@ -430,6 +441,9 @@ export function applyEnvKeys(envMap, { provider, apiKey, model }) {
|
|
|
430
441
|
for (const k of ["ANTHROPIC_API_KEY", "OPENAI_API_KEY", "GEMINI_API_KEY", "DEEPSEEK_API_KEY"]) {
|
|
431
442
|
if (!(k in envMap)) envMap[k] = "";
|
|
432
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;
|
|
433
447
|
return envMap;
|
|
434
448
|
}
|
|
435
449
|
|
package/src/watch.js
CHANGED
|
@@ -12,36 +12,14 @@ import { watch, statSync, readFileSync } from "node:fs";
|
|
|
12
12
|
import { resolve, basename, relative } from "node:path";
|
|
13
13
|
import { request } from "node:http";
|
|
14
14
|
|
|
15
|
-
// ============================================================
|
|
16
|
-
// Config
|
|
17
|
-
// ============================================================
|
|
18
|
-
|
|
19
|
-
const YATS_URL = process.env.YATS_URL ?? "http://localhost:5555";
|
|
20
|
-
const DEBOUNCE_MS = parseInt(process.env.YATS_WATCH_DEBOUNCE ?? "500", 10);
|
|
21
|
-
|
|
22
|
-
const repoPath = resolve(process.argv[2] ?? process.cwd());
|
|
23
|
-
const repoArgIdx = process.argv.indexOf("--repo");
|
|
24
|
-
const repoName = repoArgIdx >= 0 ? process.argv[repoArgIdx + 1] : basename(repoPath);
|
|
25
|
-
|
|
26
|
-
if (!process.argv[2]) {
|
|
27
|
-
console.log("Usage: yats watch <path> [--repo <name>]");
|
|
28
|
-
console.log("");
|
|
29
|
-
console.log("Watches a directory and keeps the YATS index in sync.");
|
|
30
|
-
console.log("When files change, it tells the YATS server to re-index them.");
|
|
31
|
-
console.log("");
|
|
32
|
-
console.log(" yats watch ~/my-project");
|
|
33
|
-
console.log(" yats watch ~/my-project --repo my-api");
|
|
34
|
-
process.exit(1);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
15
|
// ============================================================
|
|
38
16
|
// HTTP helpers
|
|
39
17
|
// ============================================================
|
|
40
18
|
|
|
41
|
-
function post(path, body) {
|
|
19
|
+
function post(baseUrl, path, body) {
|
|
42
20
|
return new Promise((resolve, reject) => {
|
|
43
21
|
const data = JSON.stringify(body);
|
|
44
|
-
const url = new URL(path,
|
|
22
|
+
const url = new URL(path, baseUrl);
|
|
45
23
|
const req = request(
|
|
46
24
|
{
|
|
47
25
|
hostname: url.hostname,
|
|
@@ -71,85 +49,111 @@ function post(path, body) {
|
|
|
71
49
|
});
|
|
72
50
|
}
|
|
73
51
|
|
|
74
|
-
async function
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
52
|
+
export default async function watchRepo(args = []) {
|
|
53
|
+
// ============================================================
|
|
54
|
+
// Config
|
|
55
|
+
// ============================================================
|
|
56
|
+
|
|
57
|
+
const YATS_URL = process.env.YATS_URL ?? "http://localhost:5555";
|
|
58
|
+
const DEBOUNCE_MS = parseInt(process.env.YATS_WATCH_DEBOUNCE ?? "500", 10);
|
|
59
|
+
|
|
60
|
+
const repoPath = resolve(args[0] ?? process.cwd());
|
|
61
|
+
const repoArgIdx = args.indexOf("--repo");
|
|
62
|
+
const repoName = repoArgIdx >= 0 ? args[repoArgIdx + 1] : basename(repoPath);
|
|
63
|
+
|
|
64
|
+
if (!args[0] || args[0] === "--help" || args[0] === "-h") {
|
|
65
|
+
console.log("Usage: yats watch <path> [--repo <name>]");
|
|
66
|
+
console.log("");
|
|
67
|
+
console.log("Watches a directory and keeps the YATS index in sync.");
|
|
68
|
+
console.log("When files change, it tells the YATS server to re-index them.");
|
|
69
|
+
console.log("");
|
|
70
|
+
console.log(" yats watch ~/my-project");
|
|
71
|
+
console.log(" yats watch ~/my-project --repo my-api");
|
|
72
|
+
process.exit(1);
|
|
83
73
|
}
|
|
84
|
-
}
|
|
85
74
|
|
|
86
|
-
async function
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
75
|
+
async function indexFile(filePath) {
|
|
76
|
+
const rel = relative(repoPath, filePath);
|
|
77
|
+
console.log(` ↻ Indexing: ${rel}`);
|
|
78
|
+
try {
|
|
79
|
+
const content = readFileSync(filePath, "utf-8");
|
|
80
|
+
// Send the RELATIVE path — symbol IDs must match the ones from `yats index`
|
|
81
|
+
// (the server scopes symbol IDs to the repository-relative path).
|
|
82
|
+
await post(YATS_URL, "/index/file", { filePath: rel, content, repository: repoName });
|
|
83
|
+
console.log(` ✓ Done: ${rel}`);
|
|
84
|
+
} catch (err) {
|
|
85
|
+
console.error(` ✗ Failed: ${rel} — ${err.message}`);
|
|
86
|
+
}
|
|
94
87
|
}
|
|
95
|
-
}
|
|
96
88
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
89
|
+
async function removeFile(filePath) {
|
|
90
|
+
const rel = relative(repoPath, filePath);
|
|
91
|
+
console.log(` ↻ Removing from index: ${rel}`);
|
|
92
|
+
try {
|
|
93
|
+
await post(YATS_URL, "/index/remove", { path: rel, repository: repoName });
|
|
94
|
+
console.log(` ✓ Removed: ${rel}`);
|
|
95
|
+
} catch (err) {
|
|
96
|
+
console.error(` ✗ Failed: ${rel} — ${err.message}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
100
99
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
100
|
+
// ============================================================
|
|
101
|
+
// Debounced watcher
|
|
102
|
+
// ============================================================
|
|
103
|
+
|
|
104
|
+
const pending = new Map();
|
|
105
|
+
const SKIP_PATTERNS = [
|
|
106
|
+
/node_modules/,
|
|
107
|
+
/\.git\//,
|
|
108
|
+
/vendor\//,
|
|
109
|
+
/__pycache__/,
|
|
110
|
+
/\.next\//,
|
|
111
|
+
/dist\//,
|
|
112
|
+
/\.yarn\//,
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
function shouldSkip(filename) {
|
|
116
|
+
if (!filename || filename.startsWith(".")) return true;
|
|
117
|
+
return SKIP_PATTERNS.some((p) => p.test(filename));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
console.log(`👀 Watching: ${repoPath}`);
|
|
121
|
+
console.log(` Repo: ${repoName}`);
|
|
122
|
+
console.log(` Server: ${YATS_URL}`);
|
|
123
|
+
console.log(` (debounce: ${DEBOUNCE_MS}ms)`);
|
|
124
|
+
console.log("");
|
|
125
|
+
|
|
126
|
+
watch(repoPath, { recursive: true }, (eventType, filename) => {
|
|
127
|
+
if (!filename || shouldSkip(filename)) return;
|
|
128
|
+
|
|
129
|
+
const fullPath = resolve(repoPath, filename);
|
|
130
|
+
|
|
131
|
+
// Debounce: group rapid changes to the same file
|
|
132
|
+
const existing = pending.get(fullPath);
|
|
133
|
+
if (existing) clearTimeout(existing);
|
|
116
134
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
await removeFile(fullPath);
|
|
143
|
-
}
|
|
144
|
-
}, DEBOUNCE_MS),
|
|
145
|
-
);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// Keep the process alive
|
|
149
|
-
process.stdin.resume();
|
|
150
|
-
|
|
151
|
-
// Clean shutdown
|
|
152
|
-
process.on("SIGINT", () => {
|
|
153
|
-
console.log("\n👋 Stopped watching.");
|
|
154
|
-
process.exit(0);
|
|
155
|
-
});
|
|
135
|
+
pending.set(
|
|
136
|
+
fullPath,
|
|
137
|
+
setTimeout(async () => {
|
|
138
|
+
pending.delete(fullPath);
|
|
139
|
+
|
|
140
|
+
// Check if file still exists (or was deleted)
|
|
141
|
+
try {
|
|
142
|
+
statSync(fullPath);
|
|
143
|
+
await indexFile(fullPath);
|
|
144
|
+
} catch {
|
|
145
|
+
await removeFile(fullPath);
|
|
146
|
+
}
|
|
147
|
+
}, DEBOUNCE_MS),
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// Keep the process alive
|
|
152
|
+
process.stdin.resume();
|
|
153
|
+
|
|
154
|
+
// Clean shutdown
|
|
155
|
+
process.on("SIGINT", () => {
|
|
156
|
+
console.log("\n👋 Stopped watching.");
|
|
157
|
+
process.exit(0);
|
|
158
|
+
});
|
|
159
|
+
}
|