@liendev/lien 0.12.0 → 0.14.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.
@@ -79,7 +79,7 @@ find_similar({
79
79
  - Consistency: ensure new code matches existing patterns
80
80
  - Duplication detection
81
81
 
82
- ### `list_functions` ⚡ NEW in v0.5.0
82
+ ### `list_functions` ⚡
83
83
  **Fast symbol-based search for functions, classes, and interfaces by name.**
84
84
 
85
85
  ```typescript
@@ -104,7 +104,6 @@ list_functions({
104
104
  **Best practices:**
105
105
  - Use regex patterns that match naming conventions: `.*Controller.*`, `handle.*`, `get.*`
106
106
  - Combine with language filter for large codebases: `language: "typescript"`
107
- - For best results: run `lien reindex` after upgrading to v0.5.0
108
107
 
109
108
  **When to use `list_functions` vs `semantic_search`:**
110
109
  - ✅ Use `list_functions` when you know the naming pattern (e.g., "all Controllers")
@@ -114,6 +113,182 @@ list_functions({
114
113
 
115
114
  ---
116
115
 
116
+ ## Enhanced Metadata (AST-Based) ⚡ NEW in v0.13.0
117
+
118
+ Lien now uses **Abstract Syntax Tree (AST) parsing** for TypeScript/JavaScript files to provide rich code metadata:
119
+
120
+ ### Metadata Fields in Search Results
121
+
122
+ All search results (`semantic_search`, `get_file_context`, `find_similar`, `list_functions`) now include enhanced metadata when available:
123
+
124
+ ```typescript
125
+ {
126
+ content: "function validateEmail(email: string): boolean { ... }",
127
+ metadata: {
128
+ file: "src/validators.ts",
129
+ startLine: 45,
130
+ endLine: 60,
131
+ type: "function", // 'function' | 'class' | 'block'
132
+ language: "typescript",
133
+
134
+ // AST-derived metadata (NEW in v0.13.0):
135
+ symbolName: "validateEmail", // Function/class name
136
+ symbolType: "function", // 'function' | 'method' | 'class' | 'interface'
137
+ parentClass: undefined, // For methods: parent class name
138
+ complexity: 3, // Cyclomatic complexity
139
+ parameters: ["email: string"], // Function parameters
140
+ signature: "function validateEmail(email: string): boolean", // Full signature
141
+ imports: ["@/utils/regex"] // File imports (for context)
142
+ },
143
+ score: 0.85,
144
+ relevance: "highly_relevant"
145
+ }
146
+ ```
147
+
148
+ ### AST Metadata Benefits
149
+
150
+ 1. **Never splits functions** - Chunks respect semantic boundaries (no mid-function splits)
151
+ 2. **Function context** - Know exactly which function you're looking at
152
+ 3. **Complexity metrics** - Identify complex functions that may need refactoring
153
+ 4. **Signature awareness** - See parameters and return types at a glance
154
+ 5. **Better AI context** - AI assistants get structured code information
155
+
156
+ ### Using AST Metadata
157
+
158
+ **Find complex functions:**
159
+ ```typescript
160
+ // Search for authentication logic
161
+ const results = await semantic_search({ query: "authentication logic" });
162
+
163
+ // Filter by complexity
164
+ const complexFunctions = results.filter(r => (r.metadata.complexity || 0) > 5);
165
+ ```
166
+
167
+ **Identify methods in a class:**
168
+ ```typescript
169
+ // Get file context
170
+ const context = await get_file_context({ filepath: "src/auth/AuthService.ts" });
171
+
172
+ // Find all methods
173
+ const methods = context.results.filter(r => r.metadata.symbolType === 'method');
174
+ ```
175
+
176
+ **List functions with specific parameters:**
177
+ ```typescript
178
+ const functions = await list_functions({ pattern: ".*validate.*", language: "typescript" });
179
+
180
+ // Filter by parameter count
181
+ const simpleValidators = functions.filter(r => (r.metadata.parameters?.length || 0) <= 2);
182
+ ```
183
+
184
+ ### AST Support
185
+
186
+ **Currently supported:**
187
+ - ✅ TypeScript (`.ts`, `.tsx`)
188
+ - ✅ JavaScript (`.js`, `.jsx`, `.mjs`, `.cjs`)
189
+ - ✅ Shopify Liquid (`.liquid`) - **Special regex-based chunking**
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
+ ### Shopify Liquid Support ⚡ NEW
199
+
200
+ Lien provides specialized chunking for Shopify themes with **complete dependency tracking**:
201
+
202
+ **Liquid template handling:**
203
+ - `{% schema %}` blocks - Kept as single chunks, section names extracted
204
+ - `{% style %}` blocks - Preserved together for scoped CSS
205
+ - `{% javascript %}` blocks - Kept intact
206
+ - Oversized blocks (>225 lines) - Intelligently split to prevent token limits
207
+
208
+ **JSON template handling (Shopify 2.0+):**
209
+ - `templates/**/*.json` - Template definition files
210
+ - Section references extracted from JSON structure
211
+ - Template names extracted from filepath
212
+
213
+ **Complete dependency tracking (tracked in `metadata.imports`):**
214
+ - `{% render 'snippet-name' %}` - Snippet dependencies
215
+ - `{% include 'snippet-name' %}` - Legacy includes
216
+ - `{% section 'section-name' %}` - Section usage in layouts
217
+ - JSON template sections - Section type references
218
+
219
+ **Example metadata:**
220
+ ```typescript
221
+ // JSON Template
222
+ {
223
+ content: "{\"sections\": {\"main\": {\"type\": \"main-product\"}}}",
224
+ metadata: {
225
+ file: "templates/product.json",
226
+ type: "template",
227
+ language: "json",
228
+ symbolName: "product", // Template name
229
+ symbolType: "template",
230
+ imports: ["main-product"] // Sections used by this template
231
+ }
232
+ }
233
+
234
+ // Liquid Section Schema
235
+ {
236
+ content: "{% schema %}\n{\"name\": \"Hero Section\", ...}\n{% endschema %}",
237
+ metadata: {
238
+ file: "sections/hero.liquid",
239
+ type: "block",
240
+ language: "liquid",
241
+ symbolName: "Hero Section", // Extracted from schema JSON
242
+ symbolType: "schema",
243
+ imports: undefined // No render/include/section tags found in this block
244
+ }
245
+ }
246
+
247
+ // Liquid Template Content
248
+ {
249
+ content: "<div>{% render 'logo' %}{% render 'nav' %}</div>",
250
+ metadata: {
251
+ file: "sections/header.liquid",
252
+ type: "template",
253
+ language: "liquid",
254
+ imports: ["logo", "nav"] // Tracked dependencies
255
+ }
256
+ }
257
+ ```
258
+
259
+ **Benefits:**
260
+ - **Complete dependency graph** - JSON templates → sections → snippets
261
+ - **Schema preservation** - Never splits section configuration across chunks
262
+ - **Better context** - AI knows full theme structure and all dependencies
263
+
264
+ ### Known Limitations
265
+
266
+ **Very large files (1000+ lines):**
267
+ - Tree-sitter may fail with "Invalid argument" error on extremely large files
268
+ - When this occurs, Lien automatically falls back to line-based chunking
269
+ - This is a known Tree-sitter limitation with very large syntax trees
270
+ - Fallback behavior is configurable via `astFallback` setting
271
+
272
+ **Resilient parsing:**
273
+ - Tree-sitter is designed to produce best-effort ASTs even for invalid syntax
274
+ - Parse errors are rare; most malformed code still produces usable chunks
275
+ - The `astFallback: 'error'` option mainly catches edge cases like large file errors
276
+
277
+ ### Configuration
278
+
279
+ Control AST behavior in `.lien.config.json`:
280
+
281
+ ```json
282
+ {
283
+ "chunking": {
284
+ "useAST": true, // Enable AST-based chunking (default: true)
285
+ "astFallback": "line-based" // Fallback strategy: 'line-based' | 'error'
286
+ }
287
+ }
288
+ ```
289
+
290
+ ---
291
+
117
292
  ## Input Validation & Error Handling
118
293
 
119
294
  Lien uses Zod schemas for runtime type-safe validation of all tool inputs. This provides:
@@ -168,7 +343,7 @@ Lien uses structured error codes for programmatic error handling:
168
343
  - `INVALID_INPUT` - Parameter validation failed
169
344
  - `FILE_NOT_FOUND` - Requested file doesn't exist in index
170
345
  - `INDEX_NOT_FOUND` - No index found (run `lien index`)
171
- - `INDEX_CORRUPTED` - Index is corrupted (run `lien reindex`)
346
+ - `INDEX_CORRUPTED` - Index is corrupted (run `lien index` to rebuild)
172
347
  - `EMBEDDING_GENERATION_FAILED` - Embedding model failed (retryable)
173
348
  - `INTERNAL_ERROR` - Unexpected internal error
174
349
 
@@ -232,7 +407,7 @@ Lien uses structured error codes for programmatic error handling:
232
407
  4. Analyze and suggest improvements
233
408
  ```
234
409
 
235
- ### Pattern 7: Finding All Classes/Functions by Name Pattern ⚡ NEW
410
+ ### Pattern 7: Finding All Classes/Functions by Name Pattern ⚡
236
411
  ```
237
412
  1. list_functions({ pattern: ".*Controller.*", language: "php" })
238
413
  2. Review the list of matching classes
@@ -245,6 +420,39 @@ Lien uses structured error codes for programmatic error handling:
245
420
  - "What Services exist?" → `list_functions({ pattern: ".*Service.*" })`
246
421
  - "Find all API handlers" → `list_functions({ pattern: "handle.*" })`
247
422
 
423
+ ### Pattern 8: Working with Shopify Themes (Liquid + JSON) ⚡
424
+ ```
425
+ 1. semantic_search({ query: "product template configuration" })
426
+ → Finds JSON template with section references
427
+ 2. Check metadata.imports to see which sections are used
428
+ 3. semantic_search({ query: "main-product section schema" })
429
+ → Find section definition
430
+ 4. Review section's metadata.imports to see which snippets it renders
431
+ → Complete dependency chain visible!
432
+ ```
433
+
434
+ **Example queries:**
435
+ - "Find the product template sections" → Returns `templates/product.json` with section imports
436
+ - "Which sections are on the collection page?" → Check JSON template imports
437
+ - "What sections use the product-card snippet?" → Reverse lookup via imports
438
+ - "Show the hero section schema" → Returns complete `{% schema %}` block with name
439
+ - "What snippets does the footer render?" → See `metadata.imports: ["logo", "nav", ...]`
440
+
441
+ **Complete dependency graph:**
442
+ ```
443
+ templates/product.json
444
+ → imports: ["main-product", "recommendations"]
445
+ → sections/main-product.liquid
446
+ → imports: ["product-card", "price-tag"]
447
+ → snippets/product-card.liquid
448
+ → snippets/price-tag.liquid
449
+ ```
450
+
451
+ **Dependency tracking:**
452
+ - **JSON templates** - `metadata.imports` contains section type references
453
+ - **Liquid templates** - `metadata.imports` contains `{% render %}`, `{% include %}`, `{% section %}` references
454
+ - Full theme architecture visible through imports metadata
455
+
248
456
  ---
249
457
 
250
458
  ## Decision Tree: Lien vs Other Tools
@@ -256,7 +464,7 @@ Lien uses structured error codes for programmatic error handling:
256
464
  ✅ Exploring unfamiliar parts of codebase
257
465
  ✅ Searching by what code **does** (behavior, functionality)
258
466
 
259
- ### Use `list_functions` when: ⚡ NEW
467
+ ### Use `list_functions` when: ⚡
260
468
  ✅ User asks "show me all Controllers" or similar structural queries
261
469
  ✅ Looking for classes/functions matching a **naming pattern**
262
470
  ✅ Getting architectural overview (all Services, all Handlers, etc.)
@@ -297,6 +505,9 @@ Lien uses structured error codes for programmatic error handling:
297
505
  - "React components with form state"
298
506
  - "database migration scripts"
299
507
  - "API endpoints for user data"
508
+ - "Shopify section schema for hero banner" (Liquid)
509
+ - "files that render product-card snippet" (Liquid)
510
+ - "layout file with header and footer sections" (Liquid)
300
511
 
301
512
  ### Bad Queries (DON'T DO THIS):
302
513
  - "auth" (too vague)
@@ -317,9 +528,10 @@ Lien uses structured error codes for programmatic error handling:
317
528
  - First query loads embeddings (~1-2s), subsequent queries are fast (<500ms)
318
529
  - Increase `limit` to 10-15 for broad exploration
319
530
  - Results are ranked by semantic relevance (trust the ranking)
320
- - User can re-index with `lien reindex` if results seem stale
531
+ - User can re-index with `lien index` if results seem stale
321
532
  - **Relevance categories**: All search results include a `relevance` field (`highly_relevant`, `relevant`, `loosely_related`, `not_relevant`) to help interpret search quality at a glance
322
533
  - **Test associations**: Lien automatically detects test-source relationships across 12 languages using convention-based patterns and import analysis
534
+ - **Shopify Liquid themes**: Semantic chunking reduces chunk count by ~60% (schema/style/javascript blocks preserved), improving search quality and performance
323
535
 
324
536
  ---
325
537
 
@@ -341,10 +553,12 @@ Create a `lien.mdc` file in your `.cursor/rules/` directory:
341
553
  ```bash
342
554
  # From your project directory
343
555
  mkdir -p .cursor/rules
344
- cp /path/to/lien/CURSOR_RULES_TEMPLATE.md .cursor/rules/lien.mdc
556
+ cp node_modules/@liendev/lien/CURSOR_RULES_TEMPLATE.md .cursor/rules/lien.mdc
345
557
  ```
346
558
 
347
559
  The `alwaysApply: true` frontmatter ensures Cursor uses Lien for all files in your project.
348
560
 
349
561
  This approach allows you to have multiple rule files in `.cursor/rules/` without conflicts.
350
562
 
563
+ **Note:** The template is automatically copied during `lien init` to `.cursor/rules/lien.mdc`.
564
+
package/README.md CHANGED
@@ -72,7 +72,15 @@ Contributions welcome! See **[CONTRIBUTING.md](./CONTRIBUTING.md)** for guidelin
72
72
 
73
73
  ## License
74
74
 
75
- MIT © [Alf Henderson](https://github.com/alfhen)
75
+ AGPL-3.0 © [Alf Henderson](https://github.com/alfhen)
76
+
77
+ **Lien is free forever for local use.** The AGPL license ensures that:
78
+ - ✅ You can use Lien locally without restrictions
79
+ - ✅ You can modify and distribute Lien freely
80
+ - ✅ Improvements get contributed back to the community
81
+ - ✅ We can sustain long-term development
82
+
83
+ For questions about licensing, contact us at alf@lien.dev
76
84
 
77
85
  ---
78
86