@dreb/semantic-search 2.0.5 → 2.0.7

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.
Files changed (49) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/bin/server.js +13 -3
  3. package/dist/chunker.d.ts.map +1 -1
  4. package/dist/chunker.js.map +1 -1
  5. package/dist/db.d.ts.map +1 -1
  6. package/dist/db.js +0 -1
  7. package/dist/db.js.map +1 -1
  8. package/dist/embedder.d.ts.map +1 -1
  9. package/dist/embedder.js +3 -6
  10. package/dist/embedder.js.map +1 -1
  11. package/dist/format.d.ts.map +1 -1
  12. package/dist/format.js.map +1 -1
  13. package/dist/index-manager.d.ts +4 -0
  14. package/dist/index-manager.d.ts.map +1 -1
  15. package/dist/index-manager.js +2 -3
  16. package/dist/index-manager.js.map +1 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/mcp-server.d.ts.map +1 -1
  19. package/dist/mcp-server.js.map +1 -1
  20. package/dist/metrics/bm25.d.ts.map +1 -1
  21. package/dist/metrics/bm25.js.map +1 -1
  22. package/dist/metrics/git-recency.d.ts.map +1 -1
  23. package/dist/metrics/git-recency.js.map +1 -1
  24. package/dist/metrics/import-graph.d.ts.map +1 -1
  25. package/dist/metrics/import-graph.js.map +1 -1
  26. package/dist/metrics/path-match.d.ts.map +1 -1
  27. package/dist/metrics/path-match.js.map +1 -1
  28. package/dist/metrics/symbol-match.d.ts.map +1 -1
  29. package/dist/metrics/symbol-match.js.map +1 -1
  30. package/dist/metrics/tokenize.d.ts.map +1 -1
  31. package/dist/metrics/tokenize.js.map +1 -1
  32. package/dist/poem.d.ts.map +1 -1
  33. package/dist/poem.js.map +1 -1
  34. package/dist/query-classifier.d.ts.map +1 -1
  35. package/dist/query-classifier.js.map +1 -1
  36. package/dist/scanner.d.ts.map +1 -1
  37. package/dist/scanner.js.map +1 -1
  38. package/dist/search.d.ts.map +1 -1
  39. package/dist/search.js +3 -5
  40. package/dist/search.js.map +1 -1
  41. package/dist/text-chunker.d.ts.map +1 -1
  42. package/dist/text-chunker.js.map +1 -1
  43. package/dist/tree-sitter-chunker.d.ts.map +1 -1
  44. package/dist/tree-sitter-chunker.js.map +1 -1
  45. package/dist/types.d.ts.map +1 -1
  46. package/dist/vector-store.d.ts.map +1 -1
  47. package/dist/vector-store.js.map +1 -1
  48. package/package.json +3 -3
  49. package/skills/search/SKILL.md +5 -0
@@ -1 +1 @@
1
- {"version":3,"file":"tree-sitter-chunker.js","sourceRoot":"","sources":["../src/tree-sitter-chunker.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAIvC,4DAA4D;AAC5D,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAiC/C,IAAI,MAAM,GAAuB,IAAI,CAAC;AACtC,IAAI,QAAQ,GAAyB,IAAI,CAAC;AAE1C,IAAI,WAAW,GAAyB,IAAI,CAAC;AAC7C,IAAI,WAAW,GAAG,KAAK,CAAC;AAExB,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E,MAAM,aAAa,GAAG,IAAI,GAAG,EAA0D,CAAC;AAExF,4CAA4C;AAC5C,MAAM,aAAa,GAAuC;IACzD,UAAU,EAAE,oDAAoD;IAChE,GAAG,EAAE,6CAA6C;IAClD,UAAU,EAAE,oDAAoD;IAChE,MAAM,EAAE,4CAA4C;IACpD,EAAE,EAAE,oCAAoC;IACxC,IAAI,EAAE,wCAAwC;IAC9C,IAAI,EAAE,wCAAwC;IAC9C,CAAC,EAAE,kCAAkC;IACrC,GAAG,EAAE,sCAAsC;CAC3C,CAAC;AAEF,+EAA+E;AAC/E,kBAAkB;AAClB,+EAA+E;AAE/E,2CAA2C;AAC3C,SAAS,SAAS,CAAC,IAAY,EAAiB;IAC/C,OAAO,IA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AAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC;QAE9C,mEAAmE;QACnE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO;gBACN;oBACC,QAAQ;oBACR,SAAS,EAAE,CAAC;oBACZ,OAAO,EAAE,WAAW,CAAC,MAAM;oBAC3B,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,IAAI;oBACV,OAAO;oBACP,QAAQ,EAAE,QAAQ;iBAClB;aACD,CAAC;QACH,CAAC;QAED,OAAO,GAAG,CAAC;IACZ,CAAC;YAAS,CAAC;QACV,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,MAAM,CAAC,MAAM,EAAE,CAAC;IACjB,CAAC;AAAA,CACD","sourcesContent":["/**\n * AST-aware code chunking using tree-sitter (WASM).\n *\n * Parses source files into syntax trees and extracts meaningful code constructs\n * (functions, classes, methods, structs, etc.) as individual chunks. Gaps between\n * extracted nodes are captured as file-level chunks when substantial.\n */\n\nimport { readFileSync } from \"fs\";\nimport { createRequire } from \"module\";\nimport type { Node as TSNode } from \"web-tree-sitter\";\nimport type { Chunk, ChunkKind, TreeSitterLanguage } from \"./types.js\";\n\n// Use createRequire for resolving WASM paths in ESM context\nconst require = createRequire(import.meta.url);\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/** Describes which AST node types to extract for a language and how to get names. */\ninterface NodeExtractor {\n\t/** The tree-sitter node type string. */\n\ttype: string;\n\t/** The ChunkKind to assign to extracted chunks. */\n\tkind: ChunkKind;\n\t/** How to extract the symbol name from the node. */\n\tgetName: (node: TSNode) => string | null;\n}\n\n/** Intermediate representation of an extracted AST region. */\ninterface ExtractedRegion {\n\tname: string | null;\n\tkind: ChunkKind;\n\tstartLine: number; // 1-indexed\n\tendLine: number; // 1-indexed, inclusive\n\tcontent: string;\n}\n\n// ============================================================================\n// Lazy Imports\n// ============================================================================\n\n// web-tree-sitter types imported dynamically to avoid top-level await\ntype ParserClass = typeof import(\"web-tree-sitter\").Parser;\ntype LanguageClass = typeof import(\"web-tree-sitter\").Language;\n\nlet Parser: ParserClass | null = null;\nlet Language: LanguageClass | null = null;\n\nlet initPromise: Promise<void> | null = null;\nlet initialized = false;\n\n// ============================================================================\n// Language Cache\n// ============================================================================\n\nconst languageCache = new Map<TreeSitterLanguage, import(\"web-tree-sitter\").Language>();\n\n/** Grammar WASM paths keyed by language. */\nconst GRAMMAR_PATHS: Record<TreeSitterLanguage, string> = {\n\ttypescript: \"tree-sitter-typescript/tree-sitter-typescript.wasm\",\n\ttsx: \"tree-sitter-typescript/tree-sitter-tsx.wasm\",\n\tjavascript: \"tree-sitter-javascript/tree-sitter-javascript.wasm\",\n\tpython: \"tree-sitter-python/tree-sitter-python.wasm\",\n\tgo: \"tree-sitter-go/tree-sitter-go.wasm\",\n\trust: \"tree-sitter-rust/tree-sitter-rust.wasm\",\n\tjava: \"tree-sitter-java/tree-sitter-java.wasm\",\n\tc: \"tree-sitter-c/tree-sitter-c.wasm\",\n\tcpp: \"tree-sitter-cpp/tree-sitter-cpp.wasm\",\n};\n\n// ============================================================================\n// Name Extractors\n// ============================================================================\n\n/** Get name from a node's `name` field. */\nfunction nameField(node: TSNode): string | null {\n\treturn node.childForFieldName(\"name\")?.text ?? null;\n}\n\n/** Get name for an arrow function assigned to a variable. */\nfunction arrowFunctionName(node: TSNode): string | null {\n\tconst parent = node.parent;\n\tif (parent?.type === \"variable_declarator\") {\n\t\treturn parent.childForFieldName(\"name\")?.text ?? null;\n\t}\n\treturn null;\n}\n\n/** Get name for C function_definition: name is in the function_declarator child. */\nfunction cFunctionName(node: TSNode): string | null {\n\tconst declarator = node.childForFieldName(\"declarator\");\n\tif (!declarator) return null;\n\t// function_declarator has a `declarator` field for the actual name\n\tif (declarator.type === \"function_declarator\") {\n\t\treturn declarator.childForFieldName(\"declarator\")?.text ?? null;\n\t}\n\treturn declarator.text ?? null;\n}\n\n/** Get name from an export_statement's inner declaration. */\nfunction exportName(node: TSNode): string | null {\n\tconst decl = node.childForFieldName(\"declaration\");\n\tif (!decl) {\n\t\t// Named export like `export { foo }` — use the full text isn't useful,\n\t\t// just return null for anonymous exports\n\t\treturn null;\n\t}\n\treturn decl.childForFieldName(\"name\")?.text ?? null;\n}\n\n// ============================================================================\n// Per-Language Node Extractors\n// ============================================================================\n\nconst TS_EXTRACTORS: NodeExtractor[] = [\n\t{ type: \"function_declaration\", kind: \"function\", getName: nameField },\n\t{ type: \"method_definition\", kind: \"method\", getName: nameField },\n\t{ type: \"class_declaration\", kind: \"class\", getName: nameField },\n\t{ type: \"interface_declaration\", kind: \"interface\", getName: nameField },\n\t{ type: \"type_alias_declaration\", kind: \"type_alias\", getName: nameField },\n\t{ type: \"export_statement\", kind: \"export\", getName: exportName },\n\t{ type: \"arrow_function\", kind: \"function\", getName: arrowFunctionName },\n];\n\nconst JS_EXTRACTORS: NodeExtractor[] = [\n\t{ type: \"function_declaration\", kind: \"function\", getName: nameField },\n\t{ type: \"method_definition\", kind: \"method\", getName: nameField },\n\t{ type: \"class_declaration\", kind: \"class\", getName: nameField },\n\t{ type: \"export_statement\", kind: \"export\", getName: exportName },\n\t{ type: \"arrow_function\", kind: \"function\", getName: arrowFunctionName },\n];\n\nconst PYTHON_EXTRACTORS: NodeExtractor[] = [\n\t{ type: \"function_definition\", kind: \"function\", getName: nameField },\n\t{ type: \"class_definition\", kind: \"class\", getName: nameField },\n];\n\nconst GO_EXTRACTORS: NodeExtractor[] = [\n\t{ type: \"function_declaration\", kind: \"function\", getName: nameField },\n\t{ type: \"method_declaration\", kind: \"method\", getName: nameField },\n\t{ type: \"type_spec\", kind: \"struct\", getName: nameField },\n];\n\nconst RUST_EXTRACTORS: NodeExtractor[] = [\n\t{ type: \"function_item\", kind: \"function\", getName: nameField },\n\t{ type: \"impl_item\", kind: \"impl\", getName: (n) => n.childForFieldName(\"type\")?.text ?? null },\n\t{ type: \"struct_item\", kind: \"struct\", getName: nameField },\n\t{ type: \"enum_item\", kind: \"enum\", getName: nameField },\n\t{ type: \"trait_item\", kind: \"interface\", getName: nameField },\n];\n\nconst JAVA_EXTRACTORS: NodeExtractor[] = [\n\t{ type: \"class_declaration\", kind: \"class\", getName: nameField },\n\t{ type: \"method_declaration\", kind: \"method\", getName: nameField },\n\t{ type: \"interface_declaration\", kind: \"interface\", getName: nameField },\n];\n\nconst C_EXTRACTORS: NodeExtractor[] = [\n\t{ type: \"function_definition\", kind: \"function\", getName: cFunctionName },\n\t{ type: \"struct_specifier\", kind: \"struct\", getName: nameField },\n];\n\nconst CPP_EXTRACTORS: NodeExtractor[] = [\n\t...C_EXTRACTORS,\n\t{ type: \"class_specifier\", kind: \"class\", getName: nameField },\n];\n\nconst LANGUAGE_EXTRACTORS: Record<TreeSitterLanguage, NodeExtractor[]> = {\n\ttypescript: TS_EXTRACTORS,\n\ttsx: TS_EXTRACTORS,\n\tjavascript: JS_EXTRACTORS,\n\tpython: PYTHON_EXTRACTORS,\n\tgo: GO_EXTRACTORS,\n\trust: RUST_EXTRACTORS,\n\tjava: JAVA_EXTRACTORS,\n\tc: C_EXTRACTORS,\n\tcpp: CPP_EXTRACTORS,\n};\n\n// ============================================================================\n// Initialization\n// ============================================================================\n\n/**\n * Initialize the tree-sitter WASM runtime. Must be called before parsing.\n * Safe to call multiple times — subsequent calls are no-ops.\n */\nexport async function initTreeSitter(): Promise<void> {\n\tif (initialized) return;\n\tif (initPromise) return initPromise;\n\n\tinitPromise = (async () => {\n\t\ttry {\n\t\t\tconst mod = await import(\"web-tree-sitter\");\n\t\t\tParser = mod.Parser;\n\t\t\tLanguage = mod.Language;\n\n\t\t\tconst wasmPath = require.resolve(\"web-tree-sitter/web-tree-sitter.wasm\");\n\t\t\tconst wasmBuf = readFileSync(wasmPath);\n\t\t\tawait Parser.init({ locateFile: () => wasmPath, wasmBinary: wasmBuf });\n\t\t\tinitialized = true;\n\t\t} catch (err) {\n\t\t\t// Reset so subsequent calls can retry instead of returning\n\t\t\t// the same rejected promise forever\n\t\t\tinitPromise = null;\n\t\t\tthrow err;\n\t\t}\n\t})();\n\n\treturn initPromise;\n}\n\n// ============================================================================\n// Language Loading\n// ============================================================================\n\n/** Load and cache a tree-sitter language grammar. */\nasync function loadLanguage(lang: TreeSitterLanguage): Promise<import(\"web-tree-sitter\").Language> {\n\tconst cached = languageCache.get(lang);\n\tif (cached) return cached;\n\n\tif (!Language) {\n\t\tthrow new Error(\"tree-sitter not initialized — call initTreeSitter() first\");\n\t}\n\n\tconst grammarPath = require.resolve(GRAMMAR_PATHS[lang]);\n\tconst loaded = await Language.load(grammarPath);\n\tlanguageCache.set(lang, loaded);\n\treturn loaded;\n}\n\n// ============================================================================\n// AST Extraction\n// ============================================================================\n\n/**\n * Walk the tree and collect nodes matching the target types.\n * Returns regions sorted by start position, with nested nodes skipped\n * (only outermost matches are kept).\n */\nfunction extractRegions(rootNode: TSNode, extractors: NodeExtractor[], _sourceLines: string[]): ExtractedRegion[] {\n\t// Gather all target node types\n\tconst typeToExtractors = new Map<string, NodeExtractor>();\n\tfor (const ext of extractors) {\n\t\ttypeToExtractors.set(ext.type, ext);\n\t}\n\n\tconst targetTypes = extractors.map((e) => e.type);\n\tconst candidates = rootNode.descendantsOfType(targetTypes);\n\n\t// Convert to regions\n\tconst raw: ExtractedRegion[] = [];\n\tfor (const node of candidates) {\n\t\tconst ext = typeToExtractors.get(node.type);\n\t\tif (!ext) continue;\n\n\t\t// For struct_specifier in C, only extract if it has a body (field_declaration_list)\n\t\tif (node.type === \"struct_specifier\") {\n\t\t\tconst hasBody = node.children.some((c) => c.type === \"field_declaration_list\");\n\t\t\tif (!hasBody) continue;\n\t\t}\n\n\t\t// For arrow_function, only extract if parent is variable_declarator (named assignment)\n\t\tif (node.type === \"arrow_function\") {\n\t\t\tif (node.parent?.type !== \"variable_declarator\") continue;\n\t\t}\n\n\t\tconst startLine = node.startPosition.row + 1; // 0→1 indexed\n\t\tconst endLine = node.endPosition.row + 1;\n\n\t\traw.push({\n\t\t\tname: ext.getName(node),\n\t\t\tkind: ext.kind,\n\t\t\tstartLine,\n\t\t\tendLine,\n\t\t\tcontent: node.text,\n\t\t});\n\t}\n\n\t// Sort by start line, then by end line descending (larger ranges first)\n\traw.sort((a, b) => a.startLine - b.startLine || b.endLine - a.endLine);\n\n\t// Remove nested regions — keep only outermost\n\tconst regions: ExtractedRegion[] = [];\n\tlet lastEndLine = -1;\n\n\tfor (const region of raw) {\n\t\tif (region.startLine > lastEndLine) {\n\t\t\tregions.push(region);\n\t\t\tlastEndLine = region.endLine;\n\t\t}\n\t\t// else: this region is nested inside the previous one — skip\n\t}\n\n\treturn regions;\n}\n\n// ============================================================================\n// Gap Collection\n// ============================================================================\n\n/** Minimum number of non-blank lines for a gap to become its own chunk. */\nconst MIN_GAP_LINES = 3;\n\n/**\n * Create file-level chunks for substantial code between extracted regions.\n */\nfunction collectGaps(\n\tregions: ExtractedRegion[],\n\tsourceLines: string[],\n\tfilePath: string,\n\tfileType: TreeSitterLanguage,\n): Chunk[] {\n\tconst gaps: Chunk[] = [];\n\tlet cursor = 1; // 1-indexed current line\n\n\tfor (const region of regions) {\n\t\tif (region.startLine > cursor) {\n\t\t\tconst gapLines = sourceLines.slice(cursor - 1, region.startLine - 1);\n\t\t\tconst nonBlank = gapLines.filter((l) => l.trim().length > 0).length;\n\t\t\tif (nonBlank > MIN_GAP_LINES) {\n\t\t\t\tgaps.push({\n\t\t\t\t\tfilePath,\n\t\t\t\t\tstartLine: cursor,\n\t\t\t\t\tendLine: region.startLine - 1,\n\t\t\t\t\tkind: \"file\",\n\t\t\t\t\tname: null,\n\t\t\t\t\tcontent: gapLines.join(\"\\n\"),\n\t\t\t\t\tfileType,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tcursor = region.endLine + 1;\n\t}\n\n\t// Trailing gap after last region\n\tif (cursor <= sourceLines.length) {\n\t\tconst gapLines = sourceLines.slice(cursor - 1);\n\t\tconst nonBlank = gapLines.filter((l) => l.trim().length > 0).length;\n\t\tif (nonBlank > MIN_GAP_LINES) {\n\t\t\tgaps.push({\n\t\t\t\tfilePath,\n\t\t\t\tstartLine: cursor,\n\t\t\t\tendLine: sourceLines.length,\n\t\t\t\tkind: \"file\",\n\t\t\t\tname: null,\n\t\t\t\tcontent: gapLines.join(\"\\n\"),\n\t\t\t\tfileType,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn gaps;\n}\n\n// ============================================================================\n// Public API\n// ============================================================================\n\n/**\n * Parse a source file with tree-sitter and extract AST-aware chunks.\n *\n * Returns chunks for functions, classes, methods, and other language-specific\n * constructs, plus file-level chunks for substantial gaps between them.\n *\n * @param content - Raw source code text\n * @param filePath - Relative file path (stored in chunk metadata)\n * @param language - Tree-sitter language identifier\n */\nexport async function chunkWithTreeSitter(\n\tcontent: string,\n\tfilePath: string,\n\tlanguage: TreeSitterLanguage,\n): Promise<Chunk[]> {\n\tif (!initialized || !Parser) {\n\t\tawait initTreeSitter();\n\t}\n\n\t// After init, Parser is guaranteed to be set\n\tconst ParserCtor = Parser!;\n\tconst lang = await loadLanguage(language);\n\tconst parser = new ParserCtor();\n\tparser.setLanguage(lang);\n\n\tconst tree = parser.parse(content);\n\tif (!tree) {\n\t\t// Parse failed — free the parser WASM memory before returning\n\t\tparser.delete();\n\t\tconst lines = content.split(\"\\n\");\n\t\treturn [\n\t\t\t{\n\t\t\t\tfilePath,\n\t\t\t\tstartLine: 1,\n\t\t\t\tendLine: lines.length,\n\t\t\t\tkind: \"file\",\n\t\t\t\tname: null,\n\t\t\t\tcontent,\n\t\t\t\tfileType: language,\n\t\t\t},\n\t\t];\n\t}\n\n\ttry {\n\t\tconst sourceLines = content.split(\"\\n\");\n\t\tconst extractors = LANGUAGE_EXTRACTORS[language];\n\t\tconst regions = extractRegions(tree.rootNode, extractors, sourceLines);\n\n\t\t// Convert regions to Chunk objects\n\t\tconst chunks: Chunk[] = regions.map((r) => ({\n\t\t\tfilePath,\n\t\t\tstartLine: r.startLine,\n\t\t\tendLine: r.endLine,\n\t\t\tkind: r.kind,\n\t\t\tname: r.name,\n\t\t\tcontent: r.content,\n\t\t\tfileType: language,\n\t\t}));\n\n\t\t// Add gap chunks\n\t\tconst gaps = collectGaps(regions, sourceLines, filePath, language);\n\n\t\t// Merge and sort by start line\n\t\tconst all = [...chunks, ...gaps];\n\t\tall.sort((a, b) => a.startLine - b.startLine);\n\n\t\t// If no regions were extracted, return the whole file as one chunk\n\t\tif (chunks.length === 0) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tfilePath,\n\t\t\t\t\tstartLine: 1,\n\t\t\t\t\tendLine: sourceLines.length,\n\t\t\t\t\tkind: \"file\",\n\t\t\t\t\tname: null,\n\t\t\t\t\tcontent,\n\t\t\t\t\tfileType: language,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\treturn all;\n\t} finally {\n\t\ttree.delete();\n\t\tparser.delete();\n\t}\n}\n"]}
1
+ {"version":3,"file":"tree-sitter-chunker.js","sourceRoot":"","sources":["../src/tree-sitter-chunker.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAIvC,4DAA4D;AAC5D,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAiC/C,IAAI,MAAM,GAAuB,IAAI,CAAC;AACtC,IAAI,QAAQ,GAAyB,IAAI,CAAC;AAE1C,IAAI,WAAW,GAAyB,IAAI,CAAC;AAC7C,IAAI,WAAW,GAAG,KAAK,CAAC;AAExB,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E,MAAM,aAAa,GAAG,IAAI,GAAG,EAA0D,CAAC;AAExF,4CAA4C;AAC5C,MAAM,aAAa,GAAuC;IACzD,UAAU,EAAE,oDAAoD;IAChE,GAAG,EAAE,6CAA6C;IAClD,UAAU,EAAE,oD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jB,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAEnE,+BAA+B;QAC/B,MAAM,GAAG,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;QACjC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC;QAE9C,mEAAmE;QACnE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO;gBACN;oBACC,QAAQ;oBACR,SAAS,EAAE,CAAC;oBACZ,OAAO,EAAE,WAAW,CAAC,MAAM;oBAC3B,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,IAAI;oBACV,OAAO;oBACP,QAAQ,EAAE,QAAQ;iBAClB;aACD,CAAC;QACH,CAAC;QAED,OAAO,GAAG,CAAC;IACZ,CAAC;YAAS,CAAC;QACV,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,MAAM,CAAC,MAAM,EAAE,CAAC;IACjB,CAAC;AACF,CAAC","sourcesContent":["/**\n * AST-aware code chunking using tree-sitter (WASM).\n *\n * Parses source files into syntax trees and extracts meaningful code constructs\n * (functions, classes, methods, structs, etc.) as individual chunks. Gaps between\n * extracted nodes are captured as file-level chunks when substantial.\n */\n\nimport { readFileSync } from \"fs\";\nimport { createRequire } from \"module\";\nimport type { Node as TSNode } from \"web-tree-sitter\";\nimport type { Chunk, ChunkKind, TreeSitterLanguage } from \"./types.js\";\n\n// Use createRequire for resolving WASM paths in ESM context\nconst require = createRequire(import.meta.url);\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/** Describes which AST node types to extract for a language and how to get names. */\ninterface NodeExtractor {\n\t/** The tree-sitter node type string. */\n\ttype: string;\n\t/** The ChunkKind to assign to extracted chunks. */\n\tkind: ChunkKind;\n\t/** How to extract the symbol name from the node. */\n\tgetName: (node: TSNode) => string | null;\n}\n\n/** Intermediate representation of an extracted AST region. */\ninterface ExtractedRegion {\n\tname: string | null;\n\tkind: ChunkKind;\n\tstartLine: number; // 1-indexed\n\tendLine: number; // 1-indexed, inclusive\n\tcontent: string;\n}\n\n// ============================================================================\n// Lazy Imports\n// ============================================================================\n\n// web-tree-sitter types imported dynamically to avoid top-level await\ntype ParserClass = typeof import(\"web-tree-sitter\").Parser;\ntype LanguageClass = typeof import(\"web-tree-sitter\").Language;\n\nlet Parser: ParserClass | null = null;\nlet Language: LanguageClass | null = null;\n\nlet initPromise: Promise<void> | null = null;\nlet initialized = false;\n\n// ============================================================================\n// Language Cache\n// ============================================================================\n\nconst languageCache = new Map<TreeSitterLanguage, import(\"web-tree-sitter\").Language>();\n\n/** Grammar WASM paths keyed by language. */\nconst GRAMMAR_PATHS: Record<TreeSitterLanguage, string> = {\n\ttypescript: \"tree-sitter-typescript/tree-sitter-typescript.wasm\",\n\ttsx: \"tree-sitter-typescript/tree-sitter-tsx.wasm\",\n\tjavascript: \"tree-sitter-javascript/tree-sitter-javascript.wasm\",\n\tpython: \"tree-sitter-python/tree-sitter-python.wasm\",\n\tgo: \"tree-sitter-go/tree-sitter-go.wasm\",\n\trust: \"tree-sitter-rust/tree-sitter-rust.wasm\",\n\tjava: \"tree-sitter-java/tree-sitter-java.wasm\",\n\tc: \"tree-sitter-c/tree-sitter-c.wasm\",\n\tcpp: \"tree-sitter-cpp/tree-sitter-cpp.wasm\",\n};\n\n// ============================================================================\n// Name Extractors\n// ============================================================================\n\n/** Get name from a node's `name` field. */\nfunction nameField(node: TSNode): string | null {\n\treturn node.childForFieldName(\"name\")?.text ?? null;\n}\n\n/** Get name for an arrow function assigned to a variable. */\nfunction arrowFunctionName(node: TSNode): string | null {\n\tconst parent = node.parent;\n\tif (parent?.type === \"variable_declarator\") {\n\t\treturn parent.childForFieldName(\"name\")?.text ?? null;\n\t}\n\treturn null;\n}\n\n/** Get name for C function_definition: name is in the function_declarator child. */\nfunction cFunctionName(node: TSNode): string | null {\n\tconst declarator = node.childForFieldName(\"declarator\");\n\tif (!declarator) return null;\n\t// function_declarator has a `declarator` field for the actual name\n\tif (declarator.type === \"function_declarator\") {\n\t\treturn declarator.childForFieldName(\"declarator\")?.text ?? null;\n\t}\n\treturn declarator.text ?? null;\n}\n\n/** Get name from an export_statement's inner declaration. */\nfunction exportName(node: TSNode): string | null {\n\tconst decl = node.childForFieldName(\"declaration\");\n\tif (!decl) {\n\t\t// Named export like `export { foo }` — use the full text isn't useful,\n\t\t// just return null for anonymous exports\n\t\treturn null;\n\t}\n\treturn decl.childForFieldName(\"name\")?.text ?? null;\n}\n\n// ============================================================================\n// Per-Language Node Extractors\n// ============================================================================\n\nconst TS_EXTRACTORS: NodeExtractor[] = [\n\t{ type: \"function_declaration\", kind: \"function\", getName: nameField },\n\t{ type: \"method_definition\", kind: \"method\", getName: nameField },\n\t{ type: \"class_declaration\", kind: \"class\", getName: nameField },\n\t{ type: \"interface_declaration\", kind: \"interface\", getName: nameField },\n\t{ type: \"type_alias_declaration\", kind: \"type_alias\", getName: nameField },\n\t{ type: \"export_statement\", kind: \"export\", getName: exportName },\n\t{ type: \"arrow_function\", kind: \"function\", getName: arrowFunctionName },\n];\n\nconst JS_EXTRACTORS: NodeExtractor[] = [\n\t{ type: \"function_declaration\", kind: \"function\", getName: nameField },\n\t{ type: \"method_definition\", kind: \"method\", getName: nameField },\n\t{ type: \"class_declaration\", kind: \"class\", getName: nameField },\n\t{ type: \"export_statement\", kind: \"export\", getName: exportName },\n\t{ type: \"arrow_function\", kind: \"function\", getName: arrowFunctionName },\n];\n\nconst PYTHON_EXTRACTORS: NodeExtractor[] = [\n\t{ type: \"function_definition\", kind: \"function\", getName: nameField },\n\t{ type: \"class_definition\", kind: \"class\", getName: nameField },\n];\n\nconst GO_EXTRACTORS: NodeExtractor[] = [\n\t{ type: \"function_declaration\", kind: \"function\", getName: nameField },\n\t{ type: \"method_declaration\", kind: \"method\", getName: nameField },\n\t{ type: \"type_spec\", kind: \"struct\", getName: nameField },\n];\n\nconst RUST_EXTRACTORS: NodeExtractor[] = [\n\t{ type: \"function_item\", kind: \"function\", getName: nameField },\n\t{ type: \"impl_item\", kind: \"impl\", getName: (n) => n.childForFieldName(\"type\")?.text ?? null },\n\t{ type: \"struct_item\", kind: \"struct\", getName: nameField },\n\t{ type: \"enum_item\", kind: \"enum\", getName: nameField },\n\t{ type: \"trait_item\", kind: \"interface\", getName: nameField },\n];\n\nconst JAVA_EXTRACTORS: NodeExtractor[] = [\n\t{ type: \"class_declaration\", kind: \"class\", getName: nameField },\n\t{ type: \"method_declaration\", kind: \"method\", getName: nameField },\n\t{ type: \"interface_declaration\", kind: \"interface\", getName: nameField },\n];\n\nconst C_EXTRACTORS: NodeExtractor[] = [\n\t{ type: \"function_definition\", kind: \"function\", getName: cFunctionName },\n\t{ type: \"struct_specifier\", kind: \"struct\", getName: nameField },\n];\n\nconst CPP_EXTRACTORS: NodeExtractor[] = [\n\t...C_EXTRACTORS,\n\t{ type: \"class_specifier\", kind: \"class\", getName: nameField },\n];\n\nconst LANGUAGE_EXTRACTORS: Record<TreeSitterLanguage, NodeExtractor[]> = {\n\ttypescript: TS_EXTRACTORS,\n\ttsx: TS_EXTRACTORS,\n\tjavascript: JS_EXTRACTORS,\n\tpython: PYTHON_EXTRACTORS,\n\tgo: GO_EXTRACTORS,\n\trust: RUST_EXTRACTORS,\n\tjava: JAVA_EXTRACTORS,\n\tc: C_EXTRACTORS,\n\tcpp: CPP_EXTRACTORS,\n};\n\n// ============================================================================\n// Initialization\n// ============================================================================\n\n/**\n * Initialize the tree-sitter WASM runtime. Must be called before parsing.\n * Safe to call multiple times — subsequent calls are no-ops.\n */\nexport async function initTreeSitter(): Promise<void> {\n\tif (initialized) return;\n\tif (initPromise) return initPromise;\n\n\tinitPromise = (async () => {\n\t\ttry {\n\t\t\tconst mod = await import(\"web-tree-sitter\");\n\t\t\tParser = mod.Parser;\n\t\t\tLanguage = mod.Language;\n\n\t\t\tconst wasmPath = require.resolve(\"web-tree-sitter/web-tree-sitter.wasm\");\n\t\t\tconst wasmBuf = readFileSync(wasmPath);\n\t\t\tawait Parser.init({ locateFile: () => wasmPath, wasmBinary: wasmBuf });\n\t\t\tinitialized = true;\n\t\t} catch (err) {\n\t\t\t// Reset so subsequent calls can retry instead of returning\n\t\t\t// the same rejected promise forever\n\t\t\tinitPromise = null;\n\t\t\tthrow err;\n\t\t}\n\t})();\n\n\treturn initPromise;\n}\n\n// ============================================================================\n// Language Loading\n// ============================================================================\n\n/** Load and cache a tree-sitter language grammar. */\nasync function loadLanguage(lang: TreeSitterLanguage): Promise<import(\"web-tree-sitter\").Language> {\n\tconst cached = languageCache.get(lang);\n\tif (cached) return cached;\n\n\tif (!Language) {\n\t\tthrow new Error(\"tree-sitter not initialized — call initTreeSitter() first\");\n\t}\n\n\tconst grammarPath = require.resolve(GRAMMAR_PATHS[lang]);\n\tconst loaded = await Language.load(grammarPath);\n\tlanguageCache.set(lang, loaded);\n\treturn loaded;\n}\n\n// ============================================================================\n// AST Extraction\n// ============================================================================\n\n/**\n * Walk the tree and collect nodes matching the target types.\n * Returns regions sorted by start position, with nested nodes skipped\n * (only outermost matches are kept).\n */\nfunction extractRegions(rootNode: TSNode, extractors: NodeExtractor[], _sourceLines: string[]): ExtractedRegion[] {\n\t// Gather all target node types\n\tconst typeToExtractors = new Map<string, NodeExtractor>();\n\tfor (const ext of extractors) {\n\t\ttypeToExtractors.set(ext.type, ext);\n\t}\n\n\tconst targetTypes = extractors.map((e) => e.type);\n\tconst candidates = rootNode.descendantsOfType(targetTypes);\n\n\t// Convert to regions\n\tconst raw: ExtractedRegion[] = [];\n\tfor (const node of candidates) {\n\t\tconst ext = typeToExtractors.get(node.type);\n\t\tif (!ext) continue;\n\n\t\t// For struct_specifier in C, only extract if it has a body (field_declaration_list)\n\t\tif (node.type === \"struct_specifier\") {\n\t\t\tconst hasBody = node.children.some((c) => c.type === \"field_declaration_list\");\n\t\t\tif (!hasBody) continue;\n\t\t}\n\n\t\t// For arrow_function, only extract if parent is variable_declarator (named assignment)\n\t\tif (node.type === \"arrow_function\") {\n\t\t\tif (node.parent?.type !== \"variable_declarator\") continue;\n\t\t}\n\n\t\tconst startLine = node.startPosition.row + 1; // 0→1 indexed\n\t\tconst endLine = node.endPosition.row + 1;\n\n\t\traw.push({\n\t\t\tname: ext.getName(node),\n\t\t\tkind: ext.kind,\n\t\t\tstartLine,\n\t\t\tendLine,\n\t\t\tcontent: node.text,\n\t\t});\n\t}\n\n\t// Sort by start line, then by end line descending (larger ranges first)\n\traw.sort((a, b) => a.startLine - b.startLine || b.endLine - a.endLine);\n\n\t// Remove nested regions — keep only outermost\n\tconst regions: ExtractedRegion[] = [];\n\tlet lastEndLine = -1;\n\n\tfor (const region of raw) {\n\t\tif (region.startLine > lastEndLine) {\n\t\t\tregions.push(region);\n\t\t\tlastEndLine = region.endLine;\n\t\t}\n\t\t// else: this region is nested inside the previous one — skip\n\t}\n\n\treturn regions;\n}\n\n// ============================================================================\n// Gap Collection\n// ============================================================================\n\n/** Minimum number of non-blank lines for a gap to become its own chunk. */\nconst MIN_GAP_LINES = 3;\n\n/**\n * Create file-level chunks for substantial code between extracted regions.\n */\nfunction collectGaps(\n\tregions: ExtractedRegion[],\n\tsourceLines: string[],\n\tfilePath: string,\n\tfileType: TreeSitterLanguage,\n): Chunk[] {\n\tconst gaps: Chunk[] = [];\n\tlet cursor = 1; // 1-indexed current line\n\n\tfor (const region of regions) {\n\t\tif (region.startLine > cursor) {\n\t\t\tconst gapLines = sourceLines.slice(cursor - 1, region.startLine - 1);\n\t\t\tconst nonBlank = gapLines.filter((l) => l.trim().length > 0).length;\n\t\t\tif (nonBlank > MIN_GAP_LINES) {\n\t\t\t\tgaps.push({\n\t\t\t\t\tfilePath,\n\t\t\t\t\tstartLine: cursor,\n\t\t\t\t\tendLine: region.startLine - 1,\n\t\t\t\t\tkind: \"file\",\n\t\t\t\t\tname: null,\n\t\t\t\t\tcontent: gapLines.join(\"\\n\"),\n\t\t\t\t\tfileType,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tcursor = region.endLine + 1;\n\t}\n\n\t// Trailing gap after last region\n\tif (cursor <= sourceLines.length) {\n\t\tconst gapLines = sourceLines.slice(cursor - 1);\n\t\tconst nonBlank = gapLines.filter((l) => l.trim().length > 0).length;\n\t\tif (nonBlank > MIN_GAP_LINES) {\n\t\t\tgaps.push({\n\t\t\t\tfilePath,\n\t\t\t\tstartLine: cursor,\n\t\t\t\tendLine: sourceLines.length,\n\t\t\t\tkind: \"file\",\n\t\t\t\tname: null,\n\t\t\t\tcontent: gapLines.join(\"\\n\"),\n\t\t\t\tfileType,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn gaps;\n}\n\n// ============================================================================\n// Public API\n// ============================================================================\n\n/**\n * Parse a source file with tree-sitter and extract AST-aware chunks.\n *\n * Returns chunks for functions, classes, methods, and other language-specific\n * constructs, plus file-level chunks for substantial gaps between them.\n *\n * @param content - Raw source code text\n * @param filePath - Relative file path (stored in chunk metadata)\n * @param language - Tree-sitter language identifier\n */\nexport async function chunkWithTreeSitter(\n\tcontent: string,\n\tfilePath: string,\n\tlanguage: TreeSitterLanguage,\n): Promise<Chunk[]> {\n\tif (!initialized || !Parser) {\n\t\tawait initTreeSitter();\n\t}\n\n\t// After init, Parser is guaranteed to be set\n\tconst ParserCtor = Parser!;\n\tconst lang = await loadLanguage(language);\n\tconst parser = new ParserCtor();\n\tparser.setLanguage(lang);\n\n\tconst tree = parser.parse(content);\n\tif (!tree) {\n\t\t// Parse failed — free the parser WASM memory before returning\n\t\tparser.delete();\n\t\tconst lines = content.split(\"\\n\");\n\t\treturn [\n\t\t\t{\n\t\t\t\tfilePath,\n\t\t\t\tstartLine: 1,\n\t\t\t\tendLine: lines.length,\n\t\t\t\tkind: \"file\",\n\t\t\t\tname: null,\n\t\t\t\tcontent,\n\t\t\t\tfileType: language,\n\t\t\t},\n\t\t];\n\t}\n\n\ttry {\n\t\tconst sourceLines = content.split(\"\\n\");\n\t\tconst extractors = LANGUAGE_EXTRACTORS[language];\n\t\tconst regions = extractRegions(tree.rootNode, extractors, sourceLines);\n\n\t\t// Convert regions to Chunk objects\n\t\tconst chunks: Chunk[] = regions.map((r) => ({\n\t\t\tfilePath,\n\t\t\tstartLine: r.startLine,\n\t\t\tendLine: r.endLine,\n\t\t\tkind: r.kind,\n\t\t\tname: r.name,\n\t\t\tcontent: r.content,\n\t\t\tfileType: language,\n\t\t}));\n\n\t\t// Add gap chunks\n\t\tconst gaps = collectGaps(regions, sourceLines, filePath, language);\n\n\t\t// Merge and sort by start line\n\t\tconst all = [...chunks, ...gaps];\n\t\tall.sort((a, b) => a.startLine - b.startLine);\n\n\t\t// If no regions were extracted, return the whole file as one chunk\n\t\tif (chunks.length === 0) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tfilePath,\n\t\t\t\t\tstartLine: 1,\n\t\t\t\t\tendLine: sourceLines.length,\n\t\t\t\t\tkind: \"file\",\n\t\t\t\t\tname: null,\n\t\t\t\t\tcontent,\n\t\t\t\t\tfileType: language,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\treturn all;\n\t} finally {\n\t\ttree.delete();\n\t\tparser.delete();\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,uDAAuD;AACvD,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,KAAK,GAAG,YAAY,GAAG,QAAQ,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,GAAG,GAAG,KAAK,CAAC;AAEvH,4DAA4D;AAC5D,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,WAAW,CAAC;AAE/E,0CAA0C;AAC1C,MAAM,MAAM,QAAQ,GAAG,kBAAkB,GAAG,YAAY,CAAC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;IAChB,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,QAAQ,CAAC;CACnB;AAED,8BAA8B;AAC9B,MAAM,WAAW,eAAe;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,YAAY,CAAC;CACrB;AAMD,uDAAuD;AACvD,MAAM,WAAW,YAAY;IAC5B,uCAAuC;IACvC,KAAK,EAAE,WAAW,CAAC;IACnB,0DAAwD;IACxD,MAAM,EAAE,YAAY,CAAC;IACrB,0EAA0E;IAC1E,IAAI,EAAE,MAAM,CAAC;CACb;AAED,uCAAuC;AACvC,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,sCAAsC;AACtC,MAAM,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC;AAE5C,kDAAkD;AAClD,eAAO,MAAM,YAAY,EAAE,UAAU,EAAgF,CAAC;AAMtH,wDAAwD;AACxD,MAAM,MAAM,qBAAqB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;AAM5F,+DAA+D;AAC/D,MAAM,WAAW,UAAU;IAC1B,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAC;CACf","sourcesContent":["/**\n * Shared types for the semantic codebase search subsystem.\n */\n\n// ============================================================================\n// Languages\n// ============================================================================\n\n/** Languages supported by tree-sitter AST chunking. */\nexport type TreeSitterLanguage = \"typescript\" | \"tsx\" | \"javascript\" | \"python\" | \"go\" | \"rust\" | \"java\" | \"c\" | \"cpp\";\n\n/** Non-code file types chunked by format-specific rules. */\nexport type TextFileType = \"markdown\" | \"yaml\" | \"json\" | \"toml\" | \"plaintext\";\n\n/** Union of all recognized file types. */\nexport type FileType = TreeSitterLanguage | TextFileType;\n\n// ============================================================================\n// Chunks\n// ============================================================================\n\n/** The kind of code construct a chunk represents. */\nexport type ChunkKind =\n\t| \"function\"\n\t| \"method\"\n\t| \"class\"\n\t| \"interface\"\n\t| \"struct\"\n\t| \"enum\"\n\t| \"impl\"\n\t| \"export\"\n\t| \"type_alias\"\n\t| \"module\"\n\t| \"heading_section\"\n\t| \"top_level_key\"\n\t| \"paragraph\"\n\t| \"file\";\n\n/** A chunk of code or text extracted from a file. */\nexport interface Chunk {\n\t/** Relative file path from project root. */\n\tfilePath: string;\n\t/** 1-indexed start line in the source file. */\n\tstartLine: number;\n\t/** 1-indexed end line (inclusive) in the source file. */\n\tendLine: number;\n\t/** The kind of construct this chunk represents. */\n\tkind: ChunkKind;\n\t/** Symbol name (function name, class name, heading text, etc.). Null for anonymous chunks. */\n\tname: string | null;\n\t/** The raw source text of the chunk. */\n\tcontent: string;\n\t/** Detected file type. */\n\tfileType: FileType;\n}\n\n// ============================================================================\n// Index\n// ============================================================================\n\n/** Configuration for the search index. */\nexport interface IndexConfig {\n\t/** Absolute path to the project root. */\n\tprojectRoot: string;\n\t/** Absolute path to the index database directory. */\n\tindexDir: string;\n\t/** Absolute path to the global memory directory (e.g. ~/.dreb/memory/). */\n\tglobalMemoryDir?: string;\n\t/** Additional directories to include in scans (bypasses gitignore). */\n\tvisibleDirs?: string[];\n\t/** Embedding model name (used to key the embeddings table). */\n\tmodelName: string;\n}\n\n/** Stored metadata for a file in the index. */\nexport interface IndexedFile {\n\tid: number;\n\tfilePath: string;\n\tmtime: number;\n\tfileType: FileType;\n}\n\n/** A stored chunk row from the database. */\nexport interface StoredChunk {\n\tid: number;\n\tfileId: number;\n\tfilePath: string;\n\tstartLine: number;\n\tendLine: number;\n\tkind: ChunkKind;\n\tname: string | null;\n\tcontent: string;\n\tfileType: FileType;\n}\n\n/** A stored embedding row. */\nexport interface StoredEmbedding {\n\tchunkId: number;\n\tmodelName: string;\n\tvector: Float32Array;\n}\n\n// ============================================================================\n// Search Results\n// ============================================================================\n\n/** A single search result with scores and metadata. */\nexport interface SearchResult {\n\t/** The chunk this result refers to. */\n\tchunk: StoredChunk;\n\t/** Individual metric scores (0–1, higher is better). */\n\tscores: MetricScores;\n\t/** Combined rank from POEM (lower is better, 0 = top of Pareto front). */\n\trank: number;\n}\n\n/** Scores from each ranking metric. */\nexport interface MetricScores {\n\tbm25: number;\n\tcosine: number;\n\tpathMatch: number;\n\tsymbolMatch: number;\n\timportGraph: number;\n\tgitRecency: number;\n}\n\n/** Names of the 6 ranking metrics. */\nexport type MetricName = keyof MetricScores;\n\n/** All metric names as an array for iteration. */\nexport const METRIC_NAMES: MetricName[] = [\"bm25\", \"cosine\", \"pathMatch\", \"symbolMatch\", \"importGraph\", \"gitRecency\"];\n\n// ============================================================================\n// Callbacks\n// ============================================================================\n\n/** Progress reporting callback for index operations. */\nexport type IndexProgressCallback = (phase: string, current: number, total: number) => void;\n\n// ============================================================================\n// Import Graph\n// ============================================================================\n\n/** A resolved import edge: source file imports target file. */\nexport interface ImportEdge {\n\t/** Relative path of the importing file. */\n\tsource: string;\n\t/** Relative path of the imported file. */\n\ttarget: string;\n}\n"]}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,uDAAuD;AACvD,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,KAAK,GAAG,YAAY,GAAG,QAAQ,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,GAAG,GAAG,KAAK,CAAC;AAEvH,4DAA4D;AAC5D,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,WAAW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ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,MAAM,CAOzE;AAMD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAEvD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,YAAY,CAE3D;AAMD;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAC1B,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,EAClC,CAAC,EAAE,MAAM,GACP,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAgBtC","sourcesContent":["/**\n * Vector operations for semantic search.\n *\n * Pure JS implementations — no native dependencies or SQLite UDFs needed.\n * Vectors are computed and compared in JS, stored as BLOBs in SQLite.\n */\n\n// ============================================================================\n// Similarity\n// ============================================================================\n\n/**\n * Compute cosine similarity between two normalized vectors.\n *\n * For normalized vectors, cosine similarity is simply the dot product:\n * cos(a, b) = Σ a[i] * b[i]\n *\n * Returns a value in [-1, 1] where 1 = identical, 0 = orthogonal, -1 = opposite.\n */\nexport function cosineSimilarity(a: Float32Array, b: Float32Array): number {\n\tconst len = a.length;\n\tlet dot = 0;\n\tfor (let i = 0; i < len; i++) {\n\t\tdot += a[i] * b[i];\n\t}\n\treturn dot;\n}\n\n// ============================================================================\n// Serialization\n// ============================================================================\n\n/**\n * Pack a Float32Array into a Buffer for SQLite BLOB storage.\n *\n * Creates a copy to ensure the buffer isn't shared with other typed arrays.\n */\nexport function packVector(vector: Float32Array): Buffer {\n\treturn Buffer.from(vector.buffer, vector.byteOffset, vector.byteLength);\n}\n\n/**\n * Unpack a BLOB (Uint8Array from node:sqlite) back to a Float32Array.\n *\n * The returned array shares the underlying buffer with the input for\n * zero-copy performance. Callers should not mutate the input after calling.\n */\nexport function unpackVector(blob: Uint8Array): Float32Array {\n\treturn new Float32Array(blob.buffer, blob.byteOffset, blob.byteLength / 4);\n}\n\n// ============================================================================\n// Top-K Search\n// ============================================================================\n\n/**\n * Find the top-K most similar vectors from a set.\n *\n * Computes cosine similarity between the query vector and every candidate,\n * then returns the K highest-scoring results sorted by descending score.\n *\n * Uses a simple full scan — suitable for the index sizes we expect in a\n * single-project codebase (typically <100K chunks). For millions of vectors,\n * an approximate nearest neighbor index (HNSW, IVF) would be needed.\n */\nexport function topKSimilar(\n\tquery: Float32Array,\n\tvectors: Map<number, Float32Array>,\n\tk: number,\n): Array<{ id: number; score: number }> {\n\tif (k <= 0 || vectors.size === 0) return [];\n\n\t// For small k relative to n, a min-heap would be more efficient.\n\t// For typical codebase sizes (<100K vectors) the difference is negligible,\n\t// and a sorted array is simpler and correct.\n\tconst scored: Array<{ id: number; score: number }> = [];\n\n\tfor (const [id, vector] of vectors) {\n\t\tscored.push({ id, score: cosineSimilarity(query, vector) });\n\t}\n\n\t// Partial sort: only need top-k, but full sort is fine for expected sizes\n\tscored.sort((a, b) => b.score - a.score);\n\n\treturn scored.slice(0, k);\n}\n"]}
1
+ {"version":3,"file":"vector-store.d.ts","sourceRoot":"","sources":["../src/vector-store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,MAAM,CAOzE;AAMD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAEvD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,YAAY,CAE3D;AAMD;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAC1B,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY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AAI,OAAO,CAAC,IAAI,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAE5C,iEAAiE;IACjE,2EAA2E;IAC3E,6CAA6C;IAC7C,MAAM,MAAM,GAAyC,EAAE,CAAC;IAExD,KAAK,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACpC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,0EAA0E;IAC1E,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IAEzC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAAA,CAC1B","sourcesContent":["/**\n * Vector operations for semantic search.\n *\n * Pure JS implementations — no native dependencies or SQLite UDFs needed.\n * Vectors are computed and compared in JS, stored as BLOBs in SQLite.\n */\n\n// ============================================================================\n// Similarity\n// ============================================================================\n\n/**\n * Compute cosine similarity between two normalized vectors.\n *\n * For normalized vectors, cosine similarity is simply the dot product:\n * cos(a, b) = Σ a[i] * b[i]\n *\n * Returns a value in [-1, 1] where 1 = identical, 0 = orthogonal, -1 = opposite.\n */\nexport function cosineSimilarity(a: Float32Array, b: Float32Array): number {\n\tconst len = a.length;\n\tlet dot = 0;\n\tfor (let i = 0; i < len; i++) {\n\t\tdot += a[i] * b[i];\n\t}\n\treturn dot;\n}\n\n// ============================================================================\n// Serialization\n// ============================================================================\n\n/**\n * Pack a Float32Array into a Buffer for SQLite BLOB storage.\n *\n * Creates a copy to ensure the buffer isn't shared with other typed arrays.\n */\nexport function packVector(vector: Float32Array): Buffer {\n\treturn Buffer.from(vector.buffer, vector.byteOffset, vector.byteLength);\n}\n\n/**\n * Unpack a BLOB (Uint8Array from node:sqlite) back to a Float32Array.\n *\n * The returned array shares the underlying buffer with the input for\n * zero-copy performance. Callers should not mutate the input after calling.\n */\nexport function unpackVector(blob: Uint8Array): Float32Array {\n\treturn new Float32Array(blob.buffer, blob.byteOffset, blob.byteLength / 4);\n}\n\n// ============================================================================\n// Top-K Search\n// ============================================================================\n\n/**\n * Find the top-K most similar vectors from a set.\n *\n * Computes cosine similarity between the query vector and every candidate,\n * then returns the K highest-scoring results sorted by descending score.\n *\n * Uses a simple full scan — suitable for the index sizes we expect in a\n * single-project codebase (typically <100K chunks). For millions of vectors,\n * an approximate nearest neighbor index (HNSW, IVF) would be needed.\n */\nexport function topKSimilar(\n\tquery: Float32Array,\n\tvectors: Map<number, Float32Array>,\n\tk: number,\n): Array<{ id: number; score: number }> {\n\tif (k <= 0 || vectors.size === 0) return [];\n\n\t// For small k relative to n, a min-heap would be more efficient.\n\t// For typical codebase sizes (<100K vectors) the difference is negligible,\n\t// and a sorted array is simpler and correct.\n\tconst scored: Array<{ id: number; score: number }> = [];\n\n\tfor (const [id, vector] of vectors) {\n\t\tscored.push({ id, score: cosineSimilarity(query, vector) });\n\t}\n\n\t// Partial sort: only need top-k, but full sort is fine for expected sizes\n\tscored.sort((a, b) => b.score - a.score);\n\n\treturn scored.slice(0, k);\n}\n"]}
1
+ {"version":3,"file":"vector-store.js","sourceRoot":"","sources":["../src/vector-store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+EAA+E;AAC/E,aAAa;AACb,+EAA+E;AAE/E;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,CAAe,EAAE,CAAe;IAChE,MAAM,GAAG,GAAG,CAAC,CAAC,MAAM,CAAC;IACrB,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9B,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,C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ementations — no native dependencies or SQLite UDFs needed.\n * Vectors are computed and compared in JS, stored as BLOBs in SQLite.\n */\n\n// ============================================================================\n// Similarity\n// ============================================================================\n\n/**\n * Compute cosine similarity between two normalized vectors.\n *\n * For normalized vectors, cosine similarity is simply the dot product:\n * cos(a, b) = Σ a[i] * b[i]\n *\n * Returns a value in [-1, 1] where 1 = identical, 0 = orthogonal, -1 = opposite.\n */\nexport function cosineSimilarity(a: Float32Array, b: Float32Array): number {\n\tconst len = a.length;\n\tlet dot = 0;\n\tfor (let i = 0; i < len; i++) {\n\t\tdot += a[i] * b[i];\n\t}\n\treturn dot;\n}\n\n// ============================================================================\n// Serialization\n// ============================================================================\n\n/**\n * Pack a Float32Array into a Buffer for SQLite BLOB storage.\n *\n * Creates a copy to ensure the buffer isn't shared with other typed arrays.\n */\nexport function packVector(vector: Float32Array): Buffer {\n\treturn Buffer.from(vector.buffer, vector.byteOffset, vector.byteLength);\n}\n\n/**\n * Unpack a BLOB (Uint8Array from node:sqlite) back to a Float32Array.\n *\n * The returned array shares the underlying buffer with the input for\n * zero-copy performance. Callers should not mutate the input after calling.\n */\nexport function unpackVector(blob: Uint8Array): Float32Array {\n\treturn new Float32Array(blob.buffer, blob.byteOffset, blob.byteLength / 4);\n}\n\n// ============================================================================\n// Top-K Search\n// ============================================================================\n\n/**\n * Find the top-K most similar vectors from a set.\n *\n * Computes cosine similarity between the query vector and every candidate,\n * then returns the K highest-scoring results sorted by descending score.\n *\n * Uses a simple full scan — suitable for the index sizes we expect in a\n * single-project codebase (typically <100K chunks). For millions of vectors,\n * an approximate nearest neighbor index (HNSW, IVF) would be needed.\n */\nexport function topKSimilar(\n\tquery: Float32Array,\n\tvectors: Map<number, Float32Array>,\n\tk: number,\n): Array<{ id: number; score: number }> {\n\tif (k <= 0 || vectors.size === 0) return [];\n\n\t// For small k relative to n, a min-heap would be more efficient.\n\t// For typical codebase sizes (<100K vectors) the difference is negligible,\n\t// and a sorted array is simpler and correct.\n\tconst scored: Array<{ id: number; score: number }> = [];\n\n\tfor (const [id, vector] of vectors) {\n\t\tscored.push({ id, score: cosineSimilarity(query, vector) });\n\t}\n\n\t// Partial sort: only need top-k, but full sort is fine for expected sizes\n\tscored.sort((a, b) => b.score - a.score);\n\n\treturn scored.slice(0, k);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreb/semantic-search",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
4
4
  "description": "Semantic codebase search engine with embedding-based ranking and MCP server",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -27,8 +27,8 @@
27
27
  ],
28
28
  "scripts": {
29
29
  "clean": "shx rm -rf dist",
30
- "build": "tsgo -p tsconfig.build.json",
31
- "dev": "tsgo -p tsconfig.build.json --watch --preserveWatchOutput",
30
+ "build": "tsc -p tsconfig.build.json",
31
+ "dev": "tsc -p tsconfig.build.json --watch --preserveWatchOutput",
32
32
  "test": "vitest --run",
33
33
  "prepublishOnly": "npm run clean && npm run build"
34
34
  },
@@ -1,3 +1,8 @@
1
+ ---
2
+ name: search
3
+ description: "Semantic codebase search — use for exploring code, finding implementations, and answering questions about any project. Searches using natural language queries, identifier names, or file paths. Returns ranked results using embedding-based similarity, BM25 keyword matching, symbol matching, import graph analysis, and git recency. Use this as the default exploration tool instead of grep when you don't know the exact text to search for."
4
+ ---
5
+
1
6
  # Semantic Codebase Search
2
7
 
3
8
  Use `search` as your **default exploration tool** for understanding code, finding implementations, and answering questions about the codebase. Use `grep` when you already know the exact text or pattern you're looking for.