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