milens 0.5.1 → 0.5.3

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,7 +1,315 @@
1
- <div align="center"><h1>milens</h1>Code Intelligence Engine for AI AgentsIndex any codebase → Knowledge graph → AI agents that never miss codeWhy? •Quick Start •Agent Tools •Editors •Languages •Architecture</div>🛑 The ProblemAI agents are blind to structure. They see files as text, not as a connected graph of dependencies.A real scenario:You ask your agent to refactor resolveLinks() in your codebase.The agent searches for "resolveLinks" — finds matches in code, tests, comments, and docs.It renames the function, but misses that resolveLinksWithStats wraps it and analyze() calls the wrapper — a chain invisible to text search.Your pipeline breaks. The agent didn't know the call graph.[!IMPORTANT]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."✨ How milens Solves This<p align="center"><img src="docs/diagram1.svg" alt="Without milens vs With milens comparison" width="700"></p>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.🚀 Quick Start2 commands. That's it.npx milens analyze # index your codebase
2
- npx milens analyze --skills # + generate AI skill files
3
- Then add the MCP server to your editor (setup below) and your agent immediately gets 19 tools, 4 resources, and 3 prompts — with built-in instructions that teach it how to use them.[!NOTE]No config files needed. milens sends tool usage guidance via the MCP protocol initialize response — every connected agent automatically learns the workflows.🛠️ What Your AI Agent Gets19 MCP ToolsToolWhat It Does🔍 Search & NavigatequerySymbol search (FTS5 full-text)grepText search ALL files — templates, SCSS, configs, docs. Scoped: all, code, imports, definitionscontext360° symbol view — incoming refs + outgoing depsget_file_symbolsAll symbols in a file with ref/dep countsget_type_hierarchyInheritance/implementation tree🛡️ Impact & SafetyimpactBlast radius: what breaks if this changes? Depth-groupededit_checkPre-edit safety: callers + exports + re-export chains + test coverage + ⚠ warningsdetect_changesgit diff → affected symbols + direct dependentsfind_dead_codeExported symbols with zero references🧠 Understandingsmart_contextIntent-aware context: understand / edit / debug / test — returns only what matterstraceExecution flow: call chains from entrypoints to a target (or downstream)routesDetect framework routes/endpoints (Express, FastAPI, NestJS, Flask, Go, PHP, Rails)explain_relationshipShortest dependency path between two symbols📊 Codebase OverviewoverviewCombined context + impact + grep in ONE call (saves 2-3 round trips)domainsDomain clusters — groups of files forming logical modulesreposList all indexed repositories with summary statsstatusIndex stats, domains, test coverage, staleness4 MCP ResourcesResourceWhat It Returns📈 milens://overviewIndex overview: stats, domains, coverage, staleness🧩 milens://symbol/{name}Symbol definition + relationships📄 milens://file/{path}All symbols in a file🗂️ milens://domain/{name}Domain cluster details3 Guided PromptsPromptWorkflow🗑️ delete-featuregrep → impact → context → full deletion plan🏗️ refactor-symbolcontext → impact → grep → hierarchy → every file to update🧭 explore-symbolquery → context → impact (both directions) → grep → summary💻 Editor SetupVS Code / GitHub Copilot (Recommended)First, run the indexer once:npx milens analyze -p .
4
- Then, add this to .vscode/mcp.json:{
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-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="#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 19 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, staleness | `status({})` |
292
+
293
+ ### Resources & Prompts
294
+
295
+ **4 Resources:** `milens://overview`, `milens://symbol/{name}`, `milens://file/{path}`, `milens://domain/{name}`
296
+
297
+ **3 Guided Prompts:** `delete-feature`, `refactor-symbol`, `explore-symbol` — each triggers a multi-step workflow using the tools above.
298
+
299
+ ---
300
+
301
+ ## Editor Setup
302
+
303
+ ### VS Code / GitHub Copilot
304
+
305
+ ```bash
306
+ npx milens analyze -p . # index your repo (run once)
307
+ ```
308
+
309
+ Add to `.vscode/mcp.json`:
310
+
311
+ ```json
312
+ {
5
313
  "servers": {
6
314
  "milens": {
7
315
  "type": "stdio",
@@ -10,7 +318,17 @@ Then, add this to .vscode/mcp.json:{
10
318
  }
11
319
  }
12
320
  }
13
- Done. Copilot now has access to 19 code intelligence tools.<details><summary><strong>👉 Show setup for other editors (Cursor, Claude Code, Windsurf, etc.)</strong></summary>CursorAdd to .cursor/mcp.json:{
321
+ ```
322
+
323
+ <details>
324
+ <summary><strong>Other Editors</strong></summary>
325
+
326
+ #### Cursor
327
+
328
+ Add to `.cursor/mcp.json`:
329
+
330
+ ```json
331
+ {
14
332
  "mcpServers": {
15
333
  "milens": {
16
334
  "command": "npx",
@@ -18,8 +336,20 @@ Done. Copilot now has access to 19 code intelligence tools.<details><summary><st
18
336
  }
19
337
  }
20
338
  }
21
- Claude Codeclaude mcp add milens -- npx -y milens serve -p .
22
- WindsurfAdd to ~/.codeium/windsurf/mcp_config.json:{
339
+ ```
340
+
341
+ #### Claude Code
342
+
343
+ ```bash
344
+ claude mcp add milens -- npx -y milens serve -p .
345
+ ```
346
+
347
+ #### Windsurf
348
+
349
+ Add to `~/.codeium/windsurf/mcp_config.json`:
350
+
351
+ ```json
352
+ {
23
353
  "mcpServers": {
24
354
  "milens": {
25
355
  "command": "npx",
@@ -27,88 +357,105 @@ WindsurfAdd to ~/.codeium/windsurf/mcp_config.json:{
27
357
  }
28
358
  }
29
359
  }
30
- CodexAdd to .codex/config.toml:[mcp_servers.milens]
360
+ ```
361
+
362
+ #### Codex
363
+
364
+ Add to `.codex/config.toml`:
365
+
366
+ ```toml
367
+ [mcp_servers.milens]
31
368
  command = "npx"
32
369
  args = ["-y", "milens", "serve", "-p", "."]
33
- HTTP Mode (Remote Agents)npx milens serve --http --port 3100 # localhost only, no auth needed
34
- Endpoint: POST http://localhost:3100/mcp</details>🧠 Skills GenerationGenerate editor-specific context files from your knowledge graph:npx milens analyze -p . --skills # all editors at once
35
- npx milens analyze -p . --skills-copilot # GitHub Copilot only
36
- npx milens analyze -p . --skills-cursor # Cursor only
37
- npx milens analyze -p . --skills-claude # Claude Code only
38
- npx milens analyze -p . --skills-agents # AGENTS.md only
39
- npx milens analyze -p . --skills-windsurf # Windsurf only
40
- 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.EditorOutput PathGitHub Copilot.github/instructions/*.instructions.md + .github/copilot-instructions.mdCursor.cursor/rules/*.mdc + .cursor/index.mdcClaude Code.claude/skills/generated/*/SKILL.md + .claude/rules/*.md + CLAUDE.mdGeneral Agents.agents/skills/*/SKILL.md + AGENTS.mdWindsurf.windsurfrules[!TIP]Root config files use <!-- milens:start/end --> markers for idempotent injection — re-running replaces the milens section without overwriting your custom content.⌨️ CLI Commands# ── Index & Explore ──
41
- npx milens analyze -p . # index current directory
42
- npx milens analyze -p . --force --verbose # full re-index with progress
43
- npx milens search "UserService" # search symbols (FTS5)
44
- npx milens inspect "AuthService" # 360° view: refs + deps
45
-
46
- # ── Impact Analysis ──
47
- npx milens impact "createUser" # what breaks if this changes?
48
- npx milens impact "UserModel" -d downstream # what does this depend on?
49
-
50
- # ── MCP Server ──
51
- npx milens serve -p . # stdio (for editors)
52
- npx milens serve --http --port 3100 # HTTP (for remote agents)
53
-
54
- # ── Management ──
55
- npx milens status -p . # index stats
56
- npx milens list # all indexed repos
57
- npx milens clean -p . # remove index
58
- npx milens clean --all # remove all indexes
59
-
60
- # ── Dashboard ──
61
- npx milens dashboard # usage analytics on port 3200
62
- npx milens dashboard --port 8080 # custom port
63
- 🌍 Supported LanguagesLanguageExtensionsImportsCallsHeritageFrameworksTypeScript.ts .tsx✓✓✓NestJS, React JSXJavaScript.js .jsx .mjs .cjs✓✓✓React JSX, ExpressPython.py✓✓✓FastAPI, FlaskJava.java✓✓✓SpringGo.go✓✓—net/httpRust.rs✓✓✓—PHP.php✓✓✓LaravelRuby.rb✓✓✓RailsVue.vue✓✓✓Vue 3 SFCHTML.html .htm✓✓——CSS.css✓——Custom properties🏗️ Architecture<p align="center"><img src="docs/diagram2.svg" alt="milens architecture: Indexing Pipeline → MCP Server → AI Agent" width="700"></p>Multi-Repo Architecturemilens uses a global registry — one MCP server serves all indexed repos. No per-project server config needed.<p align="center"><img src="docs/diagram3.svg" alt="Multi-repo architecture: CLI → Registry → Per-Repo DBs → MCP Server" width="500"></p>Security & Privacymilens is offline by design — zero network calls, zero telemetry. Everything executes on your machine.LayerProtectionData localityIndex lives in .milens/ per repo (gitignored). Global registry (~/.milens/) stores only file paths — no source code.HTTP transportBinds to 127.0.0.1 only — requires explicit --http flag, never auto-exposed.File accessAll reads bounded to the repo root — no path traversal.🔍 Tool ExamplesThese examples are from milens indexing itself (npx milens analyze -p .):# Pre-edit safety check — real output from milens self-index
64
- edit_check({name: "createMcpServer"})
65
- → createMcpServer [function] src/server/mcp.ts:272 {utility,heat:70} (exported)
66
- callers (2):
67
- calls: startStdio [function] src/server/mcp.ts:1475
68
- calls: startHttp [function] src/server/mcp.ts:1483
69
- deps (32): searchSymbols, findSymbolByName, getIncomingLinks, findUpstream,
70
- grepFiles, traceToEntrypoints, getDomainStats, getStaleFiles, ...
71
-
72
- # Context — 360° view with callers and callees
73
- context({name: "analyze"})
74
- analyze [function] src/analyzer/engine.ts:23 {utility,heat:55} (exported)
75
- incoming:
76
- calls: src/cli.ts (CLI entry point)
77
- outgoing (26 deps):
78
- calls: scanFiles [function] src/analyzer/scanner.ts:11
79
- calls: resolveLinksWithStats [function] src/analyzer/resolver.ts:27
80
- calls: enrichMetadata [function] src/analyzer/enrich.ts:21
81
- calls: loadLanguage [function] src/parser/loader.ts:20
82
- calls: transaction, insertSymbol, insertLink, rebuildSearch ... (db ops)
83
-
84
- # Impact analysis what breaks if searchSymbols changes?
85
- impact({target: "searchSymbols", direction: "upstream"})
86
- depth 1:
87
- createMcpServer [function] src/server/mcp.ts:272 (calls)
88
- depth 2:
89
- startStdio [function] src/server/mcp.ts:1475 (calls)
90
- startHttp [function] src/server/mcp.ts:1483 (calls)
91
- 🤝 Adding a LanguageCreate src/parser/lang-xxx.ts:import type { LangSpec } from './extract.js';
92
-
93
- const spec: LangSpec = {
94
- id: 'xxx',
95
- extensions: ['.xxx'],
96
- wasmName: 'tree-sitter-xxx',
97
- queries: {
98
- functions: `(function_definition name: (identifier) @name) @def`,
99
- classes: `(class_definition name: (identifier) @name) @def`,
100
- },
101
- resolveImport(raw, fromFile, root, aliases) {
102
- // return resolved file path or null
103
- },
104
- };
105
-
106
- export default spec;
107
- Then register it in src/parser/languages.ts.💻 Developmentnpm install # install dependencies
370
+ ```
371
+
372
+ </details>
373
+
374
+ ---
375
+
376
+ ## Supported Languages
377
+
378
+ | Language | Extensions | Imports | Calls | Heritage | Frameworks |
379
+ |---|---|---|---|---|---|
380
+ | TypeScript | `.ts` `.tsx` | ✓ ESM + require | ✓ + decorators | ✓ extends/implements | NestJS, React JSX |
381
+ | JavaScript | `.js` `.jsx` `.mjs` `.cjs` | ✓ ESM + require | ✓ | ✓ | React JSX, Express |
382
+ | Python | `.py` | ✓ | ✓ + decorators | ✓ | FastAPI, Flask |
383
+ | Java | `.java` | ✓ + static | ✓ + annotations, new | ✓ | Spring |
384
+ | Go | `.go` | | | — | net/http |
385
+ | Rust | `.rs` | | + macros | ✓ | — |
386
+ | PHP | `.php` | ✓ + include | ✓ + static, new | ✓ + traits | Laravel |
387
+ | Ruby | `.rb` | ✓ | ✓ | ✓ | Rails |
388
+ | Vue | `.vue` | | ✓ template refs | ✓ | Vue 3 SFC |
389
+ | HTML | `.html` `.htm` | `<script src>` `<link>` | ✓ inline `<script>` | — | — |
390
+ | CSS | `.css` | ✓ `@import` | — | — | Custom properties |
391
+ | Markdown | `.md` `.mdx` | ✓ local `[links]()` | — | — | Headings → section symbols, parent-child hierarchy |
392
+
393
+ ---
394
+
395
+ ## Architecture
396
+
397
+ <p align="center">
398
+ <img src="docs/diagram2.svg" alt="milens architecture: Indexing Pipeline MCP Server → AI Agent" width="700">
399
+ </p>
400
+
401
+ ### How it works
402
+
403
+ 1. **Scan** — find all source files matching supported extensions
404
+ 2. **Parse** tree-sitter extracts symbols (functions, classes, methods, etc.) and raw references (imports, calls, extends)
405
+ 3. **Resolve** — cross-file link resolution: match import paths to files, match call names to symbol definitions
406
+ 4. **Enrich** — compute roles (entrypoint/hub/utility/leaf), heat scores, domain clusters
407
+ 5. **Persist** store everything in SQLite with FTS5 search and recursive CTEs for graph traversal
408
+
409
+ ### Multi-Repo
410
+
411
+ milens uses a global registry (`~/.milens/`) — one MCP server serves all indexed repos. Pass `repo` to target a specific one when multiple are registered.
412
+
413
+ <p align="center">
414
+ <img src="docs/diagram3.svg" alt="Multi-repo architecture" width="500">
415
+ </p>
416
+
417
+ ### Design Decisions
418
+
419
+ | Decision | Rationale |
420
+ |---|---|
421
+ | **Declarative LangSpec** | Each language = 1 config object with tree-sitter queries. One universal extractor for all 12 languages |
422
+ | **SQLite + recursive CTE** | Impact analysis runs entirely in the database — no full graph in memory |
423
+ | **Token-compact output** | `name [kind] file:line` format — saves 40-60% tokens for AI |
424
+ | **Incremental by hash** | SHA-256 file hashing — only changed files get re-parsed |
425
+ | **Localhost-only HTTP** | Binds `127.0.0.1` — no network exposure without explicit intent |
426
+
427
+ ---
428
+
429
+ ## Security & Privacy
430
+
431
+ milens is **offline by design** — zero network calls, zero telemetry.
432
+
433
+ | Layer | Protection |
434
+ |---|---|
435
+ | **Data locality** | Index lives in `.milens/` per repo (gitignored). No source code stored in registry |
436
+ | **HTTP transport** | Binds to `127.0.0.1` only requires explicit `--http` flag |
437
+ | **User-supplied regex** | Validated against ReDoS patterns |
438
+ | **FTS5 queries** | Each token quoted as a literal — no query injection |
439
+ | **File access** | All reads bounded to the repo root — no path traversal |
440
+ | **Git integration** | `execFileSync` with argument arrays — no shell interpolation |
441
+
442
+ ---
443
+
444
+ ## Development
445
+
446
+ ```bash
447
+ npm install # install dependencies
108
448
  npm run build # tsc → dist/
109
- npm test # vitest (43 tests)
449
+ npm test # vitest (55 tests)
110
450
  npm run lint # tsc --noEmit
111
451
  npm run self-analyze # index this repo
112
452
  npm run self-serve # start MCP server on port 3100
113
- npx milens dashboard # open usage analytics dashboard
114
- 📜 LicensePolyForm Noncommercial 1.0.0Architectural inspiration from GitNexus by Abhigyan Patwari.
453
+ ```
454
+
455
+ ---
456
+
457
+ ## License
458
+
459
+ [PolyForm Noncommercial 1.0.0](LICENSE)
460
+
461
+ Architectural inspiration from [GitNexus](https://github.com/abhigyanpatwari/GitNexus) by Abhigyan Patwari.
@@ -1 +1 @@
1
- {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/analyzer/engine.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAA8E,aAAa,EAAE,MAAM,aAAa,CAAC;AAI7H,UAAU,aAAa;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,wBAAsB,OAAO,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CAmMzE"}
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/analyzer/engine.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAA8E,aAAa,EAAE,MAAM,aAAa,CAAC;AAI7H,UAAU,aAAa;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,wBAAsB,OAAO,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CA0OzE"}
@@ -6,6 +6,7 @@ import { getParser, loadLanguage } from '../parser/loader.js';
6
6
  import { extractFromTree, clearQueryCache } from '../parser/extract.js';
7
7
  import { extractVueScript, extractVueTemplateRefs } from '../parser/lang-vue.js';
8
8
  import { extractHtmlScripts, extractHtmlRefs } from '../parser/lang-html.js';
9
+ import { extractMarkdown } from '../parser/lang-md.js';
9
10
  import { resolveLinksWithStats } from './resolver.js';
10
11
  import { enrichMetadata } from './enrich.js';
11
12
  import { Database } from '../store/db.js';
@@ -30,6 +31,10 @@ export async function analyze(opts) {
30
31
  group.push({ ...file, spec });
31
32
  langGroups.set(spec.wasmName, group);
32
33
  }
34
+ // Phase 2.5: Separate document files (regex-based, no tree-sitter)
35
+ const docGroup = langGroups.get('');
36
+ if (docGroup)
37
+ langGroups.delete('');
33
38
  // Phase 3: Parse & extract — process each language group together
34
39
  // This keeps the same parser/language/compiled queries hot in cache
35
40
  const symbolsByFile = new Map();
@@ -41,6 +46,40 @@ export async function analyze(opts) {
41
46
  const resolvedImportPaths = new Map();
42
47
  const parsedFiles = new Set();
43
48
  let filesParsed = 0;
49
+ // Process document files (no tree-sitter needed)
50
+ if (docGroup) {
51
+ for (const file of docGroup) {
52
+ const source = readFileSync(file.absolutePath, 'utf-8');
53
+ if (!opts.force && db.isFileUpToDate(file.relativePath, source)) {
54
+ if (opts.verbose)
55
+ console.log(`[skip] ${file.relativePath} (unchanged)`);
56
+ continue;
57
+ }
58
+ try {
59
+ const result = parseDocFile(source, file.relativePath, file.spec);
60
+ if (!result)
61
+ continue;
62
+ symbolsByFile.set(file.relativePath, result.symbols);
63
+ allSymbols.push(...result.symbols);
64
+ allImports.push(...result.imports);
65
+ for (const imp of result.imports) {
66
+ const resolved = file.spec.resolveImport(imp.modulePath, imp.filePath, rootPath, aliases);
67
+ if (resolved) {
68
+ resolvedImportPaths.set(`${imp.filePath}::${imp.modulePath}`, resolved);
69
+ }
70
+ }
71
+ db.upsertFileHash(file.relativePath, source);
72
+ parsedFiles.add(file.relativePath);
73
+ filesParsed++;
74
+ if (opts.verbose)
75
+ console.log(`[parse] ${file.relativePath}: ${result.symbols.length} symbols`);
76
+ }
77
+ catch (err) {
78
+ if (opts.verbose)
79
+ console.error(`[error] ${file.relativePath}: ${err}`);
80
+ }
81
+ }
82
+ }
44
83
  for (const [wasmName, group] of langGroups) {
45
84
  // Pre-load parser + language once per group
46
85
  const parser = await getParser(wasmName);
@@ -302,6 +341,12 @@ async function parseFile(source, filePath, spec, parser, lang) {
302
341
  }
303
342
  return result;
304
343
  }
344
+ function parseDocFile(source, filePath, spec) {
345
+ if (spec.id === 'markdown') {
346
+ return extractMarkdown(source, filePath);
347
+ }
348
+ return null;
349
+ }
305
350
  /** Check if a file path looks like a test/spec file */
306
351
  function isTestFile(filePath) {
307
352
  return /\.(test|spec)\.[jt]sx?$/.test(filePath) ||