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: add imports, contains, stats, doctor commands and update MCP expand tool
riley022707b92ebe517e
diff --git a/ix-cli/src/cli/commands/contains.ts b/ix-cli/src/cli/commands/contains.tsnew file mode 100644index 00000000..54844fb4--- /dev/null+++ b/ix-cli/src/cli/commands/contains.ts@@ -0,0 +1,24 @@+import type { Command } from "commander";+import { IxClient } from "../../client/api.js";+import { getEndpoint } from "../config.js";+import { formatEdgeResults } from "../format.js";++export function registerContainsCommand(program: Command): void {+ program+ .command("contains <symbol>")+ .description("Show members contained by the given entity (class, module, file)")+ .option("--format <fmt>", "Output format (text|json)", "text")+ .action(async (symbol: string, opts: { format: string }) => {+ const client = new IxClient(getEndpoint());++ const nodes = await client.search(symbol, { limit: 1 });+ if (nodes.length === 0) {+ console.log(`No entity found matching "${symbol}".`);+ return;+ }+ const entityId = (nodes[0] as any).id;++ const result = await client.expand(entityId, { direction: "out", predicates: ["CONTAINS"] });+ formatEdgeResults(result.nodes, "contains", symbol, opts.format);+ });+}diff --git a/ix-cli/src/cli/commands/doctor.ts b/ix-cli/src/cli/commands/doctor.tsnew file mode 100644index 00000000..b0d44cb4--- /dev/null+++ b/ix-cli/src/cli/commands/doctor.ts@@ -0,0 +1,98 @@+import type { Command } from "commander";+import chalk from "chalk";+import { IxClient } from "../../client/api.js";+import { getEndpoint } from "../config.js";++interface Check {+ name: string;+ run: () => Promise<{ ok: boolean; detail: string }>;+}++export function registerDoctorCommand(program: Command): void {+ program+ .command("doctor")+ .description("Check Ix system health — server, database, graph integrity")+ .option("--format <fmt>", "Output format (text|json)", "text")+ .action(async (opts: { format: string }) => {+ const endpoint = getEndpoint();+ const client = new IxClient(endpoint);++ const checks: Check[] = [+ {+ name: "Server reachable",+ run: async () => {+ try {+ const h = await client.health();+ return { ok: h.status === "ok", detail: `${endpoint} → ${h.status}` };+ } catch (e: any) {+ return { ok: false, detail: e.message ?? "unreachable" };+ }+ },+ },+ {+ name: "Graph has nodes",+ run: async () => {+ try {+ const s = await client.stats();+ const total = s.nodes?.total ?? 0;+ return { ok: total > 0, detail: `${total} nodes` };+ } catch (e: any) {+ return { ok: false, detail: e.message ?? "stats failed" };+ }+ },+ },+ {+ name: "Graph has edges",+ run: async () => {+ try {+ const s = await client.stats();+ const total = s.edges?.total ?? 0;+ return { ok: total > 0, detail: `${total} edges` };+ } catch (e: any) {+ return { ok: false, detail: e.message ?? "stats failed" };+ }+ },+ },+ {+ name: "No unresolved conflicts",+ run: async () => {+ try {+ const c = await client.conflicts();+ const count = Array.isArray(c) ? c.length : 0;+ return { ok: count === 0, detail: count === 0 ? "clean" : `${count} conflict(s)` };+ } catch (e: any) {+ return { ok: false, detail: e.message ?? "conflicts check failed" };+ }+ },+ },+ ];++ const results: Array<{ name: string; ok: boolean; detail: string }> = [];+ for (const check of checks) {+ const result = await check.run();+ results.push({ name: check.name, ...result });+ }++ if (opts.format === "json") {+ const allOk = results.every((r) => r.ok);+ console.log(JSON.stringify({ healthy: allOk, checks: results }, null, 2));+ return;+ }++ console.log(chalk.bold("\nIx Doctor\n"));+ for (const r of results) {+ const icon = r.ok ? chalk.green("✓") : chalk.red("✗");+ const detail = chalk.dim(` — ${r.detail}`);+ console.log(` ${icon} ${r.name}${detail}`);+ }++ const allOk = results.every((r) => r.ok);+ console.log();+ if (allOk) {+ console.log(chalk.green("All checks passed."));+ } else {+ console.log(chalk.red("Some checks failed. Run with --format json for details."));+ }+ console.log();+ });+}diff --git a/ix-cli/src/cli/commands/imports.ts b/ix-cli/src/cli/commands/imports.tsnew file mode 100644index 00000000..982f8114--- /dev/null+++ b/ix-cli/src/cli/commands/imports.ts@@ -0,0 +1,42 @@+import type { Command } from "commander";+import { IxClient } from "../../client/api.js";+import { getEndpoint } from "../config.js";+import { formatEdgeResults } from "../format.js";++export function registerImportsCommand(program: Command): void {+ program+ .command("imports <symbol>")+ .description("Show what the given entity imports")+ .option("--format <fmt>", "Output format (text|json)", "text")+ .action(async (symbol: string, opts: { format: string }) => {+ const client = new IxClient(getEndpoint());++ const nodes = await client.search(symbol, { limit: 1 });+ if (nodes.length === 0) {+ console.log(`No entity found matching "${symbol}".`);+ return;+ }+ const entityId = (nodes[0] as any).id;++ const result = await client.expand(entityId, { direction: "out", predicates: ["IMPORTS"] });+ formatEdgeResults(result.nodes, "imports", symbol, opts.format);+ });++ program+ .command("imported-by <symbol>")+ .description("Show what imports the given entity")+ .option("--format <fmt>", "Output format (text|json)", "text")+ .action(async (symbol: string, opts: { format: string }) => {+ const client = new IxClient(getEndpoint());++ const nodes = await client.search(symbol, { limit: 1 });+ if (nodes.length === 0) {+ console.log(`No entity found matching "${symbol}".`);+ return;+ }+ const entityId = (nodes[0] as any).id;++ const result = await client.expand(entityId, { direction: "in", predicates: ["IMPORTS"] });+ formatEdgeResults(result.nodes, "imported-by", symbol, opts.format);+ });+}diff --git a/ix-cli/src/cli/commands/stats.ts b/ix-cli/src/cli/commands/stats.tsnew file mode 100644index 00000000..62a1e861--- /dev/null+++ b/ix-cli/src/cli/commands/stats.ts@@ -0,0 +1,35 @@+import type { Command } from "commander";+import chalk from "chalk";+import { IxClient } from "../../client/api.js";+import { getEndpoint } from "../config.js";++export function registerStatsCommand(program: Command): void {+ program+ .command("stats")+ .description("Show graph statistics — node/edge counts by type")+ .option("--format <fmt>", "Output format (text|json)", "text")+ .action(async (opts: { format: string }) => {+ const client = new IxClient(getEndpoint());+ const result = await client.stats();++ if (opts.format === "json") {+ console.log(JSON.stringify(result, null, 2));+ return;+ }++ console.log(chalk.bold("\nnodes") + chalk.dim(` (${result.nodes.total} total)`));+ for (const entry of result.nodes.byKind) {+ const kind = entry.kind ?? "unknown";+ const count = entry.count ?? 0;+ console.log(` ${chalk.cyan(kind)}: ${count}`);+ }++ console.log(chalk.bold("\nedges") + chalk.dim(` (${result.edges.total} total)`));+ for (const entry of result.edges.byPredicate) {+ const pred = entry.predicate ?? "unknown";+ const count = entry.count ?? 0;+ console.log(` ${chalk.cyan(pred)}: ${count}`);+ }+ console.log();+ });+}diff --git a/ix-cli/src/cli/main.ts b/ix-cli/src/cli/main.tsindex 0bb616fa..139a4cb4 100644--- a/ix-cli/src/cli/main.ts+++ b/ix-cli/src/cli/main.ts@@ -18,6 +18,10 @@ import { registerTextCommand } from "./commands/text.js";import { registerLocateCommand } from "./commands/locate.js";import { registerExplainCommand } from "./commands/explain.js";import { registerCallersCommand } from "./commands/callers.js";+import { registerImportsCommand } from "./commands/imports.js";+import { registerContainsCommand } from "./commands/contains.js";+import { registerStatsCommand } from "./commands/stats.js";+import { registerDoctorCommand } from "./commands/doctor.js";const program = new Command();program@@ -43,6 +47,10 @@ registerTextCommand(program);registerLocateCommand(program);registerExplainCommand(program);registerCallersCommand(program);+registerImportsCommand(program);+registerContainsCommand(program);+registerStatsCommand(program);+registerDoctorCommand(program);program.command("mcp-start")diff --git a/ix-cli/src/client/api.ts b/ix-cli/src/client/api.tsindex 6825e360..d0a94a0f 100644--- a/ix-cli/src/client/api.ts+++ b/ix-cli/src/client/api.ts@@ -116,6 +116,10 @@ export class IxClient {return this.post(`/v1/provenance/${entityId}`, {});}+ async stats(): Promise<any> {+ return this.get("/v1/stats");+ }+async health(): Promise<HealthResponse> {return this.get("/v1/health");}diff --git a/ix-cli/src/mcp/server.ts b/ix-cli/src/mcp/server.tsindex 832a29b0..2d2d26ce 100644--- a/ix-cli/src/mcp/server.ts+++ b/ix-cli/src/mcp/server.ts@@ -1,7 +1,7 @@/*** Ix Memory MCP Server*- * Exposes 13 tools and 2 resources over the Model Context Protocol,+ * Exposes 14 tools and 2 resources over the Model Context Protocol,* providing persistent, time-aware memory to LLM coding assistants.*/@@ -345,7 +345,7 @@ server.tool(// --- ix_expand ---------------------------------------------------------------server.tool("ix_expand",- "Expand a node's neighborhood — retrieve connected nodes and edges.",+ "Expand a node's neighborhood — retrieve connected nodes and edges. Filter by direction and edge predicates (CALLS, IMPORTS, CONTAINS, etc.).",{nodeId: z.string().describe("Node ID to expand from"),hops: z@@ -354,15 +354,17 @@ server.tool(direction: z.optional(z.string()).describe("Edge direction: in | out | both (default both)"),+ predicates: z+ .optional(z.array(z.string()))+ .describe("Filter by edge predicates (e.g. ['CALLS', 'IMPORTS'])"),},- async ({ nodeId, hops: _hops, direction: _direction }) => {+ async ({ nodeId, hops, direction, predicates }) => {try {const resolvedId = await client.resolvePrefix(nodeId);- // The entity endpoint already returns edges; use it as the expansion source.- const entity = await client.entity(resolvedId);+ const result = await client.expand(resolvedId, { direction, predicates, hops });return {content: [- { type: "text" as const, text: JSON.stringify(entity, null, 2) },+ { type: "text" as const, text: JSON.stringify(result, null, 2) },],};} catch (err) {@@ -568,6 +570,30 @@ server.tool(},);+// --- ix_stats ----------------------------------------------------------------+server.tool(+ "ix_stats",+ "Get graph statistics — total node/edge counts broken down by kind and predicate.",+ {},+ async () => {+ try {+ const result = await client.stats();+ return {+ content: [+ { type: "text" as const, text: JSON.stringify(result, null, 2) },+ ],+ };+ } catch (err) {+ return {+ isError: true,+ content: [+ { type: "text" as const, text: `ix_stats failed: ${String(err)}` },+ ],+ };+ }+ },+);+// ============================= RESOURCES ====================================// --- ix://session/context ----------------------------------------------------diff --git a/memory-layer/src/main/scala/ix/memory/api/Routes.scala b/memory-layer/src/main/scala/ix/memory/api/Routes.scalaindex 9d507a43..c379c8f3 100644--- a/memory-layer/src/main/scala/ix/memory/api/Routes.scala+++ b/memory-layer/src/main/scala/ix/memory/api/Routes.scala@@ -41,9 +41,11 @@ object Routes {val patchRoutes = new PatchRoutes(client).routesval decisionListRoutes = new DecisionRoutes(queryApi).routesval expandRoutes = new ExpandRoutes(queryApi).routes+ val statsRoutes = new StatsRoutes(client).routeshealth <+> contextRoutes <+> ingestionRoutes <+> entityRoutes <+>diffRoutes <+> conflictRoutes <+> decideRoutes <+> searchRoutes <+>- truthRoutes <+> patchRoutes <+> decisionListRoutes <+> expandRoutes+ truthRoutes <+> patchRoutes <+> decisionListRoutes <+> expandRoutes <+>+ statsRoutes}}diff --git a/memory-layer/src/main/scala/ix/memory/api/StatsRoutes.scala b/memory-layer/src/main/scala/ix/memory/api/StatsRoutes.scalanew file mode 100644index 00000000..1bfb86a0--- /dev/null+++ b/memory-layer/src/main/scala/ix/memory/api/StatsRoutes.scala@@ -0,0 +1,53 @@+package ix.memory.api++import cats.effect.IO+import io.circe.Json+import io.circe.syntax._+import org.http4s.HttpRoutes+import org.http4s.circe.CirceEntityCodec._+import org.http4s.dsl.io._++import ix.memory.db.ArangoClient++class StatsRoutes(client: ArangoClient) {++ val routes: HttpRoutes[IO] = HttpRoutes.of[IO] {+ case GET -> Root / "v1" / "stats" =>+ (for {+ nodeStats <- client.query(+ """FOR n IN nodes+ | FILTER n.deleted_rev == null+ | COLLECT kind = n.kind WITH COUNT INTO cnt+ | SORT cnt DESC+ | RETURN { kind: kind, count: cnt }""".stripMargin,+ Map.empty[String, AnyRef]+ )+ edgeStats <- client.query(+ """FOR e IN edges+ | FILTER e.deleted_rev == null+ | COLLECT predicate = e.predicate WITH COUNT INTO cnt+ | SORT cnt DESC+ | RETURN { predicate: predicate, count: cnt }""".stripMargin,+ Map.empty[String, AnyRef]+ )+ totalNodes <- client.query(+ """RETURN LENGTH(FOR n IN nodes FILTER n.deleted_rev == null RETURN 1)""",+ Map.empty[String, AnyRef]+ )+ totalEdges <- client.query(+ """RETURN LENGTH(FOR e IN edges FILTER e.deleted_rev == null RETURN 1)""",+ Map.empty[String, AnyRef]+ )+ resp <- Ok(Json.obj(+ "nodes" -> Json.obj(+ "total" -> totalNodes.headOption.flatMap(_.asNumber).flatMap(_.toInt).getOrElse(0).asJson,+ "byKind" -> nodeStats.asJson+ ),+ "edges" -> Json.obj(+ "total" -> totalEdges.headOption.flatMap(_.asNumber).flatMap(_.toInt).getOrElse(0).asJson,+ "byPredicate" -> edgeStats.asJson+ )+ ))+ } yield resp).handleErrorWith(ErrorHandler.handle(_))+ }+}