yats-toolkit 0.1.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 +124 -0
- package/bin/setup.js +46 -0
- package/package.json +51 -0
- package/src/bridge.js +101 -0
- package/src/indexer.js +86 -0
- package/src/setup.js +662 -0
- package/src/status.js +43 -0
- package/src/stop.js +15 -0
package/README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# YATS Toolkit
|
|
2
|
+
|
|
3
|
+
**Give your AI agent superpowers over your codebase.**
|
|
4
|
+
|
|
5
|
+
YATS indexes your repositories into a knowledge graph so AI coding agents (Claude, Cursor, Copilot) can search, navigate, and understand your code — without burning thousands of tokens reading files one by one.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx yats-toolkit
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## What it does
|
|
12
|
+
|
|
13
|
+
| | Without YATS | With YATS |
|
|
14
|
+
|---|---|---|
|
|
15
|
+
| Find implementations of an interface | Agent reads dozens of files | `find_implementations("PaymentGateway")` → instant |
|
|
16
|
+
| Trace call chains | Manual grep, guesswork | `find_callers` → `find_callees` → complete graph |
|
|
17
|
+
| Understand architecture | Read README, hope it's updated | `architecture_summary` → services, controllers, DTOs |
|
|
18
|
+
| Search code semantically | Text grep only | `search_code("JWT token validation")` → vector + graph results |
|
|
19
|
+
|
|
20
|
+
## How it works
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
Your code → Analyzer (AST) → Symbols + Relationships
|
|
24
|
+
↓
|
|
25
|
+
Neo4j (knowledge graph) + Qdrant (vectors)
|
|
26
|
+
↓
|
|
27
|
+
MCP Server → AI agent queries, not reads
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
1. **Index** your repos (`yats index ~/my-project`)
|
|
31
|
+
2. **Configure** your AI agent with the MCP endpoint
|
|
32
|
+
3. **Ask** questions about your code — YATS answers in < 50ms
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# One command
|
|
38
|
+
npx yats-toolkit
|
|
39
|
+
|
|
40
|
+
# The wizard will:
|
|
41
|
+
# 1. Pull the YATS Docker image from ghcr.io
|
|
42
|
+
# 2. Start Neo4j + Qdrant + YATS MCP server
|
|
43
|
+
# 3. Configure everything automatically
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
After setup, add repos:
|
|
47
|
+
```bash
|
|
48
|
+
yats index ~/work/backend
|
|
49
|
+
yats index ~/work/frontend
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## MCP Configuration
|
|
53
|
+
|
|
54
|
+
Add this to your AI agent's MCP config:
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"mcpServers": {
|
|
59
|
+
"yats": {
|
|
60
|
+
"url": "http://localhost:5555/mcp"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
| Agent | Config location |
|
|
67
|
+
|---|---|
|
|
68
|
+
| Cursor | `.cursor/mcp.json` |
|
|
69
|
+
| Claude Desktop | `~/Library/Application Support/Claude/claude_desktop_config.json` |
|
|
70
|
+
| VS Code Copilot | `.vscode/mcp.json` |
|
|
71
|
+
| Continue.dev | `~/.continue/config.json` |
|
|
72
|
+
| Zed | `.zed/mcp.json` |
|
|
73
|
+
|
|
74
|
+
## Available Tools (20)
|
|
75
|
+
|
|
76
|
+
| Category | Tools |
|
|
77
|
+
|---|---|
|
|
78
|
+
| Search | `search_code`, `search_documentation`, `search_similar` |
|
|
79
|
+
| Navigation | `find_symbol`, `find_references`, `find_callers`, `find_callees` |
|
|
80
|
+
| Inheritance | `find_implementations`, `find_inheritors` |
|
|
81
|
+
| Graph | `expand_graph`, `related_symbols` |
|
|
82
|
+
| Discovery | `list_symbols`, `find_routes`, `find_configuration`, `find_tests` |
|
|
83
|
+
| Repository | `list_repositories`, `index_repository`, `delete_repository` |
|
|
84
|
+
| Analysis | `repository_summary`, `architecture_summary` |
|
|
85
|
+
|
|
86
|
+
## Commands
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
yats setup # Run the setup wizard
|
|
90
|
+
yats index <path> # Index a repository
|
|
91
|
+
yats status # Check what's indexed
|
|
92
|
+
yats stop # Stop all YATS services
|
|
93
|
+
yats bridge # MCP stdio ↔ HTTP proxy (for CLI-only agents)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Requirements
|
|
97
|
+
|
|
98
|
+
- **Docker** with Compose plugin
|
|
99
|
+
- ~2GB free disk space
|
|
100
|
+
- Internet connection (first pull only, then runs fully local with Ollama)
|
|
101
|
+
|
|
102
|
+
## Languages Supported
|
|
103
|
+
|
|
104
|
+
TypeScript, JavaScript, Python, Go, C#, PHP — plus universal fallback via Tree-sitter.
|
|
105
|
+
|
|
106
|
+
## Architecture
|
|
107
|
+
|
|
108
|
+
Built on a layered monorepo (pnpm workspaces):
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
packages/
|
|
112
|
+
├── shared/ Domain models, ports, DTOs
|
|
113
|
+
├── infra/ Neo4j, Qdrant, embeddings (OpenAI, Ollama, Mistral, Voyage)
|
|
114
|
+
├── indexing/ Pipeline: walk → analyze → embed → store
|
|
115
|
+
├── retrieval/ Hybrid: vector + graph → rank → dedup → compress
|
|
116
|
+
├── mcp-server/ 20 MCP tools over stdio, HTTP+SSE, Streamable HTTP
|
|
117
|
+
├── cli/ CLI: index, search, serve, clear
|
|
118
|
+
├── setup/ One-command installer (this package)
|
|
119
|
+
└── analyzers/ Per-language AST analyzers (TS, Python, Go, C#, PHP, Tree-sitter)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
|
|
124
|
+
MIT © Franco Vinciarelli
|
package/bin/setup.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* YATS Toolkit — Code intelligence for AI agents.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* yats setup # One-time setup wizard
|
|
7
|
+
* yats index <path> # Index a repository
|
|
8
|
+
* yats status # Check indexed repos
|
|
9
|
+
* yats stop # Stop all YATS services
|
|
10
|
+
* yats bridge # MCP stdio ↔ HTTP proxy (for Copilot, Claude)
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const cmd = process.argv[2] || "setup";
|
|
14
|
+
const args = process.argv.slice(3);
|
|
15
|
+
|
|
16
|
+
switch (cmd) {
|
|
17
|
+
case "setup":
|
|
18
|
+
import("../src/setup.js").then(m => m.default());
|
|
19
|
+
break;
|
|
20
|
+
case "index":
|
|
21
|
+
case "add":
|
|
22
|
+
import("../src/indexer.js").then(m => m.default(args));
|
|
23
|
+
break;
|
|
24
|
+
case "status":
|
|
25
|
+
import("../src/status.js").then(m => m.default());
|
|
26
|
+
break;
|
|
27
|
+
case "stop":
|
|
28
|
+
import("../src/stop.js").then(m => m.default());
|
|
29
|
+
break;
|
|
30
|
+
case "bridge":
|
|
31
|
+
import("../src/bridge.js");
|
|
32
|
+
break;
|
|
33
|
+
case "--version":
|
|
34
|
+
case "-v":
|
|
35
|
+
console.log("yats v0.1.0");
|
|
36
|
+
break;
|
|
37
|
+
default:
|
|
38
|
+
console.log(`YATS Toolkit — Code intelligence for AI agents`);
|
|
39
|
+
console.log(``);
|
|
40
|
+
console.log(` yats setup Setup wizard`);
|
|
41
|
+
console.log(` yats index <path> Index a repository`);
|
|
42
|
+
console.log(` yats status Check indexed repos`);
|
|
43
|
+
console.log(` yats stop Stop YATS services`);
|
|
44
|
+
console.log(` yats bridge Stdio proxy for Copilot/Claude`);
|
|
45
|
+
break;
|
|
46
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "yats-toolkit",
|
|
3
|
+
"version": "0.1.0",
|
|
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
|
+
"author": "Franco Vinciarelli <vinciarellifranco@gmail.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/fvinciarelli/yats.git"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"mcp",
|
|
13
|
+
"model-context-protocol",
|
|
14
|
+
"code-indexer",
|
|
15
|
+
"code-search",
|
|
16
|
+
"knowledge-graph",
|
|
17
|
+
"semantic-search",
|
|
18
|
+
"embeddings",
|
|
19
|
+
"rag",
|
|
20
|
+
"llm",
|
|
21
|
+
"ai",
|
|
22
|
+
"claude",
|
|
23
|
+
"cursor",
|
|
24
|
+
"copilot",
|
|
25
|
+
"neo4j",
|
|
26
|
+
"qdrant",
|
|
27
|
+
"developer-tools",
|
|
28
|
+
"code-navigation",
|
|
29
|
+
"token-saver",
|
|
30
|
+
"token-reducer",
|
|
31
|
+
"context-window",
|
|
32
|
+
"codebase-intelligence",
|
|
33
|
+
"cli"
|
|
34
|
+
],
|
|
35
|
+
"type": "module",
|
|
36
|
+
"bin": {
|
|
37
|
+
"yats": "bin/setup.js"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"bin/",
|
|
41
|
+
"src/",
|
|
42
|
+
"README.md"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"start": "node bin/setup.js"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=18.0.0"
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/bridge.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* YATS Bridge — MCP stdio ↔ HTTP proxy
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* npx yats-bridge # defaults to localhost:5555
|
|
7
|
+
* npx yats-bridge --port 5555
|
|
8
|
+
* npx yats-bridge --url http://my-server:5555
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const YATS_URL = process.env.YATS_URL || "http://localhost:5555";
|
|
12
|
+
|
|
13
|
+
// Parse CLI args
|
|
14
|
+
const args = process.argv.slice(2);
|
|
15
|
+
let baseUrl = YATS_URL;
|
|
16
|
+
for (let i = 0; i < args.length; i++) {
|
|
17
|
+
if (args[i] === "--port" && args[i + 1]) baseUrl = `http://localhost:${args[++i]}`;
|
|
18
|
+
if (args[i] === "--url" && args[i + 1]) baseUrl = args[++i];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let sessionId = null;
|
|
22
|
+
let sseBuffer = "";
|
|
23
|
+
|
|
24
|
+
async function getSession() {
|
|
25
|
+
const res = await fetch(`${baseUrl}/mcp/sse`);
|
|
26
|
+
const reader = res.body.getReader();
|
|
27
|
+
const decoder = new TextDecoder();
|
|
28
|
+
|
|
29
|
+
// Read first SSE event to get the session endpoint
|
|
30
|
+
while (true) {
|
|
31
|
+
const { done, value } = await reader.read();
|
|
32
|
+
if (done) break;
|
|
33
|
+
sseBuffer += decoder.decode(value, { stream: true });
|
|
34
|
+
|
|
35
|
+
const match = sseBuffer.match(/event: endpoint\ndata: (.+)/);
|
|
36
|
+
if (match) {
|
|
37
|
+
const endpoint = match[1];
|
|
38
|
+
sessionId = new URL(endpoint, baseUrl).searchParams.get("sessionId");
|
|
39
|
+
sseBuffer = sseBuffer.slice(match.index + match[0].length);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!sessionId) throw new Error("Failed to get SSE session");
|
|
45
|
+
|
|
46
|
+
// Keep reading SSE in background — forward messages to stdout
|
|
47
|
+
(async () => {
|
|
48
|
+
while (true) {
|
|
49
|
+
const { done, value } = await reader.read();
|
|
50
|
+
if (done) break;
|
|
51
|
+
sseBuffer += decoder.decode(value, { stream: true });
|
|
52
|
+
|
|
53
|
+
// Extract "message" events
|
|
54
|
+
const parts = sseBuffer.split("\n\n");
|
|
55
|
+
sseBuffer = parts.pop() || "";
|
|
56
|
+
|
|
57
|
+
for (const part of parts) {
|
|
58
|
+
const msgMatch = part.match(/^event: message\ndata: (.+)$/m);
|
|
59
|
+
if (msgMatch) {
|
|
60
|
+
process.stdout.write(msgMatch[1].trim() + "\n");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
})();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function sendRequest(jsonLine) {
|
|
68
|
+
if (!sessionId) await getSession();
|
|
69
|
+
if (!sessionId) return;
|
|
70
|
+
|
|
71
|
+
await fetch(`${baseUrl}/mcp/message?sessionId=${sessionId}`, {
|
|
72
|
+
method: "POST",
|
|
73
|
+
headers: { "Content-Type": "application/json" },
|
|
74
|
+
body: jsonLine,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Read JSON-RPC from stdin
|
|
79
|
+
let stdinBuffer = "";
|
|
80
|
+
process.stdin.setEncoding("utf-8");
|
|
81
|
+
process.stdin.on("data", async (chunk) => {
|
|
82
|
+
stdinBuffer += chunk;
|
|
83
|
+
const lines = stdinBuffer.split("\n");
|
|
84
|
+
stdinBuffer = lines.pop() || "";
|
|
85
|
+
|
|
86
|
+
for (const line of lines) {
|
|
87
|
+
const trimmed = line.trim();
|
|
88
|
+
if (!trimmed) continue;
|
|
89
|
+
try {
|
|
90
|
+
JSON.parse(trimmed); // validate JSON
|
|
91
|
+
await sendRequest(trimmed);
|
|
92
|
+
} catch {
|
|
93
|
+
process.stderr.write(`Bridge: invalid JSON: ${trimmed.slice(0, 100)}\n`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
process.stdin.on("end", () => {
|
|
99
|
+
// Keep process alive briefly for pending SSE responses
|
|
100
|
+
setTimeout(() => process.exit(0), 2000);
|
|
101
|
+
});
|
package/src/indexer.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* yats index <path> — Index a repository by sending files to YATS server.
|
|
3
|
+
* Reads each file from the host and POSTs it via HTTP.
|
|
4
|
+
*/
|
|
5
|
+
import { readFileSync, statSync, readdirSync } from "node:fs";
|
|
6
|
+
import { join, relative, basename } from "node:path";
|
|
7
|
+
|
|
8
|
+
const YATS_URL = process.env.YATS_URL || "http://localhost:5555";
|
|
9
|
+
|
|
10
|
+
const IGNORED = new Set([
|
|
11
|
+
"node_modules", ".git", "dist", "build", ".next", "__pycache__",
|
|
12
|
+
"vendor", "target", "bin", "obj", ".venv", "venv", ".yarn", ".pnpm",
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
async function walk(dir) {
|
|
16
|
+
const files = [];
|
|
17
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
18
|
+
for (const e of entries) {
|
|
19
|
+
if (IGNORED.has(e.name) || e.name.startsWith(".")) continue;
|
|
20
|
+
const full = join(dir, e.name);
|
|
21
|
+
if (e.isDirectory()) {
|
|
22
|
+
files.push(...await walk(full));
|
|
23
|
+
} else if (e.isFile()) {
|
|
24
|
+
files.push(full);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return files;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default async function indexRepo(args) {
|
|
31
|
+
const repoPath = args[0];
|
|
32
|
+
if (!repoPath) {
|
|
33
|
+
console.error("Usage: npx yats index <path>");
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const repoName = basename(repoPath);
|
|
38
|
+
const stat = statSync(repoPath);
|
|
39
|
+
if (!stat.isDirectory()) {
|
|
40
|
+
console.error(`Not a directory: ${repoPath}`);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Register repo
|
|
45
|
+
try {
|
|
46
|
+
await fetch(`${YATS_URL}/index`, {
|
|
47
|
+
method: "POST",
|
|
48
|
+
headers: { "Content-Type": "application/json" },
|
|
49
|
+
body: JSON.stringify({ path: repoPath }),
|
|
50
|
+
});
|
|
51
|
+
} catch {
|
|
52
|
+
console.error(`Cannot reach YATS at ${YATS_URL}. Is it running?`);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Walk and send files
|
|
57
|
+
console.log(`Indexing ${repoPath}...`);
|
|
58
|
+
const files = await walk(repoPath);
|
|
59
|
+
let sent = 0;
|
|
60
|
+
let errors = 0;
|
|
61
|
+
|
|
62
|
+
for (const file of files) {
|
|
63
|
+
const relPath = relative(repoPath, file);
|
|
64
|
+
try {
|
|
65
|
+
const content = readFileSync(file, "utf-8");
|
|
66
|
+
// Skip binary/large files
|
|
67
|
+
if (content.includes("\0") || content.length > 1_000_000) continue;
|
|
68
|
+
|
|
69
|
+
const res = await fetch(`${YATS_URL}/index/file`, {
|
|
70
|
+
method: "POST",
|
|
71
|
+
headers: { "Content-Type": "application/json" },
|
|
72
|
+
body: JSON.stringify({ repoName, filePath: relPath, content }),
|
|
73
|
+
});
|
|
74
|
+
if (res.ok) {
|
|
75
|
+
sent++;
|
|
76
|
+
process.stdout.write(`\r ${sent}/${files.length} files`);
|
|
77
|
+
} else {
|
|
78
|
+
errors++;
|
|
79
|
+
}
|
|
80
|
+
} catch {
|
|
81
|
+
errors++;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
console.log(`\r ✓ ${sent} files indexed${errors > 0 ? `, ${errors} skipped` : ""}`);
|
|
85
|
+
console.log(``);
|
|
86
|
+
}
|
package/src/setup.js
ADDED
|
@@ -0,0 +1,662 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YATS Setup — One-command wizard to get YATS running on your machine.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* npx yats-toolkit
|
|
6
|
+
* curl -fsSL https://get.yats.site | bash
|
|
7
|
+
*
|
|
8
|
+
* Requirements: Docker (with compose plugin)
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { spawn } from "node:child_process";
|
|
12
|
+
import { writeFileSync, mkdirSync, existsSync } from "node:fs";
|
|
13
|
+
import { homedir } from "node:os";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import { createInterface } from "node:readline";
|
|
16
|
+
|
|
17
|
+
// ============================================================
|
|
18
|
+
// Constants
|
|
19
|
+
// ============================================================
|
|
20
|
+
|
|
21
|
+
const YATS_VERSION = "0.1.0";
|
|
22
|
+
const YATS_DIR = join(homedir(), ".yats");
|
|
23
|
+
const REPOS_DIR = join(YATS_DIR, "repos");
|
|
24
|
+
const COMPOSE_FILE = join(YATS_DIR, "docker-compose.yml");
|
|
25
|
+
const MCP_CONFIG_FILE = join(YATS_DIR, "mcp-config.json");
|
|
26
|
+
|
|
27
|
+
const GITHUB_COMPOSE_URL =
|
|
28
|
+
"https://raw.githubusercontent.com/fvinciarelli/yats/main/docker/docker-compose.yml";
|
|
29
|
+
|
|
30
|
+
const B = "\x1b[1m";
|
|
31
|
+
const D = "\x1b[2m";
|
|
32
|
+
const R = "\x1b[0m";
|
|
33
|
+
const G = "\x1b[32m";
|
|
34
|
+
const Y = "\x1b[33m";
|
|
35
|
+
const C = "\x1b[36m";
|
|
36
|
+
const RED = "\x1b[31m";
|
|
37
|
+
|
|
38
|
+
// Minimal embedded docker-compose as fallback
|
|
39
|
+
const EMBEDDED_COMPOSE = `services:
|
|
40
|
+
neo4j:
|
|
41
|
+
image: neo4j:5.26-community
|
|
42
|
+
expose: ["7474", "7687"]
|
|
43
|
+
environment:
|
|
44
|
+
- NEO4J_AUTH=neo4j/\${NEO4J_PASSWORD:-password}
|
|
45
|
+
- NEO4J_apoc_export_file_enabled=true
|
|
46
|
+
- NEO4J_apoc_import_file_enabled=true
|
|
47
|
+
- NEO4J_apoc_import_file_use__neo4j__config=true
|
|
48
|
+
- NEO4J_PLUGINS=["apoc"]
|
|
49
|
+
- NEO4J_server_memory_heap_initial__size=512m
|
|
50
|
+
- NEO4J_server_memory_heap_max__size=1g
|
|
51
|
+
volumes:
|
|
52
|
+
- neo4j-data:/data
|
|
53
|
+
- neo4j-logs:/logs
|
|
54
|
+
healthcheck:
|
|
55
|
+
test: ["CMD-SHELL", "echo 'RETURN 1;' | cypher-shell -u neo4j -p \${NEO4J_PASSWORD:-password} 2>/dev/null || exit 1"]
|
|
56
|
+
interval: 10s
|
|
57
|
+
timeout: 10s
|
|
58
|
+
retries: 10
|
|
59
|
+
start_period: 30s
|
|
60
|
+
restart: unless-stopped
|
|
61
|
+
qdrant:
|
|
62
|
+
image: qdrant/qdrant:latest
|
|
63
|
+
expose: ["6333", "6334"]
|
|
64
|
+
volumes:
|
|
65
|
+
- qdrant-storage:/qdrant/storage
|
|
66
|
+
environment:
|
|
67
|
+
- QDRANT__SERVICE__GRPC_PORT=6334
|
|
68
|
+
- QDRANT__SERVICE__HTTP_PORT=6333
|
|
69
|
+
healthcheck:
|
|
70
|
+
test: ["CMD-SHELL", "timeout 1 bash -c 'cat < /dev/null > /dev/tcp/localhost/6333' 2>/dev/null || exit 1"]
|
|
71
|
+
interval: 10s
|
|
72
|
+
timeout: 5s
|
|
73
|
+
retries: 5
|
|
74
|
+
start_period: 5s
|
|
75
|
+
restart: unless-stopped
|
|
76
|
+
__OLLAMA_PLACEHOLDER__
|
|
77
|
+
yats:
|
|
78
|
+
image: ghcr.io/fvinciarelli/yats:latest
|
|
79
|
+
ports: ["__MCP_PORT__:__MCP_PORT__"]
|
|
80
|
+
environment:
|
|
81
|
+
- NEO4J_URI=bolt://neo4j:7687
|
|
82
|
+
- NEO4J_USER=neo4j
|
|
83
|
+
- NEO4J_PASSWORD=\${NEO4J_PASSWORD:-password}
|
|
84
|
+
- QDRANT_URL=http://qdrant:6333
|
|
85
|
+
- EMBEDDING_PROVIDER=__PROVIDER__
|
|
86
|
+
- OLLAMA_URL=http://ollama:11434
|
|
87
|
+
- OLLAMA_MODEL=__OLLAMA_MODEL__
|
|
88
|
+
- OPENAI_API_KEY=__OPENAI_KEY__
|
|
89
|
+
- MISTRAL_API_KEY=__MISTRAL_KEY__
|
|
90
|
+
- VOYAGE_API_KEY=__VOYAGE_KEY__
|
|
91
|
+
- REPOSITORIES_PATH=/repos
|
|
92
|
+
- YATS_PORT=__MCP_PORT__
|
|
93
|
+
- EMBEDDING_BATCH_SIZE=__BATCH_SIZE__
|
|
94
|
+
- INDEX_DOCS=__INDEX_DOCS__
|
|
95
|
+
- DOC_MAX_FILES=__DOC_MAX__
|
|
96
|
+
- LOG_LEVEL=info
|
|
97
|
+
volumes:
|
|
98
|
+
- \${REPOS_PATH:-~/.yats/repos}:/repos:ro
|
|
99
|
+
depends_on:
|
|
100
|
+
neo4j:
|
|
101
|
+
condition: service_healthy
|
|
102
|
+
qdrant:
|
|
103
|
+
condition: service_healthy
|
|
104
|
+
restart: unless-stopped
|
|
105
|
+
volumes:
|
|
106
|
+
neo4j-data:
|
|
107
|
+
neo4j-logs:
|
|
108
|
+
qdrant-storage:
|
|
109
|
+
`;
|
|
110
|
+
|
|
111
|
+
const OLLAMA_SERVICE = ` ollama:
|
|
112
|
+
image: ollama/ollama:latest
|
|
113
|
+
expose: ["11434"]
|
|
114
|
+
volumes:
|
|
115
|
+
- ollama-models:/root/.ollama
|
|
116
|
+
environment:
|
|
117
|
+
- OLLAMA_KEEP_ALIVE=24h
|
|
118
|
+
restart: unless-stopped
|
|
119
|
+
entrypoint: ["/bin/sh", "-c"]
|
|
120
|
+
command:
|
|
121
|
+
- |
|
|
122
|
+
ollama serve &
|
|
123
|
+
sleep 5
|
|
124
|
+
ollama pull __OLLAMA_MODEL__ 2>/dev/null || true
|
|
125
|
+
wait
|
|
126
|
+
ollama-models:
|
|
127
|
+
`;
|
|
128
|
+
|
|
129
|
+
// ============================================================
|
|
130
|
+
// UI helpers
|
|
131
|
+
// ============================================================
|
|
132
|
+
|
|
133
|
+
const W = 52; // inner box width
|
|
134
|
+
|
|
135
|
+
/** Strip ANSI codes to count visible chars */
|
|
136
|
+
function visibleLen(s) {
|
|
137
|
+
return s.replace(/\x1b\[[0-9;]*m/g, "").length;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Pad a string to exactly W visible chars */
|
|
141
|
+
function pad(s) {
|
|
142
|
+
const vlen = visibleLen(s);
|
|
143
|
+
const total = W + (s.length - vlen); // account for ANSI codes
|
|
144
|
+
return s + " ".repeat(Math.max(0, W - vlen));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Center text within width, preserving ANSI codes */
|
|
148
|
+
function center(text, width = W) {
|
|
149
|
+
const vlen = visibleLen(text);
|
|
150
|
+
const left = Math.floor((width - vlen) / 2);
|
|
151
|
+
const right = width - vlen - left;
|
|
152
|
+
return " ".repeat(left) + text + " ".repeat(right);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Draw a box with centered lines */
|
|
156
|
+
function box(lines, width = W) {
|
|
157
|
+
const top = ` ╔${"═".repeat(width + 2)}╗`;
|
|
158
|
+
const bottom = ` ╚${"═".repeat(width + 2)}╝`;
|
|
159
|
+
console.log(top);
|
|
160
|
+
for (const line of lines) {
|
|
161
|
+
if (line === "") {
|
|
162
|
+
console.log(` ║ ${" ".repeat(width)} ║`);
|
|
163
|
+
} else {
|
|
164
|
+
console.log(` ║ ${pad(line)} ║`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
console.log(bottom);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function header() {
|
|
171
|
+
console.log("");
|
|
172
|
+
box([
|
|
173
|
+
center(`${B}YATS Setup${R}`),
|
|
174
|
+
"",
|
|
175
|
+
center(`${D}Yet Another Token Saver — v${YATS_VERSION}${R}`),
|
|
176
|
+
center(`${D}by Franco Vinciarelli${R}`),
|
|
177
|
+
]);
|
|
178
|
+
console.log("");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function step(title) {
|
|
182
|
+
console.log(` ${C}▸${R} ${B}${title}${R}`);
|
|
183
|
+
console.log("");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async function ask(rl, question) {
|
|
187
|
+
return new Promise((resolve) => rl.question(question, resolve));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function spinner(text) {
|
|
191
|
+
process.stdout.write(` ${D}${text}${R}`);
|
|
192
|
+
return {
|
|
193
|
+
done: (ok = true) => {
|
|
194
|
+
process.stdout.write(`\r ${ok ? `${G}✓${R}` : `${RED}✗${R}`} ${text}\n`);
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Selector: arrow keys to move + type a number + Enter to pick
|
|
200
|
+
async function choose(prompt, options) {
|
|
201
|
+
console.log(` ${prompt}`);
|
|
202
|
+
for (let i = 0; i < options.length; i++) {
|
|
203
|
+
console.log(` ${B}${i + 1}${R}. ${options[i].label}`);
|
|
204
|
+
}
|
|
205
|
+
console.log("");
|
|
206
|
+
|
|
207
|
+
let selected = 0;
|
|
208
|
+
let buf = "";
|
|
209
|
+
|
|
210
|
+
const render = () => {
|
|
211
|
+
// move up to the prompt line and clear everything below
|
|
212
|
+
const lines = options.length + 3;
|
|
213
|
+
for (let i = 0; i < lines; i++) process.stdout.write("\x1b[1A\x1b[2K");
|
|
214
|
+
console.log(` ${prompt}`);
|
|
215
|
+
for (let i = 0; i < options.length; i++) {
|
|
216
|
+
const arrow = i === selected ? `${C}▸${R}` : " ";
|
|
217
|
+
console.log(` ${arrow} ${B}${i + 1}${R}. ${options[i].label}`);
|
|
218
|
+
}
|
|
219
|
+
console.log("");
|
|
220
|
+
const hint = buf ? ` ${D}Selected: ${buf}. Press Enter to confirm, ↑/↓ to change${R}` : ` ${D}↑/↓ to move, or type a number, Enter to select${R}`;
|
|
221
|
+
console.log(hint);
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
render();
|
|
225
|
+
|
|
226
|
+
const stdin = process.stdin;
|
|
227
|
+
return new Promise((resolve) => {
|
|
228
|
+
let rawOk = true;
|
|
229
|
+
try { stdin.setRawMode(true); } catch { rawOk = false; }
|
|
230
|
+
|
|
231
|
+
if (!rawOk) {
|
|
232
|
+
// Fallback to plain readline (piped stdin, no TTY)
|
|
233
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
234
|
+
const ask = () => {
|
|
235
|
+
rl.question(` ${B}Pick [1-${options.length}]:${R} `, (answer) => {
|
|
236
|
+
const num = parseInt(answer.trim(), 10);
|
|
237
|
+
if (num >= 1 && num <= options.length) {
|
|
238
|
+
rl.close();
|
|
239
|
+
console.log("");
|
|
240
|
+
resolve(options[num - 1].value);
|
|
241
|
+
} else {
|
|
242
|
+
console.log(` ${RED}Invalid. Type 1-${options.length}.${R}\n`);
|
|
243
|
+
ask();
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
ask();
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const onData = (key) => {
|
|
252
|
+
const k = key.toString();
|
|
253
|
+
if (k === "\u001b[A" || k === "\u001bOA") { selected = Math.max(0, selected - 1); buf = ""; render(); return; }
|
|
254
|
+
if (k === "\u001b[B" || k === "\u001bOB") { selected = Math.min(options.length - 1, selected + 1); buf = ""; render(); return; }
|
|
255
|
+
if (k >= "0" && k <= "9") { buf += k; render(); return; }
|
|
256
|
+
if (k === "\r" || k === "\n") {
|
|
257
|
+
if (buf) { const n = parseInt(buf, 10); if (n >= 1 && n <= options.length) selected = n - 1; }
|
|
258
|
+
stdin.removeListener("data", onData);
|
|
259
|
+
try { stdin.setRawMode(false); } catch {}
|
|
260
|
+
console.log("");
|
|
261
|
+
resolve(options[selected].value);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
if (k === "\u0003") { try { stdin.setRawMode(false); } catch {} process.exit(0); }
|
|
265
|
+
buf = "";
|
|
266
|
+
};
|
|
267
|
+
stdin.resume();
|
|
268
|
+
stdin.on("data", onData);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function divider() {
|
|
273
|
+
console.log(` ${D}───────────────────────────────────────────────────────${R}`);
|
|
274
|
+
console.log("");
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// ============================================================
|
|
278
|
+
// System checks
|
|
279
|
+
// ============================================================
|
|
280
|
+
|
|
281
|
+
async function checkDocker() {
|
|
282
|
+
return new Promise((resolve) => {
|
|
283
|
+
const proc = spawn("docker", ["info"], { stdio: "ignore" });
|
|
284
|
+
proc.on("close", (code) => resolve(code === 0));
|
|
285
|
+
proc.on("error", () => resolve(false));
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
async function checkPort(port) {
|
|
290
|
+
return new Promise((resolve) => {
|
|
291
|
+
const proc = spawn("docker", ["ps", "--format", "{{.Ports}}"], { stdio: "pipe" });
|
|
292
|
+
let out = "";
|
|
293
|
+
proc.stdout.on("data", (d) => (out += d));
|
|
294
|
+
proc.on("close", () => resolve(out.includes(`:${port}->`)));
|
|
295
|
+
proc.on("error", () => resolve(false));
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async function checkYatsRunning() {
|
|
300
|
+
return new Promise((resolve) => {
|
|
301
|
+
const proc = spawn("docker", ["ps", "--format", "{{.Names}}", "--filter", "name=yats"], { stdio: "pipe" });
|
|
302
|
+
let out = "";
|
|
303
|
+
proc.stdout.on("data", (d) => (out += d));
|
|
304
|
+
proc.on("close", () => resolve(out.trim().length > 0));
|
|
305
|
+
proc.on("error", () => resolve(false));
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// ============================================================
|
|
310
|
+
// Compose file generation
|
|
311
|
+
// ============================================================
|
|
312
|
+
|
|
313
|
+
function generateCompose(provider, ollamaModel, apiKey, mcpPort, batchSize, indexDocs, docMaxFiles) {
|
|
314
|
+
let compose = EMBEDDED_COMPOSE;
|
|
315
|
+
|
|
316
|
+
if (provider === "ollama") {
|
|
317
|
+
compose = compose.replace("__OLLAMA_PLACEHOLDER__", OLLAMA_SERVICE.replace("__OLLAMA_MODEL__", ollamaModel));
|
|
318
|
+
} else {
|
|
319
|
+
compose = compose.replace("__OLLAMA_PLACEHOLDER__", "");
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
compose = compose
|
|
323
|
+
.replace(/__PROVIDER__/g, provider)
|
|
324
|
+
.replace(/__OLLAMA_MODEL__/g, ollamaModel)
|
|
325
|
+
.replace(/__OPENAI_KEY__/g, provider === "openai" ? apiKey : "")
|
|
326
|
+
.replace(/__MISTRAL_KEY__/g, provider === "mistral" ? apiKey : "")
|
|
327
|
+
.replace(/__VOYAGE_KEY__/g, provider === "voyage" ? apiKey : "")
|
|
328
|
+
.replace(/__MCP_PORT__/g, String(mcpPort))
|
|
329
|
+
.replace(/__BATCH_SIZE__/g, String(batchSize))
|
|
330
|
+
.replace(/__INDEX_DOCS__/g, indexDocs ? "true" : "false")
|
|
331
|
+
.replace(/__DOC_MAX__/g, String(docMaxFiles))
|
|
332
|
+
|
|
333
|
+
return compose;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// ============================================================
|
|
337
|
+
// Docker operations
|
|
338
|
+
// ============================================================
|
|
339
|
+
|
|
340
|
+
function runCmd(cmd, args, opts = {}) {
|
|
341
|
+
return new Promise((resolve, reject) => {
|
|
342
|
+
const proc = spawn(cmd, args, { stdio: "inherit", ...opts });
|
|
343
|
+
proc.on("close", (code) => (code === 0 ? resolve() : reject(new Error(`${cmd} exited with ${code}`))));
|
|
344
|
+
proc.on("error", reject);
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function sleep(ms) {
|
|
349
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
async function waitForHealth(url, retries = 30, delay = 2000) {
|
|
353
|
+
for (let i = 0; i < retries; i++) {
|
|
354
|
+
try {
|
|
355
|
+
const resp = await fetch(url);
|
|
356
|
+
if (resp.ok) return true;
|
|
357
|
+
} catch {}
|
|
358
|
+
await sleep(delay);
|
|
359
|
+
}
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// ============================================================
|
|
364
|
+
// Main
|
|
365
|
+
// ============================================================
|
|
366
|
+
|
|
367
|
+
async function main() {
|
|
368
|
+
header();
|
|
369
|
+
|
|
370
|
+
// Check Docker
|
|
371
|
+
const hasDocker = await checkDocker();
|
|
372
|
+
if (!hasDocker) {
|
|
373
|
+
console.log(` ${RED}✗ Docker is not installed or not running.${R}`);
|
|
374
|
+
console.log("");
|
|
375
|
+
console.log(` Please install Docker Desktop from ${C}https://docker.com${R}`);
|
|
376
|
+
console.log(` Then re-run: ${B}npx yats-toolkit${R}`);
|
|
377
|
+
console.log("");
|
|
378
|
+
process.exit(1);
|
|
379
|
+
}
|
|
380
|
+
console.log(` ${G}✓${R} Docker found`);
|
|
381
|
+
console.log("");
|
|
382
|
+
|
|
383
|
+
// Check for existing YATS containers BEFORE the wizard
|
|
384
|
+
const existingContainers = await checkYatsRunning();
|
|
385
|
+
if (existingContainers) {
|
|
386
|
+
console.log(` ${Y}YATS containers are already running.${R}`);
|
|
387
|
+
console.log("");
|
|
388
|
+
console.log(` To start fresh, run this first ${B}(destroys all indexed data):${R}`);
|
|
389
|
+
console.log(` ${C}docker compose -f ~/.yats/docker-compose.yml down -v${R}`);
|
|
390
|
+
console.log("");
|
|
391
|
+
console.log(` Then re-run ${B}npx yats-toolkit${R}`);
|
|
392
|
+
console.log("");
|
|
393
|
+
process.exit(0);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// Step 1: Embedding provider
|
|
397
|
+
step("Step 1 — Embedding provider");
|
|
398
|
+
|
|
399
|
+
const provider = await choose("How should I generate embeddings for your code?", [
|
|
400
|
+
{ label: "Ollama (local, private, included) — recommended", value: "ollama" },
|
|
401
|
+
{ label: "OpenAI (cloud, needs API key)", value: "openai" },
|
|
402
|
+
{ label: "Mistral (cloud, needs API key)", value: "mistral" },
|
|
403
|
+
{ label: "Voyage AI (cloud, optimized for code, needs API key)", value: "voyage" },
|
|
404
|
+
]);
|
|
405
|
+
|
|
406
|
+
let apiKey = "";
|
|
407
|
+
let ollamaModel = "nomic-embed-text";
|
|
408
|
+
|
|
409
|
+
if (provider === "ollama") {
|
|
410
|
+
step("Step 2 — Ollama model");
|
|
411
|
+
ollamaModel = await choose("Which model?", [
|
|
412
|
+
{ label: "nomic-embed-text (768d, fast, ~274MB)", value: "nomic-embed-text" },
|
|
413
|
+
{ label: "mxbai-embed-large (1024d, more accurate, ~669MB)", value: "mxbai-embed-large" },
|
|
414
|
+
]);
|
|
415
|
+
} else {
|
|
416
|
+
const providerNames = { openai: "OpenAI", mistral: "Mistral", voyage: "Voyage AI" };
|
|
417
|
+
step(`Step 2 — ${providerNames[provider]} API key`);
|
|
418
|
+
const rl2 = createInterface({ input: process.stdin, output: process.stdout });
|
|
419
|
+
apiKey = await ask(rl2, ` ${B}Your ${providerNames[provider]} API key:${R} `);
|
|
420
|
+
rl2.close();
|
|
421
|
+
console.log("");
|
|
422
|
+
console.log(` ${Y}⚠${R} This is a paid service — you may be charged for API usage.`);
|
|
423
|
+
console.log("");
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// Step 3: Embedding batch size
|
|
427
|
+
const BATCH_DEFAULTS = {
|
|
428
|
+
openai: 200,
|
|
429
|
+
mistral: 200,
|
|
430
|
+
voyage: 100,
|
|
431
|
+
ollama: 4,
|
|
432
|
+
};
|
|
433
|
+
const BATCH_MAX = {
|
|
434
|
+
openai: 2048,
|
|
435
|
+
mistral: 1024,
|
|
436
|
+
voyage: 128,
|
|
437
|
+
ollama: 4,
|
|
438
|
+
};
|
|
439
|
+
const defaultBatch = BATCH_DEFAULTS[provider];
|
|
440
|
+
const maxBatch = BATCH_MAX[provider];
|
|
441
|
+
|
|
442
|
+
step(`Step 3 — Embedding batch size`);
|
|
443
|
+
console.log(` ${D}How many texts to embed per API request.${R}`);
|
|
444
|
+
console.log(` ${D}Higher = faster indexing, lower = safer for rate limits.${R}`);
|
|
445
|
+
console.log(` ${D}Provider max: ${maxBatch}${R}`);
|
|
446
|
+
console.log("");
|
|
447
|
+
|
|
448
|
+
const rlBatch = createInterface({ input: process.stdin, output: process.stdout });
|
|
449
|
+
const batchAnswer = await ask(rlBatch, ` ${B}Batch size${R} [${defaultBatch}]: `);
|
|
450
|
+
rlBatch.close();
|
|
451
|
+
let batchSize = defaultBatch;
|
|
452
|
+
const batchTrimmed = batchAnswer.trim();
|
|
453
|
+
if (batchTrimmed) {
|
|
454
|
+
const num = parseInt(batchTrimmed, 10);
|
|
455
|
+
if (num >= 1 && num <= maxBatch) {
|
|
456
|
+
batchSize = num;
|
|
457
|
+
} else {
|
|
458
|
+
console.log(` ${Y}⚠${R} Must be 1–${maxBatch}. Using default ${defaultBatch}.`);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
console.log(` ${G}✓${R} Batch size: ${batchSize}`);
|
|
462
|
+
console.log("");
|
|
463
|
+
|
|
464
|
+
// Step 4: Documentation indexing
|
|
465
|
+
const docMaxFiles = 300;
|
|
466
|
+
let indexDocs = true;
|
|
467
|
+
|
|
468
|
+
step("Step 4 — Documentation indexing");
|
|
469
|
+
console.log(` ${D}Index README, ARCHITECTURE, AI/ docs, and docs/ directory.${R}`);
|
|
470
|
+
console.log(` ${D}Patterns (edit via DOC_PATTERNS env): AI/*.md, README.md, docs/${R}`);
|
|
471
|
+
console.log(` ${D}If docs/ has >${docMaxFiles} .md files, you'll get a warning.${R}`);
|
|
472
|
+
console.log("");
|
|
473
|
+
|
|
474
|
+
const rlDocs = createInterface({ input: process.stdin, output: process.stdout });
|
|
475
|
+
const docsAnswer = await ask(rlDocs, ` ${B}Index documentation? [Y/n]${R} `);
|
|
476
|
+
rlDocs.close();
|
|
477
|
+
if (docsAnswer.toLowerCase() === "n") {
|
|
478
|
+
indexDocs = false;
|
|
479
|
+
console.log(` ${Y}⚠${R} Documentation indexing disabled. Set INDEX_DOCS=true to re-enable.`);
|
|
480
|
+
} else {
|
|
481
|
+
console.log(` ${G}✓${R} Documentation will be indexed.`);
|
|
482
|
+
}
|
|
483
|
+
console.log("");
|
|
484
|
+
|
|
485
|
+
// Optional: pre-index directories
|
|
486
|
+
step("Step 5 — Pre-index (optional)");
|
|
487
|
+
console.log(` ${D}Indexing happens automatically on first search.${R}`);
|
|
488
|
+
console.log(` ${D}Want to pre-index some directories now to skip the wait later?${R}`);
|
|
489
|
+
console.log("");
|
|
490
|
+
console.log(` ${D}Tip: type a path or drag-n-drop a folder from your file manager.${R}`);
|
|
491
|
+
|
|
492
|
+
const rl3 = createInterface({ input: process.stdin, output: process.stdout });
|
|
493
|
+
const pathsToIndex = [];
|
|
494
|
+
while (true) {
|
|
495
|
+
const p = await ask(rl3, ` ${B}Directory path (Enter to skip):${R} `);
|
|
496
|
+
const trimmed = p.trim();
|
|
497
|
+
if (!trimmed) break;
|
|
498
|
+
if (existsSync(trimmed)) {
|
|
499
|
+
pathsToIndex.push(trimmed);
|
|
500
|
+
console.log(` ${G}✓${R} Added: ${trimmed}`);
|
|
501
|
+
} else {
|
|
502
|
+
console.log(` ${RED}✗${R} Not found: ${trimmed}`);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
rl3.close();
|
|
506
|
+
console.log("");
|
|
507
|
+
|
|
508
|
+
// Port selection
|
|
509
|
+
let mcpPort = 5555;
|
|
510
|
+
{
|
|
511
|
+
const rlPort = createInterface({ input: process.stdin, output: process.stdout });
|
|
512
|
+
const inUse = await checkPort(mcpPort);
|
|
513
|
+
const suggested = inUse ? 5556 : mcpPort;
|
|
514
|
+
const hint = inUse ? ` ${Y}(default 5555 is in use)${R}` : "";
|
|
515
|
+
const answer = await ask(rlPort, ` ${B}MCP server port${R} [${suggested}]:${hint} `);
|
|
516
|
+
const trimmed = answer.trim();
|
|
517
|
+
if (trimmed) {
|
|
518
|
+
const num = parseInt(trimmed, 10);
|
|
519
|
+
if (num >= 1024 && num <= 65535) mcpPort = num;
|
|
520
|
+
} else {
|
|
521
|
+
mcpPort = suggested;
|
|
522
|
+
}
|
|
523
|
+
rlPort.close();
|
|
524
|
+
}
|
|
525
|
+
console.log(` ${G}✓${R} MCP server on ${C}http://localhost:${mcpPort}/mcp/sse${R}`);
|
|
526
|
+
console.log("");
|
|
527
|
+
|
|
528
|
+
// Step 5: Confirm
|
|
529
|
+
step(`Step ${pathsToIndex.length ? "6" : "5"} — Confirm`);
|
|
530
|
+
const providerName = provider === "ollama"
|
|
531
|
+
? `Ollama (${ollamaModel})`
|
|
532
|
+
: { openai: "OpenAI", mistral: "Mistral", voyage: "Voyage AI" }[provider];
|
|
533
|
+
|
|
534
|
+
box([
|
|
535
|
+
`${B}Provider:${R} ${providerName}`,
|
|
536
|
+
`${B}Port:${R} ${String(mcpPort)}`,
|
|
537
|
+
...(pathsToIndex.length ? [`${B}Pre-index:${R} ${String(pathsToIndex.length + " directorie(s)")}`] : []),
|
|
538
|
+
`${B}Batch:${R} ${String(batchSize)}`,
|
|
539
|
+
`${B}Index docs:${R} ${indexDocs ? "Yes (max " + docMaxFiles + " files)" : "No"}`,
|
|
540
|
+
`${B}API calls:${R} ${provider === "ollama" ? "None (runs locally)" : `To ${provider} API`}`,
|
|
541
|
+
`${B}Disk needed:${R} ${provider === "ollama" ? "~3GB" : "~1GB"}`,
|
|
542
|
+
]);
|
|
543
|
+
console.log("");
|
|
544
|
+
|
|
545
|
+
const proceed = await (() => {
|
|
546
|
+
const rl4 = createInterface({ input: process.stdin, output: process.stdout });
|
|
547
|
+
return ask(rl4, ` ${B}Proceed? [Y/n]${R} `).then((a) => { rl4.close(); return a; });
|
|
548
|
+
})();
|
|
549
|
+
if (proceed.toLowerCase() === "n") {
|
|
550
|
+
console.log("");
|
|
551
|
+
console.log(` Setup cancelled. Run ${B}npx yats-toolkit${R} anytime to try again.`);
|
|
552
|
+
console.log("");
|
|
553
|
+
process.exit(0);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// Install
|
|
557
|
+
console.log("");
|
|
558
|
+
step(`${D}Installing${R}`);
|
|
559
|
+
|
|
560
|
+
// Create directories
|
|
561
|
+
mkdirSync(YATS_DIR, { recursive: true });
|
|
562
|
+
mkdirSync(REPOS_DIR, { recursive: true });
|
|
563
|
+
|
|
564
|
+
// Generate and write docker-compose
|
|
565
|
+
const compose = generateCompose(provider, ollamaModel, apiKey, mcpPort, batchSize, indexDocs, docMaxFiles);
|
|
566
|
+
writeFileSync(COMPOSE_FILE, compose);
|
|
567
|
+
|
|
568
|
+
// Write MCP config
|
|
569
|
+
const mcpConfig = { mcpServers: { yats: { url: `http://localhost:${mcpPort}/mcp/sse` } } };
|
|
570
|
+
writeFileSync(MCP_CONFIG_FILE, JSON.stringify(mcpConfig, null, 2));
|
|
571
|
+
|
|
572
|
+
// Pull the YATS Docker image from GitHub Container Registry
|
|
573
|
+
const sPull = spinner("Pulling YATS image from registry...");
|
|
574
|
+
try {
|
|
575
|
+
await runCmd("docker", ["pull", "ghcr.io/fvinciarelli/yats:latest"]);
|
|
576
|
+
sPull.done(true);
|
|
577
|
+
} catch {
|
|
578
|
+
sPull.done(false);
|
|
579
|
+
console.log(` ${RED}Failed to pull YATS image. Is Docker running and internet accessible?${R}`);
|
|
580
|
+
process.exit(1);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
const sUp = spinner("Starting services (Neo4j, Qdrant, YATS)...");
|
|
584
|
+
try {
|
|
585
|
+
await runCmd("docker", ["compose", "-f", COMPOSE_FILE, "up", "-d"]);
|
|
586
|
+
sUp.done(true);
|
|
587
|
+
} catch {
|
|
588
|
+
sUp.done(false);
|
|
589
|
+
console.log(` ${RED}Failed to start Docker services. Check docker logs.${R}`);
|
|
590
|
+
process.exit(1);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
const sWait = spinner("Starting YATS server...");
|
|
594
|
+
const yatsOk = await waitForHealth(`http://localhost:${mcpPort}/health`, 60, 2000);
|
|
595
|
+
sWait.done(yatsOk);
|
|
596
|
+
|
|
597
|
+
if (!yatsOk) {
|
|
598
|
+
console.log("");
|
|
599
|
+
console.log(` ${RED}✗ YATS server failed to start within 2 minutes.${R}`);
|
|
600
|
+
console.log(` Check logs: ${C}docker compose -f ${COMPOSE_FILE} logs yats${R}`);
|
|
601
|
+
console.log("");
|
|
602
|
+
process.exit(1);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
// Pre-index directories if user added them
|
|
606
|
+
if (pathsToIndex.length > 0 && yatsOk) {
|
|
607
|
+
console.log("");
|
|
608
|
+
const sIndex = spinner(`Pre-indexing ${pathsToIndex.length} directorie(s)...`);
|
|
609
|
+
try {
|
|
610
|
+
for (const dir of pathsToIndex) {
|
|
611
|
+
const repoName = dir.split("/").pop() || dir;
|
|
612
|
+
// Path inside the container: repos are mounted under /repos/
|
|
613
|
+
const containerPath = `/repos/${repoName}`;
|
|
614
|
+
await fetch(`http://localhost:${mcpPort}/index`, {
|
|
615
|
+
method: "POST",
|
|
616
|
+
headers: { "Content-Type": "application/json" },
|
|
617
|
+
body: JSON.stringify({ path: containerPath }),
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
sIndex.done(true);
|
|
621
|
+
} catch {
|
|
622
|
+
sIndex.done(false);
|
|
623
|
+
console.log(` ${Y}Index endpoint not ready yet. Repos will be indexed on first search.${R}`);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// Done
|
|
628
|
+
console.log("");
|
|
629
|
+
console.log(` ✅ ${G}YATS is ready!${R}`);
|
|
630
|
+
divider();
|
|
631
|
+
console.log("");
|
|
632
|
+
console.log(` ${B}MCP configuration for your AI agent:${R}`);
|
|
633
|
+
console.log("");
|
|
634
|
+
|
|
635
|
+
box([
|
|
636
|
+
`${B}For Cursor, Zed, Cline, Continue.dev, Roo Code:${R}`,
|
|
637
|
+
`{ "url": "http://localhost:${mcpPort}/mcp/sse" }`,
|
|
638
|
+
"",
|
|
639
|
+
`${B}For Copilot, Claude Desktop (stdio only):${R}`,
|
|
640
|
+
`{ "command": "npx", "args": ["yats-bridge"] }`,
|
|
641
|
+
]);
|
|
642
|
+
console.log("");
|
|
643
|
+
console.log(` Config saved to ${C}${MCP_CONFIG_FILE}${R}`);
|
|
644
|
+
divider();
|
|
645
|
+
console.log("");
|
|
646
|
+
console.log(` ${B}How it works:${R}`);
|
|
647
|
+
console.log("");
|
|
648
|
+
console.log(` Just ask your AI agent about your code.`);
|
|
649
|
+
console.log(` The index builds automatically on the first search.`);
|
|
650
|
+
console.log("");
|
|
651
|
+
console.log(` Example: "${D}how does authentication work in my project?${R}"`);
|
|
652
|
+
console.log("");
|
|
653
|
+
console.log(` ${B}Commands:${R}`);
|
|
654
|
+
console.log(` yats add ~/work/project Add a repo to index`);
|
|
655
|
+
console.log(` yats status Check what's indexed`);
|
|
656
|
+
console.log(` yats stop Stop all services`);
|
|
657
|
+
console.log(` yats update Update to latest version`);
|
|
658
|
+
console.log("");
|
|
659
|
+
console.log(` Docs: ${C}https://yats.site${R}`);
|
|
660
|
+
console.log("");
|
|
661
|
+
}
|
|
662
|
+
export default main;
|
package/src/status.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** yats status — Check indexed repos via YATS MCP */
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
|
|
4
|
+
const YATS_URL = process.env.YATS_URL || "http://localhost:5555";
|
|
5
|
+
|
|
6
|
+
export default async function status() {
|
|
7
|
+
// Check Docker status
|
|
8
|
+
try {
|
|
9
|
+
const res = await fetch(`${YATS_URL}/health`);
|
|
10
|
+
const data = await res.json();
|
|
11
|
+
console.log(` YATS: ${data.status} (sessions: ${data.sessions || 0})`);
|
|
12
|
+
} catch {
|
|
13
|
+
console.log(" YATS: not running");
|
|
14
|
+
console.log(` Start with: npx yats setup`);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Get repos via MCP
|
|
19
|
+
try {
|
|
20
|
+
const res = await fetch(`${YATS_URL}/mcp`, {
|
|
21
|
+
method: "POST",
|
|
22
|
+
headers: { "Content-Type": "application/json" },
|
|
23
|
+
body: JSON.stringify({
|
|
24
|
+
jsonrpc: "2.0",
|
|
25
|
+
id: 1,
|
|
26
|
+
method: "tools/call",
|
|
27
|
+
params: { name: "list_repositories", arguments: {} },
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
30
|
+
const data = await res.json();
|
|
31
|
+
const repos = JSON.parse(data?.result?.content?.[0]?.text || "[]");
|
|
32
|
+
if (repos.length === 0) {
|
|
33
|
+
console.log(" No indexed repositories.");
|
|
34
|
+
} else {
|
|
35
|
+
console.log(" Indexed repositories:");
|
|
36
|
+
for (const r of repos) {
|
|
37
|
+
console.log(` ${r.name} → ${r.rootPath}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
} catch {
|
|
41
|
+
console.log(" Could not fetch repository list.");
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/stop.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** yats stop — Stop all YATS Docker services */
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
|
|
6
|
+
export default async function stop() {
|
|
7
|
+
const composeFile = join(homedir(), ".yats", "docker-compose.yml");
|
|
8
|
+
console.log("Stopping YATS services...");
|
|
9
|
+
await new Promise((resolve, reject) => {
|
|
10
|
+
const proc = spawn("docker", ["compose", "-f", composeFile, "down"], { stdio: "inherit" });
|
|
11
|
+
proc.on("close", (code) => code === 0 ? resolve() : reject(new Error(`exit ${code}`)));
|
|
12
|
+
proc.on("error", reject);
|
|
13
|
+
});
|
|
14
|
+
console.log("YATS stopped.");
|
|
15
|
+
}
|