Skip to content

armgit / Ix

Public Imported from GitHub
0

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

feat: standardize ix text schema and add --language filter

riley02270d597f492d44
diff --git a/ix-cli/src/cli/__tests__/format.test.ts b/ix-cli/src/cli/__tests__/format.test.ts
index 7d8e91a0..c401732c 100644
--- a/ix-cli/src/cli/__tests__/format.test.ts
+++ b/ix-cli/src/cli/__tests__/format.test.ts
@@ -307,7 +307,7 @@ describe("formatDecisions", () => {
describe("formatTextResults", () => {
it("should output JSON when format is json", () => {
const spy = vi.spyOn(console, "log").mockImplementation(() => {});
- const results = [{ path: "src/foo.ts", line: 42, snippet: "const foo = bar;" }];
+ const results = [{ path: "src/foo.ts", line_start: 42, line_end: 42, snippet: "const foo = bar;", engine: "ripgrep", score: 1.0 }];
formatTextResults(results, "json");
expect(spy).toHaveBeenCalledWith(JSON.stringify(results, null, 2));
spy.mockRestore();
@@ -320,9 +320,9 @@ describe("formatTextResults", () => {
spy.mockRestore();
});
- it("should display path:line and snippet in text mode", () => {
+ it("should display path:line_start and snippet in text mode", () => {
const spy = vi.spyOn(console, "log").mockImplementation(() => {});
- const results = [{ path: "src/foo.ts", line: 42, snippet: "const foo = bar;" }];
+ const results = [{ path: "src/foo.ts", line_start: 42, line_end: 42, snippet: "const foo = bar;", engine: "ripgrep", score: 1.0 }];
formatTextResults(results, "text");
const output = spy.mock.calls.map(c => c[0]).join("\n");
expect(output).toContain("src/foo.ts");
diff --git a/ix-cli/src/cli/commands/text.ts b/ix-cli/src/cli/commands/text.ts
index 36373450..a29a529c 100644
--- a/ix-cli/src/cli/commands/text.ts
+++ b/ix-cli/src/cli/commands/text.ts
@@ -11,17 +11,26 @@ export function registerTextCommand(program: Command): void {
.description("Fast lexical/text search across the codebase (uses ripgrep)")
.option("--limit <n>", "Max results", "20")
.option("--path <dir>", "Restrict search to a directory", ".")
+ .option("--language <lang>", "Filter by language (python, typescript, scala, etc.)")
.option("--format <fmt>", "Output format (text|json)", "text")
- .action(async (term: string, opts: { limit: string; path: string; format: string }) => {
+ .action(async (term: string, opts: { limit: string; path: string; format: string; language?: string }) => {
const limit = parseInt(opts.limit, 10);
try {
- const { stdout } = await execFileAsync("rg", [
+ const rgArgs = [
"--json",
"--max-count", String(limit),
"--no-heading",
- term,
- opts.path,
- ], { maxBuffer: 10 * 1024 * 1024 });
+ ];
+
+ if (opts.language) {
+ for (const g of languageGlobs(opts.language)) {
+ rgArgs.push("--glob", g);
+ }
+ }
+
+ rgArgs.push(term, opts.path);
+
+ const { stdout } = await execFileAsync("rg", rgArgs, { maxBuffer: 10 * 1024 * 1024 });
const results: TextResult[] = [];
for (const line of stdout.split("\n")) {
@@ -30,10 +39,16 @@ export function registerTextCommand(program: Command): void {
const parsed = JSON.parse(line);
if (parsed.type === "match") {
const data = parsed.data;
+ const filePath = data.path?.text ?? "";
+ const lineNum = data.line_number ?? 0;
results.push({
- path: data.path?.text ?? "",
- line: data.line_number ?? 0,
+ path: filePath,
+ line_start: lineNum,
+ line_end: lineNum,
snippet: data.lines?.text ?? "",
+ engine: "ripgrep",
+ score: 1.0,
+ language: inferLanguage(filePath),
});
}
} catch {
@@ -55,3 +70,34 @@ export function registerTextCommand(program: Command): void {
}
});
}
+
+function inferLanguage(filePath: string): string | undefined {
+ if (filePath.endsWith(".py")) return "python";
+ if (filePath.endsWith(".ts") || filePath.endsWith(".tsx")) return "typescript";
+ if (filePath.endsWith(".js") || filePath.endsWith(".jsx")) return "javascript";
+ if (filePath.endsWith(".scala") || filePath.endsWith(".sc")) return "scala";
+ if (filePath.endsWith(".java")) return "java";
+ if (filePath.endsWith(".go")) return "go";
+ if (filePath.endsWith(".rs")) return "rust";
+ if (filePath.endsWith(".rb")) return "ruby";
+ if (filePath.endsWith(".md")) return "markdown";
+ if (filePath.endsWith(".json")) return "json";
+ if (filePath.endsWith(".yaml") || filePath.endsWith(".yml")) return "yaml";
+ return undefined;
+}
+
+function languageGlobs(lang: string): string[] {
+ switch (lang) {
+ case "python": return ["*.py"];
+ case "typescript": return ["*.ts", "*.tsx"];
+ case "javascript": return ["*.js", "*.jsx", "*.mjs", "*.cjs"];
+ case "scala": return ["*.scala", "*.sc"];
+ case "java": return ["*.java"];
+ case "go": return ["*.go"];
+ case "rust": return ["*.rs"];
+ case "ruby": return ["*.rb"];
+ case "markdown": return ["*.md", "*.mdx"];
+ case "config": return ["*.json", "*.yaml", "*.yml", "*.toml"];
+ default: return [`*.${lang}`];
+ }
+}
diff --git a/ix-cli/src/cli/format.ts b/ix-cli/src/cli/format.ts
index 22635d8b..1c030095 100644
--- a/ix-cli/src/cli/format.ts
+++ b/ix-cli/src/cli/format.ts
@@ -213,10 +213,13 @@ export function formatDiff(result: any, format: string): void {
export interface TextResult {
path: string;
- line: number;
+ line_start: number;
+ line_end: number;
snippet: string;
- score?: number;
- symbol?: string;
+ engine: string;
+ score: number;
+ language?: string;
+ symbol_hint?: string;
}
export function formatTextResults(results: TextResult[], format: string): void {
@@ -229,8 +232,10 @@ export function formatTextResults(results: TextResult[], format: string): void {
return;
}
for (const r of results) {
+ const lang = r.language ? chalk.magenta(`[${r.language}]`) + " " : "";
+ const sym = r.symbol_hint ? chalk.yellow(`(${r.symbol_hint})`) + " " : "";
console.log(
- ` ${chalk.dim(r.path)}${chalk.cyan(":" + r.line)} ${r.snippet.trim()}`
+ ` ${lang}${chalk.dim(r.path)}${chalk.cyan(":" + r.line_start)} ${sym}${r.snippet.trim()}`
);
}
}
diff --git a/ix-cli/src/mcp/server.ts b/ix-cli/src/mcp/server.ts
index 90fcbd77..832a29b0 100644
--- a/ix-cli/src/mcp/server.ts
+++ b/ix-cli/src/mcp/server.ts
@@ -465,8 +465,9 @@ server.tool(
term: z.string().describe("Text/pattern to search for"),
limit: z.optional(z.number()).describe("Max results (default 20)"),
path: z.optional(z.string()).describe("Restrict search to a directory path"),
+ language: z.optional(z.string()).describe("Filter by language (python, typescript, scala, etc.)"),
},
- async ({ term, limit, path }) => {
+ async ({ term, limit, path, language }) => {
try {
const { execFile } = await import("node:child_process");
const { promisify } = await import("node:util");
@@ -474,15 +475,23 @@ server.tool(
const maxResults = limit ?? 20;
const searchPath = path ?? ".";
- const { stdout } = await execFileAsync("rg", [
+ const rgArgs = [
"--json",
"--max-count", String(maxResults),
"--no-heading",
- term,
- searchPath,
- ], { maxBuffer: 10 * 1024 * 1024 });
+ ];
- const results: Array<{ path: string; line: number; snippet: string }> = [];
+ if (language) {
+ for (const g of ixTextLanguageGlobs(language)) {
+ rgArgs.push("--glob", g);
+ }
+ }
+
+ rgArgs.push(term, searchPath);
+
+ const { stdout } = await execFileAsync("rg", rgArgs, { maxBuffer: 10 * 1024 * 1024 });
+
+ const results: Array<{ path: string; line_start: number; line_end: number; snippet: string; engine: string; score: number }> = [];
for (const line of stdout.split("\n")) {
if (!line.trim()) continue;
try {
@@ -491,8 +500,11 @@ server.tool(
const data = parsed.data;
results.push({
path: data.path?.text ?? "",
- line: data.line_number ?? 0,
+ line_start: data.line_number ?? 0,
+ line_end: data.line_number ?? 0,
snippet: (data.lines?.text ?? "").trim(),
+ engine: "ripgrep",
+ score: 1.0,
});
}
} catch { /* skip */ }
@@ -608,6 +620,24 @@ server.resource(
},
);
+// ============================= HELPERS ======================================
+
+function ixTextLanguageGlobs(lang: string): string[] {
+ switch (lang) {
+ case "python": return ["*.py"];
+ case "typescript": return ["*.ts", "*.tsx"];
+ case "javascript": return ["*.js", "*.jsx", "*.mjs", "*.cjs"];
+ case "scala": return ["*.scala", "*.sc"];
+ case "java": return ["*.java"];
+ case "go": return ["*.go"];
+ case "rust": return ["*.rs"];
+ case "ruby": return ["*.rb"];
+ case "markdown": return ["*.md", "*.mdx"];
+ case "config": return ["*.json", "*.yaml", "*.yml", "*.toml"];
+ default: return [`*.${lang}`];
+ }
+}
+
// ============================= START ========================================
const transport = new StdioServerTransport();