Skip to content

armgit / Ix

Public Imported from GitHub
0

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

refactor(client): build every IxClient through one factory

KageBinary11824d3a5de7
diff --git a/ix-cli/eslint.config.js b/ix-cli/eslint.config.js
index 5f9623ff..40acba99 100644
--- a/ix-cli/eslint.config.js
+++ b/ix-cli/eslint.config.js
@@ -56,6 +56,21 @@ export default tseslint.config(
"no-control-regex": "off",
},
},
+ {
+ // Every client comes from createClient() in client/factory.ts, so a token,
+ // an abort signal, a limiter or a deadline is added in one place.
+ files: ["src/**/*.ts"],
+ ignores: ["src/client/**", "src/**/__tests__/**"],
+ rules: {
+ "no-restricted-syntax": [
+ "error",
+ {
+ selector: "NewExpression[callee.name='IxClient']",
+ message: "Build clients with createClient() from client/factory.ts, not new IxClient().",
+ },
+ ],
+ },
+ },
{
// Tests exercise odd shapes deliberately; relax the strictest type rules.
files: ["src/**/__tests__/**", "test/**"],
diff --git a/ix-cli/src/cli/bootstrap.ts b/ix-cli/src/cli/bootstrap.ts
index 076706fb..4b86a90f 100644
--- a/ix-cli/src/cli/bootstrap.ts
+++ b/ix-cli/src/cli/bootstrap.ts
@@ -5,7 +5,7 @@ import { join, basename, resolve } from "node:path";
import { homedir } from "node:os";
import { execFileSync } from "node:child_process";
import chalk from "chalk";
-import { IxClient } from "../client/api.js";
+import { createClient } from "../client/factory.js";
import { renderBanner } from "./banner.js";
import { canonicalWorkspacePath, getEndpoint, gitRootFor, loadConfig, loadWorkspaces, saveConfig, findWorkspaceForCwd, type WorkspaceConfig } from "./config.js";
import { WorkspaceNotMappedError, workspaceNotMappedHint } from "./errors.js";
@@ -200,7 +200,7 @@ export function canAutoStartBackend(endpoint: string): boolean {
*/
export async function ensureBackendAvailable(): Promise<void> {
const endpoint = getEndpoint();
- const client = new IxClient(endpoint);
+ const client = createClient({ endpoint });
try {
// Through readBackendHealth so this probe records the release the backend
// reports, like every other health fetch. `ix init` never reaches the
diff --git a/ix-cli/src/cli/commands/around.ts b/ix-cli/src/cli/commands/around.ts
index 5c49682d..491cb5fd 100644
--- a/ix-cli/src/cli/commands/around.ts
+++ b/ix-cli/src/cli/commands/around.ts
@@ -4,8 +4,8 @@ import * as fs from "node:fs";
import * as path from "node:path";
import type { Command } from "commander";
import chalk from "chalk";
-import { IxClient } from "../../client/api.js";
-import { getEndpoint, resolveWorkspaceRoot } from "../config.js";
+import { createClient } from "../../client/factory.js";
+import { resolveWorkspaceRoot } from "../config.js";
import { printJson } from "../format.js";
import { llmError, printLlmLines } from "../llm.js";
import { parseBudgetOption } from "../options.js";
@@ -106,7 +106,7 @@ Examples:
const lines = readLines(abs);
const limit = Math.max(1, parseInt(opts.limit, 10) || DEFAULT_CAPS.callers);
const caps = capsFor(limit);
- const client = new IxClient(getEndpoint());
+ const client = createClient();
let result: AroundResult;
try {
diff --git a/ix-cli/src/cli/commands/callers.ts b/ix-cli/src/cli/commands/callers.ts
index f077f927..96b6ff69 100644
--- a/ix-cli/src/cli/commands/callers.ts
+++ b/ix-cli/src/cli/commands/callers.ts
@@ -4,8 +4,8 @@ import { execFile } from "node:child_process";
import { promisify } from "node:util";
import type { Command } from "commander";
import chalk from "chalk";
-import { IxClient } from "../../client/api.js";
-import { getEndpoint, resolveWorkspaceRoot } from "../config.js";
+import { createClient } from "../../client/factory.js";
+import { resolveWorkspaceRoot } from "../config.js";
import { formatEdgeResults, printJson, relativePath, sliceEdgeResults, type Diagnostic } from "../format.js";
import { checkGraphHealth, graphHealthProse, isUnhealthy, type GraphHealth } from "../graph-health.js";
import { parsePickOption } from "../options.js";
@@ -44,7 +44,7 @@ export function registerCallersCommand(program: Command): void {
.option("--format <fmt>", "Output format (text|json|llm)", "text")
.addHelpText("after", "\nExamples:\n ix callers verify_token\n ix callers processPayment --format json\n ix callers parse --kind method --limit 20")
.action(async (symbol: string, opts: { kind?: string; path?: string; pick?: number; limit: string; format: string }) => {
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const limit = parseInt(opts.limit, 10);
const resolveOpts = { kind: opts.kind, path: opts.path, pick: opts.pick };
const target = await resolveFileOrReport(client, symbol, resolveOpts, opts.format);
@@ -166,7 +166,7 @@ export function registerCallersCommand(program: Command): void {
.option("--format <fmt>", "Output format (text|json|llm)", "text")
.addHelpText("after", "\nExamples:\n ix callees processPayment\n ix callees parse --format json")
.action(async (symbol: string, opts: { kind?: string; path?: string; pick?: number; limit: string; format: string }) => {
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const calleeLimit = parseInt(opts.limit, 10);
const resolveOpts = { kind: opts.kind, path: opts.path, pick: opts.pick };
const target = await resolveFileOrReport(client, symbol, resolveOpts, opts.format);
diff --git a/ix-cli/src/cli/commands/conflicts.ts b/ix-cli/src/cli/commands/conflicts.ts
index 5ae490e6..7d414e2a 100644
--- a/ix-cli/src/cli/commands/conflicts.ts
+++ b/ix-cli/src/cli/commands/conflicts.ts
@@ -1,8 +1,7 @@
// Copyright 2026 Ix Infrastructure Inc.
import type { Command } from "commander";
-import { IxClient } from "../../client/api.js";
-import { getEndpoint } from "../config.js";
+import { createClient } from "../../client/factory.js";
import { formatConflicts } from "../format.js";
export function registerConflictsCommand(program: Command): void {
@@ -11,7 +10,7 @@ export function registerConflictsCommand(program: Command): void {
.description("List detected conflicts")
.option("--format <fmt>", "Output format (text|json|llm)", "text")
.action(async (opts: { format: string }) => {
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const conflicts = await client.conflicts();
formatConflicts(conflicts as any[], opts.format);
});
diff --git a/ix-cli/src/cli/commands/contains.ts b/ix-cli/src/cli/commands/contains.ts
index e962045c..676b43df 100644
--- a/ix-cli/src/cli/commands/contains.ts
+++ b/ix-cli/src/cli/commands/contains.ts
@@ -1,8 +1,7 @@
// Copyright 2026 Ix Infrastructure Inc.
import type { Command } from "commander";
-import { IxClient } from "../../client/api.js";
-import { getEndpoint } from "../config.js";
+import { createClient } from "../../client/factory.js";
import { formatEdgeResults, sliceEdgeResults } from "../format.js";
import { parsePickOption } from "../options.js";
import { resolveFileOrReport, printResolved } from "../resolve.js";
@@ -18,7 +17,7 @@ export function registerContainsCommand(program: Command): void {
.option("--format <fmt>", "Output format (text|json|llm)", "text")
.addHelpText("after", "\nExamples:\n ix contains IngestionService\n ix contains auth.py --kind file --format json\n ix contains MyClass --limit 20\n ix contains package --path crates/regex/Cargo.toml")
.action(async (symbol: string, opts: { kind?: string; path?: string; pick?: number; limit: string; format: string }) => {
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const limit = parseInt(opts.limit, 10);
const resolveOpts = { kind: opts.kind, path: opts.path, pick: opts.pick };
const target = await resolveFileOrReport(client, symbol, resolveOpts, opts.format);
diff --git a/ix-cli/src/cli/commands/context.ts b/ix-cli/src/cli/commands/context.ts
index aeeaf67f..1eaf2258 100644
--- a/ix-cli/src/cli/commands/context.ts
+++ b/ix-cli/src/cli/commands/context.ts
@@ -12,7 +12,7 @@ import {
} from "../context-bundle-schema.js";
import { IxClient } from "../../client/api.js";
-import { QUERY_CLIENT_OPTIONS } from "../../client/request-memo.js";
+import { createClient } from "../../client/factory.js";
import type {
ConflictReport,
DecisionReport,
@@ -20,7 +20,7 @@ import type {
IntentReport,
StructuredContext,
} from "../../client/types.js";
-import { getEndpoint, resolveWorkspaceRoot } from "../config.js";
+import { resolveWorkspaceRoot } from "../config.js";
import { collectFacts, type ContextFacts, type EntityLocation } from "../explain/facts.js";
import {
CENTRE_FALLBACK_TRIES,
@@ -456,7 +456,7 @@ export function registerContextCommand(program: Command): void {
return;
}
- const client = new IxClient(getEndpoint(), undefined, QUERY_CLIENT_OPTIONS);
+ const client = createClient({ query: true });
const resolved = await resolveFileOrReport(client, target, {
kind: opts.kind,
@@ -571,7 +571,7 @@ async function buildFreshBundle(
budgets: BudgetSnapshot,
format: string,
): Promise<ContextBundle | undefined> {
- const client = new IxClient(getEndpoint(), undefined, QUERY_CLIENT_OPTIONS);
+ const client = createClient({ query: true });
const resolved = await resolveFileOrReport(client, target, {
kind: opts.kind,
path: opts.path,
@@ -1675,7 +1675,7 @@ async function buildIssueBundle(
): Promise<ContextBundle | undefined> {
const text = await readIssueOrReport(arg, opts.format);
if (text === undefined) return undefined;
- const client = new IxClient(getEndpoint(), undefined, QUERY_CLIENT_OPTIONS);
+ const client = createClient({ query: true });
const plan = await planIssueWith(client, text);
// A path start has no node yet, and the graph may not have one either: it
// does not index every tracked file. chooseCentre walks BM25 for one it does.
@@ -1776,7 +1776,7 @@ async function planIssueWith(client: IxClient, text: string) {
async function emitLeanIssue(arg: string, opts: ContextOptions): Promise<void> {
const text = await readIssueOrReport(arg, opts.format);
if (text === undefined) return;
- const view = leanIssueView(await planIssueWith(new IxClient(getEndpoint(), undefined, QUERY_CLIENT_OPTIONS), text));
+ const view = leanIssueView(await planIssueWith(createClient({ query: true }), text));
if (opts.format === "json") {
printJson({ kind: "issue_lean", ...view });
} else if (opts.format === "llm") {
diff --git a/ix-cli/src/cli/commands/depends.ts b/ix-cli/src/cli/commands/depends.ts
index dcfdcd24..981e1b44 100644
--- a/ix-cli/src/cli/commands/depends.ts
+++ b/ix-cli/src/cli/commands/depends.ts
@@ -3,7 +3,7 @@
import type { Command } from "commander";
import chalk from "chalk";
import { IxClient } from "../../client/api.js";
-import { getEndpoint } from "../config.js";
+import { createClient } from "../../client/factory.js";
import { resolveFileOrReport, printResolved, isRawId } from "../resolve.js";
import { walkTree, type TreeWalkResult } from "../tree-walk.js";
import { compactTreeNode, relativePath, printJson } from "../format.js";
@@ -206,7 +206,7 @@ export function registerDependsCommand(program: Command): void {
ix depends parser.py --kind file
ix depends NodeKind --pick 1 --cap 500`)
.action(async (symbol: string, opts: { kind?: string; path?: string; pick?: number; depth?: string; cap?: string; format: string; includeTests?: boolean; testsOnly?: boolean }) => {
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const resolveOpts = {
kind: opts.kind,
diff --git a/ix-cli/src/cli/commands/diff.ts b/ix-cli/src/cli/commands/diff.ts
index 41af339b..691c16d9 100644
--- a/ix-cli/src/cli/commands/diff.ts
+++ b/ix-cli/src/cli/commands/diff.ts
@@ -8,8 +8,9 @@ import { promisify } from "node:util";
import type { Command } from "commander";
import chalk from "chalk";
import { IxClient } from "../../client/api.js";
+import { createClient } from "../../client/factory.js";
-import { absoluteFromSourceUri, getEndpoint, resolveWorkspaceRoot } from "../config.js";
+import { absoluteFromSourceUri, resolveWorkspaceRoot } from "../config.js";
import { resolveFileOrReport, printResolved, type ResolvedEntity } from "../resolve.js";
import { formatDiff, relativePath, printJson } from "../format.js";
import { llmLine } from "../llm.js";
@@ -491,7 +492,7 @@ export function registerDiffCommand(program: Command): void {
reportFailure("mode_conflict", conflict, opts.format);
return;
}
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const from = parseInt(fromRev, 10);
const to = parseInt(toRev, 10);
diff --git a/ix-cli/src/cli/commands/doctor.ts b/ix-cli/src/cli/commands/doctor.ts
index d8341ddf..a8c7413c 100644
--- a/ix-cli/src/cli/commands/doctor.ts
+++ b/ix-cli/src/cli/commands/doctor.ts
@@ -3,7 +3,7 @@
import type { Command } from "commander";
import chalk from "chalk";
import { renderSection, renderSuccess, renderError } from "../ui.js";
-import { IxClient } from "../../client/api.js";
+import { createClient } from "../../client/factory.js";
import {
canonicalWorkspacePath,
findWorkspaceForCwd,
@@ -207,7 +207,7 @@ export function registerDoctorCommand(program: Command): void {
.option("--format <fmt>", "Output format (text|json|llm)", "text")
.action(async (opts: { format: string }) => {
const endpoint = getEndpoint();
- const client = new IxClient(endpoint);
+ const client = createClient({ endpoint });
// "Graph has nodes" and "Graph has edges" are two questions about one
// response. They were two `client.stats()` calls, run back to back by the
diff --git a/ix-cli/src/cli/commands/entity.ts b/ix-cli/src/cli/commands/entity.ts
index cedf59dc..28dca814 100644
--- a/ix-cli/src/cli/commands/entity.ts
+++ b/ix-cli/src/cli/commands/entity.ts
@@ -2,8 +2,7 @@
import type { Command } from "commander";
import chalk from "chalk";
-import { IxClient } from "../../client/api.js";
-import { getEndpoint } from "../config.js";
+import { createClient } from "../../client/factory.js";
import { lineSpan, relativePath, rowLocation, stripNulls, printJson } from "../format.js";
import { llmLine, llmShortId } from "../llm.js";
@@ -39,7 +38,7 @@ export function registerEntityCommand(program: Command): void {
.description("Get entity details with claims and edges")
.option("--format <fmt>", "Output format (text|json|llm)", "text")
.action(async (id: string, opts: { format: string }) => {
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const resolvedId = await client.resolvePrefix(id);
const result = await client.entity(resolvedId);
if (opts.format === "json") {
diff --git a/ix-cli/src/cli/commands/explain.ts b/ix-cli/src/cli/commands/explain.ts
index 589ef666..c602528f 100644
--- a/ix-cli/src/cli/commands/explain.ts
+++ b/ix-cli/src/cli/commands/explain.ts
@@ -2,8 +2,7 @@
import type { Command } from "commander";
import { IxClient } from "../../client/api.js";
-import { QUERY_CLIENT_OPTIONS } from "../../client/request-memo.js";
-import { getEndpoint } from "../config.js";
+import { createClient } from "../../client/factory.js";
import { formatExplain, relativePath, printJson, type ExplainResult, type EntityRef, type Diagnostic } from "../format.js";
import { resolveFileOrReport, isRawId, activeReadScope } from "../resolve.js";
import { isFileStale } from "../stale.js";
@@ -31,7 +30,7 @@ export function registerExplainCommand(program: Command): void {
.option("--raw", "Show raw metadata dump (legacy format)")
.addHelpText("after", "\nExamples:\n ix explain IngestionService\n ix explain expand --path memory-layer\n ix explain verify_token --kind function --format json\n ix explain IxClient --raw")
.action(async (symbol: string, opts: { kind?: string; path?: string; pick?: number; format: string; raw?: boolean }) => {
- const client = new IxClient(getEndpoint(), undefined, QUERY_CLIENT_OPTIONS);
+ const client = createClient({ query: true });
const resolveOpts = { kind: opts.kind, path: opts.path, pick: opts.pick };
const target = await resolveFileOrReport(client, symbol, resolveOpts, opts.format);
if (!target) return;
diff --git a/ix-cli/src/cli/commands/history.ts b/ix-cli/src/cli/commands/history.ts
index 0e371bb3..fe820b05 100644
--- a/ix-cli/src/cli/commands/history.ts
+++ b/ix-cli/src/cli/commands/history.ts
@@ -2,8 +2,7 @@
import type { Command } from "commander";
import chalk from "chalk";
-import { IxClient } from "../../client/api.js";
-import { getEndpoint } from "../config.js";
+import { createClient } from "../../client/factory.js";
import { resolveFileOrReport, printResolved } from "../resolve.js";
import { relativePath, printJson } from "../format.js";
import { llmLine } from "../llm.js";
@@ -39,7 +38,7 @@ export function registerHistoryCommand(program: Command): void {
ix history IngestionService --kind class
ix history <entity-uuid>`)
.action(async (target: string, opts: { kind?: string; path?: string; pick?: number; format: string }) => {
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const resolveOpts = { kind: opts.kind, path: opts.path, pick: opts.pick };
const resolved = await resolveFileOrReport(client, target, resolveOpts, opts.format);
if (!resolved) return;
diff --git a/ix-cli/src/cli/commands/impact.ts b/ix-cli/src/cli/commands/impact.ts
index 756568b3..33c38074 100644
--- a/ix-cli/src/cli/commands/impact.ts
+++ b/ix-cli/src/cli/commands/impact.ts
@@ -4,8 +4,7 @@ import type { Command } from "commander";
import chalk from "chalk";
import { renderSection, renderKeyValue, renderNote, renderResolvedHeader, renderWarning, colorizeKind } from "../ui.js";
import { IxClient } from "../../client/api.js";
-import { QUERY_CLIENT_OPTIONS } from "../../client/request-memo.js";
-import { getEndpoint } from "../config.js";
+import { createClient } from "../../client/factory.js";
import { activeReadScope, resolveFileOrReport, printResolved } from "../resolve.js";
import { checkGraphHealth, graphHealthJson, graphHealthLlmFields, graphHealthProse, isUnhealthy } from "../graph-health.js";
import { bucketByHierarchy, getSystemPath, formatSystemPath, hasMapData, type SystemPath } from "../hierarchy.js";
@@ -35,7 +34,7 @@ export function registerImpactCommand(program: Command): void {
symbol: string,
opts: { kind?: string; path?: string; pick?: number; depth: string; limit: string; format: string }
) => {
- const client = new IxClient(getEndpoint(), undefined, QUERY_CLIENT_OPTIONS);
+ const client = createClient({ query: true });
const limit = parseInt(opts.limit, 10);
const depth = Math.min(Math.max(parseInt(opts.depth, 10) || 1, 1), 3);
diff --git a/ix-cli/src/cli/commands/imports.ts b/ix-cli/src/cli/commands/imports.ts
index 8523be75..b4105c4f 100644
--- a/ix-cli/src/cli/commands/imports.ts
+++ b/ix-cli/src/cli/commands/imports.ts
@@ -1,8 +1,7 @@
// Copyright 2026 Ix Infrastructure Inc.
import type { Command } from "commander";
-import { IxClient } from "../../client/api.js";
-import { getEndpoint } from "../config.js";
+import { createClient } from "../../client/factory.js";
import { formatEdgeResults, sliceEdgeResults } from "../format.js";
import { resolveFileOrReport, printResolved } from "../resolve.js";
import { parsePickOption } from "../options.js";
@@ -19,7 +18,7 @@ export function registerImportsCommand(program: Command): void {
.option("--format <fmt>", "Output format (text|json|llm)", "text")
.addHelpText("after", "\nExamples:\n ix imports auth.py\n ix imports IngestionService --format json")
.action(async (symbol: string, opts: { kind?: string; path?: string; pick?: number; limit: string; format: string }) => {
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const limit = parseInt(opts.limit, 10);
const resolveOpts = { kind: opts.kind, path: opts.path, pick: opts.pick };
const target = await resolveFileOrReport(client, symbol, resolveOpts, opts.format);
@@ -41,7 +40,7 @@ export function registerImportsCommand(program: Command): void {
.option("--format <fmt>", "Output format (text|json|llm)", "text")
.addHelpText("after", "\nExamples:\n ix imported-by AuthProvider\n ix imported-by io.circe.Json --format json")
.action(async (symbol: string, opts: { kind?: string; path?: string; pick?: number; limit: string; format: string }) => {
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const limit = parseInt(opts.limit, 10);
const resolveOpts = { kind: opts.kind, path: opts.path, pick: opts.pick };
const target = await resolveFileOrReport(client, symbol, resolveOpts, opts.format);
diff --git a/ix-cli/src/cli/commands/ingest.ts b/ix-cli/src/cli/commands/ingest.ts
index 47f9ff07..cc866318 100644
--- a/ix-cli/src/cli/commands/ingest.ts
+++ b/ix-cli/src/cli/commands/ingest.ts
@@ -12,7 +12,7 @@ import { ParsePool } from './parse-pool.js';
import chalk from 'chalk';
import { IxClient } from '../../client/api.js';
import type { GraphPatchPayload } from '../../client/types.js';
-import { canonicalWorkspacePath, getEndpoint, isPathInside, resolveWorkspaceRoot, clearMapResultCache, clearStitchScopeCache } from '../config.js';
+import { canonicalWorkspacePath, isPathInside, resolveWorkspaceRoot, clearMapResultCache, clearStitchScopeCache } from '../config.js';
import { resolveIngestRoot } from '../map-root.js';
import {
clearRebuildProgress, extractorChanged, isRev, loadIngestBaseline, loadRebuildProgress,
@@ -51,6 +51,7 @@ import {
transformCommit,
} from '../github/transform.js';
import { printJson } from '../format.js';
+import { createClient } from "../../client/factory.js";
// ---------------------------------------------------------------------------
// File discovery
// ---------------------------------------------------------------------------
@@ -1713,7 +1714,7 @@ export async function ingestFiles(
process.stderr.write(`[multi-repo] system "${detectedSystem!.name}" (${systemId}) members=${detectedSystem!.members.join(', ')} packages=${Object.keys(packageRegistry).length} declaredDeps=${depCount}\n`);
}
- const client = new IxClient(getEndpoint(), opts.deadlineSignal);
+ const client = createClient({ deadlineSignal: opts.deadlineSignal });
// Schema-version check forces a clean re-ingest when the backend's graph
// format has changed in a way that invalidates existing node IDs (e.g. the
@@ -4067,7 +4068,7 @@ async function ingestGitHub(opts: {
}): Promise<void> {
const repo = parseGitHubRepo(opts.github!);
const token = await resolveGitHubToken(opts.token);
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const limit = parseInt(opts.limit, 10);
const start = performance.now();
diff --git a/ix-cli/src/cli/commands/inventory.ts b/ix-cli/src/cli/commands/inventory.ts
index b74a7278..e9423ee5 100644
--- a/ix-cli/src/cli/commands/inventory.ts
+++ b/ix-cli/src/cli/commands/inventory.ts
@@ -2,8 +2,7 @@
import type { Command } from "commander";
import chalk from "chalk";
-import { IxClient } from "../../client/api.js";
-import { getEndpoint } from "../config.js";
+import { createClient } from "../../client/factory.js";
import { resolveWorkspaceId } from "../bootstrap.js";
import { resolveReadSystemId } from "../resolve.js";
import { relativePath, printJson } from "../format.js";
@@ -79,7 +78,7 @@ Examples:
.action(async (opts: {
kind: string; path?: string; limit: string; format: string;
}) => {
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const limit = parseInt(opts.limit, 10);
// Pass --path as a server-side scope so the LIMIT is applied AFTER path
diff --git a/ix-cli/src/cli/commands/locate.ts b/ix-cli/src/cli/commands/locate.ts
index 49cf19be..044ec607 100644
--- a/ix-cli/src/cli/commands/locate.ts
+++ b/ix-cli/src/cli/commands/locate.ts
@@ -2,7 +2,7 @@
import type { Command } from "commander";
import { IxClient } from "../../client/api.js";
-import { getEndpoint } from "../config.js";
+import { createClient } from "../../client/factory.js";
import {
resolveFileOrEntity, resolveEntityFull, printResolved, printAmbiguous,
looksFileLike, isRawId, type ResolvedEntity,
@@ -48,7 +48,7 @@ export function registerLocateCommand(program: Command): void {
ix locate ArangoClient --format json
ix locate scoreCandidate --pick 2`)
.action(async (symbol: string, opts: { kind?: string; path?: string; pick?: number; format: string }) => {
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const diagnostics: string[] = [];
const isJson = opts.format === "json";
diff --git a/ix-cli/src/cli/commands/map.ts b/ix-cli/src/cli/commands/map.ts
index 78ca3aea..3ed67711 100644
--- a/ix-cli/src/cli/commands/map.ts
+++ b/ix-cli/src/cli/commands/map.ts
@@ -2,8 +2,8 @@
import { type Command } from "commander";
import chalk from "chalk";
-import { IxClient } from "../../client/api.js";
-import { clearMapBaseline, clearMapResultCache, getEndpoint } from "../config.js";
+import { createClient } from "../../client/factory.js";
+import { clearMapBaseline, clearMapResultCache } from "../config.js";
import { roundFloat, printJson } from "../format.js";
import { llmLine, llmError, llmShortId } from "../llm.js";
import { bootstrap, resolveWorkspaceId } from "../bootstrap.js";
@@ -533,7 +533,7 @@ Examples:
}
const ingestMs = Math.round(performance.now() - ingestStart);
- const client = new IxClient(getEndpoint(), deadlineSignal);
+ const client = createClient({ deadlineSignal });
const mapBarWidth = 25;
const mapStart = performance.now();
diff --git a/ix-cli/src/cli/commands/overview.ts b/ix-cli/src/cli/commands/overview.ts
index 586e4f68..c1c1635f 100644
--- a/ix-cli/src/cli/commands/overview.ts
+++ b/ix-cli/src/cli/commands/overview.ts
@@ -2,8 +2,7 @@
import type { Command } from "commander";
import { IxClient } from "../../client/api.js";
-import { QUERY_CLIENT_OPTIONS } from "../../client/request-memo.js";
-import { getEndpoint } from "../config.js";
+import { createClient } from "../../client/factory.js";
import { resolveFileOrReport, printResolved } from "../resolve.js";
import { getEffectiveSystemPath, getSystemPath, hasMapData } from "../hierarchy.js";
import { humanizeLabel } from "../impact/risk-semantics.js";
@@ -58,7 +57,7 @@ Examples:
ix overview scoreCandidate --pick 2`
)
.action(async (symbol: string, opts: { kind?: string; path?: string; pick?: number; format: string }) => {
- const client = new IxClient(getEndpoint(), undefined, QUERY_CLIENT_OPTIONS);
+ const client = createClient({ query: true });
const resolveOpts = { kind: opts.kind, path: opts.path, pick: opts.pick };
const target = await resolveFileOrReport(client, symbol, resolveOpts, opts.format);
if (!target) return;
diff --git a/ix-cli/src/cli/commands/query.ts b/ix-cli/src/cli/commands/query.ts
index ea1c4845..b8273ed2 100644
--- a/ix-cli/src/cli/commands/query.ts
+++ b/ix-cli/src/cli/commands/query.ts
@@ -1,8 +1,7 @@
// Copyright 2026 Ix Infrastructure Inc.
import type { Command } from "commander";
-import { IxClient } from "../../client/api.js";
-import { getEndpoint } from "../config.js";
+import { createClient } from "../../client/factory.js";
import { formatContext } from "../format.js";
import { stderr } from "../stderr.js";
@@ -35,7 +34,7 @@ export function registerQueryCommand(program: Command): void {
return;
}
stderr("Running with --unsafe...\n");
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const result = await client.query(question, {
asOfRev: opts.asOf ? parseInt(opts.asOf, 10) : undefined,
depth: opts.depth,
diff --git a/ix-cli/src/cli/commands/rank.ts b/ix-cli/src/cli/commands/rank.ts
index 5c590c23..788c2e37 100644
--- a/ix-cli/src/cli/commands/rank.ts
+++ b/ix-cli/src/cli/commands/rank.ts
@@ -3,7 +3,7 @@
import type { Command } from "commander";
import chalk from "chalk";
import { IxClient } from "../../client/api.js";
-import { getEndpoint } from "../config.js";
+import { createClient } from "../../client/factory.js";
import { activeReadScope, ensureReadScope } from "../resolve.js";
import { llmLine } from "../llm.js";
import { normalizePathSeparators } from "../path-match.js";
@@ -186,7 +186,7 @@ export function registerRankCommand(program: Command): void {
const topN = parseInt(opts.top, 10);
const isJson = opts.format === "json";
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const diagnostics: string[] = [];
// 1. Fetch all entities of the given kind
diff --git a/ix-cli/src/cli/commands/read.ts b/ix-cli/src/cli/commands/read.ts
index 46a3f745..97cbe152 100644
--- a/ix-cli/src/cli/commands/read.ts
+++ b/ix-cli/src/cli/commands/read.ts
@@ -5,7 +5,8 @@ import * as path from "node:path";
import type { Command } from "commander";
import chalk from "chalk";
import { IxClient } from "../../client/api.js";
-import { absoluteFromSourceUri, getEndpoint, isReadablePath, readableRoots, resolveWorkspaceRoot } from "../config.js";
+import { createClient } from "../../client/factory.js";
+import { absoluteFromSourceUri, isReadablePath, readableRoots, resolveWorkspaceRoot } from "../config.js";
import { resolveEntityFull, activeReadScope, ensureReadScope } from "../resolve.js";
import { stderr } from "../stderr.js";
import { isFileStale } from "../stale.js";
@@ -334,7 +335,7 @@ Examples:
// say otherwise.
const cap = opts.all ? undefined : READ_LINE_CAP;
const root = resolveWorkspaceRoot(opts.root);
- const client = new IxClient(getEndpoint());
+ const client = createClient();
// --- Step 1: Parse line range if present ---
const lineRangeMatch = target.match(/^(.+?):(\d+)-(\d+)$/);
diff --git a/ix-cli/src/cli/commands/reset.ts b/ix-cli/src/cli/commands/reset.ts
index 7e6375b0..c3c4c64f 100644
--- a/ix-cli/src/cli/commands/reset.ts
+++ b/ix-cli/src/cli/commands/reset.ts
@@ -3,7 +3,7 @@
import type { Command } from "commander";
import chalk from "chalk";
import { spawnSync } from "child_process";
-import { IxClient } from "../../client/api.js";
+import { createClient } from "../../client/factory.js";
import { getEndpoint, clearIngestMtimeCache, clearStitchScopeCache, findWorkspaceForCwd } from "../config.js";
import { canRenderProgress } from "../stderr.js";
import { resolveWorkspaceId } from "../bootstrap.js";
@@ -63,7 +63,7 @@ export function registerResetCommand(program: Command): void {
}
}
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const label = opts.code ? "Wiping code graph..." : "Wiping graph...";
const spinnerFrames = ["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];
let spinIdx = 0;
@@ -181,7 +181,7 @@ async function resetThisWorkspace(opts: { yes?: boolean; ingest?: boolean }): Pr
}
}
- const client = new IxClient(getEndpoint());
+ const client = createClient();
try {
await client.deleteWorkspace(ws.workspace_id);
} catch (err: any) {
diff --git a/ix-cli/src/cli/commands/savings.ts b/ix-cli/src/cli/commands/savings.ts
index 94c805d8..68fb5a6e 100644
--- a/ix-cli/src/cli/commands/savings.ts
+++ b/ix-cli/src/cli/commands/savings.ts
@@ -2,8 +2,7 @@
import type { Command } from "commander";
import chalk from "chalk";
-import { IxClient } from "../../client/api.js";
-import { getEndpoint } from "../config.js";
+import { createClient } from "../../client/factory.js";
import { llmLine, printLlmLines } from "../llm.js";
import { printJson } from "../format.js";
@@ -145,7 +144,7 @@ export function registerSavingsCommand(program: Command): void {
.option("--format <fmt>", "Output format (text|json|llm)", "text");
cmd.action(async (opts: { detail?: boolean; model: string; format: string }) => {
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const detail = opts.detail ?? false;
const result: SavingsResponse = await client.savings(detail);
@@ -202,7 +201,7 @@ export function registerSavingsCommand(program: Command): void {
cmd.command("reset")
.description("Reset lifetime savings totals")
.action(async () => {
- const client = new IxClient(getEndpoint());
+ const client = createClient();
await client.savingsReset();
console.log(chalk.green(" Savings data reset."));
});
diff --git a/ix-cli/src/cli/commands/search.ts b/ix-cli/src/cli/commands/search.ts
index 145ca38c..5aff7e16 100644
--- a/ix-cli/src/cli/commands/search.ts
+++ b/ix-cli/src/cli/commands/search.ts
@@ -2,8 +2,7 @@
import type { Command } from "commander";
import chalk from "chalk";
-import { IxClient } from "../../client/api.js";
-import { getEndpoint } from "../config.js";
+import { createClient } from "../../client/factory.js";
import { resolveWorkspaceId } from "../bootstrap.js";
import { disambiguatingIds, formatNodes, lineSpan, relativePath, printJson, rowLocation } from "../format.js";
import { baseScore, originPenalty, hasDefinitionOf, mergeById, resolveReadSystemId } from "../resolve.js";
@@ -328,7 +327,7 @@ Examples:
.action(async (term: string, opts: {
limit: string; kind?: string; language?: string; path?: string; asOf?: string; format: string; includeTests?: boolean; testsOnly?: boolean; semantic?: boolean
}) => {
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const limit = parseInt(opts.limit, 10);
// Only an explicit --path scopes results. The active workspace is already
// applied server-side via workspaceId (below), and provenance.sourceUri is
diff --git a/ix-cli/src/cli/commands/smells.ts b/ix-cli/src/cli/commands/smells.ts
index aae3d6b1..229b53b8 100644
--- a/ix-cli/src/cli/commands/smells.ts
+++ b/ix-cli/src/cli/commands/smells.ts
@@ -2,8 +2,7 @@
import type { Command } from "commander";
import chalk from "chalk";
-import { IxClient } from "../../client/api.js";
-import { getEndpoint } from "../config.js";
+import { createClient } from "../../client/factory.js";
import { resolveWorkspaceId } from "../bootstrap.js";
import { resolveReadSystemId } from "../resolve.js";
import { llmLine, llmError, type LlmValue } from "../llm.js";
@@ -63,7 +62,7 @@ Examples:
weakMaxNeighbors: string;
list?: boolean;
}) => {
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const systemId = await resolveReadSystemId(client);
if (opts.list) {
diff --git a/ix-cli/src/cli/commands/stats.ts b/ix-cli/src/cli/commands/stats.ts
index a43a33d6..e7893a3c 100644
--- a/ix-cli/src/cli/commands/stats.ts
+++ b/ix-cli/src/cli/commands/stats.ts
@@ -2,8 +2,7 @@
import type { Command } from "commander";
import chalk from "chalk";
-import { IxClient } from "../../client/api.js";
-import { getEndpoint } from "../config.js";
+import { createClient } from "../../client/factory.js";
import { resolveWorkspaceId } from "../bootstrap.js";
import { resolveReadSystemId } from "../resolve.js";
import { llmLine, llmError, type LlmValue } from "../llm.js";
@@ -28,7 +27,7 @@ export function registerStatsCommand(program: Command): void {
.description("Show graph statistics — node/edge counts by type")
.option("--format <fmt>", "Output format (text|json|llm)", "text")
.action(async (opts: { format: string }) => {
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const systemId = await resolveReadSystemId(client);
let result;
try {
diff --git a/ix-cli/src/cli/commands/status.ts b/ix-cli/src/cli/commands/status.ts
index 70a6b5cf..e04759b3 100644
--- a/ix-cli/src/cli/commands/status.ts
+++ b/ix-cli/src/cli/commands/status.ts
@@ -2,7 +2,7 @@
import type { Command } from "commander";
import { renderSection, renderKeyValue, renderWarning, renderNote, renderSuccess } from "../ui.js";
-import { IxClient } from "../../client/api.js";
+import { createClient } from "../../client/factory.js";
import { readBackendHealth } from "./upgrade.js";
import { getEndpoint, resolveWorkspaceRoot } from "../config.js";
import { detectStaleFiles } from "../stale.js";
@@ -58,7 +58,7 @@ export function registerStatusCommand(program: Command): void {
.option("--format <fmt>", "Output format (text|json|llm)", "text")
.option("--root <dir>", "Workspace root directory")
.action(async (opts: { format: string; root?: string }) => {
- const client = new IxClient(getEndpoint());
+ const client = createClient();
try {
const health = await readBackendHealth(client);
const root = resolveWorkspaceRoot(opts.root);
diff --git a/ix-cli/src/cli/commands/subsystems.ts b/ix-cli/src/cli/commands/subsystems.ts
index 8e224eb1..5ef7b8bc 100644
--- a/ix-cli/src/cli/commands/subsystems.ts
+++ b/ix-cli/src/cli/commands/subsystems.ts
@@ -3,7 +3,7 @@
import type { Command } from "commander";
import chalk from "chalk";
import { IxClient, type ListSubsystemsOptions } from "../../client/api.js";
-import { getEndpoint } from "../config.js";
+import { createClient } from "../../client/factory.js";
import { resolveWorkspaceId } from "../bootstrap.js";
import { resolveReadSystemId } from "../resolve.js";
import { roundFloat, printJson } from "../format.js";
@@ -117,7 +117,7 @@ Examples:
verbose?: boolean;
explain?: boolean;
}) => {
- const client = new IxClient(getEndpoint());
+ const client = createClient();
// Auto-detect a multi-repo system; scope by system_id (spanning all member
// repos) when present, otherwise the single-repo workspace_id.
const systemId = await resolveReadSystemId(client);
diff --git a/ix-cli/src/cli/commands/trace.ts b/ix-cli/src/cli/commands/trace.ts
index ea84188b..baa2a52f 100644
--- a/ix-cli/src/cli/commands/trace.ts
+++ b/ix-cli/src/cli/commands/trace.ts
@@ -3,7 +3,7 @@
import type { Command } from "commander";
import chalk from "chalk";
import { IxClient } from "../../client/api.js";
-import { getEndpoint } from "../config.js";
+import { createClient } from "../../client/factory.js";
import { resolveFileOrEntityFull, resolveFileOrReport, activeReadScope, ensureReadScope } from "../resolve.js";
import type { ResolvedEntity } from "../resolve.js";
import {
@@ -508,7 +508,7 @@ export function registerTraceCommand(program: Command): void {
testsOnly?: boolean;
},
) => {
- const client = new IxClient(getEndpoint());
+ const client = createClient();
const resolveOpts = {
path: opts.path,
diff --git a/ix-cli/src/cli/commands/view.ts b/ix-cli/src/cli/commands/view.ts
index 6ada996f..2ef6f7b1 100644
--- a/ix-cli/src/cli/commands/view.ts
+++ b/ix-cli/src/cli/commands/view.ts
@@ -14,9 +14,9 @@ import { homedir, platform } from "os";
import { fileURLToPath } from "url";
import { createConnection } from "net";
import { resolveWorkspaceId } from "../bootstrap.js";
-import { findWorkspaceForCwd, getDefaultWorkspace, loadWorkspaces, getEndpoint } from "../config.js";
+import { findWorkspaceForCwd, getDefaultWorkspace, loadWorkspaces } from "../config.js";
import { detectSystem } from "../system.js";
-import { IxClient } from "../../client/api.js";
+import { createClient } from "../../client/factory.js";
const IX_HOME = process.env.IX_HOME || join(homedir(), ".ix");
const PID_FILE = join(IX_HOME, "compass.pid");
@@ -665,7 +665,7 @@ export function registerViewCommand(program: Command): void {
systemId = detectSystem(process.cwd())?.systemId ?? null;
if (!systemId && workspaceId) {
try {
- const looked = await new IxClient(getEndpoint()).workspaceSystem(workspaceId);
+ const looked = await createClient().workspaceSystem(workspaceId);
systemId = looked.systemId ?? null;
} catch {
// Older backend without the stitch endpoint, or backend down — fall back to
diff --git a/ix-cli/src/cli/config.ts b/ix-cli/src/cli/config.ts
index f1c8047f..f2cfee4c 100644
--- a/ix-cli/src/cli/config.ts
+++ b/ix-cli/src/cli/config.ts
@@ -254,11 +254,12 @@ export function getEndpoint(): string {
return process.env.IX_ENDPOINT || loadConfig().endpoint;
}
-// Single-place factory for IxClient instances. Pro commands and future OSS
-// code paths should prefer this over `new IxClient(getEndpoint())` so auth
-// and endpoint resolution can evolve in one spot.
+// Kept for @ix/pro, which imports it. The factory itself is the synchronous
+// `createClient` in client/factory.ts; this wrapper loads it lazily because
+// that module imports `getEndpoint` from this one.
export async function createClient(): Promise<IxClient> {
- return new IxClient(getEndpoint());
+ const factory = await import("../client/factory.js");
+ return factory.createClient();
}
export function loadWorkspaces(): WorkspaceConfig[] {
diff --git a/ix-cli/src/cli/hook/claude-post-edit.ts b/ix-cli/src/cli/hook/claude-post-edit.ts
index 8106e5c3..1009a651 100644
--- a/ix-cli/src/cli/hook/claude-post-edit.ts
+++ b/ix-cli/src/cli/hook/claude-post-edit.ts
@@ -2,8 +2,8 @@
import * as fs from "node:fs";
import * as path from "node:path";
-import { IxClient } from "../../client/api.js";
-import { getEndpoint, resolveWorkspaceRoot } from "../config.js";
+import { createClient } from "../../client/factory.js";
+import { resolveWorkspaceRoot } from "../config.js";
import { SourceFiles } from "../edge-sites.js";
import { isSourcePath } from "../explain/issue.js";
import type { FileDiff } from "./session.js";
@@ -299,7 +299,7 @@ function graphPath(roots: Roots, worktreeFile: string): string | undefined {
function gatherWith(deps: HookDeps, opts: HookOptions): (req: AroundRequest) => Promise<AroundResult> {
if (deps.gather) return deps.gather;
const timeoutMs = hookTimeoutMs(opts.env);
- return (req) => gatherAround(new IxClient(getEndpoint(), AbortSignal.timeout(timeoutMs)), req);
+ return (req) => gatherAround(createClient({ deadlineSignal: AbortSignal.timeout(timeoutMs) }), req);
}
/**
diff --git a/ix-cli/src/client/__tests__/factory.test.ts b/ix-cli/src/client/__tests__/factory.test.ts
new file mode 100644
index 00000000..72cf2f76
--- /dev/null
+++ b/ix-cli/src/client/__tests__/factory.test.ts
@@ -0,0 +1,91 @@
+// Copyright 2026 Ix Infrastructure Inc.
+
+import { createServer, type Server } from "node:http";
+import type { AddressInfo } from "node:net";
+import { afterEach, beforeEach, describe, expect, it } from "vitest";
+
+import { createClient as createClientAsync } from "../../cli/config.js";
+import { IxClient } from "../api.js";
+import { createClient } from "../factory.js";
+
+const servers: Server[] = [];
+let savedEndpoint: string | undefined;
+
+/** A backend that answers every request with an empty expand and counts them. */
+async function backend() {
+ let requests = 0;
+ const server = createServer((request, response) => {
+ request.resume();
+ request.on("end", () => {
+ requests++;
+ response.writeHead(200, { "content-type": "application/json" });
+ response.end(JSON.stringify({ nodes: [], edges: [] }));
+ });
+ });
+ servers.push(server);
+ await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
+ return {
+ requests: () => requests,
+ endpoint: `http://127.0.0.1:${(server.address() as AddressInfo).port}`,
+ };
+}
+
+beforeEach(() => {
+ savedEndpoint = process.env.IX_ENDPOINT;
+});
+
+afterEach(async () => {
+ if (savedEndpoint === undefined) delete process.env.IX_ENDPOINT;
+ else process.env.IX_ENDPOINT = savedEndpoint;
+ await Promise.all(
+ servers.splice(0).map(
+ (server) =>
+ new Promise<void>((resolve) => {
+ server.closeAllConnections();
+ server.close(() => resolve());
+ }),
+ ),
+ );
+});
+
+const read = (client: IxClient) => client.expand("a", { direction: "in", predicates: ["CALLS"] });
+
+describe("createClient", () => {
+ it("uses the configured endpoint unless one is passed", () => {
+ process.env.IX_ENDPOINT = "http://127.0.0.1:1";
+ expect(createClient().endpoint).toBe("http://127.0.0.1:1");
+ expect(createClient({ endpoint: "http://127.0.0.1:2" }).endpoint).toBe("http://127.0.0.1:2");
+ });
+
+ it("shares repeated reads only for a query client", async () => {
+ const b = await backend();
+ process.env.IX_ENDPOINT = b.endpoint;
+
+ const plain = createClient();
+ await read(plain);
+ await read(plain);
+ expect(b.requests()).toBe(2);
+ expect(plain.sharedReadHits).toBe(0);
+
+ const query = createClient({ query: true });
+ await read(query);
+ await read(query);
+ expect(b.requests()).toBe(3);
+ expect(query.sharedReadHits).toBe(1);
+ });
+
+ it("aborts every request once the deadline signal fires", async () => {
+ const b = await backend();
+ const client = createClient({ endpoint: b.endpoint, deadlineSignal: AbortSignal.abort() });
+
+ await expect(read(client)).rejects.toThrow();
+ expect(b.requests()).toBe(0);
+ });
+
+ it("keeps the async createClient that @ix/pro imports from cli/config", async () => {
+ process.env.IX_ENDPOINT = "http://127.0.0.1:3";
+ const client = await createClientAsync();
+ expect(client).toBeInstanceOf(IxClient);
+ expect(client.endpoint).toBe("http://127.0.0.1:3");
+ });
+});
diff --git a/ix-cli/src/client/factory.ts b/ix-cli/src/client/factory.ts
new file mode 100644
index 00000000..f06da157
--- /dev/null
+++ b/ix-cli/src/client/factory.ts
@@ -0,0 +1,31 @@
+// Copyright 2026 Ix Infrastructure Inc.
+
+import { getEndpoint } from "../cli/config.js";
+import { IxClient } from "./api.js";
+import { QUERY_CLIENT_OPTIONS } from "./request-memo.js";
+
+export interface CreateClientOptions {
+ /** Backend URL. Defaults to `getEndpoint()` (IX_ENDPOINT, then config.yaml). */
+ endpoint?: string;
+ /** Aborts every request this client makes once it fires (a whole-command deadline). */
+ deadlineSignal?: AbortSignal;
+ /**
+ * A read-heavy, single-command client: repeated reads are answered from the
+ * first response and requests in flight are capped (`QUERY_CLIENT_OPTIONS`).
+ */
+ query?: boolean;
+}
+
+/**
+ * The one place an `IxClient` is built. Every command gets its client here, so
+ * anything that must apply to every request (an auth token, an abort signal, a
+ * limiter, a deadline) is added once. An ESLint rule forbids `new IxClient(`
+ * outside `src/client/` and tests.
+ */
+export function createClient(opts: CreateClientOptions = {}): IxClient {
+ return new IxClient(
+ opts.endpoint ?? getEndpoint(),
+ opts.deadlineSignal,
+ opts.query ? QUERY_CLIENT_OPTIONS : {},
+ );
+}