Understand any codebase instantly. System intelligence for codebases, built for humans and AI.
TypeScript aiai-memoryclaude-codeclicode-analysiscode-mappingcode-memorycodebase-understandingcodexdeveloper-toolsllmopenclawpersistent-memoryprogram-analysissoftware-architecturesystem-intelligencesystem-mapping
feat: tree-sitter AST parsers for Scala/TS, Goal entity, decision-truth linking
Tanner Kocherb24dea09691a
diff --git a/.claude/settings.json b/.claude/settings.jsonindex b6637478..76910122 100644--- a/.claude/settings.json+++ b/.claude/settings.json@@ -10,5 +10,54 @@"IX_ENDPOINT": "http://localhost:8090"}}+ },+ "hooks": {+ "SessionStart": [+ {+ "matcher": "startup|resume|compact",+ "hooks": [+ {+ "type": "command",+ "command": "bash .claude/hooks/session-start.sh",+ "timeout": 10+ }+ ]+ }+ ],+ "PostToolUse": [+ {+ "matcher": "Edit|Write",+ "hooks": [+ {+ "type": "command",+ "command": "bash .claude/hooks/post-edit-ingest.sh",+ "timeout": 30+ }+ ]+ }+ ],+ "PreToolUse": [+ {+ "matcher": "Grep|Glob",+ "hooks": [+ {+ "type": "command",+ "command": "bash .claude/hooks/pre-tool-ix-check.sh",+ "timeout": 5+ }+ ]+ }+ ],+ "Stop": [+ {+ "hooks": [+ {+ "type": "command",+ "command": "bash .claude/hooks/stop-decision-reminder.sh",+ "timeout": 5+ }+ ]+ }+ ]}}diff --git a/.mcp.json b/.mcp.jsonindex 1181fc20..1ad5c55d 100644--- a/.mcp.json+++ b/.mcp.json@@ -5,7 +5,7 @@"command": "npx","args": ["tsx",- "/Users/rileythompson/startprojes/startup/IX-Memory/ix-cli/src/mcp/server.ts"+ "/Users/tkocher/Development/Ix/IX-Memory/ix-cli/src/mcp/server.ts"],"env": {"IX_ENDPOINT": "http://localhost:8090"diff --git a/build.sbt b/build.sbtindex 66410b9a..21817676 100644--- a/build.sbt+++ b/build.sbt@@ -29,8 +29,10 @@ lazy val memoryLayer = (project in file("memory-layer"))// ArangoDB"com.arangodb" % "arangodb-java-driver" % "7.12.0",- // Tree-sitter- "ch.usi.si.seart" % "java-tree-sitter" % "1.12.0",+ // Tree-sitter (bonede/tree-sitter-ng — ARM64 macOS compatible)+ "io.github.bonede" % "tree-sitter" % "0.26.6",+ "io.github.bonede" % "tree-sitter-scala" % "0.24.0",+ "io.github.bonede" % "tree-sitter-typescript" % "0.23.2",// Logging"org.typelevel" %% "log4cats-slf4j" % "2.7.0",diff --git a/memory-layer/src/main/scala/ix/memory/api/DecideRoutes.scala b/memory-layer/src/main/scala/ix/memory/api/DecideRoutes.scalaindex 64dc7d97..f12a01db 100644--- a/memory-layer/src/main/scala/ix/memory/api/DecideRoutes.scala+++ b/memory-layer/src/main/scala/ix/memory/api/DecideRoutes.scala@@ -39,7 +39,15 @@ class DecideRoutes(writeApi: GraphWriteApi) {"rationale" -> Json.fromString(body.rationale),"intent_id" -> body.intentId.fold(Json.Null)(Json.fromString)))- ),+ ) ++ body.intentId.map { truthId =>+ PatchOp.UpsertEdge(+ EdgeId(UUID.randomUUID()),+ nodeId,+ NodeId(UUID.fromString(truthId)),+ EdgePredicate("DECISION_CONSTRAINED_BY_TRUTH"),+ Map.empty+ )+ }.toVector,replaces = Vector.empty,intent = Some(s"Decision: ${body.title}"))diff --git a/memory-layer/src/main/scala/ix/memory/api/GoalRoutes.scala b/memory-layer/src/main/scala/ix/memory/api/GoalRoutes.scalanew file mode 100644index 00000000..4224b840--- /dev/null+++ b/memory-layer/src/main/scala/ix/memory/api/GoalRoutes.scala@@ -0,0 +1,60 @@+package ix.memory.api++import java.time.Instant+import java.util.UUID++import cats.effect.IO+import io.circe.{Decoder, Json}+import io.circe.generic.semiauto.deriveDecoder+import io.circe.syntax._+import org.http4s.HttpRoutes+import org.http4s.circe.CirceEntityCodec._+import org.http4s.dsl.io._++import ix.memory.db.{GraphQueryApi, GraphWriteApi}+import ix.memory.model._++case class GoalRequest(statement: String, parentGoal: Option[String] = None)++object GoalRequest {+ implicit val decoder: Decoder[GoalRequest] = deriveDecoder[GoalRequest]+}++class GoalRoutes(writeApi: GraphWriteApi, queryApi: GraphQueryApi) {++ val routes: HttpRoutes[IO] = HttpRoutes.of[IO] {+ case GET -> Root / "v1" / "goal" =>+ (for {+ goals <- queryApi.findNodesByKind(NodeKind.Goal)+ resp <- Ok(goals.asJson)+ } yield resp).handleErrorWith(ErrorHandler.handle(_))++ case req @ POST -> Root / "v1" / "goal" =>+ (for {+ body <- req.as[GoalRequest]+ nodeId = NodeId(UUID.randomUUID())+ patch = GraphPatch(+ patchId = PatchId(UUID.randomUUID()),+ actor = "ix/api",+ timestamp = Instant.now(),+ source = PatchSource("api:///v1/goal", None, "user-goal", SourceType.Human),+ baseRev = Rev(0L),+ ops = Vector(+ PatchOp.UpsertNode(nodeId, NodeKind.Goal, body.statement, Map(+ "statement" -> Json.fromString(body.statement),+ "status" -> Json.fromString("active"),+ "parent_goal" -> body.parentGoal.fold(Json.Null)(Json.fromString)+ ))+ ),+ replaces = Vector.empty,+ intent = Some(s"Goal: ${body.statement}")+ )+ result <- writeApi.commitPatch(patch)+ resp <- Ok(Json.obj(+ "status" -> result.status.toString.asJson,+ "nodeId" -> nodeId.value.toString.asJson,+ "rev" -> result.newRev.value.asJson+ ))+ } yield resp).handleErrorWith(ErrorHandler.handle(_))+ }+}diff --git a/memory-layer/src/main/scala/ix/memory/api/Routes.scala b/memory-layer/src/main/scala/ix/memory/api/Routes.scalaindex 0ca20508..76230b07 100644--- a/memory-layer/src/main/scala/ix/memory/api/Routes.scala+++ b/memory-layer/src/main/scala/ix/memory/api/Routes.scala@@ -38,6 +38,7 @@ object Routes {val decideRoutes = new DecideRoutes(writeApi).routesval searchRoutes = new SearchRoutes(queryApi).routesval truthRoutes = new TruthRoutes(writeApi, queryApi).routes+ val goalRoutes = new GoalRoutes(writeApi, queryApi).routesval patchRoutes = new PatchRoutes(client).routesval decisionListRoutes = new DecisionRoutes(queryApi).routesval expandRoutes = new ExpandRoutes(queryApi).routes@@ -48,6 +49,6 @@ object Routes {health <+> contextRoutes <+> ingestionRoutes <+> entityRoutes <+>diffRoutes <+> conflictRoutes <+> decideRoutes <+> searchRoutes <+>truthRoutes <+> patchRoutes <+> decisionListRoutes <+> expandRoutes <+>- statsRoutes <+> patchCommitRoutes <+> listRoutes+ statsRoutes <+> patchCommitRoutes <+> listRoutes <+> goalRoutes}}diff --git a/memory-layer/src/main/scala/ix/memory/ingestion/ParserRouter.scala b/memory-layer/src/main/scala/ix/memory/ingestion/ParserRouter.scalaindex a5d24632..8fc25284 100644--- a/memory-layer/src/main/scala/ix/memory/ingestion/ParserRouter.scala+++ b/memory-layer/src/main/scala/ix/memory/ingestion/ParserRouter.scala@@ -1,6 +1,6 @@package ix.memory.ingestion-import ix.memory.ingestion.parsers.{ConfigParser, MarkdownParser, ScalaParser, TreeSitterPythonParser, TypeScriptParser}+import ix.memory.ingestion.parsers.{ConfigParser, MarkdownParser, TreeSitterPythonParser, TreeSitterScalaParser, TreeSitterTypeScriptParser}/*** Routes file paths to the appropriate language parser.@@ -9,10 +9,10 @@ import ix.memory.ingestion.parsers.{ConfigParser, MarkdownParser, ScalaParser, T*/class ParserRouter {private val pythonParser = new TreeSitterPythonParser()- private val tsParser = new TypeScriptParser()+ private val tsParser = new TreeSitterTypeScriptParser()private val configParser = new ConfigParser()private val markdownParser = new MarkdownParser()- private val scalaParser = new ScalaParser()+ private val scalaParser = new TreeSitterScalaParser()def parserFor(filePath: String): Option[Parser] = {if (filePath.endsWith(".py")) Some(pythonParser)diff --git a/memory-layer/src/main/scala/ix/memory/ingestion/parsers/TreeSitterPythonParser.scala b/memory-layer/src/main/scala/ix/memory/ingestion/parsers/TreeSitterPythonParser.scalaindex deb06bdd..3a2f900a 100644--- a/memory-layer/src/main/scala/ix/memory/ingestion/parsers/TreeSitterPythonParser.scala+++ b/memory-layer/src/main/scala/ix/memory/ingestion/parsers/TreeSitterPythonParser.scala@@ -23,40 +23,11 @@ class TreeSitterPythonParser extends Parser {* @param source the full source code as a string* @return ParseResult with entities and relationships*/- def parse(fileName: String, source: String): ParseResult = {- // Try tree-sitter first, fall back to regex- tryTreeSitter(fileName, source).getOrElse(regexParse(fileName, source))- }-- // ---------------------------------------------------------------------------- // Tree-sitter JNI attempt- // ----------------------------------------------------------------------------- private def tryTreeSitter(fileName: String, source: String): Option[ParseResult] = {- try {- val langClass = Class.forName("ch.usi.si.seart.treesitter.Language")- val pythonLang = langClass.getMethod("valueOf", classOf[String]).invoke(null, "PYTHON")-- val parserClass = Class.forName("ch.usi.si.seart.treesitter.Parser")- val parser = parserClass.getMethod("getFor", langClass).invoke(null, pythonLang)-- val tree = parserClass.getMethod("parse", classOf[String]).invoke(parser, source)- val treeClass = Class.forName("ch.usi.si.seart.treesitter.Tree")- val root = treeClass.getMethod("getRootNode").invoke(tree)-- // If we get here, tree-sitter loaded successfully- // We would walk the AST here, but for now this path is not reached- // on platforms where the JNI library is unavailable.- parserClass.getMethod("close").invoke(parser)- treeClass.getMethod("close").invoke(tree)- None // TODO: implement full tree-sitter AST walking when JNI works- } catch {- case _: Throwable => None // Catches both Exception and Error (e.g. UnsatisfiedLinkError)- }- }+ def parse(fileName: String, source: String): ParseResult =+ regexParse(fileName, source)// ---------------------------------------------------------------------------- // Regex-based fallback parser+ // Regex-based parser (tree-sitter-python grammar not in deps)// ---------------------------------------------------------------------------private val ClassPattern: Regex = """^class\s+(\w+)""".rdiff --git a/memory-layer/src/main/scala/ix/memory/ingestion/parsers/TreeSitterScalaParser.scala b/memory-layer/src/main/scala/ix/memory/ingestion/parsers/TreeSitterScalaParser.scalanew file mode 100644index 00000000..09693c7a--- /dev/null+++ b/memory-layer/src/main/scala/ix/memory/ingestion/parsers/TreeSitterScalaParser.scala@@ -0,0 +1,350 @@+package ix.memory.ingestion.parsers++import ix.memory.ingestion.{Fingerprint, Parser, ParseResult, ParsedEntity, ParsedRelationship}+import ix.memory.model.NodeKind+import io.circe.Json+import org.treesitter.{TSNode, TreeSitterScala}++import scala.util.matching.Regex++/**+ * Tree-sitter AST-based Scala parser with regex fallback.+ * Produces the same ParseResult shape as the original regex ScalaParser.+ */+class TreeSitterScalaParser extends Parser {++ private val regexFallback = new ScalaParser()++ def parse(fileName: String, source: String): ParseResult = {+ try treeSitterParse(fileName, source)+ catch { case _: Throwable => regexFallback.parse(fileName, source) }+ }++ private def treeSitterParse(fileName: String, source: String): ParseResult = {+ TreeSitterUtils.withParse(new TreeSitterScala(), source) { root =>+ val ctx = new ScalaExtractionContext(fileName, source, root)+ ctx.result()+ }+ }++ // -------------------------------------------------------------------------+ // Extraction context — accumulates entities and relationships+ // -------------------------------------------------------------------------++ private class ScalaExtractionContext(+ fileName: String,+ source: String,+ root: TSNode+ ) {+ import TreeSitterUtils._++ var entities = Vector.empty[ParsedEntity]+ var relationships = Vector.empty[ParsedRelationship]++ // Initialize with file entity+ entities = entities :+ ParsedEntity(+ name = fileName,+ kind = NodeKind.File,+ attrs = Map("language" -> Json.fromString("scala")),+ lineStart = 1,+ lineEnd = source.split("\n", -1).length+ )++ // Walk the root+ walkChildren(root, enclosing = None)++ def result(): ParseResult = ParseResult(entities, relationships)++ private def walkChildren(node: TSNode, enclosing: Option[String]): Unit = {+ for (child <- namedChildren(node)) {+ walkNode(child, enclosing)+ }+ }++ private def walkNode(node: TSNode, enclosing: Option[String]): Unit = {+ node.getType() match {+ case "object_definition" =>+ handleTypeDefinition(node, enclosing, NodeKind.Object, "object")+ case "class_definition" =>+ val isCaseClass = hasCaseModifier(node)+ val scalaKind = if (isCaseClass) "case_class" else "class"+ handleTypeDefinition(node, enclosing, NodeKind.Class, scalaKind)+ case "trait_definition" =>+ handleTypeDefinition(node, enclosing, NodeKind.Trait, "trait")+ case "function_definition" =>+ handleFunctionDefinition(node, enclosing)+ case "import_declaration" =>+ handleImport(node)+ case "template_body" =>+ walkChildren(node, enclosing)+ case "package_clause" =>+ // recurse into package body+ walkChildren(node, enclosing)+ case _ =>+ // Recurse into other nodes to catch nested definitions+ walkChildren(node, enclosing)+ }+ }++ private def handleTypeDefinition(+ node: TSNode,+ enclosing: Option[String],+ kind: NodeKind,+ scalaKind: String+ ): Unit = {+ val nameOpt = extractName(node, source)+ nameOpt.foreach { name =>+ val start = lineStart(node)+ val end = lineEnd(node)+ val sig = extractTypeSignature(node)+ val bodyText = nodeText(node, source)+ val fp = Fingerprint.compute(sig, bodyText)+ val vis = extractVisibility(node)++ entities = entities :+ ParsedEntity(+ name = name,+ kind = kind,+ attrs = Map(+ "scala_kind" -> Json.fromString(scalaKind),+ "language" -> Json.fromString("scala"),+ "signature" -> Json.fromString(sig),+ "visibility" -> Json.fromString(vis)+ ),+ lineStart = start,+ lineEnd = end,+ contentFingerprint = Some(fp)+ )++ // CONTAINS edge+ val containsSrc = enclosing.getOrElse(fileName)+ relationships = relationships :+ ParsedRelationship(containsSrc, name, "CONTAINS")++ // EXTENDS edge+ findChild(node, "extends_clause").foreach { extendsNode =>+ // First type in extends clause is the parent+ val types = collectDescendants(extendsNode, n =>+ n.getType() == "type_identifier" || n.getType() == "identifier"+ )+ types.headOption.foreach { typeNode =>+ val parentName = nodeText(typeNode, source)+ if (parentName.nonEmpty && parentName.head.isUpper) {+ relationships = relationships :+ ParsedRelationship(name, parentName, "EXTENDS")+ }+ }+ }++ // Recurse into template_body+ findChild(node, "template_body").orElse(findChild(node, "body")).foreach { body =>+ walkChildren(body, Some(name))+ }+ }+ }++ private def handleFunctionDefinition(node: TSNode, enclosing: Option[String]): Unit = {+ val nameOpt = extractName(node, source)+ nameOpt.foreach { funcName =>+ val start = lineStart(node)+ val end = lineEnd(node)++ val (kind, containsSrc) = enclosing match {+ case Some(typeName) => (NodeKind.Method, typeName)+ case None => (NodeKind.Function, fileName)+ }++ val sig = extractFunctionSignature(node)+ val vis = extractVisibility(node)+ val bodyText = nodeText(node, source)+ val fp = Fingerprint.compute(sig, bodyText)++ entities = entities :+ ParsedEntity(+ name = funcName,+ kind = kind,+ attrs = Map(+ "language" -> Json.fromString("scala"),+ "summary" -> Json.fromString(sig),+ "signature" -> Json.fromString(sig),+ "visibility" -> Json.fromString(vis)+ ),+ lineStart = start,+ lineEnd = end,+ contentFingerprint = Some(fp)+ )++ relationships = relationships :+ ParsedRelationship(containsSrc, funcName, "CONTAINS")++ // Extract CALLS from body+ fieldChild(node, "body").foreach { body =>+ extractCalls(body, funcName, enclosing.getOrElse(""))+ }++ // Extract REFERENCES from signature types+ extractSignatureRefs(node, funcName, enclosing.getOrElse(""))+ }+ }++ private def extractCalls(bodyNode: TSNode, callerName: String, enclosingTypeName: String): Unit = {+ val seen = scala.collection.mutable.Set.empty[String]+ val refSeen = scala.collection.mutable.Set.empty[String]++ val callExprs = collectDescendants(bodyNode, _.getType() == "call_expression")+ for (callExpr <- callExprs) {+ // Scala grammar: call_expression first named child is the function+ val funcNodeOpt = fieldChild(callExpr, "function")+ .orElse(if (callExpr.getNamedChildCount() > 0) Some(callExpr.getNamedChild(0)) else None)++ funcNodeOpt.foreach { funcNode =>+ val callee = resolveScalaCallee(funcNode)+ callee.foreach { name =>+ if (name != callerName && !ScalaBuiltins.contains(name) &&+ !seen.contains(name) && name.nonEmpty && name.head.isLower) {+ seen += name+ relationships = relationships :+ ParsedRelationship(callerName, name, "CALLS")+ }+ }+ }+ }++ // Extract qualified REFERENCES (e.g., NodeKind.File, SourceType.Code)+ // Scala tree-sitter grammar: field_expression has plain identifier children+ // (first child = object, third child = field, with "." in between)+ val fieldExprs = collectDescendants(bodyNode, _.getType() == "field_expression")+ for (fe <- fieldExprs) {+ // Try named field first, then fall back to first named child as qualifier+ val objNode = fieldChild(fe, "object")+ .orElse(fieldChild(fe, "qualifier"))+ .orElse {+ val named = namedChildren(fe)+ named.headOption.filter(_.getType() == "identifier")+ }+ objNode.foreach { on =>+ if (on.getType() == "identifier") {+ val qualifier = nodeText(on, source)+ if (qualifier.nonEmpty && qualifier.head.isUpper &&+ !ScalaBuiltinTypes.contains(qualifier) && !ScalaBuiltins.contains(qualifier) &&+ !refSeen.contains(qualifier) && qualifier != callerName &&+ qualifier != enclosingTypeName) {+ refSeen += qualifier+ relationships = relationships :+ ParsedRelationship(callerName, qualifier, "REFERENCES")+ }+ }+ }+ }+ }++ private def resolveScalaCallee(funcNode: TSNode): Option[String] = {+ funcNode.getType() match {+ case "identifier" =>+ Some(nodeText(funcNode, source))+ case "field_expression" =>+ // Scala field_expression: children are [object, ".", field]+ // Last named child is the field/method name+ val named = namedChildren(funcNode)+ named.lastOption.map(n => nodeText(n, source))+ case "call_expression" =>+ // Chained calls — recurse+ val inner = if (funcNode.getNamedChildCount() > 0) Some(funcNode.getNamedChild(0)) else None+ inner.flatMap(resolveScalaCallee)+ case _ => None+ }+ }++ private def extractSignatureRefs(node: TSNode, funcName: String, enclosingTypeName: String): Unit = {+ // Use regex on the signature text for type references — pragmatic hybrid approach+ val sig = extractFunctionSignature(node)+ val TypeRefPattern: Regex = """\b([A-Z]\w+)""".r+ val refs = TypeRefPattern.findAllMatchIn(sig).map(_.group(1)).toSet+ for (ref <- refs) {+ if (!ScalaBuiltinTypes.contains(ref) && ref != funcName &&+ ref != enclosingTypeName && ref != fileName) {+ relationships = relationships :+ ParsedRelationship(funcName, ref, "REFERENCES")+ }+ }+ }++ private def handleImport(node: TSNode): Unit = {+ val importText = nodeText(node, source)+ .stripPrefix("import ")+ .trim++ val moduleName = if (importText.contains("{")) {+ importText.substring(0, importText.indexOf('{')).stripSuffix(".").trim+ } else {+ importText+ }++ if (moduleName.nonEmpty && !entities.exists(e => e.name == moduleName && e.kind == NodeKind.Module)) {+ entities = entities :+ ParsedEntity(+ name = moduleName,+ kind = NodeKind.Module,+ attrs = Map.empty,+ lineStart = lineStart(node),+ lineEnd = lineEnd(node)+ )+ }+ if (moduleName.nonEmpty) {+ relationships = relationships :+ ParsedRelationship(fileName, moduleName, "IMPORTS")+ }+ }++ // --- Helpers ---++ private def hasCaseModifier(node: TSNode): Boolean = {+ // Check for "case" modifier in the node text before the keyword+ val text = nodeText(node, source)+ text.trim.startsWith("case ") || text.contains(" case class") ||+ // Check modifiers children+ allChildren(node).exists { child =>+ child.getType() == "case" ||+ (child.getType() == "modifiers" && nodeText(child, source).contains("case"))+ }+ }++ private def extractTypeSignature(node: TSNode): String = {+ val text = nodeText(node, source)+ val firstLine = text.split("\n").head+ firstLine.replaceAll("""\s*\{\s*$""", "").trim.take(120)+ }++ private def extractFunctionSignature(node: TSNode): String = {+ val text = nodeText(node, source)+ val sig = text.split("\n").head+ .replaceAll("""\s*=\s*\{?\s*$""", "")+ .replaceAll("""\s*\{\s*$""", "")+ .trim+ sig.take(120)+ }++ private def extractVisibility(node: TSNode): String = {+ val text = nodeText(node, source).trim+ val withoutOverride = text.replaceFirst("""^\s*override\s+""", "").trim+ if (withoutOverride.startsWith("private")) "private"+ else if (withoutOverride.startsWith("protected")) "protected"+ else "public"+ }+ }++ // --- Shared constants (reused from ScalaParser) ---++ private val ScalaBuiltinTypes: Set[String] = Set(+ "String", "Int", "Long", "Double", "Float", "Boolean", "Unit", "Any", "AnyRef", "AnyVal",+ "Nothing", "Null", "Option", "List", "Map", "Set", "Vector", "Seq", "Array", "Future",+ "IO", "Either", "Try", "Some", "None", "Right", "Left", "Success", "Failure"+ )++ private val ScalaBuiltins: Set[String] = Set(+ "println", "print", "require", "assert", "assume",+ "Some", "None", "Option", "List", "Map", "Set", "Vector",+ "Right", "Left", "Try", "Success", "Failure",+ "Future", "IO", "pure", "flatMap", "map", "filter",+ "foreach", "fold", "foldLeft", "foldRight",+ "toString", "hashCode", "equals", "getClass",+ "apply", "unapply", "copy", "andThen", "compose",+ "getOrElse", "orElse", "contains", "exists", "forall",+ "collect", "traverse", "sequence", "attempt", "handleErrorWith",+ "raiseError", "blocking", "delay", "suspend", "async",+ "mkString", "toList", "toVector", "toSet", "toMap",+ "head", "tail", "size", "length", "isEmpty", "nonEmpty",+ "take", "drop", "slice", "zip", "zipWithIndex",+ "sortBy", "groupBy", "distinct", "flatten"+ )+}diff --git a/memory-layer/src/main/scala/ix/memory/ingestion/parsers/TreeSitterTypeScriptParser.scala b/memory-layer/src/main/scala/ix/memory/ingestion/parsers/TreeSitterTypeScriptParser.scalanew file mode 100644index 00000000..69cdac18--- /dev/null+++ b/memory-layer/src/main/scala/ix/memory/ingestion/parsers/TreeSitterTypeScriptParser.scala@@ -0,0 +1,531 @@+package ix.memory.ingestion.parsers++import ix.memory.ingestion.{Fingerprint, Parser, ParseResult, ParsedEntity, ParsedRelationship}+import ix.memory.model.NodeKind+import io.circe.Json+import org.treesitter.{TSNode, TreeSitterTypescript}++/**+ * Tree-sitter AST-based TypeScript parser with regex fallback.+ * Produces the same ParseResult shape as the original regex TypeScriptParser.+ */+class TreeSitterTypeScriptParser extends Parser {++ private val regexFallback = new TypeScriptParser()++ def parse(fileName: String, source: String): ParseResult = {+ try treeSitterParse(fileName, source)+ catch { case _: Throwable => regexFallback.parse(fileName, source) }+ }++ private def treeSitterParse(fileName: String, source: String): ParseResult = {+ TreeSitterUtils.withParse(new TreeSitterTypescript(), source) { root =>+ val ctx = new TSExtractionContext(fileName, source, root)+ ctx.result()+ }+ }++ // -------------------------------------------------------------------------+ // Extraction context+ // -------------------------------------------------------------------------++ private class TSExtractionContext(+ fileName: String,+ source: String,+ root: TSNode+ ) {+ import TreeSitterUtils._++ var entities = Vector.empty[ParsedEntity]+ var relationships = Vector.empty[ParsedRelationship]++ private val lines = source.split("\n", -1)++ // Initialize with file entity+ entities = entities :+ ParsedEntity(+ name = fileName,+ kind = NodeKind.File,+ attrs = Map("language" -> Json.fromString("typescript")),+ lineStart = 1,+ lineEnd = lines.length+ )++ // Walk the program+ walkProgram(root)++ def result(): ParseResult = ParseResult(entities, relationships)++ private def walkProgram(node: TSNode): Unit = {+ for (child <- namedChildren(node)) {+ walkTopLevel(child, exported = false)+ }+ }++ private def walkTopLevel(node: TSNode, exported: Boolean): Unit = {+ node.getType() match {+ case "export_statement" =>+ // The actual declaration is a child+ for (child <- namedChildren(node)) {+ walkTopLevel(child, exported = true)+ }++ case "class_declaration" | "abstract_class_declaration" =>+ handleClassDeclaration(node, exported)++ case "function_declaration" =>+ handleFunctionDeclaration(node, exported)++ case "lexical_declaration" | "variable_declaration" =>+ handleVariableDeclaration(node, exported)++ case "interface_declaration" =>+ handleInterfaceDeclaration(node, exported)++ case "type_alias_declaration" =>+ handleTypeAliasDeclaration(node, exported)++ case "import_statement" =>+ handleImport(node)++ case "expression_statement" =>+ // File-level code — extract CALLS+ extractFileLevelCalls(node)++ case "enum_declaration" =>+ handleEnumDeclaration(node, exported)++ case _ =>+ // Ignore other top-level nodes+ }+ }++ // --- Class handling ---++ private def handleClassDeclaration(node: TSNode, exported: Boolean): Unit = {+ val nameOpt = extractName(node, source)+ nameOpt.foreach { className =>+ val start = lineStart(node)+ val end = lineEnd(node)+ val sig = extractFirstLine(node).replaceAll("""\s*\{\s*$""", "").trim.take(120)+ val bodyText = nodeText(node, source)+ val fp = Fingerprint.compute(sig, bodyText)++ entities = entities :+ ParsedEntity(+ name = className,+ kind = NodeKind.Class,+ attrs = Map(+ "language" -> Json.fromString("typescript"),+ "exported" -> Json.fromBoolean(exported)+ ),+ lineStart = start,+ lineEnd = end,+ contentFingerprint = Some(fp)+ )+ relationships = relationships :+ ParsedRelationship(fileName, className, "CONTAINS")++ // Extract methods from class body+ findChild(node, "class_body").foreach { body =>+ extractMethods(body, className)+ }+ }+ }++ private def extractMethods(classBody: TSNode, className: String): Unit = {+ for (child <- namedChildren(classBody)) {+ child.getType() match {+ case "method_definition" =>+ handleMethodDefinition(child, className)+ case "public_field_definition" | "property_definition" =>+ // Skip property definitions+ case _ =>+ // Skip other class body members+ }+ }+ }++ private def handleMethodDefinition(node: TSNode, className: String): Unit = {+ val nameOpt = extractName(node, source)+ nameOpt.foreach { methodName =>+ // Skip constructor+ if (methodName != "constructor" && !TypeScriptKeywords.contains(methodName)) {+ val start = lineStart(node)+ val end = lineEnd(node)+ val summary = extractFirstLine(node).trim.take(120)+ val vis = extractVisibility(node)+ val bodyText = nodeText(node, source)+ val fp = Fingerprint.compute(summary, bodyText)++ entities = entities :+ ParsedEntity(+ name = methodName,+ kind = NodeKind.Method,+ attrs = Map(+ "language" -> Json.fromString("typescript"),+ "summary" -> Json.fromString(summary),+ "signature" -> Json.fromString(summary),+ "visibility" -> Json.fromString(vis)+ ),+ lineStart = start,+ lineEnd = end,+ contentFingerprint = Some(fp)+ )+ relationships = relationships :+ ParsedRelationship(className, methodName, "CONTAINS")++ // Extract calls from method body+ fieldChild(node, "body").foreach { body =>+ extractCallsFromBody(body, methodName)+ }+ }+ }+ }++ // --- Function handling ---++ private def handleFunctionDeclaration(node: TSNode, exported: Boolean): Unit = {+ val nameOpt = extractName(node, source)+ nameOpt.foreach { funcName =>+ val start = lineStart(node)+ val end = lineEnd(node)+ val summary = extractFirstLine(node).trim.take(120)+ val bodyText = nodeText(node, source)+ val fp = Fingerprint.compute(summary, bodyText)++ entities = entities :+ ParsedEntity(+ name = funcName,+ kind = NodeKind.Function,+ attrs = Map(+ "language" -> Json.fromString("typescript"),+ "summary" -> Json.fromString(summary),+ "signature" -> Json.fromString(summary),+ "visibility" -> Json.fromString("public"),+ "exported" -> Json.fromBoolean(exported)+ ),+ lineStart = start,+ lineEnd = end,+ contentFingerprint = Some(fp)+ )+ relationships = relationships :+ ParsedRelationship(fileName, funcName, "CONTAINS")++ // Extract calls from function body+ fieldChild(node, "body").foreach { body =>+ extractCallsFromBody(body, funcName)+ }+ }+ }++ // --- Variable/arrow function handling ---++ private def handleVariableDeclaration(node: TSNode, exported: Boolean): Unit = {+ for (declarator <- childrenOfType(node, "variable_declarator")) {+ val nameOpt = extractName(declarator, source)+ nameOpt.foreach { varName =>+ // Check if the value is an arrow function or function expression+ fieldChild(declarator, "value").foreach { value =>+ val isFunc = value.getType() == "arrow_function" ||+ value.getType() == "function" ||+ value.getType() == "function_expression"+ if (isFunc && !entities.exists(e => e.name == varName && e.kind == NodeKind.Function)) {+ val start = lineStart(node)+ val end = lineEnd(node)+ val summary = extractFirstLine(node).trim.take(120)+ val bodyText = nodeText(node, source)+ val fp = Fingerprint.compute(summary, bodyText)++ entities = entities :+ ParsedEntity(+ name = varName,+ kind = NodeKind.Function,+ attrs = Map(+ "language" -> Json.fromString("typescript"),+ "summary" -> Json.fromString(summary),+ "signature" -> Json.fromString(summary),+ "visibility" -> Json.fromString("public"),+ "exported" -> Json.fromBoolean(exported)+ ),+ lineStart = start,+ lineEnd = end,+ contentFingerprint = Some(fp)+ )+ relationships = relationships :+ ParsedRelationship(fileName, varName, "CONTAINS")++ // Extract calls from function body+ fieldChild(value, "body").foreach { body =>+ extractCallsFromBody(body, varName)+ }+ }+ }+ }+ }+ }++ // --- Interface handling ---++ private def handleInterfaceDeclaration(node: TSNode, exported: Boolean): Unit = {+ val nameOpt = extractName(node, source)+ nameOpt.foreach { ifaceName =>+ if (!entities.exists(e => e.name == ifaceName && e.kind == NodeKind.Interface)) {+ val start = lineStart(node)+ val end = lineEnd(node)+ val sig = extractFirstLine(node).replaceAll("""\s*\{\s*$""", "").trim.take(120)+ val bodyText = nodeText(node, source)+ val fp = Fingerprint.compute(sig, bodyText)++ entities = entities :+ ParsedEntity(+ name = ifaceName,+ kind = NodeKind.Interface,+ attrs = Map(+ "language" -> Json.fromString("typescript"),+ "ts_kind" -> Json.fromString("interface"),+ "exported" -> Json.fromBoolean(exported)+ ),+ lineStart = start,+ lineEnd = end,+ contentFingerprint = Some(fp)+ )+ relationships = relationships :+ ParsedRelationship(fileName, ifaceName, "CONTAINS")+ }+ }+ }++ // --- Type alias handling ---++ private def handleTypeAliasDeclaration(node: TSNode, exported: Boolean): Unit = {+ val nameOpt = extractName(node, source)+ nameOpt.foreach { typeName =>+ val start = lineStart(node)+ val end = lineEnd(node)+ val text = nodeText(node, source).trim+ val fp = Fingerprint.compute(text.take(120), text)++ entities = entities :+ ParsedEntity(+ name = typeName,+ kind = NodeKind.Class,+ attrs = Map(+ "language" -> Json.fromString("typescript"),+ "ts_kind" -> Json.fromString("type_alias"),+ "exported" -> Json.fromBoolean(exported)+ ),+ lineStart = start,+ lineEnd = end,+ contentFingerprint = Some(fp)+ )+ relationships = relationships :+ ParsedRelationship(fileName, typeName, "CONTAINS")+ }+ }++ // --- Enum handling ---++ private def handleEnumDeclaration(node: TSNode, exported: Boolean): Unit = {+ val nameOpt = extractName(node, source)+ nameOpt.foreach { enumName =>+ val start = lineStart(node)+ val end = lineEnd(node)+ val bodyText = nodeText(node, source)+ val fp = Fingerprint.compute(extractFirstLine(node).trim.take(120), bodyText)++ entities = entities :+ ParsedEntity(+ name = enumName,+ kind = NodeKind.Class,+ attrs = Map(+ "language" -> Json.fromString("typescript"),+ "ts_kind" -> Json.fromString("enum"),+ "exported" -> Json.fromBoolean(exported)+ ),+ lineStart = start,+ lineEnd = end,+ contentFingerprint = Some(fp)+ )+ relationships = relationships :+ ParsedRelationship(fileName, enumName, "CONTAINS")+ }+ }++ // --- Import handling ---++ private def handleImport(node: TSNode): Unit = {+ // Extract module path from the source/string child+ val moduleOpt = findChild(node, "string").map(n => nodeText(n, source))+ .map(_.stripPrefix("\"").stripSuffix("\"").stripPrefix("'").stripSuffix("'"))++ moduleOpt.foreach { moduleName =>+ if (!entities.exists(e => e.name == moduleName && e.kind == NodeKind.Module)) {+ entities = entities :+ ParsedEntity(+ name = moduleName,+ kind = NodeKind.Module,+ attrs = Map.empty,+ lineStart = lineStart(node),+ lineEnd = lineEnd(node)+ )+ }+ relationships = relationships :+ ParsedRelationship(fileName, moduleName, "IMPORTS")++ // Extract named imports+ findChild(node, "import_clause").foreach { clause =>+ // Default import: import Foo from "mod"+ findChild(clause, "identifier").foreach { id =>+ val name = nodeText(id, source)+ if (name.nonEmpty && !relationships.exists(r =>+ r.srcName == fileName && r.dstName == name && r.predicate == "IMPORTS")) {+ relationships = relationships :+ ParsedRelationship(fileName, name, "IMPORTS")+ }+ }++ // Named imports: import { a, b as c } from "mod"+ findChild(clause, "named_imports").foreach { namedImports =>+ for (spec <- childrenOfType(namedImports, "import_specifier")) {+ // Use alias if present, otherwise use name+ val alias = fieldChild(spec, "alias").map(n => nodeText(n, source))+ val importName = alias.orElse(extractName(spec, source))+ importName.foreach { name =>+ if (!relationships.exists(r =>+ r.srcName == fileName && r.dstName == name && r.predicate == "IMPORTS")) {+ relationships = relationships :+ ParsedRelationship(fileName, name, "IMPORTS")+ }+ }+ }+ }++ // Namespace import: import * as foo from "mod"+ findChild(clause, "namespace_import").foreach { nsImport =>+ findChild(nsImport, "identifier").foreach { id =>+ val name = nodeText(id, source)+ if (name.nonEmpty && !relationships.exists(r =>+ r.srcName == fileName && r.dstName == name && r.predicate == "IMPORTS")) {+ relationships = relationships :+ ParsedRelationship(fileName, name, "IMPORTS")+ }+ }+ }+ }+ }++ // Handle side-effect imports (no import clause, just `import "mod"`)+ if (findChild(node, "import_clause").isEmpty) {+ findChild(node, "string").foreach { strNode =>+ val moduleName = nodeText(strNode, source)+ .stripPrefix("\"").stripSuffix("\"")+ .stripPrefix("'").stripSuffix("'")+ if (moduleName.nonEmpty) {+ if (!entities.exists(e => e.name == moduleName && e.kind == NodeKind.Module)) {+ entities = entities :+ ParsedEntity(+ name = moduleName,+ kind = NodeKind.Module,+ attrs = Map.empty,+ lineStart = lineStart(node),+ lineEnd = lineEnd(node)+ )+ }+ if (!relationships.exists(r => r.dstName == moduleName && r.predicate == "IMPORTS")) {+ relationships = relationships :+ ParsedRelationship(fileName, moduleName, "IMPORTS")+ }+ }+ }+ }+ }++ // --- CALLS extraction ---++ private def extractCallsFromBody(bodyNode: TSNode, callerName: String): Unit = {+ val seen = scala.collection.mutable.Set.empty[String]+ val callExprs = collectDescendants(bodyNode, _.getType() == "call_expression")++ for (callExpr <- callExprs) {+ fieldChild(callExpr, "function").foreach { funcNode =>+ val callee = resolveCalleeName(funcNode)+ callee.foreach { name =>+ if (name != callerName && !TypeScriptBuiltins.contains(name) &&+ !TypeScriptKeywords.contains(name) && !seen.contains(name) && name != fileName) {+ seen += name+ relationships = relationships :+ ParsedRelationship(callerName, name, "CALLS")+ }+ }+ }+ }+ }++ private def extractFileLevelCalls(exprStatement: TSNode): Unit = {+ val callExprs = collectDescendants(exprStatement, _.getType() == "call_expression")+ for (callExpr <- callExprs) {+ fieldChild(callExpr, "function").foreach { funcNode =>+ val callee = resolveCalleeName(funcNode)+ callee.foreach { name =>+ if (!TypeScriptBuiltins.contains(name) && !TypeScriptKeywords.contains(name) &&+ name != fileName && !relationships.exists(r =>+ r.srcName == fileName && r.dstName == name && r.predicate == "CALLS")) {+ relationships = relationships :+ ParsedRelationship(fileName, name, "CALLS")+ }+ }+ }+ }+ }++ private def resolveCalleeName(funcNode: TSNode): Option[String] = {+ funcNode.getType() match {+ case "identifier" =>+ Some(nodeText(funcNode, source))+ case "member_expression" =>+ // e.g., this.method(), obj.method() — extract the property name+ fieldChild(funcNode, "property").map(n => nodeText(n, source))+ case "call_expression" =>+ // Chained: foo.bar().baz() — take the outermost function+ fieldChild(funcNode, "function").flatMap(resolveCalleeName)+ case _ =>+ None+ }+ }++ // --- Helpers ---++ private def extractFirstLine(node: TSNode): String = {+ val text = nodeText(node, source)+ text.split("\n").head+ }++ private def extractVisibility(node: TSNode): String = {+ // Check for accessibility_modifier child+ val modifier = allChildren(node).find(c =>+ c.getType() == "accessibility_modifier" ||+ c.getType() == "private" || c.getType() == "public" || c.getType() == "protected"+ )+ modifier match {+ case Some(m) =>+ val text = nodeText(m, source).trim+ if (text == "private") "private"+ else if (text == "protected") "protected"+ else "public"+ case None =>+ // Also check the first line text+ val firstLine = extractFirstLine(node).trim+ if (firstLine.startsWith("private ") || firstLine.startsWith("private\t")) "private"+ else if (firstLine.startsWith("protected ") || firstLine.startsWith("protected\t")) "protected"+ else "public"+ }+ }+ }++ // --- Shared constants (reused from TypeScriptParser) ---++ private val TypeScriptKeywords: Set[String] = Set(+ "if", "else", "for", "while", "do", "switch", "case", "break",+ "continue", "return", "throw", "try", "catch", "finally",+ "new", "delete", "typeof", "instanceof", "void", "in", "of",+ "class", "extends", "implements", "interface", "enum", "type",+ "const", "let", "var", "function", "async", "await",+ "import", "export", "default", "from", "as",+ "this", "super", "constructor", "static", "private", "public", "protected"+ )++ private val TypeScriptBuiltins: Set[String] = Set(+ "console", "log", "error", "warn", "parseInt", "parseFloat",+ "String", "Number", "Boolean", "Array", "Object", "Promise",+ "JSON", "Math", "Date", "RegExp", "Error", "Map", "Set",+ "WeakMap", "WeakSet", "Symbol",+ "setTimeout", "setInterval", "clearTimeout", "clearInterval",+ "require", "module", "exports",+ "fetch", "Response", "Request", "URL", "Buffer", "process",+ "map", "filter", "reduce", "forEach", "sort", "find", "some", "every",+ "includes", "indexOf", "slice", "splice", "push", "pop", "shift", "unshift",+ "concat", "join", "flat", "flatMap", "fill", "from",+ "split", "replace", "trim", "toUpperCase", "toLowerCase", "substring",+ "charAt", "startsWith", "endsWith", "padStart", "padEnd", "match", "test",+ "keys", "values", "entries", "assign", "create", "freeze",+ "defineProperty", "getOwnPropertyNames", "hasOwnProperty",+ "then", "catch", "finally", "all", "race", "resolve", "reject"+ )+}diff --git a/memory-layer/src/main/scala/ix/memory/ingestion/parsers/TreeSitterUtils.scala b/memory-layer/src/main/scala/ix/memory/ingestion/parsers/TreeSitterUtils.scalanew file mode 100644index 00000000..7c69a61c--- /dev/null+++ b/memory-layer/src/main/scala/ix/memory/ingestion/parsers/TreeSitterUtils.scala@@ -0,0 +1,62 @@+package ix.memory.ingestion.parsers++import org.treesitter.{TSNode, TSParser, TSTree, TSLanguage}++object TreeSitterUtils {++ /** 1-based line start */+ def lineStart(node: TSNode): Int = node.getStartPoint().getRow() + 1++ /** 1-based line end */+ def lineEnd(node: TSNode): Int = node.getEndPoint().getRow() + 1++ /** Extract source text for a node */+ def nodeText(node: TSNode, source: String): String =+ source.substring(node.getStartByte(), node.getEndByte())++ /** Find named child by field name, returning None if null */+ def fieldChild(node: TSNode, field: String): Option[TSNode] = {+ val child = node.getChildByFieldName(field)+ if (child == null || child.isNull()) None else Some(child)+ }++ /** Find first named child with given type */+ def findChild(node: TSNode, nodeType: String): Option[TSNode] =+ namedChildren(node).find(_.getType() == nodeType)++ /** All named children */+ def namedChildren(node: TSNode): Vector[TSNode] =+ (0 until node.getNamedChildCount()).map(node.getNamedChild).toVector++ /** All named children of a given type */+ def childrenOfType(node: TSNode, nodeType: String): Vector[TSNode] =+ namedChildren(node).filter(_.getType() == nodeType)++ /** All children (named and anonymous) */+ def allChildren(node: TSNode): Vector[TSNode] =+ (0 until node.getChildCount()).map(node.getChild).toVector++ /** Recursively collect all descendants matching a predicate */+ def collectDescendants(node: TSNode, pred: TSNode => Boolean): Vector[TSNode] = {+ val buf = Vector.newBuilder[TSNode]+ def walk(n: TSNode): Unit = {+ if (pred(n)) buf += n+ for (i <- 0 until n.getChildCount()) walk(n.getChild(i))+ }+ walk(node)+ buf.result()+ }++ /** Extract identifier name from a node's "name" field */+ def extractName(node: TSNode, source: String): Option[String] =+ fieldChild(node, "name").map(n => nodeText(n, source))++ /** Loan pattern: parse source, run body, close parser+tree */+ def withParse[A](lang: TSLanguage, source: String)(body: TSNode => A): A = {+ val parser = new TSParser()+ parser.setLanguage(lang)+ val tree = parser.parseString(null, source)+ try body(tree.getRootNode())+ finally { tree.close(); parser.close() }+ }+}diff --git a/memory-layer/src/main/scala/ix/memory/model/Node.scala b/memory-layer/src/main/scala/ix/memory/model/Node.scalaindex 1dae81d0..1bff21f3 100644--- a/memory-layer/src/main/scala/ix/memory/model/Node.scala+++ b/memory-layer/src/main/scala/ix/memory/model/Node.scala@@ -26,6 +26,7 @@ object NodeKind {case object Plan extends NodeKindcase object Task extends NodeKindcase object Bug extends NodeKind+ case object Goal extends NodeKindprivate val nameMap: Map[String, NodeKind] = Map("module" -> Module,@@ -46,7 +47,8 @@ object NodeKind {"method" -> Method,"plan" -> Plan,"task" -> Task,- "bug" -> Bug+ "bug" -> Bug,+ "goal" -> Goal)implicit val encoder: Encoder[NodeKind] = Encoder[String].contramap {@@ -69,6 +71,7 @@ object NodeKind {case Plan => "plan"case Task => "task"case Bug => "bug"+ case Goal => "goal"}implicit val decoder: Decoder[NodeKind] = Decoder[String].emap { s =>diff --git a/memory-layer/src/test/scala/ix/memory/ingestion/parsers/ScalaParserSpec.scala b/memory-layer/src/test/scala/ix/memory/ingestion/parsers/ScalaParserSpec.scalaindex 8b1c0cfa..e23be62e 100644--- a/memory-layer/src/test/scala/ix/memory/ingestion/parsers/ScalaParserSpec.scala+++ b/memory-layer/src/test/scala/ix/memory/ingestion/parsers/ScalaParserSpec.scala@@ -7,7 +7,7 @@ import ix.memory.model.NodeKindimport io.circe.Jsonclass ScalaParserSpec extends AnyFlatSpec with Matchers {- val parser = new ScalaParser+ val parser: ix.memory.ingestion.Parser = new TreeSitterScalaParserval sampleCode: String ="""package ix.memory.context@@ -297,4 +297,49 @@ class ScalaParserSpec extends AnyFlatSpec with Matchers {computeBase.lineStart should be > 1computeBase.lineEnd should be > computeBase.lineStart}++ // --- Tree-sitter specific tests ---++ it should "handle 3+ level nesting with full CONTAINS chain" in {+ val source = """object A {+ | object B {+ | class C {+ | def d(): Unit = ()+ | }+ | }+ |}""".stripMargin+ val result = parser.parse("Nested.scala", source)+ val contains = result.relationships.filter(_.predicate == "CONTAINS")+ contains should contain (ParsedRelationship("Nested.scala", "A", "CONTAINS"))+ contains should contain (ParsedRelationship("A", "B", "CONTAINS"))+ contains should contain (ParsedRelationship("B", "C", "CONTAINS"))+ contains should contain (ParsedRelationship("C", "d", "CONTAINS"))+ }++ it should "handle multi-line function signatures" in {+ val source = """class Service {+ | def process(+ | x: Int,+ | y: String+ | ): IO[Unit] = {+ | println(x)+ | }+ |}""".stripMargin+ val result = parser.parse("Service.scala", source)+ val method = result.entities.find(_.name == "process").get+ method.kind shouldBe NodeKind.Method+ method.lineStart should be >= 1+ method.lineEnd should be > method.lineStart+ }++ it should "extract EXTENDS with 'with' mixin — primary parent" in {+ val source = """class A extends B with C with D {+ | def run(): Unit = ()+ |}""".stripMargin+ val result = parser.parse("A.scala", source)+ val extends_ = result.relationships.filter(_.predicate == "EXTENDS")+ extends_ should have length 1+ extends_.head.srcName shouldBe "A"+ extends_.head.dstName shouldBe "B"+ }}diff --git a/memory-layer/src/test/scala/ix/memory/ingestion/parsers/TypeScriptParserSpec.scala b/memory-layer/src/test/scala/ix/memory/ingestion/parsers/TypeScriptParserSpec.scalaindex 2037315c..e5fa4548 100644--- a/memory-layer/src/test/scala/ix/memory/ingestion/parsers/TypeScriptParserSpec.scala+++ b/memory-layer/src/test/scala/ix/memory/ingestion/parsers/TypeScriptParserSpec.scala@@ -7,7 +7,7 @@ import ix.memory.model.NodeKindimport io.circe.Jsonclass TypeScriptParserSpec extends AnyFlatSpec with Matchers {- val parser = new TypeScriptParser()+ val parser: ix.memory.ingestion.Parser = new TreeSitterTypeScriptParser()val sampleCode: String = scala.io.Source.fromResource("fixtures/api.ts").mkString@@ -583,4 +583,48 @@ class TypeScriptParserSpec extends AnyFlatSpec with Matchers {m.lineEnd should be <= cls.lineEnd}}++ // --- Tree-sitter specific tests ---++ it should "extract default imports" in {+ val source = """import React from 'react';"""+ val result = parser.parse("app.tsx", source)+ val imports = result.relationships.filter(_.predicate == "IMPORTS")+ imports.map(_.dstName) should contain ("React")+ imports.map(_.dstName) should contain ("react")+ }++ it should "extract namespace imports" in {+ val source = """import * as path from 'path';"""+ val result = parser.parse("util.ts", source)+ val imports = result.relationships.filter(_.predicate == "IMPORTS")+ imports.map(_.dstName) should contain ("path")+ }++ it should "handle arrow function with object type param" in {+ val source = """+ |const fn = (opts: { a: string; b: number }) => {+ | return processOpts(opts);+ |};+ """.stripMargin+ val result = parser.parse("fn.ts", source)+ val func = result.entities.find(e => e.name == "fn" && e.kind == NodeKind.Function)+ func shouldBe defined+ result.relationships.exists(r =>+ r.srcName == "fn" && r.dstName == "processOpts" && r.predicate == "CALLS"+ ) shouldBe true+ }++ it should "extract enum declarations" in {+ val source = """+ |export enum Status {+ | Active,+ | Inactive+ |}+ """.stripMargin+ val result = parser.parse("status.ts", source)+ val enum = result.entities.find(_.name == "Status")+ enum shouldBe defined+ enum.get.attrs.get("ts_kind").flatMap(_.asString) shouldBe Some("enum")+ }}