@liendev/lien 0.8.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/CURSOR_RULES_TEMPLATE.md +283 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3695 -0
- package/dist/index.js.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
---
|
|
2
|
+
alwaysApply: true
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Lien MCP Integration Rules
|
|
6
|
+
|
|
7
|
+
This project uses **Lien** - a local semantic code search MCP server. You MUST use Lien tools proactively to understand the codebase before making changes.
|
|
8
|
+
|
|
9
|
+
## Core Rules
|
|
10
|
+
|
|
11
|
+
### ALWAYS Use Lien When:
|
|
12
|
+
1. **Before reading any file** - Use `semantic_search` or `get_file_context` to understand what you're looking for
|
|
13
|
+
2. **User asks about code location** - Use `semantic_search` before grepping
|
|
14
|
+
3. **User asks "how does X work"** - Use `semantic_search` to find implementations
|
|
15
|
+
4. **Before making changes** - Use `get_file_context` to understand dependencies
|
|
16
|
+
5. **User asks for examples** - Use `find_similar` to locate patterns
|
|
17
|
+
6. **Exploring unfamiliar code** - Use `semantic_search` with broad queries first
|
|
18
|
+
|
|
19
|
+
### NEVER:
|
|
20
|
+
1. Skip Lien and go straight to reading files when you don't know the codebase
|
|
21
|
+
2. Use grep when the user is asking about functionality (use semantic search instead)
|
|
22
|
+
3. Make assumptions about code location without searching first
|
|
23
|
+
4. Edit files without getting context via `get_file_context`
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## MCP Tools Reference
|
|
28
|
+
|
|
29
|
+
### `semantic_search` - PRIMARY TOOL
|
|
30
|
+
**Use this FIRST for almost all code understanding tasks.**
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
semantic_search({
|
|
34
|
+
query: "natural language description of what you're looking for",
|
|
35
|
+
limit: 5 // increase to 10-15 for broad exploration
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**Use for:**
|
|
40
|
+
- "Where is X implemented?" → `semantic_search({ query: "X implementation" })`
|
|
41
|
+
- "How does Y work?" → `semantic_search({ query: "Y functionality" })`
|
|
42
|
+
- Finding patterns, features, utilities, handlers, validators, etc.
|
|
43
|
+
- Understanding architecture before making changes
|
|
44
|
+
|
|
45
|
+
**Query tips:**
|
|
46
|
+
- Use full sentences describing what the code does
|
|
47
|
+
- Focus on behavior: "handles user authentication", "validates email input"
|
|
48
|
+
- Not exact names: search semantically, not syntactically
|
|
49
|
+
|
|
50
|
+
### `get_file_context`
|
|
51
|
+
**Use BEFORE editing any file you haven't read yet.**
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
get_file_context({
|
|
55
|
+
filepath: "relative/path/to/file.ts",
|
|
56
|
+
includeRelated: true // default, gets related chunks
|
|
57
|
+
})
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**MANDATORY for:**
|
|
61
|
+
- Before making any file edits
|
|
62
|
+
- Understanding file dependencies and relationships
|
|
63
|
+
- Getting full context of what a file does
|
|
64
|
+
|
|
65
|
+
**Pro tip:** Use after `semantic_search` identifies the right file
|
|
66
|
+
|
|
67
|
+
### `find_similar`
|
|
68
|
+
**Use for finding patterns and ensuring consistency.**
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
find_similar({
|
|
72
|
+
code: "function example() { ... }",
|
|
73
|
+
limit: 5
|
|
74
|
+
})
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Use for:**
|
|
78
|
+
- Refactoring: find all similar implementations
|
|
79
|
+
- Consistency: ensure new code matches existing patterns
|
|
80
|
+
- Duplication detection
|
|
81
|
+
|
|
82
|
+
### `list_functions` ⚡ NEW in v0.5.0
|
|
83
|
+
**Fast symbol-based search for functions, classes, and interfaces by name.**
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
list_functions({
|
|
87
|
+
pattern: ".*Controller.*", // regex to match symbol names
|
|
88
|
+
language: "php" // optional language filter
|
|
89
|
+
})
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**How it works:**
|
|
93
|
+
- Extracts and indexes function/class/interface names during indexing
|
|
94
|
+
- Direct symbol name matching (not semantic search)
|
|
95
|
+
- **10x faster** than semantic search for finding specific symbols
|
|
96
|
+
- Automatic fallback for old indices
|
|
97
|
+
|
|
98
|
+
**Use for:**
|
|
99
|
+
- Finding all classes matching a pattern (e.g., `.*Controller.*`, `.*Service$`)
|
|
100
|
+
- Getting structural overview of functions/classes
|
|
101
|
+
- Discovering API endpoints, handlers, or utilities by name pattern
|
|
102
|
+
- Understanding code organization and naming conventions
|
|
103
|
+
|
|
104
|
+
**Best practices:**
|
|
105
|
+
- Use regex patterns that match naming conventions: `.*Controller.*`, `handle.*`, `get.*`
|
|
106
|
+
- Combine with language filter for large codebases: `language: "typescript"`
|
|
107
|
+
- For best results: run `lien reindex` after upgrading to v0.5.0
|
|
108
|
+
|
|
109
|
+
**When to use `list_functions` vs `semantic_search`:**
|
|
110
|
+
- ✅ Use `list_functions` when you know the naming pattern (e.g., "all Controllers")
|
|
111
|
+
- ✅ Use `semantic_search` when searching by functionality (e.g., "handles authentication")
|
|
112
|
+
|
|
113
|
+
**Note:** Test files are indexed alongside source code and will naturally appear in semantic search results when relevant.
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Workflow Patterns (FOLLOW THESE)
|
|
118
|
+
|
|
119
|
+
### Pattern 1: User Asks "Where is X?"
|
|
120
|
+
```
|
|
121
|
+
1. semantic_search({ query: "X functionality" })
|
|
122
|
+
2. Review results, identify file(s)
|
|
123
|
+
3. get_file_context({ filepath: "identified/file.ts" })
|
|
124
|
+
4. Answer with specific information
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Pattern 2: User Asks to Edit/Change Code
|
|
128
|
+
```
|
|
129
|
+
1. semantic_search({ query: "area being modified" })
|
|
130
|
+
2. get_file_context({ filepath: "target/file.ts" })
|
|
131
|
+
3. find_similar({ code: "existing pattern" }) // if ensuring consistency
|
|
132
|
+
4. Make changes with full context
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Pattern 3: User Asks "How Does X Work?"
|
|
136
|
+
```
|
|
137
|
+
1. semantic_search({ query: "X implementation", limit: 10 })
|
|
138
|
+
2. Review top results
|
|
139
|
+
3. get_file_context for key files
|
|
140
|
+
4. Explain with references to actual code locations
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Pattern 4: Debugging or Understanding Error
|
|
144
|
+
```
|
|
145
|
+
1. semantic_search({ query: "error handling for [area]" })
|
|
146
|
+
2. semantic_search({ query: "[specific error type] handling" })
|
|
147
|
+
3. get_file_context for relevant files
|
|
148
|
+
4. Provide analysis
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Pattern 5: Modifying Source Code (Test-Aware)
|
|
152
|
+
```
|
|
153
|
+
1. semantic_search({ query: "functionality being modified" })
|
|
154
|
+
2. get_file_context({ filepath: "target/file.ts" })
|
|
155
|
+
3. Check testAssociations in response to see which tests cover this code
|
|
156
|
+
4. Make changes
|
|
157
|
+
5. Remind user to run the associated tests
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Pattern 6: Understanding Test Coverage
|
|
161
|
+
```
|
|
162
|
+
1. get_file_context({ filepath: "src/component.ts" })
|
|
163
|
+
2. Review testAssociations field in response
|
|
164
|
+
3. Use get_file_context for each test file to understand coverage
|
|
165
|
+
4. Analyze and suggest improvements
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Pattern 7: Finding All Classes/Functions by Name Pattern ⚡ NEW
|
|
169
|
+
```
|
|
170
|
+
1. list_functions({ pattern: ".*Controller.*", language: "php" })
|
|
171
|
+
2. Review the list of matching classes
|
|
172
|
+
3. Use get_file_context on specific files for deeper investigation
|
|
173
|
+
4. Answer user's structural/architectural questions
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**Example queries:**
|
|
177
|
+
- "Show me all Controllers" → `list_functions({ pattern: ".*Controller.*" })`
|
|
178
|
+
- "What Services exist?" → `list_functions({ pattern: ".*Service.*" })`
|
|
179
|
+
- "Find all API handlers" → `list_functions({ pattern: "handle.*" })`
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## Decision Tree: Lien vs Other Tools
|
|
184
|
+
|
|
185
|
+
### Use `semantic_search` when:
|
|
186
|
+
✅ User asks about functionality, features, or "how X works"
|
|
187
|
+
✅ You need to understand what code exists before editing
|
|
188
|
+
✅ Looking for patterns, implementations, handlers, validators, etc.
|
|
189
|
+
✅ Exploring unfamiliar parts of codebase
|
|
190
|
+
✅ Searching by what code **does** (behavior, functionality)
|
|
191
|
+
|
|
192
|
+
### Use `list_functions` when: ⚡ NEW
|
|
193
|
+
✅ User asks "show me all Controllers" or similar structural queries
|
|
194
|
+
✅ Looking for classes/functions matching a **naming pattern**
|
|
195
|
+
✅ Getting architectural overview (all Services, all Handlers, etc.)
|
|
196
|
+
✅ Searching by what code is **named** (symbol names, not behavior)
|
|
197
|
+
✅ Need fast results for known naming conventions
|
|
198
|
+
|
|
199
|
+
### Use `grep` when:
|
|
200
|
+
✅ User provides exact function/variable name to find
|
|
201
|
+
✅ Looking for specific string literals or imports
|
|
202
|
+
✅ Finding all occurrences of exact text
|
|
203
|
+
|
|
204
|
+
### Use `get_file_context` when:
|
|
205
|
+
✅ You identified a file via search and need to understand it
|
|
206
|
+
✅ About to edit a file (MANDATORY)
|
|
207
|
+
✅ Need to understand file relationships and dependencies
|
|
208
|
+
|
|
209
|
+
### Use `find_similar` when:
|
|
210
|
+
✅ Refactoring multiple similar pieces of code
|
|
211
|
+
✅ Ensuring new code matches existing patterns
|
|
212
|
+
✅ Finding duplicated logic
|
|
213
|
+
|
|
214
|
+
### Check test associations when:
|
|
215
|
+
✅ Before modifying any source file (use `get_file_context` to see testAssociations)
|
|
216
|
+
✅ User asks "what tests cover this?" (use `semantic_search` and check metadata)
|
|
217
|
+
✅ Understanding what a test file is testing (use `get_file_context` on the test file)
|
|
218
|
+
✅ Working on bug fixes (search results include test metadata)
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## Query Construction Guide
|
|
223
|
+
|
|
224
|
+
### Good Semantic Queries (DO THIS):
|
|
225
|
+
- "handles user authentication"
|
|
226
|
+
- "validates email addresses"
|
|
227
|
+
- "processes payment transactions"
|
|
228
|
+
- "parses JSON responses"
|
|
229
|
+
- "middleware for authorization"
|
|
230
|
+
- "React components with form state"
|
|
231
|
+
- "database migration scripts"
|
|
232
|
+
- "API endpoints for user data"
|
|
233
|
+
|
|
234
|
+
### Bad Queries (DON'T DO THIS):
|
|
235
|
+
- "auth" (too vague)
|
|
236
|
+
- "validateEmail" (use grep for exact names)
|
|
237
|
+
- "line 234" (Lien doesn't work with line numbers)
|
|
238
|
+
- "code" (way too generic)
|
|
239
|
+
|
|
240
|
+
### Query Formula:
|
|
241
|
+
`[action verb] + [domain object] + [optional context]`
|
|
242
|
+
- "handles authentication for API requests"
|
|
243
|
+
- "validates user input in forms"
|
|
244
|
+
- "caches API responses from external services"
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## Performance Notes
|
|
249
|
+
|
|
250
|
+
- First query loads embeddings (~1-2s), subsequent queries are fast (<500ms)
|
|
251
|
+
- Increase `limit` to 10-15 for broad exploration
|
|
252
|
+
- Results are ranked by semantic relevance (trust the ranking)
|
|
253
|
+
- User can re-index with `lien reindex` if results seem stale
|
|
254
|
+
- **Relevance categories**: All search results include a `relevance` field (`highly_relevant`, `relevant`, `loosely_related`, `not_relevant`) to help interpret search quality at a glance
|
|
255
|
+
- **Test associations**: Lien automatically detects test-source relationships across 12 languages using convention-based patterns and import analysis
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## Key Principles
|
|
260
|
+
|
|
261
|
+
1. **Search First, Read Second**: Use Lien before reading files blindly
|
|
262
|
+
2. **Semantic Over Syntactic**: Think about what code *does*, not what it's *named*
|
|
263
|
+
3. **Context Before Changes**: Always get file context before editing
|
|
264
|
+
4. **Test-Aware Development**: Check testAssociations in results to understand test coverage
|
|
265
|
+
5. **Trust the Results**: Semantic search finds relevant code even with different naming. Use the `relevance` field (`highly_relevant`, `relevant`, `loosely_related`, `not_relevant`) to quickly assess result quality
|
|
266
|
+
6. **Chain Your Tools**: semantic_search → get_file_context (includes testAssociations) → make changes is a powerful pattern
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## Setup Instructions
|
|
271
|
+
|
|
272
|
+
Create a `lien.mdc` file in your `.cursor/rules/` directory:
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
# From your project directory
|
|
276
|
+
mkdir -p .cursor/rules
|
|
277
|
+
cp /path/to/lien/CURSOR_RULES_TEMPLATE.md .cursor/rules/lien.mdc
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
The `alwaysApply: true` frontmatter ensures Cursor uses Lien for all files in your project.
|
|
281
|
+
|
|
282
|
+
This approach allows you to have multiple rule files in `.cursor/rules/` without conflicts.
|
|
283
|
+
|
package/dist/index.d.ts
ADDED