Skip to content

armgit / Ix

Public Imported from GitHub
0

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

feat: add REFERENCES predicate to all CLI query commands

Tanner Kocher5f23b934facc
diff --git a/ix-cli/src/cli/commands/callers.ts b/ix-cli/src/cli/commands/callers.ts
index c57cc08d..97da4118 100644
--- a/ix-cli/src/cli/commands/callers.ts
+++ b/ix-cli/src/cli/commands/callers.ts
@@ -29,7 +29,7 @@ export function registerCallersCommand(program: Command): void {
// Use expandByName for cross-file resolution
const result = await client.expandByName(target.name, {
direction: "in",
- predicates: ["CALLS"],
+ predicates: ["CALLS", "REFERENCES"],
kinds: ["function", "method"],
});
@@ -76,11 +76,11 @@ export function registerCallersCommand(program: Command): void {
},
diagnostics: [{
code: "text_fallback_used",
- message: "No graph-backed CALLS edges found. If files were ingested before CALLS extraction was added, run: ix ingest --force --recursive .",
+ message: "No graph-backed CALLS/REFERENCES edges found. If files were ingested before extraction was added, run: ix ingest --force --recursive .",
}],
}, null, 2));
} else {
- stderr(chalk.dim("No graph-backed CALLS edges found. Showing text-based candidate usages."));
+ stderr(chalk.dim("No graph-backed CALLS/REFERENCES edges found. Showing text-based candidate usages."));
stderr(chalk.dim("Tip: if files were ingested before CALLS extraction, run: ix ingest --force --recursive .\n"));
for (const r of textResults) {
const snippet = r.attrs?.snippet ?? "";
diff --git a/ix-cli/src/cli/commands/depends.ts b/ix-cli/src/cli/commands/depends.ts
index 5ce7115c..8cfabe9d 100644
--- a/ix-cli/src/cli/commands/depends.ts
+++ b/ix-cli/src/cli/commands/depends.ts
@@ -12,8 +12,8 @@ export interface DependencyNode {
name: string;
kind: string;
resolved: boolean;
- relation: "called_by" | "imported_by";
- sourceEdge: "CALLS" | "IMPORTS";
+ relation: "called_by" | "imported_by" | "referenced_by";
+ sourceEdge: "CALLS" | "IMPORTS" | "REFERENCES";
path?: string;
children: DependencyNode[];
cycle?: boolean;
@@ -46,14 +46,15 @@ export async function buildDependencyTree(
maxDepthReached = Math.max(maxDepthReached, depth);
- const [callResult, importResult] = await Promise.all([
+ const [callResult, importResult, refResult] = await Promise.all([
client.expand(nodeId, { direction: "in", predicates: ["CALLS"], hops: 1 }),
client.expand(nodeId, { direction: "in", predicates: ["IMPORTS"], hops: 1 }),
+ client.expand(nodeId, { direction: "in", predicates: ["REFERENCES"], hops: 1 }),
]);
const children: DependencyNode[] = [];
- const processNodes = async (nodes: any[], relation: "called_by" | "imported_by", sourceEdge: "CALLS" | "IMPORTS") => {
+ const processNodes = async (nodes: any[], relation: "called_by" | "imported_by" | "referenced_by", sourceEdge: "CALLS" | "IMPORTS" | "REFERENCES") => {
for (const n of nodes) {
if (nodesVisited >= maxNodes) { truncated = true; break; }
const name = n.name || n.attrs?.name || "";
@@ -85,6 +86,7 @@ export async function buildDependencyTree(
await processNodes(callResult.nodes, "called_by", "CALLS");
await processNodes(importResult.nodes, "imported_by", "IMPORTS");
+ await processNodes(refResult.nodes, "referenced_by", "REFERENCES");
return children;
}
diff --git a/ix-cli/src/cli/commands/impact.ts b/ix-cli/src/cli/commands/impact.ts
index 13391498..f4f21a0d 100644
--- a/ix-cli/src/cli/commands/impact.ts
+++ b/ix-cli/src/cli/commands/impact.ts
@@ -55,7 +55,7 @@ async function containerImpact(
const [containsResult, importersResult, dependentsResult, decisionsResult, tasksResult, bugsResult] = await Promise.all([
client.expand(target.id, { direction: "out", predicates: ["CONTAINS"] }),
client.expand(target.id, { direction: "in", predicates: ["IMPORTS"] }),
- client.expand(target.id, { direction: "in", predicates: ["CALLS"] }),
+ client.expand(target.id, { direction: "in", predicates: ["CALLS", "REFERENCES"] }),
client.expand(target.id, { direction: "in", predicates: ["DECISION_AFFECTS"] }),
client.expand(target.id, { direction: "in", predicates: ["TASK_AFFECTS"] }),
client.expand(target.id, { direction: "in", predicates: ["BUG_AFFECTS"] }),
@@ -83,7 +83,7 @@ async function containerImpact(
try {
const callersResult = await client.expand(member.id, {
direction: "in",
- predicates: ["CALLS"],
+ predicates: ["CALLS", "REFERENCES"],
});
return {
name: member.name || member.attrs?.name || "(unnamed)",
@@ -194,8 +194,8 @@ async function leafImpact(
): Promise<void> {
// Fetch callers, callees, and developer-cycle context in parallel
const [callersResult, calleesResult, decisionsResult, tasksResult, bugsResult] = await Promise.all([
- client.expand(target.id, { direction: "in", predicates: ["CALLS"] }),
- client.expand(target.id, { direction: "out", predicates: ["CALLS"] }),
+ client.expand(target.id, { direction: "in", predicates: ["CALLS", "REFERENCES"] }),
+ client.expand(target.id, { direction: "out", predicates: ["CALLS", "REFERENCES"] }),
client.expand(target.id, { direction: "in", predicates: ["DECISION_AFFECTS"] }),
client.expand(target.id, { direction: "in", predicates: ["TASK_AFFECTS"] }),
client.expand(target.id, { direction: "in", predicates: ["BUG_AFFECTS"] }),
diff --git a/ix-cli/src/cli/commands/locate.ts b/ix-cli/src/cli/commands/locate.ts
index 07630623..c89adeb4 100644
--- a/ix-cli/src/cli/commands/locate.ts
+++ b/ix-cli/src/cli/commands/locate.ts
@@ -16,7 +16,7 @@ interface RelatedItem {
name: string;
kind: string;
id?: string;
- relationship: "contains" | "contained-by" | "depends-on" | "imported-by" | "calls" | "called-by";
+ relationship: "contains" | "contained-by" | "depends-on" | "imported-by" | "calls" | "called-by" | "referenced-by";
}
interface TextMatch {
@@ -94,6 +94,7 @@ export function registerLocateCommand(program: Command): void {
calleesResult,
importsResult,
importedByResult,
+ referencedByResult,
] = await Promise.all([
client.entity(target.id),
isContainer
@@ -103,6 +104,7 @@ export function registerLocateCommand(program: Command): void {
client.expand(target.id, { direction: "out", predicates: ["CALLS"] }),
client.expand(target.id, { direction: "out", predicates: ["IMPORTS"] }),
client.expand(target.id, { direction: "in", predicates: ["IMPORTS"] }),
+ client.expand(target.id, { direction: "in", predicates: ["REFERENCES"] }),
]);
const node = details.node as any;
@@ -154,6 +156,9 @@ export function registerLocateCommand(program: Command): void {
for (const n of importedByResult.nodes) {
relationships.push(nodeToRelated(n, "imported-by"));
}
+ for (const n of referencedByResult.nodes) {
+ relationships.push(nodeToRelated(n, "referenced-by"));
+ }
// If container, show contained members as relationships too
if (isContainer) {
diff --git a/ix-cli/src/cli/commands/overview.ts b/ix-cli/src/cli/commands/overview.ts
index 5c261686..c0b701bd 100644
--- a/ix-cli/src/cli/commands/overview.ts
+++ b/ix-cli/src/cli/commands/overview.ts
@@ -85,7 +85,7 @@ async function overviewContainer(
client.entity(target.id),
client.expand(target.id, { direction: "out", predicates: ["CONTAINS"] }),
client.expand(target.id, { direction: "out", predicates: ["IMPORTS"] }),
- client.expand(target.id, { direction: "in", predicates: ["CALLS", "IMPORTS"] }),
+ client.expand(target.id, { direction: "in", predicates: ["CALLS", "IMPORTS", "REFERENCES"] }),
client.expand(target.id, { direction: "in", predicates: ["DECISION_AFFECTS"] }),
client.expand(target.id, { direction: "in", predicates: ["TASK_AFFECTS"] }),
client.expand(target.id, { direction: "in", predicates: ["BUG_AFFECTS"] }),
@@ -134,7 +134,7 @@ async function overviewContainer(
try {
const callersResult = await client.expand(m.id, {
direction: "in",
- predicates: ["CALLS"],
+ predicates: ["CALLS", "REFERENCES"],
});
return callersResult.nodes.length;
} catch {
@@ -225,8 +225,8 @@ async function overviewCallable(
// Fetch entity details, callers, and callees in parallel
const [details, callersResult, calleesResult, decisionsResult, tasksResult, bugsResult] = await Promise.all([
client.entity(target.id),
- client.expand(target.id, { direction: "in", predicates: ["CALLS"] }),
- client.expand(target.id, { direction: "out", predicates: ["CALLS"] }),
+ client.expand(target.id, { direction: "in", predicates: ["CALLS", "REFERENCES"] }),
+ client.expand(target.id, { direction: "out", predicates: ["CALLS", "REFERENCES"] }),
client.expand(target.id, { direction: "in", predicates: ["DECISION_AFFECTS"] }),
client.expand(target.id, { direction: "in", predicates: ["TASK_AFFECTS"] }),
client.expand(target.id, { direction: "in", predicates: ["BUG_AFFECTS"] }),
@@ -260,7 +260,7 @@ async function overviewCallable(
const callees = calleesResult.nodes;
if (callers.length === 0 && callees.length === 0) {
- diagnostics.push("No CALLS edges found. If files were ingested before CALLS extraction, run: ix ingest --force --recursive .");
+ diagnostics.push("No CALLS/REFERENCES edges found. If files were ingested before extraction was added, run: ix ingest --force --recursive .");
}
const decisions = decisionsResult.nodes.map((n: any) => ({
diff --git a/ix-cli/src/cli/commands/rank.ts b/ix-cli/src/cli/commands/rank.ts
index 6ad63ae9..3bdf2325 100644
--- a/ix-cli/src/cli/commands/rank.ts
+++ b/ix-cli/src/cli/commands/rank.ts
@@ -6,8 +6,8 @@ import { getEndpoint } from "../config.js";
type Metric = "dependents" | "callers" | "importers" | "members";
const METRIC_CONFIG: Record<Metric, { direction: string; predicates: string[] }> = {
- dependents: { direction: "in", predicates: ["CALLS", "IMPORTS"] },
- callers: { direction: "in", predicates: ["CALLS"] },
+ dependents: { direction: "in", predicates: ["CALLS", "IMPORTS", "REFERENCES"] },
+ callers: { direction: "in", predicates: ["CALLS", "REFERENCES"] },
importers: { direction: "in", predicates: ["IMPORTS"] },
members: { direction: "out", predicates: ["CONTAINS"] },
};
diff --git a/memory-layer/src/test/resources/fixtures/command_module.ts b/memory-layer/src/test/resources/fixtures/command_module.ts
new file mode 100644
index 00000000..382466b7
--- /dev/null
+++ b/memory-layer/src/test/resources/fixtures/command_module.ts
@@ -0,0 +1,15 @@
+import type { Command } from "commander";
+
+export function registerExplainCommand(program: Command): void {
+ program
+ .command("explain <symbol>")
+ .description("Explain an entity")
+ .action(async (symbol: string) => {
+ const result = await resolveEntity(symbol);
+ console.log(result);
+ });
+}
+
+async function resolveEntity(symbol: string): Promise<string> {
+ return `Resolved: ${symbol}`;
+}
diff --git a/memory-layer/src/test/resources/fixtures/command_registration.ts b/memory-layer/src/test/resources/fixtures/command_registration.ts
new file mode 100644
index 00000000..324867dd
--- /dev/null
+++ b/memory-layer/src/test/resources/fixtures/command_registration.ts
@@ -0,0 +1,9 @@
+import { Command } from "commander";
+import { registerExplainCommand } from "./commands/command_module.js";
+
+const program = new Command();
+program.name("test-cli").version("0.1.0");
+
+registerExplainCommand(program);
+
+program.parse();
diff --git a/memory-layer/src/test/resources/fixtures/node_kind.scala b/memory-layer/src/test/resources/fixtures/node_kind.scala
new file mode 100644
index 00000000..2da07612
--- /dev/null
+++ b/memory-layer/src/test/resources/fixtures/node_kind.scala
@@ -0,0 +1,11 @@
+package ix.memory.model
+
+sealed trait NodeKind
+
+object NodeKind {
+ case object File extends NodeKind
+ case object Module extends NodeKind
+ case object Class extends NodeKind
+ case object Function extends NodeKind
+ case object Method extends NodeKind
+}
diff --git a/memory-layer/src/test/resources/fixtures/node_kind_user.scala b/memory-layer/src/test/resources/fixtures/node_kind_user.scala
new file mode 100644
index 00000000..57aba7a4
--- /dev/null
+++ b/memory-layer/src/test/resources/fixtures/node_kind_user.scala
@@ -0,0 +1,13 @@
+package ix.memory.ingestion
+
+class GraphPatchBuilder {
+ def buildNode(kind: NodeKind, name: String): GraphNode = {
+ val effectiveKind = NodeKind.File
+ val result = createNode(name, effectiveKind)
+ result
+ }
+
+ private def createNode(name: String, kind: NodeKind): GraphNode = {
+ GraphNode(name, kind)
+ }
+}
diff --git a/memory-layer/src/test/scala/ix/memory/QueryUsefulnessSpec.scala b/memory-layer/src/test/scala/ix/memory/QueryUsefulnessSpec.scala
new file mode 100644
index 00000000..96518684
--- /dev/null
+++ b/memory-layer/src/test/scala/ix/memory/QueryUsefulnessSpec.scala
@@ -0,0 +1,184 @@
+package ix.memory
+
+import java.nio.file.{Path, Paths}
+
+import cats.effect.IO
+import cats.effect.testing.scalatest.AsyncIOSpec
+import org.scalatest.flatspec.AsyncFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+import ix.memory.db._
+import ix.memory.ingestion.{IngestionService, ParserRouter}
+import ix.memory.model._
+
+/**
+ * Integration tests verifying that parser-emitted edges (especially REFERENCES)
+ * are persisted and queryable via the expand API.
+ *
+ * Requires a running ArangoDB instance on localhost:8529.
+ */
+class QueryUsefulnessSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers with TestDbHelper {
+
+ val clientResource = ArangoClient.resource(
+ host = "localhost", port = 8529,
+ database = "ix_memory_test", user = "root", password = ""
+ )
+
+ private def fixturePath(name: String): Path = {
+ val url = getClass.getClassLoader.getResource(s"fixtures/$name")
+ Paths.get(url.toURI)
+ }
+
+ // ── Scala REFERENCES: object references become query-useful ──
+
+ "QueryUsefulness" should "persist REFERENCES edges from Scala parser and return them via expand" in {
+ clientResource.use { client =>
+ val writeApi = new ArangoGraphWriteApi(client)
+ val queryApi = new ArangoGraphQueryApi(client)
+ val router = new ParserRouter()
+ val service = new IngestionService(router, writeApi, queryApi)
+
+ for {
+ _ <- cleanDatabase(client)
+ _ <- service.ingestFile(fixturePath("node_kind.scala"))
+ _ <- service.ingestFile(fixturePath("node_kind_user.scala"))
+
+ nodeKindResults <- queryApi.searchNodes("NodeKind", limit = 10, nameOnly = true)
+ nodeKindEntity = nodeKindResults.find(n => n.name == "NodeKind" && n.kind != NodeKind.Module)
+
+ _ = nodeKindEntity shouldBe defined
+
+ refResult <- queryApi.expand(
+ nodeKindEntity.get.id,
+ Direction.In,
+ predicates = Some(Set("REFERENCES")),
+ hops = 1
+ )
+
+ _ = refResult.nodes should not be empty
+ refNames = refResult.nodes.map(_.name)
+ _ = refNames should contain atLeastOneOf ("buildNode", "createNode")
+ } yield succeed
+ }
+ }
+
+ it should "return REFERENCES edges alongside CALLS in combined dependency queries" in {
+ clientResource.use { client =>
+ val writeApi = new ArangoGraphWriteApi(client)
+ val queryApi = new ArangoGraphQueryApi(client)
+ val router = new ParserRouter()
+ val service = new IngestionService(router, writeApi, queryApi)
+
+ for {
+ _ <- cleanDatabase(client)
+ _ <- service.ingestFile(fixturePath("node_kind.scala"))
+ _ <- service.ingestFile(fixturePath("node_kind_user.scala"))
+
+ nodeKindResults <- queryApi.searchNodes("NodeKind", limit = 10, nameOnly = true)
+ nodeKindEntity = nodeKindResults.find(n => n.name == "NodeKind" && n.kind != NodeKind.Module)
+ _ = nodeKindEntity shouldBe defined
+
+ combinedResult <- queryApi.expand(
+ nodeKindEntity.get.id,
+ Direction.In,
+ predicates = Some(Set("CALLS", "IMPORTS", "REFERENCES")),
+ hops = 1
+ )
+
+ _ = combinedResult.nodes should not be empty
+ } yield succeed
+ }
+ }
+
+ // ── Scala nested CONTAINS: object membership is queryable ──
+
+ it should "persist nested CONTAINS edges for case objects inside companion" in {
+ clientResource.use { client =>
+ val writeApi = new ArangoGraphWriteApi(client)
+ val queryApi = new ArangoGraphQueryApi(client)
+ val router = new ParserRouter()
+ val service = new IngestionService(router, writeApi, queryApi)
+
+ for {
+ _ <- cleanDatabase(client)
+ _ <- service.ingestFile(fixturePath("node_kind.scala"))
+
+ results <- queryApi.searchNodes("NodeKind", limit = 10, nameOnly = true)
+ nodeKindObj = results.find(n => n.name == "NodeKind" && n.kind == NodeKind.Object)
+ _ = nodeKindObj shouldBe defined
+
+ containsResult <- queryApi.expand(
+ nodeKindObj.get.id,
+ Direction.Out,
+ predicates = Some(Set("CONTAINS")),
+ hops = 1
+ )
+
+ memberNames = containsResult.nodes.map(_.name)
+ _ = memberNames should contain allOf ("File", "Module", "Class", "Function", "Method")
+ } yield succeed
+ }
+ }
+
+ // ── TypeScript: file-level CALLS correctness ──
+
+ it should "not create false file-level CALLS for exported function definitions" in {
+ clientResource.use { client =>
+ val writeApi = new ArangoGraphWriteApi(client)
+ val queryApi = new ArangoGraphQueryApi(client)
+ val router = new ParserRouter()
+ val service = new IngestionService(router, writeApi, queryApi)
+
+ for {
+ _ <- cleanDatabase(client)
+ _ <- service.ingestFile(fixturePath("command_module.ts"))
+
+ fileResults <- queryApi.searchNodes("command_module.ts", limit = 5, nameOnly = true)
+ fileEntity = fileResults.find(n => n.name == "command_module.ts" && n.kind == NodeKind.File)
+ _ = fileEntity shouldBe defined
+
+ callsResult <- queryApi.expand(
+ fileEntity.get.id,
+ Direction.Out,
+ predicates = Some(Set("CALLS")),
+ hops = 1
+ )
+
+ calleeNames = callsResult.nodes.map(_.name)
+ _ = calleeNames should not contain ("registerExplainCommand")
+ } yield succeed
+ }
+ }
+
+ // ── TypeScript: cross-file caller attribution ──
+
+ it should "create cross-file CALLS edges for imported function invocations" in {
+ clientResource.use { client =>
+ val writeApi = new ArangoGraphWriteApi(client)
+ val queryApi = new ArangoGraphQueryApi(client)
+ val router = new ParserRouter()
+ val service = new IngestionService(router, writeApi, queryApi)
+
+ for {
+ _ <- cleanDatabase(client)
+ _ <- service.ingestFile(fixturePath("command_module.ts"))
+ _ <- service.ingestFile(fixturePath("command_registration.ts"))
+
+ funcResults <- queryApi.searchNodes("registerExplainCommand", limit = 10, nameOnly = true)
+ funcEntity = funcResults.find(n => n.name == "registerExplainCommand" && n.kind == NodeKind.Function)
+ _ = funcEntity shouldBe defined
+
+ callersResult <- queryApi.expand(
+ funcEntity.get.id,
+ Direction.In,
+ predicates = Some(Set("CALLS")),
+ hops = 1
+ )
+
+ callerNames = callersResult.nodes.map(_.name)
+ _ = callerNames should contain ("command_registration.ts")
+ _ = callerNames should not contain ("command_module.ts")
+ } yield succeed
+ }
+ }
+}