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
fix: skip comments in parser, fix resource leak, improve class scope tracking
riley022796962aefad9b
diff --git a/memory-layer/src/main/scala/ix/memory/ingestion/GraphPatchBuilder.scala b/memory-layer/src/main/scala/ix/memory/ingestion/GraphPatchBuilder.scalaindex 949bc1a5..1a19dedb 100644--- a/memory-layer/src/main/scala/ix/memory/ingestion/GraphPatchBuilder.scala+++ b/memory-layer/src/main/scala/ix/memory/ingestion/GraphPatchBuilder.scala@@ -10,7 +10,7 @@ object GraphPatchBuilder {/*** Build a GraphPatch from a ParseResult and file metadata.*- * Uses deterministic UUID generation (UUID v5 / nameUUID) so that+ * Uses deterministic UUID generation (UUID v3 (MD5-based nameUUID)) so that* re-parsing the same file produces the same node/edge IDs, enabling* idempotent upserts.*/diff --git a/memory-layer/src/main/scala/ix/memory/ingestion/IngestionService.scala b/memory-layer/src/main/scala/ix/memory/ingestion/IngestionService.scalaindex 41c4f719..b40fe473 100644--- a/memory-layer/src/main/scala/ix/memory/ingestion/IngestionService.scala+++ b/memory-layer/src/main/scala/ix/memory/ingestion/IngestionService.scala@@ -18,7 +18,10 @@ class IngestionService(parserRouter: ParserRouter, writeApi: GraphWriteApi) {*/def ingestFile(tenant: TenantId, filePath: Path): IO[CommitResult] = {for {- source <- IO.blocking(scala.io.Source.fromFile(filePath.toFile).mkString)+ source <- IO.blocking {+ val s = scala.io.Source.fromFile(filePath.toFile)+ try s.mkString finally s.close()+ }parser <- IO.fromOption(parserRouter.parserFor(filePath.toString))(new IllegalArgumentException(s"No parser for: $filePath"))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 bf932e94..bd9b51c7 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@@ -81,32 +81,35 @@ class TreeSitterPythonParser {var entities = Vector(fileEntity)var relationships = Vector.empty[ParsedRelationship]- // Track which class we're currently inside (based on indentation)- var currentClass: Option[String] = None- var classIndent: Int = -1+ // Track class ranges: (className, lineStart, lineEnd) for containment checks+ var classRanges = Vector.empty[(String, Int, Int)]for ((line, idx) <- lines.zipWithIndex) {val lineNum = idx + 1+ // Skip comment lines — prevents matching patterns inside comments+ if (line.trim.startsWith("#")) {+ // no-op: skip this line entirely+ } else {+// Check for class definitionClassPattern.findFirstMatchIn(line).foreach { m =>val className = m.group(1)+ val classEnd = findBlockEnd(lines, idx)entities = entities :+ ParsedEntity(name = className,kind = NodeKind.Class,attrs = Map("language" -> Json.fromString("python")),lineStart = lineNum,- lineEnd = findBlockEnd(lines, idx)+ lineEnd = classEnd)// File DEFINES classrelationships = relationships :+ ParsedRelationship(fileName, className, "DEFINES")- currentClass = Some(className)- classIndent = line.takeWhile(_ == ' ').length+ classRanges = classRanges :+ (className, lineNum, classEnd)}// Check for function/method definitionFuncPattern.findFirstMatchIn(line).foreach { m =>- val indent = m.group(1).lengthval funcName = m.group(2)entities = entities :+ ParsedEntity(@@ -117,13 +120,17 @@ class TreeSitterPythonParser {lineEnd = findBlockEnd(lines, idx))- if (indent > 0 && currentClass.isDefined && indent > classIndent) {- // Method inside a class- relationships = relationships :+ ParsedRelationship(currentClass.get, funcName, "DEFINES")- } else {- // Top-level function — file defines it- relationships = relationships :+ ParsedRelationship(fileName, funcName, "DEFINES")- currentClass = None+ // Check if this function's line falls within any class range+ val enclosingClass = classRanges.find { case (_, start, end) =>+ lineNum > start && lineNum <= end+ }+ enclosingClass match {+ case Some((className, _, _)) =>+ // Method inside a class+ relationships = relationships :+ ParsedRelationship(className, funcName, "DEFINES")+ case None =>+ // Top-level function — file defines it+ relationships = relationships :+ ParsedRelationship(fileName, funcName, "DEFINES")}// Extract function calls within the function body@@ -158,6 +165,8 @@ class TreeSitterPythonParser {}relationships = relationships :+ ParsedRelationship(fileName, moduleName, "IMPORTS")}++ } // end else (non-comment line)}ParseResult(entities, relationships)