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