@winci/local-rag 0.2.2 → 0.2.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@winci/local-rag",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Semantic search for your codebase — local-first RAG MCP server with hybrid search, AST-aware chunking, and usage analytics",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -41,7 +41,7 @@
41
41
  "dependencies": {
42
42
  "@huggingface/transformers": "^3.4.0",
43
43
  "@modelcontextprotocol/sdk": "^1.12.0",
44
- "code-chunk": "^0.1.13",
44
+ "@winci/bun-chunk": "^0.1.0",
45
45
  "gray-matter": "^4.0.3",
46
46
  "sqlite-vec": "^0.1.6",
47
47
  "zod": "^4.3.6"
@@ -1,4 +1,4 @@
1
- import { chunk as astChunk } from "code-chunk";
1
+ import { chunk as astChunk } from "@winci/bun-chunk";
2
2
  import { log } from "../utils/log";
3
3
 
4
4
  export interface ChunkImport {
@@ -97,18 +97,23 @@ async function _chunkText(
97
97
  // Try AST-aware chunking for supported code files (even small ones, for import/export extraction)
98
98
  if (AST_SUPPORTED.has(extension)) {
99
99
  try {
100
- const astChunks = await astChunk(filePath || `file${extension}`, text, {
101
- maxChunkSize: chunkSize,
102
- });
100
+ const astChunks = await astChunk(filePath || `file${extension}`, text);
103
101
  if (astChunks.length > 0) {
104
- return astChunks.map((c, i) => ({
105
- text: c.text,
106
- index: i,
107
- imports: c.context.imports.map((im) => ({ name: im.name, source: im.source })),
108
- exports: c.context.entities
109
- .filter((e) => e.type === "export" || e.type === "function" || e.type === "class" || e.type === "interface" || e.type === "type" || e.type === "enum")
110
- .map((e) => ({ name: e.name, type: e.type })),
111
- }));
102
+ return astChunks.map((c, i) => {
103
+ const chunk: Chunk = {
104
+ text: c.text,
105
+ index: i,
106
+ startLine: c.startLine + 1, // bun-chunk is 0-indexed, local-rag is 1-indexed
107
+ endLine: c.endLine + 1,
108
+ };
109
+ if (c.type === "import") {
110
+ chunk.imports = parseImportText(c.text);
111
+ }
112
+ if (c.name && c.type !== "import" && c.type !== "block") {
113
+ chunk.exports = [{ name: c.name, type: c.type }];
114
+ }
115
+ return chunk;
116
+ });
112
117
  }
113
118
  } catch (err) {
114
119
  log.debug(`AST chunking failed for ${filePath || extension}, using heuristic: ${err instanceof Error ? err.message : err}`, "chunker");
@@ -201,6 +206,29 @@ function assignLineNumbers(chunks: Chunk[], fullText: string): void {
201
206
  }
202
207
  }
203
208
 
209
+ /** Extract import name and source from an import statement text */
210
+ function parseImportText(text: string): ChunkImport[] {
211
+ // Match: import { foo } from "bar" / import foo from "bar" / import * as foo from "bar"
212
+ const match = text.match(/from\s+["']([^"']+)["']/);
213
+ if (!match) {
214
+ // import "side-effect" or Python: import foo / from foo import bar
215
+ const pyImport = text.match(/^import\s+(\S+)/);
216
+ if (pyImport) return [{ name: pyImport[1], source: pyImport[1] }];
217
+ const pyFrom = text.match(/^from\s+(\S+)\s+import\s+(.+)/);
218
+ if (pyFrom) return [{ name: pyFrom[2].trim(), source: pyFrom[1] }];
219
+ // Go/Rust: use/import with path
220
+ const quotedPath = text.match(/["']([^"']+)["']/);
221
+ if (quotedPath) return [{ name: quotedPath[1].split("/").pop()!, source: quotedPath[1] }];
222
+ return [];
223
+ }
224
+ const source = match[1];
225
+ const nameMatch = text.match(/import\s+(?:\{([^}]+)\}|(\w+)|\*\s+as\s+(\w+))/);
226
+ const name = nameMatch
227
+ ? (nameMatch[1]?.trim() || nameMatch[2] || nameMatch[3] || source)
228
+ : source;
229
+ return [{ name, source }];
230
+ }
231
+
204
232
  function splitMarkdown(text: string): string[] {
205
233
  // Split on heading boundaries (## or ###)
206
234
  const parts = text.split(/(?=^#{1,3}\s)/m);