yats-toolkit 0.1.11 → 0.1.13
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/benchmark/README.md +54 -0
- package/benchmark/questions/csharp/Carter/01-modules.md +1 -0
- package/benchmark/questions/csharp/Carter/02-handlers.md +1 -0
- package/benchmark/questions/csharp/MediatR/01-pipeline.md +1 -0
- package/benchmark/questions/csharp/MediatR/02-dispatch.md +1 -0
- package/benchmark/questions/csharp/eShopOnWeb/01-repository.md +1 -0
- package/benchmark/questions/csharp/eShopOnWeb/02-architecture.md +1 -0
- package/benchmark/questions/go/gin/01-middleware.md +1 -0
- package/benchmark/questions/go/gin/02-routing.md +1 -0
- package/benchmark/questions/go/lab_hub/01-protocol-translation.md +1 -0
- package/benchmark/questions/go/lab_hub/02-bidirectional-flow.md +1 -0
- package/benchmark/questions/go/terraform/01-providers.md +1 -0
- package/benchmark/questions/go/terraform/02-graph.md +1 -0
- package/benchmark/questions/php/laravel/01-container.md +1 -0
- package/benchmark/questions/php/laravel/02-routing.md +1 -0
- package/benchmark/questions/php/symfony/01-dependency-injection.md +1 -0
- package/benchmark/questions/php/symfony/02-event-dispatcher.md +1 -0
- package/benchmark/questions/python/01-middleware.md +8 -0
- package/benchmark/questions/python/02-routing.md +9 -0
- package/benchmark/questions/python/django/01-middleware.md +1 -0
- package/benchmark/questions/python/django/01-orm.md +1 -0
- package/benchmark/questions/python/fastapi/01-middleware.md +1 -0
- package/benchmark/questions/python/fastapi/02-routing.md +1 -0
- package/benchmark/questions/typescript/nestjs/01-decorators.md +1 -0
- package/benchmark/questions/typescript/nestjs/02-modules.md +1 -0
- package/benchmark/questions/typescript/nextjs/01-rendering.md +1 -0
- package/benchmark/questions/typescript/nextjs/02-routing.md +1 -0
- package/benchmark/run.sh +288 -0
- package/benchmark/scripts/compare-codex-mcp.sh +94 -0
- package/benchmark/scripts/compare.py +42 -0
- package/benchmark/scripts/parse-copilot.sh +34 -0
- package/benchmark/scripts/report.py +123 -0
- package/benchmark/targets/repos.json +23 -0
- package/package.json +5 -1
- package/src/bridge.js +158 -75
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# YATS Benchmark
|
|
2
|
+
|
|
3
|
+
Measures how many tokens YATS saves when an AI agent answers questions about a codebase.
|
|
4
|
+
|
|
5
|
+
## What it measures
|
|
6
|
+
|
|
7
|
+
For each question, the agent answers twice on a fresh LLM context:
|
|
8
|
+
|
|
9
|
+
| | Tools available |
|
|
10
|
+
|---|---|
|
|
11
|
+
| **Without YATS** | `read_file`, `grep` — reads source files directly |
|
|
12
|
+
| **With YATS** | `search_code`, `find_symbol`, `find_callers`, etc. — queries knowledge graph |
|
|
13
|
+
|
|
14
|
+
Metrics collected:
|
|
15
|
+
- **Time**: how long the agent took to answer
|
|
16
|
+
- **Input tokens**: tokens sent to the LLM
|
|
17
|
+
- **Output tokens**: tokens generated by the LLM
|
|
18
|
+
- **Savings**: percentage of tokens saved with YATS vs without
|
|
19
|
+
|
|
20
|
+
## How to run
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# 1. Make sure YATS is running
|
|
24
|
+
yats status
|
|
25
|
+
|
|
26
|
+
# 2. Run the wizard
|
|
27
|
+
./run.sh
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The wizard will:
|
|
31
|
+
1. Let you pick an agent (Cursor, Claude CLI, Codex)
|
|
32
|
+
2. Pick a language and repo (auto-cloned + indexed if needed)
|
|
33
|
+
3. Pick which questions to run
|
|
34
|
+
4. Run each question, measure everything
|
|
35
|
+
5. Show a results table
|
|
36
|
+
6. Save to `results/`
|
|
37
|
+
|
|
38
|
+
## Results format
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"agent": "cursor",
|
|
43
|
+
"repo": "fastapi/fastapi",
|
|
44
|
+
"language": "python",
|
|
45
|
+
"questions": [
|
|
46
|
+
{
|
|
47
|
+
"name": "01-middleware",
|
|
48
|
+
"without_yats": { "time_ms": 4500, "input_tokens": 8200, "output_tokens": 350 },
|
|
49
|
+
"with_yats": { "time_ms": 1200, "input_tokens": 800, "output_tokens": 280 },
|
|
50
|
+
"savings_pct": 89
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does Carter implement minimal API modules? Find ICarterModule and how routes are registered.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does Carter handle request/response processing? Find the route handlers, binding, and response negotiation.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does MediatR's request pipeline work? Find IRequestHandler and IPipelineBehavior interfaces and how they compose the pipeline.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does MediatR dispatch requests to handlers? Find the IMediator interface, Send method, and how handlers are resolved.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does eShopOnWeb implement the repository pattern? Find the Repository and Specification classes and their interfaces.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does eShopOnWeb organize its architecture? Find Controllers, Services, Entities, and DTOs and how they depend on each other.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does Gin handle middleware? Find the middleware chain implementation and how custom middleware is registered.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does Gin's router work? Trace how HTTP verbs and path patterns are registered and how requests are dispatched to handlers.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does Hub Lab identify instruments and translate their protocols? Trace the flow from receiving a raw ASTM/HL7/CSV message from an analyzer to delivering a normalized FHIR result to the LIS. What key components handle identification, translation, normalization, and delivery?
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does the bidirectional flow work in Hub Lab? Trace both paths: (1) orders from LIS to analyzer and (2) results from analyzer back to LIS. What are the key components and how do they handle the different protocols, validation, and the audit trail?
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does Terraform's provider system work? Find how providers are registered, configured, and how the plugin system operates.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does Terraform build and walk the dependency graph? Find the graph construction and traversal algorithms.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does Laravel's service container work? Find the binding resolution, contextual binding, and automatic injection.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does Laravel handle HTTP routing? Find the route registration, middleware pipeline, and controller dispatch.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does Symfony's dependency injection container work? Find the compiled container, service definitions, and autowiring.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does Symfony's event dispatcher work? Find how events are registered, dispatched, and how listeners/subscribers are resolved.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
## Question: How does middleware work in FastAPI?
|
|
2
|
+
|
|
3
|
+
Find and explain the middleware stack: how middleware is registered, in what order it executes, and what built-in middleware FastAPI provides.
|
|
4
|
+
|
|
5
|
+
### Expected answer should cover:
|
|
6
|
+
- The `build_middleware_stack` method in `fastapi/applications.py`
|
|
7
|
+
- Order: ServerErrorMiddleware → user middleware → ExceptionMiddleware → AsyncExitStackMiddleware
|
|
8
|
+
- How `@app.middleware("http")` registers custom middleware
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
## Question: How is routing implemented in FastAPI?
|
|
2
|
+
|
|
3
|
+
Trace how HTTP routes are registered, stored, and dispatched. Find the key classes and methods involved.
|
|
4
|
+
|
|
5
|
+
### Expected answer should cover:
|
|
6
|
+
- `APIRouter` class and its `add_api_route` method
|
|
7
|
+
- How decorators like `@app.get("/path")` register routes
|
|
8
|
+
- The relationship between `Route`, `APIRoute`, and path operations
|
|
9
|
+
- How dependencies are injected into route handlers
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does Django's middleware system work? Find the middleware chain and how request/response processing flows through it.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does Django's ORM work? Trace how a model query like `User.objects.filter(name="John")` gets translated to SQL and executed.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does middleware work in FastAPI? Trace the registration, ordering, and execution of the middleware stack.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How are HTTP routes registered and dispatched in FastAPI? Find the key classes responsible for routing.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does NestJS use decorators for dependency injection and route registration? Find the key decorator implementations.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does NestJS module system work? Trace how modules are defined, imported, and how providers are resolved across module boundaries.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does Next.js handle server-side rendering vs static generation? Find the key functions and components involved.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
How does Next.js file-based routing work? Find the routing implementation and how dynamic routes are resolved.
|
package/benchmark/run.sh
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -e
|
|
3
|
+
# YATS Benchmark — Interactive wizard
|
|
4
|
+
|
|
5
|
+
B='\033[1m'; D='\033[2m'; R='\033[0m'
|
|
6
|
+
G='\033[32m'; Y='\033[33m'; C='\033[36m'; RED='\033[31m'
|
|
7
|
+
|
|
8
|
+
BENCH_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
9
|
+
AGENTS_DIR="$BENCH_DIR/agents"
|
|
10
|
+
QUESTIONS_DIR="$BENCH_DIR/questions"
|
|
11
|
+
RESULTS_DIR="$BENCH_DIR/results"
|
|
12
|
+
mkdir -p "$RESULTS_DIR"
|
|
13
|
+
|
|
14
|
+
echo -e ""
|
|
15
|
+
echo -e " ╔══════════════════════════════════════════════════════╗"
|
|
16
|
+
echo -e " ║ YATS Benchmark ║"
|
|
17
|
+
echo -e " ╚══════════════════════════════════════════════════════╝"
|
|
18
|
+
echo -e ""
|
|
19
|
+
|
|
20
|
+
# Step 1: Agent
|
|
21
|
+
echo -e " ${B}Step 1 — AI Agent${R}"
|
|
22
|
+
echo -e ""
|
|
23
|
+
agents=("cursor" "claude-cli" "copilot-cli" "codex" "gemini")
|
|
24
|
+
labels=("Cursor" "Claude CLI" "GitHub Copilot CLI" "VS Code Codex" "Gemini CLI")
|
|
25
|
+
for i in "${!labels[@]}"; do
|
|
26
|
+
echo -e " ${B}$((i+1))${R}. ${labels[$i]}"
|
|
27
|
+
done
|
|
28
|
+
echo -e ""
|
|
29
|
+
read -p " Pick [1-${#agents[@]}]: " c
|
|
30
|
+
AGENT="${agents[$((c-1))]}"
|
|
31
|
+
[ -z "$AGENT" ] && echo -e " ${RED}Invalid${R}" && exit 1
|
|
32
|
+
echo -e " ${G}✓${R} ${labels[$((c-1))]}"
|
|
33
|
+
echo -e ""
|
|
34
|
+
|
|
35
|
+
# Step 2: Language
|
|
36
|
+
echo -e " ${B}Step 2 — Language${R}"
|
|
37
|
+
echo -e ""
|
|
38
|
+
langs=($(ls -d "$QUESTIONS_DIR"/*/ | xargs -n1 basename))
|
|
39
|
+
for i in "${!langs[@]}"; do
|
|
40
|
+
echo -e " ${B}$((i+1))${R}. ${langs[$i]}"
|
|
41
|
+
done
|
|
42
|
+
echo -e ""
|
|
43
|
+
read -p " Pick [1-${#langs[@]}]: " c
|
|
44
|
+
LANG="${langs[$((c-1))]}"
|
|
45
|
+
[ -z "$LANG" ] && echo -e " ${RED}Invalid${R}" && exit 1
|
|
46
|
+
echo -e " ${G}✓${R} $LANG"
|
|
47
|
+
echo -e ""
|
|
48
|
+
|
|
49
|
+
# Step 3: Repo
|
|
50
|
+
echo -e " ${B}Step 3 — Repository${R}"
|
|
51
|
+
echo -e ""
|
|
52
|
+
repos=($(ls -d "$QUESTIONS_DIR/$LANG"/*/ | xargs -n1 basename))
|
|
53
|
+
for i in "${!repos[@]}"; do
|
|
54
|
+
echo -e " ${B}$((i+1))${R}. ${repos[$i]}"
|
|
55
|
+
done
|
|
56
|
+
echo -e ""
|
|
57
|
+
read -p " Pick [1-${#repos[@]}]: " c
|
|
58
|
+
REPO="${repos[$((c-1))]}"
|
|
59
|
+
[ -z "$REPO" ] && echo -e " ${RED}Invalid${R}" && exit 1
|
|
60
|
+
echo -e " ${G}✓${R} $REPO"
|
|
61
|
+
echo -e ""
|
|
62
|
+
|
|
63
|
+
# Step 3.5: Working directory for repo clone
|
|
64
|
+
echo -e " ${B}Step 3.5 — Working directory${R}"
|
|
65
|
+
echo -e " ${D}Directory where repos will be cloned for the agent to work on${R}"
|
|
66
|
+
echo -e ""
|
|
67
|
+
default_workdir="${YATS_BENCH_WORKDIR:-$HOME/yats-bench-repos}"
|
|
68
|
+
read -p " Path [${default_workdir}]: " workdir_input
|
|
69
|
+
WORKDIR="${workdir_input:-$default_workdir}"
|
|
70
|
+
mkdir -p "$WORKDIR"
|
|
71
|
+
echo -e " ${G}✓${R} $WORKDIR"
|
|
72
|
+
echo -e ""
|
|
73
|
+
|
|
74
|
+
# Clone repo if needed
|
|
75
|
+
REPO_DIR="$WORKDIR/$REPO"
|
|
76
|
+
REPO_URL=$(python3 -c "
|
|
77
|
+
import json
|
|
78
|
+
with open('$BENCH_DIR/targets/repos.json') as f:
|
|
79
|
+
data = json.load(f)
|
|
80
|
+
for r in data.get('$LANG', []):
|
|
81
|
+
if r['name'] == '$REPO':
|
|
82
|
+
print(r['url'])
|
|
83
|
+
break
|
|
84
|
+
" 2>/dev/null)
|
|
85
|
+
|
|
86
|
+
if [ ! -d "$REPO_DIR/.git" ]; then
|
|
87
|
+
if [ -n "$REPO_URL" ]; then
|
|
88
|
+
echo -e " ${D}Cloning $REPO from $REPO_URL...${R}"
|
|
89
|
+
git clone --depth 1 "$REPO_URL" "$REPO_DIR" 2>&1 | tail -1
|
|
90
|
+
echo -e " ${G}✓${R} Cloned to $REPO_DIR"
|
|
91
|
+
else
|
|
92
|
+
echo -e " ${Y}⚠ No URL in targets/repos.json — using existing $REPO_DIR if any${R}"
|
|
93
|
+
fi
|
|
94
|
+
else
|
|
95
|
+
echo -e " ${G}✓${R} Repo already exists at $REPO_DIR"
|
|
96
|
+
fi
|
|
97
|
+
echo -e ""
|
|
98
|
+
|
|
99
|
+
# Index repo in YATS if needed
|
|
100
|
+
YATS_HEALTH=$(curl -s -m 3 http://localhost:5555/health 2>/dev/null || echo '')
|
|
101
|
+
if [ -n "$YATS_HEALTH" ]; then
|
|
102
|
+
echo -e " ${D}Checking if $REPO is indexed...${R}"
|
|
103
|
+
if yats list 2>/dev/null | grep -q "^ $REPO "; then
|
|
104
|
+
echo -e " ${G}✓${R} Already indexed"
|
|
105
|
+
else
|
|
106
|
+
echo -e " ${D}Indexing $REPO (this may take a while)...${R}"
|
|
107
|
+
yats index "$REPO_DIR" 2>&1 | tail -3
|
|
108
|
+
echo -e " ${G}✓${R} Indexed as '$REPO'"
|
|
109
|
+
fi
|
|
110
|
+
else
|
|
111
|
+
echo -e " ${Y}⚠ YATS not running — skip indexing. Start with: yats start${R}"
|
|
112
|
+
fi
|
|
113
|
+
echo -e ""
|
|
114
|
+
|
|
115
|
+
# Export for run-agent.sh
|
|
116
|
+
export YATS_BENCH_REPO_DIR="$REPO_DIR"
|
|
117
|
+
export YATS_BENCH_REPO_NAME="$REPO"
|
|
118
|
+
|
|
119
|
+
# Step 4: Questions
|
|
120
|
+
echo -e " ${B}Step 4 — Questions${R}"
|
|
121
|
+
echo -e ""
|
|
122
|
+
questions=($(ls "$QUESTIONS_DIR/$LANG/$REPO"/*.md | sort))
|
|
123
|
+
selected=()
|
|
124
|
+
for i in "${!questions[@]}"; do
|
|
125
|
+
qname=$(basename "${questions[$i]}" .md)
|
|
126
|
+
read -p " Run ${qname}? [Y/n] " yn
|
|
127
|
+
if [ "$yn" != "n" ]; then
|
|
128
|
+
selected+=("${questions[$i]}")
|
|
129
|
+
echo -e " ${G}✓${R} $qname"
|
|
130
|
+
else
|
|
131
|
+
echo -e " ${D}✗${R} $qname"
|
|
132
|
+
fi
|
|
133
|
+
done
|
|
134
|
+
[ ${#selected[@]} -eq 0 ] && echo -e " ${RED}None selected${R}" && exit 1
|
|
135
|
+
echo -e ""
|
|
136
|
+
|
|
137
|
+
# Step 5: Confirm
|
|
138
|
+
echo -e " ${B}${#selected[@]} question(s) on $REPO${R}"
|
|
139
|
+
read -p " Proceed? [Y/n] " yn
|
|
140
|
+
[ "$yn" = "n" ] && echo -e " Cancelled." && exit 0
|
|
141
|
+
|
|
142
|
+
echo -e ""
|
|
143
|
+
echo -e " ${D}───────────────────────────────────────────────────────${R}"
|
|
144
|
+
echo -e ""
|
|
145
|
+
|
|
146
|
+
# Extract tokens from stream-json
|
|
147
|
+
extract_tokens_and_model() {
|
|
148
|
+
python3 -c "
|
|
149
|
+
import json
|
|
150
|
+
total = 0
|
|
151
|
+
nanoaiu = 0
|
|
152
|
+
model = ''
|
|
153
|
+
cost = 0
|
|
154
|
+
try:
|
|
155
|
+
with open('$1') as f:
|
|
156
|
+
for line in f:
|
|
157
|
+
line = line.strip()
|
|
158
|
+
if not line: continue
|
|
159
|
+
try: evt = json.loads(line)
|
|
160
|
+
except: continue
|
|
161
|
+
t = evt.get('type','')
|
|
162
|
+
# Capture model from first init/system event
|
|
163
|
+
if not model:
|
|
164
|
+
if t == 'init':
|
|
165
|
+
model = evt.get('model','')
|
|
166
|
+
elif t == 'system' and evt.get('subtype') == 'init':
|
|
167
|
+
model = evt.get('model','')
|
|
168
|
+
elif t == 'session.tools_updated':
|
|
169
|
+
model = evt.get('data',{}).get('model','')
|
|
170
|
+
elif t == 'tool.execution_start':
|
|
171
|
+
model = evt.get('data',{}).get('model','')
|
|
172
|
+
# Cursor/Claude: result events
|
|
173
|
+
if t in ('result','message'):
|
|
174
|
+
u = evt.get('usage',{})
|
|
175
|
+
total += u.get('input_tokens',0) + u.get('output_tokens',0) + u.get('cache_read_input_tokens',0) + u.get('cache_read_tokens',0)
|
|
176
|
+
# Codex: turn.completed events
|
|
177
|
+
if t == 'turn.completed':
|
|
178
|
+
u = evt.get('usage',{})
|
|
179
|
+
total += u.get('input_tokens',0) + u.get('cached_input_tokens',0) + u.get('output_tokens',0) + u.get('reasoning_output_tokens',0)
|
|
180
|
+
# Copilot: assistant.usage events OR nanoAiu from usage_checkpoint
|
|
181
|
+
if t == 'assistant.usage':
|
|
182
|
+
total += evt.get('inputTokens',0) + evt.get('outputTokens',0) + evt.get('cacheReadTokens',0)
|
|
183
|
+
if t == 'session.usage_checkpoint':
|
|
184
|
+
nanoaiu = evt.get('data',{}).get('totalNanoAiu', 0)
|
|
185
|
+
# Claude: total_cost_usd in wrapper events
|
|
186
|
+
if 'total_cost_usd' in evt:
|
|
187
|
+
cost = max(cost, evt.get('total_cost_usd', 0))
|
|
188
|
+
# Gemini: result events with stats
|
|
189
|
+
if t == 'result':
|
|
190
|
+
s = evt.get('stats',{})
|
|
191
|
+
total += s.get('input_tokens',0) + s.get('output_tokens',0)
|
|
192
|
+
if not model:
|
|
193
|
+
models = s.get('models',{})
|
|
194
|
+
if models:
|
|
195
|
+
model = list(models.keys())[0]
|
|
196
|
+
except: pass
|
|
197
|
+
# If Copilot, use nanoAiu as the metric (no token events)
|
|
198
|
+
if nanoaiu > 0 and total == 0:
|
|
199
|
+
total = nanoaiu
|
|
200
|
+
print(json.dumps({'tokens': total, 'model': model, 'cost': cost}))
|
|
201
|
+
" 2>/dev/null || echo '{"tokens":0,"model":""}'
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
TIMESTAMP=$(date +%Y-%m-%dT%H:%M:%S)
|
|
205
|
+
results_json="[]"
|
|
206
|
+
|
|
207
|
+
YATS_MCP="$AGENTS_DIR/yats-mcp.json"
|
|
208
|
+
# Gemini, Copilot, and Codex use stdio bridge; Cursor and Claude use HTTP
|
|
209
|
+
if [ "$AGENT" = "gemini" ] || [ "$AGENT" = "copilot-cli" ] || [ "$AGENT" = "codex" ]; then
|
|
210
|
+
cat > "$YATS_MCP" << 'MCPEOF'
|
|
211
|
+
{
|
|
212
|
+
"mcpServers": {
|
|
213
|
+
"yats": {
|
|
214
|
+
"command": "node",
|
|
215
|
+
"args": ["/home/franco/cosas/code_indexer/packages/yats-toolkit/benchmark/adapters/mcp-bridge-stdio.cjs", "--stdio"],
|
|
216
|
+
"trust": true
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
MCPEOF
|
|
221
|
+
else
|
|
222
|
+
cat > "$YATS_MCP" << 'MCPEOF'
|
|
223
|
+
{ "mcpServers": { "yats": { "url": "http://localhost:5555/mcp" } } }
|
|
224
|
+
MCPEOF
|
|
225
|
+
fi
|
|
226
|
+
|
|
227
|
+
for qfile in "${selected[@]}"; do
|
|
228
|
+
qname=$(basename "$qfile" .md)
|
|
229
|
+
echo -e " ${B}${qname}${R}"
|
|
230
|
+
|
|
231
|
+
# Without YATS
|
|
232
|
+
echo -ne " ${D}without YATS...${R} "
|
|
233
|
+
bash "$AGENTS_DIR/run-agent.sh" "$AGENT" "$qfile" "" > /tmp/yats-bench-without.jsonl 2>/dev/null || true
|
|
234
|
+
without_result=$(extract_tokens_and_model /tmp/yats-bench-without.jsonl)
|
|
235
|
+
without_total=$(echo "$without_result" | python3 -c "import json,sys; print(json.load(sys.stdin)['tokens'])" 2>/dev/null || echo 0)
|
|
236
|
+
without_model=$(echo "$without_result" | python3 -c "import json,sys; print(json.load(sys.stdin).get('model',''))" 2>/dev/null || echo "")
|
|
237
|
+
|
|
238
|
+
# With YATS
|
|
239
|
+
echo -ne "${D}with YATS...${R} "
|
|
240
|
+
bash "$AGENTS_DIR/run-agent.sh" "$AGENT" "$qfile" "$YATS_MCP" > /tmp/yats-bench-with.jsonl 2>/dev/null || true
|
|
241
|
+
with_result=$(extract_tokens_and_model /tmp/yats-bench-with.jsonl)
|
|
242
|
+
with_total=$(echo "$with_result" | python3 -c "import json,sys; print(json.load(sys.stdin)['tokens'])" 2>/dev/null || echo 0)
|
|
243
|
+
with_model=$(echo "$with_result" | python3 -c "import json,sys; print(json.load(sys.stdin).get('model',''))" 2>/dev/null || echo "")
|
|
244
|
+
without_cost=$(echo "$without_result" | python3 -c "import json,sys; print(json.load(sys.stdin).get('cost',0))" 2>/dev/null || echo 0)
|
|
245
|
+
with_cost=$(echo "$with_result" | python3 -c "import json,sys; print(json.load(sys.stdin).get('cost',0))" 2>/dev/null || echo 0)
|
|
246
|
+
|
|
247
|
+
if [ "$without_total" -gt 0 ]; then
|
|
248
|
+
savings=$((100 - (with_total * 100 / without_total)))
|
|
249
|
+
else
|
|
250
|
+
savings=0
|
|
251
|
+
fi
|
|
252
|
+
|
|
253
|
+
echo -e "${G}${savings}% saved${R} (${without_total} → ${with_total} tokens)"
|
|
254
|
+
|
|
255
|
+
result=$(python3 -c "
|
|
256
|
+
import json
|
|
257
|
+
r = {'question':'$qname','without_tokens':$without_total,'with_tokens':$with_total,'savings_pct':$savings,'model':'$with_model' if '$with_model' else '$without_model','without_cost':$without_cost,'with_cost':$with_cost}
|
|
258
|
+
print(json.dumps(r))
|
|
259
|
+
" 2>/dev/null)
|
|
260
|
+
results_json=$(python3 -c "import json; r=json.loads('$results_json'); r.append($result); print(json.dumps(r))" 2>/dev/null)
|
|
261
|
+
echo -e ""
|
|
262
|
+
done
|
|
263
|
+
|
|
264
|
+
# Save
|
|
265
|
+
output="$RESULTS_DIR/${LANG}_${REPO}_${AGENT}_${TIMESTAMP}.json"
|
|
266
|
+
python3 -c "
|
|
267
|
+
import json
|
|
268
|
+
data = {'agent':'$AGENT','repo':'$REPO','language':'$LANG','timestamp':'$TIMESTAMP','questions':json.loads('$results_json')}
|
|
269
|
+
with open('$output','w') as f: json.dump(data, f, indent=2)
|
|
270
|
+
" 2>/dev/null
|
|
271
|
+
|
|
272
|
+
# Table
|
|
273
|
+
echo -e " ${D}───────────────────────────────────────────────────────${R}"
|
|
274
|
+
echo -e ""
|
|
275
|
+
echo -e " ${B}Results${R}"
|
|
276
|
+
echo -e ""
|
|
277
|
+
python3 -c "
|
|
278
|
+
import json
|
|
279
|
+
data = json.loads('$results_json')
|
|
280
|
+
print(' ┌────────────────────────┬──────────┬──────────┬──────────┬──────────────────────┐')
|
|
281
|
+
print(' │ Question │ W/o YATS │ With YATS│ Savings │ Model │')
|
|
282
|
+
print(' ├────────────────────────┼──────────┼──────────┼──────────┼──────────────────────┤')
|
|
283
|
+
for q in data:
|
|
284
|
+
print(f\" │ {q['question'][:22]:<22} │ {q['without_tokens']:>5}t │ {q['with_tokens']:>5}t │ {q['savings_pct']:>3}% │\")
|
|
285
|
+
print(' └────────────────────────┴──────────┴──────────┴──────────┴──────────────────────┘')
|
|
286
|
+
print(f\"\\n Saved to $output\")
|
|
287
|
+
" 2>/dev/null
|
|
288
|
+
echo -e ""
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
# Compare the same Codex prompt with YATS enabled and disabled.
|
|
4
|
+
# Run from the repository root:
|
|
5
|
+
# ./scripts/compare-codex-mcp.sh
|
|
6
|
+
# Or provide a different prompt:
|
|
7
|
+
# ./scripts/compare-codex-mcp.sh 'Explain the authentication flow in FastAPI.'
|
|
8
|
+
|
|
9
|
+
set -euo pipefail
|
|
10
|
+
|
|
11
|
+
readonly SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
|
12
|
+
# The benchmark script lives under .plans/, so its parent is not the repository root.
|
|
13
|
+
# Git finds the actual project root regardless of the script's location inside it.
|
|
14
|
+
readonly REPOSITORY_ROOT="$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel)"
|
|
15
|
+
readonly RUN_ID="$(date +%Y%m%dT%H%M%S)"
|
|
16
|
+
readonly OUTPUT_DIR="${OUTPUT_DIR:-$REPOSITORY_ROOT/artifacts/codex-mcp-comparison/$RUN_ID}"
|
|
17
|
+
readonly DEFAULT_PROMPT='Explain how FastAPI resolves dependency injection. If YATS is available, consult it before answering. Mention get_dependant, Dependant, and solve_dependencies. Do not modify files. Maximum 200 words.'
|
|
18
|
+
readonly PROMPT="${1:-$DEFAULT_PROMPT}"
|
|
19
|
+
|
|
20
|
+
require_command() {
|
|
21
|
+
command -v "$1" >/dev/null 2>&1 || {
|
|
22
|
+
echo "Required command not found: $1" >&2
|
|
23
|
+
exit 127
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
require_command codex
|
|
28
|
+
require_command jq
|
|
29
|
+
|
|
30
|
+
if [[ ! -f "$REPOSITORY_ROOT/.codex/config.toml" ]] || ! grep -q '^\[mcp_servers\.yats\]' "$REPOSITORY_ROOT/.codex/config.toml"; then
|
|
31
|
+
echo "YATS is not configured in $REPOSITORY_ROOT/.codex/config.toml" >&2
|
|
32
|
+
exit 2
|
|
33
|
+
fi
|
|
34
|
+
|
|
35
|
+
mkdir -p "$OUTPUT_DIR"
|
|
36
|
+
|
|
37
|
+
write_summary_header() {
|
|
38
|
+
printf 'case\texit_code\telapsed_ms\tinput_tokens\tcached_input_tokens\toutput_tokens\treasoning_output_tokens\tmcp_tool_events\n' > "$OUTPUT_DIR/summary.tsv"
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
append_summary() {
|
|
42
|
+
local case_name="$1"
|
|
43
|
+
local exit_code="$2"
|
|
44
|
+
local elapsed_ms="$3"
|
|
45
|
+
local jsonl_file="$4"
|
|
46
|
+
local usage
|
|
47
|
+
local mcp_tool_events
|
|
48
|
+
|
|
49
|
+
usage="$(jq -r 'select(.type == "turn.completed") | [.usage.input_tokens // 0, .usage.cached_input_tokens // 0, .usage.output_tokens // 0, .usage.reasoning_output_tokens // 0] | @tsv' "$jsonl_file" | tail -n 1)"
|
|
50
|
+
usage="${usage:-$'0\t0\t0\t0'}"
|
|
51
|
+
mcp_tool_events="$(grep -c '"mcp_tool_call"' "$jsonl_file" || true)"
|
|
52
|
+
|
|
53
|
+
printf '%s\t%s\t%s\t%s\t%s\n' "$case_name" "$exit_code" "$elapsed_ms" "$usage" "$mcp_tool_events" >> "$OUTPUT_DIR/summary.tsv"
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
run_case() {
|
|
57
|
+
local case_name="$1"
|
|
58
|
+
shift
|
|
59
|
+
|
|
60
|
+
local jsonl_file="$OUTPUT_DIR/$case_name.jsonl"
|
|
61
|
+
local answer_file="$OUTPUT_DIR/$case_name.md"
|
|
62
|
+
local stderr_file="$OUTPUT_DIR/$case_name.stderr.log"
|
|
63
|
+
local start_ns
|
|
64
|
+
local end_ns
|
|
65
|
+
local elapsed_ms
|
|
66
|
+
local exit_code
|
|
67
|
+
|
|
68
|
+
start_ns="$(date +%s%N)"
|
|
69
|
+
set +e
|
|
70
|
+
(
|
|
71
|
+
cd "$REPOSITORY_ROOT"
|
|
72
|
+
codex exec "$@" --json --output-last-message "$answer_file" "$PROMPT"
|
|
73
|
+
) > "$jsonl_file" 2> "$stderr_file"
|
|
74
|
+
exit_code=$?
|
|
75
|
+
set -e
|
|
76
|
+
end_ns="$(date +%s%N)"
|
|
77
|
+
elapsed_ms=$(( (end_ns - start_ns) / 1000000 ))
|
|
78
|
+
|
|
79
|
+
append_summary "$case_name" "$exit_code" "$elapsed_ms" "$jsonl_file"
|
|
80
|
+
printf '%s finished in %sms (exit %s)\n' "$case_name" "$elapsed_ms" "$exit_code"
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
write_summary_header
|
|
84
|
+
|
|
85
|
+
run_case with-mcp \
|
|
86
|
+
-c 'mcp_servers.yats.enabled=true' \
|
|
87
|
+
-c 'mcp_servers.yats.required=true'
|
|
88
|
+
|
|
89
|
+
run_case without-mcp \
|
|
90
|
+
-c 'mcp_servers.yats.enabled=false'
|
|
91
|
+
|
|
92
|
+
echo
|
|
93
|
+
echo "Results: $OUTPUT_DIR"
|
|
94
|
+
column -t -s $'\t' "$OUTPUT_DIR/summary.tsv" 2>/dev/null || cat "$OUTPUT_DIR/summary.tsv"
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Compare two benchmark runs and show savings."""
|
|
3
|
+
import json, sys
|
|
4
|
+
|
|
5
|
+
b1_path = sys.argv[1] # baseline
|
|
6
|
+
b2_path = sys.argv[2] # yats
|
|
7
|
+
|
|
8
|
+
with open(b1_path) as f: b1 = json.load(f)
|
|
9
|
+
with open(b2_path) as f: b2 = json.load(f)
|
|
10
|
+
|
|
11
|
+
t1 = b1["total_tokens"]
|
|
12
|
+
t2 = b2["total_tokens"]
|
|
13
|
+
c1 = b1["cost_usd"]
|
|
14
|
+
c2 = b2["cost_usd"]
|
|
15
|
+
token_save = (1 - t2/t1) * 100 if t1 else 0
|
|
16
|
+
cost_save = (1 - c2/c1) * 100 if c1 else 0
|
|
17
|
+
|
|
18
|
+
print(f"""
|
|
19
|
+
╔═══════════════════════════════════════════════════════════╗
|
|
20
|
+
║ YATS BENCHMARK ║
|
|
21
|
+
╠═══════════════════════════════════════════════════════════╣
|
|
22
|
+
║ ║
|
|
23
|
+
║ {'':10s} {'BASELINE':>15s} {'YATS':>15s} {'SAVINGS':>12s} ║
|
|
24
|
+
║ {'─'*58} ║
|
|
25
|
+
║ {'Tokens':10s} {t1:>15,d} {t2:>15,d} {token_save:>+11.1f}% ║
|
|
26
|
+
║ {'Cost':10s} {'$'+str(round(c1,4)):>15s} {'$'+str(round(c2,4)):>15s} {cost_save:>+11.1f}% ║
|
|
27
|
+
║ {'─'*58} ║
|
|
28
|
+
║ {'Strategy':10s} {'':>15s} {'':>15s} {'':>12s} ║
|
|
29
|
+
║ {'YATS queries':10s} {b1['strategy']['yats_queries']:>15} {b2['strategy']['yats_queries']:>15} {'':>12s} ║
|
|
30
|
+
║ {'File reads':10s} {b1['strategy']['file_reads']:>15} {b2['strategy']['file_reads']:>15} {(((1 - b2['strategy']['file_reads']/b1['strategy']['file_reads'])*100) if b1['strategy']['file_reads'] else 0):>+11.1f}% ║
|
|
31
|
+
║ {'Bash cmds':10s} {b1['strategy']['bash_commands']:>15} {b2['strategy']['bash_commands']:>15} {(((1 - b2['strategy']['bash_commands']/b1['strategy']['bash_commands'])*100) if b1['strategy']['bash_commands'] else 0):>+11.1f}% ║
|
|
32
|
+
║ {'Agent spawns':10s} {b1['strategy']['agent_spawns']:>15} {b2['strategy']['agent_spawns']:>15} {'':>12s} ║
|
|
33
|
+
║ {'Content':10s} {b1['content_chars']:>15,} {b2['content_chars']:>15,} {(((1 - b2['content_chars']/b1['content_chars'])*100) if b1['content_chars'] else 0):>+11.1f}% ║
|
|
34
|
+
║ {'─'*58} ║
|
|
35
|
+
║ {'Tokens':10s} {'':>15s} {'':>15s} {'':>12s} ║
|
|
36
|
+
║ {' Input':10s} {b1['tokens']['input_tokens']:>15,d} {b2['tokens']['input_tokens']:>15,d} {'':>12s} ║
|
|
37
|
+
║ {' Output':10s} {b1['tokens']['output_tokens']:>15,d} {b2['tokens']['output_tokens']:>15,d} {'← mas caro':>12s} ║
|
|
38
|
+
║ {' Cache R':10s} {b1['tokens']['cache_read_input_tokens']:>15,d} {b2['tokens']['cache_read_input_tokens']:>15,d} {'← barato':>12s} ║
|
|
39
|
+
║ {' Cache W':10s} {b1['tokens']['cache_creation_input_tokens']:>15,d} {b2['tokens']['cache_creation_input_tokens']:>15,d} {'← caro':>12s} ║
|
|
40
|
+
║ ║
|
|
41
|
+
╚═══════════════════════════════════════════════════════════╝
|
|
42
|
+
""")
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# YATS Benchmark — Copilot-specific token & tool extractor
|
|
3
|
+
# Usage: parse-copilot.sh <output_file>
|
|
4
|
+
|
|
5
|
+
file="$1"
|
|
6
|
+
|
|
7
|
+
# Count MCP tool calls
|
|
8
|
+
mcp_calls=$(grep -c "(MCP: yats)" "$file" 2>/dev/null || echo 0)
|
|
9
|
+
|
|
10
|
+
# Extract tokens and credits from last summary line
|
|
11
|
+
summary=$(grep "Tokens" "$file" | tail -1)
|
|
12
|
+
credits=$(echo "$summary" | grep -oP 'AI Credits \K[\d.]+' || echo 0)
|
|
13
|
+
time_s=$(echo "$summary" | grep -oP '\(\K\d+' | head -1 || echo 0)
|
|
14
|
+
|
|
15
|
+
# Token breakdown
|
|
16
|
+
tokens_total=$(echo "$summary" | grep -oP '↑ \K[\d.]+k' | head -1 | sed 's/k//' || echo 0)
|
|
17
|
+
cached=$(echo "$summary" | grep -oP '[\d.]+k cached' | head -1 | grep -oP '[\d.]+' || echo 0)
|
|
18
|
+
written=$(echo "$summary" | grep -oP '[\d.]+k written' | head -1 | grep -oP '[\d.]+' || echo 0)
|
|
19
|
+
|
|
20
|
+
# Count file reads (non-MCP reads)
|
|
21
|
+
file_reads=$(grep -c "● Read" "$file" 2>/dev/null || echo 0)
|
|
22
|
+
|
|
23
|
+
python3 -c "
|
|
24
|
+
import json
|
|
25
|
+
print(json.dumps({
|
|
26
|
+
'mcp_calls': $mcp_calls,
|
|
27
|
+
'file_reads': $file_reads,
|
|
28
|
+
'credits': $credits,
|
|
29
|
+
'time_s': $time_s,
|
|
30
|
+
'tokens_total': '${tokens_total}k',
|
|
31
|
+
'tokens_cached': '${cached}k',
|
|
32
|
+
'tokens_written': '${written}k',
|
|
33
|
+
'savings': 'MCP tool calls replace grep/file scanning'
|
|
34
|
+
}))" 2>/dev/null
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Aggregate benchmark metrics from Claude stream-json output."""
|
|
3
|
+
import json, sys
|
|
4
|
+
|
|
5
|
+
logfile = sys.argv[1]
|
|
6
|
+
tag = sys.argv[2] if len(sys.argv) > 2 else "?"
|
|
7
|
+
|
|
8
|
+
with open(logfile) as f:
|
|
9
|
+
events = [json.loads(line.strip()) for line in f if line.strip()]
|
|
10
|
+
|
|
11
|
+
results = [e for e in events if e.get("type") == "result"]
|
|
12
|
+
if not results:
|
|
13
|
+
print("NO RESULTS"); sys.exit(1)
|
|
14
|
+
|
|
15
|
+
# ── Tokens from modelUsage (session-aggregated, includes sub-agents) ──
|
|
16
|
+
usage_keys = ["input_tokens", "output_tokens",
|
|
17
|
+
"cache_creation_input_tokens", "cache_read_input_tokens"]
|
|
18
|
+
totals = {k: 0 for k in usage_keys}
|
|
19
|
+
models_seen = set()
|
|
20
|
+
total_cost = 0.0
|
|
21
|
+
turns = sum(r.get("num_turns", 0) for r in results)
|
|
22
|
+
errors = []
|
|
23
|
+
all_denials = sum(len(r.get("permission_denials", [])) for r in results)
|
|
24
|
+
for r in results:
|
|
25
|
+
for e in (r.get("errors") or []):
|
|
26
|
+
errors.append(e)
|
|
27
|
+
|
|
28
|
+
# modelUsage is the canonical source — same across all results (session total)
|
|
29
|
+
last = results[-1]
|
|
30
|
+
total_cost = last.get("total_cost_usd", 0)
|
|
31
|
+
for m, mu in last.get("modelUsage", {}).items():
|
|
32
|
+
models_seen.add(m)
|
|
33
|
+
totals["input_tokens"] += mu.get("inputTokens", 0)
|
|
34
|
+
totals["output_tokens"] += mu.get("outputTokens", 0)
|
|
35
|
+
totals["cache_creation_input_tokens"] += mu.get("cacheCreationInputTokens", 0)
|
|
36
|
+
totals["cache_read_input_tokens"] += mu.get("cacheReadInputTokens", 0)
|
|
37
|
+
|
|
38
|
+
# ── Tool calls ──
|
|
39
|
+
tool_calls = {}
|
|
40
|
+
for e in events:
|
|
41
|
+
if e.get("type") == "assistant":
|
|
42
|
+
for c in e.get("message", {}).get("content", []):
|
|
43
|
+
if c.get("type") == "tool_use":
|
|
44
|
+
name = c.get("name", "?")
|
|
45
|
+
tool_calls[name] = tool_calls.get(name, 0) + 1
|
|
46
|
+
|
|
47
|
+
yats = sum(v for k, v in tool_calls.items() if "yats" in k or "mcp__" in k)
|
|
48
|
+
reads = tool_calls.get("Read", 0)
|
|
49
|
+
bash = tool_calls.get("Bash", 0)
|
|
50
|
+
agents = tool_calls.get("Agent", 0) + tool_calls.get("Task", 0)
|
|
51
|
+
other = sum(tool_calls.values()) - yats - reads - bash - agents
|
|
52
|
+
|
|
53
|
+
# ── Content fetched ──
|
|
54
|
+
content_chars = 0
|
|
55
|
+
for e in events:
|
|
56
|
+
if e.get("type") == "user":
|
|
57
|
+
for c in e.get("message", {}).get("content", []):
|
|
58
|
+
if c.get("type") == "tool_result":
|
|
59
|
+
text = c.get("content", "")
|
|
60
|
+
if isinstance(text, list):
|
|
61
|
+
text = "".join(str(x.get("text", "")) for x in text)
|
|
62
|
+
content_chars += len(text)
|
|
63
|
+
|
|
64
|
+
# ── Report ──
|
|
65
|
+
total_tokens = sum(totals.values())
|
|
66
|
+
pcts = {k: (totals[k] / total_tokens * 100) if total_tokens else 0 for k in usage_keys}
|
|
67
|
+
|
|
68
|
+
lines = [
|
|
69
|
+
"",
|
|
70
|
+
f" {'='*50}",
|
|
71
|
+
f" {tag:^50}",
|
|
72
|
+
f" {'='*50}",
|
|
73
|
+
"",
|
|
74
|
+
f" TOKENS",
|
|
75
|
+
f" Input: {totals['input_tokens']:>12,} ({pcts['input_tokens']:5.1f}%)",
|
|
76
|
+
f" Output: {totals['output_tokens']:>12,} ({pcts['output_tokens']:5.1f}%)",
|
|
77
|
+
f" Cache read: {totals['cache_read_input_tokens']:>12,} ({pcts['cache_read_input_tokens']:5.1f}%) ← barato (0.1x)",
|
|
78
|
+
f" Cache write:{totals['cache_creation_input_tokens']:>12,} ({pcts['cache_creation_input_tokens']:5.1f}%) ← caro (1.25x)",
|
|
79
|
+
f" ─────────────────────────────",
|
|
80
|
+
f" TOTAL: {total_tokens:>12,}",
|
|
81
|
+
"",
|
|
82
|
+
f" COST: ${total_cost:.4f}",
|
|
83
|
+
"",
|
|
84
|
+
f" STRATEGY",
|
|
85
|
+
f" Turns: {turns:>8}",
|
|
86
|
+
f" Agent spawns: {agents:>8}",
|
|
87
|
+
f" YATS queries: {yats:>8} ← barato, dirigido",
|
|
88
|
+
f" File reads: {reads:>8} ← caro, contenido crudo",
|
|
89
|
+
f" Bash commands: {bash:>8} ← exploracion a ciegas" if bash > 0 else f" Bash commands: {bash:>8}",
|
|
90
|
+
f" Other: {other:>8}",
|
|
91
|
+
f" Content fetched: {content_chars:>8,} chars",
|
|
92
|
+
"",
|
|
93
|
+
f" Models: {', '.join(sorted(models_seen))}",
|
|
94
|
+
f" Errors: {len(errors)}, Denials: {all_denials}",
|
|
95
|
+
"",
|
|
96
|
+
]
|
|
97
|
+
|
|
98
|
+
for line in lines:
|
|
99
|
+
print(line)
|
|
100
|
+
|
|
101
|
+
# ── JSON summary ──
|
|
102
|
+
summary = {
|
|
103
|
+
"tag": tag,
|
|
104
|
+
"tokens": totals,
|
|
105
|
+
"total_tokens": total_tokens,
|
|
106
|
+
"cost_usd": round(total_cost, 6),
|
|
107
|
+
"turns": turns,
|
|
108
|
+
"strategy": {
|
|
109
|
+
"agent_spawns": agents,
|
|
110
|
+
"yats_queries": yats,
|
|
111
|
+
"file_reads": reads,
|
|
112
|
+
"bash_commands": bash,
|
|
113
|
+
"other": other,
|
|
114
|
+
"tool_breakdown": dict(sorted(tool_calls.items(), key=lambda x: -x[1])),
|
|
115
|
+
},
|
|
116
|
+
"content_chars": content_chars,
|
|
117
|
+
"models": sorted(models_seen),
|
|
118
|
+
"errors": len(errors),
|
|
119
|
+
"permission_denials": all_denials,
|
|
120
|
+
}
|
|
121
|
+
json_path = logfile.replace(".jsonl", ".summary.json")
|
|
122
|
+
with open(json_path, "w") as f:
|
|
123
|
+
json.dump(summary, f, indent=2)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"python": [
|
|
3
|
+
{ "name": "fastapi", "url": "https://github.com/fastapi/fastapi", "desc": "FastAPI web framework" },
|
|
4
|
+
{ "name": "django", "url": "https://github.com/django/django", "desc": "Django web framework" }
|
|
5
|
+
],
|
|
6
|
+
"typescript": [
|
|
7
|
+
{ "name": "nestjs", "url": "https://github.com/nestjs/nest", "desc": "NestJS progressive Node.js framework" },
|
|
8
|
+
{ "name": "nextjs", "url": "https://github.com/vercel/next.js", "desc": "Next.js React framework" }
|
|
9
|
+
],
|
|
10
|
+
"go": [
|
|
11
|
+
{ "name": "gin", "url": "https://github.com/gin-gonic/gin", "desc": "Gin HTTP web framework" },
|
|
12
|
+
{ "name": "terraform", "url": "https://github.com/hashicorp/terraform", "desc": "Terraform IaC tool" }
|
|
13
|
+
],
|
|
14
|
+
"csharp": [
|
|
15
|
+
{ "name": "MediatR", "url": "https://github.com/jbogard/MediatR", "desc": "MediatR CQRS/Mediator library" },
|
|
16
|
+
{ "name": "eShopOnWeb", "url": "https://github.com/dotnet-architecture/eShopOnWeb", "desc": "Microsoft clean architecture reference app" },
|
|
17
|
+
{ "name": "Carter", "url": "https://github.com/CarterCommunity/Carter", "desc": "Minimal APIs framework for ASP.NET Core" }
|
|
18
|
+
],
|
|
19
|
+
"php": [
|
|
20
|
+
{ "name": "laravel", "url": "https://github.com/laravel/framework", "desc": "Laravel PHP framework" },
|
|
21
|
+
{ "name": "symfony", "url": "https://github.com/symfony/symfony", "desc": "Symfony PHP framework" }
|
|
22
|
+
]
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yats-toolkit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
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",
|
|
@@ -40,6 +40,10 @@
|
|
|
40
40
|
"files": [
|
|
41
41
|
"bin/",
|
|
42
42
|
"src/",
|
|
43
|
+
"benchmark/questions/",
|
|
44
|
+
"benchmark/targets/",
|
|
45
|
+
"benchmark/scripts/",
|
|
46
|
+
"benchmark/run.sh",
|
|
43
47
|
"README.md"
|
|
44
48
|
],
|
|
45
49
|
"scripts": {
|
package/src/bridge.js
CHANGED
|
@@ -1,101 +1,184 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* YATS Bridge — MCP stdio ↔ HTTP proxy
|
|
3
|
+
* YATS Bridge — MCP stdio ↔ YATS HTTP proxy
|
|
4
|
+
*
|
|
5
|
+
* Acts as a local MCP server over stdio that wraps YATS MCP tools.
|
|
6
|
+
* Used by AI agents (Copilot, Gemini, Codex, Claude) to connect to YATS.
|
|
4
7
|
*
|
|
5
8
|
* Usage:
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
+
* yats bridge # default: localhost:5555
|
|
10
|
+
* yats bridge --port 5555
|
|
11
|
+
* yats bridge --url http://my-server:5555
|
|
12
|
+
*
|
|
13
|
+
* Agent configs:
|
|
14
|
+
* Copilot: { "type": "local", "command": "node", "args": ["bridge.cjs", "--stdio"] }
|
|
15
|
+
* Gemini: { "command": "node", "args": ["bridge.cjs", "--stdio"], "trust": true }
|
|
16
|
+
* Codex: command = "node", args = ["bridge.cjs", "--stdio"]
|
|
17
|
+
* Claude: { "command": "node", "args": ["bridge.cjs", "--stdio"] }
|
|
9
18
|
*/
|
|
10
19
|
|
|
11
|
-
|
|
20
|
+
import http from "node:http";
|
|
21
|
+
import https from "node:https";
|
|
22
|
+
import { createInterface } from "node:readline";
|
|
23
|
+
import { basename } from "node:path";
|
|
24
|
+
|
|
25
|
+
// ── Config ──────────────────────────────────────────────
|
|
26
|
+
let yatsUrl = process.env.YATS_URL || "http://localhost:5555";
|
|
12
27
|
|
|
13
28
|
// Parse CLI args
|
|
14
29
|
const args = process.argv.slice(2);
|
|
15
|
-
let baseUrl = YATS_URL;
|
|
16
30
|
for (let i = 0; i < args.length; i++) {
|
|
17
|
-
if (args[i] === "--port" && args[i + 1])
|
|
18
|
-
|
|
31
|
+
if (args[i] === "--port" && args[i + 1]) {
|
|
32
|
+
yatsUrl = `http://localhost:${args[++i]}`;
|
|
33
|
+
} else if (args[i] === "--url" && args[i + 1]) {
|
|
34
|
+
yatsUrl = args[++i];
|
|
35
|
+
}
|
|
19
36
|
}
|
|
20
37
|
|
|
21
|
-
|
|
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
|
-
}
|
|
38
|
+
const YATS_MCP_URL = yatsUrl.endsWith("/mcp") ? yatsUrl : yatsUrl + "/mcp";
|
|
43
39
|
|
|
44
|
-
|
|
40
|
+
// Default repo: env var > cwd basename
|
|
41
|
+
const DEFAULT_REPO = process.env.YATS_DEFAULT_REPO || basename(process.cwd());
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
// Tools that require a repository parameter
|
|
44
|
+
const REPO_TOOLS = new Set([
|
|
45
|
+
"search_code", "find_symbol", "find_callers", "find_callees",
|
|
46
|
+
"find_references", "find_implementations", "find_inheritors", "find_routes",
|
|
47
|
+
"find_configuration", "expand_graph", "related_symbols", "list_symbols",
|
|
48
|
+
"repository_summary", "architecture_summary", "search_similar",
|
|
49
|
+
]);
|
|
52
50
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
sseBuffer = parts.pop() || "";
|
|
51
|
+
// ── Logger ───────────────────────────────────────────────
|
|
52
|
+
const log = (msg) => process.stderr.write(`[yats-bridge] ${msg}\n`);
|
|
56
53
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
// ── HTTP helpers ─────────────────────────────────────────
|
|
55
|
+
function post(url, body) {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
const u = new URL(url);
|
|
58
|
+
const transport = u.protocol === "https:" ? https : http;
|
|
59
|
+
const req = transport.request({
|
|
60
|
+
hostname: u.hostname,
|
|
61
|
+
port: u.port || (u.protocol === "https:" ? 443 : 80),
|
|
62
|
+
path: u.pathname,
|
|
63
|
+
method: "POST",
|
|
64
|
+
headers: { "Content-Type": "application/json", "Accept": "application/json" },
|
|
65
|
+
}, (res) => {
|
|
66
|
+
let data = "";
|
|
67
|
+
res.on("data", (c) => data += c);
|
|
68
|
+
res.on("end", () => {
|
|
69
|
+
try { resolve(JSON.parse(data)); }
|
|
70
|
+
catch (e) { reject(new Error(`Parse error: ${e.message}`)); }
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
req.on("error", reject);
|
|
74
|
+
req.setTimeout(30_000, () => { req.destroy(); reject(new Error("Timeout")); });
|
|
75
|
+
req.write(JSON.stringify(body));
|
|
76
|
+
req.end();
|
|
77
|
+
});
|
|
65
78
|
}
|
|
66
79
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
80
|
+
// ── MCP operations ───────────────────────────────────────
|
|
81
|
+
async function fetchTools() {
|
|
82
|
+
const r = await post(YATS_MCP_URL, { jsonrpc: "2.0", id: 1, method: "tools/list", params: {} });
|
|
83
|
+
return r.result?.tools || [];
|
|
84
|
+
}
|
|
70
85
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
86
|
+
async function callTool(name, args) {
|
|
87
|
+
const r = await post(YATS_MCP_URL, {
|
|
88
|
+
jsonrpc: "2.0", id: Date.now(), method: "tools/call",
|
|
89
|
+
params: { name, arguments: args },
|
|
75
90
|
});
|
|
91
|
+
return r.result?.content || [{ type: "text", text: JSON.stringify(r) }];
|
|
76
92
|
}
|
|
77
93
|
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
94
|
+
// ── stdio MCP server ─────────────────────────────────────
|
|
95
|
+
async function start() {
|
|
96
|
+
log(`Connecting to ${YATS_MCP_URL}...`);
|
|
97
|
+
const tools = await fetchTools();
|
|
98
|
+
log(`Fetched ${tools.length} tools — default repo: "${DEFAULT_REPO}"`);
|
|
99
|
+
|
|
100
|
+
const rl = createInterface({ input: process.stdin, terminal: false });
|
|
101
|
+
let pending = 0;
|
|
102
|
+
let stdinClosed = false;
|
|
103
|
+
|
|
104
|
+
const checkDone = () => {
|
|
105
|
+
if (stdinClosed && pending === 0) {
|
|
106
|
+
log("All done, exiting.");
|
|
107
|
+
process.exit(0);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
rl.on("line", (line) => {
|
|
112
|
+
line = line.trim();
|
|
113
|
+
if (!line) return;
|
|
114
|
+
pending++;
|
|
115
|
+
|
|
116
|
+
handleLine(line).finally(() => {
|
|
117
|
+
pending--;
|
|
118
|
+
checkDone();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
async function handleLine(line) {
|
|
123
|
+
let request;
|
|
124
|
+
try { request = JSON.parse(line); }
|
|
125
|
+
catch { return; }
|
|
126
|
+
|
|
127
|
+
const { id, method, params } = request;
|
|
128
|
+
|
|
89
129
|
try {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
130
|
+
if (method === "initialize") {
|
|
131
|
+
respond({ jsonrpc: "2.0", id, result: {
|
|
132
|
+
protocolVersion: "2025-03-26",
|
|
133
|
+
capabilities: { tools: {} },
|
|
134
|
+
serverInfo: { name: "yats-bridge", version: "1.0.0" },
|
|
135
|
+
}});
|
|
136
|
+
} else if (method === "notifications/initialized") {
|
|
137
|
+
// No response needed
|
|
138
|
+
} else if (method === "tools/list") {
|
|
139
|
+
respond({ jsonrpc: "2.0", id, result: { tools } });
|
|
140
|
+
} else if (method === "tools/call") {
|
|
141
|
+
const toolName = params?.name;
|
|
142
|
+
const toolArgs = params?.arguments || {};
|
|
143
|
+
|
|
144
|
+
// Auto-inject repository if missing
|
|
145
|
+
if (REPO_TOOLS.has(toolName) && !toolArgs.repository && !toolArgs.path) {
|
|
146
|
+
toolArgs.repository = DEFAULT_REPO;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
log(`call: ${toolName}(${JSON.stringify(toolArgs).slice(0, 200)})`);
|
|
150
|
+
const content = await callTool(toolName, toolArgs);
|
|
151
|
+
const text = content.map((c) => c.text || "").join("\n");
|
|
152
|
+
|
|
153
|
+
// structuredContent fixes Gemini CLI compatibility
|
|
154
|
+
respond({ jsonrpc: "2.0", id, result: {
|
|
155
|
+
content,
|
|
156
|
+
structuredContent: { result: text },
|
|
157
|
+
}});
|
|
158
|
+
} else if (method === "shutdown") {
|
|
159
|
+
respond({ jsonrpc: "2.0", id, result: {} });
|
|
160
|
+
stdinClosed = true;
|
|
161
|
+
checkDone();
|
|
162
|
+
} else {
|
|
163
|
+
respond({ jsonrpc: "2.0", id, error: { code: -32601, message: `Unknown: ${method}` } });
|
|
164
|
+
}
|
|
165
|
+
} catch (e) {
|
|
166
|
+
log(`error: ${e.message}`);
|
|
167
|
+
respond({ jsonrpc: "2.0", id, error: { code: -32603, message: e.message } });
|
|
94
168
|
}
|
|
95
169
|
}
|
|
96
|
-
});
|
|
97
170
|
|
|
98
|
-
process.stdin.on("end", () => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
171
|
+
process.stdin.on("end", () => {
|
|
172
|
+
stdinClosed = true;
|
|
173
|
+
checkDone();
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
log("Ready — waiting for MCP client on stdio");
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function respond(obj) {
|
|
180
|
+
process.stdout.write(JSON.stringify(obj) + "\n");
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// ── Main ─────────────────────────────────────────────────
|
|
184
|
+
start().catch((e) => { log(`FATAL: ${e.message}`); process.exit(1); });
|