milens 0.5.8 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,468 +1,477 @@
1
- <p align="center">
2
- <strong>milens</strong><br>
3
- <em>Code Intelligence Engine for AI Agents</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
- <img src="https://img.shields.io/badge/languages-12-orange" alt="12 Languages">
11
- <img src="https://img.shields.io/badge/MCP_tools-21-purple" alt="21 MCP Tools">
12
- </p>
13
-
14
- <p align="center">
15
- <strong>Index any codebase → Knowledge graph → AI agents that never miss code</strong>
16
- </p>
17
-
18
- <p align="center">
19
- <a href="#the-problem">Why?</a> •
20
- <a href="#quick-start">Quick Start</a> •
21
- <a href="#cli-commands">CLI Commands</a> •
22
- <a href="#mcp-tools">MCP Tools</a> •
23
- <a href="#editor-setup">Editors</a> •
24
- <a href="#supported-languages">Languages</a>
25
- </p>
26
-
27
- ---
28
-
29
- ## The Problem
30
-
31
- You're burning tokens and premium requests on tasks that milens can handle at a fraction of the cost. Every time your agent explores a codebase — reading files one by one, searching for references, tracing call chains — you're paying for what a pre-built knowledge graph delivers instantly.
32
-
33
- **Why not let milens save your wallet?**
34
-
35
- One `milens analyze` replaces dozens of agent tool calls. Instead of the agent spending 10+ steps to map out a function's dependencies, `impact()` returns the full blast radius in a single call.
36
-
37
- If you're concerned about security, read our [Security & Privacy](#security--privacy) guarantees — milens is fully offline, zero telemetry, localhost-only.
38
-
39
- ### How milens Solves This
40
-
41
- <p align="center">
42
- <img src="docs/diagram1.svg" alt="Without milens vs With milens comparison" width="700">
43
- </p>
44
-
45
- milens builds a **pre-indexed knowledge graph** at analysis time — resolving every import, call, and inheritance chain — so that any tool query returns the full dependency picture instantly, without multi-step exploration.
46
-
47
- ---
48
-
49
- ## Quick Start
50
-
51
- ```bash
52
- npx milens analyze # index your codebase
53
- ```
54
-
55
- Then add the MCP server to your editor ([setup below](#editor-setup)) and your agent immediately gets 19 code intelligence tools.
56
-
57
- ---
58
-
59
- ## CLI Commands
60
-
61
- ### `milens analyze` — Index a codebase
62
-
63
- Parse all source files, resolve cross-file dependencies, and build a searchable knowledge graph.
64
-
65
- ```bash
66
- milens analyze # index current directory
67
- milens analyze -p /path/to/repo # index a specific repo
68
- milens analyze -p . --force # full re-index (ignore cache)
69
- milens analyze -p . --force --verbose # full re-index with detailed progress
70
- ```
71
-
72
- **Output:** A `.milens/milens.db` SQLite database containing every symbol, relationship, and search index.
73
-
74
- **Incremental mode:** By default, only re-parses files whose SHA-256 hash has changed since the last run.
75
-
76
- #### Generating AI skill files
77
-
78
- Skill files teach your AI agent the codebase structure — key symbols, entry points, cross-area dependencies — without reading every file.
79
-
80
- ```bash
81
- milens analyze -p . --skills # generate for all editors
82
- milens analyze -p . --skills-copilot # GitHub Copilot only
83
- milens analyze -p . --skills-cursor # Cursor only
84
- milens analyze -p . --skills-claude # Claude Code only
85
- milens analyze -p . --skills-agents # AGENTS.md only
86
- milens analyze -p . --skills-windsurf # Windsurf only
87
- ```
88
-
89
- | Flag | Output files |
90
- |---|---|
91
- | `--skills-copilot` | `.github/instructions/*.instructions.md` + `.github/copilot-instructions.md` |
92
- | `--skills-cursor` | `.cursor/rules/*.mdc` + `.cursor/index.mdc` |
93
- | `--skills-claude` | `.claude/skills/generated/*/SKILL.md` + `.claude/rules/*.md` + `CLAUDE.md` |
94
- | `--skills-agents` | `.agents/skills/*/SKILL.md` + `AGENTS.md` |
95
- | `--skills-windsurf` | `.windsurfrules` |
96
-
97
- > Root config files use `<!-- milens:start/end -->` markers for **idempotent injection** — re-running replaces the milens section without overwriting your custom content.
98
-
99
- ---
100
-
101
- ### `milens search` Find symbols by name
102
-
103
- Full-text search (BM25) across all indexed symbol names and file paths.
104
-
105
- ```bash
106
- milens search "UserService" # search for symbols
107
- milens search "auth" --limit 50 # increase result limit (default: 20)
108
- milens search "handler" -p /path/to/repo # search in a specific repo
109
- ```
110
-
111
- **Output format:** `name [kind] file:line (exported)`
112
-
113
- ```
114
- AuthService [class] src/auth.ts:15 (exported)
115
- hashPassword [function] src/auth.ts:3 (exported)
116
- ```
117
-
118
- ---
119
-
120
- ### `milens inspect` 360° symbol view
121
-
122
- Show everything about a symbol: who calls it (incoming) and what it depends on (outgoing).
123
-
124
- ```bash
125
- milens inspect "AuthService"
126
- milens inspect "resolveLinks" -p .
127
- ```
128
-
129
- **Output:**
130
-
131
- ```
132
- AuthService [class] src/auth.ts:15
133
- incoming:
134
- calls: handleLogin (src/routes.ts)
135
- calls: UserController (src/controllers/user.ts)
136
- outgoing:
137
- imports: User (src/models.ts)
138
- calls: hashPassword (src/auth.ts)
139
- calls: createUser (src/models.ts)
140
- ```
141
-
142
- ---
143
-
144
- ### `milens impact` — Blast radius analysis
145
-
146
- Recursively trace what depends on a symbol (upstream) or what a symbol depends on (downstream).
147
-
148
- ```bash
149
- milens impact "createUser" # upstream: what breaks if this changes?
150
- milens impact "UserModel" -d downstream # downstream: what does this depend on?
151
- milens impact "searchSymbols" --depth 2 # limit traversal depth (default: 3)
152
- ```
153
-
154
- **Output:**
155
-
156
- ```
157
- TARGET: createUser [function] src/models.ts:42
158
- [depth 1] AuthService [class] src/auth.ts:15 (calls)
159
- [depth 1] UserController [class] src/controllers/user.ts:8 (calls)
160
- [depth 2] handleLogin [function] src/routes.ts:23 (calls)
161
- ```
162
-
163
- **Depth meaning:**
164
- - Depth 1 = **WILL BREAK** — direct callers/dependents
165
- - Depth 2 = **LIKELY AFFECTED** — indirect dependents
166
- - Depth 3 = **MAY NEED TESTING** — transitive dependents
167
-
168
- ---
169
-
170
- ### `milens serve` — Start MCP server
171
-
172
- Expose the knowledge graph to AI agents via the Model Context Protocol.
173
-
174
- ```bash
175
- milens serve # stdio transport (for editors)
176
- milens serve -p /path/to/repo # serve a specific repo
177
- milens serve --http # HTTP transport on port 3100
178
- milens serve --http --port 8080 # HTTP on custom port
179
- ```
180
-
181
- **stdio mode** (default): Used by editors like VS Code, Cursor, and Claude Code. The agent communicates through stdin/stdout.
182
-
183
- **HTTP mode**: Used by remote agents or custom integrations. Binds to `127.0.0.1` only — no network exposure.
184
-
185
- Endpoint: `POST http://localhost:3100/mcp`
186
-
187
- ---
188
-
189
- ### `milens status` — Show index stats
190
-
191
- ```bash
192
- milens status # current directory
193
- milens status -p /path/to/repo # specific repo
194
- ```
195
-
196
- **Output:**
197
-
198
- ```
199
- Repository: /home/user/my-project
200
- Database: /home/user/my-project/.milens/milens.db
201
- Indexed: 2026-04-11T10:30:00Z
202
- Symbols: 210
203
- Links: 348
204
- Files: 30
205
- ```
206
-
207
- ---
208
-
209
- ### `milens list` — List all indexed repositories
210
-
211
- ```bash
212
- milens list
213
- ```
214
-
215
- **Output:**
216
-
217
- ```
218
- 3 indexed repositories:
219
-
220
- /home/user/project-a
221
- DB: /home/user/project-a/.milens/milens.db
222
- Indexed: 2026-04-11T10:30:00Z
223
-
224
- /home/user/project-b
225
- DB: /home/user/project-b/.milens/milens.db
226
- Indexed: 2026-04-10T15:22:00Z
227
- ```
228
-
229
- ---
230
-
231
- ### `milens clean` — Remove index
232
-
233
- ```bash
234
- milens clean # remove index for current directory
235
- milens clean -p /path/to/repo # remove index for specific repo
236
- milens clean --all # remove ALL indexes
237
- ```
238
-
239
- ---
240
-
241
- ### `milens dashboard` — Usage analytics
242
-
243
- Open a browser-based dashboard showing tool usage statistics, token savings, and response times.
244
-
245
- ```bash
246
- milens dashboard # open on port 3200
247
- milens dashboard --port 8080 # custom port
248
- ```
249
-
250
- ---
251
-
252
- ## MCP Tools
253
-
254
- When the MCP server is running, your AI agent gets these 21 tools:
255
-
256
- ### Search & Navigate
257
-
258
- | Tool | What It Does | Example |
259
- |---|---|---|
260
- | `query` | Symbol search (FTS5 full-text) | `query({query: "UserService"})` |
261
- | `grep` | Text search ALL files — code, templates, configs, docs | `grep({pattern: "TODO", scope: "all"})` |
262
- | `context` | 360° symbol view — incoming refs + outgoing deps | `context({name: "AuthService"})` |
263
- | `get_file_symbols` | All symbols in a file with ref/dep counts | `get_file_symbols({file: "src/auth.ts"})` |
264
- | `get_type_hierarchy` | Inheritance/implementation tree | `get_type_hierarchy({name: "BaseController"})` |
265
-
266
- ### Impact & Safety
267
-
268
- | Tool | What It Does | Example |
269
- |---|---|---|
270
- | `impact` | Blast radius: what breaks if this changes? | `impact({target: "createUser"})` |
271
- | `edit_check` | Pre-edit safety: callers + exports + test coverage + warnings | `edit_check({name: "resolveLinks"})` |
272
- | `detect_changes` | Git diff affected symbols + direct dependents | `detect_changes({})` |
273
- | `find_dead_code` | Exported symbols with zero references | `find_dead_code({})` |
274
-
275
- ### Understanding
276
-
277
- | Tool | What It Does | Example |
278
- |---|---|---|
279
- | `smart_context` | Intent-aware context: `understand`/`edit`/`debug`/`test` | `smart_context({name: "analyze", intent: "edit"})` |
280
- | `trace` | Execution flow: call chains to/from entrypoints | `trace({to: "searchSymbols"})` |
281
- | `routes` | Detect framework routes/endpoints | `routes({})` |
282
- | `explain_relationship` | Shortest path between two symbols | `explain_relationship({from: "A", to: "B"})` |
283
- | `overview` | Combined context + impact + grep in ONE call | `overview({name: "Database"})` |
284
-
285
- ### Codebase Overview
286
-
287
- | Tool | What It Does | Example |
288
- |---|---|---|
289
- | `domains` | Domain clusters groups of files forming logical modules | `domains({})` |
290
- | `repos` | List all indexed repositories | `repos({})` |
291
- | `status` | Index stats, domains, test coverage, accuracy report | `status({})` |
292
-
293
- ### Developer Tools
294
-
295
- | Tool | What It Does | Example |
296
- |---|---|---|
297
- | `ast_explore` | Parse code snippet → S-expression AST tree | `ast_explore({code: "const x = 1", language: "typescript"})` |
298
- | `test_query` | Test tree-sitter query against code snippet | `test_query({query: "(identifier) @name", code: "const x = 1", language: "typescript"})` |
299
-
300
- ### Resources & Prompts
301
-
302
- **4 Resources:** `milens://overview`, `milens://symbol/{name}`, `milens://file/{path}`, `milens://domain/{name}`
303
-
304
- **3 Guided Prompts:** `delete-feature`, `refactor-symbol`, `explore-symbol` each triggers a multi-step workflow using the tools above.
305
-
306
- ---
307
-
308
- ## Editor Setup
309
-
310
- ### VS Code / GitHub Copilot
311
-
312
- ```bash
313
- npx milens analyze -p . # index your repo (run once)
314
- ```
315
-
316
- Add to `.vscode/mcp.json`:
317
-
318
- ```json
319
- {
320
- "servers": {
321
- "milens": {
322
- "type": "stdio",
323
- "command": "npx",
324
- "args": ["-y", "milens", "serve", "-p", "${workspaceFolder}"]
325
- }
326
- }
327
- }
328
- ```
329
-
330
- <details>
331
- <summary><strong>Other Editors</strong></summary>
332
-
333
- #### Cursor
334
-
335
- Add to `.cursor/mcp.json`:
336
-
337
- ```json
338
- {
339
- "mcpServers": {
340
- "milens": {
341
- "command": "npx",
342
- "args": ["-y", "milens", "serve", "-p", "."]
343
- }
344
- }
345
- }
346
- ```
347
-
348
- #### Claude Code
349
-
350
- ```bash
351
- claude mcp add milens -- npx -y milens serve -p .
352
- ```
353
-
354
- #### Windsurf
355
-
356
- Add to `~/.codeium/windsurf/mcp_config.json`:
357
-
358
- ```json
359
- {
360
- "mcpServers": {
361
- "milens": {
362
- "command": "npx",
363
- "args": ["-y", "milens", "serve", "-p", "."]
364
- }
365
- }
366
- }
367
- ```
368
-
369
- #### Codex
370
-
371
- Add to `.codex/config.toml`:
372
-
373
- ```toml
374
- [mcp_servers.milens]
375
- command = "npx"
376
- args = ["-y", "milens", "serve", "-p", "."]
377
- ```
378
-
379
- </details>
380
-
381
- ---
382
-
383
- ## Supported Languages
384
-
385
- | Language | Extensions | Imports | Calls | Heritage | Frameworks |
386
- |---|---|---|---|---|---|
387
- | TypeScript | `.ts` `.tsx` | ✓ ESM + require | ✓ + decorators | ✓ extends/implements | NestJS, React JSX |
388
- | JavaScript | `.js` `.jsx` `.mjs` `.cjs` | ✓ ESM + require | ✓ | ✓ | React JSX, Express |
389
- | Python | `.py` | ✓ | ✓ + decorators | ✓ | FastAPI, Flask |
390
- | Java | `.java` | ✓ + static | ✓ + annotations, new | ✓ | Spring |
391
- | Go | `.go` | ✓ | ✓ | — | net/http |
392
- | Rust | `.rs` | ✓ | ✓ + macros | ✓ | — |
393
- | PHP | `.php` | ✓ + include | ✓ + static, new | ✓ + traits | Laravel |
394
- | Ruby | `.rb` | | | | Rails |
395
- | Vue | `.vue` | ✓ | ✓ template refs | ✓ | Vue 3 SFC |
396
- | HTML | `.html` `.htm` | ✓ `<script src>` `<link>` | ✓ inline `<script>` | | |
397
- | CSS | `.css` | ✓ `@import` | | | Custom properties |
398
- | Markdown | `.md` `.mdx` | ✓ local `[links]()` | | | Headings → section symbols, parent-child hierarchy |
399
-
400
- ---
401
-
402
- ## Architecture
403
-
404
- <p align="center">
405
- <img src="docs/diagram2.svg" alt="milens architecture: Indexing Pipeline MCP Server AI Agent" width="700">
406
- </p>
407
-
408
- ### How it works
409
-
410
- 1. **Scan** — find all source files matching supported extensions
411
- 2. **Parse** — tree-sitter extracts symbols (functions, classes, methods, etc.) and raw references (imports, calls, extends)
412
- 3. **Resolve** — cross-file link resolution: match import paths to files, match call names to symbol definitions
413
- 4. **Enrich** — compute roles (entrypoint/hub/utility/leaf), heat scores, domain clusters
414
- 5. **Persist** store everything in SQLite with FTS5 search and recursive CTEs for graph traversal
415
-
416
- ### Multi-Repo
417
-
418
- milens uses a global registry (`~/.milens/`) — one MCP server serves all indexed repos. Pass `repo` to target a specific one when multiple are registered.
419
-
420
- <p align="center">
421
- <img src="docs/diagram3.svg" alt="Multi-repo architecture" width="500">
422
- </p>
423
-
424
- ### Design Decisions
425
-
426
- | Decision | Rationale |
427
- |---|---|
428
- | **Declarative LangSpec** | Each language = 1 config object with tree-sitter queries. One universal extractor for all 12 languages |
429
- | **SQLite + recursive CTE** | Impact analysis runs entirely in the database — no full graph in memory |
430
- | **Token-compact output** | `name [kind] file:line` format — saves 40-60% tokens for AI |
431
- | **Incremental by hash** | SHA-256 file hashing — only changed files get re-parsed |
432
- | **Localhost-only HTTP** | Binds `127.0.0.1` — no network exposure without explicit intent |
433
-
434
- ---
435
-
436
- ## Security & Privacy
437
-
438
- milens is **offline by design** — zero network calls, zero telemetry.
439
-
440
- | Layer | Protection |
441
- |---|---|
442
- | **Data locality** | Index lives in `.milens/` per repo (gitignored). No source code stored in registry |
443
- | **HTTP transport** | Binds to `127.0.0.1` only — requires explicit `--http` flag |
444
- | **User-supplied regex** | Validated against ReDoS patterns |
445
- | **FTS5 queries** | Each token quoted as a literal — no query injection |
446
- | **File access** | All reads bounded to the repo root — no path traversal |
447
- | **Git integration** | `execFileSync` with argument arrays no shell interpolation |
448
-
449
- ---
450
-
451
- ## Development
452
-
453
- ```bash
454
- npm install # install dependencies
455
- npm run build # tsc dist/
456
- npm test # vitest (65 tests)
457
- npm run lint # tsc --noEmit
458
- npm run self-analyze # index this repo
459
- npm run self-serve # start MCP server on port 3100
460
- ```
461
-
462
- ---
463
-
464
- ## License
465
-
466
- [PolyForm Noncommercial 1.0.0](LICENSE)
467
-
468
- Architectural inspiration from [GitNexus](https://github.com/abhigyanpatwari/GitNexus) by Abhigyan Patwari.
1
+ <p align="center">
2
+ <strong>milens</strong><br>
3
+ <em>Code Intelligence Engine for AI Agents</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
+ <img src="https://img.shields.io/badge/languages-12-orange" alt="12 Languages">
11
+ <img src="https://img.shields.io/badge/MCP_tools-21-purple" alt="21 MCP Tools">
12
+ </p>
13
+
14
+ <p align="center">
15
+ <strong>Index any codebase → Knowledge graph → AI agents that never miss code</strong>
16
+ </p>
17
+
18
+ <p align="center">
19
+ <a href="#the-problem">Why?</a> •
20
+ <a href="#quick-start">Quick Start</a> •
21
+ <a href="#cli-commands">CLI Commands</a> •
22
+ <a href="#mcp-tools">MCP Tools</a> •
23
+ <a href="#editor-setup">Editors</a> •
24
+ <a href="#supported-languages">Languages</a>
25
+ </p>
26
+
27
+ ---
28
+
29
+ ## The Problem
30
+
31
+ You're burning tokens and premium requests on tasks that milens can handle at a fraction of the cost. Every time your agent explores a codebase — reading files one by one, searching for references, tracing call chains — you're paying for what a pre-built knowledge graph delivers instantly.
32
+
33
+ **Why not let milens save your wallet?**
34
+
35
+ One `milens analyze` replaces dozens of agent tool calls. Instead of the agent spending 10+ steps to map out a function's dependencies, `impact()` returns the full blast radius in a single call.
36
+
37
+ If you're concerned about security, read our [Security & Privacy](#security--privacy) guarantees — milens is fully offline, zero telemetry, localhost-only.
38
+
39
+ ### How milens Solves This
40
+
41
+ <p align="center">
42
+ <img src="docs/diagram1.svg" alt="Without milens vs With milens comparison" width="700">
43
+ </p>
44
+
45
+ milens builds a **pre-indexed knowledge graph** at analysis time — resolving every import, call, and inheritance chain — so that any tool query returns the full dependency picture instantly, without multi-step exploration.
46
+
47
+ ---
48
+
49
+ ## Quick Start
50
+
51
+ ```bash
52
+ npx milens analyze # index your codebase
53
+ ```
54
+
55
+ Then add the MCP server to your editor ([setup below](#editor-setup)) and your agent immediately gets 19 code intelligence tools.
56
+
57
+ ---
58
+
59
+ ## CLI Commands
60
+
61
+ ### `milens analyze` — Index a codebase
62
+
63
+ Parse all source files, resolve cross-file dependencies, and build a searchable knowledge graph.
64
+
65
+ ```bash
66
+ milens analyze # index current directory
67
+ milens analyze -p /path/to/repo # index a specific repo
68
+ milens analyze -p . --force # full re-index (ignore cache)
69
+ milens analyze -p . --force --verbose # full re-index with detailed progress
70
+ ```
71
+
72
+ **Output:** A `.milens/milens.db` SQLite database containing every symbol, relationship, and search index.
73
+
74
+ **Incremental mode:** By default, only re-parses files whose SHA-256 hash has changed since the last run.
75
+
76
+ #### Generating AI skill files
77
+
78
+ Skill files teach your AI agent the codebase structure — key symbols, entry points, cross-area dependencies — without reading every file.
79
+
80
+ ```bash
81
+ milens analyze -p . --skills # generate for all editors
82
+ milens analyze -p . --skills-copilot # GitHub Copilot only
83
+ milens analyze -p . --skills-cursor # Cursor only
84
+ milens analyze -p . --skills-claude # Claude Code only
85
+ milens analyze -p . --skills-agents # AGENTS.md only
86
+ milens analyze -p . --skills-windsurf # Windsurf only
87
+ ```
88
+
89
+ | Flag | Output files |
90
+ |---|---|
91
+ | `--skills-copilot` | `.github/instructions/*.instructions.md` + `.github/copilot-instructions.md` |
92
+ | `--skills-cursor` | `.cursor/rules/*.mdc` + `.cursor/index.mdc` |
93
+ | `--skills-claude` | `.claude/skills/generated/*/SKILL.md` + `.claude/rules/*.md` + `CLAUDE.md` |
94
+ | `--skills-agents` | `.agents/skills/*/SKILL.md` + `AGENTS.md` |
95
+ | `--skills-windsurf` | `.windsurfrules` |
96
+
97
+ > Root config files use `<!-- milens:start/end -->` markers for **idempotent injection** — re-running replaces the milens section without overwriting your custom content.
98
+
99
+ **Team Collaboration Notes:**
100
+
101
+ - **Instruction files are safe to commit** - They use `<workspaceRoot>` placeholder instead of absolute paths
102
+ - ✅ **No merge conflicts** - No machine-specific information (username, absolute paths, etc.)
103
+ - **Consistent AI assistance** - All team members get the same codebase intelligence
104
+ - ⚠️ **Database is gitignored** - `.milens/*.db` files are local; each developer runs `npx milens analyze` after clone
105
+
106
+ See [`.milens/README.md`](.milens/README.md) for more details on the index directory.
107
+
108
+ ---
109
+
110
+ ### `milens search` — Find symbols by name
111
+
112
+ Full-text search (BM25) across all indexed symbol names and file paths.
113
+
114
+ ```bash
115
+ milens search "UserService" # search for symbols
116
+ milens search "auth" --limit 50 # increase result limit (default: 20)
117
+ milens search "handler" -p /path/to/repo # search in a specific repo
118
+ ```
119
+
120
+ **Output format:** `name [kind] file:line (exported)`
121
+
122
+ ```
123
+ AuthService [class] src/auth.ts:15 (exported)
124
+ hashPassword [function] src/auth.ts:3 (exported)
125
+ ```
126
+
127
+ ---
128
+
129
+ ### `milens inspect` — 360° symbol view
130
+
131
+ Show everything about a symbol: who calls it (incoming) and what it depends on (outgoing).
132
+
133
+ ```bash
134
+ milens inspect "AuthService"
135
+ milens inspect "resolveLinks" -p .
136
+ ```
137
+
138
+ **Output:**
139
+
140
+ ```
141
+ AuthService [class] src/auth.ts:15
142
+ incoming:
143
+ calls: handleLogin (src/routes.ts)
144
+ calls: UserController (src/controllers/user.ts)
145
+ outgoing:
146
+ imports: User (src/models.ts)
147
+ calls: hashPassword (src/auth.ts)
148
+ calls: createUser (src/models.ts)
149
+ ```
150
+
151
+ ---
152
+
153
+ ### `milens impact` — Blast radius analysis
154
+
155
+ Recursively trace what depends on a symbol (upstream) or what a symbol depends on (downstream).
156
+
157
+ ```bash
158
+ milens impact "createUser" # upstream: what breaks if this changes?
159
+ milens impact "UserModel" -d downstream # downstream: what does this depend on?
160
+ milens impact "searchSymbols" --depth 2 # limit traversal depth (default: 3)
161
+ ```
162
+
163
+ **Output:**
164
+
165
+ ```
166
+ TARGET: createUser [function] src/models.ts:42
167
+ [depth 1] AuthService [class] src/auth.ts:15 (calls)
168
+ [depth 1] UserController [class] src/controllers/user.ts:8 (calls)
169
+ [depth 2] handleLogin [function] src/routes.ts:23 (calls)
170
+ ```
171
+
172
+ **Depth meaning:**
173
+ - Depth 1 = **WILL BREAK** — direct callers/dependents
174
+ - Depth 2 = **LIKELY AFFECTED** — indirect dependents
175
+ - Depth 3 = **MAY NEED TESTING** — transitive dependents
176
+
177
+ ---
178
+
179
+ ### `milens serve` — Start MCP server
180
+
181
+ Expose the knowledge graph to AI agents via the Model Context Protocol.
182
+
183
+ ```bash
184
+ milens serve # stdio transport (for editors)
185
+ milens serve -p /path/to/repo # serve a specific repo
186
+ milens serve --http # HTTP transport on port 3100
187
+ milens serve --http --port 8080 # HTTP on custom port
188
+ ```
189
+
190
+ **stdio mode** (default): Used by editors like VS Code, Cursor, and Claude Code. The agent communicates through stdin/stdout.
191
+
192
+ **HTTP mode**: Used by remote agents or custom integrations. Binds to `127.0.0.1` only — no network exposure.
193
+
194
+ Endpoint: `POST http://localhost:3100/mcp`
195
+
196
+ ---
197
+
198
+ ### `milens status` — Show index stats
199
+
200
+ ```bash
201
+ milens status # current directory
202
+ milens status -p /path/to/repo # specific repo
203
+ ```
204
+
205
+ **Output:**
206
+
207
+ ```
208
+ Repository: /home/user/my-project
209
+ Database: /home/user/my-project/.milens/milens.db
210
+ Indexed: 2026-04-11T10:30:00Z
211
+ Symbols: 210
212
+ Links: 348
213
+ Files: 30
214
+ ```
215
+
216
+ ---
217
+
218
+ ### `milens list` — List all indexed repositories
219
+
220
+ ```bash
221
+ milens list
222
+ ```
223
+
224
+ **Output:**
225
+
226
+ ```
227
+ 3 indexed repositories:
228
+
229
+ /home/user/project-a
230
+ DB: /home/user/project-a/.milens/milens.db
231
+ Indexed: 2026-04-11T10:30:00Z
232
+
233
+ /home/user/project-b
234
+ DB: /home/user/project-b/.milens/milens.db
235
+ Indexed: 2026-04-10T15:22:00Z
236
+ ```
237
+
238
+ ---
239
+
240
+ ### `milens clean` — Remove index
241
+
242
+ ```bash
243
+ milens clean # remove index for current directory
244
+ milens clean -p /path/to/repo # remove index for specific repo
245
+ milens clean --all # remove ALL indexes
246
+ ```
247
+
248
+ ---
249
+
250
+ ### `milens dashboard` — Usage analytics
251
+
252
+ Open a browser-based dashboard showing tool usage statistics, token savings, and response times.
253
+
254
+ ```bash
255
+ milens dashboard # open on port 3200
256
+ milens dashboard --port 8080 # custom port
257
+ ```
258
+
259
+ ---
260
+
261
+ ## MCP Tools
262
+
263
+ When the MCP server is running, your AI agent gets these 21 tools:
264
+
265
+ ### Search & Navigate
266
+
267
+ | Tool | What It Does | Example |
268
+ |---|---|---|
269
+ | `query` | Symbol search (FTS5 full-text) | `query({query: "UserService"})` |
270
+ | `grep` | Text search ALL files code, templates, configs, docs | `grep({pattern: "TODO", scope: "all"})` |
271
+ | `context` | 360° symbol view incoming refs + outgoing deps | `context({name: "AuthService"})` |
272
+ | `get_file_symbols` | All symbols in a file with ref/dep counts | `get_file_symbols({file: "src/auth.ts"})` |
273
+ | `get_type_hierarchy` | Inheritance/implementation tree | `get_type_hierarchy({name: "BaseController"})` |
274
+
275
+ ### Impact & Safety
276
+
277
+ | Tool | What It Does | Example |
278
+ |---|---|---|
279
+ | `impact` | Blast radius: what breaks if this changes? | `impact({target: "createUser"})` |
280
+ | `edit_check` | Pre-edit safety: callers + exports + test coverage + ⚠ warnings | `edit_check({name: "resolveLinks"})` |
281
+ | `detect_changes` | Git diff affected symbols + direct dependents | `detect_changes({})` |
282
+ | `find_dead_code` | Exported symbols with zero references | `find_dead_code({})` |
283
+
284
+ ### Understanding
285
+
286
+ | Tool | What It Does | Example |
287
+ |---|---|---|
288
+ | `smart_context` | Intent-aware context: `understand`/`edit`/`debug`/`test` | `smart_context({name: "analyze", intent: "edit"})` |
289
+ | `trace` | Execution flow: call chains to/from entrypoints | `trace({to: "searchSymbols"})` |
290
+ | `routes` | Detect framework routes/endpoints | `routes({})` |
291
+ | `explain_relationship` | Shortest path between two symbols | `explain_relationship({from: "A", to: "B"})` |
292
+ | `overview` | Combined context + impact + grep in ONE call | `overview({name: "Database"})` |
293
+
294
+ ### Codebase Overview
295
+
296
+ | Tool | What It Does | Example |
297
+ |---|---|---|
298
+ | `domains` | Domain clusters groups of files forming logical modules | `domains({})` |
299
+ | `repos` | List all indexed repositories | `repos({})` |
300
+ | `status` | Index stats, domains, test coverage, accuracy report | `status({})` |
301
+
302
+ ### Developer Tools
303
+
304
+ | Tool | What It Does | Example |
305
+ |---|---|---|
306
+ | `ast_explore` | Parse code snippet → S-expression AST tree | `ast_explore({code: "const x = 1", language: "typescript"})` |
307
+ | `test_query` | Test tree-sitter query against code snippet | `test_query({query: "(identifier) @name", code: "const x = 1", language: "typescript"})` |
308
+
309
+ ### Resources & Prompts
310
+
311
+ **4 Resources:** `milens://overview`, `milens://symbol/{name}`, `milens://file/{path}`, `milens://domain/{name}`
312
+
313
+ **3 Guided Prompts:** `delete-feature`, `refactor-symbol`, `explore-symbol` each triggers a multi-step workflow using the tools above.
314
+
315
+ ---
316
+
317
+ ## Editor Setup
318
+
319
+ ### VS Code / GitHub Copilot
320
+
321
+ ```bash
322
+ npx milens analyze -p . # index your repo (run once)
323
+ ```
324
+
325
+ Add to `.vscode/mcp.json`:
326
+
327
+ ```json
328
+ {
329
+ "servers": {
330
+ "milens": {
331
+ "type": "stdio",
332
+ "command": "npx",
333
+ "args": ["-y", "milens", "serve", "-p", "${workspaceFolder}"]
334
+ }
335
+ }
336
+ }
337
+ ```
338
+
339
+ <details>
340
+ <summary><strong>Other Editors</strong></summary>
341
+
342
+ #### Cursor
343
+
344
+ Add to `.cursor/mcp.json`:
345
+
346
+ ```json
347
+ {
348
+ "mcpServers": {
349
+ "milens": {
350
+ "command": "npx",
351
+ "args": ["-y", "milens", "serve", "-p", "."]
352
+ }
353
+ }
354
+ }
355
+ ```
356
+
357
+ #### Claude Code
358
+
359
+ ```bash
360
+ claude mcp add milens -- npx -y milens serve -p .
361
+ ```
362
+
363
+ #### Windsurf
364
+
365
+ Add to `~/.codeium/windsurf/mcp_config.json`:
366
+
367
+ ```json
368
+ {
369
+ "mcpServers": {
370
+ "milens": {
371
+ "command": "npx",
372
+ "args": ["-y", "milens", "serve", "-p", "."]
373
+ }
374
+ }
375
+ }
376
+ ```
377
+
378
+ #### Codex
379
+
380
+ Add to `.codex/config.toml`:
381
+
382
+ ```toml
383
+ [mcp_servers.milens]
384
+ command = "npx"
385
+ args = ["-y", "milens", "serve", "-p", "."]
386
+ ```
387
+
388
+ </details>
389
+
390
+ ---
391
+
392
+ ## Supported Languages
393
+
394
+ | Language | Extensions | Imports | Calls | Heritage | Frameworks |
395
+ |---|---|---|---|---|---|
396
+ | TypeScript | `.ts` `.tsx` | ✓ ESM + require | ✓ + decorators | extends/implements | NestJS, React JSX |
397
+ | JavaScript | `.js` `.jsx` `.mjs` `.cjs` | ✓ ESM + require | | | React JSX, Express |
398
+ | Python | `.py` | ✓ | + decorators | | FastAPI, Flask |
399
+ | Java | `.java` | ✓ + static | ✓ + annotations, new | ✓ | Spring |
400
+ | Go | `.go` | ✓ | ✓ | — | net/http |
401
+ | Rust | `.rs` | ✓ | ✓ + macros | ✓ | — |
402
+ | PHP | `.php` | ✓ + include | ✓ + static, new | ✓ + traits | Laravel |
403
+ | Ruby | `.rb` | ✓ | ✓ | ✓ | Rails |
404
+ | Vue | `.vue` | ✓ | ✓ template refs | ✓ | Vue 3 SFC |
405
+ | HTML | `.html` `.htm` | ✓ `<script src>` `<link>` | inline `<script>` | | |
406
+ | CSS | `.css` | ✓ `@import` | — | — | Custom properties |
407
+ | Markdown | `.md` `.mdx` | ✓ local `[links]()` | — | — | Headings → section symbols, parent-child hierarchy |
408
+
409
+ ---
410
+
411
+ ## Architecture
412
+
413
+ <p align="center">
414
+ <img src="docs/diagram2.svg" alt="milens architecture: Indexing Pipeline MCP Server AI Agent" width="700">
415
+ </p>
416
+
417
+ ### How it works
418
+
419
+ 1. **Scan** — find all source files matching supported extensions
420
+ 2. **Parse** — tree-sitter extracts symbols (functions, classes, methods, etc.) and raw references (imports, calls, extends)
421
+ 3. **Resolve** — cross-file link resolution: match import paths to files, match call names to symbol definitions
422
+ 4. **Enrich** — compute roles (entrypoint/hub/utility/leaf), heat scores, domain clusters
423
+ 5. **Persist** — store everything in SQLite with FTS5 search and recursive CTEs for graph traversal
424
+
425
+ ### Multi-Repo
426
+
427
+ milens uses a global registry (`~/.milens/`) — one MCP server serves all indexed repos. Pass `repo` to target a specific one when multiple are registered.
428
+
429
+ <p align="center">
430
+ <img src="docs/diagram3.svg" alt="Multi-repo architecture" width="500">
431
+ </p>
432
+
433
+ ### Design Decisions
434
+
435
+ | Decision | Rationale |
436
+ |---|---|
437
+ | **Declarative LangSpec** | Each language = 1 config object with tree-sitter queries. One universal extractor for all 12 languages |
438
+ | **SQLite + recursive CTE** | Impact analysis runs entirely in the database no full graph in memory |
439
+ | **Token-compact output** | `name [kind] file:line` format — saves 40-60% tokens for AI |
440
+ | **Incremental by hash** | SHA-256 file hashing — only changed files get re-parsed |
441
+ | **Localhost-only HTTP** | Binds `127.0.0.1` — no network exposure without explicit intent |
442
+
443
+ ---
444
+
445
+ ## Security & Privacy
446
+
447
+ milens is **offline by design** zero network calls, zero telemetry.
448
+
449
+ | Layer | Protection |
450
+ |---|---|
451
+ | **Data locality** | Index lives in `.milens/` per repo (gitignored). No source code stored in registry |
452
+ | **HTTP transport** | Binds to `127.0.0.1` only — requires explicit `--http` flag |
453
+ | **User-supplied regex** | Validated against ReDoS patterns |
454
+ | **FTS5 queries** | Each token quoted as a literal — no query injection |
455
+ | **File access** | All reads bounded to the repo root — no path traversal |
456
+ | **Git integration** | `execFileSync` with argument arrays — no shell interpolation |
457
+
458
+ ---
459
+
460
+ ## Development
461
+
462
+ ```bash
463
+ npm install # install dependencies
464
+ npm run build # tsc → dist/
465
+ npm test # vitest (65 tests)
466
+ npm run lint # tsc --noEmit
467
+ npm run self-analyze # index this repo
468
+ npm run self-serve # start MCP server on port 3100
469
+ ```
470
+
471
+ ---
472
+
473
+ ## License
474
+
475
+ [PolyForm Noncommercial 1.0.0](LICENSE)
476
+
477
+ Architectural inspiration from [GitNexus](https://github.com/abhigyanpatwari/GitNexus) by Abhigyan Patwari.