milens 0.2.4 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +75 -75
- package/README.md +435 -392
- package/dist/analyzer/engine.js +6 -1
- package/dist/analyzer/engine.js.map +1 -1
- package/dist/cli.js +17 -5
- package/dist/cli.js.map +1 -1
- package/dist/parser/extract.d.ts.map +1 -1
- package/dist/parser/extract.js +8 -0
- package/dist/parser/extract.js.map +1 -1
- package/dist/parser/lang-go.d.ts.map +1 -1
- package/dist/parser/lang-go.js +22 -18
- package/dist/parser/lang-go.js.map +1 -1
- package/dist/parser/lang-java.d.ts.map +1 -1
- package/dist/parser/lang-java.js +28 -17
- package/dist/parser/lang-java.js.map +1 -1
- package/dist/parser/lang-js.d.ts.map +1 -1
- package/dist/parser/lang-js.js +42 -32
- package/dist/parser/lang-js.js.map +1 -1
- package/dist/parser/lang-php.d.ts.map +1 -1
- package/dist/parser/lang-php.js +35 -20
- package/dist/parser/lang-php.js.map +1 -1
- package/dist/parser/lang-py.d.ts.map +1 -1
- package/dist/parser/lang-py.js +36 -17
- package/dist/parser/lang-py.js.map +1 -1
- package/dist/parser/lang-rust.d.ts.map +1 -1
- package/dist/parser/lang-rust.js +26 -19
- package/dist/parser/lang-rust.js.map +1 -1
- package/dist/parser/lang-ts.d.ts.map +1 -1
- package/dist/parser/lang-ts.js +57 -44
- package/dist/parser/lang-ts.js.map +1 -1
- package/dist/parser/lang-vue.d.ts +6 -0
- package/dist/parser/lang-vue.d.ts.map +1 -1
- package/dist/parser/lang-vue.js +44 -0
- package/dist/parser/lang-vue.js.map +1 -1
- package/dist/server/mcp.d.ts.map +1 -1
- package/dist/server/mcp.js +289 -21
- package/dist/server/mcp.js.map +1 -1
- package/dist/skills.d.ts +1 -1
- package/dist/skills.d.ts.map +1 -1
- package/dist/skills.js +204 -14
- package/dist/skills.js.map +1 -1
- package/dist/store/db.d.ts.map +1 -1
- package/dist/store/db.js +73 -59
- package/dist/store/db.js.map +1 -1
- package/dist/store/schema.sql +60 -60
- package/package.json +60 -60
package/README.md
CHANGED
|
@@ -1,392 +1,435 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<strong>milens</strong><br>
|
|
3
|
-
<em>Lightweight Code Intelligence Engine</em>
|
|
4
|
-
</p>
|
|
5
|
-
|
|
6
|
-
<p align="center">
|
|
7
|
-
<a href="https://www.npmjs.com/package/milens"><img src="https://img.shields.io/npm/v/milens" alt="npm version"></a>
|
|
8
|
-
<a href="https://github.com/fuze210699/milens/blob/develop/LICENSE"><img src="https://img.shields.io/badge/license-PolyForm--Noncommercial-blue" alt="License: PolyForm Noncommercial"></a>
|
|
9
|
-
<a href="https://nodejs.org"><img src="https://img.shields.io/badge/node-%3E%3D20-brightgreen" alt="Node.js >= 20"></a>
|
|
10
|
-
</p>
|
|
11
|
-
|
|
12
|
-
<p align="center">
|
|
13
|
-
<a href="#features">Features</a> •
|
|
14
|
-
<a href="#installation">Install</a> •
|
|
15
|
-
<a href="#quick-start">Quick Start</a> •
|
|
16
|
-
<a href="#cli-commands">CLI</a> •
|
|
17
|
-
<a href="#mcp-server">MCP Server</a> •
|
|
18
|
-
<a href="#editor-integration">Editors</a> •
|
|
19
|
-
<a href="#architecture">Architecture</a> •
|
|
20
|
-
<a href="#adding-a-language">Extend</a>
|
|
21
|
-
</p>
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
Parse codebases into **knowledge graphs** — symbols, imports, calls, inheritance — and serve them to **AI agents** via the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/).
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
npx milens analyze # index any codebase
|
|
29
|
-
npx milens serve # start MCP server for AI agents
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Features
|
|
33
|
-
|
|
34
|
-
- **8 languages** — TypeScript, JavaScript, Python, Java, Go, Rust, PHP, Vue
|
|
35
|
-
- **Declarative grammars** — add a new language by writing a config object, not code
|
|
36
|
-
- **
|
|
37
|
-
- **
|
|
38
|
-
- **
|
|
39
|
-
- **
|
|
40
|
-
- **
|
|
41
|
-
- **
|
|
42
|
-
- **
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
milens analyze -p .
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
|
84
|
-
|
|
85
|
-
| `
|
|
86
|
-
| `
|
|
87
|
-
| `
|
|
88
|
-
| `
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
|
103
|
-
|
|
104
|
-
| `-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
### `
|
|
121
|
-
|
|
122
|
-
```bash
|
|
123
|
-
npx milens
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
→
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
```
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<strong>milens</strong><br>
|
|
3
|
+
<em>Lightweight Code Intelligence Engine</em>
|
|
4
|
+
</p>
|
|
5
|
+
|
|
6
|
+
<p align="center">
|
|
7
|
+
<a href="https://www.npmjs.com/package/milens"><img src="https://img.shields.io/npm/v/milens" alt="npm version"></a>
|
|
8
|
+
<a href="https://github.com/fuze210699/milens/blob/develop/LICENSE"><img src="https://img.shields.io/badge/license-PolyForm--Noncommercial-blue" alt="License: PolyForm Noncommercial"></a>
|
|
9
|
+
<a href="https://nodejs.org"><img src="https://img.shields.io/badge/node-%3E%3D20-brightgreen" alt="Node.js >= 20"></a>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
<p align="center">
|
|
13
|
+
<a href="#features">Features</a> •
|
|
14
|
+
<a href="#installation">Install</a> •
|
|
15
|
+
<a href="#quick-start">Quick Start</a> •
|
|
16
|
+
<a href="#cli-commands">CLI</a> •
|
|
17
|
+
<a href="#mcp-server">MCP Server</a> •
|
|
18
|
+
<a href="#editor-integration">Editors</a> •
|
|
19
|
+
<a href="#architecture">Architecture</a> •
|
|
20
|
+
<a href="#adding-a-language">Extend</a>
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
Parse codebases into **knowledge graphs** — symbols, imports, calls, inheritance — and serve them to **AI agents** via the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/).
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx milens analyze # index any codebase
|
|
29
|
+
npx milens serve # start MCP server for AI agents
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Features
|
|
33
|
+
|
|
34
|
+
- **8 languages** — TypeScript, JavaScript, Python, Java, Go, Rust, PHP, Vue
|
|
35
|
+
- **Declarative grammars** — add a new language by writing a config object, not code
|
|
36
|
+
- **11 MCP tools + 3 prompts** — query, grep, context, impact, status, detect_changes, explain_relationship, find_dead_code, get_file_symbols, get_type_hierarchy
|
|
37
|
+
- **Full-text grep** — search ALL project files (templates, SCSS, configs, docs) — not just indexed symbols
|
|
38
|
+
- **SQLite + FTS5** — full-text symbol search + recursive CTE graph traversal
|
|
39
|
+
- **Token-compact output** — minimal structured text, saving 40-60% tokens for AI agents
|
|
40
|
+
- **Incremental indexing** — file-hash based, only re-parses changed files
|
|
41
|
+
- **Multi-repo registry** — manage multiple codebases from `~/.milens/`
|
|
42
|
+
- **Dual transport** — MCP over stdio (VS Code / Cursor) or HTTP (localhost-bound, secure)
|
|
43
|
+
- **Skills generation** — auto-generate context files for Copilot, Cursor, Claude, Codex, and 40+ agents. Injects into root configs (`.github/copilot-instructions.md`, `.cursorrules`, `CLAUDE.md`, `AGENTS.md`)
|
|
44
|
+
- **MCP protocol instructions** — server-level instructions sent to every connected agent on `initialize`, guiding tool usage without static files
|
|
45
|
+
- **Per-editor CLI** — `--skills-copilot`, `--skills-cursor`, `--skills-claude`, `--skills-agents` for targeted generation
|
|
46
|
+
- **Security hardened** — ReDoS protection, path traversal prevention, FTS5 injection sanitization, command injection prevention
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# Use directly (no install needed)
|
|
52
|
+
npx milens analyze -p .
|
|
53
|
+
|
|
54
|
+
# Or install globally
|
|
55
|
+
npm install -g milens
|
|
56
|
+
milens analyze -p . # after global install, npx prefix is optional
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Quick Start
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# Index a codebase
|
|
63
|
+
npx milens analyze -p /path/to/repo --verbose
|
|
64
|
+
|
|
65
|
+
# Search for symbols
|
|
66
|
+
npx milens search "UserService"
|
|
67
|
+
|
|
68
|
+
# 360° symbol context
|
|
69
|
+
npx milens inspect "AuthService"
|
|
70
|
+
|
|
71
|
+
# Blast radius — what breaks if this changes?
|
|
72
|
+
npx milens impact "createUser" --depth 3
|
|
73
|
+
|
|
74
|
+
# Start MCP server (stdio for editors)
|
|
75
|
+
npx milens serve -p /path/to/repo
|
|
76
|
+
|
|
77
|
+
# Start MCP server (HTTP for remote agents)
|
|
78
|
+
npx milens serve --http --port 3100
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## CLI Commands
|
|
82
|
+
|
|
83
|
+
| Command | Description |
|
|
84
|
+
|---|---|
|
|
85
|
+
| `analyze` | Index a codebase into a knowledge graph |
|
|
86
|
+
| `search` | Full-text symbol search (FTS5) |
|
|
87
|
+
| `inspect` | 360° symbol context — incoming refs + outgoing deps |
|
|
88
|
+
| `impact` | Blast radius analysis via recursive CTE |
|
|
89
|
+
| `serve` | Start MCP server (stdio or HTTP) |
|
|
90
|
+
| `status` | Show index stats |
|
|
91
|
+
| `list` | List all indexed repositories |
|
|
92
|
+
| `clean` | Remove index for a repository |
|
|
93
|
+
|
|
94
|
+
### `analyze`
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
npx milens analyze -p /path/to/repo --verbose --force --skills
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Scans source files, parses symbols with tree-sitter, resolves imports/calls/inheritance, and stores everything in `.milens/milens.db`.
|
|
101
|
+
|
|
102
|
+
| Flag | Description |
|
|
103
|
+
|---|---|
|
|
104
|
+
| `-p, --path` | Repository root (default: `.`) |
|
|
105
|
+
| `-o, --output` | Custom output directory for the database |
|
|
106
|
+
| `-v, --verbose` | Show detailed progress |
|
|
107
|
+
| `-f, --force` | Force full re-index (skip hash check) |
|
|
108
|
+
| `-s, --skills` | Generate skill files for all supported editors |
|
|
109
|
+
| `--skills-copilot` | Generate skill files for GitHub Copilot only |
|
|
110
|
+
| `--skills-cursor` | Generate skill files for Cursor only |
|
|
111
|
+
| `--skills-claude` | Generate skill files for Claude Code only |
|
|
112
|
+
| `--skills-agents` | Generate skill files for AGENTS.md only |
|
|
113
|
+
|
|
114
|
+
### `search`
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
npx milens search "createUser" --limit 10
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### `inspect`
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
npx milens inspect "AuthService"
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Shows incoming references (who calls/uses it) and outgoing dependencies (what it calls/imports/extends).
|
|
127
|
+
|
|
128
|
+
### `impact`
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
npx milens impact "UserModel" --direction upstream --depth 3
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
*"What breaks if this symbol changes?"* — traverses the dependency graph via recursive CTEs.
|
|
135
|
+
|
|
136
|
+
| Flag | Description |
|
|
137
|
+
|---|---|
|
|
138
|
+
| `-d, --direction` | `upstream` (default) or `downstream` |
|
|
139
|
+
| `--depth` | Max traversal depth (default: `3`) |
|
|
140
|
+
|
|
141
|
+
### `serve`
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
npx milens serve -p /path/to/repo # stdio (for editors)
|
|
145
|
+
npx milens serve -p /path/to/repo --http --port 3100 # HTTP
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### `list`
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
npx milens list # show all indexed repositories
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### `clean`
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
npx milens clean -p /path/to/repo # remove index for one repo
|
|
158
|
+
npx milens clean --all # remove all indexes
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## MCP Server
|
|
162
|
+
|
|
163
|
+
milens exposes **11 tools** and **3 prompt templates** via the Model Context Protocol.
|
|
164
|
+
|
|
165
|
+
The server includes **built-in instructions** sent via the MCP `initialize` response — every connected agent automatically receives tool usage guidance (when to combine `impact` + `grep`, workflow for deletions/refactors, etc.) without needing static files.
|
|
166
|
+
|
|
167
|
+
### Tools
|
|
168
|
+
|
|
169
|
+
| Tool | Description | Key params |
|
|
170
|
+
|---|---|---|
|
|
171
|
+
| `query` | Search indexed symbol definitions (FTS5) | `query`, `limit` |
|
|
172
|
+
| `grep` | Text search across ALL project files (templates, SCSS, configs, docs) | `pattern`, `isRegex`, `include` |
|
|
173
|
+
| `context` | 360° symbol view — incoming refs, outgoing deps | `name` |
|
|
174
|
+
| `impact` | Blast radius with depth grouping (code deps only) | `target`, `direction`, `depth` |
|
|
175
|
+
| `status` | Index stats for a repository | `repo` |
|
|
176
|
+
| `detect_changes` | Git diff → affected symbols + dependents | `ref` |
|
|
177
|
+
| `explain_relationship` | Shortest path between two symbols | `from`, `to` |
|
|
178
|
+
| `find_dead_code` | Exported symbols with zero references | `kind`, `limit` |
|
|
179
|
+
| `get_file_symbols` | All symbols in a specific file | `file` |
|
|
180
|
+
| `get_type_hierarchy` | Inheritance/implementation tree | `name` |
|
|
181
|
+
|
|
182
|
+
> **`query` vs `grep`**: `query` searches indexed symbol definitions only. `grep` searches raw text across every file — essential for finding references in templates, SCSS, configs, routes, and docs that `query`/`impact` cannot see.
|
|
183
|
+
|
|
184
|
+
> When only one repo is indexed, the `repo` parameter is optional on all tools.
|
|
185
|
+
|
|
186
|
+
### Prompts
|
|
187
|
+
|
|
188
|
+
| Prompt | Description | Params |
|
|
189
|
+
|---|---|---|
|
|
190
|
+
| `delete-feature` | Guided workflow for safe feature deletion (grep + impact + context) | `name` |
|
|
191
|
+
| `refactor-symbol` | Guided workflow for renaming/refactoring with full coverage | `name` |
|
|
192
|
+
| `explore-symbol` | Deep exploration of unfamiliar code | `name` |
|
|
193
|
+
|
|
194
|
+
### Tool Examples
|
|
195
|
+
|
|
196
|
+
```
|
|
197
|
+
# Search indexed symbols
|
|
198
|
+
query({query: "auth"})
|
|
199
|
+
→ AuthService [class] src/auth/service.ts:10
|
|
200
|
+
validateUser [function] src/auth/validate.ts:15
|
|
201
|
+
|
|
202
|
+
# Grep ALL files (templates, SCSS, configs, docs)
|
|
203
|
+
grep({pattern: "AuthService"})
|
|
204
|
+
→ src/auth/service.ts L10: export class AuthService {
|
|
205
|
+
src/components/Login.vue L5: <AuthForm @submit="handleAuth" />
|
|
206
|
+
src/routes/index.ts L12: import { AuthService } from '../auth'
|
|
207
|
+
docs/api.md L42: The `AuthService` handles JWT...
|
|
208
|
+
|
|
209
|
+
# Context
|
|
210
|
+
context({name: "validateUser"})
|
|
211
|
+
→ incoming:
|
|
212
|
+
calls: handleLogin (src/api/auth.ts)
|
|
213
|
+
outgoing:
|
|
214
|
+
calls: checkPassword (src/auth/hash.ts)
|
|
215
|
+
|
|
216
|
+
# Impact
|
|
217
|
+
impact({target: "UserService", direction: "upstream"})
|
|
218
|
+
→ depth 1:
|
|
219
|
+
handleLogin [function] src/api/auth.ts:45 (calls)
|
|
220
|
+
UserController [class] src/controllers/user.ts:12 (calls)
|
|
221
|
+
depth 2:
|
|
222
|
+
authRouter [module] src/routes/auth.ts (imports)
|
|
223
|
+
|
|
224
|
+
# Detect changes
|
|
225
|
+
detect_changes({ref: "HEAD"})
|
|
226
|
+
→ changed: src/auth/service.ts
|
|
227
|
+
affected: handleLogin, UserController
|
|
228
|
+
|
|
229
|
+
# Dead code
|
|
230
|
+
find_dead_code({kind: "function"})
|
|
231
|
+
→ legacyHash [function] src/utils/hash.ts:42 (0 refs)
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Editor Integration
|
|
235
|
+
|
|
236
|
+
### VS Code / GitHub Copilot
|
|
237
|
+
|
|
238
|
+
Add to `.vscode/mcp.json`:
|
|
239
|
+
|
|
240
|
+
```json
|
|
241
|
+
{
|
|
242
|
+
"servers": {
|
|
243
|
+
"milens": {
|
|
244
|
+
"type": "stdio",
|
|
245
|
+
"command": "npx",
|
|
246
|
+
"args": ["-y", "milens", "serve", "-p", "${workspaceFolder}"]
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Cursor
|
|
253
|
+
|
|
254
|
+
Add to `.cursor/mcp.json` (per-project):
|
|
255
|
+
|
|
256
|
+
```json
|
|
257
|
+
{
|
|
258
|
+
"mcpServers": {
|
|
259
|
+
"milens": {
|
|
260
|
+
"command": "npx",
|
|
261
|
+
"args": ["-y", "milens", "serve", "-p", "."]
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Claude Code
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
claude mcp add milens -- npx -y milens serve -p .
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Codex
|
|
274
|
+
|
|
275
|
+
Add to `.codex/config.toml`:
|
|
276
|
+
|
|
277
|
+
```toml
|
|
278
|
+
[mcp_servers.milens]
|
|
279
|
+
command = "npx"
|
|
280
|
+
args = ["-y", "milens", "serve", "-p", "."]
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### HTTP Mode (remote agents)
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
npx milens serve --http --port 3100
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
Endpoint: `POST http://localhost:3100/mcp`
|
|
290
|
+
|
|
291
|
+
## Skills Generation
|
|
292
|
+
|
|
293
|
+
Generate editor-specific context files from your codebase's knowledge graph:
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
# Generate for all editors
|
|
297
|
+
npx milens analyze -p . --skills
|
|
298
|
+
|
|
299
|
+
# Generate for a specific editor only
|
|
300
|
+
npx milens analyze -p . --skills-cursor
|
|
301
|
+
npx milens analyze -p . --skills-copilot --skills-agents # combine multiple
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
This creates:
|
|
305
|
+
|
|
306
|
+
| Path | For |
|
|
307
|
+
|---|---|
|
|
308
|
+
| `.github/instructions/*.instructions.md` | GitHub Copilot |
|
|
309
|
+
| `.github/copilot-instructions.md` | GitHub Copilot (root config, always loaded) |
|
|
310
|
+
| `.cursor/rules/*.mdc` | Cursor |
|
|
311
|
+
| `.cursorrules` | Cursor (root config, always loaded) |
|
|
312
|
+
| `.claude/skills/generated/*/SKILL.md` | Claude Code |
|
|
313
|
+
| `CLAUDE.md` | Claude Code (root config, always loaded) |
|
|
314
|
+
| `.agents/skills/*/SKILL.md` | 40+ agents ([Agent Skills](https://agentskills.io)) |
|
|
315
|
+
| `AGENTS.md` | Universal agents (root config, always loaded) |
|
|
316
|
+
| `.milens/skills/*.md` | milens internal |
|
|
317
|
+
|
|
318
|
+
All root config files use `<!-- milens:start/end -->` markers for idempotent injection — re-running replaces the milens section without duplicating or overwriting other content.
|
|
319
|
+
|
|
320
|
+
Each generated file contains: key symbols, entry points, cross-area dependencies, file listings, and **full MCP tool usage instructions** with `mcp_milens_*` tool names, repo path, workflows, and "Never Do" rules — so AI agents know both the codebase structure and exactly how to use milens tools.
|
|
321
|
+
|
|
322
|
+
## Architecture
|
|
323
|
+
|
|
324
|
+
```
|
|
325
|
+
src/
|
|
326
|
+
cli.ts — CLI entry point (commander, 8 commands)
|
|
327
|
+
types.ts — Shared types (CodeSymbol, SymbolLink, etc.)
|
|
328
|
+
skills.ts — Skills/context file generator
|
|
329
|
+
parser/
|
|
330
|
+
loader.ts — Tree-sitter WASM loading + caching
|
|
331
|
+
extract.ts — Universal extractor + LangSpec interface
|
|
332
|
+
lang-ts.ts — TypeScript (+ .tsx)
|
|
333
|
+
lang-js.ts — JavaScript (+ .jsx, .mjs, .cjs)
|
|
334
|
+
lang-py.ts — Python
|
|
335
|
+
lang-java.ts — Java
|
|
336
|
+
lang-go.ts — Go
|
|
337
|
+
lang-rust.ts — Rust
|
|
338
|
+
lang-php.ts — PHP
|
|
339
|
+
lang-vue.ts — Vue (extracts <script> + <template> refs)
|
|
340
|
+
languages.ts — Language registry
|
|
341
|
+
analyzer/
|
|
342
|
+
scanner.ts — File discovery (.gitignore aware)
|
|
343
|
+
resolver.ts — Import + call + heritage resolution
|
|
344
|
+
engine.ts — Pipeline orchestrator (6 phases)
|
|
345
|
+
store/
|
|
346
|
+
schema.sql — SQLite schema (FTS5, triggers, indexes)
|
|
347
|
+
db.ts — Database adapter (30+ methods, recursive CTEs)
|
|
348
|
+
registry.ts — Multi-repo registry (~/.milens/)
|
|
349
|
+
server/
|
|
350
|
+
mcp.ts — MCP server (11 tools, stdio + HTTP)
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### How It Works
|
|
354
|
+
|
|
355
|
+
```
|
|
356
|
+
Source Files → [Scan] → [Parse] → [Resolve] → [Store] → [Serve]
|
|
357
|
+
│ │ │ │ │
|
|
358
|
+
.gitignore tree-sitter imports SQLite MCP
|
|
359
|
+
filter WASM AST calls FTS5 stdio/HTTP
|
|
360
|
+
heritage CTE
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
1. **Scan** — Walk file tree respecting `.gitignore`, skip `node_modules`/`dist`/`build`/etc.
|
|
364
|
+
2. **Parse** — Extract symbols (functions, classes, methods, interfaces, enums, structs, traits) via tree-sitter WASM grammars
|
|
365
|
+
3. **Resolve** — Link imports → symbols, calls → definitions, inheritance chains. Confidence-scored.
|
|
366
|
+
4. **Store** — Write symbols + links to SQLite with FTS5 search index in a single transaction
|
|
367
|
+
5. **Serve** — Expose the knowledge graph via 11 MCP tools + 3 prompts, with built-in agent instructions
|
|
368
|
+
|
|
369
|
+
### Design Decisions
|
|
370
|
+
|
|
371
|
+
- **Declarative `LangSpec`**: Each language is a config object with tree-sitter queries. One universal extractor processes all — no per-language extraction code.
|
|
372
|
+
- **SQLite recursive CTE**: Impact analysis (upstream/downstream) runs entirely in the database. No need to load the full graph into memory.
|
|
373
|
+
- **Token-compact output**: MCP responses use `name [kind] file:line` format. Saves 40-60% tokens for AI agents.
|
|
374
|
+
- **Incremental by default**: File content is SHA-256 hashed; only changed files get re-parsed.
|
|
375
|
+
- **Lazy DB pools**: MCP server opens database connections on demand and evicts them after 5 minutes of inactivity.
|
|
376
|
+
|
|
377
|
+
## Supported Languages
|
|
378
|
+
|
|
379
|
+
| Language | Extensions | Symbols | Imports | Calls | Heritage |
|
|
380
|
+
|---|---|---|---|---|---|
|
|
381
|
+
| TypeScript | `.ts`, `.tsx` | functions, classes, methods, interfaces, enums | ✓ (ESM + require) | ✓ | ✓ |
|
|
382
|
+
| JavaScript | `.js`, `.jsx`, `.mjs`, `.cjs` | functions, classes, methods | ✓ (ESM + require) | ✓ | ✓ |
|
|
383
|
+
| Python | `.py` | functions, classes, methods (+ decorated) | ✓ | ✓ (+ decorators) | ✓ |
|
|
384
|
+
| Java | `.java` | classes, records, interfaces, methods, enums | ✓ (+ static) | ✓ (+ annotations, new) | ✓ |
|
|
385
|
+
| Go | `.go` | functions, methods, structs, interfaces, consts, vars | ✓ | ✓ | — |
|
|
386
|
+
| Rust | `.rs` | functions, structs, enums, traits, methods, consts, mods | ✓ | ✓ (+ macros) | ✓ |
|
|
387
|
+
| PHP | `.php` | functions, classes, interfaces, traits, methods, consts | ✓ (+ include) | ✓ | ✓ (+ traits) |
|
|
388
|
+
| Vue | `.vue` | `<script>` symbols + `<template>` refs (components, events, directives, interpolations) | ✓ | ✓ | ✓ |
|
|
389
|
+
|
|
390
|
+
## Adding a Language
|
|
391
|
+
|
|
392
|
+
Create `src/parser/lang-xxx.ts`:
|
|
393
|
+
|
|
394
|
+
```typescript
|
|
395
|
+
import type { LangSpec } from './extract.js';
|
|
396
|
+
|
|
397
|
+
const spec: LangSpec = {
|
|
398
|
+
id: 'xxx',
|
|
399
|
+
extensions: ['.xxx'],
|
|
400
|
+
wasmName: 'tree-sitter-xxx',
|
|
401
|
+
queries: {
|
|
402
|
+
functions: `(function_definition name: (identifier) @name) @def`,
|
|
403
|
+
classes: `(class_definition name: (identifier) @name) @def`,
|
|
404
|
+
// add queries using tree-sitter playground
|
|
405
|
+
},
|
|
406
|
+
resolveImport(raw, fromFile, root, aliases) {
|
|
407
|
+
// return resolved file path or null
|
|
408
|
+
},
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
export default spec;
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
Then register it in `src/parser/languages.ts`.
|
|
415
|
+
|
|
416
|
+
## Development
|
|
417
|
+
|
|
418
|
+
```bash
|
|
419
|
+
npm install # install dependencies
|
|
420
|
+
npm run build # tsc → dist/
|
|
421
|
+
npm test # vitest
|
|
422
|
+
npm run lint # tsc --noEmit
|
|
423
|
+
npm run self-analyze # index this repo
|
|
424
|
+
npm run self-serve # start MCP server on port 3100
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
## Requirements
|
|
428
|
+
|
|
429
|
+
- Node.js >= 20.0.0
|
|
430
|
+
|
|
431
|
+
## License
|
|
432
|
+
|
|
433
|
+
[PolyForm Noncommercial 1.0.0](LICENSE)
|
|
434
|
+
|
|
435
|
+
Architectural inspiration from [GitNexus](https://github.com/abhigyanpatwari/GitNexus) by Abhigyan Patwari.
|