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.
Files changed (46) hide show
  1. package/LICENSE +75 -75
  2. package/README.md +435 -392
  3. package/dist/analyzer/engine.js +6 -1
  4. package/dist/analyzer/engine.js.map +1 -1
  5. package/dist/cli.js +17 -5
  6. package/dist/cli.js.map +1 -1
  7. package/dist/parser/extract.d.ts.map +1 -1
  8. package/dist/parser/extract.js +8 -0
  9. package/dist/parser/extract.js.map +1 -1
  10. package/dist/parser/lang-go.d.ts.map +1 -1
  11. package/dist/parser/lang-go.js +22 -18
  12. package/dist/parser/lang-go.js.map +1 -1
  13. package/dist/parser/lang-java.d.ts.map +1 -1
  14. package/dist/parser/lang-java.js +28 -17
  15. package/dist/parser/lang-java.js.map +1 -1
  16. package/dist/parser/lang-js.d.ts.map +1 -1
  17. package/dist/parser/lang-js.js +42 -32
  18. package/dist/parser/lang-js.js.map +1 -1
  19. package/dist/parser/lang-php.d.ts.map +1 -1
  20. package/dist/parser/lang-php.js +35 -20
  21. package/dist/parser/lang-php.js.map +1 -1
  22. package/dist/parser/lang-py.d.ts.map +1 -1
  23. package/dist/parser/lang-py.js +36 -17
  24. package/dist/parser/lang-py.js.map +1 -1
  25. package/dist/parser/lang-rust.d.ts.map +1 -1
  26. package/dist/parser/lang-rust.js +26 -19
  27. package/dist/parser/lang-rust.js.map +1 -1
  28. package/dist/parser/lang-ts.d.ts.map +1 -1
  29. package/dist/parser/lang-ts.js +57 -44
  30. package/dist/parser/lang-ts.js.map +1 -1
  31. package/dist/parser/lang-vue.d.ts +6 -0
  32. package/dist/parser/lang-vue.d.ts.map +1 -1
  33. package/dist/parser/lang-vue.js +44 -0
  34. package/dist/parser/lang-vue.js.map +1 -1
  35. package/dist/server/mcp.d.ts.map +1 -1
  36. package/dist/server/mcp.js +289 -21
  37. package/dist/server/mcp.js.map +1 -1
  38. package/dist/skills.d.ts +1 -1
  39. package/dist/skills.d.ts.map +1 -1
  40. package/dist/skills.js +204 -14
  41. package/dist/skills.js.map +1 -1
  42. package/dist/store/db.d.ts.map +1 -1
  43. package/dist/store/db.js +73 -59
  44. package/dist/store/db.js.map +1 -1
  45. package/dist/store/schema.sql +60 -60
  46. 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
- - **10 MCP tools** — query, context, impact, status, detect_changes, explain_relationship, find_dead_code, get_file_symbols, get_type_hierarchy
37
- - **SQLite + FTS5** — full-text symbol search + recursive CTE graph traversal
38
- - **Token-compact output** — minimal structured text, saving 40-60% tokens for AI agents
39
- - **Incremental indexing** — file-hash based, only re-parses changed files
40
- - **Multi-repo registry** — manage multiple codebases from `~/.milens/`
41
- - **Dual transport** — MCP over stdio (VS Code / Cursor) or HTTP (remote agents)
42
- - **Skills generation** — auto-generate context files for Copilot, Cursor, Claude, and Codex
43
-
44
- ## Installation
45
-
46
- ```bash
47
- # Use directly (no install needed)
48
- npx milens analyze -p .
49
-
50
- # Or install globally
51
- npm install -g milens
52
- milens analyze -p . # after global install, npx prefix is optional
53
- ```
54
-
55
- ## Quick Start
56
-
57
- ```bash
58
- # Index a codebase
59
- npx milens analyze -p /path/to/repo --verbose
60
-
61
- # Search for symbols
62
- npx milens search "UserService"
63
-
64
- # 360° symbol context
65
- npx milens inspect "AuthService"
66
-
67
- # Blast radius — what breaks if this changes?
68
- npx milens impact "createUser" --depth 3
69
-
70
- # Start MCP server (stdio for editors)
71
- npx milens serve -p /path/to/repo
72
-
73
- # Start MCP server (HTTP for remote agents)
74
- npx milens serve --http --port 3100
75
- ```
76
-
77
- ## CLI Commands
78
-
79
- | Command | Description |
80
- |---|---|
81
- | `analyze` | Index a codebase into a knowledge graph |
82
- | `search` | Full-text symbol search (FTS5) |
83
- | `inspect` | 360° symbol context — incoming refs + outgoing deps |
84
- | `impact` | Blast radius analysis via recursive CTE |
85
- | `serve` | Start MCP server (stdio or HTTP) |
86
- | `status` | Show index stats |
87
- | `list` | List all indexed repositories |
88
- | `clean` | Remove index for a repository |
89
-
90
- ### `analyze`
91
-
92
- ```bash
93
- npx milens analyze -p /path/to/repo --verbose --force --skills
94
- ```
95
-
96
- Scans source files, parses symbols with tree-sitter, resolves imports/calls/inheritance, and stores everything in `.milens/milens.db`.
97
-
98
- | Flag | Description |
99
- |---|---|
100
- | `-p, --path` | Repository root (default: `.`) |
101
- | `-o, --output` | Custom output directory for the database |
102
- | `-v, --verbose` | Show detailed progress |
103
- | `-f, --force` | Force full re-index (skip hash check) |
104
- | `-s, --skills` | Generate SKILL.md files for Copilot, Cursor, Claude |
105
-
106
- ### `search`
107
-
108
- ```bash
109
- npx milens search "createUser" --limit 10
110
- ```
111
-
112
- ### `inspect`
113
-
114
- ```bash
115
- npx milens inspect "AuthService"
116
- ```
117
-
118
- Shows incoming references (who calls/uses it) and outgoing dependencies (what it calls/imports/extends).
119
-
120
- ### `impact`
121
-
122
- ```bash
123
- npx milens impact "UserModel" --direction upstream --depth 3
124
- ```
125
-
126
- *"What breaks if this symbol changes?"* traverses the dependency graph via recursive CTEs.
127
-
128
- | Flag | Description |
129
- |---|---|
130
- | `-d, --direction` | `upstream` (default) or `downstream` |
131
- | `--depth` | Max traversal depth (default: `3`) |
132
-
133
- ### `serve`
134
-
135
- ```bash
136
- npx milens serve -p /path/to/repo # stdio (for editors)
137
- npx milens serve -p /path/to/repo --http --port 3100 # HTTP
138
- ```
139
-
140
- ### `list`
141
-
142
- ```bash
143
- npx milens list # show all indexed repositories
144
- ```
145
-
146
- ### `clean`
147
-
148
- ```bash
149
- npx milens clean -p /path/to/repo # remove index for one repo
150
- npx milens clean --all # remove all indexes
151
- ```
152
-
153
- ## MCP Server
154
-
155
- milens exposes **10 tools** via the Model Context Protocol:
156
-
157
- | Tool | Description | Key params |
158
- |---|---|---|
159
- | `query` | Search symbols by name/keyword (FTS5) | `query`, `limit` |
160
- | `context` | 360° symbol view — incoming refs, outgoing deps | `name` |
161
- | `impact` | Blast radius with depth grouping | `target`, `direction`, `depth` |
162
- | `status` | Index stats for a repository | `repo` |
163
- | `detect_changes` | Git diff affected symbols + dependents | `ref` |
164
- | `explain_relationship` | Shortest path between two symbols | `from`, `to` |
165
- | `find_dead_code` | Exported symbols with zero references | `kind`, `limit` |
166
- | `get_file_symbols` | All symbols in a specific file | `file` |
167
- | `get_type_hierarchy` | Inheritance/implementation tree | `name` |
168
-
169
- > When only one repo is indexed, the `repo` parameter is optional on all tools.
170
-
171
- ### Tool Examples
172
-
173
- ```
174
- # Search
175
- query({query: "auth"})
176
- AuthService [class] src/auth/service.ts:10
177
- validateUser [function] src/auth/validate.ts:15
178
-
179
- # Context
180
- context({name: "validateUser"})
181
- → incoming:
182
- calls: handleLogin (src/api/auth.ts)
183
- outgoing:
184
- calls: checkPassword (src/auth/hash.ts)
185
-
186
- # Impact
187
- impact({target: "UserService", direction: "upstream"})
188
- depth 1:
189
- handleLogin [function] src/api/auth.ts:45 (calls)
190
- UserController [class] src/controllers/user.ts:12 (calls)
191
- depth 2:
192
- authRouter [module] src/routes/auth.ts (imports)
193
-
194
- # Detect changes
195
- detect_changes({ref: "HEAD"})
196
- → changed: src/auth/service.ts
197
- affected: handleLogin, UserController
198
-
199
- # Dead code
200
- find_dead_code({kind: "function"})
201
- → legacyHash [function] src/utils/hash.ts:42 (0 refs)
202
- ```
203
-
204
- ## Editor Integration
205
-
206
- ### VS Code / GitHub Copilot
207
-
208
- Add to `.vscode/mcp.json`:
209
-
210
- ```json
211
- {
212
- "servers": {
213
- "milens": {
214
- "type": "stdio",
215
- "command": "npx",
216
- "args": ["-y", "milens", "serve", "-p", "${workspaceFolder}"]
217
- }
218
- }
219
- }
220
- ```
221
-
222
- ### Cursor
223
-
224
- Add to `.cursor/mcp.json` (per-project):
225
-
226
- ```json
227
- {
228
- "mcpServers": {
229
- "milens": {
230
- "command": "npx",
231
- "args": ["-y", "milens", "serve", "-p", "."]
232
- }
233
- }
234
- }
235
- ```
236
-
237
- ### Claude Code
238
-
239
- ```bash
240
- claude mcp add milens -- npx -y milens serve -p .
241
- ```
242
-
243
- ### Codex
244
-
245
- Add to `.codex/config.toml`:
246
-
247
- ```toml
248
- [mcp_servers.milens]
249
- command = "npx"
250
- args = ["-y", "milens", "serve", "-p", "."]
251
- ```
252
-
253
- ### HTTP Mode (remote agents)
254
-
255
- ```bash
256
- npx milens serve --http --port 3100
257
- ```
258
-
259
- Endpoint: `POST http://localhost:3100/mcp`
260
-
261
- ## Skills Generation
262
-
263
- Generate editor-specific context files from your codebase's knowledge graph:
264
-
265
- ```bash
266
- npx milens analyze -p . --skills
267
- ```
268
-
269
- This creates:
270
-
271
- | Path | For |
272
- |---|---|
273
- | `.github/instructions/*.instructions.md` | GitHub Copilot |
274
- | `.cursor/rules/*.mdc` | Cursor |
275
- | `.claude/skills/generated/*/SKILL.md` | Claude Code |
276
-
277
- Each skill file contains: key symbols, entry points, cross-area dependencies, and file listings — so AI agents get targeted context for the area of code you're working in.
278
-
279
- ## Architecture
280
-
281
- ```
282
- src/
283
- cli.ts — CLI entry point (commander, 8 commands)
284
- types.ts — Shared types (CodeSymbol, SymbolLink, etc.)
285
- skills.ts — Skills/context file generator
286
- parser/
287
- loader.ts — Tree-sitter WASM loading + caching
288
- extract.ts — Universal extractor + LangSpec interface
289
- lang-ts.ts — TypeScript (+ .tsx)
290
- lang-js.ts — JavaScript (+ .jsx, .mjs, .cjs)
291
- lang-py.ts — Python
292
- lang-java.ts — Java
293
- lang-go.ts — Go
294
- lang-rust.ts — Rust
295
- lang-php.ts — PHP
296
- lang-vue.ts — Vue (extracts <script>, delegates to TS)
297
- languages.ts — Language registry
298
- analyzer/
299
- scanner.ts — File discovery (.gitignore aware)
300
- resolver.ts — Import + call + heritage resolution
301
- engine.ts — Pipeline orchestrator (6 phases)
302
- store/
303
- schema.sql — SQLite schema (FTS5, triggers, indexes)
304
- db.ts — Database adapter (30+ methods, recursive CTEs)
305
- registry.ts — Multi-repo registry (~/.milens/)
306
- server/
307
- mcp.ts — MCP server (10 tools, stdio + HTTP)
308
- ```
309
-
310
- ### How It Works
311
-
312
- ```
313
- Source Files [Scan] [Parse] [Resolve] [Store] → [Serve]
314
- │ │ │ │ │
315
- .gitignore tree-sitter imports SQLite MCP
316
- filter WASM AST calls FTS5 stdio/HTTP
317
- heritage CTE
318
- ```
319
-
320
- 1. **Scan** — Walk file tree respecting `.gitignore`, skip `node_modules`/`dist`/`build`/etc.
321
- 2. **Parse** — Extract symbols (functions, classes, methods, interfaces, enums, structs, traits) via tree-sitter WASM grammars
322
- 3. **Resolve** — Link imports → symbols, calls → definitions, inheritance chains. Confidence-scored.
323
- 4. **Store** — Write symbols + links to SQLite with FTS5 search index in a single transaction
324
- 5. **Serve** — Expose the knowledge graph via 10 MCP tools or CLI commands
325
-
326
- ### Design Decisions
327
-
328
- - **Declarative `LangSpec`**: Each language is a config object with tree-sitter queries. One universal extractor processes all no per-language extraction code.
329
- - **SQLite recursive CTE**: Impact analysis (upstream/downstream) runs entirely in the database. No need to load the full graph into memory.
330
- - **Token-compact output**: MCP responses use `name [kind] file:line` format. Saves 40-60% tokens for AI agents.
331
- - **Incremental by default**: File content is SHA-256 hashed; only changed files get re-parsed.
332
- - **Lazy DB pools**: MCP server opens database connections on demand and evicts them after 5 minutes of inactivity.
333
-
334
- ## Supported Languages
335
-
336
- | Language | Extensions | Symbols | Imports | Calls | Heritage |
337
- |---|---|---|---|---|---|
338
- | TypeScript | `.ts`, `.tsx` | functions, classes, methods, interfaces, enums | ✓ | ✓ | ✓ |
339
- | JavaScript | `.js`, `.jsx`, `.mjs`, `.cjs` | functions, classes, methods | ✓ | ✓ | ✓ |
340
- | Python | `.py` | functions, classes, methods | ✓ | ✓ | ✓ |
341
- | Java | `.java` | classes, interfaces, methods, enums | ✓ | ✓ | ✓ |
342
- | Go | `.go` | functions, methods, structs, interfaces | ✓ | ✓ | — |
343
- | Rust | `.rs` | functions, structs, enums, traits, methods | ✓ | ✓ | ✓ |
344
- | PHP | `.php` | functions, classes, interfaces, methods | ✓ | ✓ | ✓ |
345
- | Vue | `.vue` | (delegates to TypeScript on `<script>` block) | ✓ | ✓ | ✓ |
346
-
347
- ## Adding a Language
348
-
349
- Create `src/parser/lang-xxx.ts`:
350
-
351
- ```typescript
352
- import type { LangSpec } from './extract.js';
353
-
354
- const spec: LangSpec = {
355
- id: 'xxx',
356
- extensions: ['.xxx'],
357
- wasmName: 'tree-sitter-xxx',
358
- queries: {
359
- functions: `(function_definition name: (identifier) @name) @def`,
360
- classes: `(class_definition name: (identifier) @name) @def`,
361
- // add queries using tree-sitter playground
362
- },
363
- resolveImport(raw, fromFile, root, aliases) {
364
- // return resolved file path or null
365
- },
366
- };
367
-
368
- export default spec;
369
- ```
370
-
371
- Then register it in `src/parser/languages.ts`.
372
-
373
- ## Development
374
-
375
- ```bash
376
- npm install # install dependencies
377
- npm run build # tsc → dist/
378
- npm test # vitest
379
- npm run lint # tsc --noEmit
380
- npm run self-analyze # index this repo
381
- npm run self-serve # start MCP server on port 3100
382
- ```
383
-
384
- ## Requirements
385
-
386
- - Node.js >= 20.0.0
387
-
388
- ## License
389
-
390
- [PolyForm Noncommercial 1.0.0](LICENSE)
391
-
392
- Architectural inspiration from [GitNexus](https://github.com/abhigyanpatwari/GitNexus) by Abhigyan Patwari.
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.