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 ix text command for fast lexical search via ripgrep

riley0227bb45feb1cde9
diff --git a/ix-cli/src/cli/commands/text.ts b/ix-cli/src/cli/commands/text.ts
new file mode 100644
index 00000000..36373450
--- /dev/null
+++ b/ix-cli/src/cli/commands/text.ts
@@ -0,0 +1,57 @@
+import { execFile } from "node:child_process";
+import { promisify } from "node:util";
+import type { Command } from "commander";
+import { formatTextResults, type TextResult } from "../format.js";
+
+const execFileAsync = promisify(execFile);
+
+export function registerTextCommand(program: Command): void {
+ program
+ .command("text <term>")
+ .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("--format <fmt>", "Output format (text|json)", "text")
+ .action(async (term: string, opts: { limit: string; path: string; format: string }) => {
+ const limit = parseInt(opts.limit, 10);
+ try {
+ const { stdout } = await execFileAsync("rg", [
+ "--json",
+ "--max-count", String(limit),
+ "--no-heading",
+ term,
+ opts.path,
+ ], { maxBuffer: 10 * 1024 * 1024 });
+
+ const results: TextResult[] = [];
+ for (const line of stdout.split("\n")) {
+ if (!line.trim()) continue;
+ try {
+ const parsed = JSON.parse(line);
+ if (parsed.type === "match") {
+ const data = parsed.data;
+ results.push({
+ path: data.path?.text ?? "",
+ line: data.line_number ?? 0,
+ snippet: data.lines?.text ?? "",
+ });
+ }
+ } catch {
+ // skip non-JSON lines
+ }
+ }
+
+ formatTextResults(results.slice(0, limit), opts.format);
+ } catch (err: any) {
+ if (err.code === "ENOENT") {
+ console.error("Error: ripgrep (rg) is not installed. Install it: https://github.com/BurntSushi/ripgrep#installation");
+ process.exit(1);
+ }
+ if (err.code === 1 || err.status === 1) {
+ formatTextResults([], opts.format);
+ } else {
+ throw err;
+ }
+ }
+ });
+}
diff --git a/ix-cli/src/cli/format.ts b/ix-cli/src/cli/format.ts
index e80b73ae..22635d8b 100644
--- a/ix-cli/src/cli/format.ts
+++ b/ix-cli/src/cli/format.ts
@@ -211,6 +211,30 @@ export function formatDiff(result: any, format: string): void {
}
}
+export interface TextResult {
+ path: string;
+ line: number;
+ snippet: string;
+ score?: number;
+ symbol?: string;
+}
+
+export function formatTextResults(results: TextResult[], format: string): void {
+ if (format === "json") {
+ console.log(JSON.stringify(results, null, 2));
+ return;
+ }
+ if (results.length === 0) {
+ console.log("No text matches found.");
+ return;
+ }
+ for (const r of results) {
+ console.log(
+ ` ${chalk.dim(r.path)}${chalk.cyan(":" + r.line)} ${r.snippet.trim()}`
+ );
+ }
+}
+
export function formatConflicts(conflicts: any[], format: string): void {
if (format === "json") {
console.log(JSON.stringify(conflicts, null, 2));
diff --git a/ix-cli/src/cli/main.ts b/ix-cli/src/cli/main.ts
index fc809646..6502e9b6 100644
--- a/ix-cli/src/cli/main.ts
+++ b/ix-cli/src/cli/main.ts
@@ -14,6 +14,7 @@ import { registerConflictsCommand } from "./commands/conflicts.js";
import { registerDiffCommand } from "./commands/diff.js";
import { registerInitCommand } from "./commands/init.js";
import { registerMcpInstallCommand } from "./commands/mcp-install.js";
+import { registerTextCommand } from "./commands/text.js";
const program = new Command();
program
@@ -35,6 +36,7 @@ registerConflictsCommand(program);
registerDiffCommand(program);
registerInitCommand(program);
registerMcpInstallCommand(program);
+registerTextCommand(program);
program
.command("mcp-start")