From efc784915e550fbaf6f8d439d5c631aee85b7212 Mon Sep 17 00:00:00 2001 From: abhigyanpatwari Date: Sun, 11 Jan 2026 06:56:54 +0530 Subject: [PATCH] fixed: S-queries modified to support arrow functions --- src/components/QueryFAB.tsx | 12 +++---- src/components/ToolCallCard.tsx | 9 +++-- src/core/ingestion/tree-sitter-queries.ts | 44 +++++++++++++++++++++++ src/core/llm/tools.ts | 2 +- src/core/llm/types.ts | 38 +++++++++++++------- 5 files changed, 82 insertions(+), 23 deletions(-) diff --git a/src/components/QueryFAB.tsx b/src/components/QueryFAB.tsx index 03a8d84f00..55f7d4c7aa 100644 --- a/src/components/QueryFAB.tsx +++ b/src/components/QueryFAB.tsx @@ -5,23 +5,23 @@ import { useAppState } from '../hooks/useAppState'; const EXAMPLE_QUERIES = [ { label: 'All Functions', - query: `MATCH (n:CodeNode) WHERE n.label = 'Function' RETURN n.id AS id, n.name AS name, n.filePath AS path`, + query: `MATCH (n:Function) RETURN n.id AS id, n.name AS name, n.filePath AS path LIMIT 50`, }, { label: 'All Classes', - query: `MATCH (n:CodeNode) WHERE n.label = 'Class' RETURN n.id AS id, n.name AS name, n.filePath AS path`, + query: `MATCH (n:Class) RETURN n.id AS id, n.name AS name, n.filePath AS path LIMIT 50`, }, { label: 'All Interfaces', - query: `MATCH (n:CodeNode) WHERE n.label = 'Interface' RETURN n.id AS id, n.name AS name, n.filePath AS path`, + query: `MATCH (n:Interface) RETURN n.id AS id, n.name AS name, n.filePath AS path LIMIT 50`, }, { label: 'Function Calls', - query: `MATCH (a:CodeNode)-[r:CodeRelation]->(b:CodeNode) WHERE r.type = 'CALLS' RETURN a.id AS id, a.name AS caller, b.name AS callee LIMIT 50`, + query: `MATCH (a:File)-[r:CodeRelation {type: 'CALLS'}]->(b:Function) RETURN a.id AS id, a.name AS caller, b.name AS callee LIMIT 50`, }, { label: 'Import Dependencies', - query: `MATCH (a:CodeNode)-[r:CodeRelation]->(b:CodeNode) WHERE r.type = 'IMPORTS' RETURN a.id AS id, a.name AS from, b.name AS imports LIMIT 50`, + query: `MATCH (a:File)-[r:CodeRelation {type: 'IMPORTS'}]->(b:File) RETURN a.id AS id, a.name AS from, b.name AS imports LIMIT 50`, }, ]; @@ -203,7 +203,7 @@ export const QueryFAB = () => { value={query} onChange={(e) => setQuery(e.target.value)} onKeyDown={handleKeyDown} - placeholder="MATCH (n:CodeNode) WHERE n.label = 'Function' RETURN n" + placeholder="MATCH (n:Function) RETURN n.name, n.filePath LIMIT 10" rows={3} className=" w-full px-3 py-2.5 diff --git a/src/components/ToolCallCard.tsx b/src/components/ToolCallCard.tsx index eb6debb32e..659a72885b 100644 --- a/src/components/ToolCallCard.tsx +++ b/src/components/ToolCallCard.tsx @@ -161,9 +161,12 @@ export const ToolCallCard = ({ toolCall, defaultExpanded = false }: ToolCallCard return (
{/* Header - always visible */} - +
{/* Expanded content */} {isExpanded && ( diff --git a/src/core/ingestion/tree-sitter-queries.ts b/src/core/ingestion/tree-sitter-queries.ts index c5d0c07197..4eb6686abc 100644 --- a/src/core/ingestion/tree-sitter-queries.ts +++ b/src/core/ingestion/tree-sitter-queries.ts @@ -22,6 +22,28 @@ export const TYPESCRIPT_QUERIES = ` (method_definition name: (property_identifier) @name) @definition.method +(lexical_declaration + (variable_declarator + name: (identifier) @name + value: (arrow_function))) @definition.function + +(lexical_declaration + (variable_declarator + name: (identifier) @name + value: (function_expression))) @definition.function + +(export_statement + declaration: (lexical_declaration + (variable_declarator + name: (identifier) @name + value: (arrow_function)))) @definition.function + +(export_statement + declaration: (lexical_declaration + (variable_declarator + name: (identifier) @name + value: (function_expression)))) @definition.function + (import_statement source: (string) @import.source) @import @@ -44,6 +66,28 @@ export const JAVASCRIPT_QUERIES = ` (method_definition name: (property_identifier) @name) @definition.method +(lexical_declaration + (variable_declarator + name: (identifier) @name + value: (arrow_function))) @definition.function + +(lexical_declaration + (variable_declarator + name: (identifier) @name + value: (function_expression))) @definition.function + +(export_statement + declaration: (lexical_declaration + (variable_declarator + name: (identifier) @name + value: (arrow_function)))) @definition.function + +(export_statement + declaration: (lexical_declaration + (variable_declarator + name: (identifier) @name + value: (function_expression)))) @definition.function + (import_statement source: (string) @import.source) @import diff --git a/src/core/llm/tools.ts b/src/core/llm/tools.ts index c1a90ba926..50922e9ffb 100644 --- a/src/core/llm/tools.ts +++ b/src/core/llm/tools.ts @@ -11,7 +11,7 @@ import { tool } from '@langchain/core/tools'; import { z } from 'zod'; -import { GRAPH_SCHEMA_DESCRIPTION } from './types'; +// Note: GRAPH_SCHEMA_DESCRIPTION from './types' is available if needed for additional context import { WebGPUNotAvailableError, embedText, embeddingToArray, initEmbedder, isEmbedderReady } from '../embeddings/embedder'; /** diff --git a/src/core/llm/types.ts b/src/core/llm/types.ts index 80b4c02e93..c01811933f 100644 --- a/src/core/llm/types.ts +++ b/src/core/llm/types.ts @@ -258,11 +258,15 @@ NODE TABLES: - nodeId: STRING (primary key) - embedding: FLOAT[384] -RELATIONSHIP TABLES: -1. CONTAINS (Folder->Folder, Folder->File) -2. DEFINES (File->Function, File->Class, File->Interface, File->Method, File->CodeElement) -3. IMPORTS (File->File) -4. CALLS (File->Function, File->Method) +RELATIONSHIP TABLE: +CodeRelation - Single table with 'type' property connecting all node tables + - type: STRING (values: CONTAINS, DEFINES, IMPORTS, CALLS) + +Connection patterns: +- CONTAINS: Folder->Folder, Folder->File +- DEFINES: File->Function, File->Class, File->Interface, File->Method, File->CodeElement +- IMPORTS: File->File +- CALLS: File->Function, File->Method, Function->Function, Function->Method QUERY PATTERNS: @@ -270,19 +274,23 @@ QUERY PATTERNS: MATCH (f:Function) RETURN f.name, f.filePath LIMIT 10 2. Find what a file defines: - MATCH (f:File)-[:DEFINES]->(fn:Function) + MATCH (f:File)-[:CodeRelation {type: 'DEFINES'}]->(fn:Function) WHERE f.name = 'utils.ts' RETURN fn.name 3. Find function callers: - MATCH (caller:File)-[:CALLS]->(fn:Function {name: 'myFunction'}) + MATCH (caller:File)-[:CodeRelation {type: 'CALLS'}]->(fn:Function {name: 'myFunction'}) RETURN caller.name, caller.filePath 4. Find imports: - MATCH (f:File {name: 'main.ts'})-[:IMPORTS]->(imported:File) + MATCH (f:File {name: 'main.ts'})-[:CodeRelation {type: 'IMPORTS'}]->(imported:File) RETURN imported.name -5. SEMANTIC SEARCH (embeddings in separate table - MUST JOIN): +5. Find files that import a specific file: + MATCH (f:File)-[:CodeRelation {type: 'IMPORTS'}]->(target:File {name: 'utils.ts'}) + RETURN f.name, f.filePath + +6. SEMANTIC SEARCH (embeddings in separate table - MUST JOIN): CALL QUERY_VECTOR_INDEX('CodeEmbedding', 'code_embedding_idx', $queryVector, 10) YIELD node AS emb, distance WITH emb, distance @@ -291,23 +299,27 @@ QUERY PATTERNS: RETURN n.name, n.filePath, distance ORDER BY distance -6. Search across all code types (use UNION or separate queries): +7. Search across all code types (use UNION or separate queries): MATCH (f:Function) WHERE f.name CONTAINS 'auth' RETURN f.id, f.name, 'Function' AS type UNION ALL MATCH (c:Class) WHERE c.name CONTAINS 'auth' RETURN c.id, c.name, 'Class' AS type -7. Folder structure: - MATCH (parent:Folder)-[:CONTAINS]->(child) +8. Folder structure: + MATCH (parent:Folder)-[:CodeRelation {type: 'CONTAINS'}]->(child) WHERE parent.name = 'src' RETURN child.name, labels(child)[0] AS type +9. Get all connections for a node: + MATCH (f:File {name: 'index.ts'})-[r:CodeRelation]-(m) + RETURN m.name, r.type + TOOLING NOTE (for execute_vector_cypher): - Write Cypher containing {{QUERY_VECTOR}} where the vector should go. - The tool will replace {{QUERY_VECTOR}} with CAST([..] AS FLOAT[384]). NOTES: - Use proper table names: File, Folder, Function, Class, Interface, Method, CodeElement -- Relationship labels are: CONTAINS, DEFINES, IMPORTS, CALLS +- Use CodeRelation with type property: [:CodeRelation {type: 'DEFINES'}] - For vector search, join CodeEmbedding.nodeId to the appropriate table's id - Use LIMIT to avoid returning too many results `;