Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

feat: cross-file edges, global diff, decision search, relevance boost, node labels, empty file skip

riley0227635e79952bfd
diff --git a/ix-cli/src/cli/commands/diff.ts b/ix-cli/src/cli/commands/diff.ts
index 6076d831..3f4472b7 100644
--- a/ix-cli/src/cli/commands/diff.ts
+++ b/ix-cli/src/cli/commands/diff.ts
@@ -1,6 +1,8 @@
import type { Command } from "commander";
+import chalk from "chalk";
import { IxClient } from "../../client/api.js";
import { getEndpoint } from "../config.js";
+import { formatDiff } from "../format.js";
export function registerDiffCommand(program: Command): void {
program
@@ -14,7 +16,7 @@ export function registerDiffCommand(program: Command): void {
if (opts.format === "json") {
console.log(JSON.stringify(result, null, 2));
} else {
- console.log(JSON.stringify(result, null, 2));
+ formatDiff(result, "text");
}
});
}
diff --git a/ix-cli/src/cli/format.ts b/ix-cli/src/cli/format.ts
index c94f3674..b5a94db3 100644
--- a/ix-cli/src/cli/format.ts
+++ b/ix-cli/src/cli/format.ts
@@ -162,6 +162,26 @@ export function formatIntents(intents: any[], format: string): void {
}
}
+export function formatDiff(result: any, format: string): void {
+ if (format === "json") {
+ console.log(JSON.stringify(result, null, 2));
+ return;
+ }
+ console.log(chalk.cyan.bold(`Diff: rev ${result.fromRev} → ${result.toRev}`));
+ if (!result.changes?.length) {
+ console.log(chalk.dim(" No changes in this range."));
+ return;
+ }
+ for (const change of result.changes) {
+ const icon = change.changeType === "removed" ? chalk.red("- ")
+ : change.changeType === "added" ? chalk.green("+ ")
+ : chalk.yellow("~ ");
+ const name = change.atToRev?.attrs?.name || change.entityId?.substring(0, 8);
+ const kind = change.atToRev?.kind || "unknown";
+ console.log(` ${icon}${chalk.bold(name)} (${kind}) [${change.changeType}]`);
+ }
+}
+
export function formatConflicts(conflicts: any[], format: string): void {
if (format === "json") {
console.log(JSON.stringify(conflicts, null, 2));
diff --git a/memory-layer/src/main/scala/ix/memory/api/DiffRoutes.scala b/memory-layer/src/main/scala/ix/memory/api/DiffRoutes.scala
index 05a7a107..fce9a99e 100644
--- a/memory-layer/src/main/scala/ix/memory/api/DiffRoutes.scala
+++ b/memory-layer/src/main/scala/ix/memory/api/DiffRoutes.scala
@@ -53,9 +53,16 @@ class DiffRoutes(queryApi: GraphQueryApi) {
result <- diffEntity(eid, Rev(body.fromRev), Rev(body.toRev))
} yield result.toVector
case None =>
- IO.raiseError(new UnsupportedOperationException(
- "Diff without entityId is not yet supported. Please provide an entityId."
- ))
+ queryApi.getChangedEntities(Rev(body.fromRev), Rev(body.toRev)).map { nodes =>
+ nodes.map { n =>
+ DiffEntry(
+ entityId = n.id,
+ changeType = if (n.deletedRev.isDefined) "removed" else "added_or_modified",
+ atFromRev = None,
+ atToRev = Some(n)
+ )
+ }
+ }
}
resp <- Ok(DiffResponse(body.fromRev, body.toRev, changes))
} yield resp).handleErrorWith(ErrorHandler.handle(_))
diff --git a/memory-layer/src/main/scala/ix/memory/context/ContextService.scala b/memory-layer/src/main/scala/ix/memory/context/ContextService.scala
index c885181b..d79c9664 100644
--- a/memory-layer/src/main/scala/ix/memory/context/ContextService.scala
+++ b/memory-layer/src/main/scala/ix/memory/context/ContextService.scala
@@ -66,8 +66,8 @@ class ContextService(
))
}
- // 7. Relevance score: weight claims by hop distance from seeds
- relevant = RelevanceScorer.score(scored, seeds.map(_.id).toSet, expanded.edges)
+ // 7. Relevance score: weight claims by hop distance from seeds, boost exact matches
+ relevant = RelevanceScorer.scoreWithTerms(scored, seeds.map(_.id).toSet, expanded.edges, terms)
// 8. Rank claims by finalScore (relevance x confidence) descending
ranked = ContextRanker.rank(relevant)
@@ -96,7 +96,14 @@ class ContextService(
// Lightweight summaries for LLM navigation (lets the model drill down with ix_entity/ix_expand)
nodeSummaries: Vector[NodeSummary] = allNodes.map { n =>
- val display = n.attrs.hcursor.get[String]("name").getOrElse(n.id.value.toString)
+ val display = n.attrs.hcursor.get[String]("name").toOption
+ .orElse(n.attrs.hcursor.get[String]("title").toOption)
+ .orElse(n.attrs.hcursor.get[String]("heading").toOption)
+ .getOrElse {
+ val uri = n.provenance.sourceUri
+ val basename = uri.split("/").lastOption.getOrElse(uri)
+ if (basename.nonEmpty) basename else n.id.value.toString.take(8)
+ }
NodeSummary(n.id, n.kind, display, rev)
}
edgeSummaries: Vector[EdgeSummary] = edgesTrimmed.map(e => EdgeSummary(e.id, e.src, e.dst, e.predicate, rev))
diff --git a/memory-layer/src/main/scala/ix/memory/context/RelevanceScorer.scala b/memory-layer/src/main/scala/ix/memory/context/RelevanceScorer.scala
index 4fc04e2d..ec163acb 100644
--- a/memory-layer/src/main/scala/ix/memory/context/RelevanceScorer.scala
+++ b/memory-layer/src/main/scala/ix/memory/context/RelevanceScorer.scala
@@ -7,15 +7,33 @@ object RelevanceScorer {
claims: Vector[ScoredClaim],
seedNodeIds: Set[NodeId],
expandedEdges: Vector[GraphEdge]
+ ): Vector[ScoredClaim] =
+ scoreWithTerms(claims, seedNodeIds, expandedEdges, Vector.empty)
+
+ def scoreWithTerms(
+ claims: Vector[ScoredClaim],
+ seedNodeIds: Set[NodeId],
+ expandedEdges: Vector[GraphEdge],
+ queryTerms: Vector[String]
): Vector[ScoredClaim] = {
val oneHopIds = expandedEdges
.flatMap(e => Vector(e.src, e.dst))
.toSet -- seedNodeIds
+ val termsLower = queryTerms.map(_.toLowerCase)
claims.map { sc =>
- val relevance = if (seedNodeIds.contains(sc.claim.entityId)) 1.0
- else if (oneHopIds.contains(sc.claim.entityId)) 0.7
- else 0.4
+ val hopRelevance =
+ if (seedNodeIds.contains(sc.claim.entityId)) 1.0
+ else if (oneHopIds.contains(sc.claim.entityId)) 0.7
+ else 0.4
+
+ val fieldLower = sc.claim.statement.toLowerCase
+ val exactBoost = if (termsLower.exists(t => fieldLower.contains(t))) 1.2 else 1.0
+
+ val pathLower = sc.claim.provenance.sourceUri.toLowerCase
+ val pathBoost = if (termsLower.exists(t => pathLower.contains(t))) 1.1 else 1.0
+
+ val relevance = math.min(1.0, hopRelevance * exactBoost * pathBoost)
sc.copy(relevance = relevance, finalScore = relevance * sc.confidence.score)
}
}
diff --git a/memory-layer/src/main/scala/ix/memory/db/ArangoGraphQueryApi.scala b/memory-layer/src/main/scala/ix/memory/db/ArangoGraphQueryApi.scala
index eb22f2d6..39f2f228 100644
--- a/memory-layer/src/main/scala/ix/memory/db/ArangoGraphQueryApi.scala
+++ b/memory-layer/src/main/scala/ix/memory/db/ArangoGraphQueryApi.scala
@@ -71,7 +71,18 @@ class ArangoGraphQueryApi(client: ArangoClient) extends GraphQueryApi {
| RETURN DISTINCT c.entity_id
|)
|
- |LET all_ids = UNION_DISTINCT(name_matches, provenance_matches, claim_matches)
+ |LET decision_matches = (
+ | FOR n IN nodes
+ | FILTER n.kind == "decision"
+ | AND n.deleted_rev == null
+ | AND (
+ | CONTAINS(LOWER(TO_STRING(n.attrs.title)), LOWER(@text))
+ | OR CONTAINS(LOWER(TO_STRING(n.attrs.rationale)), LOWER(@text))
+ | )
+ | RETURN DISTINCT n.logical_id
+ |)
+ |
+ |LET all_ids = UNION_DISTINCT(name_matches, provenance_matches, claim_matches, decision_matches)
|
|FOR id IN all_ids
| FOR n IN nodes
@@ -214,6 +225,19 @@ class ArangoGraphQueryApi(client: ArangoClient) extends GraphQueryApi {
)
).map(_.toVector)
+ override def getChangedEntities(fromRev: Rev, toRev: Rev): IO[Vector[GraphNode]] =
+ client.query(
+ """FOR n IN nodes
+ | FILTER n.created_rev > @fromRev AND n.created_rev <= @toRev
+ | COLLECT logicalId = n.logical_id INTO group
+ | LET latest = LAST(group[*].n)
+ | RETURN latest""".stripMargin,
+ Map(
+ "fromRev" -> Long.box(fromRev.value).asInstanceOf[AnyRef],
+ "toRev" -> Long.box(toRev.value).asInstanceOf[AnyRef]
+ )
+ ).map(_.flatMap(parseNode).toVector)
+
// ── JSON Parsers (snake_case → camelCase) ───────────────────────────
private def parseNode(json: Json): Option[GraphNode] = {
diff --git a/memory-layer/src/main/scala/ix/memory/db/GraphQueryApi.scala b/memory-layer/src/main/scala/ix/memory/db/GraphQueryApi.scala
index d75b735b..c9974d08 100644
--- a/memory-layer/src/main/scala/ix/memory/db/GraphQueryApi.scala
+++ b/memory-layer/src/main/scala/ix/memory/db/GraphQueryApi.scala
@@ -15,6 +15,7 @@ trait GraphQueryApi {
def getLatestRev: IO[Rev]
def getPatchesForEntity(entityId: NodeId): IO[List[Json]]
def getPatchesBySource(sourceUri: String, extractor: String): IO[Vector[Json]]
+ def getChangedEntities(fromRev: Rev, toRev: Rev): IO[Vector[GraphNode]]
}
sealed trait Direction
diff --git a/memory-layer/src/main/scala/ix/memory/ingestion/GraphPatchBuilder.scala b/memory-layer/src/main/scala/ix/memory/ingestion/GraphPatchBuilder.scala
index 0c34aaca..382b365e 100644
--- a/memory-layer/src/main/scala/ix/memory/ingestion/GraphPatchBuilder.scala
+++ b/memory-layer/src/main/scala/ix/memory/ingestion/GraphPatchBuilder.scala
@@ -30,6 +30,7 @@ object GraphPatchBuilder {
val extractor = if (filePath.endsWith(".py")) "tree-sitter-python/1.0"
else if (filePath.endsWith(".ts") || filePath.endsWith(".tsx")) "typescript-parser/1.0"
+ else if (filePath.endsWith(".scala") || filePath.endsWith(".sc")) "scala-parser/1.0"
else if (filePath.endsWith(".json") || filePath.endsWith(".yaml") || filePath.endsWith(".yml") || filePath.endsWith(".toml")) "config-parser/1.0"
else if (filePath.endsWith(".md")) "markdown-parser/1.0"
else "unknown-parser/1.0"
@@ -72,7 +73,7 @@ object GraphPatchBuilder {
val claimOps = relationshipClaims ++ attributeClaims
val allOps = nodeOps ++ edgeOps ++ claimOps
- val sourceType = if (filePath.endsWith(".py") || filePath.endsWith(".ts") || filePath.endsWith(".tsx")) SourceType.Code
+ val sourceType = if (filePath.endsWith(".py") || filePath.endsWith(".ts") || filePath.endsWith(".tsx") || filePath.endsWith(".scala") || filePath.endsWith(".sc")) SourceType.Code
else if (filePath.endsWith(".json") || filePath.endsWith(".yaml") || filePath.endsWith(".yml") || filePath.endsWith(".toml")) SourceType.Config
else if (filePath.endsWith(".md")) SourceType.Doc
else SourceType.Code
diff --git a/memory-layer/src/main/scala/ix/memory/ingestion/IngestionService.scala b/memory-layer/src/main/scala/ix/memory/ingestion/IngestionService.scala
index 9ecf6198..7390d36d 100644
--- a/memory-layer/src/main/scala/ix/memory/ingestion/IngestionService.scala
+++ b/memory-layer/src/main/scala/ix/memory/ingestion/IngestionService.scala
@@ -1,11 +1,13 @@
package ix.memory.ingestion
import java.nio.file.{Files, Path}
+import java.time.Instant
+import java.util.UUID
import cats.effect.IO
import cats.syntax.all._
import ix.memory.db.{CommitResult, GraphQueryApi, GraphWriteApi}
-import ix.memory.model.{NodeKind, PatchId, Rev}
+import ix.memory.model._
import io.circe.Json
/**
@@ -20,6 +22,8 @@ class IngestionService(parserRouter: ParserRouter, writeApi: GraphWriteApi, quer
def ingestFile(filePath: Path): IO[CommitResult] = {
for {
bytes <- IO.blocking(Files.readAllBytes(filePath))
+ _ <- if (bytes.isEmpty) IO.raiseError(new RuntimeException(s"Skipping empty file: $filePath"))
+ else IO.unit
// Hash raw bytes so revisions are stable across encodings
hash = Some(sha256Bytes(bytes))
// Decode text with UTF-8, fallback to ISO-8859-1 to avoid hard failures
@@ -53,6 +57,8 @@ class IngestionService(parserRouter: ParserRouter, writeApi: GraphWriteApi, quer
patch = GraphPatchBuilder.build(filePath.toString, hash, result).copy(replaces = replaces)
_ <- IO.fromEither(PatchValidator.validate(patch).left.map(msg => new IllegalStateException(msg)))
commit <- writeApi.commitPatch(patch)
+ // Resolve cross-file import edges after main patch is committed
+ _ <- resolveImportEdges(filePath, result, hash).attempt.void
} yield commit
}
@@ -153,6 +159,54 @@ class IngestionService(parserRouter: ParserRouter, writeApi: GraphWriteApi, quer
}
}
+ private def resolveImportEdges(
+ filePath: Path,
+ parseResult: ParseResult,
+ sourceHash: Option[String]
+ ): IO[Unit] = {
+ val importRels = parseResult.relationships.filter(_.predicate == "IMPORTS")
+ importRels.traverse_ { rel =>
+ val targetName = rel.dstName
+ // Try to resolve relative imports (./config, ../utils)
+ val resolvedPath = resolveRelativePath(filePath, targetName)
+ resolvedPath match {
+ case Some(resolved) =>
+ queryApi.searchNodes(resolved.getFileName.toString, limit = 1).flatMap {
+ case nodes if nodes.nonEmpty =>
+ val srcId = NodeId(UUID.nameUUIDFromBytes(s"${filePath}:${filePath.getFileName}".getBytes("UTF-8")))
+ val dstId = nodes.head.id
+ val edgeId = EdgeId(UUID.nameUUIDFromBytes(s"${srcId.value}:${dstId.value}:IMPORTS".getBytes("UTF-8")))
+ val patch = GraphPatch(
+ patchId = PatchId(UUID.randomUUID()),
+ actor = "ix/cross-file",
+ timestamp = Instant.now(),
+ source = PatchSource(filePath.toString, sourceHash, "cross-file-resolver/1.0", SourceType.Code),
+ baseRev = Rev(0L),
+ ops = Vector(PatchOp.UpsertEdge(edgeId, srcId, dstId, EdgePredicate("IMPORTS"), Map.empty)),
+ replaces = Vector.empty,
+ intent = Some(s"Cross-file import: ${filePath.getFileName} -> ${resolved.getFileName}")
+ )
+ writeApi.commitPatch(patch).void
+ case _ => IO.unit
+ }
+ case None => IO.unit
+ }
+ }
+ }
+
+ private def resolveRelativePath(from: Path, importTarget: String): Option[Path] = {
+ if (importTarget.startsWith("./") || importTarget.startsWith("../")) {
+ val base = from.getParent
+ if (base == null) return None
+ val extensions = List("", ".ts", ".tsx", ".scala", ".py", ".js")
+ extensions.collectFirst {
+ case ext =>
+ val candidate = base.resolve(importTarget + ext).normalize()
+ if (Files.exists(candidate)) candidate else null
+ }.flatMap(Option(_))
+ } else None
+ }
+
private def sha256Bytes(bytes: Array[Byte]): String = {
val md = java.security.MessageDigest.getInstance("SHA-256")
md.digest(bytes).map("%02x".format(_)).mkString