@liendev/lien 0.11.0 → 0.13.0

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.
@@ -114,6 +114,182 @@ list_functions({
114
114
 
115
115
  ---
116
116
 
117
+ ## Enhanced Metadata (AST-Based) ⚡ NEW in v0.13.0
118
+
119
+ Lien now uses **Abstract Syntax Tree (AST) parsing** for TypeScript/JavaScript files to provide rich code metadata:
120
+
121
+ ### Metadata Fields in Search Results
122
+
123
+ All search results (`semantic_search`, `get_file_context`, `find_similar`, `list_functions`) now include enhanced metadata when available:
124
+
125
+ ```typescript
126
+ {
127
+ content: "function validateEmail(email: string): boolean { ... }",
128
+ metadata: {
129
+ file: "src/validators.ts",
130
+ startLine: 45,
131
+ endLine: 60,
132
+ type: "function", // 'function' | 'class' | 'block'
133
+ language: "typescript",
134
+
135
+ // AST-derived metadata (NEW in v0.13.0):
136
+ symbolName: "validateEmail", // Function/class name
137
+ symbolType: "function", // 'function' | 'method' | 'class' | 'interface'
138
+ parentClass: undefined, // For methods: parent class name
139
+ complexity: 3, // Cyclomatic complexity
140
+ parameters: ["email: string"], // Function parameters
141
+ signature: "function validateEmail(email: string): boolean", // Full signature
142
+ imports: ["@/utils/regex"] // File imports (for context)
143
+ },
144
+ score: 0.85,
145
+ relevance: "highly_relevant"
146
+ }
147
+ ```
148
+
149
+ ### AST Metadata Benefits
150
+
151
+ 1. **Never splits functions** - Chunks respect semantic boundaries (no mid-function splits)
152
+ 2. **Function context** - Know exactly which function you're looking at
153
+ 3. **Complexity metrics** - Identify complex functions that may need refactoring
154
+ 4. **Signature awareness** - See parameters and return types at a glance
155
+ 5. **Better AI context** - AI assistants get structured code information
156
+
157
+ ### Using AST Metadata
158
+
159
+ **Find complex functions:**
160
+ ```typescript
161
+ // Search for authentication logic
162
+ const results = await semantic_search({ query: "authentication logic" });
163
+
164
+ // Filter by complexity
165
+ const complexFunctions = results.filter(r => (r.metadata.complexity || 0) > 5);
166
+ ```
167
+
168
+ **Identify methods in a class:**
169
+ ```typescript
170
+ // Get file context
171
+ const context = await get_file_context({ filepath: "src/auth/AuthService.ts" });
172
+
173
+ // Find all methods
174
+ const methods = context.results.filter(r => r.metadata.symbolType === 'method');
175
+ ```
176
+
177
+ **List functions with specific parameters:**
178
+ ```typescript
179
+ const functions = await list_functions({ pattern: ".*validate.*", language: "typescript" });
180
+
181
+ // Filter by parameter count
182
+ const simpleValidators = functions.filter(r => (r.metadata.parameters?.length || 0) <= 2);
183
+ ```
184
+
185
+ ### AST Support
186
+
187
+ **Currently supported:**
188
+ - ✅ TypeScript (`.ts`, `.tsx`)
189
+ - ✅ JavaScript (`.js`, `.jsx`, `.mjs`, `.cjs`)
190
+
191
+ **Coming soon:**
192
+ - 🔜 Python, Go, Rust, Java, PHP, and more
193
+
194
+ **Fallback behavior:**
195
+ - For unsupported languages, Lien automatically falls back to line-based chunking
196
+ - No disruption to existing workflows
197
+
198
+ ### Known Limitations
199
+
200
+ **Very large files (1000+ lines):**
201
+ - Tree-sitter may fail with "Invalid argument" error on extremely large files
202
+ - When this occurs, Lien automatically falls back to line-based chunking
203
+ - This is a known Tree-sitter limitation with very large syntax trees
204
+ - Fallback behavior is configurable via `astFallback` setting
205
+
206
+ **Resilient parsing:**
207
+ - Tree-sitter is designed to produce best-effort ASTs even for invalid syntax
208
+ - Parse errors are rare; most malformed code still produces usable chunks
209
+ - The `astFallback: 'error'` option mainly catches edge cases like large file errors
210
+
211
+ ### Configuration
212
+
213
+ Control AST behavior in `.lien.config.json`:
214
+
215
+ ```json
216
+ {
217
+ "chunking": {
218
+ "useAST": true, // Enable AST-based chunking (default: true)
219
+ "astFallback": "line-based" // Fallback strategy: 'line-based' | 'error'
220
+ }
221
+ }
222
+ ```
223
+
224
+ ---
225
+
226
+ ## Input Validation & Error Handling
227
+
228
+ Lien uses Zod schemas for runtime type-safe validation of all tool inputs. This provides:
229
+ - **Automatic validation** of all parameters before tool execution
230
+ - **Rich error messages** with field-level feedback
231
+ - **Type safety** with full TypeScript inference
232
+ - **Consistent error structure** across all tools
233
+
234
+ ### Understanding Validation Errors
235
+
236
+ When you provide invalid parameters, you'll receive a structured error response:
237
+
238
+ ```json
239
+ {
240
+ "error": "Invalid parameters",
241
+ "code": "INVALID_INPUT",
242
+ "details": [
243
+ {
244
+ "field": "query",
245
+ "message": "Query must be at least 3 characters"
246
+ },
247
+ {
248
+ "field": "limit",
249
+ "message": "Limit cannot exceed 50"
250
+ }
251
+ ]
252
+ }
253
+ ```
254
+
255
+ ### Common Validation Rules
256
+
257
+ **semantic_search:**
258
+ - `query`: 3-500 characters (required)
259
+ - `limit`: 1-50 (default: 5)
260
+
261
+ **find_similar:**
262
+ - `code`: minimum 10 characters (required)
263
+ - `limit`: 1-20 (default: 5)
264
+
265
+ **get_file_context:**
266
+ - `filepath`: cannot be empty (required)
267
+ - `includeRelated`: boolean (default: true)
268
+
269
+ **list_functions:**
270
+ - `pattern`: optional regex string
271
+ - `language`: optional language filter
272
+
273
+ ### Error Codes
274
+
275
+ Lien uses structured error codes for programmatic error handling:
276
+
277
+ - `INVALID_INPUT` - Parameter validation failed
278
+ - `FILE_NOT_FOUND` - Requested file doesn't exist in index
279
+ - `INDEX_NOT_FOUND` - No index found (run `lien index`)
280
+ - `INDEX_CORRUPTED` - Index is corrupted (run `lien reindex`)
281
+ - `EMBEDDING_GENERATION_FAILED` - Embedding model failed (retryable)
282
+ - `INTERNAL_ERROR` - Unexpected internal error
283
+
284
+ ### Best Practices
285
+
286
+ 1. **Always provide required fields**: Check tool schemas for required parameters
287
+ 2. **Respect validation limits**: Don't exceed max values for `limit` parameters
288
+ 3. **Use descriptive queries**: Avoid very short or vague queries
289
+ 4. **Handle validation errors gracefully**: Parse error details to understand what went wrong
290
+
291
+ ---
292
+
117
293
  ## Workflow Patterns (FOLLOW THESE)
118
294
 
119
295
  ### Pattern 1: User Asks "Where is X?"