milens 0.4.0 → 0.4.2

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 (59) hide show
  1. package/LICENSE +75 -75
  2. package/README.md +479 -453
  3. package/dist/analyzer/config.d.ts +8 -0
  4. package/dist/analyzer/config.d.ts.map +1 -0
  5. package/dist/analyzer/config.js +132 -0
  6. package/dist/analyzer/config.js.map +1 -0
  7. package/dist/analyzer/engine.d.ts.map +1 -1
  8. package/dist/analyzer/engine.js +77 -4
  9. package/dist/analyzer/engine.js.map +1 -1
  10. package/dist/analyzer/enrich.d.ts +18 -0
  11. package/dist/analyzer/enrich.d.ts.map +1 -0
  12. package/dist/analyzer/enrich.js +139 -0
  13. package/dist/analyzer/enrich.js.map +1 -0
  14. package/dist/analyzer/resolver.d.ts +10 -1
  15. package/dist/analyzer/resolver.d.ts.map +1 -1
  16. package/dist/analyzer/resolver.js +309 -18
  17. package/dist/analyzer/resolver.js.map +1 -1
  18. package/dist/cli.js +478 -32
  19. package/dist/cli.js.map +1 -1
  20. package/dist/parser/extract.d.ts +2 -0
  21. package/dist/parser/extract.d.ts.map +1 -1
  22. package/dist/parser/extract.js +27 -3
  23. package/dist/parser/extract.js.map +1 -1
  24. package/dist/parser/lang-go.js +22 -22
  25. package/dist/parser/lang-go.js.map +1 -1
  26. package/dist/parser/lang-java.d.ts.map +1 -1
  27. package/dist/parser/lang-java.js +29 -25
  28. package/dist/parser/lang-java.js.map +1 -1
  29. package/dist/parser/lang-js.d.ts.map +1 -1
  30. package/dist/parser/lang-js.js +60 -43
  31. package/dist/parser/lang-js.js.map +1 -1
  32. package/dist/parser/lang-php.d.ts.map +1 -1
  33. package/dist/parser/lang-php.js +39 -33
  34. package/dist/parser/lang-php.js.map +1 -1
  35. package/dist/parser/lang-py.js +31 -31
  36. package/dist/parser/lang-ruby.d.ts +4 -0
  37. package/dist/parser/lang-ruby.d.ts.map +1 -0
  38. package/dist/parser/lang-ruby.js +50 -0
  39. package/dist/parser/lang-ruby.js.map +1 -0
  40. package/dist/parser/lang-rust.js +24 -24
  41. package/dist/parser/lang-ts.d.ts.map +1 -1
  42. package/dist/parser/lang-ts.js +73 -57
  43. package/dist/parser/lang-ts.js.map +1 -1
  44. package/dist/parser/languages.d.ts.map +1 -1
  45. package/dist/parser/languages.js +2 -1
  46. package/dist/parser/languages.js.map +1 -1
  47. package/dist/server/mcp.d.ts.map +1 -1
  48. package/dist/server/mcp.js +883 -95
  49. package/dist/server/mcp.js.map +1 -1
  50. package/dist/skills.js +100 -88
  51. package/dist/skills.js.map +1 -1
  52. package/dist/store/db.d.ts +62 -0
  53. package/dist/store/db.d.ts.map +1 -1
  54. package/dist/store/db.js +244 -59
  55. package/dist/store/db.js.map +1 -1
  56. package/dist/store/schema.sql +83 -60
  57. package/dist/types.d.ts +14 -0
  58. package/dist/types.d.ts.map +1 -1
  59. package/package.json +60 -60
package/README.md CHANGED
@@ -1,453 +1,479 @@
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, Windsurf, and 40+ agents. Injects into root configs (`.github/copilot-instructions.md`, `.cursor/index.mdc`, `CLAUDE.md`, `.windsurfrules`, `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-windsurf`, `--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
- | `--skills-windsurf` | Generate config for Windsurf only |
114
-
115
- ### `search`
116
-
117
- ```bash
118
- npx milens search "createUser" --limit 10
119
- ```
120
-
121
- ### `inspect`
122
-
123
- ```bash
124
- npx milens inspect "AuthService"
125
- ```
126
-
127
- Shows incoming references (who calls/uses it) and outgoing dependencies (what it calls/imports/extends).
128
-
129
- ### `impact`
130
-
131
- ```bash
132
- npx milens impact "UserModel" --direction upstream --depth 3
133
- ```
134
-
135
- *"What breaks if this symbol changes?"* — traverses the dependency graph via recursive CTEs.
136
-
137
- | Flag | Description |
138
- |---|---|
139
- | `-d, --direction` | `upstream` (default) or `downstream` |
140
- | `--depth` | Max traversal depth (default: `3`) |
141
-
142
- ### `serve`
143
-
144
- ```bash
145
- npx milens serve -p /path/to/repo # stdio (for editors)
146
- npx milens serve -p /path/to/repo --http --port 3100 # HTTP
147
- ```
148
-
149
- ### `list`
150
-
151
- ```bash
152
- npx milens list # show all indexed repositories
153
- ```
154
-
155
- ### `clean`
156
-
157
- ```bash
158
- npx milens clean -p /path/to/repo # remove index for one repo
159
- npx milens clean --all # remove all indexes
160
- ```
161
-
162
- ## MCP Server
163
-
164
- milens exposes **11 tools** and **3 prompt templates** via the Model Context Protocol.
165
-
166
- 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.
167
-
168
- ### Tools
169
-
170
- | Tool | Description | Key params |
171
- |---|---|---|
172
- | `query` | Search indexed symbol definitions (FTS5) | `query`, `limit` |
173
- | `grep` | Text search across ALL project files (templates, SCSS, configs, docs) | `pattern`, `isRegex`, `include` |
174
- | `context` | 360° symbol view — incoming refs, outgoing deps | `name` |
175
- | `impact` | Blast radius with depth grouping (code deps only) | `target`, `direction`, `depth` |
176
- | `status` | Index stats for a repository | `repo` |
177
- | `detect_changes` | Git diff → affected symbols + dependents | `ref` |
178
- | `explain_relationship` | Shortest path between two symbols | `from`, `to` |
179
- | `find_dead_code` | Exported symbols with zero references | `kind`, `limit` |
180
- | `get_file_symbols` | All symbols in a specific file | `file` |
181
- | `get_type_hierarchy` | Inheritance/implementation tree | `name` |
182
-
183
- > **`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.
184
-
185
- > When only one repo is indexed, the `repo` parameter is optional on all tools.
186
-
187
- ### Prompts
188
-
189
- | Prompt | Description | Params |
190
- |---|---|---|
191
- | `delete-feature` | Guided workflow for safe feature deletion (grep + impact + context) | `name` |
192
- | `refactor-symbol` | Guided workflow for renaming/refactoring with full coverage | `name` |
193
- | `explore-symbol` | Deep exploration of unfamiliar code | `name` |
194
-
195
- ### Tool Examples
196
-
197
- ```
198
- # Search indexed symbols
199
- query({query: "auth"})
200
- AuthService [class] src/auth/service.ts:10
201
- validateUser [function] src/auth/validate.ts:15
202
-
203
- # Grep ALL files (templates, SCSS, configs, docs)
204
- grep({pattern: "AuthService"})
205
- → src/auth/service.ts L10: export class AuthService {
206
- src/components/Login.vue L5: <AuthForm @submit="handleAuth" />
207
- src/routes/index.ts L12: import { AuthService } from '../auth'
208
- docs/api.md L42: The `AuthService` handles JWT...
209
-
210
- # Context
211
- context({name: "validateUser"})
212
- → incoming:
213
- calls: handleLogin (src/api/auth.ts)
214
- outgoing:
215
- calls: checkPassword (src/auth/hash.ts)
216
-
217
- # Impact
218
- impact({target: "UserService", direction: "upstream"})
219
- → depth 1:
220
- handleLogin [function] src/api/auth.ts:45 (calls)
221
- UserController [class] src/controllers/user.ts:12 (calls)
222
- depth 2:
223
- authRouter [module] src/routes/auth.ts (imports)
224
-
225
- # Detect changes
226
- detect_changes({ref: "HEAD"})
227
- changed: src/auth/service.ts
228
- affected: handleLogin, UserController
229
-
230
- # Dead code
231
- find_dead_code({kind: "function"})
232
- legacyHash [function] src/utils/hash.ts:42 (0 refs)
233
- ```
234
-
235
- ## Editor Integration
236
-
237
- ### VS Code / GitHub Copilot
238
-
239
- Add to `.vscode/mcp.json`:
240
-
241
- ```json
242
- {
243
- "servers": {
244
- "milens": {
245
- "type": "stdio",
246
- "command": "npx",
247
- "args": ["-y", "milens", "serve", "-p", "${workspaceFolder}"]
248
- }
249
- }
250
- }
251
- ```
252
-
253
- ### Cursor
254
-
255
- Add to `.cursor/mcp.json` (per-project):
256
-
257
- ```json
258
- {
259
- "mcpServers": {
260
- "milens": {
261
- "command": "npx",
262
- "args": ["-y", "milens", "serve", "-p", "."]
263
- }
264
- }
265
- }
266
- ```
267
-
268
- ### Claude Code
269
-
270
- ```bash
271
- claude mcp add milens -- npx -y milens serve -p .
272
- ```
273
-
274
- ### Windsurf
275
-
276
- Add to `~/.codeium/windsurf/mcp_config.json`:
277
-
278
- ```json
279
- {
280
- "mcpServers": {
281
- "milens": {
282
- "command": "npx",
283
- "args": ["-y", "milens", "serve", "-p", "."]
284
- }
285
- }
286
- }
287
- ```
288
-
289
- ### Codex
290
-
291
- Add to `.codex/config.toml`:
292
-
293
- ```toml
294
- [mcp_servers.milens]
295
- command = "npx"
296
- args = ["-y", "milens", "serve", "-p", "."]
297
- ```
298
-
299
- ### HTTP Mode (remote agents)
300
-
301
- ```bash
302
- npx milens serve --http --port 3100
303
- ```
304
-
305
- Endpoint: `POST http://localhost:3100/mcp`
306
-
307
- ## Skills Generation
308
-
309
- Generate editor-specific context files from your codebase's knowledge graph:
310
-
311
- ```bash
312
- # Generate for all editors
313
- npx milens analyze -p . --skills
314
-
315
- # Generate for a specific editor only
316
- npx milens analyze -p . --skills-cursor
317
- npx milens analyze -p . --skills-copilot --skills-agents # combine multiple
318
- npx milens analyze -p . --skills-windsurf
319
- ```
320
-
321
- This creates:
322
-
323
- | Path | For |
324
- |---|---|
325
- | `.github/instructions/*.instructions.md` | GitHub Copilot |
326
- | `.github/copilot-instructions.md` | GitHub Copilot (root config, always loaded) |
327
- | `.cursor/rules/*.mdc` | Cursor (per-area, `globs:` scoped) |
328
- | `.cursor/index.mdc` | Cursor (root config, `alwaysApply: true`) |
329
- | `.claude/skills/generated/*/SKILL.md` | Claude Code (skills) |
330
- | `.claude/rules/*.md` | Claude Code (path-scoped rules, `paths:` frontmatter) |
331
- | `CLAUDE.md` | Claude Code (root config, always loaded) |
332
- | `.windsurfrules` | Windsurf (root config, always loaded) |
333
- | `.agents/skills/*/SKILL.md` | 40+ agents ([Agent Skills](https://agentskills.io)) |
334
- | `AGENTS.md` | Universal agents (root config, always loaded) |
335
-
336
- All root config files use `<!-- milens:start/end -->` markers for idempotent injection — re-running replaces the milens section without duplicating or overwriting other content.
337
-
338
- 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.
339
-
340
- ## Architecture
341
-
342
- ```
343
- src/
344
- cli.ts — CLI entry point (commander, 8 commands)
345
- types.ts — Shared types (CodeSymbol, SymbolLink, etc.)
346
- skills.ts — Skills/context file generator
347
- parser/
348
- loader.ts — Tree-sitter WASM loading + caching
349
- extract.ts — Universal extractor + LangSpec interface
350
- lang-ts.ts — TypeScript (+ .tsx)
351
- lang-js.ts — JavaScript (+ .jsx, .mjs, .cjs)
352
- lang-py.ts — Python
353
- lang-java.ts — Java
354
- lang-go.ts — Go
355
- lang-rust.ts — Rust
356
- lang-php.ts — PHP
357
- lang-vue.ts — Vue (extracts <script> + <template> refs)
358
- languages.ts — Language registry
359
- analyzer/
360
- scanner.ts — File discovery (.gitignore aware)
361
- resolver.ts — Import + call + heritage resolution
362
- engine.ts Pipeline orchestrator (6 phases)
363
- store/
364
- schema.sql SQLite schema (FTS5, triggers, indexes)
365
- db.ts — Database adapter (30+ methods, recursive CTEs)
366
- registry.ts — Multi-repo registry (~/.milens/)
367
- server/
368
- mcp.ts MCP server (11 tools, stdio + HTTP)
369
- ```
370
-
371
- ### How It Works
372
-
373
- ```
374
- Source Files [Scan] [Parse] [Resolve] [Store] [Serve]
375
- │ │ │ │ │
376
- .gitignore tree-sitter imports SQLite MCP
377
- filter WASM AST calls FTS5 stdio/HTTP
378
- heritage CTE
379
- ```
380
-
381
- 1. **Scan** Walk file tree respecting `.gitignore`, skip `node_modules`/`dist`/`build`/etc.
382
- 2. **Parse** Extract symbols (functions, classes, methods, interfaces, enums, structs, traits) via tree-sitter WASM grammars
383
- 3. **Resolve** Link imports symbols, calls definitions, inheritance chains. Confidence-scored.
384
- 4. **Store** — Write symbols + links to SQLite with FTS5 search index in a single transaction
385
- 5. **Serve** — Expose the knowledge graph via 11 MCP tools + 3 prompts, with built-in agent instructions
386
-
387
- ### Design Decisions
388
-
389
- - **Declarative `LangSpec`**: Each language is a config object with tree-sitter queries. One universal extractor processes all — no per-language extraction code.
390
- - **SQLite recursive CTE**: Impact analysis (upstream/downstream) runs entirely in the database. No need to load the full graph into memory.
391
- - **Token-compact output**: MCP responses use `name [kind] file:line` format. Saves 40-60% tokens for AI agents.
392
- - **Incremental by default**: File content is SHA-256 hashed; only changed files get re-parsed.
393
- - **Lazy DB pools**: MCP server opens database connections on demand and evicts them after 5 minutes of inactivity.
394
-
395
- ## Supported Languages
396
-
397
- | Language | Extensions | Symbols | Imports | Calls | Heritage |
398
- |---|---|---|---|---|---|
399
- | TypeScript | `.ts`, `.tsx` | functions, classes, methods, interfaces, enums | ✓ (ESM + require) | ✓ | ✓ |
400
- | JavaScript | `.js`, `.jsx`, `.mjs`, `.cjs` | functions, classes, methods | ✓ (ESM + require) | ✓ | ✓ |
401
- | Python | `.py` | functions, classes, methods (+ decorated) | ✓ | ✓ (+ decorators) | ✓ |
402
- | Java | `.java` | classes, records, interfaces, methods, enums | ✓ (+ static) | ✓ (+ annotations, new) | ✓ |
403
- | Go | `.go` | functions, methods, structs, interfaces, consts, vars | ✓ | ✓ | — |
404
- | Rust | `.rs` | functions, structs, enums, traits, methods, consts, mods | ✓ | ✓ (+ macros) | ✓ |
405
- | PHP | `.php` | functions, classes, interfaces, traits, methods, consts | ✓ (+ include) | ✓ | ✓ (+ traits) |
406
- | Vue | `.vue` | `<script>` symbols + `<template>` refs (components, events, directives, interpolations) | ✓ | ✓ | ✓ |
407
-
408
- ## Adding a Language
409
-
410
- Create `src/parser/lang-xxx.ts`:
411
-
412
- ```typescript
413
- import type { LangSpec } from './extract.js';
414
-
415
- const spec: LangSpec = {
416
- id: 'xxx',
417
- extensions: ['.xxx'],
418
- wasmName: 'tree-sitter-xxx',
419
- queries: {
420
- functions: `(function_definition name: (identifier) @name) @def`,
421
- classes: `(class_definition name: (identifier) @name) @def`,
422
- // add queries using tree-sitter playground
423
- },
424
- resolveImport(raw, fromFile, root, aliases) {
425
- // return resolved file path or null
426
- },
427
- };
428
-
429
- export default spec;
430
- ```
431
-
432
- Then register it in `src/parser/languages.ts`.
433
-
434
- ## Development
435
-
436
- ```bash
437
- npm install # install dependencies
438
- npm run build # tsc → dist/
439
- npm test # vitest
440
- npm run lint # tsc --noEmit
441
- npm run self-analyze # index this repo
442
- npm run self-serve # start MCP server on port 3100
443
- ```
444
-
445
- ## Requirements
446
-
447
- - Node.js >= 20.0.0
448
-
449
- ## License
450
-
451
- [PolyForm Noncommercial 1.0.0](LICENSE)
452
-
453
- 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-9-orange" alt="9 Languages">
11
+ <img src="https://img.shields.io/badge/MCP_tools-19-purple" alt="19 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="#what-your-ai-agent-gets">Agent Tools</a>
22
+ <a href="#editor-setup">Editors</a> •
23
+ <a href="#supported-languages">Languages</a> •
24
+ <a href="#architecture">Architecture</a>
25
+ </p>
26
+
27
+ ---
28
+
29
+ ## The Problem
30
+
31
+ AI agents are blind to structure. They see files as text, not as a connected graph of dependencies.
32
+
33
+ **A real scenario:**
34
+
35
+ 1. You ask your agent to refactor `resolveLinks()` in your codebase
36
+ 2. The agent searches for `"resolveLinks"`finds matches in code, tests, comments, and docs
37
+ 3. It renames the function, but misses that `resolveLinksWithStats` wraps it and `analyze()` calls the wrapper a chain invisible to text search
38
+ 4. **Your pipeline breaks. The agent didn't know the call graph.**
39
+
40
+ The root cause: text search can't distinguish a caller from a comment from a type annotation. It has no concept of "what actually depends on this at the code level."
41
+
42
+ ### How milens Solves This
43
+
44
+ ```mermaid
45
+ flowchart LR
46
+ subgraph WITHOUT["Without milens"]
47
+ direction TB
48
+ W1["Agent: rename resolveLinks"] --> W2["grep for text matches"]
49
+ W2 --> W3["Finds 8 results — code, tests, configs, docs"]
50
+ W3 --> W4["Misses: resolveLinksWithStats wraps it,\nanalyze() calls the wrapper"]
51
+ end
52
+
53
+ subgraph WITH["With milens"]
54
+ direction TB
55
+ M1["Agent: rename resolveLinks"] --> M2["edit_check resolveLinks"]
56
+ M2 --> M3["1 caller (resolveLinksWithStats),\nwhich has 1 upstream (analyze).\nTest file imports it directly."]
57
+ M3 --> M4["Complete chain — safe rename"]
58
+ end
59
+ ```
60
+
61
+ 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.
62
+
63
+ ---
64
+
65
+ ## Quick Start
66
+
67
+ **2 commands. That's it.**
68
+
69
+ ```bash
70
+ npx milens analyze # index your codebase
71
+ npx milens analyze --skills # + generate AI skill files
72
+ ```
73
+
74
+ Then add the MCP server to your editor ([setup below](#editor-setup)) and your agent immediately gets 19 tools + 4 resources + 3 prompts — with built-in instructions that teach it how to use them.
75
+
76
+ > **No config files needed.** milens sends tool usage guidance via the MCP protocol `initialize` response — every connected agent automatically learns the workflows.
77
+
78
+ ---
79
+
80
+ ## What Your AI Agent Gets
81
+
82
+ ### 19 MCP Tools
83
+
84
+ | Tool | What It Does |
85
+ |---|---|
86
+ | **Search & Navigate** | |
87
+ | `query` | Symbol search (FTS5 full-text) |
88
+ | `grep` | Text search ALL files templates, SCSS, configs, docs. Scoped: `all`, `code`, `imports`, `definitions` |
89
+ | `context` | 360° symbol view incoming refs + outgoing deps |
90
+ | `get_file_symbols` | All symbols in a file with ref/dep counts |
91
+ | `get_type_hierarchy` | Inheritance/implementation tree |
92
+ | **Impact & Safety** | |
93
+ | `impact` | Blast radius: what breaks if this changes? Depth-grouped |
94
+ | `edit_check` | Pre-edit safety: callers + exports + re-export chains + test coverage + ⚠ warnings |
95
+ | `detect_changes` | `git diff` → affected symbols + direct dependents |
96
+ | `find_dead_code` | Exported symbols with zero references |
97
+ | **Understanding** | |
98
+ | `smart_context` | Intent-aware context: `understand` / `edit` / `debug` / `test` — returns only what matters |
99
+ | `trace` | Execution flow: call chains from entrypoints to a target (or downstream) |
100
+ | `routes` | Detect framework routes/endpoints (Express, FastAPI, NestJS, Flask, Go, PHP, Rails) |
101
+ | `explain_relationship` | Shortest dependency path between two symbols |
102
+ | **Codebase Overview** | |
103
+ | `overview` | Combined context + impact + grep in ONE call (saves 2-3 round trips) |
104
+ | `domains` | Domain clusters groups of files forming logical modules |
105
+ | `repos` | List all indexed repositories with summary stats |
106
+ | `status` | Index stats, domains, test coverage, staleness |
107
+
108
+ ### 4 MCP Resources
109
+
110
+ | Resource | What It Returns |
111
+ |---|---|
112
+ | `milens://overview` | Index overview: stats, domains, coverage, staleness |
113
+ | `milens://symbol/{name}` | Symbol definition + relationships |
114
+ | `milens://file/{path}` | All symbols in a file |
115
+ | `milens://domain/{name}` | Domain cluster details |
116
+
117
+ ### 3 Guided Prompts
118
+
119
+ | Prompt | Workflow |
120
+ |---|---|
121
+ | `delete-feature` | grep → impact → context → full deletion plan |
122
+ | `refactor-symbol` | context → impact → grep → hierarchy → every file to update |
123
+ | `explore-symbol` | query → context → impact (both directions) → grep → summary |
124
+
125
+ ### Built-in Agent Instructions
126
+
127
+ The MCP server sends **tool usage guidance** on every `initialize` agents automatically learn:
128
+
129
+ - When to combine `impact` + `grep` (code deps + text references)
130
+ - Pre-edit workflow (`edit_check` or `smart_context intent=edit`)
131
+ - `query` for code identifiers vs `grep` for display text
132
+ - Impact depth meaning: 1 = WILL BREAK, 2 = LIKELY AFFECTED, 3 = MAY NEED TESTING
133
+ - ⚠ unresolved markers vs ✓ external (expected) classification
134
+
135
+ ---
136
+
137
+ ## Editor Setup
138
+
139
+ ### VS Code / GitHub Copilot (recommended)
140
+
141
+ ```bash
142
+ npx milens analyze -p . # index your repo (run once)
143
+ ```
144
+
145
+ Add to `.vscode/mcp.json`:
146
+
147
+ ```json
148
+ {
149
+ "servers": {
150
+ "milens": {
151
+ "type": "stdio",
152
+ "command": "npx",
153
+ "args": ["-y", "milens", "serve", "-p", "${workspaceFolder}"]
154
+ }
155
+ }
156
+ }
157
+ ```
158
+
159
+ **Done.** Copilot now has access to 19 code intelligence tools.
160
+
161
+ <details>
162
+ <summary><strong>Other Editors</strong></summary>
163
+
164
+ #### Cursor
165
+
166
+ Add to `.cursor/mcp.json`:
167
+
168
+ ```json
169
+ {
170
+ "mcpServers": {
171
+ "milens": {
172
+ "command": "npx",
173
+ "args": ["-y", "milens", "serve", "-p", "."]
174
+ }
175
+ }
176
+ }
177
+ ```
178
+
179
+ #### Claude Code
180
+
181
+ ```bash
182
+ claude mcp add milens -- npx -y milens serve -p .
183
+ ```
184
+
185
+ #### Windsurf
186
+
187
+ Add to `~/.codeium/windsurf/mcp_config.json`:
188
+
189
+ ```json
190
+ {
191
+ "mcpServers": {
192
+ "milens": {
193
+ "command": "npx",
194
+ "args": ["-y", "milens", "serve", "-p", "."]
195
+ }
196
+ }
197
+ }
198
+ ```
199
+
200
+ #### Codex
201
+
202
+ Add to `.codex/config.toml`:
203
+
204
+ ```toml
205
+ [mcp_servers.milens]
206
+ command = "npx"
207
+ args = ["-y", "milens", "serve", "-p", "."]
208
+ ```
209
+
210
+ #### HTTP Mode (remote agents)
211
+
212
+ ```bash
213
+ npx milens serve --http --port 3100 # localhost only, no auth needed
214
+ ```
215
+
216
+ Endpoint: `POST http://localhost:3100/mcp`
217
+
218
+ </details>
219
+
220
+ ---
221
+
222
+ ## Skills Generation
223
+
224
+ Generate editor-specific context files from your knowledge graph:
225
+
226
+ ```bash
227
+ npx milens analyze -p . --skills # all editors at once
228
+ npx milens analyze -p . --skills-copilot # GitHub Copilot only
229
+ npx milens analyze -p . --skills-cursor # Cursor only
230
+ npx milens analyze -p . --skills-claude # Claude Code only
231
+ npx milens analyze -p . --skills-agents # AGENTS.md only
232
+ npx milens analyze -p . --skills-windsurf # Windsurf only
233
+ ```
234
+
235
+ This generates per-area skill files with: key symbols, entry points, cross-area dependencies, and **MCP tool usage instructions** — so agents know both the codebase structure and how to use milens tools.
236
+
237
+ | Output Path | Editor |
238
+ |---|---|
239
+ | `.github/instructions/*.instructions.md` + `.github/copilot-instructions.md` | GitHub Copilot |
240
+ | `.cursor/rules/*.mdc` + `.cursor/index.mdc` | Cursor |
241
+ | `.claude/skills/generated/*/SKILL.md` + `.claude/rules/*.md` + `CLAUDE.md` | Claude Code |
242
+ | `.agents/skills/*/SKILL.md` + `AGENTS.md` | 40+ agents |
243
+ | `.windsurfrules` | Windsurf |
244
+
245
+ > Root config files use `<!-- milens:start/end -->` markers for **idempotent injection** — re-running replaces the milens section without overwriting your custom content.
246
+
247
+ ---
248
+
249
+ ## CLI Commands
250
+
251
+ ```bash
252
+ # ── Index & Explore ──
253
+ npx milens analyze -p . # index current directory
254
+ npx milens analyze -p . --force --verbose # full re-index with progress
255
+ npx milens search "UserService" # search symbols (FTS5)
256
+ npx milens inspect "AuthService" # 360° view: refs + deps
257
+
258
+ # ── Impact Analysis ──
259
+ npx milens impact "createUser" # what breaks if this changes?
260
+ npx milens impact "UserModel" -d downstream # what does this depend on?
261
+
262
+ # ── MCP Server ──
263
+ npx milens serve -p . # stdio (for editors)
264
+ npx milens serve --http --port 3100 # HTTP (for remote agents)
265
+
266
+ # ── Management ──
267
+ npx milens status -p . # index stats
268
+ npx milens list # all indexed repos
269
+ npx milens clean -p . # remove index
270
+ npx milens clean --all # remove all indexes
271
+
272
+ # ── Dashboard ──
273
+ npx milens dashboard # usage analytics on port 3200
274
+ npx milens dashboard --port 8080 # custom port
275
+ ```
276
+
277
+ ---
278
+
279
+ ## Supported Languages
280
+
281
+ | Language | Extensions | Imports | Calls | Heritage | Frameworks |
282
+ |---|---|---|---|---|---|
283
+ | TypeScript | `.ts` `.tsx` | ✓ ESM + require | ✓ + decorators | ✓ extends/implements | NestJS, React JSX |
284
+ | JavaScript | `.js` `.jsx` `.mjs` `.cjs` | ✓ ESM + require | ✓ | ✓ | React JSX, Express |
285
+ | Python | `.py` | ✓ | ✓ + decorators | ✓ | FastAPI, Flask |
286
+ | Java | `.java` | ✓ + static | ✓ + annotations, new | ✓ | Spring |
287
+ | Go | `.go` | ✓ | ✓ | — | net/http |
288
+ | Rust | `.rs` | ✓ | ✓ + macros | ✓ | — |
289
+ | PHP | `.php` | ✓ + include | ✓ + static, new | ✓ + traits | Laravel |
290
+ | Ruby | `.rb` | ✓ | ✓ | ✓ | Rails |
291
+ | Vue | `.vue` | ✓ | ✓ template refs | ✓ | Vue 3 SFC |
292
+
293
+ ---
294
+
295
+ ## Architecture
296
+
297
+ ```mermaid
298
+ flowchart LR
299
+ subgraph Pipeline["Indexing Pipeline"]
300
+ Scan["📁 Scan\n.gitignore aware"]
301
+ Parse["🌳 Parse\ntree-sitter WASM"]
302
+ Resolve["🔗 Resolve\nimports · calls · heritage"]
303
+ Enrich["⚡ Enrich\nroles · heat · domains"]
304
+ Store["💾 Store\nSQLite + FTS5"]
305
+ end
306
+
307
+ subgraph Serve["MCP Server"]
308
+ Tools["19 Tools"]
309
+ Resources["4 Resources"]
310
+ Prompts["3 Prompts"]
311
+ end
312
+
313
+ Scan --> Parse --> Resolve --> Enrich --> Store
314
+ Store --> Tools
315
+ Store --> Resources
316
+ Store --> Prompts
317
+
318
+ Agent["🤖 AI Agent\nCopilot · Cursor\nClaude · Codex"]
319
+ Tools --> Agent
320
+ Resources --> Agent
321
+ Prompts --> Agent
322
+ ```
323
+
324
+ ### Multi-Repo Architecture
325
+
326
+ milens uses a **global registry** one MCP server serves all indexed repos. No per-project server config needed.
327
+
328
+ ```mermaid
329
+ flowchart TD
330
+ subgraph Commands["CLI"]
331
+ Idx["milens analyze -p /repo/A"]
332
+ Srv["milens serve"]
333
+ end
334
+
335
+ subgraph Global["~/.milens/"]
336
+ Reg["registry.json\n(repo paths + DB locations)"]
337
+ end
338
+
339
+ subgraph Projects["Per-Repo Indexes"]
340
+ DbA["repo-A/.milens/milens.db"]
341
+ DbB["repo-B/.milens/milens.db"]
342
+ end
343
+
344
+ subgraph Server["MCP Server"]
345
+ ConnPool["On-demand DB pool\nidle timeout: 5 min"]
346
+ end
347
+
348
+ Idx -- "adds entry" --> Reg
349
+ Idx -- "writes SQLite" --> DbA
350
+ Srv -- "loads list" --> Reg
351
+ ConnPool -- "opens on first query" --> DbA
352
+ ConnPool -- "opens on first query" --> DbB
353
+ ```
354
+
355
+ > With a single indexed repo, all tools work without specifying `repo`. When multiple repos are registered, pass `repo` to target a specific one.
356
+
357
+ ### Design Decisions
358
+
359
+ | Decision | Rationale |
360
+ |---|---|
361
+ | **Declarative LangSpec** | Each language = 1 config object with tree-sitter queries. One universal extractor for all 9 languages |
362
+ | **SQLite + recursive CTE** | Impact analysis runs entirely in the database no full graph in memory |
363
+ | **Token-compact output** | `name [kind] file:line` format — saves 40-60% tokens for AI |
364
+ | **Incremental by hash** | SHA-256 file hashing only changed files get re-parsed |
365
+ | **Union-Find domains** | Graph-based clustering (files with ≥2 mutual links = same domain) — smarter than directory-based |
366
+ | **External-aware resolution** | Separates internal unresolved (⚠ data quality) from external packages (✓ expected) |
367
+ | **Lazy DB pools** | Connections opened on demand, evicted after 5min idle |
368
+ | **Localhost-only HTTP** | Binds `127.0.0.1` no network exposure without explicit intent |
369
+
370
+ ---
371
+
372
+ ## Security & Privacy
373
+
374
+ milens is **offline by design** zero network calls, zero telemetry. Everything executes on your machine.
375
+
376
+ | Layer | Protection |
377
+ |---|---|
378
+ | **Data locality** | Index lives in `.milens/` per repo (gitignored). Global registry (`~/.milens/`) stores only file paths — no source code |
379
+ | **HTTP transport** | Binds to `127.0.0.1` only — requires explicit `--http` flag, never auto-exposed |
380
+ | **User-supplied regex** | Validated against ReDoS patterns before execution |
381
+ | **FTS5 queries** | Each search token quoted as a literal — no query injection |
382
+ | **File access** | All reads bounded to the repo root no path traversal |
383
+ | **Git integration** | Uses `execFileSync` with argument arrays no shell interpolation |
384
+
385
+ ---
386
+
387
+ ## Tool Examples
388
+
389
+ These examples are from **milens indexing itself** (`npx milens analyze -p .`):
390
+
391
+ ```
392
+ # Pre-edit safety check real output from milens self-index
393
+ edit_check({name: "createMcpServer"})
394
+ → createMcpServer [function] src/server/mcp.ts:272 {utility,heat:70} (exported)
395
+ callers (2):
396
+ calls: startStdio [function] src/server/mcp.ts:1475
397
+ calls: startHttp [function] src/server/mcp.ts:1483
398
+ deps (32): searchSymbols, findSymbolByName, getIncomingLinks, findUpstream,
399
+ grepFiles, traceToEntrypoints, getDomainStats, getStaleFiles, ...
400
+
401
+ # Context 360° view with callers and callees
402
+ context({name: "analyze"})
403
+ analyze [function] src/analyzer/engine.ts:23 {utility,heat:55} (exported)
404
+ incoming:
405
+ calls: src/cli.ts (CLI entry point)
406
+ outgoing (26 deps):
407
+ calls: scanFiles [function] src/analyzer/scanner.ts:11
408
+ calls: resolveLinksWithStats [function] src/analyzer/resolver.ts:27
409
+ calls: enrichMetadata [function] src/analyzer/enrich.ts:21
410
+ calls: loadLanguage [function] src/parser/loader.ts:20
411
+ calls: transaction, insertSymbol, insertLink, rebuildSearch ... (db ops)
412
+
413
+ # Impact analysis what breaks if searchSymbols changes?
414
+ impact({target: "searchSymbols", direction: "upstream"})
415
+ depth 1:
416
+ createMcpServer [function] src/server/mcp.ts:272 (calls)
417
+ depth 2:
418
+ startStdio [function] src/server/mcp.ts:1475 (calls)
419
+ startHttp [function] src/server/mcp.ts:1483 (calls)
420
+
421
+ # File symbols what's inside a file?
422
+ get_file_symbols({file: "src/store/db.ts"})
423
+ → src/store/db.ts: 45 symbols
424
+ Database [class] L10-461 (exported) 0 refs, 0 deps
425
+ searchSymbols [method] L150-165 3 refs, → 0 deps
426
+ findUpstream [method] L192-195 ← 3 refs, → 1 deps
427
+ traceToEntrypoints [method] L346-388 ← 2 refs, → 2 deps
428
+ getDomainStats [method] L406-417 ← 3 refs, → 0 deps
429
+ ... (40 more)
430
+ ```
431
+
432
+ ---
433
+
434
+ ## Adding a Language
435
+
436
+ Create `src/parser/lang-xxx.ts`:
437
+
438
+ ```typescript
439
+ import type { LangSpec } from './extract.js';
440
+
441
+ const spec: LangSpec = {
442
+ id: 'xxx',
443
+ extensions: ['.xxx'],
444
+ wasmName: 'tree-sitter-xxx',
445
+ queries: {
446
+ functions: `(function_definition name: (identifier) @name) @def`,
447
+ classes: `(class_definition name: (identifier) @name) @def`,
448
+ },
449
+ resolveImport(raw, fromFile, root, aliases) {
450
+ // return resolved file path or null
451
+ },
452
+ };
453
+
454
+ export default spec;
455
+ ```
456
+
457
+ Then register it in `src/parser/languages.ts`.
458
+
459
+ ---
460
+
461
+ ## Development
462
+
463
+ ```bash
464
+ npm install # install dependencies
465
+ npm run build # tsc → dist/
466
+ npm test # vitest (32 tests)
467
+ npm run lint # tsc --noEmit
468
+ npm run self-analyze # index this repo
469
+ npm run self-serve # start MCP server on port 3100
470
+ npx milens dashboard # open usage analytics dashboard
471
+ ```
472
+
473
+ ---
474
+
475
+ ## License
476
+
477
+ [PolyForm Noncommercial 1.0.0](LICENSE)
478
+
479
+ Architectural inspiration from [GitNexus](https://github.com/abhigyanpatwari/GitNexus) by Abhigyan Patwari.