Skip to content

armgit / Ix

Public Imported from GitHub
0

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

feat: ix init and ix mcp-install commands

riley0227bf9415c7ec69
diff --git a/ix-cli/src/cli/commands/init.ts b/ix-cli/src/cli/commands/init.ts
new file mode 100644
index 00000000..5e2af438
--- /dev/null
+++ b/ix-cli/src/cli/commands/init.ts
@@ -0,0 +1,56 @@
+import { mkdir, writeFile } from "node:fs/promises";
+import { join } from "node:path";
+import { homedir } from "node:os";
+import type { Command } from "commander";
+import { IxClient } from "../../client/api.js";
+import { getEndpoint } from "../config.js";
+
+const CLAUDE_MD = `# Ix Memory System
+
+This project uses Ix Memory for persistent, time-aware context.
+
+## MANDATORY RULES
+1. BEFORE answering any question about this codebase → call ix_query
+2. AFTER making any design/architecture decision → call ix_decide
+3. When noticing contradictory information → call ix_conflicts
+4. NEVER guess about codebase facts when Ix has structured data
+5. After modifying code → call ix_ingest on changed files
+6. At start of each session → review ix://session/context for prior work
+7. When the user states a goal → call ix_truth to record it
+`;
+
+export function registerInitCommand(program: Command): void {
+ program
+ .command("init")
+ .description("Initialize Ix in the current project")
+ .action(async () => {
+ console.log("Initializing Ix Memory...\n");
+
+ // 1. Check backend health
+ const client = new IxClient(getEndpoint());
+ try {
+ await client.health();
+ console.log(" [ok] Backend is running at " + getEndpoint());
+ } catch {
+ console.error(" [!!] Backend not reachable at " + getEndpoint());
+ console.error(" Run ./stack.sh first, or set IX_ENDPOINT.");
+ process.exit(1);
+ }
+
+ // 2. Create ~/.ix/config.yaml
+ const configDir = join(homedir(), ".ix");
+ await mkdir(configDir, { recursive: true });
+ await writeFile(
+ join(configDir, "config.yaml"),
+ `endpoint: ${getEndpoint()}\nformat: text\n`
+ );
+ console.log(" [ok] Created ~/.ix/config.yaml");
+
+ // 3. Create CLAUDE.md in project root
+ await writeFile("CLAUDE.md", CLAUDE_MD);
+ console.log(" [ok] Created CLAUDE.md");
+
+ console.log("\nIx Memory initialized.");
+ console.log("Next: run 'ix ingest ./src --recursive' to ingest your codebase.");
+ });
+}
diff --git a/ix-cli/src/cli/commands/mcp-install.ts b/ix-cli/src/cli/commands/mcp-install.ts
new file mode 100644
index 00000000..1c8507d5
--- /dev/null
+++ b/ix-cli/src/cli/commands/mcp-install.ts
@@ -0,0 +1,91 @@
+import { mkdir, writeFile, readFile } from "node:fs/promises";
+import { existsSync } from "node:fs";
+import { join } from "node:path";
+import { homedir } from "node:os";
+import type { Command } from "commander";
+
+interface McpConfig {
+ mcpServers: Record<string, {
+ command: string;
+ args: string[];
+ env?: Record<string, string>;
+ }>;
+}
+
+const ixMcpEntry = {
+ command: "npx",
+ args: ["tsx", join(process.cwd(), "ix-cli/src/mcp/server.ts")],
+ env: {
+ IX_ENDPOINT: "http://localhost:8090",
+ },
+};
+
+export function registerMcpInstallCommand(program: Command): void {
+ program
+ .command("mcp-install")
+ .description("Install Ix MCP server configuration")
+ .option("--cursor", "Configure for Cursor")
+ .option("--claude-code", "Configure for Claude Code")
+ .action(async (opts: { cursor?: boolean; claudeCode?: boolean }) => {
+ if (opts.cursor) {
+ await installCursor();
+ } else if (opts.claudeCode) {
+ await installClaudeCode();
+ } else {
+ await installClaudeDesktop();
+ }
+ });
+}
+
+async function installClaudeDesktop(): Promise<void> {
+ const platform = process.platform;
+ let configPath: string;
+ if (platform === "darwin") {
+ configPath = join(homedir(), "Library", "Application Support", "Claude", "claude_desktop_config.json");
+ } else if (platform === "win32") {
+ configPath = join(homedir(), "AppData", "Roaming", "Claude", "claude_desktop_config.json");
+ } else {
+ configPath = join(homedir(), ".config", "claude", "claude_desktop_config.json");
+ }
+
+ const config = await loadOrCreateConfig(configPath);
+ config.mcpServers["ix-memory"] = ixMcpEntry;
+ await mkdir(join(configPath, ".."), { recursive: true });
+ await writeFile(configPath, JSON.stringify(config, null, 2) + "\n");
+ console.log(` [ok] Installed Ix MCP server in Claude Desktop config`);
+ console.log(` ${configPath}`);
+ console.log(" Restart Claude Desktop to activate.");
+}
+
+async function installCursor(): Promise<void> {
+ const configPath = join(process.cwd(), ".cursor", "mcp.json");
+ const config = await loadOrCreateConfig(configPath);
+ config.mcpServers["ix-memory"] = ixMcpEntry;
+ await mkdir(join(configPath, ".."), { recursive: true });
+ await writeFile(configPath, JSON.stringify(config, null, 2) + "\n");
+ console.log(` [ok] Installed Ix MCP server in Cursor config`);
+ console.log(` ${configPath}`);
+}
+
+async function installClaudeCode(): Promise<void> {
+ const configPath = join(process.cwd(), ".claude", "settings.json");
+ const config = await loadOrCreateConfig(configPath);
+ config.mcpServers["ix-memory"] = ixMcpEntry;
+ await mkdir(join(configPath, ".."), { recursive: true });
+ await writeFile(configPath, JSON.stringify(config, null, 2) + "\n");
+ console.log(` [ok] Installed Ix MCP server in Claude Code config`);
+ console.log(` ${configPath}`);
+}
+
+async function loadOrCreateConfig(path: string): Promise<McpConfig> {
+ if (existsSync(path)) {
+ try {
+ const raw = await readFile(path, "utf-8");
+ const parsed = JSON.parse(raw) as Partial<McpConfig>;
+ return { mcpServers: {}, ...parsed };
+ } catch {
+ return { mcpServers: {} };
+ }
+ }
+ return { mcpServers: {} };
+}
diff --git a/ix-cli/src/cli/main.ts b/ix-cli/src/cli/main.ts
index 09f0556b..a0d3d554 100644
--- a/ix-cli/src/cli/main.ts
+++ b/ix-cli/src/cli/main.ts
@@ -11,6 +11,8 @@ import { registerEntityCommand } from "./commands/entity.js";
import { registerHistoryCommand } from "./commands/history.js";
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";
const program = new Command();
program
@@ -29,6 +31,8 @@ registerEntityCommand(program);
registerHistoryCommand(program);
registerConflictsCommand(program);
registerDiffCommand(program);
+registerInitCommand(program);
+registerMcpInstallCommand(program);
program
.command("mcp-start")