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 resultSource metadata to CLI edge/navigation commands

riley02272c7d4f87a785
diff --git a/ix-cli/src/cli/commands/callers.ts b/ix-cli/src/cli/commands/callers.ts
index e649b8f0..217d2793 100644
--- a/ix-cli/src/cli/commands/callers.ts
+++ b/ix-cli/src/cli/commands/callers.ts
@@ -21,7 +21,7 @@ export function registerCallersCommand(program: Command): void {
predicates: ["CALLS"],
kinds: ["function", "method"],
});
- formatEdgeResults(result.nodes, "callers", target.name, opts.format, target);
+ formatEdgeResults(result.nodes, "callers", target.name, opts.format, target, "graph");
});
program
@@ -40,6 +40,6 @@ export function registerCallersCommand(program: Command): void {
predicates: ["CALLS"],
kinds: ["function", "method"],
});
- formatEdgeResults(result.nodes, "callees", target.name, opts.format, target);
+ formatEdgeResults(result.nodes, "callees", target.name, opts.format, target, "graph");
});
}
diff --git a/ix-cli/src/cli/commands/contains.ts b/ix-cli/src/cli/commands/contains.ts
index 50f4e937..6b8767ea 100644
--- a/ix-cli/src/cli/commands/contains.ts
+++ b/ix-cli/src/cli/commands/contains.ts
@@ -16,6 +16,6 @@ export function registerContainsCommand(program: Command): void {
if (!target) return;
printResolved(target);
const result = await client.expand(target.id, { direction: "out", predicates: ["CONTAINS"] });
- formatEdgeResults(result.nodes, "contains", target.name, opts.format, target);
+ formatEdgeResults(result.nodes, "contains", target.name, opts.format, target, "graph");
});
}
diff --git a/ix-cli/src/cli/commands/depends.ts b/ix-cli/src/cli/commands/depends.ts
index c0f98b81..4f7a2a3e 100644
--- a/ix-cli/src/cli/commands/depends.ts
+++ b/ix-cli/src/cli/commands/depends.ts
@@ -48,6 +48,7 @@ export function registerDependsCommand(program: Command): void {
if (opts.format === "json") {
console.log(JSON.stringify({
+ resultSource: "graph" as const,
resolvedTarget: target,
directDependents: allDependents.map((d: any) => ({
id: d.id,
diff --git a/ix-cli/src/cli/commands/imports.ts b/ix-cli/src/cli/commands/imports.ts
index 48914707..85ec8d05 100644
--- a/ix-cli/src/cli/commands/imports.ts
+++ b/ix-cli/src/cli/commands/imports.ts
@@ -16,7 +16,7 @@ export function registerImportsCommand(program: Command): void {
if (!target) return;
printResolved(target);
const result = await client.expand(target.id, { direction: "out", predicates: ["IMPORTS"] });
- formatEdgeResults(result.nodes, "imports", target.name, opts.format, target);
+ formatEdgeResults(result.nodes, "imports", target.name, opts.format, target, "graph");
});
program
@@ -30,6 +30,6 @@ export function registerImportsCommand(program: Command): void {
if (!target) return;
printResolved(target);
const result = await client.expand(target.id, { direction: "in", predicates: ["IMPORTS"] });
- formatEdgeResults(result.nodes, "imported-by", target.name, opts.format, target);
+ formatEdgeResults(result.nodes, "imported-by", target.name, opts.format, target, "graph");
});
}
diff --git a/ix-cli/src/cli/format.ts b/ix-cli/src/cli/format.ts
index fd46bf7d..48c02f64 100644
--- a/ix-cli/src/cli/format.ts
+++ b/ix-cli/src/cli/format.ts
@@ -1,5 +1,7 @@
import chalk from "chalk";
+export type ResultSource = "graph" | "text" | "graph+text" | "heuristic";
+
export function confidenceColor(score: number): (text: string) => string {
if (score >= 0.8) return chalk.green;
if (score >= 0.5) return chalk.yellow;
@@ -310,11 +312,15 @@ export function formatLocateResults(results: LocateResult[], format: string): vo
export function formatEdgeResults(
nodes: any[], relation: string, symbol: string, format: string,
- resolvedTarget?: { id: string; kind: string; name: string }
+ resolvedTarget?: { id: string; kind: string; name: string; resolutionMode?: string },
+ source?: ResultSource
): void {
if (format === "json") {
- const output: any = { results: nodes };
- if (resolvedTarget) output.resolvedTarget = resolvedTarget;
+ const output: any = { results: nodes, resultSource: source ?? "graph" };
+ if (resolvedTarget) {
+ output.resolvedTarget = resolvedTarget;
+ output.resolutionMode = resolvedTarget.resolutionMode ?? "exact";
+ }
console.log(JSON.stringify(output, null, 2));
return;
}
@@ -323,6 +329,9 @@ export function formatEdgeResults(
return;
}
console.log(`${chalk.bold(relation)} of ${chalk.cyan(symbol)}:`);
+ if (source && source !== "graph") {
+ console.log(chalk.dim(`Source: ${source}`));
+ }
for (const n of nodes) {
const shortId = n.id?.slice(0, 8) ?? "";
const name = n.name || n.attrs?.name || n.id;
@@ -364,7 +373,7 @@ export interface ExplainResult {
export function formatExplain(result: ExplainResult, format: string): void {
if (format === "json") {
- console.log(JSON.stringify(result, null, 2));
+ console.log(JSON.stringify({ ...result, resultSource: "graph" }, null, 2));
return;
}
const shortId = result.id.slice(0, 8);