yats-toolkit 0.3.4 → 0.4.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/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 will use the `index_repository` MCP tool, which tells it to run `yats index` and then polls until complete.
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`, `index_repository`, `delete_repository` |
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.4",
3
+ "version": "0.4.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
@@ -1301,8 +1301,7 @@ function parseResult(logFile, agentName) {
1301
1301
  "find_implementations", "find_inheritors", "find_tests",
1302
1302
  "find_routes", "find_configuration", "expand_graph", "related_symbols",
1303
1303
  "list_symbols", "list_repositories", "repository_summary",
1304
- "architecture_summary", "index_repository", "delete_repository",
1305
- "reindex", "index_file", "remove_file",
1304
+ "architecture_summary", "delete_repository",
1306
1305
  ]);
1307
1306
  const yatsQueries = Object.entries(toolCalls)
1308
1307
  .filter(([k]) => /yats|mcp__/i.test(k) || YATS_TOOLS.has(k))
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/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, YATS_URL);
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 indexFile(filePath) {
75
- const rel = relative(repoPath, filePath);
76
- console.log(` ↻ Indexing: ${rel}`);
77
- try {
78
- const content = readFileSync(filePath, "utf-8");
79
- await post("/index/file", { path: filePath, content, repository: repoName });
80
- console.log(` ✓ Done: ${rel}`);
81
- } catch (err) {
82
- console.error(` ✗ Failed: ${rel} — ${err.message}`);
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 removeFile(filePath) {
87
- const rel = relative(repoPath, filePath);
88
- console.log(` ↻ Removing from index: ${rel}`);
89
- try {
90
- await post("/index/remove", { path: filePath, repository: repoName });
91
- console.log(` ✓ Removed: ${rel}`);
92
- } catch (err) {
93
- console.error(` ✗ Failed: ${rel} — ${err.message}`);
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
- // Debounced watcher
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
- const pending = new Map();
102
- const SKIP_PATTERNS = [
103
- /node_modules/,
104
- /\.git\//,
105
- /vendor\//,
106
- /__pycache__/,
107
- /\.next\//,
108
- /dist\//,
109
- /\.yarn\//,
110
- ];
111
-
112
- function shouldSkip(filename) {
113
- if (!filename || filename.startsWith(".")) return true;
114
- return SKIP_PATTERNS.some((p) => p.test(filename));
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
- console.log(`👀 Watching: ${repoPath}`);
118
- console.log(` Repo: ${repoName}`);
119
- console.log(` Server: ${YATS_URL}`);
120
- console.log(` (debounce: ${DEBOUNCE_MS}ms)`);
121
- console.log("");
122
-
123
- watch(repoPath, { recursive: true }, (eventType, filename) => {
124
- if (!filename || shouldSkip(filename)) return;
125
-
126
- const fullPath = resolve(repoPath, filename);
127
-
128
- // Debounce: group rapid changes to the same file
129
- const existing = pending.get(fullPath);
130
- if (existing) clearTimeout(existing);
131
-
132
- pending.set(
133
- fullPath,
134
- setTimeout(async () => {
135
- pending.delete(fullPath);
136
-
137
- // Check if file still exists (or was deleted)
138
- try {
139
- statSync(fullPath);
140
- await indexFile(fullPath);
141
- } catch {
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
+ }